use of org.apache.maven.AbstractMavenLifecycleParticipant 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.AbstractMavenLifecycleParticipant 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);
}
}
use of org.apache.maven.AbstractMavenLifecycleParticipant in project che by eclipse.
the class MavenServerImpl method getLifecycleParticipants.
/**
* method from org.apache.maven.DefaultMaven#getLifecycleParticipants
*/
private Collection<AbstractMavenLifecycleParticipant> getLifecycleParticipants(Collection<MavenProject> projects) {
Collection<AbstractMavenLifecycleParticipant> lifecycleListeners = new LinkedHashSet<AbstractMavenLifecycleParticipant>();
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
try {
lifecycleListeners.addAll(container.lookupList(AbstractMavenLifecycleParticipant.class));
} catch (ComponentLookupException e) {
// this is just silly, lookupList should return an empty list!
logWarn("Failed to lookup lifecycle participants: " + e.getMessage());
}
Collection<ClassLoader> scannedRealms = new HashSet<ClassLoader>();
for (MavenProject project : projects) {
ClassLoader projectRealm = project.getClassRealm();
if (projectRealm != null && scannedRealms.add(projectRealm)) {
Thread.currentThread().setContextClassLoader(projectRealm);
try {
lifecycleListeners.addAll(container.lookupList(AbstractMavenLifecycleParticipant.class));
} catch (ComponentLookupException e) {
// this is just silly, lookupList should return an empty list!
logWarn("Failed to lookup lifecycle participants: " + e.getMessage());
}
}
}
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
return lifecycleListeners;
}
Aggregations