Search in sources :

Example 11 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project tycho by eclipse.

the class BuildQualifierTest method getProject.

private MavenProject getProject(String baseDir, String pom) throws Exception {
    File basedirFile = getBasedir(baseDir);
    File pomFile = new File(basedirFile, pom);
    MavenExecutionRequest request = newMavenExecutionRequest(pomFile);
    request.getProjectBuildingRequest().setProcessPlugins(false);
    MavenExecutionResult result = maven.execute(request);
    return result.getProject();
}
Also used : MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) File(java.io.File)

Example 12 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest 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 13 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project pom-manipulation-ext by release-engineering.

the class VersioningCalculatorTest method setupSession.

private VersioningState setupSession(final Properties properties, final Map<ProjectRef, String[]> versionMap) throws Exception {
    final ArtifactRepository ar = new MavenArtifactRepository("test", "http://repo.maven.apache.org/maven2", new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
    final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(properties).setRemoteRepositories(Arrays.asList(ar));
    final PlexusContainer container = new DefaultPlexusContainer();
    final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
    session = new ManipulationSession();
    session.setMavenSession(mavenSession);
    final VersioningState state = new VersioningState(properties);
    session.setState(state);
    final Map<String, byte[]> dataMap = new HashMap<>();
    if (versionMap != null && !versionMap.isEmpty()) {
        for (final Map.Entry<ProjectRef, String[]> entry : versionMap.entrySet()) {
            final String path = toMetadataPath(entry.getKey());
            final byte[] data = setupMetadataVersions(entry.getValue());
            dataMap.put(path, data);
        }
    }
    final Location mdLoc = MavenLocationExpander.EXPANSION_TARGET;
    final Transport mdTrans = new StubTransport(dataMap);
    modder = new TestVersionCalculator(new ManipulationSession(), mdLoc, mdTrans, temp.newFolder("galley-cache"));
    return state;
}
Also used : DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) HashMap(java.util.HashMap) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) StubTransport(org.commonjava.maven.ext.core.fixture.StubTransport) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) MavenSession(org.apache.maven.execution.MavenSession) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) VersioningState(org.commonjava.maven.ext.core.state.VersioningState) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Transport(org.commonjava.maven.galley.spi.transport.Transport) StubTransport(org.commonjava.maven.ext.core.fixture.StubTransport) HashMap(java.util.HashMap) Map(java.util.Map) Location(org.commonjava.maven.galley.model.Location)

Example 14 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project maven-archetype by apache.

the class RemoteCatalogArchetypeDataSource method getAuthenticationInfo.

private AuthenticationInfo getAuthenticationInfo(String id) {
    MavenSession session = legacySupport.getSession();
    if (session != null && id != null) {
        MavenExecutionRequest request = session.getRequest();
        if (request != null) {
            List<Server> servers = request.getServers();
            if (servers != null) {
                for (Server server : servers) {
                    if (id.equalsIgnoreCase(server.getId())) {
                        SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(server));
                        server = result.getServer();
                        AuthenticationInfo authInfo = new AuthenticationInfo();
                        authInfo.setUserName(server.getUsername());
                        authInfo.setPassword(server.getPassword());
                        authInfo.setPrivateKey(server.getPrivateKey());
                        authInfo.setPassphrase(server.getPassphrase());
                        return authInfo;
                    }
                }
            }
        }
    }
    // empty one to prevent NPE
    return new AuthenticationInfo();
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) Server(org.apache.maven.settings.Server) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo)

Example 15 with MavenExecutionRequest

use of org.apache.maven.execution.MavenExecutionRequest in project maven-archetype by apache.

the class RemoteCatalogArchetypeDataSource method getMirror.

private Mirror getMirror(String repoId) {
    MavenSession session = legacySupport.getSession();
    MavenExecutionRequest request = session.getRequest();
    if (request != null) {
        return getMirror(repoId, request.getMirrors());
    }
    return null;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest)

Aggregations

MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)56 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)40 File (java.io.File)24 MavenSession (org.apache.maven.execution.MavenSession)20 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)14 MavenProject (org.apache.maven.project.MavenProject)14 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)10 IOException (java.io.IOException)9 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)9 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)9 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)8 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)7 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)7 FileNotFoundException (java.io.FileNotFoundException)6 Path (java.nio.file.Path)6 Properties (java.util.Properties)6 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)6 LifecycleExecutionException (org.apache.maven.lifecycle.LifecycleExecutionException)5 ProjectBuilder (org.apache.maven.project.ProjectBuilder)5