<s> from pypomvisualiser . pom . PomTreeNode import PomTreeNode <EOL> from pypomvisualiser . exceptions . PyPomExceptions import PomParseError <EOL> from enum import Enum <EOL> import logging <EOL> class NodeEnum ( Enum ) : <EOL> EXTDEP = "<STR_LIT>" <EOL> USERPOM = "<STR_LIT>" <EOL> ROOTPOM = "<STR_LIT>" <EOL> class TreeCreation ( object ) : <EOL> def __init__ ( self , listOfPoms ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> self . rootNode = None <EOL> self . nodeList = [ ] <EOL> self . resolveTreeStructure ( listOfPoms ) <EOL> def resolveTreeStructure ( self , listOfPoms ) : <EOL> for pom in listOfPoms : <EOL> print ( pom . getFileLocation ( ) ) <EOL> pomArt = pom . getArtifactId ( ) <EOL> pomGrp = pom . getGroupId ( ) <EOL> '''<STR_LIT>''' <EOL> tmpnode = self . getNodeWith ( pomArt , pomGrp ) <EOL> if tmpnode == None : <EOL> tmpnode = PomTreeNode ( pomArt , pomGrp , NodeEnum . USERPOM , pom ) <EOL> self . nodeList . append ( tmpnode ) <EOL> if tmpnode . getData ( ) == None : <EOL> tmpnode . setData ( pom ) <EOL> '''<STR_LIT>''' <EOL> '''<STR_LIT>''' <EOL> if pom . getParentPom ( ) : <EOL> parPom = pom . getParentPom ( ) <EOL> if ( pomArt == parPom . getArtifactId ) and ( pomGrp == parPom . getGroupId ) : <EOL> pass <EOL> else : <EOL> par = self . inNodeList ( self . nodeList , PomTreeNode ( parPom . getArtifactId ( ) , parPom . getGroupId ( ) , NodeEnum . USERPOM , None ) ) <EOL> tmpnode . setParentNode ( par ) <EOL> par . addChildNodes ( tmpnode ) <EOL> '''<STR_LIT>''' <EOL> for dep in pom . getDependencies ( ) : <EOL> notfound = True <EOL> for inner in listOfPoms : <EOL> if ( inner . getGroupId ( ) == dep . getGroupId ( ) ) and ( inner . getArtifactId ( ) == dep . getArtifactId ( ) ) : <EOL> '''<STR_LIT>''' <EOL> foundNode = self . inNodeList ( self . nodeList , PomTreeNode ( inner . getArtifactId ( ) , inner . getGroupId ( ) , NodeEnum . USERPOM , None ) ) <EOL> tmpnode . addDependencyNode ( foundNode ) <EOL> foundNode . addReverseDependencyNode ( tmpnode ) <EOL> notfound = False <EOL> break <EOL> if notfound is True : <EOL> depNode = self . inNodeList ( self . nodeList , PomTreeNode ( dep . getArtifactId ( ) , dep . getGroupId ( ) , NodeEnum . EXTDEP , dep ) ) <EOL> tmpnode . addDependencyNode ( depNode ) <EOL> depNode . addReverseDependencyNode ( tmpnode ) <EOL> '''<STR_LIT>''' <EOL> self . resolveRootNode ( ) <EOL> def getNodeWith ( self , artId , grpId ) : <EOL> for temporaryNode in self . nodeList : <EOL> if ( temporaryNode . getGroupId ( ) == grpId ) and ( temporaryNode . getArtifactId ( ) == artId ) : <EOL> return temporaryNode <EOL> def inNodeList ( self , nodeList , nodeToFind ) : <EOL> assert type ( nodeToFind ) is PomTreeNode <EOL> for node in nodeList : <EOL> if ( node . getGroupId ( ) == nodeToFind . getGroupId ( ) ) and ( node . getArtifactId ( ) == nodeToFind . getArtifactId ( ) ) : <EOL> self . nodeList . append ( node ) <EOL> return node <EOL> self . nodeList . append ( nodeToFind ) <EOL> return nodeToFind <EOL> def resolveRootNode ( self ) : <EOL> length = len ( self . nodeList ) <EOL> if length > <NUM_LIT:0> : <EOL> activeNode = None <EOL> for node in self . nodeList : <EOL> assert type ( node ) is PomTreeNode <EOL> if activeNode != None : <EOL> act = self . resolveNodeRelations ( node ) <EOL> if act != activeNode : <EOL> logging . error ( "<STR_LIT>" ) <EOL> raise PomParseError ( "<STR_LIT>" ) <EOL> else : <EOL> activeNode = self . resolveNodeRelations ( node ) <EOL> else : <EOL> raise PomParseError ( "<STR_LIT>" ) <EOL> def resolveNodeRelations ( self , potentialRootNode ) : <EOL> parent = potentialRootNode . getParent ( ) <EOL> if parent != None and parent != potentialRootNode : <EOL> print ( parent . getArtifactId ( ) ) <EOL> self . resolveNodeRelations ( parent ) <EOL> elif potentialRootNode . getReverseDependencyNodes ( ) : <EOL> print ( "<STR_LIT>" ) <EOL> '''<STR_LIT>''' <EOL> else : <EOL> self . rootNode = potentialRootNode <EOL> logging . info ( "<STR_LIT>" + potentialRootNode . getArtifactId ( ) + "<STR_LIT:U+0020>" + potentialRootNode . getGroupId ( ) ) <EOL> self . rootNode . setType ( NodeEnum . ROOTPOM ) <EOL> '''<STR_LIT>''' <EOL> def getRootNode ( self ) : <EOL> return self . rootNode </s>
