private void buildDependencyTree( Queue<DependencyNode> nodeQueue, boolean full, boolean online, Session session, Map<String, Profile> profiles, PomFileLoader loader, Log log )
		{
			int neededLevels = full ? -1 : 1;
			while( !nodeQueue.isEmpty() )
			{
				DependencyNode node = nodeQueue.poll();
				if( neededLevels >= 0 && node.getLevel() >= neededLevels )
					continue;
				node.collectDependencyManagement( profiles, session.projects(), log );
				Map<DependencyKey, RawDependency> localDependencies = getHierarchicalDependencies( session, node.getProject(), null, online, profiles, log );
				if( localDependencies == null )
					continue;
				for( Entry<DependencyKey, RawDependency> e : localDependencies.entrySet() )
				{
					DependencyKey dependencyKey = e.getKey();
					RawDependency dependency = e.getValue();
					if( dependency.isOptional() && !node.isRoot() )
						continue;
					GroupArtifact ga = new GroupArtifact( dependencyKey.getGroupId(), dependencyKey.getArtifactId() );
					if( isGroupArtifactExcluded( node, ga ) )
						continue;
					DependencyNode existingNode = node.searchNodeForGroupArtifact( ga );
					if( existingNode != null )
					{
						if( existingNode.getLevel() <= node.getLevel() + 1 )
							continue;
						else
							existingNode.removeFromParent();
					}
					final Optional<VersionScope> optionalVs = getVersionScopeFromDependencyManagement( node, dependencyKey, dependency );
					final VersionScope vs;
					if(optionalVs.isPresent() )
					{
						vs = optionalVs.get();
					}
					else
					{
						vs = dependency.getVs();
						if( node.isRoot() )
						{
							if(vs.getScope() == null) {
								vs.setScope( Scope.COMPILE );
							}
						}
						else
						{
							Scope scope = Scope.getScopeTransformation( node.getVs().getScope(), dependency.getVs().getScope() );
							if(scope == null )
								continue;
							vs.setScope( scope );
						}
					}
					Scope scope = vs.getScope();
					assert scope != null;
					assert vs.getVersion() != null : "null version of dependency " + dependencyKey + " -> " + dependency + " (for project " + project + ")";
					if( scope == Scope.IMPORT || scope == Scope.SYSTEM )
						continue;
					// get remote repositories
					List<Repository> additionalRepos = getProjectRepositories( session, node.getProject(), log );
					Gav dependencyGav = new Gav( dependencyKey.getGroupId(), dependencyKey.getArtifactId(), vs.getVersion() );
					Project childProject = null;
					if( neededLevels < 0 || node.getLevel() >= neededLevels )
					{
						childProject = session.projects().forGav( dependencyGav );
						if( childProject == null )
						{
							File pomFile = loader.loadPomFileForGav( dependencyGav, additionalRepos, log );
							if( pomFile == null )
							{
								log.html( Tools.errorMessage( "cannot fetch project " + dependencyGav + " referenced in " + node.getProject() ) );
								continue;
							}
							PomAnalysis analysis = new PomAnalysis( session, loader, null, false, log );
							analysis.addFile( pomFile );
							Set<Project> loadedProjects = analysis.loadProjects();
							if( loadedProjects.size() != 1 )
							{
								log.html( Tools.errorMessage( "cannot fetch project " + dependencyGav + " referenced in " + node.getProject() ) );
								continue;
							}
							childProject = loadedProjects.iterator().next();
							analysis.completeLoadedProjects();
							analysis.addCompletedProjectsToSession();
							Set<Project> addedToGraph = analysis.addCompletedProjectsToGraph();
							if( !addedToGraph.contains( childProject ) )
							{
								log.html( Tools.errorMessage( "cannot fetch project " + dependencyGav + " referenced in " + node.getProject() ) );
								continue;
							}
						}
						if( childProject == null )
						{
							// TODO : use specified repositories if needed !
							log.html( Tools.warningMessage( "cannot fetch project " + dependencyGav + " referenced in " + node.getProject() + (dependency.isOptional() ? " (this is an optional dependency)" : "") ) );
							continue;
						}
					}
					DependencyNode child = new DependencyNode( childProject, dependencyKey, vs );
					child.addExclusions( dependency.getExclusions() );
					node.addChild( child );
					DependencyManagement dm = node.getLocalManagement( dependencyKey );
					if( dm != null )
						child.addExclusions( dm.getExclusions() );
					//FIXME is always false
					if( scope == Scope.SYSTEM )
						continue;
					// TODO it seems to me that transitive dependency policy only
					// applies to jar artifacts, is that true ??
					// if( "jar".equals( dependencyKey.getType() ) )
					nodeQueue.add( child );
				}
			}
		}
