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
Ejemplo n.º 2
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