Search in sources :

Example 41 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class AssemblyFormatUtilsTest method verifyOutputDir.

private void verifyOutputDir(final String outDir, final String finalName, final MavenProject mainProject, final MavenProject moduleProject, final MavenProject artifactProject, final String checkValue) throws AssemblyFormattingException {
    final MavenSession session = mockManager.createMock(MavenSession.class);
    expect(session.getExecutionProperties()).andReturn(System.getProperties()).anyTimes();
    expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
    final AssemblerConfigurationSource cs = mockManager.createMock(AssemblerConfigurationSource.class);
    expect(cs.getMavenSession()).andReturn(session).anyTimes();
    DefaultAssemblyArchiverTest.setupInterpolators(cs, mainProject);
    String result;
    mockManager.replayAll();
    result = AssemblyFormatUtils.getOutputDirectory(outDir, finalName, cs, AssemblyFormatUtils.moduleProjectInterpolator(moduleProject), AssemblyFormatUtils.artifactProjectInterpolator(artifactProject));
    assertEquals(checkValue, result);
    mockManager.verifyAll();
    mockManager.resetAll();
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) Properties(java.util.Properties)

Example 42 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class JiraUnicodeTestCase method testUnicodeReport.

public void testUnicodeReport() throws Exception {
    File pom = new File(getBasedir(), "/src/test/unit/jira-plugin-config.xml");
    assertNotNull(pom);
    assertTrue(pom.exists());
    JiraMojo mojo = (JiraMojo) lookupMojo("jira-report", pom);
    MavenProject project = new JiraUnicodeTestProjectStub();
    MavenSession session = newMavenSession(project);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager("target/local-repo"));
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "mavenSession", session);
    InputStream testJiraXmlStream = JiraUnicodeTestCase.class.getResourceAsStream("unicode-jira-results.xml");
    String jiraXml = null;
    try {
        jiraXml = IOUtils.toString(testJiraXmlStream, "utf-8");
    } finally {
        testJiraXmlStream.close();
    }
    MockJiraDownloader mockDownloader = new MockJiraDownloader();
    mockDownloader.setJiraXml(jiraXml);
    mojo.setMockDownloader(mockDownloader);
    File outputDir = new File("target/jira-test-output");
    outputDir.mkdirs();
    mojo.setReportOutputDirectory(outputDir);
    mojo.execute();
    String reportHtml = FileUtils.readFileToString(new File(outputDir, "jira-report.html"), "utf-8");
    int turtleIndex = reportHtml.indexOf(TEST_TURTLES);
    assertTrue(turtleIndex >= 0);
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) InputStream(java.io.InputStream) JiraMojo(org.apache.maven.plugins.jira.JiraMojo) File(java.io.File)

Example 43 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class CompilerMojoTestCase method getMockMavenSession.

private MavenSession getMockMavenSession() {
    MavenSession session = mock(MavenSession.class);
    // when( session.getPluginContext( isA(PluginDescriptor.class), isA(MavenProject.class) ) ).thenReturn(
    // Collections.emptyMap() );
    when(session.getCurrentProject()).thenReturn(getMockMavenProject());
    return session;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession)

Example 44 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class DescribeMojoTest method testLookupPluginDescriptorGAV.

public void testLookupPluginDescriptorGAV() throws Throwable {
    DescribeMojo mojo = new DescribeMojo();
    PluginInfo pi = new PluginInfo();
    pi.setGroupId("org.test");
    pi.setArtifactId("test");
    pi.setVersion("1.0");
    PluginDescriptor pd = new PluginDescriptor();
    MojoDescriptorCreator mojoDescriptorCreator = mock(MojoDescriptorCreator.class);
    PluginVersionResolver pluginVersionResolver = mock(PluginVersionResolver.class);
    MavenPluginManagerHelper pluginManager = mock(MavenPluginManagerHelper.class);
    MavenSession session = mock(MavenSession.class);
    PrivateAccessor.setField(mojo, "mojoDescriptorCreator", mojoDescriptorCreator);
    PrivateAccessor.setField(mojo, "pluginVersionResolver", pluginVersionResolver);
    PrivateAccessor.setField(mojo, "pluginManager", pluginManager);
    PrivateAccessor.setField(mojo, "session", session);
    when(pluginManager.getPluginDescriptor(any(Plugin.class), eq(session))).thenReturn(pd);
    PluginDescriptor returned = (PluginDescriptor) PrivateAccessor.invoke(mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, new Object[] { pi });
    assertEquals(pd, returned);
    verify(mojoDescriptorCreator, never()).findPluginForPrefix(any(String.class), any(MavenSession.class));
    verify(pluginVersionResolver, never()).resolve(any(PluginVersionRequest.class));
    ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass(Plugin.class);
    verify(pluginManager).getPluginDescriptor(argument.capture(), eq(session));
    Plugin capturedPlugin = argument.getValue();
    assertEquals("org.test", capturedPlugin.getGroupId());
    assertEquals("test", capturedPlugin.getArtifactId());
    assertEquals("1.0", capturedPlugin.getVersion());
}
Also used : PluginVersionResolver(org.apache.maven.plugin.version.PluginVersionResolver) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MavenSession(org.apache.maven.execution.MavenSession) MojoDescriptorCreator(org.apache.maven.lifecycle.internal.MojoDescriptorCreator) PluginInfo(org.apache.maven.plugins.help.DescribeMojo.PluginInfo) MavenPluginManagerHelper(org.apache.maven.reporting.exec.MavenPluginManagerHelper) PluginVersionRequest(org.apache.maven.plugin.version.PluginVersionRequest) Plugin(org.apache.maven.model.Plugin)

