use of org.apache.maven.model.building.ModelProblem in project intellij-community by JetBrains.
the class Maven3ServerEmbedderImpl method doResolveProject.
@NotNull
public Collection<MavenExecutionResult> doResolveProject(@NotNull final Collection<File> files, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles, final List<ResolutionListener> listeners) throws RemoteException {
final File file = files.size() == 1 ? files.iterator().next() : null;
final MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
request.setUpdateSnapshots(myAlwaysUpdateSnapshots);
final Collection<MavenExecutionResult> executionResults = ContainerUtil.newArrayList();
executeWithMavenSession(request, new Runnable() {
@Override
public void run() {
try {
RepositorySystemSession repositorySession = getComponent(LegacySupport.class).getRepositorySession();
if (repositorySession instanceof DefaultRepositorySystemSession) {
DefaultRepositorySystemSession session = (DefaultRepositorySystemSession) repositorySession;
session.setTransferListener(new TransferListenerAdapter(myCurrentIndicator));
if (myWorkspaceMap != null) {
session.setWorkspaceReader(new Maven3WorkspaceReader(myWorkspaceMap));
}
session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true);
session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
}
List<ProjectBuildingResult> buildingResults = getProjectBuildingResults(request, files);
for (ProjectBuildingResult buildingResult : buildingResults) {
MavenProject project = buildingResult.getProject();
if (project == null) {
List<Exception> exceptions = new ArrayList<Exception>();
for (ModelProblem problem : buildingResult.getProblems()) {
exceptions.add(problem.getException());
}
MavenExecutionResult mavenExecutionResult = new MavenExecutionResult(buildingResult.getPomFile(), exceptions);
executionResults.add(mavenExecutionResult);
continue;
}
List<Exception> exceptions = new ArrayList<Exception>();
loadExtensions(project, exceptions);
//Artifact projectArtifact = project.getArtifact();
//Map managedVersions = project.getManagedVersionMap();
//ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
project.setDependencyArtifacts(project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING) {
addMvn2CompatResults(project, exceptions, listeners, myLocalRepository, executionResults);
} else {
final DependencyResolutionResult dependencyResolutionResult = resolveDependencies(project, repositorySession);
final List<Dependency> dependencies = dependencyResolutionResult.getDependencies();
final Map<Dependency, Artifact> winnerDependencyMap = new IdentityHashMap<Dependency, Artifact>();
Set<Artifact> artifacts = new LinkedHashSet<Artifact>(dependencies.size());
dependencyResolutionResult.getDependencyGraph().accept(new TreeDependencyVisitor(new DependencyVisitor() {
@Override
public boolean visitEnter(org.eclipse.aether.graph.DependencyNode node) {
final Object winner = node.getData().get(ConflictResolver.NODE_DATA_WINNER);
final Dependency dependency = node.getDependency();
if (dependency != null && winner == null) {
Artifact winnerArtifact = Maven3AetherModelConverter.toArtifact(dependency);
winnerDependencyMap.put(dependency, winnerArtifact);
}
return true;
}
@Override
public boolean visitLeave(org.eclipse.aether.graph.DependencyNode node) {
return true;
}
}));
for (Dependency dependency : dependencies) {
final Artifact artifact = winnerDependencyMap.get(dependency);
if (artifact != null) {
artifacts.add(artifact);
resolveAsModule(artifact);
}
}
project.setArtifacts(artifacts);
executionResults.add(new MavenExecutionResult(project, dependencyResolutionResult, exceptions));
}
}
} catch (Exception e) {
executionResults.add(handleException(e));
}
}
});
return executionResults;
}
use of org.apache.maven.model.building.ModelProblem in project intellij-community by JetBrains.
the class Maven30ServerEmbedderImpl method doResolveProject.
@NotNull
public Collection<MavenExecutionResult> doResolveProject(@NotNull final Collection<File> files, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles, final List<ResolutionListener> listeners) throws RemoteException {
final File file = files.size() == 1 ? files.iterator().next() : null;
final MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
request.setUpdateSnapshots(myAlwaysUpdateSnapshots);
final Collection<MavenExecutionResult> executionResults = ContainerUtil.newArrayList();
executeWithMavenSession(request, new Runnable() {
@Override
public void run() {
try {
RepositorySystemSession repositorySession = getComponent(LegacySupport.class).getRepositorySession();
if (repositorySession instanceof DefaultRepositorySystemSession) {
((DefaultRepositorySystemSession) repositorySession).setTransferListener(new Maven30TransferListenerAdapter(myCurrentIndicator));
if (myWorkspaceMap != null) {
((DefaultRepositorySystemSession) repositorySession).setWorkspaceReader(new Maven30WorkspaceReader(myWorkspaceMap));
}
}
List<ProjectBuildingResult> buildingResults = getProjectBuildingResults(request, files);
for (ProjectBuildingResult buildingResult : buildingResults) {
MavenProject project = buildingResult.getProject();
if (project == null) {
List<Exception> exceptions = new ArrayList<Exception>();
for (ModelProblem problem : buildingResult.getProblems()) {
exceptions.add(problem.getException());
}
MavenExecutionResult mavenExecutionResult = new MavenExecutionResult(buildingResult.getPomFile(), exceptions);
executionResults.add(mavenExecutionResult);
continue;
}
List<Exception> exceptions = new ArrayList<Exception>();
loadExtensions(project, exceptions);
//Artifact projectArtifact = project.getArtifact();
//Map managedVersions = project.getManagedVersionMap();
//ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
project.setDependencyArtifacts(project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING) {
addMvn2CompatResults(project, exceptions, listeners, myLocalRepository, executionResults);
} else {
final DependencyResolutionResult dependencyResolutionResult = resolveDependencies(project, repositorySession);
final List<Dependency> dependencies = dependencyResolutionResult.getDependencies();
Set<Artifact> artifacts = new LinkedHashSet<Artifact>(dependencies.size());
for (Dependency dependency : dependencies) {
final Artifact artifact = RepositoryUtils.toArtifact(dependency.getArtifact());
artifact.setScope(dependency.getScope());
artifact.setOptional(dependency.isOptional());
artifacts.add(artifact);
resolveAsModule(artifact);
}
project.setArtifacts(artifacts);
executionResults.add(new MavenExecutionResult(project, dependencyResolutionResult, exceptions));
}
}
} catch (Exception e) {
executionResults.add(handleException(e));
}
}
});
return executionResults;
}
Aggregations