use of org.apache.maven.execution.MavenSession in project che by eclipse.
the class MavenServerImpl method loadExtensions.
private void loadExtensions(MavenProject project, List<Exception> exceptions) {
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
Collection<AbstractMavenLifecycleParticipant> participants = getLifecycleParticipants(Collections.singletonList(project));
if (!participants.isEmpty()) {
LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
MavenSession session = legacySupport.getSession();
session.setCurrentProject(project);
session.setProjects(Collections.singletonList(project));
for (AbstractMavenLifecycleParticipant participant : participants) {
Thread.currentThread().setContextClassLoader(participant.getClass().getClassLoader());
try {
participant.afterProjectsRead(session);
} catch (MavenExecutionException e) {
exceptions.add(e);
} finally {
Thread.currentThread().setContextClassLoader(currentClassLoader);
}
}
}
}
use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.
the class JavadocReportTest method testTaglets.
/**
* Method to test the taglet artifact configuration
*
* @throws Exception if any
*/
public void testTaglets() throws Exception {
// ----------------------------------------------------------------------
// taglet-test: check if a taglet is used
// ----------------------------------------------------------------------
File testPom = new File(unit, "taglet-test/taglet-test-plugin-config.xml");
JavadocReport mojo = lookupMojo(testPom);
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);
mojo.execute();
File apidocs = new File(getBasedir(), "target/test/unit/taglet-test/target/site/apidocs");
assertTrue(new File(apidocs, "index.html").exists());
File appFile = new File(apidocs, "taglet/test/App.html");
assertTrue(appFile.exists());
String appString = readFile(appFile);
assertTrue(appString.contains("<b>To Do:</b>"));
}
use of org.apache.maven.execution.MavenSession in project liferay-ide by liferay.
the class ThemePluginBuildParticipant method executeThemeMojo.
protected IStatus executeThemeMojo(IMavenProjectFacade facade, IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
IStatus retval = null;
List<String> goals = Collections.singletonList(getGoal());
MavenProject mavenProject = facade.getMavenProject(monitor);
MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, goals, true, monitor);
monitor.worked(10);
MojoExecution liferayMojoExecution = MavenUtil.getExecution(plan, ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_ARTIFACT_ID);
Xpp3Dom originalConfig = liferayMojoExecution.getConfiguration();
Xpp3Dom config = Xpp3DomUtils.mergeXpp3Dom(new Xpp3Dom("configuration"), originalConfig);
configureExecution(facade, config);
boolean parentHierarchyLoaded = false;
try {
parentHierarchyLoaded = MavenUtil.loadParentHierarchy(facade, monitor);
monitor.worked(10);
ResolverConfiguration configuration = facade.getResolverConfiguration();
configuration.setResolveWorkspaceProjects(true);
liferayMojoExecution.setConfiguration(config);
maven.execute(mavenProject, liferayMojoExecution, monitor);
monitor.worked(50);
MavenSession mavenSession = context.getSession();
List<Throwable> exceptions = mavenSession.getResult().getExceptions();
if (exceptions.size() == 1) {
retval = LiferayMavenCore.createErrorStatus(exceptions.get(0));
} else if (exceptions.size() > 1) {
List<IStatus> statuses = new ArrayList<>();
for (Throwable t : exceptions) {
statuses.add(LiferayMavenCore.createErrorStatus(t));
}
retval = LiferayMavenCore.createMultiStatus(IStatus.ERROR, statuses.toArray(new IStatus[0]));
}
retval = retval == null ? Status.OK_STATUS : retval;
} catch (CoreException ce) {
retval = LiferayMavenCore.createErrorStatus(ce);
} finally {
liferayMojoExecution.setConfiguration(originalConfig);
if (parentHierarchyLoaded) {
mavenProject.setParent(null);
}
}
return retval;
}
use of org.apache.maven.execution.MavenSession in project maven-dependency-plugin by apache.
the class TestIncludeExcludeUnpackMojo method setUp.
protected void setUp() throws Exception {
// required for mojo lookups to work
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.silent = true;
// 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 + PACKED_FILE_PATH));
Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null);
ArtifactItem item = stubFactory.getArtifactItem(artifact);
List<ArtifactItem> list = new ArrayList<ArtifactItem>(1);
list.add(item);
assertNotNull(mojo);
assertNotNull(mojo.getProject());
mojo.setArchiverManager((ArchiverManager) lookup(ArchiverManager.ROLE));
mojo.setMarkersDirectory(new File(this.testDir, "markers"));
mojo.setArtifactItems(list);
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 TestCopyMojo method setUp.
protected void setUp() throws Exception {
super.setUp("copy", false, false);
File testPom = new File(getBasedir(), "target/test-classes/unit/copy-test/plugin-config.xml");
mojo = (CopyMojo) lookupMojo("copy", testPom);
mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
mojo.setSilent(true);
assertNotNull(mojo);
assertNotNull(mojo.getProject());
// MavenProject project = mojo.getProject();
// init classifier things
MavenSession session = newMavenSession(mojo.getProject());
setVariableValueToObject(mojo, "session", session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
Aggregations