def Call_from_spring_Batch_Job_to_Step(self, application): nb_links = 0 for springBatchStep in application.objects().has_type( 'SpringBatchStep'): springBatchStep_full_name = springBatchStep.get_fullname() #logging.info(" Spring Batch Step name : [" + str(springBatchStep) + "]") springBatchjob_full_name = springBatchStep_full_name[:-( len(springBatchStep.get_name()) + 1)] springBatchjob_name = springBatchjob_full_name.split('].')[1] #logging.info(" Spring Batch Job full name : [" + str(springBatchjob_full_name) + "]") if springBatchjob_name in self.springBatchJob: SpringBatchJob = self.springBatchJob[springBatchjob_name] create_link('callLink', SpringBatchJob, springBatchStep) logging.debug("Creating link between " + str(SpringBatchJob) + " and " + str(springBatchStep)) nb_links += 1 else: logging.debug("Spring Batch Job not found [" + str(springBatchjob_name) + "]") logging.debug( "Nb of links created between Spring Batch Job and Spring Batch Step : " + str(nb_links)) self.global_nb_links += nb_links
def callLinkFromTilesDefToTilesAttribute(self, application): nb_TilesAttribute = 0 nb_links = 0 for tilesAttribute in application.objects().has_type('TilesAttribute'): nb_TilesAttribute += 1 # find the parent of the object #tilesDef_fullname = '.'.join(tilesAttribute.get_fullname().split('.')[:-1]) tilesDef_fullname = tilesAttribute.get_fullname()[:-( len(tilesAttribute.get_name()) + 1)] #logging.info("tilesAttribute full Name = [" + str(tilesAttribute.get_fullname()) + "]") #logging.info("tilesDefinition full Name = [" + tilesDef_fullname + "]") if tilesDef_fullname in self.tilesDef: tilesDef = self.tilesDef[tilesDef_fullname] #logging.info(" Creating call link between tileDef = [" + tilesDef_fullname + "] and TilesAttribute = [" + str(tilesAttribute.get_fullname()) + "]") create_link('callLink', tilesDef, tilesAttribute) nb_links += 1 else: logging.info( " Did not find the Tiles Definition parent of the TilesAttribute = [" + str(tilesAttribute) + "]") logging.info( " Full name of the Tiles Definition not found = [" + tilesDef_fullname + "]") logging.debug("Nb of Tiles Attributes : " + str(nb_TilesAttribute)) logging.debug( "Nb of call links created between Tiles Definitions and Tiles Attributes : " + str(nb_links))
def Call_to_spring_Batch_Job(self, application): springBatch_access = ReferenceFinder() springBatch_access.add_pattern( "springBatchCall", before="", element="\(Job\)[ ]*context\.getBean\(\"[a-zA-Z0-9_-]+", after="") nb_links = 0 for o in application.get_files(['JV_FILE']): # check if file is analyzed source code, or if it generated (Unknown) if not o.get_path(): continue for reference in springBatch_access.find_references_in_file(o): #logging.debug("Reference " + reference.value) springBatchJob_name = reference.value.split("\"")[1] #logging.debug("searching " + springBatchJob_name) if springBatchJob_name in self.springBatchJob: springBatchJob_target = self.springBatchJob[ springBatchJob_name] create_link('callLink', reference.object, springBatchJob_target, reference.bookmark) logging.debug("Creating link between " + str(reference.object) + " and " + str(springBatchJob_target)) nb_links += 1 else: logging.debug("Spring Batch Job not found [" + str(springBatchJob_name) + "]") # Begin Specific for CPP 2017 project if 'processFlux' in str(springBatchJob_name): logging.debug(" !!!!!! Spring Batch Job name dynamic ") for springBatchJob_target_processFlux_name in self.springBatchJob: if 'processFlux' in springBatchJob_target_processFlux_name: springBatchJob_target_processFlux = self.springBatchJob[ springBatchJob_target_processFlux_name] create_link('callLink', reference.object, springBatchJob_target_processFlux, reference.bookmark) logging.debug( "Creating link between " + str(reference.object) + " and " + str(springBatchJob_target_processFlux)) nb_links += 1 # end Specific for CPP 2017 project logging.debug( "Nb of links created between Java classes and Spring Batch Job : " + str(nb_links)) self.global_nb_links += nb_links
def Call_from_spring_Batch_Job_to_Step(self, application): nb_links = 0 for springBatchJob in application.objects().has_type('Spring_BatchJob'): springBatchJob.load_children() for springBatchStep in springBatchJob.get_children(): create_link('callLink', springBatchJob, springBatchStep) logging.info("Creating link between " + springBatchJob.get_fullname() + " and " + springBatchStep.get_name()) nb_links += 1 #logging.Info("Nb of links created between Spring Batch Jobs and Spring Batch Steps : " + str(nb_links)) self.global_nb_links += nb_links
def end_application(self, application): logging.info('Creating links to iBatis objects...') for namedQuery in application.search_objects(category='CAST_SQL_NamedQuery', load_properties=True): logging.debug('Processing Name query %s' % namedQuery.get_name()) iBatisLinks.create(application, namedQuery, 'iBatisProperties.class') iBatisLinks.create(application, namedQuery, 'iBatisProperties.parameterClass') iBatisLinks.create(application, namedQuery, 'iBatisProperties.resultClass') iBatisLinks.create(application, namedQuery, 'iBatisProperties.listClass') iBatisLinks.create(application, namedQuery, 'iBatisProperties.resultType') MyBatisLinks.create(application, namedQuery) #GREP in DotNet/Java, looking for iBatis objects logging.info('Creating dynamic links to iBatis objects...') rf = ReferenceFinder() rf.add_pattern('iBatis', before='["\.]', element='[A-Za-z0-9_\-]+', after='"') references = [] for o in application.get_files(['CAST_DotNet_CSharpFile', 'JV_FILE']): # check if file is analyzed source code, or if it generated (Unknown) if not o.get_path(): continue references += [reference for reference in rf.find_references_in_file(o)] for reference in references: for namedQuery in application.objects().has_type('CAST_SQL_NamedQuery'): if reference.value == namedQuery.get_name(): logging.debug('Reference to %s found in %s' % (namedQuery.get_name(), reference.object.get_name())) link = create_link('callLink', reference.object, namedQuery, reference.bookmark) link.mark_as_not_sure()
def create(application, namedQuery): # @todo : inefficient : this a unitary query inside a loop logging.debug('Looking for %s' % namedQuery.get_name()) for methodObject in application.search_objects(name=namedQuery.get_name(), category='JV_METHOD'): if methodObject.get_fullname() == '%s.%s' % (namedQuery.get_property('iBatisProperties.namespace'), namedQuery.get_name()): logging.debug('MyBatis structural link from %s to %s' % (methodObject.get_fullname(), namedQuery.get_name())) link = create_link('useLink', methodObject, namedQuery) link.mark_as_not_sure()
def links_to_error_pages(self, application): nb_links = 0 logging.info( "==> Solving the following problem : Missing links to error or exception pages " ) links = [] error_JSP = "applicationErrorView.jsp" error_JSP_iter = application.get_objects_by_name(name=error_JSP) for error_JSP_object in error_JSP_iter: #logging.debug("Error JSP full name[" + error_JSP_object.get_fullname() + "]") java_exceptions = { "fi.op.jopo.exception.JopoException", "fi.op.jopo.exception.JopoApplicationException", "fi.op.jopo.exception.JopoSystemException" } for java_exception in java_exceptions: java_exception_short_name = java_exception.split( "exception.")[1] #logging.debug("Java Exception short name[" + java_exception_short_name + "]") java_exception_iter = application.get_objects_by_name( name=java_exception_short_name, external=True) for java_exception_object in java_exception_iter: if (java_exception_object.get_fullname() == java_exception ): #logging.debug("Java Exception full name[" + java_exception_object.get_fullname() + "]") links.append(('callLink', java_exception_object, error_JSP_object, 0)) # 3. Create the links for link in links: logging.debug("Creating link between " + str(link[1]) + " and " + str(link[2])) create_link(*link) nb_links = nb_links + 1 logging.debug("Nb of links to error pages created " + str(nb_links)) self.global_nb_links = self.global_nb_links + nb_links
def end_application(self, application): logging.debug("end_application1") for o in application.objects(): # for o in application.objects().has_type('APIConnect_myobject'): # logging.debug(o.get_name()) a = re.search("Cobol prgm (\w+)", o.get_fullname()) if(a!=None): logging.debug("oui1") logging.debug(o.get_fullname()) nolinkcreated = True a = a.group(1) logging.debug(a) b = a.split("cherche") logging.debug(b) # try: logging.debug(b[1]) print(o.get_fullname()+" o.get_fullname()") # logging.debug(ob.get_name()) for ob in application.objects().has_type(b[1]): # logging.debug("ob = "+ob.get_name()+" "+b[0]) if (ob.get_name() == b[0]): logging.debug(ob.get_type()+" "+ob.get_name()+" "+o.get_type()+" "+o.get_fullname() ) # logging.debug("qqqqqqqqqqqqqqqqqqq") create_link("callLink",o,ob) logging.debug("link created") nolinkcreated = False if(nolinkcreated): logging.debug("oui") ab = re.search("(.+) Cobol", o.get_fullname()).group(1) logging.debug("a = "+ab) for ob in application.objects().has_type("APIConnect_unknownqueue"): logging.debug(ob.get_fullname()) a = re.search("thereisnoprogram"+ab,ob.get_fullname()) if(a != None): # logging.debug(a) create_link("callLink", o, ob) logging.debug("lien de type et objets crees")
def BeansList(self, application): # all classes with a link to a Spring Bean for link in application.links().has_callee(application.objects().is_class()).has_caller(application.objects().has_type('SPRING_BEAN')): bean = link.get_caller() bean_name = bean.get_name() #logging.debug("Spring Bean [" + bean_name + "]") logging.info(" Adding a link call between the bean and the class it relies on : " + bean_name + " to " + link.get_callee().get_name()) create_link('callLink', bean, link.get_callee()) if bean_name in self.beans: logging.info(" ---- Warning duplicate on Spring Bean : " + bean_name) else: self.beans[bean_name] = bean for link in application.links().has_callee(application.objects().is_class()).has_caller(application.objects().has_type('JSP_BEAN')): bean = link.get_caller() bean_name = bean.get_name() #logging.debug("JEE Scoped Bean [" + bean_name + "]") logging.info(" Adding a link call between the bean and the class it relies on : " + bean_name + " to " + link.get_callee().get_name()) create_link('callLink', bean, link.get_callee()) if bean_name in self.beans: logging.info(" ---- Warning duplicate on JSP Bean : " + bean_name) else: self.beans[bean_name] = bean for link in application.links().has_callee(application.objects().is_class()).has_caller(application.objects().has_type('XML_BEAN')): bean = link.get_caller() bean_name = bean.get_name() #logging.debug("XML Bean [" + bean_name + "]") logging.info(" Adding a link call between the bean and the class it relies on : " + bean_name + " to " + link.get_callee().get_name()) create_link('callLink', bean, link.get_callee()) if bean_name in self.beans: logging.info(" ---- Warning duplicate on XML Bean : " + bean_name) else: self.beans[bean_name] = bean
def end_application(self, application): logging.info( "GenericRefLink : Running extension code at the end of an application" ) # list all files saved try: #fpath="C:\ProgramData\CAST\CAST\Extensions\com.castsoftware.labs.GenRefLink.1.0.0\Generic.xml" fpath = self.Castpath.get_drive( ) + "ProgramData\CAST\CAST\Extensions\com.castsoftware.labs.GenericRefLink.1.1.0\Generic.xml" logging.info(str(fpath)) if (os.path.isfile(fpath)): tree = ET.parse(fpath, ET.XMLParser(encoding="UTF-8")) root = tree.getroot() cnt = 0 for group in root.findall('Search'): sbefore = group.find('RegexPatternBefore').text safter = group.find('RegexPatternAfter').text sregex = group.find('RegexPattern').text sfileext = group.find('RefFileExtension').text sfilecategory = group.find('RefFileCastCatergory').text nb_links = 0 links = [] files = [] rf = ReferenceFinder() cnt = cnt + 1 if sbefore is None: sbefore = "" if safter is None: safter = "" if sfileext is not None: sfileext = sfileext.replace(".", "") logging.debug( str(sbefore) + "---" + str(sregex) + "---" + str(safter)) rf.add_pattern('Search' + sfileext + str(cnt), before=sbefore, element=sregex, after=safter) # list all files saved try: fileCount = sum( 1 for x in application.get_files([sfilecategory])) files = application.get_files([sfilecategory]) self.findpattern(application, files, group, links, rf) except Exception as e: logging.error(": Error getting source file set : %s", str(e)) # 3. Create the links for link in links: logging.info("Creating link between " + str(link[1]) + " and " + str(link[2])) create_link(*link) nb_links = nb_links + 1 links = [] logging.info("Nb of links created " + str(nb_links)) except Exception as e: logging.error(": Error Generic ref link extension set : %s", str(e))
def end_application(self, application): logging.info('Creating links for Informix 4GL...') previousFileName = "" with self.get_intermediate_file("Informix4GL_linksFile.txt") as f: for line in f: fileName, programName, linkType, callerShortName, callerFullName, calledShortName, lineNbr, colStart, colEnd = line.split('|') #logging.info("%s to %s" % (linkType, callerFullName)) #Get Caller Program if previousFileName != fileName: for fo in application.get_files(): #TODO Need to filter better here but languages did not work if fo.get_fullname() == fileName: fileObj = fo callerProgramObj = None for o in application.get_objects_by_name(name=programName): if o.get_fullname().startswith(fileName): callerProgramObj = o callerProgramObj.load_children() #logging.info(" -p %s" % callerProgramObj.get_fullname()) #Get Caller Object callerObj = None for o in application.get_objects_by_name(name=callerShortName): if o.get_fullname() == callerFullName: callerObj = o #logging.info(" -r %s" % callerObj.get_fullname()) #Get Called Object calledObj = None if linkType == "callLink": calledObjList = application.get_objects_by_name(name=calledShortName) for o in calledObjList: if o.get_fullname().startswith(fileName): calledObj = o #logging.info(" -d %s" % calledObj.get_fullname()) if calledObj is None: for o in calledObjList: for o in callerProgramObj.get_children(): if o.get_type() == "INFORMIX4GLGlobals" and o.get_fullname().contains(o.get_name()): calledObj = o #logging.info(" -D %s" % (calledObj.get_name())) if linkType == "screenLink": for o in application.search_objects(name=calledShortName, category="INFORMIX4GLScreen"): calledObj = o #logging.info(" -d %s" % calledObj.get_fullname()) if callerObj is None: logging.warning("%s could not be found in the KB!" % callerFullName) else: if calledObj is None: #The regex catches lots of things that are not functions to begin with... #no need for it to be a warning logging.debug("%s could not be found in the KB!" % calledShortName) else: logging.debug("create link from %s to %s" % (callerObj.get_fullname(), calledObj.get_fullname())) link = create_link('callLink', callerObj, calledObj, Bookmark(fileObj, lineNbr, colStart, lineNbr, colEnd)) link.mark_as_not_sure() previousFileName = fileName
def scan_phpfile(self, application, phpfile): logging.debug("INIT scan_phpfile > " + str(phpfile.name)) # one RF for multiples patterns rfCall = ReferenceFinder() # Be careful, the order here is important !!!!!! # lines comments in PHP files rfCall.add_pattern('CSCOMMENTEDline', before='', element=r'^[\t ]*//.*$|^[\t ]*#.*$', after='') # requires application_1_4_7 or above # Mapping class # example : @ORM\Table(name="affaire_r" #/** # * AffaireR # * @ORM\Table(name="affaire_r") # * @ORM\Entity(repositoryClass="NatachaBundle\Repository\AffaireRRepository") # * @ORM\Entity # * @ORM\Table(name="affaire_r") #*/ rexTableAnnotation = '@ORM\\\\Table\(name=[\'"]([A-Za-z0-9\-_]+)[\'"]' rfCall.add_pattern('DoctrineTableAnnotation', before='', element=rexTableAnnotation, after='') # Repository class #rexRepositoryClass = '@ORM\\\\Entity\(repositoryClass="[A-Za-z0-9\-_\\\\]([A-Za-z0-9\-_]+)"' rexRepositoryClass = '@ORM\\\\Entity\(repositoryClass=[\'"][A-Za-z0-9\-_\\\\]+[\\\\]([A-Za-z0-9\-_]+)[\'"]' rfCall.add_pattern('DoctrineRepositoryClass', before='', element=rexRepositoryClass, after='') # Class from methods to Classes # looking for class name after a namespace # examples : # -> LeftJoin("NatachaBundle:AffaireC",'ac','WITH','a.id=ac.ic' # . "JOIN AppBundle:AuditLog audit " # -> getRepository("AppTdexBundle:TCasier"); # $commune = $em-> getRepository('AppBundle:Commune')->getAutocomplete(); # ->from('NatachaBundle:AffaireC' rexClass = '[\'"].*[A-Za-z0-9\-_]+[:]([A-Za-z0-9\-_]+)' # examples : # ->join('u.AffaireR', 'ar', 'WITH', 'a.id = ar.id') rexClass = rexClass + '|' + '\([\'"][A-Za-z0-9]+[.]([A-Za-z0-9_-]+)' # examples : # ->from('AffaireR' # ->join('AffaireR' # ->leftJoin('AffaireR' # ->innerJoin('AffaireR' rexClass = rexClass + '|' + '([fF][rR][oO][mM]|[jJ][oO][iI][nN])\([\'"]([A-Za-z0-9]+)[\'"]' rfCall.add_pattern('MethodToClassLink', before='', element=rexClass, after='') # PHP to symfony services # examples : rexphpToSymfonyService = '[gG][eE][tT]\(["\']([A-Za-z0-9_\.-]+)["\']' rfCall.add_pattern('PhpToSymfonyService', before='', element=rexphpToSymfonyService, after='') try: references = [ reference for reference in rfCall.find_references_in_file(phpfile) ] except FileNotFoundError: logging.warning("Wrong file or file path, from Vn-1 or previous " + str(phpfile)) else: # for debugging and traversing the results for reference in references: #logging.debug(" DONE: reference found: >" +str(reference)) # identify the boolmark and parent object bk_line_code = reference.bookmark.begin_line most_specific_object = phpfile.find_most_specific_object( bk_line_code, 1) # Pattern 1 - Looking for the @ORM\Table Doctrine annotation if reference.pattern_name == 'DoctrineTableAnnotation': logging.debug("\t\t DoctrineTableAnnotation>" + reference.value) m0 = re.search(rexTableAnnotation, reference.value) if m0: tablename = m0.group(1) try: tableObject = self.tables[tablename] try: # get the class name parentObject = self.mappingSectionClass[ most_specific_object.get_fullname()] except KeyError: #if there is no php class in the php section we keep the section as parent object parentObject = most_specific_object create_link("useLink", parentObject, tableObject, reference.bookmark) self.nbLinksDoctrineTableAnnotation += 1 except KeyError: logging.warning( "\t\t Couldn't find table in local schema : " + tablename) # Pattern 2 - Looking for the repository class if reference.pattern_name == 'DoctrineRepositoryClass': logging.debug("\t\t DoctrineRepositoryClass>" + reference.value) m0 = re.search(rexRepositoryClass, reference.value) if m0: repositoryClassName = m0.group(1) try: repositoryClassObject = self.phpClassesByName[ repositoryClassName] try: # get the class name for this section parentObject = self.mappingSectionClass[ most_specific_object.get_fullname()] except KeyError: #if there is no php class in the php section we keep the section as parent object parentObject = most_specific_object create_link("useLink", parentObject, repositoryClassObject, reference.bookmark) self.nbLinksDoctrineRepositoryClass += 1 except KeyError: logging.warning( "\t\t Couldn't find phpClass in local schema (DoctrineRepositoryClass) : " + repositoryClassName) # Pattern 3 - Looking for method with namespace to class link to create if reference.pattern_name == 'MethodToClassLink': logging.debug("\t\t MethodToClassLink>" + reference.value) m0 = re.search(rexClass, reference.value) if m0: classname = m0.group(1) if classname == None: classname = m0.group(2) if classname == None: classname = m0.group(4) logging.debug("\t\t classname>" + classname) try: classObject = self.phpClassesByName[classname] parentObject = most_specific_object create_link("useLink", parentObject, classObject, reference.bookmark) self.nbLinksMethodToClass += 1 except KeyError: logging.warning( "\t\t Couldn't find phpClass in local schema (MethodToClassLink) : " + classname) if reference.pattern_name == 'PhpToSymfonyService': logging.debug("\t\t PhpToSymfonyService>" + reference.value) m0 = re.search(rexphpToSymfonyService, reference.value) if m0: servicename = m0.group(1) try: serviceObject = self.phpSymfonyServices[ servicename] parentObject = most_specific_object create_link("callLink", parentObject, serviceObject, reference.bookmark) self.nbLinksPHPToSymfonyService += 1 except KeyError: logging.warning( "\t\t Couldn't find symfony service in local schema (PhpToSymfonyService) : " + servicename)
def scan_yamlfile(self, application, yfile): logging.debug("INIT scan_yamlfile > " + str(yfile.name)) bContainsService = False # one RF for multiples patterns rfCall = ReferenceFinder() # to make sure this file contains Symfony services rfCall.add_pattern('containsService', before='', element='services:', after='') # to collect the Symfony service name rexSymfonyServiceName = '^[ ][ ][ ][ ]([A-Za-z0-9_\.-]+)[:]' rfCall.add_pattern('SymfonyServiceName', before='', element=rexSymfonyServiceName, after='') # to collect the service clas name rexSymfonyServiceClassName = '^[ ][ ][ ][ ][ ][ ][ ][ ][cC][lL][aA][sS][sS][:][\t ]*[A-Za-z0-9\-_\\\\]+[\\\\]([A-Za-z0-9\-_]+)' rfCall.add_pattern('SymfonyServiceClassName', before='', element=rexSymfonyServiceClassName, after='') try: references = [ reference for reference in rfCall.find_references_in_file(yfile) ] except FileNotFoundError: logging.warning("Wrong file or file path, from Vn-1 or previous " + str(yfile)) else: # for debugging and traversing the results for reference in references: #logging.debug(" DONE: reference found: >" +str(reference)) # identify the boolmark and parent object bk_line_code = reference.bookmark.begin_line most_specific_object = yfile.find_most_specific_object( bk_line_code, 1) # Service name if reference.pattern_name == 'containsService': logging.debug("\t\t containsService>" + reference.value) bContainsService = True self.nbYAMLFileWithSymfonyServices += 1 # Service name if bContainsService and reference.pattern_name == 'SymfonyServiceName': logging.debug("\t\t SymfonyServiceName>" + str(reference)) m0 = re.search(rexSymfonyServiceName, reference.value) if m0: self.currentSymfonyServiceName = m0.group(1) # Service class name if bContainsService and reference.pattern_name == 'SymfonyServiceClassName': logging.debug("\t\t\t SymfonyServiceClassName>" + str(reference)) logging.debug("\t\t\t\t self.currentSymfonyServiceName>" + self.currentSymfonyServiceName) m0 = re.search(rexSymfonyServiceClassName, reference.value) if m0: symfonyServiceClassName = m0.group(1) try: oclass = self.phpClassesByName[ symfonyServiceClassName] osymfonyservice = self.phpSymfonyServices[ self.currentSymfonyServiceName] logging.debug( "\t\t\t\t creating link betwween SymfonyService " + osymfonyservice.get_fullname() + " and class " + oclass.get_fullname()) create_link("useLink", osymfonyservice, oclass, reference.bookmark) self.nbLinksSymfonyServiceToServiceClass += 1 except KeyError: logging.warning('Not able to find class ' + symfonyServiceClassName)
def links_from_Tiles_to_JSP(self, application): nb_links = 0 #for tilesDef in application.search_objects(category='TilesDefinition', load_properties=True): for tilesDef in application.objects().has_type( 'TilesDefinition').load_property( 'TilesDefinition.definition_template'): # check if file is analyzed source code, or if it generated (Unknown) logging.info("tilesDefinition Name1 = " + tilesDef.get_name()) jspTarget_name = tilesDef.get_property( 'TilesDefinition.definition_template') if not jspTarget_name == None: logging.info("jsp target name = [" + str(jspTarget_name) + "]") jspTarget_name = jspTarget_name.replace('.jspx', '').replace( '.jsp', '') logging.info("jsp target name = [" + str(jspTarget_name) + "]") try: create_link('callLink', tilesDef, self.jsp[jspTarget_name]) nb_links += 1 except KeyError: logging.info("jsp or jspx not found") logging.debug( "Nb of links created between Tiles definition tags and JSP : " + str(nb_links)) self.global_nb_links = self.global_nb_links + nb_links nb_links = 0 for tilesDef in application.objects().has_type( 'TilesDefinition').load_property( 'TilesDefinition.definition_extends'): # check if file is analyzed source code, or if it generated (Unknown) logging.info("tilesDefinition Name2 = " + tilesDef.get_name()) tilesDef_webapp = self.webapp_container(tilesDef) logging.info("tilesDefinition Webapp = " + str(tilesDef_webapp)) tilesDefTarget_name = tilesDef.get_property( 'TilesDefinition.definition_extends') logging.info("TilesDefinition target = [" + str(tilesDefTarget_name) + "]") # Searching in TilesDefinition if (tilesDef_webapp + "#" + tilesDefTarget_name.replace( "\\", "/")) in self.tilesDefWebapp: target = self.tilesDefWebapp[tilesDef_webapp + "#" + tilesDefTarget_name.replace( "\\", "/")] logging.debug("target tilesDef = [" + str(target) + "]") create_link('callLink', tilesDef, target) nb_links += 1 logging.debug( "Nb of links created between Tiles definition tags and another Tiles Definition : " + str(nb_links)) self.global_nb_links = self.global_nb_links + nb_links nb_links = 0 nb_links2 = 0 #for putAtt in application.search_objects(category='TilesAttribute', load_properties=True): for putAtt in application.objects().has_type( 'TilesAttribute').load_property( 'TilesAttribute.put_attribute_value'): # check if file is analyzed source code, or if it generated (Unknown) logging.info("TilesAttribute Name = " + putAtt.get_name()) put_attribute_value = putAtt.get_property( 'TilesAttribute.put_attribute_value') logging.info("TilesAttribute Value = [" + str(put_attribute_value) + ']') if put_attribute_value is None: logging.info("TilesAttribute Value is null") if not put_attribute_value is None: if put_attribute_value.endswith( '.jsp') or put_attribute_value.endswith( '.jspx'): # link to a JSP jspTarget_name = put_attribute_value jspTarget_name = jspTarget_name.replace('.jspx', '').replace( '.jsp', '') logging.info("jsp(x) target = [" + str(jspTarget_name) + "] should be called from [" + str(putAtt) + "]") try: create_link('callLink', putAtt, self.jsp[jspTarget_name]) nb_links += 1 except KeyError: logging.info("jsp not found") if (not put_attribute_value.endswith('.jsp')) and ( not put_attribute_value.endswith('.jspx') ): # link to a Tiles Definition tilesDef_target = put_attribute_value logging.info("Tiles Definition target = [" + str(tilesDef_target) + "]") tiles_webapp = self.webapp_container(putAtt) # Searching in TilesDefinition if (tiles_webapp + "#" + tilesDef_target.replace( "\\", "/")) in self.tilesDefWebapp: logging.info("**** Tiles Definition target found") target = self.tilesDefWebapp[tiles_webapp + "#" + tilesDef_target.replace( "\\", "/")] logging.debug("target tiles = [" + str(target) + "]") create_link('callLink', putAtt, target) nb_links2 += 1 logging.debug( "Nb of links created between Tiles put-attribute tags and JSP : " + str(nb_links)) logging.debug( "Nb of links created between Tiles put-attribute tags and Definition tag : " + str(nb_links2)) self.global_nb_links = self.global_nb_links + nb_links + nb_links2
def links_from_JSP_to_Tiles(self, application): nb_links = 0 nb_links2 = 0 nb_links3 = 0 nb_notfound = 0 logging.info( "==> solves the following problem : Missing links between JSP and Tiles" ) # 1. search all references in all files logging.info("Scanning jsp and jspx files for calls to Tiles tags") # 2. scan each JSP file # we search a pattern jsp_access = ReferenceFinder() jsp_access.add_pattern( "Mapping", before="tiles:insertAttribute", element= "[ \n\r\t]+name[ \n\r\t]*\=[ \n\r\t]*[A-Za-z0-9\=_\-\.\" ]+", after="") links = [] # iterate all objects of the application for o in application.get_files(['CAST_Web_File']): # check if file is analyzed source code, or if it generated (Unknown) if not o.get_path(): continue if (not o.get_path().lower().endswith('.jsp')) and (not o.get_path( ).lower().endswith('.jspx')): # check if JSP file continue #logging.debug("JSP name = [" + o.get_path() + "]") jsp_webapp = self.webapp_container(o) #logging.debug("JSP webapp = [" + jsp_webapp + "]") for reference in jsp_access.find_references_in_file(o): #logging.debug("Reference [" + reference.value + "]") # manipulate the reference pattern found if not 'name=\"' in reference.value: continue searched_tiles_tag_name = reference.value.split("\"")[1] #logging.debug("searching [" + searched_tiles_tag_name + "]") #logging.debug('searching [' + jsp_webapp + '#' + searched_tiles_tag_name.replace("\\", "/") + ']') # Searching in TilesDefinition if (jsp_webapp + "#" + searched_tiles_tag_name.replace( "\\", "/")) in self.tilesDefWebapp: target = self.tilesDefWebapp[ jsp_webapp + "#" + searched_tiles_tag_name.replace("\\", "/")] #logging.debug("target tilesDef = [" + str(target) + "]") create_link('callLink', o, target) nb_links += 1 # Searching in Put-attribute elif (jsp_webapp + "#" + searched_tiles_tag_name.replace( "\\", "/")) in self.tilesPutAttWebapp: target = self.tilesPutAttWebapp[ jsp_webapp + "#" + searched_tiles_tag_name.replace("\\", "/")] #logging.debug("target put-attribute = [" + str(target) + "]") create_link('callLink', o, target) nb_links2 += 1 else: logging.debug( "target not a tilesDef neither of put-attribute in the same webapp as the JSP = [" + str(searched_tiles_tag_name) + "] search was [" + jsp_webapp + "#" + searched_tiles_tag_name.replace("\\", "/") + "]") if searched_tiles_tag_name in self.tilesPutAtt: target = self.tilesPutAtt[searched_tiles_tag_name] logging.debug( "creating a less targeted link : target tilesDef = [" + str(target) + "]") create_link('callLink', o, target) nb_links3 += 1 else: logging.debug( "no link created between the JSP and the tilesDef or put-attribute" ) nb_notfound += 1 # 3. Create the links for link in links: logging.debug("Creating link between " + str(link[1]) + " and " + str(link[2])) create_link(*link) logging.debug( "Nb of links created between JSP and Tiles Definition tags : " + str(nb_links)) logging.debug( "Nb of links created between JSP and Tiles put-attribute tags : " + str(nb_links2)) logging.debug( "Nb of links created between JSP and Tiles put-attribute tags without targeting the webapp: " + str(nb_links3)) logging.debug( "Nb of links not created between JSP and Tiles Definition or put-attribute tags : " + str(nb_notfound)) self.global_nb_links = self.global_nb_links + nb_links + nb_links2 + nb_links3
def handle_Steps(self, application): nb_links = 0 nb_links2 = 0 for springBatchStep in application.objects().has_type( 'SpringBatchStep' ).load_property('SpringBatchStep.step_tasklet').load_property( 'SpringBatchStep.step_next').load_property( 'SpringBatchStep.step_tasklet_chunk').load_property( 'SpringBatchStep.step_tasklet_transaction_manager'): #logging.info(" Spring Batch Step : [" + str(springBatchStep_name) + "]") springBatchStep_tasklet = springBatchStep.get_property( 'SpringBatchStep.step_tasklet') #logging.info("== Spring Batch Tasklet = [" + str(springBatchStep_tasklet) + "]") if not springBatchStep_tasklet is None: if springBatchStep_tasklet in self.beans: target_bean = self.beans[str(springBatchStep_tasklet)] #logging.info("== Target bean = [" + str(target_bean) + "]") create_link('callLink', springBatchStep, target_bean) #logging.debug("Creating link between " + str(springBatchStep) + " and " + str(target_bean)) nb_links += 1 else: logging.info(" Tasklet ref : bean not found = [" + str(springBatchStep_tasklet) + "]") springBatchStep_tasklet_transaction_manager = springBatchStep.get_property( 'SpringBatchStep.step_tasklet_transaction_manager') if not springBatchStep_tasklet_transaction_manager is None: logging.info("== Spring Batch Tasklet Transaction-manager= [" + str(springBatchStep_tasklet_transaction_manager) + "]") if springBatchStep_tasklet_transaction_manager in self.beans: target_bean = self.beans[str( springBatchStep_tasklet_transaction_manager)] logging.info("== Target bean = [" + str(target_bean) + "]") create_link('callLink', springBatchStep, target_bean) logging.debug("Creating link between " + str(springBatchStep) + " and " + str(target_bean)) nb_links += 1 else: logging.info( " Tasklet transaction-manager : bean not found = [" + str(springBatchStep_tasklet) + "]") springBatchStep_next = springBatchStep.get_property( 'SpringBatchStep.step_next') #logging.info("== Spring Batch Next = [" + str(springBatchStep_next) + "]") if not springBatchStep_next is None: next_split = springBatchStep_next.split('#') for springBatchStep_next_split in next_split: if springBatchStep_next_split in self.springBatchStep: target_step = self.springBatchStep[str( springBatchStep_next_split)] #logging.info("== Target step = [" + str(target_step) + "]") create_link('callLink', springBatchStep, target_step) #logging.debug("Creating link between " + str(springBatchStep) + " and " + str(target_step)) nb_links2 += 1 else: if springBatchStep_next_split != "": logging.info(" Next : step not found = [" + str(springBatchStep_next_split) + "]") springBatchStep_chunk = springBatchStep.get_property( 'SpringBatchStep.step_tasklet_chunk') if not springBatchStep_chunk is None: logging.info("== Spring Batch Next = [" + str(springBatchStep_chunk) + "]") chunk_split = springBatchStep_chunk.split('#') for springBatchStep_chunk_split in chunk_split: if not springBatchStep_chunk_split == "": if springBatchStep_chunk_split in self.beans: target_bean = self.beans[str( springBatchStep_chunk_split)] logging.info("== Target bean = [" + str(target_bean) + "]") create_link('callLink', springBatchStep, target_bean) logging.debug("Creating link between " + str(springBatchStep) + " and " + str(target_bean)) nb_links += 1 else: logging.info(" Chunk : bean not found = [" + str(springBatchStep_next_split) + "]") logging.debug( "Nb of links created between Spring Batch Step and Beans : " + str(nb_links)) logging.debug( "Nb of links created between Spring Batch Step and other Spring Batch Step : " + str(nb_links2)) self.global_nb_links += nb_links self.global_nb_links += nb_links2
def create_iBatisLink(application, namedQuery, prop, classname, constructorObject): if constructorObject.get_fullname() == '%s.%s' % (namedQuery.get_property(prop), classname): logging.debug('iBatis structural link from %s to %s' % (namedQuery.get_name(), constructorObject.get_fullname())) link = create_link('referLink', namedQuery, constructorObject) link.mark_as_not_sure()
def links_through_ActionMapping_SpringMVC(self, application): nb_links = 0 logging.info( "==> Solving the following problem : Missing links between Portlet (JSP) and Java Methods" ) # 1. search all references in all files logging.info( "Scanning Portlets for calls to Java Methods through Annotation ActionMapping (Spring MVC)" ) Java_Methods = {} for Java_Method in application.search_objects(category='JV_METHOD', load_properties=True): #logging.debug("Java Method [" + str(Java_Method) + "]") for Annotation in Java_Method.get_property( "CAST_Java_AnnotationMetrics.Annotation"): if str(Annotation).startswith("@ActionMapping"): #logging.debug("Java Method get Property Annotation StartsWith[" + Annotation + "]") if '"' in str(Annotation): Target = str(Annotation).split("\"")[1] #logging.debug("Java Method [" + str(Java_Method) + "] Target[" + Target + "]") Java_Methods[Target] = Java_Method # 2. scan each JSP file # we search a pattern portlet_and_method_access = ReferenceFinder() #portlet_and_method_access.add_pattern("ActionMapping", before="", element="<portlet:actionURL name=\"[a-zA-Z0-9_-]+", after="") portlet_and_method_access.add_pattern("ActionMapping", before="<portlet:actionURL", element="[A-Za-z0-9\=_\-\" ]+", after="") links = [] for o in application.get_files(['CAST_Web_File']): # check if file is analyzed source code, or if it generated (Unknown) if not o.get_path(): continue for reference in portlet_and_method_access.find_references_in_file( o): #logging.debug("Reference " + reference.value) # manipulate the reference pattern found if not 'name=\"' in reference.value: continue searched_java_method_name = reference.value.split("\"")[1] #logging.debug("searching " + searched_java_method_name) try: Java_Method = Java_Methods[searched_java_method_name] links.append(('callLink', reference.object, Java_Method, reference.bookmark)) except: pass # 3. Create the links for link in links: logging.debug("Creating link between " + str(link[1]) + " and " + str(link[2])) create_link(*link) nb_links = nb_links + 1 logging.debug("Nb of links created " + str(nb_links)) self.global_nb_links = self.global_nb_links + nb_links
def end_application(self, application): #print('Yo') qwe = 0 variables = application.objects().has_type( "CAST_DotNet_MethodCSharp") #get all the variables # # # t = 0 for link in application.links().has_callee(variables).load_positions(): # print(link.get_caller().get_name()) try: code = link.get_code(3) # #print("test11") # print(link.get_caller().get_name()) # print(code) # print() sql, b = testifsql(code) # print(sql) if (sql == "nothing"): continue try: c, a = b.split("=") b = c except: pass # print("test1 = ",b) objettemp = b.split("\\\"") #split at /" # #print(link.get_caller().get_name()+ " : type SELECT") objet = [""] * len(objettemp) t = 0 motsinterdits = { " FROM ", ".", ", ", "\");", "\");\n", " ", " WHERE ", " ORDER BY ", "(", ") FROM ", "" } for x in range(len(objettemp)): # #print("objettemp[x] =" + objettemp[x] , end = " ") h = 0 for y in motsinterdits: if (objettemp[x] == y): h = 1 if (h == 0): # objet[t] = objettemp[x] t += 1 # print(objet) for obj in objet: for f in application.objects(): # #print("name =" + f.get_name() + "<=>" + objet[t] + "!") if (f.get_name() == obj and f.get_type() == "SQLScriptTable"): # print(f.get_name()+ " " +f.get_type()) try: # #print("getting positions") positions = str( link.get_caller().get_positions()) #print(positions) pos = "" for i in range(len(positions) - 2): pos += positions[i + 1] #print("testa") arr = pos.split(",") file = arr[0].split("(") #print("testb") line = int(arr[2]) + 2 for ds in application.objects(): if (ds.get_name() == file[2]): #print("file found") asd = ds hg = 0 tes = 0 if (sql == "select"): code = code.split("{")[1] # print("done") for lo in range(len(code)): # try: # print(str(hg)+" "+obj[hg]+" "+str(lo)+" "+code[lo]) # except: # print("fail:", sys.exc_info()[0]) if (hg < len(obj)): if (code[lo] == obj[hg]): hg += 1 continue else: hg = 0 else: tes = 1 column = lo - len(obj) break except: print("Unexpected error:", sys.exc_info()[0]) #print("test1") print("creating a link from" + link.get_caller().get_name() + " to " + f.get_name()) bookmark = Bookmark(asd, line, column, line, column + len(obj)) #print("test1") print("type : ", end="") if (sql == "insert"): create_link("useInsertLink", link.get_caller(), f, bookmark) print("insert") if (sql == "insert into"): create_link("useInsertLink", link.get_caller(), f, bookmark) print("insert into") #print("test2") if (sql == "select"): create_link("useSelectLink", link.get_caller(), f, bookmark) print("select") if (sql == "update"): create_link("useUpdateLink", link.get_caller(), f, bookmark) print("update") #print("test3") if (sql == "select count"): create_link("useSelectLink", link.get_caller(), f, bookmark) print("select") qwe = 1 if (qwe == 1): qwe = 0 break except: print("Unexpected error 2:", sys.exc_info()[0]) t += 1
def links_through_RequestMapping_SpringMVC(self, application): nb_links = 0 logging.info( "==> Solving the following problem : Missing links between Java Methods and Portlet (JSP) response " ) # 1. search all references in all files logging.info( "Scanning Java Methods for calls to Portlet through Annotation RequestMapping (Spring MVC)" ) Java_Methods = {} Request_Mappings = {} # annotation RequestMapping request_mapping = next( application.get_objects_by_name(name="RequestMapping", external=True)) #logging.debug("Annotation request Mapping [" + str(request_mapping) + "]") # all method with a link to annotation for link in application.links().has_callee([ request_mapping ]).has_caller(application.objects().is_executable()).load_positions(): JSPRedirection = False #logging.debug("caller (Method calling the RequestMapping Annotation) [" + str(link.get_caller()) + "]") Java_Methods = application.search_objects( name=link.get_caller().get_name(), load_properties=True) for Java_Method in Java_Methods: #logging.debug("Java Method =[" + str(Java_Method) + "]") for Annotation in Java_Method.get_property( "CAST_Java_AnnotationMetrics.Annotation"): if str(Annotation).startswith( "@RequestMapping(params=\"action="): AnnotationAction = str(Annotation).split( "\"")[1].split("=")[1] #logging.debug("Annotation Action =[" + AnnotationAction +"]") # caller code : code = link.get_caller().get_positions()[0].get_code() #logging.debug(code) #Search in code the following #return \"[A-Za-z0-9_-]+\" #JSP with same name can be part of different packages main_package = link.get_caller().get_fullname().split(".")[4] #logging.debug("Main package [" + main_package + "] + caller name = [" + link.get_caller().get_fullname() + "]") # Return all words beginning with character 'a', as an iterator yielding match objects it = re.finditer("return \"[A-Za-z0-9_\-\/]+\"", code) for match in it: #logging.debug("match = [" + format(match.group()) + "]") if "/" in format(match.group()): redirectJSP = format( match.group()).split("/")[1].split("\"")[0] + ".jsp" if "/" not in format(match.group()): redirectJSP = format(match.group()).split("\"")[1] + ".jsp" #logging.debug("Redirect JSP [" + redirectJSP + "]") redirectJSP_iter = application.get_objects_by_name( name=redirectJSP) for redirectJSP_object in redirectJSP_iter: #logging.debug("Redirect JSP [" + redirectJSP + "] + [" + str(redirectJSP_object) + "]") #logging.debug("Redirect JSP full name[" + redirectJSP_object.get_fullname() + "]") if main_package in redirectJSP_object.get_fullname(): #logging.debug("Main package found for JSP [" + main_package +"]") Request_Mappings[ str(main_package + AnnotationAction)] = redirectJSP_object JSPRedirection = True if JSPRedirection == False: #logging.debug(code) pass # 2. scan each Java method # we search a pattern request_mapping_access = ReferenceFinder() request_mapping_access.add_pattern( "RequestMapping", before="", element= "response\.setRenderParameter\(\"action\",[ ]+\"[a-zA-Z0-9_-]+", after="") links = [] for o in application.get_files(['JV_FILE']): # check if file is analyzed source code, or if it generated (Unknown) if not o.get_path(): continue for reference in request_mapping_access.find_references_in_file(o): #logging.debug("Reference " + reference.value) # manipulate the reference pattern found searched_request_mapping = reference.value.split("\"")[3] #logging.debug("searching searched_request_mapping [" + searched_request_mapping + "]") searched_package = o.get_path().split("\\src\\")[1].split( "\\")[0] #logging.debug("o.get_path() [" + o.get_path() + "]") #logging.debug("searched package [" + searched_package + "]") try: JSP_Redirect = Request_Mappings[str( searched_package + searched_request_mapping)] links.append(('callLink', reference.object, JSP_Redirect, reference.bookmark)) pass except: pass # 3. Create the links for link in links: logging.debug("Creating link between " + str(link[1]) + " and " + str(link[2])) create_link(*link) nb_links = nb_links + 1 logging.debug("Nb of links created " + str(nb_links)) self.global_nb_links = self.global_nb_links + nb_links