use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.
the class JavadocReportTest method testHelpfile.
/**
* Method to test the <code><helpfile/></code> parameter.
*
* @throws Exception if any
*/
public void testHelpfile() throws Exception {
File testPom = new File(unit, "helpfile-test/pom.xml");
JavadocReport mojo = lookupMojo(testPom);
assertNotNull(mojo);
MavenSession session = spy(newMavenSession(mojo.project));
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);
LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(session);
setVariableValueToObject(mojo, "session", session);
File apidocs = new File(getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs");
File helpfile = new File(apidocs, "help-doc.html");
File options = new File(apidocs, "options");
// helpfile by default
mojo.execute();
String content = readFile(helpfile);
assertTrue(content.contains("<!-- Generated by javadoc"));
String optionsContent = readFile(options);
assertFalse(optionsContent.contains("-helpfile"));
// helpfile defined in a javadoc plugin dependency
setVariableValueToObject(mojo, "helpfile", "com/mycompany/app/javadoc/helpfile/help-doc.html");
setVariableValueToObject(mojo, "session", session);
mojo.execute();
content = readFile(helpfile);
assertTrue(content.contains("<!-- Help file from artefact -->"));
optionsContent = readFile(options);
assertTrue(optionsContent.contains("-helpfile"));
File help = new File(apidocs, "help-doc.html");
assertTrue(optionsContent.contains("'" + help.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
// helpfile defined as a project resource
setVariableValueToObject(mojo, "helpfile", "com/mycompany/app/javadoc/helpfile2/help-doc.html");
mojo.execute();
content = readFile(helpfile);
assertTrue(content.contains("<!-- Help file from file -->"));
optionsContent = readFile(options);
assertTrue(optionsContent.contains("-helpfile"));
help = new File(unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html");
assertTrue(optionsContent.contains("'" + help.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
// helpfile defined as file
help = new File(unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html");
setVariableValueToObject(mojo, "helpfile", help.getAbsolutePath());
mojo.execute();
content = readFile(helpfile);
assertTrue(content.contains("<!-- Help file from file -->"));
optionsContent = readFile(options);
assertTrue(optionsContent.contains("-helpfile"));
assertTrue(optionsContent.contains("'" + help.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
}
use of org.apache.maven.execution.MavenSession in project meecrowave by apache.
the class MeecrowaveRunMojoTest method run.
@Test
public void run() throws Exception {
final File moduleBase = jarLocation(MeecrowaveRunMojoTest.class).getParentFile().getParentFile();
final File basedir = new File(moduleBase, "src/test/resources/" + getClass().getSimpleName());
final File pom = new File(basedir, "pom.xml");
final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(basedir);
final ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
final DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repositorySession, new LocalRepository(new File(moduleBase, "target/fake"), "")));
configuration.setRepositorySession(repositorySession);
final MavenProject project = mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
final MavenSession session = mojo.newMavenSession(project);
final int port;
try (final ServerSocket serverSocket = new ServerSocket(0)) {
port = serverSocket.getLocalPort();
}
final MojoExecution execution = mojo.newMojoExecution("run");
execution.getConfiguration().addChild(new Xpp3Dom("httpPort") {
{
setValue(Integer.toString(port));
}
});
final InputStream in = System.in;
final CountDownLatch latch = new CountDownLatch(1);
System.setIn(new InputStream() {
// just to not return nothing
private int val = 2;
@Override
public int read() throws IOException {
try {
latch.await();
} catch (final InterruptedException e) {
Thread.interrupted();
fail(e.getMessage());
}
return val--;
}
});
final Thread runner = new Thread() {
@Override
public void run() {
try {
mojo.executeMojo(session, project, execution);
} catch (final Exception e) {
fail(e.getMessage());
}
}
};
try {
runner.start();
for (int i = 0; i < 120; i++) {
try {
assertEquals("simple", IOUtils.toString(new URL("http://localhost:" + port + "/api/test")));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("first_name"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("last_name"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("firstname"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("null"));
latch.countDown();
break;
} catch (final Exception | AssertionError e) {
Thread.sleep(500);
}
}
} finally {
runner.join(TimeUnit.MINUTES.toMillis(1));
System.setIn(in);
if (runner.isAlive()) {
runner.interrupt();
fail("Runner didn't terminate properly");
}
}
}
use of org.apache.maven.execution.MavenSession in project maven-dependency-plugin by apache.
the class TestCopyDependenciesMojo method setUp.
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("copy-dependencies", true, false);
File testPom = new File(getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml");
mojo = (CopyDependenciesMojo) lookupMojo("copy-dependencies", testPom);
mojo.outputDirectory = new File(this.testDir, "outputDirectory");
// mojo.silent = true;
assertNotNull(mojo);
assertNotNull(mojo.getProject());
MavenProject project = mojo.getProject();
MavenSession session = newMavenSession(project);
setVariableValueToObject(mojo, "session", session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
artifacts.addAll(directArtifacts);
project.setArtifacts(artifacts);
project.setDependencyArtifacts(directArtifacts);
mojo.markersDirectory = new File(this.testDir, "markers");
ArtifactHandlerManager manager = lookup(ArtifactHandlerManager.class);
setVariableValueToObject(mojo, "artifactHandlerManager", manager);
}
use of org.apache.maven.execution.MavenSession in project maven-dependency-plugin by apache.
the class TestUnpackMojo method setUp.
protected void setUp() throws Exception {
super.setUp("unpack", true, false);
File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml");
mojo = (UnpackMojo) lookupMojo("unpack", testPom);
mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
mojo.setMarkersDirectory(new File(this.testDir, "markers"));
mojo.setSilent(true);
assertNotNull(mojo);
assertNotNull(mojo.getProject());
// MavenProject project = mojo.getProject();
// init classifier things
// it needs to get the archivermanager
stubFactory.setUnpackableFile(mojo.getArchiverManager());
// i'm using one file repeatedly to archive so I can test the name
// programmatically.
stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + "target/test-classes/unit/unpack-dependencies-test/test.txt"));
mojo.setUseJvmChmod(true);
MavenSession session = newMavenSession(mojo.getProject());
setVariableValueToObject(mojo, "session", session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
use of org.apache.maven.execution.MavenSession in project maven-dependency-plugin by apache.
the class TestCopyDependenciesMojo2 method setUp.
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("copy-dependencies", true);
File testPom = new File(getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml");
mojo = (CopyDependenciesMojo) lookupMojo("copy-dependencies", testPom);
mojo.outputDirectory = new File(this.testDir, "outputDirectory");
// mojo.silent = true;
assertNotNull(mojo);
assertNotNull(mojo.getProject());
MavenProject project = mojo.getProject();
Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
artifacts.addAll(directArtifacts);
project.setArtifacts(artifacts);
project.setDependencyArtifacts(directArtifacts);
mojo.markersDirectory = new File(this.testDir, "markers");
LegacySupport legacySupport = lookup(LegacySupport.class);
MavenSession session = newMavenSession(project);
setVariableValueToObject(mojo, "session", session);
legacySupport.setSession(session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) legacySupport.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(testDir.getAbsolutePath()));
}
Aggregations