Search in sources :

Example 6 with MavenExecutionResult

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

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

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

the class DependencyComputerTest method testTYCHO0378unwantedSelfDependency.

@Test
public void testTYCHO0378unwantedSelfDependency() throws Exception {
    File basedir = getBasedir("projects/TYCHO0378unwantedSelfDependency");
    File pom = new File(basedir, "pom.xml");
    MavenExecutionRequest request = newMavenExecutionRequest(pom);
    request.getProjectBuildingRequest().setProcessPlugins(false);
    MavenExecutionResult result = maven.execute(request);
    Assert.assertEquals(0, result.getProject().getDependencies().size());
}
Also used : MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) File(java.io.File) Test(org.junit.Test)

Example 9 with MavenExecutionResult

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

the class AbstractTychoMojoTestCase method getSortedProjects.

protected List<MavenProject> getSortedProjects(File basedir, Properties userProperties, File platform) throws Exception {
    File pom = new File(basedir, "pom.xml");
    MavenExecutionRequest request = newMavenExecutionRequest(pom);
    request.getProjectBuildingRequest().setProcessPlugins(false);
    request.setLocalRepository(getLocalRepository());
    if (platform != null) {
        request.getUserProperties().put("tycho.targetPlatform", platform.getAbsolutePath());
    }
    if (userProperties != null) {
        request.getUserProperties().putAll(userProperties);
    }
    MavenExecutionResult result = maven.execute(request);
    if (result.hasExceptions()) {
        throw new CompoundRuntimeException(result.getExceptions());
    }
    return result.getTopologicallySortedProjects();
}
Also used : DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) File(java.io.File)

Example 10 with MavenExecutionResult

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

the class AbstractTychoMojoTestCase method newMavenSession.

protected MavenSession newMavenSession(MavenProject project, List<MavenProject> projects) throws Exception {
    MavenExecutionRequest request = newMavenExecutionRequest(new File(project.getBasedir(), "pom.xml"));
    MavenExecutionResult result = new DefaultMavenExecutionResult();
    DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    MavenSession session = new MavenSession(getContainer(), repositorySession, request, result);
    session.setProjects(projects);
    session.setCurrentProject(project);
    return session;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) File(java.io.File)

Aggregations

MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)15 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)11 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)8 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)7 MavenSession (org.apache.maven.execution.MavenSession)7 File (java.io.File)6 MavenProject (org.apache.maven.project.MavenProject)5 Properties (java.util.Properties)3 StubArtifactRepository (org.apache.maven.plugin.testing.stubs.StubArtifactRepository)3 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)3 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)3 LegacySupport (org.apache.maven.plugin.LegacySupport)2 ProjectBuilder (org.apache.maven.project.ProjectBuilder)2 ProjectBuildingResult (org.apache.maven.project.ProjectBuildingResult)2 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)2 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)2 DependencyResolver (org.eclipse.tycho.core.DependencyResolver)2 LocalDependencyResolver (org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver)2 PrintStream (java.io.PrintStream)1 Field (java.lang.reflect.Field)1