use of org.apache.maven.execution.MavenSession in project drools by kiegroup.
the class MavenEmbedder method init.
void init() throws MavenEmbedderException {
try {
this.mavenExecutionRequest = this.buildMavenExecutionRequest(mavenRequest);
RepositorySystemSession rss = ((DefaultMaven) componentProvider.lookup(Maven.class)).newRepositorySession(mavenExecutionRequest);
mavenSession = new MavenSession(componentProvider.getPlexusContainer(), rss, mavenExecutionRequest, new DefaultMavenExecutionResult());
componentProvider.lookup(LegacySupport.class).setSession(mavenSession);
} catch (MavenEmbedderException e) {
log.error("Unable to build MavenEmbedder", e);
throw e;
} catch (ComponentLookupException e) {
log.error("Unable to build MavenEmbedder", e);
throw new MavenEmbedderException(e.getMessage(), e);
}
}
use of org.apache.maven.execution.MavenSession in project meecrowave by apache.
the class MeecrowaveBundleMojoTest method bundle.
@Test
public void bundle() throws Exception {
final File moduleBase = jarLocation(MeecrowaveBundleMojoTest.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 Build build = new Build();
final File buildDir = new File("target/" + getClass().getName() + "/build");
build.setDirectory(buildDir.getAbsolutePath());
project.setBuild(build);
final MavenSession session = mojo.newMavenSession(project);
final MojoExecution execution = mojo.newMojoExecution("bundle");
execution.getConfiguration().addChild(new Xpp3Dom("enforceMeecrowave") {
{
setValue(Boolean.FALSE.toString());
}
});
execution.getConfiguration().addChild(new Xpp3Dom("enforceCommonsCli") {
{
setValue(Boolean.FALSE.toString());
}
});
execution.getConfiguration().addChild(new Xpp3Dom("conf") {
{
setValue("src/main/meecrowave/conf");
}
});
execution.getConfiguration().addChild(new Xpp3Dom("webapp") {
{
setValue("src/main/webapp");
}
});
mojo.executeMojo(session, project, execution);
assertTrue(buildDir.exists());
try (final ZipFile zip = new ZipFile(new File(buildDir, "test-meecrowave-distribution.zip"))) {
assertTrue(zip.getEntry("test-distribution/docBase/sub/index.html") != null);
}
}
use of org.apache.maven.execution.MavenSession in project docker-maven-plugin by fabric8io.
the class DockerFileUtilTest method mockMojoParams.
private MojoParameters mockMojoParams() {
MavenProject project = new MavenProject();
project.setArtifactId("docker-maven-plugin");
Properties projectProperties = project.getProperties();
projectProperties.put("base", "java");
projectProperties.put("name", "guenther");
projectProperties.put("age", "42");
projectProperties.put("ext", "png");
Settings settings = new Settings();
ArtifactRepository localRepository = new MavenArtifactRepository() {
public String getBasedir() {
return "repository";
}
};
@SuppressWarnings("deprecation") MavenSession session = new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", null, null, new Date(System.currentTimeMillis()));
// Maven CLI override: -DcliOverride=cliValue
session.getUserProperties().setProperty("cliOverride", "cliValue");
// Java system property: -Duser.name=somebody
session.getSystemProperties().put("user.name", "somebody");
return new MojoParameters(session, project, null, null, null, settings, "src", "target", Collections.singletonList(project));
}
use of org.apache.maven.execution.MavenSession in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManagerTest method mockMojoParams.
private MojoParameters mockMojoParams(MavenProject project) {
Settings settings = new Settings();
ArtifactRepository localRepository = new MavenArtifactRepository() {
@Mock
public String getBasedir() {
return "repository";
}
};
@SuppressWarnings("deprecation") MavenSession session = new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", null, null, new Date());
return new MojoParameters(session, project, null, null, null, settings, "src", "target", Collections.singletonList(project));
}
use of org.apache.maven.execution.MavenSession in project che by eclipse.
the class MavenServerImpl method runMavenRequest.
public void runMavenRequest(MavenExecutionRequest request, Runnable runnable) {
DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
request.getProjectBuildingRequest().setRepositorySession(repositorySystemSession);
MavenSession mavenSession = new MavenSession(container, repositorySystemSession, request, new DefaultMavenExecutionResult());
LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
MavenSession previousSession = legacySupport.getSession();
legacySupport.setSession(mavenSession);
try {
for (AbstractMavenLifecycleParticipant participant : getLifecycleParticipants(Collections.emptyList())) {
participant.afterSessionStart(mavenSession);
}
runnable.run();
} catch (MavenExecutionException e) {
throw new RuntimeException(e);
} finally {
legacySupport.setSession(previousSession);
}
}
Aggregations