示例#1
0
    def analyseXMLTilesFile(self, xmlfilepath, file):     
        
        cast.analysers.log.info('Scanning XML Tiles files for reference to JSP or JSPX : ' + xmlfilepath)

        tree = ET.parse(xmlfilepath)
        root = tree.getroot()         
    
        for definition in root.iter('definition'):
            cast.analysers.log.info('Reading the XML file : definition node')        # return a dictionary containing the elements 
            definition_name = definition.attrib.get("name")
            cast.analysers.log.info('Definition Name : ' + definition_name)
            definition_extends = definition.attrib.get("extends") 
            cast.analysers.log.info('Definition extends : ' + str(definition_extends))
            definition_template = definition.attrib.get("template") 
            cast.analysers.log.info('Definition template : ' + str(definition_template))
            
            if not (str(definition_template)).endswith('.jsp') and not (str(definition_template)).endswith('.jspx'): 
                logging.info('==> Skip this definition as it is not a jsp or jspx file')
                definition_template = ''
            
            if not definition_name in self.apacheTilesDefinition: 
                objectDefinition = cast.analysers.CustomObject()
                objectDefinition.set_name(definition_name)
                objectDefinition.set_type('TilesDefinition')
                objectDefinition.set_parent(file)
                objectDefinition.save()
                self.NbApacheTilesTilesDefinitionCreated += 1         
                bookmark = Bookmark(file, 1, 1, -1, -1) # TODO : find exact position 
                objectDefinition.save_position(bookmark)
                objectDefinition.save_property('TilesDefinition.definition_extends', str(definition_extends))
                objectDefinition.save_property('TilesDefinition.definition_template', str(definition_template))
                self.apacheTilesDefinition[definition_name] = objectDefinition 
            else: 
                cast.analysers.log.info('==== Definition [' + definition_name + '] already defined in the file ' + xmlfilepath) 
            
            for attribute in definition.iter('put-attribute'):
                cast.analysers.log.info('==== Reading the XML file : put-attribute node')        # return a dictionary containing the elements 
                put_attribute_name = attribute.attrib.get("name")
                cast.analysers.log.info('==== put_attribute Name : ' + put_attribute_name)
                put_attribute_value = attribute.attrib.get("value") 
                cast.analysers.log.info('==== put_attribute Value : ' + str(put_attribute_value))

                if not str(definition_name + "." + put_attribute_name) in self.apacheTilesPutAttribute: # to manage duplicate definition in xml files
                    objectPut_Attribute = cast.analysers.CustomObject()
                    objectPut_Attribute.set_name(put_attribute_name)
                    objectPut_Attribute.set_type('TilesAttribute')
                    objectPut_Attribute.set_parent(self.apacheTilesDefinition[definition_name])
                    objectPut_Attribute.save()
                    self.NbApacheTilesPutAttributeCreated +=1                 
                    bookmark = Bookmark(file, 1, 1, -1, -1) # TODO : find exact position 
                    objectPut_Attribute.save_position(bookmark)
                    objectPut_Attribute.save_property('TilesAttribute.put_attribute_value', str(put_attribute_value))
                    self.apacheTilesPutAttribute[str(definition_name + "." + put_attribute_name)] = attribute
                else: 
                    cast.analysers.log.info('==== put_attribute Value [' + put_attribute_name + '] already defined for the TilesDef [' + definition_name + ']')  
    def start_file(self, file):
        Print.info("Start f!"+str(file))
        contentList = []
        fList=[]
        # self.file = file
        # self.filename = "D:/CASTTOOL/RuleDevelopment/Tibco/com.castsoftware.uc.tibco/com.castsoftware.uc.tibco/TibcoTest/TibcoSample/AdapterQueueStarter.process";
        self.filename = file.get_path();
        self.file = file;
        Print.info("###############printing file name############")
        Print.info("FileName--" + str(self.filename))
        file_ref = open(self.filename, encoding='UTF_8')
        # contentList=[];
        for i in file_ref:
            contentList.append(str(i));
        Print.info("contentList >> "+ str(contentList))
        fList=contentList
        '''
        for i in file_ref:
            fList.append(str(i).strip().lower())
            '''
        Print.info("Flist >> " + str(fList))
        Tibco_Process = CustomObject();
        self.saveObject(Tibco_Process, str(self.filename), self.filename + str(self.filename), "Tibco_Process",
                        self.file,
                        self.filename + "Tibco_Process")
        Tibco_Process.save();

        # Tibco_Process.save_position(Bookmark(self.file, indexOfClass + 1, 1, indexOfClass + 1, -1));
        Print.info("object saved" + self.filename)
        Print.info(str(fList))
        for line in range(0, len(fList)):
            if ("<pd:conditiontype" in fList[line]):
                # print(fList[line])
                if any(s in fList[line] for s in CondType_Rule):
                    Print.info("valid condition type>>" + fList[line] + " Line #" + str(line + 1))
                else:
                    Print.info("invalid condition type>>" + fList[line] + " Line #" + str(line + 1))
            if ("<pd:transition" in fList[line]):
                Print.info(fList[line])
                Act_invalid=self.masterdata()
                Print.info("Act_invalid >> "+str(Act_invalid))
                if any(s in fList[line + 1] for s in Act_invalid):
                    Print.info("activity type cannot be migrated>>" + fList[line + 1] + " Line #"+ str(line + 1))
                    Tibco_Process.save_position(Bookmark(self.file, line + 1, 1, line + 1, -1));
                    Tibco_Process.save_violation("Tibco_CustomMetrics.Activitycannotbemigrated",
                                                 Bookmark(file, 1, 1, -1, -1), additional_bookmarks=None)

                    Print.info('Tibco  Violation  Saved for demo')
                else:
                    Print.info("activity type can be migrated>>"+ fList[line + 1] + " Line #" + str(line + 1))
                    Tibco_Process.save_position(Bookmark(self.file, line + 1, 1, line + 1, -1));
                    Tibco_Process.save_violation("Tibco_CustomMetrics.Activitycannotbemigrated",
                                                 Bookmark(file, 1, 1, -1, -1), additional_bookmarks=None)
                    Print.info('Tibco  Violation  Saved for demo')
        pass
