use of org.apache.maven.plugin.LegacySupport 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.plugin.LegacySupport in project intellij-community by JetBrains.
the class Maven30ServerEmbedderImpl method executeWithMavenSession.
public void executeWithMavenSession(MavenExecutionRequest request, Runnable runnable) {
DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
RepositorySystemSession repositorySession = maven.newRepositorySession(request);
request.getProjectBuildingRequest().setRepositorySession(repositorySession);
MavenSession mavenSession = new MavenSession(myContainer, repositorySession, request, new DefaultMavenExecutionResult());
LegacySupport legacySupport = getComponent(LegacySupport.class);
MavenSession oldSession = legacySupport.getSession();
legacySupport.setSession(mavenSession);
/** adapted from {@link DefaultMaven#doExecute(MavenExecutionRequest)} */
try {
for (AbstractMavenLifecycleParticipant listener : getLifecycleParticipants(Collections.<MavenProject>emptyList())) {
listener.afterSessionStart(mavenSession);
}
} catch (MavenExecutionException e) {
throw new RuntimeException(e);
}
try {
runnable.run();
} finally {
legacySupport.setSession(oldSession);
}
}
use of org.apache.maven.plugin.LegacySupport in project intellij-community by JetBrains.
the class Maven3ServerEmbedderImpl method loadExtensions.
/**
* adapted from {@link DefaultMaven#doExecute(MavenExecutionRequest)}
*/
private void loadExtensions(MavenProject project, List<Exception> exceptions) {
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
Collection<AbstractMavenLifecycleParticipant> lifecycleParticipants = getLifecycleParticipants(Arrays.asList(project));
if (!lifecycleParticipants.isEmpty()) {
LegacySupport legacySupport = getComponent(LegacySupport.class);
MavenSession session = legacySupport.getSession();
session.setCurrentProject(project);
try {
// the method can be removed
session.setAllProjects(Arrays.asList(project));
} catch (NoSuchMethodError ignore) {
}
session.setProjects(Arrays.asList(project));
for (AbstractMavenLifecycleParticipant listener : lifecycleParticipants) {
Thread.currentThread().setContextClassLoader(listener.getClass().getClassLoader());
try {
listener.afterProjectsRead(session);
} catch (Exception e) {
exceptions.add(e);
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
}
}
use of org.apache.maven.plugin.LegacySupport 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.plugin.LegacySupport 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