Exemplo n.º 1
0
 def testSimple(self):
     '''
     Tests the verticles order in:
     
     c --> a --> b --> d
     '''
     
     dag = DAG()
     a = dag.addVertex("a")
     b = dag.addVertex("b")
     c = dag.addVertex("c")
     d = dag.addVertex("d")
     
     dag.addEdge(c, a)
     dag.addEdge(a, b)
     dag.addEdge(b, d)
     dag.addEdge(c, d)
     
     rs = tsort(dag)
     
     self.assertTrue(rs.index("c") < rs.index("a"))
     self.assertTrue(rs.index("a") < rs.index("b"))
     self.assertTrue(rs.index("b") < rs.index("d"))
     self.assertTrue(rs.index("c") < rs.index("d"))
Exemplo n.º 2
0
    def loadProjects(self):
        for pomFile in  self.pomFiles:
            element = parse(pomFile).documentElement
            project = self.createProjectOfElement(element)
            
            project.pomFile = pomFile
            project.projectPath = os.path.dirname(pomFile)
            
            repository = self.repositoryPath
            repository = os.path.join(repository, project.groupId.replace(".", os.path.sep), project.artifactId, project.version)
            repository = os.path.abspath(repository)
            
            project.repositoryPath = repository
            project.repositoryPom = os.path.join(repository, project.artifactId + "-" + project.version + ".pom")
            
            if project.pid() in self.projects:
                raise DuplicateProjectDetected([pomFile, self.projects[project.pid()].pomFile], project.pid())
            
            packaging = self.nodeValue(self.xmlChildByTagName(element, 'packaging'))
            
            if "pom" == packaging:
                project.set_isParent(True)
            
            self.projects[project.pid()] = project
                
        for pid in self.projects:
            project = self.projects[pid]
            element = project.get_element()
            dependencies = self.xmlChildByTagName(element, 'dependencies')
            project.parent = self.parentOf(project)
            
            if dependencies:
                for dependency in dependencies.childNodes:
                    if dependency.nodeType != dependency.ELEMENT_NODE:
                        continue
                    
                    dependencyProject = self.createProjectOfElement(dependency, project)
                    
                    if dependencyProject:
                        dependencyId = dependencyProject.pid()
                        
                        if dependencyId in self.projects:
                            dependencyProject = self.projects[dependencyId]
                            project.addDependency(dependencyProject)
                            
        if self.logEnabled:
            logger.info("The Dependence Tree is:")
            logger.info("")
        
        
        i = 0
        
        for pid in self.projects:
            i = i + 1
            
            if self.logEnabled:
                logger.info(("%4s" % "") + " " + str(i) + ". " + pid)
            
            pVertex = self.dag.addVertex(pid)
            
            for d in self.projects[pid].get_dependencies():
                if self.logEnabled:
                    logger.info(("%6s" % "") + ("%4s" % "") + "- " + d.pid())
                
                dVertex = self.dag.addVertex(d.pid())
                self.dag.addEdge(dVertex, pVertex)
        
        self.ordenedProjects = OrderedDict()
        
        reactorOrder = tsort(self.dag)
        
        if self.logEnabled:
            logger.info("")
            logger.info("The Reactor Order is:")
            logger.info("")
        
        i = 1
        
        for pid in reactorOrder:
            project = self.projects[pid]
            
            self.ordenedProjects[pid] = project
            
            if self.logEnabled:
                logger.info("%6s" % str(i) + ". " + pid)
                
            i = i + 1

        if self.logEnabled:
            logger.info("")