private void buildDependencyTree( Queue<DependencyNode> nodeQueue, boolean full, boolean online, Session session, Map<String, Profile> profiles, PomFileLoader loader, Log log )
		{
			int neededLevels = full ? -1 : 1;
			while( !nodeQueue.isEmpty() )
			{
				DependencyNode node = nodeQueue.poll();
				if( neededLevels >= 0 && node.getLevel() >= neededLevels )
					continue;
				node.collectDependencyManagement( profiles, session.projects(), log );
				Map<DependencyKey, RawDependency> localDependencies = getHierarchicalDependencies( session, node.getProject(), null, online, profiles, log );
				if( localDependencies == null )
					continue;
				for( Entry<DependencyKey, RawDependency> e : localDependencies.entrySet() )
				{
					DependencyKey dependencyKey = e.getKey();
					RawDependency dependency = e.getValue();
					if( dependency.isOptional() && !node.isRoot() )
						continue;
					GroupArtifact ga = new GroupArtifact( dependencyKey.getGroupId(), dependencyKey.getArtifactId() );
					if( isGroupArtifactExcluded( node, ga ) )
						continue;
					DependencyNode existingNode = node.searchNodeForGroupArtifact( ga );
					if( existingNode != null )
					{
						if( existingNode.getLevel() <= node.getLevel() + 1 )
							continue;
						else
							existingNode.removeFromParent();
					}
					final Optional<VersionScope> optionalVs = getVersionScopeFromDependencyManagement( node, dependencyKey, dependency );
					final VersionScope vs;
					if(optionalVs.isPresent() )
					{
						vs = optionalVs.get();
					}
					else
					{
						vs = dependency.getVs();
						if( node.isRoot() )
						{
							if(vs.getScope() == null) {
								vs.setScope( Scope.COMPILE );
							}
						}
						else
						{
							Scope scope = Scope.getScopeTransformation( node.getVs().getScope(), dependency.getVs().getScope() );
							if(scope == null )
								continue;
							vs.setScope( scope );
						}
					}
					Scope scope = vs.getScope();
					assert scope != null;
					assert vs.getVersion() != null : "null version of dependency " + dependencyKey + " -> " + dependency + " (for project " + project + ")";
					if( scope == Scope.IMPORT || scope == Scope.SYSTEM )
						continue;
				
					List<Repository> additionalRepos = getProjectRepositories( session, node.getProject(), log );
					Gav dependencyGav = new Gav( dependencyKey.getGroupId(), dependencyKey.getArtifactId(), vs.getVersion() );
					Project childProject = null;
					if( neededLevels < 0 || node.getLevel() >= neededLevels )
					{
						childProject = session.projects().forGav( dependencyGav );
						if( childProject == null )
						{
							File pomFile = loader.loadPomFileForGav( dependencyGav, additionalRepos, log );
							if( pomFile == null )
							{
								log.html( Tools.errorMessage( "cannot fetch project " + dependencyGav + " referenced in " + node.getProject() ) );
								continue;
							}
							PomAnalysis analysis = new PomAnalysis( session, loader, null, false, log );
							analysis.addFile( pomFile );
							Set<Project> loadedProjects = analysis.loadProjects();
							if( loadedProjects.size() != 1 )
							{
								log.html( Tools.errorMessage( "cannot fetch project " + dependencyGav + " referenced in " + node.getProject() ) );
								continue;
							}
							childProject = loadedProjects.iterator().next();
							analysis.completeLoadedProjects();
							analysis.addCompletedProjectsToSession();
							Set<Project> addedToGraph = analysis.addCompletedProjectsToGraph();
							if( !addedToGraph.contains( childProject ) )
							{
								log.html( Tools.errorMessage( "cannot fetch project " + dependencyGav + " referenced in " + node.getProject() ) );
								continue;
							}
						}
						if( childProject == null )
						{
						
							log.html( Tools.warningMessage( "cannot fetch project " + dependencyGav + " referenced in " + node.getProject() + (dependency.isOptional() ? " (this is an optional dependency)" : "") ) );
							continue;
						}
					}
					DependencyNode child = new DependencyNode( childProject, dependencyKey, vs );
					child.addExclusions( dependency.getExclusions() );
					node.addChild( child );
					DependencyManagement dm = node.getLocalManagement( dependencyKey );
					if( dm != null )
						child.addExclusions( dm.getExclusions() );
				
					if( scope == Scope.SYSTEM )
						continue;
				
				
				
					nodeQueue.add( child );
				}
			}
		}
