Search in sources :

Example 11 with RepositorySystemSession

use of org.eclipse.aether.RepositorySystemSession in project build-info by JFrogDev.

the class BuildInfoRecorderLifecycleParticipantTest method testParticipantImplementation.

public void testParticipantImplementation() throws Exception {
    BuildInfoRecorder buildInfoRecorder = new BuildInfoRecorder();
    BuildInfoRecorderLifecycleParticipant participant = new BuildInfoRecorderLifecycleParticipant();
    Class<BuildInfoRecorderLifecycleParticipant> participantClass = BuildInfoRecorderLifecycleParticipant.class;
    Field recorderField = participantClass.getDeclaredField("recorder");
    recorderField.set(participant, buildInfoRecorder);
    Field loggerField = participantClass.getDeclaredField("logger");
    loggerField.setAccessible(true);
    loggerField.set(participant, new AbstractLogger(1, "dummy") {

        public void debug(String message, Throwable throwable) {
            Assert.assertTrue(message.contains("value is true"));
        }

        public void info(String message, Throwable throwable) {
            assert false;
        }

        public void warn(String message, Throwable throwable) {
            assert false;
        }

        public void error(String message, Throwable throwable) {
            assert false;
        }

        public void fatalError(String message, Throwable throwable) {
            assert false;
        }

        public Logger getChildLogger(String name) {
            assert false;
            return null;
        }
    });
    PlexusContainer plexusContainerMock = EasyMock.createMock(PlexusContainer.class);
    RepositorySystemSession repositorySystemSession = EasyMock.createMock(RepositorySystemSession.class);
    MavenExecutionRequest requestMock = EasyMock.createMock(MavenExecutionRequest.class);
    Properties mockSessionProperties = new Properties();
    mockSessionProperties.setProperty(BuildInfoConfigProperties.ACTIVATE_RECORDER, "true");
    EasyMock.expect(requestMock.getSystemProperties()).andReturn(mockSessionProperties).once();
    EasyMock.expect(requestMock.getUserProperties()).andReturn(mockSessionProperties).once();
    AbstractExecutionListener existingListener = new AbstractExecutionListener();
    EasyMock.expect(requestMock.getExecutionListener()).andReturn(existingListener).times(1);
    EasyMock.expect(requestMock.getUserSettingsFile()).andReturn(null).once();
    EasyMock.expect(requestMock.setExecutionListener(buildInfoRecorder)).andReturn(null).once();
    EasyMock.replay(requestMock);
    MavenExecutionResult resultMock = EasyMock.createMock(MavenExecutionResult.class);
    MavenSession session = new MavenSession(plexusContainerMock, repositorySystemSession, requestMock, resultMock);
    // value is true
    participant.afterProjectsRead(session);
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) PlexusContainer(org.codehaus.plexus.PlexusContainer) AbstractExecutionListener(org.apache.maven.execution.AbstractExecutionListener) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) AbstractLogger(org.codehaus.plexus.logging.AbstractLogger) Logger(org.codehaus.plexus.logging.Logger) BuildInfoConfigProperties(org.jfrog.build.api.BuildInfoConfigProperties) Properties(java.util.Properties) Field(java.lang.reflect.Field) MavenSession(org.apache.maven.execution.MavenSession) AbstractLogger(org.codehaus.plexus.logging.AbstractLogger)

Example 12 with RepositorySystemSession

use of org.eclipse.aether.RepositorySystemSession in project revapi by revapi.

the class ArtifactResolver method makeRemoteOnly.

private RepositorySystemSession makeRemoteOnly(RepositorySystemSession session) {
    return new AbstractForwardingRepositorySystemSession() {

        @Override
        protected RepositorySystemSession getSession() {
            return session;
        }

        @Override
        public WorkspaceReader getWorkspaceReader() {
            return null;
        }

        @Override
        public LocalRepositoryManager getLocalRepositoryManager() {
            LocalRepositoryManager wrapped = session.getLocalRepositoryManager();
            return new LocalRepositoryManager() {

                @Override
                public LocalRepository getRepository() {
                    return wrapped.getRepository();
                }

                @Override
                public String getPathForLocalArtifact(Artifact artifact) {
                    return wrapped.getPathForLocalArtifact(artifact);
                }

                @Override
                public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
                    return wrapped.getPathForRemoteArtifact(artifact, repository, context);
                }

                @Override
                public String getPathForLocalMetadata(Metadata metadata) {
                    return wrapped.getPathForLocalMetadata(metadata);
                }

                @Override
                public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
                    return wrapped.getPathForRemoteMetadata(metadata, repository, context);
                }

                @Override
                public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
                    return wrapped.find(session, request);
                }

                @Override
                public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
                    wrapped.add(session, request);
                }

                @Override
                public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
                    if (request.getRepository() == null) {
                        // local metadata request... the returned file must not be null but may not exist
                        // we exploit that to not include the locally built results
                        LocalMetadataResult ret = new LocalMetadataResult(request);
                        ret.setFile(new File("<faked-to-force-remote-only-resolution-of-artifacts>"));
                        return ret;
                    } else {
                        return wrapped.find(session, request);
                    }
                }

                @Override
                public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
                    wrapped.add(session, request);
                }
            };
        }
    };
}
Also used : AbstractForwardingRepositorySystemSession(org.eclipse.aether.AbstractForwardingRepositorySystemSession) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) LocalArtifactRegistration(org.eclipse.aether.repository.LocalArtifactRegistration) LocalMetadataRequest(org.eclipse.aether.repository.LocalMetadataRequest) LocalMetadataRegistration(org.eclipse.aether.repository.LocalMetadataRegistration) Metadata(org.eclipse.aether.metadata.Metadata) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) LocalMetadataResult(org.eclipse.aether.repository.LocalMetadataResult) AbstractForwardingRepositorySystemSession(org.eclipse.aether.AbstractForwardingRepositorySystemSession) File(java.io.File) LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest)