Example 45 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class DescribeMojoTest method testLookupPluginDescriptorPrefixWithVersion.

public void testLookupPluginDescriptorPrefixWithVersion() throws Throwable {
    DescribeMojo mojo = new DescribeMojo();
    PluginInfo pi = new PluginInfo();
    pi.setPrefix("help");
    pi.setVersion("1.0");
    Plugin plugin = new Plugin();
    plugin.setGroupId("org.test");
    plugin.setArtifactId("test");
    PluginDescriptor pd = new PluginDescriptor();
    MojoDescriptorCreator mojoDescriptorCreator = mock(MojoDescriptorCreator.class);
    PluginVersionResolver pluginVersionResolver = mock(PluginVersionResolver.class);
    MavenPluginManagerHelper pluginManager = mock(MavenPluginManagerHelper.class);
    MavenSession session = mock(MavenSession.class);
    PrivateAccessor.setField(mojo, "mojoDescriptorCreator", mojoDescriptorCreator);
    PrivateAccessor.setField(mojo, "pluginVersionResolver", pluginVersionResolver);
    PrivateAccessor.setField(mojo, "pluginManager", pluginManager);
    PrivateAccessor.setField(mojo, "session", session);
    when(mojoDescriptorCreator.findPluginForPrefix("help", session)).thenReturn(plugin);
    when(pluginManager.getPluginDescriptor(any(Plugin.class), eq(session))).thenReturn(pd);
    PluginDescriptor returned = (PluginDescriptor) PrivateAccessor.invoke(mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, new Object[] { pi });
    assertEquals(pd, returned);
    verify(mojoDescriptorCreator).findPluginForPrefix("help", session);
    verify(pluginVersionResolver, never()).resolve(any(PluginVersionRequest.class));
    ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass(Plugin.class);
    verify(pluginManager).getPluginDescriptor(argument.capture(), eq(session));
    Plugin capturedPlugin = argument.getValue();
    assertEquals("org.test", capturedPlugin.getGroupId());
    assertEquals("test", capturedPlugin.getArtifactId());
    assertEquals("1.0", capturedPlugin.getVersion());
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MavenSession(org.apache.maven.execution.MavenSession) PluginVersionResolver(org.apache.maven.plugin.version.PluginVersionResolver) MojoDescriptorCreator(org.apache.maven.lifecycle.internal.MojoDescriptorCreator) PluginInfo(org.apache.maven.plugins.help.DescribeMojo.PluginInfo) MavenPluginManagerHelper(org.apache.maven.reporting.exec.MavenPluginManagerHelper) PluginVersionRequest(org.apache.maven.plugin.version.PluginVersionRequest) Plugin(org.apache.maven.model.Plugin)

Aggregations

MavenSession (org.apache.maven.execution.MavenSession)117 File (java.io.File)65 MavenProject (org.apache.maven.project.MavenProject)47 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)30 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)23 Test (org.junit.Test)21 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)20 LegacySupport (org.apache.maven.plugin.LegacySupport)19 Properties (java.util.Properties)18 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)18 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)16 MojoExecution (org.apache.maven.plugin.MojoExecution)13 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)13 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)11 Artifact (org.apache.maven.artifact.Artifact)10 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)9 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)8 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)7 Settings (org.apache.maven.settings.Settings)7 ArrayList (java.util.ArrayList)6