// TODO it seems to me that transitive dependency policy only
// applies to jar artifacts, is that true ??
// if( "jar".equals( dependencyKey.getType() ) )
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 );
				}
			}
		}
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 );
}
}
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 );
}
}
}
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 );
}
}
}