Example 13 with RepositorySystemSession

use of org.eclipse.aether.RepositorySystemSession in project drools by kiegroup.

the class MavenEmbedder method getProjectBuildingRequest.

ProjectBuildingRequest getProjectBuildingRequest() throws ComponentLookupException {
    ProjectBuildingRequest projectBuildingRequest = this.mavenExecutionRequest.getProjectBuildingRequest();
    projectBuildingRequest.setValidationLevel(this.mavenRequest.getValidationLevel());
    RepositorySystemSession repositorySystemSession = componentProvider.getRepositorySystemSession(mavenExecutionRequest);
    projectBuildingRequest.setRepositorySession(repositorySystemSession);
    projectBuildingRequest.setProcessPlugins(this.mavenRequest.isProcessPlugins());
    projectBuildingRequest.setResolveDependencies(this.mavenRequest.isResolveDependencies());
    return projectBuildingRequest;
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession)

Example 14 with RepositorySystemSession

use of org.eclipse.aether.RepositorySystemSession in project drools by kiegroup.

the class MavenRepository method resolveArtifact.

public Artifact resolveArtifact(String artifactName, boolean logUnresolvedArtifact) {
    Artifact artifact = new DefaultArtifact(artifactName);
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    for (RemoteRepository repo : remoteRepositoriesForRequest) {
        artifactRequest.addRepository(repo);
    }
    RepositorySystemSession session = aether.getSession();
    Object sessionChecks = null;
    boolean isSnapshot = artifactName.endsWith("-SNAPSHOT");
    if (artifactName.endsWith("-SNAPSHOT")) {
        // ensure to always update snapshots
        sessionChecks = session.getData().get(SESSION_CHECKS);
        session.getData().set(SESSION_CHECKS, null);
    }
    try {
        ArtifactResult artifactResult = aether.getSystem().resolveArtifact(session, artifactRequest);
        return artifactResult.getArtifact();
    } catch (ArtifactResolutionException e) {
        if (logUnresolvedArtifact) {
            if (log.isDebugEnabled()) {
                log.debug("Unable to resolve artifact: " + artifactName, e);
            } else {
                log.warn("Unable to resolve artifact: " + artifactName);
            }
        }
        return null;
    } finally {
        if (sessionChecks != null) {
            session.getData().set(SESSION_CHECKS, sessionChecks);
        }
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 15 with RepositorySystemSession

use of org.eclipse.aether.RepositorySystemSession in project drools by kiegroup.

the class MavenEmbedder method init.

void init() throws MavenEmbedderException {
    try {
        this.mavenExecutionRequest = this.buildMavenExecutionRequest(mavenRequest);
        RepositorySystemSession rss = ((DefaultMaven) componentProvider.lookup(Maven.class)).newRepositorySession(mavenExecutionRequest);
        mavenSession = new MavenSession(componentProvider.getPlexusContainer(), rss, mavenExecutionRequest, new DefaultMavenExecutionResult());
        componentProvider.lookup(LegacySupport.class).setSession(mavenSession);
    } catch (MavenEmbedderException e) {
        log.error("Unable to build MavenEmbedder", e);
        throw e;
    } catch (ComponentLookupException e) {
        log.error("Unable to build MavenEmbedder", e);
        throw new MavenEmbedderException(e.getMessage(), e);
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) MavenSession(org.apache.maven.execution.MavenSession) LegacySupport(org.apache.maven.plugin.LegacySupport) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) DefaultMaven(org.apache.maven.DefaultMaven) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException)

Aggregations

RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)38 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)19 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)14 RepositorySystem (org.eclipse.aether.RepositorySystem)13 Artifact (org.eclipse.aether.artifact.Artifact)13 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)13 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)12 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)11 ArrayList (java.util.ArrayList)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)10 File (java.io.File)8 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)7 List (java.util.List)5 Artifact (org.apache.maven.artifact.Artifact)5 MavenSession (org.apache.maven.execution.MavenSession)5 IOException (java.io.IOException)4 DefaultMaven (org.apache.maven.DefaultMaven)4 Maven (org.apache.maven.Maven)4 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)4 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)4