Search in sources :

Example 1 with ArtifactResolver

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();
    }
}
Also used : ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) CheArtifactResolver(org.eclipse.che.maven.CheArtifactResolver) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver) CheArtifactResolver(org.eclipse.che.maven.CheArtifactResolver)

Example 2 with ArtifactResolver

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));
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) MavenExecutionResult(org.jetbrains.idea.maven.server.embedder.MavenExecutionResult) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver)

Example 3 with ArtifactResolver

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);
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) MavenProject(org.apache.maven.project.MavenProject) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Version(org.semver.Version) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) ArtifactMetadataSource(org.apache.maven.artifact.metadata.ArtifactMetadataSource) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) IOException(java.io.IOException) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException) ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)

Example 4 with ArtifactResolver

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();
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenExecutionException(org.apache.maven.MavenExecutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) CheArtifactResolver(org.eclipse.che.maven.CheArtifactResolver) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver) ProjectBuilder(org.apache.maven.project.ProjectBuilder) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ProjectBuildingResult(org.apache.maven.project.ProjectBuildingResult) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult)

Example 5 with ArtifactResolver

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);
}
Also used : ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) CheArtifactResolver(org.eclipse.che.maven.CheArtifactResolver) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver) CheArtifactResolver(org.eclipse.che.maven.CheArtifactResolver) Date(java.util.Date)

Aggregations

ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)8 DefaultArtifactResolver (org.eclipse.aether.internal.impl.DefaultArtifactResolver)5 CheArtifactResolver (org.eclipse.che.maven.CheArtifactResolver)3 IOException (java.io.IOException)2 RemoteException (java.rmi.RemoteException)2 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)2 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)2 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)2 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)2 MavenProject (org.apache.maven.project.MavenProject)2 ModelInterpolationException (org.apache.maven.project.interpolation.ModelInterpolationException)2 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)2 InitializationException (org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException)2 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)2 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1