private void builddependencytree( queue<dependencynode> nodequeue, boolean full, boolean online, session session, map<string, profile> profiles, pomfileloader loader, log log ) { int neededlevels = full ? -1 : 1; while( !nodequeue.isempty() ) { dependencynode node = nodequeue.poll(); if( neededlevels >= 0 && node.getlevel() >= neededlevels ) continue; node.collectdependencymanagement( profiles, session.projects(), log ); map<dependencykey, rawdependency> localdependencies = gethierarchicaldependencies( session, node.getproject(), null, online, profiles, log ); if( localdependencies == null ) continue; for( entry<dependencykey, rawdependency> e : localdependencies.entryset() ) { dependencykey dependencykey = e.getkey(); rawdependency dependency = e.getvalue(); if( dependency.isoptional() && !node.isroot() ) continue; groupartifact ga = new groupartifact( dependencykey.getgroupid(), dependencykey.getartifactid() ); if( isgroupartifactexcluded( node, ga ) ) continue; dependencynode existingnode = node.searchnodeforgroupartifact( ga ); if( existingnode != null ) { if( existingnode.getlevel() <= node.getlevel() + 1 ) continue; else existingnode.removefromparent(); } final optional<versionscope> optionalvs = getversionscopefromdependencymanagement( node, dependencykey, dependency ); final versionscope vs; if(optionalvs.ispresent() ) { vs = optionalvs.get(); } else { vs = dependency.getvs(); if( node.isroot() ) { if(vs.getscope() == null) { vs.setscope( scope.compile ); } } else { scope scope = scope.getscopetransformation( node.getvs().getscope(), dependency.getvs().getscope() ); if(scope == null ) continue; vs.setscope( scope ); } } scope scope = vs.getscope(); assert scope != null; assert vs.getversion() != null : "null version of dependency " + dependencykey + " -> " + dependency + " (for project " + project + ")"; if( scope == scope.import || scope == scope.system ) continue; list<repository> additionalrepos = getprojectrepositories( session, node.getproject(), log ); gav dependencygav = new gav( dependencykey.getgroupid(), dependencykey.getartifactid(), vs.getversion() ); project childproject = null; if( neededlevels < 0 || node.getlevel() >= neededlevels ) { childproject = session.projects().forgav( dependencygav ); if( childproject == null ) { file pomfile = loader.loadpomfileforgav( dependencygav, additionalrepos, log ); if( pomfile == null ) { log.html( tools.errormessage( "cannot fetch project " + dependencygav + " referenced in " + node.getproject() ) ); continue; } pomanalysis analysis = new pomanalysis( session, loader, null, false, log ); analysis.addfile( pomfile ); set<project> loadedprojects = analysis.loadprojects(); if( loadedprojects.size() != 1 ) { log.html( tools.errormessage( "cannot fetch project " + dependencygav + " referenced in " + node.getproject() ) ); continue; } childproject = loadedprojects.iterator().next(); analysis.completeloadedprojects(); analysis.addcompletedprojectstosession(); set<project> addedtograph = analysis.addcompletedprojectstograph(); if( !addedtograph.contains( childproject ) ) { log.html( tools.errormessage( "cannot fetch project " + dependencygav + " referenced in " + node.getproject() ) ); continue; } } if( childproject == null ) { log.html( tools.warningmessage( "cannot fetch project " + dependencygav + " referenced in " + node.getproject() + (dependency.isoptional() ? " (this is an optional dependency)" : "") ) ); continue; } } dependencynode child = new dependencynode( childproject, dependencykey, vs ); child.addexclusions( dependency.getexclusions() ); node.addchild( child ); dependencymanagement dm = node.getlocalmanagement( dependencykey ); if( dm != null ) child.addexclusions( dm.getexclusions() ); if( scope == scope.system ) continue; nodequeue.add( child ); } } }