use of org.apache.maven.artifact.resolver.ArtifactResolver in project che by eclipse.
the class MavenServerImpl method reset.
@Override
public void reset() throws RemoteException {
terminalLogger.setTerminal(null);
mavenProgressNotifier = null;
ArtifactResolver artifactResolver = getMavenComponent(ArtifactResolver.class);
if (artifactResolver instanceof CheArtifactResolver) {
((CheArtifactResolver) artifactResolver).reset();
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolver in project intellij-community by JetBrains.
the class Maven3ServerEmbedder method addMvn2CompatResults.
protected void addMvn2CompatResults(MavenProject project, List<Exception> exceptions, List<ResolutionListener> listeners, ArtifactRepository localRepository, Collection<MavenExecutionResult> executionResults) {
ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
resolutionRequest.setArtifactDependencies(project.getDependencyArtifacts());
resolutionRequest.setArtifact(project.getArtifact());
resolutionRequest.setManagedVersionMap(project.getManagedVersionMap());
resolutionRequest.setLocalRepository(localRepository);
resolutionRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
resolutionRequest.setListeners(listeners);
resolutionRequest.setResolveRoot(false);
resolutionRequest.setResolveTransitively(true);
ArtifactResolver resolver = getComponent(ArtifactResolver.class);
ArtifactResolutionResult result = resolver.resolve(resolutionRequest);
project.setArtifacts(result.getArtifacts());
executionResults.add(new MavenExecutionResult(project, exceptions));
}
use of org.apache.maven.artifact.resolver.ArtifactResolver in project semantic-versioning by jeluard.
the class AbstractEnforcerRule method execute.
@Override
public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException {
final MavenProject project = getMavenProject(helper);
if (shouldSkipRuleExecution(project)) {
helper.getLog().debug("Skipping non " + AbstractEnforcerRule.JAR_ARTIFACT_TYPE + " or " + BUNDLE_ARTIFACT_TYPE + " artifact.");
return;
}
final Artifact previousArtifact;
final Artifact currentArtifact = validateArtifact(project.getArtifact());
final Version current = Version.parse(currentArtifact.getVersion());
try {
final ArtifactRepository localRepository = (ArtifactRepository) helper.evaluate("${localRepository}");
final String version;
if (this.previousVersion != null) {
version = this.previousVersion;
helper.getLog().info("Version specified as <" + version + ">");
} else {
final ArtifactMetadataSource artifactMetadataSource = (ArtifactMetadataSource) helper.getComponent(ArtifactMetadataSource.class);
final List<ArtifactVersion> availableVersions = getAvailableReleasedVersions(artifactMetadataSource, project, localRepository);
final List<ArtifactVersion> availablePreviousVersions = filterNonPreviousVersions(availableVersions, current);
if (availablePreviousVersions.isEmpty()) {
helper.getLog().warn("No previously released version. Backward compatibility check not performed.");
return;
}
version = availablePreviousVersions.iterator().next().toString();
helper.getLog().info("Version deduced as <" + version + "> (among all availables: " + availablePreviousVersions + ")");
}
final ArtifactFactory artifactFactory = (ArtifactFactory) helper.getComponent(ArtifactFactory.class);
previousArtifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), version, null, project.getArtifact().getType());
final ArtifactResolver resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class);
resolver.resolve(previousArtifact, project.getRemoteArtifactRepositories(), localRepository);
validateArtifact(previousArtifact);
} catch (Exception e) {
helper.getLog().warn("Exception while accessing artifacts; skipping check.", e);
return;
}
final Version previous = Version.parse(previousArtifact.getVersion());
final File previousJar = previousArtifact.getFile();
final File currentJar = currentArtifact.getFile();
compareJars(helper, previous, previousJar, current, currentJar);
}
use of org.apache.maven.artifact.resolver.ArtifactResolver in project che by eclipse.
the class MavenServerImpl method internalResolveProject.
private MavenResult internalResolveProject(File pom, List<String> activeProfiles, List<String> inactiveProfiles, List<ResolutionListener> dependencyTreeResolutionListeners) {
MavenExecutionRequest request = newMavenRequest(pom, activeProfiles, inactiveProfiles, Collections.emptyList());
request.setUpdateSnapshots(updateSnapshots);
AtomicReference<MavenResult> reference = new AtomicReference<>();
runMavenRequest(request, () -> {
try {
ProjectBuilder builder = getMavenComponent(ProjectBuilder.class);
List<ProjectBuildingResult> resultList = builder.build(Collections.singletonList(pom), false, request.getProjectBuildingRequest());
ProjectBuildingResult result = resultList.get(0);
MavenProject mavenProject = result.getProject();
RepositorySystemSession repositorySession = getMavenComponent(LegacySupport.class).getRepositorySession();
if (repositorySession instanceof DefaultRepositorySystemSession) {
((DefaultRepositorySystemSession) repositorySession).setTransferListener(new ArtifactTransferListener(mavenProgressNotifier));
if (workspaceCache != null) {
((DefaultRepositorySystemSession) repositorySession).setWorkspaceReader(new MavenWorkspaceReader(workspaceCache));
}
}
List<Exception> exceptions = new ArrayList<>();
loadExtensions(mavenProject, exceptions);
mavenProject.setDependencyArtifacts(mavenProject.createArtifacts(getMavenComponent(ArtifactFactory.class), null, null));
ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
resolutionRequest.setArtifact(mavenProject.getArtifact());
resolutionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories());
resolutionRequest.setArtifactDependencies(mavenProject.getDependencyArtifacts());
resolutionRequest.setListeners(dependencyTreeResolutionListeners);
resolutionRequest.setLocalRepository(localRepo);
resolutionRequest.setManagedVersionMap(mavenProject.getManagedVersionMap());
resolutionRequest.setResolveTransitively(true);
resolutionRequest.setResolveRoot(false);
ArtifactResolver resolver = getMavenComponent(ArtifactResolver.class);
ArtifactResolutionResult resolve = resolver.resolve(resolutionRequest);
mavenProject.setArtifacts(resolve.getArtifacts());
reference.set(new MavenResult(mavenProject, exceptions));
} catch (Exception e) {
reference.set(new MavenResult(null, null, Collections.singletonList(e)));
}
});
return reference.get();
}
use of org.apache.maven.artifact.resolver.ArtifactResolver in project che by eclipse.
the class MavenServerImpl method setComponents.
@Override
public void setComponents(MavenWorkspaceCache cache, boolean failOnUnresolvedDependency, MavenTerminal mavenTerminal, MavenServerProgressNotifier notifier, boolean alwaysUpdateSnapshot) throws RemoteException {
container.addComponent(getMavenComponent(ArtifactResolver.class, "che"), ArtifactResolver.ROLE);
ArtifactResolver artifactResolver = getMavenComponent(ArtifactResolver.class);
if (artifactResolver instanceof CheArtifactResolver) {
((CheArtifactResolver) artifactResolver).setWorkspaceCache(cache, failOnUnresolvedDependency);
}
buildDate = new Date();
workspaceCache = cache;
updateSnapshots = updateSnapshots || alwaysUpdateSnapshot;
terminalLogger.setTerminal(mavenTerminal);
mavenProgressNotifier = new MavenServerProgressNotifierImpl(notifier);
}
Aggregations