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();
}
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);
}
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;
}
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());
}
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());
}
Aggregations