示例#3
0
    def tagBookmark(self, file, file_data, tag):
        flag = 0
        flag_unclose = 0
        count = 0
        #CAST.debug(tag)
        self.bookmarks = []
        self.stack_line = []
        self.stack_column = []
        for line in file_data:
            count = count + 1
            match_reference = re.search('<(.+?):' + tag, line)
            if not "</" in line and match_reference or "<" + tag in line:
                #CAST.debug(str(match_reference))
                if tag + ">" in line:
                    flag_unclose = 1
                self.start_line_no = count
                self.start_column_no = line.find("<") + 1
                self.stack_line.append(self.start_line_no)
                self.stack_column.append(self.start_column_no)
                flag = 1
            elif flag == 1:
                self.end_line_no = count
            match_reference_end = re.search('</(.+?):' + tag, line)
            if match_reference_end or "</" + tag in line:
                #CAST.debug(str(count))
                self.end_line_no = count
                self.end_column_no = line.find("</") + 1
                flag = -1
            elif flag_unclose == 1 and "/>" in line:
                self.end_line_no = count
                self.end_column_no = line.find("/>") + 1
                flag_unclose = 0
                flag = -1
            if flag == -1:
                if self.stack_line:
                    self.start_line_no = self.stack_line.pop()
                else:
                    self.start_line_no = self.end_line_no
                if self.stack_column:
                    self.start_column_no = self.stack_column.pop()
                else:
                    self.start_column_no = self.end_column_no

                bookmark = Bookmark(file, self.start_line_no,
                                    self.start_column_no, self.end_line_no,
                                    self.end_column_no)
                self.bookmarks.append(bookmark)
                #CAST.debug(str(bookmark))
                self.start_line_no = 0
                self.start_column_no = 0
                self.end_line_no = 0
                self.end_column_no = 0
                flag = 0
        return self.bookmarks
        pass
示例#4
0
    def save(self, file):
        """
        Save the symbol
        """
        self.kb_symbol = CustomObject()
        self.kb_symbol.set_name(self.name)
        self.kb_symbol.set_type(self.type)
 
        self.kb_symbol.set_parent(self.parent.kb_symbol if self.parent else file)
        self.kb_symbol.save()
        
        self.kb_symbol.save_position(Bookmark(file, *self.position))
示例#5
0
    def start_file(self, file):
        filename = file.get_path()
        #X.debug(filename)

        if filename.endswith('.xml'):
            tree = ET.parse(filename)
            root = tree.getroot()
            count = 0
            for k in list(root.iter()):
                data1 = re.sub('{.*?}', '', str(k.tag))
                if data1 == "from":
                    try:
                        X.debug(k.attrib['uri'])
                        fromObj = CustomObject()
                        self.saveObject(
                            fromObj, data1 + "." + k.attrib['uri'],
                            filename + '.' + data1, "Sender", file,
                            filename + "." + data1 + '.' + str(count))
                        count = count + 1
                        fromObj.save_position(Bookmark(file, 1, 1, -1, -1))
                        fromRef[fromObj] = [fromObj, k.attrib['uri']]
                    except (RuntimeError, TypeError, NameError):
                        pass
                elif data1 == "to":
                    try:
                        X.debug(k.attrib['uri'])
                        toObj = CustomObject()
                        self.saveObject(
                            toObj, data1 + "." + k.attrib['uri'],
                            filename + '.' + data1, "Receiver", file,
                            filename + "." + data1 + '.' + str(count))
                        count = count + 1
                        toObj.save_position(Bookmark(file, 1, 1, -1, -1))
                        toRef[toObj] = [toObj, k.attrib['uri']]
                    except (RuntimeError, TypeError, NameError):
                        pass
        elif filename.endswith('.java'):
            X.debug("")
示例#6
0
    def end_analysis(self):
        X.debug("****************")
        for fromObjs, fromURIs in fromRef.items():
            for toObjs, toURIs in toRef.items():
                if (toURIs[1] == fromURIs[1]):
                    X.debug("&&&&&&&&&")
                    create_link('callLink', fromObjs, toObjs,
                                Bookmark(toObjs.parent, 1, 1, -1, -1))
                    X.debug("__________")

            #X.debug(str(keys))
            #X.debug(str(values[1]))

        pass
 def BpelQrImplementation(self, file, bpel_process, bpel_data, file_data):
     if self.QrOnPartnerlinkName(bpel_data['partnerLink']):
         CAST.debug("Violation on Property id 1187062....")
         bpel_process.save_violation("File_Data.patnerlink_name_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnPartnerlinkRole(bpel_data['partnerLink']):
         CAST.debug("Violation on Property id 1187071....")
         bpel_process.save_violation("File_Data.patnerlink_role_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnVariableName(bpel_data['variable']):
         CAST.debug("Violation on Property id 1187061....")
         bpel_process.save_violation("File_Data.variable_name_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnVariableNamingChecker(bpel_data['variable']):
         CAST.debug("Violation on Property id 1187067....")
         bpel_process.save_violation("File_Data.variable_name_constraints",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnVariableType(bpel_data['variable']):
         CAST.debug("Violation on Property id 1187068....")
         bpel_process.save_violation("File_Data.variable_type_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnEventhanlderConflict(file_data):
         CAST.debug("Violation on Property id 1187063 &1187075....")
         bpel_process.save_violation("File_Data.eventhandler_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
         bpel_process.save_violation("File_Data.Eventhandler_constraints",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnReplyConflict(file_data):
         CAST.debug("Violation on Property id 1187064....")
         bpel_process.save_violation("File_Data.forreply_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnCorrelationsetConflict(bpel_data["correlationSet"]):
         CAST.debug("Violation on Property id 1187065....")
         bpel_process.save_violation("File_Data.correlationset_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnFromToConflict(bpel_data):
         CAST.debug("Violation on Property id 1187066....")
         bpel_process.save_violation("File_Data.from_to_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnFaultHandlerConflict(file_data):
         CAST.debug("Violation on Property id 1187069....")
         bpel_process.save_violation("File_Data.faulthandler_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnCompensateConflict(file_data):
         CAST.debug("Violation on Property id 1187070....")
         bpel_process.save_violation("File_Data.compensate_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnFlowConflict(bpel_data["link"]):
         CAST.debug("Violation on Property id 1187072....")
         bpel_process.save_violation("File_Data.flow_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnFaulthandlerConstrainst(file_data):
         CAST.debug("Violation on Property id 1187073....")
         bpel_process.save_violation("File_Data.faulthandler_constraints",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     if self.QrOnEventConflict(bpel_data["onEvent"]):
         CAST.debug("Violation on Property id 1187074....")
         bpel_process.save_violation("File_Data.onevent_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
     '''
     if self.QrOnEventhanlderConflict(file_data):
         CAST.debug("Violation on Property id 1187075....")
         bpel_process.save_violation("File_Data.Eventhandler_constraints",Bookmark(file,1,1,-1,-1),additional_bookmarks=None)
     '''
     if self.QrOnOperationNameConflict(bpel_data["invoke"]):
         CAST.debug("Violation on Property id 1187076....")
         bpel_process.save_violation("File_Data.operation_name_conflict",
                                     Bookmark(file, 1, 1, -1, -1),
                                     additional_bookmarks=None)
示例#8
0
 def checkOnmessage(self, bpel_invoke, operation_type, namespace_port,
                    onmessage_count):
     flag_link = 0
     for reference in bpel_onmessage_data:
         for data in bpel_onmessage_data[reference]:
             onmessage_data = str(data)
             onmessage_data = re.sub('(\[)|(\])|(\')|(\s+)', '',
                                     onmessage_data)
             onmessage_port_type = ""
             onmessage_operation_type = ""
             onmessage_namespace_port = ""
             process_data = ""
             for ele in list(onmessage_data.split(',')):
                 if "portType:" in ele:
                     onmessage_port_type = ele[ele.find(':') + 1:]
                 elif "operation:" in ele:
                     onmessage_operation_type = ele[ele.find(':') + 1:]
             if ':' in onmessage_port_type:
                 onmessage_namespace_port = onmessage_port_type[:
                                                                onmessage_port_type
                                                                .find(':') +
                                                                1]
             process_data = str(bpel_process_data[reference])
             process_data = re.sub('(\[)|(\])|(\')|(\s+)', '', process_data)
             process_data = process_data.replace('xmlns:map:', '')
             for ele in list(process_data.split(',')):
                 if onmessage_namespace_port in ele:
                     onmessage_namespace_port = ele[ele.find(':') + 1:]
                     onmessage_namespace_port = onmessage_namespace_port + onmessage_port_type[
                         onmessage_port_type.find(':') + 1:]
                     break
             if operation_type == onmessage_operation_type and namespace_port == onmessage_namespace_port:
                 if reference in wsdl_obj_reference:
                     #CAST.debug(onmessage_operation_type)
                     file_name = wsdl_obj_reference[
                         reference].parent.get_path()
                     wsdl_operation = CustomObject()
                     onmessage_count = onmessage_count + 1
                     self.saveObject(
                         wsdl_operation, onmessage_operation_type,
                         file_name + onmessage_operation_type,
                         "WSDL_Operation",
                         wsdl_obj_reference[reference].parent, file_name +
                         "WSDL_Operation" + str(onmessage_count))
                     wsdl_operation.save()
                     wsdl_operation.save_position(
                         Bookmark(reference.parent, 1, 1, -1, -1))
                     create_link('callLink', bpel_invoke, wsdl_operation,
                                 Bookmark(reference.parent, 1, 1, -1, -1))
                     create_link('callLink', wsdl_operation,
                                 wsdl_obj_reference[reference],
                                 Bookmark(reference.parent, 1, 1, -1, -1))
                     flag_link = 1
                     break
                 else:
                     pass
             else:
                 pass
         if flag_link == 1:
             break
     return onmessage_count
     pass
示例#9
0
 def start_file(self, file):
     self.filename = file.get_path()
     CAST.debug(self.filename)
     file_ref = open(self.filename, 'r')
     file_data = []
     for child in file_ref:
         child = child.replace("\n", "")
         file_data.append(child)
     parser = CastOperation()
     if self.filename.endswith(".wsdl"):
         try:
             index = self.filename.rfind('\\')
             self.name = self.filename[index + 1:]
         except:
             index = -1
         wsdl_process = CustomObject()
         self.saveObject(wsdl_process, self.name, self.filename,
                         "WSDL_Process", file,
                         self.filename + "WSDL_Process")
         wsdl_process.save()
         wsdl_process.save_position(Bookmark(file, 1, 1, -1, -1))
         wsdl_file_data[wsdl_process] = parser.castParserWsdl(self.filename)
         #CAST.debug(self.name)
     else:
         self.invokeList = parser.getInvokeJavaCode(self.filename)
         for child in self.invokeList:
             self.intermediate_file.write(str(child) + '\n')
         bpel_data = parser.castParserBpel(file, self.filename)
         #CAST.debug(str(bpel_data["link"]))
         for child in bpel_data:
             #attrib_data = re.sub('(\[)|(\])|(\')','',str(bpel_file_data[child]))
             if "process" in child and not "bookmark" in child:
                 for subchild in bpel_data[child]:
                     if "name" in subchild:
                         self.name = subchild[subchild.find(':') + 1:]
                         break
         bpel_process = CustomObject()
         self.saveObject(bpel_process, self.name, self.filename,
                         "BPEL_Process", file,
                         self.filename + "BPEL_Process")
         bpel_process.save()
         if bpel_data["process.bookmark"]:
             bpel_process.save_position(bpel_data["process.bookmark"][0])
         else:
             bpel_process.save_position(Bookmark(file, 1, 1, -1, -1))
         bpel_process_data[bpel_process] = bpel_data["process"]
         bpel_bookmark_data[
             str(bpel_process) +
             "invoke.bookmark"] = bpel_data["invoke.bookmark"]
         bpel_invoke_data[bpel_process] = bpel_data["invoke"]
         bpel_bookmark_data[
             str(bpel_process) +
             "receive.bookmark"] = bpel_data["receive.bookmark"]
         bpel_receive_data[bpel_process] = bpel_data["receive"]
         bpel_bookmark_data[
             str(bpel_process) +
             "onMessage.bookmark"] = bpel_data["onMessage.bookmark"]
         bpel_onmessage_data[bpel_process] = bpel_data["onMessage"]
         self.file_loc_data = parser.fileLoc(self.filename)
         self.file_checksum_data = parser.fileChecksum(self.filename)
         qr_reference = QualityRule()
         qr_reference.BpelQrImplementation(file, bpel_process, bpel_data,
                                           file_data)
         pass
示例#10
0
    def end_analysis(self):
        for child in bpel_process_data:
            bpel_target_name = ""
            bpel_name = ""
            for ele in bpel_process_data[child]:
                if "targetNamespace:" in ele:
                    bpel_target_name = ele[ele.find(':') + 1:]
                elif "name:" in ele:
                    bpel_name = ele[ele.find(':') + 1:]

            for ele in wsdl_file_data:
                wsdl_target_name = ""
                wsdl_name = ""
                for subele in wsdl_file_data[ele]["definitions"]:
                    if "targetNamespace:" in subele:
                        wsdl_target_name = subele[subele.find(':') + 1:]
                    elif "name:" in subele:
                        wsdl_name = subele[subele.find(':') + 1:]
                #CAST.debug(wsdl_name)
                if wsdl_target_name == bpel_target_name:
                    create_link('callLink', ele, child,
                                Bookmark(child.parent, 1, 1, -1, -1))
                    wsdl_obj_reference[child] = ele
                elif wsdl_name == bpel_name and len(wsdl_name) != 0 and len(
                        bpel_name) != 0:
                    #CAST.debug(bpel_name+wsdl_name)
                    create_link('callLink', ele, child,
                                Bookmark(child.parent, 1, 1, -1, -1))
                    wsdl_obj_reference[child] = ele
        invoke_count = 0
        operation_count = 0
        onmessage_count = 0
        for child in bpel_invoke_data:
            invoke_index = 0
            for ele in bpel_invoke_data[child]:
                port_type = ""
                operation_type = ""
                namespace_port = ""
                invoke_name = "null"
                patnerlink_name = ""
                ele_data = str(ele)
                ele_data = re.sub('(\[)|(\])|(\')|(\s+)', '', ele_data)
                bpel_invoke_list = []
                bpel_invoke_list = ele_data.split(',')
                for subele in bpel_invoke_list:
                    if 'portType:' in subele:
                        port_type = subele[subele.find(':') + 1:]
                    elif 'operation:' in subele:
                        operation_type = subele[subele.find(':') + 1:]
                    elif 'name:' in subele:
                        invoke_name = subele[subele.find(':') + 1:]
                    elif 'partnerLink:' in subele:
                        patnerlink_name = subele[subele.find(':') + 1:]
                filename = child.parent.get_path()
                invoke_fullname = ''
                if invoke_name == "null":
                    invoke_name = patnerlink_name
                    invoke_fullname = filename + '--null'
                else:
                    invoke_fullname = filename + '--' + invoke_name

                bpel_invoke = CustomObject()
                invoke_count = invoke_count + 1
                self.saveObject(bpel_invoke, invoke_name, invoke_fullname,
                                "BPEL_Invoke", child.parent,
                                filename + "BPEL_Invoke" + str(invoke_count))
                bpel_invoke.save()
                try:
                    bpel_invoke.save_position(
                        bpel_bookmark_data[str(child) +
                                           "invoke.bookmark"][invoke_index])
                except:
                    bpel_invoke.save_position(
                        Bookmark(child.parent, 1, 1, -1, -1))
                invoke_index = invoke_index + 1
                create_link('callLink', child, bpel_invoke,
                            Bookmark(child.parent, 1, 1, -1, -1))
                if not ("null" in port_type and "null" in operation_type):
                    if ':' in port_type:
                        namespace_port = port_type[:port_type.find(':') + 1]
                    ele_data = str(bpel_process_data[child])
                    ele_data = re.sub('(\[)|(\])|(\')|(\s+)', '', ele_data)
                    ele_data = ele_data.replace('xmlns:map:', '')
                    #CAST.debug(ele_data)
                    for invoke_data in list(ele_data.split(',')):
                        if namespace_port in invoke_data:
                            namespace_port = invoke_data[invoke_data.
                                                         find(':') + 1:]
                            namespace_port = namespace_port + port_type[
                                port_type.find(':') + 1:]
                            break
                    flag_link = 0
                    '''
                    CAST.debug(ele_data)
                    CAST.debug(operation_type+"--"+namespace_port)
                    CAST.debug('--XD')
                    '''
                    for subele in bpel_receive_data:
                        for bpel_ele in bpel_receive_data[subele]:
                            ele_data = str(bpel_ele)
                            ele_data = re.sub('(\[)|(\])|(\')|(\s+)', '',
                                              ele_data)
                            bpel_receive_list = []
                            bpel_receive_list = ele_data.split(',')
                            receive_port_type = ""
                            receive_operation_type = ""
                            receive_namespace_port = ""
                            for receive_data in bpel_receive_list:
                                if 'portType:' in receive_data:
                                    receive_port_type = receive_data[
                                        receive_data.find(':') + 1:]
                                elif 'operation:' in receive_data:
                                    receive_operation_type = receive_data[
                                        receive_data.find(':') + 1:]
                            if ':' in receive_port_type:
                                receive_namespace_port = receive_port_type[:
                                                                           receive_port_type
                                                                           .
                                                                           find(
                                                                               ':'
                                                                           ) +
                                                                           1]
                            ele_data = str(bpel_process_data[subele])
                            ele_data = re.sub('(\[)|(\])|(\')|(\s+)', '',
                                              ele_data)
                            ele_data = ele_data.replace('xmlns:map:', '')
                            for receive_data in list(ele_data.split(',')):
                                if receive_namespace_port in receive_data:
                                    receive_namespace_port = receive_data[
                                        receive_data.find(':') + 1:]
                                    receive_namespace_port = receive_namespace_port + receive_port_type[
                                        receive_port_type.find(':') + 1:]
                                    break
                            '''
                            for process_data in bpel_process_data[subele].split(','):
                                CAST.debug(str(process_data))
                            '''

                            if namespace_port == receive_namespace_port and operation_type == receive_operation_type:
                                if subele in wsdl_obj_reference:
                                    CAST.debug('Object linking.....')
                                    '''
                                    CAST.debug('XC')
                                    CAST.debug(filename)
                                    CAST.debug(invoke_name)
                                    CAST.debug(receive_namespace_operation+"--"+receive_namespace_port)
                                    '''
                                    file_name = wsdl_obj_reference[
                                        subele].parent.get_path()
                                    wsdl_operation = CustomObject()
                                    operation_count = operation_count + 1
                                    self.saveObject(
                                        wsdl_operation, receive_operation_type,
                                        file_name + receive_operation_type,
                                        "WSDL_Operation",
                                        wsdl_obj_reference[subele].parent,
                                        file_name + "WSDL_Operation" +
                                        str(operation_count))
                                    wsdl_operation.save()
                                    wsdl_operation.save_position(
                                        Bookmark(subele.parent, 1, 1, -1, -1))
                                    create_link(
                                        'callLink', bpel_invoke,
                                        wsdl_operation,
                                        Bookmark(subele.parent, 1, 1, -1, -1))
                                    create_link(
                                        'callLink', wsdl_operation,
                                        wsdl_obj_reference[subele],
                                        Bookmark(subele.parent, 1, 1, -1, -1))
                                    flag_link = 1
                                    break
                                else:
                                    pass
                            else:
                                pass
                        if flag_link == 1:
                            break
                    if flag_link != 1:
                        onmessage_count = self.checkOnmessage(
                            bpel_invoke, operation_type, namespace_port,
                            onmessage_count)
                else:
                    pass
        CAST.debug('End!!')
        '''               
        for child in bpel_file_data:
            for subchild in bpel_file_data[child]:
                CAST.debug(subchild+"->")
                for j in bpel_file_data[child][subchild]:
                    CAST.debug(str(j))           
        #for child in wsdl_file_data:
            #for subchild in wsdl_file_data[child]:
        #    CAST.debug(str(wsdl_file_data[child]))
        '''
        pass
示例#11
0
    def analyseXMLSpringBatchFile(self, xmlfilepath, file):

        cast.analysers.log.info('Scanning XML Spring Batch files ... : ' +
                                xmlfilepath)

        with minidom.parse(xmlfilepath) as doc:
            root = doc.documentElement

            for SpringBatch_job in root.getElementsByTagName('batch:job'):
                job_id = SpringBatch_job.getAttribute('id')
                cast.analysers.log.info('job Id : ' + job_id)

                objectJob = cast.analysers.CustomObject()
                objectJob.set_name(job_id)
                objectJob.set_type('SpringBatchJob')
                objectJob.set_parent(file)
                objectJob.save()
                self.NbSpringBatchJobCreated += 1
                bookmark = Bookmark(file, 1, 1, -1,
                                    -1)  # TODO : find exact position
                objectJob.save_position(bookmark)

                for SpringBatch_step in SpringBatch_job.getElementsByTagName(
                        'batch:step'):
                    step_id = SpringBatch_step.getAttribute('id')
                    cast.analysers.log.info('==== step id : ' + step_id)
                    objectStep = cast.analysers.CustomObject()
                    objectStep.set_name(step_id)
                    objectStep.set_type('SpringBatchStep')
                    objectStep.set_parent(objectJob)
                    objectStep.save()
                    self.NbSpringBatchStepCreated += 1
                    bookmark = Bookmark(file, 1, 1, -1,
                                        -1)  # TODO : find exact position
                    objectStep.save_position(bookmark)

                    tasklet_chunk = ''

                    for SpringBatch_tasklet in SpringBatch_step.getElementsByTagName(
                            'batch:tasklet'):
                        step_tasklet = SpringBatch_tasklet.getAttribute('ref')
                        cast.analysers.log.info('======== tasklet ref : ' +
                                                step_tasklet)
                        step_tasklet_transaction_manager = SpringBatch_tasklet.getAttribute(
                            'transaction-manager')
                        cast.analysers.log.info(
                            '======== tasklet transaction-manager : ' +
                            step_tasklet_transaction_manager)

                        for SpringBatch_tasklet_chunk in SpringBatch_tasklet.getElementsByTagName(
                                'chunk'):
                            step_tasklet_chunk_reader = SpringBatch_tasklet_chunk.getAttribute(
                                'reader')
                            cast.analysers.log.info(
                                '======== tasklet chunk reader : ' +
                                step_tasklet_chunk_reader)
                            tasklet_chunk += step_tasklet_chunk_reader + "#"
                            step_tasklet_chunk_writer = SpringBatch_tasklet_chunk.getAttribute(
                                'writer')
                            cast.analysers.log.info(
                                '======== tasklet chunk writer : ' +
                                step_tasklet_chunk_writer)
                            tasklet_chunk += step_tasklet_chunk_writer + "#"
                            step_tasklet_chunk_processor = SpringBatch_tasklet_chunk.getAttribute(
                                'processor')
                            cast.analysers.log.info(
                                '======== tasklet chunk processor : ' +
                                step_tasklet_chunk_processor)
                            tasklet_chunk += step_tasklet_chunk_processor + "#"
                            cast.analysers.log.info(
                                '======== tasklet chunk : ' + tasklet_chunk)

                        for SpringBatch_tasklet_chunk in SpringBatch_tasklet.getElementsByTagName(
                                'batch:chunk'):
                            step_tasklet_chunk_reader = SpringBatch_tasklet_chunk.getAttribute(
                                'reader')
                            cast.analysers.log.info(
                                '======== tasklet chunk reader : ' +
                                step_tasklet_chunk_reader)
                            tasklet_chunk += step_tasklet_chunk_reader + "#"
                            step_tasklet_chunk_writer = SpringBatch_tasklet_chunk.getAttribute(
                                'writer')
                            cast.analysers.log.info(
                                '======== tasklet chunk writer : ' +
                                step_tasklet_chunk_writer)
                            tasklet_chunk += step_tasklet_chunk_writer + "#"
                            step_tasklet_chunk_processor = SpringBatch_tasklet_chunk.getAttribute(
                                'processor')
                            cast.analysers.log.info(
                                '======== tasklet chunk processor : ' +
                                step_tasklet_chunk_processor)
                            tasklet_chunk += step_tasklet_chunk_processor + "#"
                            cast.analysers.log.info(
                                '======== tasklet chunk : ' + tasklet_chunk)

                    for SpringBatch_tasklet in SpringBatch_step.getElementsByTagName(
                            'tasklet'):
                        step_tasklet = SpringBatch_tasklet.getAttribute('ref')
                        cast.analysers.log.info('======== tasklet ref : ' +
                                                step_tasklet)
                        step_tasklet_transaction_manager = SpringBatch_tasklet.getAttribute(
                            'transaction-manager')
                        cast.analysers.log.info(
                            '======== tasklet transaction-manager : ' +
                            step_tasklet_transaction_manager)

                        for SpringBatch_tasklet_chunk in SpringBatch_tasklet.getElementsByTagName(
                                'chunk'):
                            step_tasklet_chunk_reader = SpringBatch_tasklet_chunk.getAttribute(
                                'reader')
                            cast.analysers.log.info(
                                '======== tasklet chunk reader : ' +
                                step_tasklet_chunk_reader)
                            tasklet_chunk += step_tasklet_chunk_reader + "#"
                            step_tasklet_chunk_writer = SpringBatch_tasklet_chunk.getAttribute(
                                'writer')
                            cast.analysers.log.info(
                                '======== tasklet chunk writer : ' +
                                step_tasklet_chunk_writer)
                            tasklet_chunk += step_tasklet_chunk_writer + "#"
                            step_tasklet_chunk_processor = SpringBatch_tasklet_chunk.getAttribute(
                                'processor')
                            cast.analysers.log.info(
                                '======== tasklet chunk processor : ' +
                                step_tasklet_chunk_processor)
                            tasklet_chunk += step_tasklet_chunk_processor + "#"
                            cast.analysers.log.info(
                                '======== tasklet chunk : ' + tasklet_chunk)

                        for SpringBatch_tasklet_chunk in SpringBatch_tasklet.getElementsByTagName(
                                'batch:chunk'):
                            step_tasklet_chunk_reader = SpringBatch_tasklet_chunk.getAttribute(
                                'reader')
                            cast.analysers.log.info(
                                '======== tasklet chunk reader : ' +
                                step_tasklet_chunk_reader)
                            tasklet_chunk += step_tasklet_chunk_reader + "#"
                            step_tasklet_chunk_writer = SpringBatch_tasklet_chunk.getAttribute(
                                'writer')
                            cast.analysers.log.info(
                                '======== tasklet chunk writer : ' +
                                step_tasklet_chunk_writer)
                            tasklet_chunk += step_tasklet_chunk_writer + "#"
                            step_tasklet_chunk_processor = SpringBatch_tasklet_chunk.getAttribute(
                                'processor')
                            cast.analysers.log.info(
                                '======== tasklet chunk processor : ' +
                                step_tasklet_chunk_processor)
                            tasklet_chunk += step_tasklet_chunk_processor + "#"
                            cast.analysers.log.info(
                                '======== tasklet chunk : ' + tasklet_chunk)

                    objectStep.save_property('SpringBatchStep.step_tasklet',
                                             str(step_tasklet))
                    objectStep.save_property(
                        'SpringBatchStep.step_tasklet_transaction_manager',
                        str(step_tasklet_transaction_manager))
                    objectStep.save_property(
                        'SpringBatchStep.step_tasklet_chunk',
                        str(tasklet_chunk))

                    step_next = ''

                    for SpringBatch_next in SpringBatch_step.getElementsByTagName(
                            'batch:next'):
                        next_to = SpringBatch_next.getAttribute('to')
                        step_next += next_to + "#"
                        cast.analysers.log.info('======== next to : ' +
                                                next_to)

                    objectStep.save_property('SpringBatchStep.step_next',
                                             str(step_next))
示例#12
0
    def start_file(self, file):

        self.filename = file.get_path()
        #CAST.debug("File Name:---- %s" %self.filename)
        file_ref = open(self.filename, encoding='ISO_8859_1')
        #file_ref = open(self.filename,'r')
        file_data = []
        for child in file_ref:
            try:
                child = child.replace("\n", "")
                file_data.append(child)
            except Exception as e:
                import traceback
                e = traceback.format_exc(e)
        parser = CastOperation()
        if self.filename.endswith(".wsdl"):
            try:
                index = self.filename.rfind('\\')
                self.name = self.filename[index + 1:]
            except:
                index = -1
            wsdl_process = CustomObject()
            #CAST.debug("Checking file extension---"+self.name)
            self.saveObject(wsdl_process, self.name, self.filename,
                            "WSDL_Process", file,
                            self.filename + "WSDL_Process")
            wsdl_process.save()
            wsdl_process.save_position(Bookmark(file, 1, 1, -1, -1))
            wsdl_file_data[wsdl_process] = parser.castParserWsdl(self.filename)
            #CAST.debug(str(wsdl_file_data[wsdl_process]))
            #CAST.debug("Check Name-----"+self.filename)
        else:
            #CAST.debug("************************** else")
            #CAST.debug (self.filename)
            self.invokeList = parser.getInvokeJavaCode(self.filename)
            for child in self.invokeList:
                #CAST.debug("Check Java object-------"+str(child))
                self.intermediate_file.write(str(child) + '\n')
            bpel_data = parser.castParserBpel(file, self.filename)
            #CAST.debug(str(bpel_data["link"]))
            for child in bpel_data:
                #CAST.debug("Check BPEL object-------"+str(child))
                #break
                #attrib_data = re.sub('(\[)|(\])|(\')','',str(bpel_file_data[child]))
                #CAST.debug("Atrribute is true-----"+str(attrib_data))
                if "process" in child and not "bookmark" in child:
                    #CAST.debug("Condition is true-----")
                    #CAST.debug(str(bpel_data))
                    #CAST.debug(str(child))
                    #CAST.debug("Condition is true-----"+str(bpel_data))
                    for subchild in bpel_data[child]:
                        #CAST.debug("Condition is true-----"+subchild)
                        if "name" in subchild:
                            self.name = subchild[subchild.find(':') + 1:]
                            #CAST.debug("Checking Name-----"+self.name)
                            break
            bpel_process = CustomObject()
            self.saveObject(bpel_process, self.name, self.filename,
                            "BPEL_Process", file,
                            self.filename + "BPEL_Process")
            bpel_process.save()
            if bpel_data["process.bookmark"]:
                bpel_process.save_position(bpel_data["process.bookmark"][0])
            else:
                bpel_process.save_position(Bookmark(file, 1, 1, -1, -1))
            bpel_process_data[bpel_process] = bpel_data["process"]
            bpel_bookmark_data[
                str(bpel_process) +
                "invoke.bookmark"] = bpel_data["invoke.bookmark"]
            bpel_invoke_data[bpel_process] = bpel_data["invoke"]
            bpel_bookmark_data[
                str(bpel_process) +
                "receive.bookmark"] = bpel_data["receive.bookmark"]
            bpel_receive_data[bpel_process] = bpel_data["receive"]
            bpel_bookmark_data[
                str(bpel_process) +
                "onMessage.bookmark"] = bpel_data["onMessage.bookmark"]
            bpel_onmessage_data[bpel_process] = bpel_data["onMessage"]

            #//Creating new object
            #bpel_bookmark_data[str(bpel_process)+"partnerLink.bookmark"] = bpel_data["partnerLink.bookmark"]
            #bpel_PartnerLink_data[bpel_process] = bpel_data["partnerLink"]
            '''
            bpel_bookmark_data[str(bpel_process)+"assign.bookmark"] = bpel_data["assign.bookmark"]
            bpel_assign_data[bpel_process] = bpel_data["assign"]
            bpel_bookmark_data[str(bpel_process)+"catch.bookmark"] = bpel_data["catch.bookmark"]
            bpel_catch_data[bpel_process] = bpel_data["catch"]
            bpel_bookmark_data[str(bpel_process)+"catchAll.bookmark"] = bpel_data["catchAll.bookmark"]
            bpel_catchAll_data[bpel_process] = bpel_data["catchAll"]
            bpel_bookmark_data[str(bpel_process)+"sequence.bookmark"] = bpel_data["sequence.bookmark"]
            bpel_sequence_data[bpel_process] = bpel_data["sequence"]
            bpel_bookmark_data[str(bpel_process)+"switch.bookmark"] = bpel_data["switch.bookmark"]
            bpel_switch_data[bpel_process] = bpel_data["switch"]
            bpel_bookmark_data[str(bpel_process)+"case.bookmark"] = bpel_data["case.bookmark"]
            bpel_case_data[bpel_process] = bpel_data["case"]
            bpel_bookmark_data[str(bpel_process)+"extension.bookmark"] = bpel_data["extension.bookmark"]
            bpel_extension_data[bpel_process] = bpel_data["extension"]
            bpel_bookmark_data[str(bpel_process)+"copy.bookmark"] = bpel_data["copy.bookmark"]
            bpel_copy_data[bpel_process] = bpel_data["copy"]
            '''

            self.file_loc_data = parser.fileLoc(self.filename)
            self.file_checksum_data = parser.fileChecksum(self.filename)
            qr_reference = QualityRule()
            qr_reference.BpelQrImplementation(file, bpel_process, bpel_data,
                                              file_data)
            pass
    def test_infinite_loop_correct_me(self):

        java_file = tempfile.NamedTemporaryFile(mode='w+', suffix='.py', delete=False)
        java_file.write("""
public class TopicRecvClient
{
    TopicConnection conn = null;
    TopicSession session = null;
    Topic topic = null;
    

    public void recvSync()
        throws JMSException, NamingException
    {
        System.out.println("Begin recvSync");
        // Setup the pub/sub connection, session
        setupPubSub();

        // Wait upto 5 seconds for the message
        TopicSubscriber recv = session.createSubscriber(topic);
        Message msg = recv.receive(5000);
        if (msg == null) {
            System.out.println("Timed out waiting for msg");
        } else {
            System.out.println("TopicSubscriber.recv, msgt="+msg);
        }
    }
    
}        """)
        java_file.close()
        
        #result = parser(java_file.name)
        result = parser('C:\\Users\\GSO\\eclipse-workspace2\\com.castsoftware.ibmmq\\mqTests\\Tests\\TopicRecvClient.java', [['2Method(org.jboss.book.jms.ex1.TopicRecvClient.recvSync)', 42, 57], ['Method(org.jboss.book.jms.ex1.TopicRecvClient.main)', 67, 77], ['Method(org.jboss.book.jms.ex1.TopicRecvClient.setupPubSub)', 29, 40], ['Method(org.jboss.book.jms.ex1.TopicRecvClient.stop)', 59, 65]],Bookmark('C:\\Users\\GSO\\eclipse-workspace2\\com.castsoftware.ibmmq\\mqTests\\Tests\\TopicRecvClient.java',17,1,79,2) )
        self.assertTrue('recv' in result)
    def test_parse_java(self):
        
        java_file = tempfile.NamedTemporaryFile(mode='w+', suffix='.py', delete=False)
        print(java_file.name)
        #java_file.close()
        #java_file.open("w+")
        java_file.write("""
public class TopicRecvClient
{
    TopicConnection conn = null;
    TopicSession session = null;
    Topic topic = null;
    
    public void setupPubSub()
        throws JMSException, NamingException
    {
        InitialContext iniCtx = new InitialContext();
        Object tmp = iniCtx.lookup("ConnectionFactory");
        TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
        conn = tcf.createTopicConnection();
        topic = (Topic) iniCtx.lookup("topic/testTopic");
        session = conn.createTopicSession(false,
                                          TopicSession.AUTO_ACKNOWLEDGE);
        conn.start();
    }
    
    public void recvSync()
        throws JMSException, NamingException
    {
        System.out.println("Begin recvSync");
        // Setup the pub/sub connection, session
        setupPubSub();

        // Wait upto 5 seconds for the message
        TopicSubscriber recv = session.createSubscriber(topic);
        Message msg = recv.receive(5000);
        if (msg == null) {
            System.out.println("Timed out waiting for msg");
        } else {
            System.out.println("TopicSubscriber.recv, msgt="+msg);
        }
    }
    
}        """)
        java_file.close()
        
        #result = parser(java_file.name)
        result = parser('C:\\Users\\GSO\\eclipse-workspace2\\com.castsoftware.ibmmq\\mqTests\\Tests\\TopicRecvClient.java', [['1Method(org.jboss.book.jms.ex1.TopicRecvClient.recvSync)', 42, 57], ['Method(org.jboss.book.jms.ex1.TopicRecvClient.main)', 67, 77], ['Method(org.jboss.book.jms.ex1.TopicRecvClient.setupPubSub)', 29, 40], ['Method(org.jboss.book.jms.ex1.TopicRecvClient.stop)', 59, 65]],Bookmark('C:\\Users\\GSO\\eclipse-workspace2\\com.castsoftware.ibmmq\\mqTests\\Tests\\TopicRecvClient.java',17,1,79,2) )
        self.assertTrue('recv' in result)
        
        value = result['recv']
        #declaration = value[0]
        declaration_line = value[0]
        declaration_line_Count = value[1]
        
        #variable_assignement = value[4]
        variable_value = value[-1]
        
        self.assertEqual('"topic/testTopic"', variable_value)
示例#15
0
    def start_file(self, file):
        Print.info("Start f!")
        contentList = []
        #self.file = file
        #self.filename = "C:/Users/Angelin.mariya/Desktop/app.module.ts";
        self.filename = file.get_path()
        self.file = file
        #Print.info("###############printing file name############")
        #Print.info("FileName--" + str(self.filename))
        file_ref = open(self.filename, encoding='UTF_8')
        #contentList=[];
        for i in file_ref:
            contentList.append(str(i))

        indexOfClass = self.findIndex(contentList, "[c][l][a][s][s][\s]*.*[{]",
                                      0)
        indexOfFunction = self.findIndex(
            contentList,
            "([v][o][i][d][\s]*|[s][t][r][i][n][g][\s]*|[i][n][t][\s]*).*[(].*[)][\s]+[{]",
            0)
        Print.info(str(indexOfFunction))
        classNameLine = contentList[indexOfClass]
        #className=classNameLine.replace('{',' ');
        className = classNameLine.split("{")
        className = className[0].split(" ")
        classObject = "NA"
        abstractClassObject = "NA"
        functionConnections = []
        if className[0].strip() == "class":
            classObject = className[1]
            finalData["classObject"].append([classObject, indexOfClass])
            Groovy_class = CustomObject()
            self.saveObject(Groovy_class, str(classObject),
                            self.filename + str(classObject), "Groovy_class",
                            self.file, self.filename + "Groovy_class")
            Groovy_class.save()
            Groovy_class.save_position(
                Bookmark(self.file, indexOfClass + 1, 1, indexOfClass + 1, -1))
            functionList, functionConnections = self.getFunctionList(
                contentList,
                "([v][o][i][d][\s]*|[s][t][r][i][n][g][\s]*|[i][n][t][\s]*).*[(].*[)][\s]+[{]"
            )
            for i in functionConnections:
                finalData["functionLink"].append(i)
            for i in functionList:
                Groovy_Function = CustomObject()
                self.saveObject(Groovy_Function, str(i[0]),
                                self.filename + str(i[0]), "Groovy_Function",
                                self.file, self.filename + str(i[0]))
                Groovy_Function.save()
                Groovy_Function.save_position(
                    Bookmark(self.file, i[1], 1, i[1], -1))
                create_link('containLink', Groovy_class, Groovy_Function)
        elif className[0].strip() == "abstract":
            abstractClassObject = className[2]
            finalData["abstractObject"].append(
                [abstractClassObject, indexOfClass])
            Groovy_AbstractClass = CustomObject()
            self.saveObject(Groovy_AbstractClass, str(abstractClassObject),
                            self.filename + str(abstractClassObject),
                            "Groovy_AbstractClass", self.file,
                            self.filename + "Groovy_AbstractClass")
            Groovy_AbstractClass.save()
            Groovy_AbstractClass.save_position(
                Bookmark(self.file, indexOfClass + 1, 1, indexOfClass + 1, -1))
            functionList, functionConnections = self.getFunctionList(
                contentList,
                "([v][o][i][d][\s]*|[s][t][r][i][n][g][\s]*|[i][n][t][\s]*).*[(].*[)][\s]+[{]"
            )
            for i in functionConnections:
                finalData["functionLink"].append(i)
            for i in functionList:
                Groovy_Function = CustomObject()
                self.saveObject(Groovy_Function, str(i[0]),
                                self.filename + str(i[0]), "Groovy_Function",
                                self.file, self.filename + str(i[0]))
                print("groovy object saved")
                Groovy_Function.save()
                Groovy_Function.save_position(
                    Bookmark(self.file, i[1], 1, i[1], -1))
                create_link('containLink', Groovy_AbstractClass,
                            Groovy_Function)
        in1 = self.findIndex(
            contentList,
            "([v][o][i][d][\s]*|[s][t][r][i][n][g][\s]*|[i][n][t][\s]*).*[(].*[)][\s]+[{]",
            0)
        print("sad", in1)
        #print("to",functionList);
        # save violation rule
        Groovy_Function.save_violation(
            "Groovy_CustomMetrics.AssertWithinFinallyBlock",
            Bookmark(file, 1, 1, -1, -1),
            additional_bookmarks=None)

        Print.info('Groovy  Violation  Saved for demo')

        self.validate(file)
        Print.info(str(functionList))
        return contentList