use of org.codehaus.plexus.component.repository.exception.ComponentLookupException 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.codehaus.plexus.component.repository.exception.ComponentLookupException in project drools by kiegroup.
the class MavenEmbedder method getLocalRepositoryPath.
public String getLocalRepositoryPath() {
String path = null;
try {
Settings settings = getSettings();
path = settings.getLocalRepository();
} catch (MavenEmbedderException e) {
// ignore
} catch (ComponentLookupException e) {
// ignore
}
if (this.mavenRequest.getLocalRepositoryPath() != null) {
path = this.mavenRequest.getLocalRepositoryPath();
}
if (path == null) {
path = RepositorySystem.defaultUserLocalRepository.getAbsolutePath();
}
return path;
}
use of org.codehaus.plexus.component.repository.exception.ComponentLookupException 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;
}
use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project intellij-community by JetBrains.
the class MavenEmbedder method buildSettings.
public static Settings buildSettings(PlexusContainer container, MavenEmbedderSettings embedderSettings) {
File file = embedderSettings.getGlobalSettingsFile();
if (file != null) {
System.setProperty(MavenSettingsBuilder.ALT_GLOBAL_SETTINGS_XML_LOCATION, file.getPath());
}
Settings settings = null;
try {
MavenSettingsBuilder builder = (MavenSettingsBuilder) container.lookup(MavenSettingsBuilder.ROLE);
File userSettingsFile = embedderSettings.getUserSettingsFile();
if (userSettingsFile != null && userSettingsFile.exists() && !userSettingsFile.isDirectory()) {
settings = builder.buildSettings(userSettingsFile, false);
}
if (settings == null) {
settings = builder.buildSettings();
}
} catch (ComponentLookupException e) {
MavenEmbedderLog.LOG.error(e);
} catch (IOException e) {
MavenEmbedderLog.LOG.warn(e);
} catch (XmlPullParserException e) {
MavenEmbedderLog.LOG.warn(e);
}
if (settings == null) {
settings = new Settings();
}
if (embedderSettings.getLocalRepository() != null) {
settings.setLocalRepository(embedderSettings.getLocalRepository().getPath());
}
if (settings.getLocalRepository() == null) {
settings.setLocalRepository(System.getProperty("user.home") + "/.m2/repository");
}
settings.setOffline(embedderSettings.isWorkOffline());
settings.setInteractiveMode(false);
settings.setUsePluginRegistry(embedderSettings.isUsePluginRegistry());
RuntimeInfo runtimeInfo = new RuntimeInfo(settings);
runtimeInfo.setPluginUpdateOverride(embedderSettings.getPluginUpdatePolicy() == MavenEmbedderSettings.UpdatePolicy.ALWAYS_UPDATE);
settings.setRuntimeInfo(runtimeInfo);
return settings;
}
use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project karaf by apache.
the class DependencyHelperFactory method createDependencyHelper.
/**
* <p>Create a new {@link DependencyHelper} based on what has been found in {@link org.codehaus.plexus.PlexusContainer}</p>
*
* <p>{@code karaf-maven-plugin} depends on {@code maven-core:3.0}, so for Maven 3.0.x, it may use this API directly.
* When using Maven 3.1.x/3.2.x, it should use reflection to invoke org.apache.maven.RepositoryUtils.toArtifact(Artifact)
* as this method directly references specific Aether implementation.</p>
*
* <p>When {@code karaf-maven-plugin} switches to {@code maven-core:3.1.0+}, reflection should be use for Sonatype variant of Aether.</p>
*
* @param container The Maven Plexus container to use.
* @param mavenProject The Maven project to use.
* @param mavenSession The Maven session.
* @param log The log to use for the messages.
* @return The {@link DependencyHelper} depending of the Maven version used.
* @throws MojoExecutionException If the plugin execution fails.
*/
public static DependencyHelper createDependencyHelper(PlexusContainer container, MavenProject mavenProject, MavenSession mavenSession, Log log) throws MojoExecutionException {
try {
if (container.hasComponent("org.sonatype.aether.RepositorySystem")) {
org.sonatype.aether.RepositorySystem system = container.lookup(org.sonatype.aether.RepositorySystem.class);
org.sonatype.aether.RepositorySystemSession session = mavenSession.getRepositorySession();
List<RemoteRepository> repositories = mavenProject.getRemoteProjectRepositories();
return new Dependency30Helper(repositories, session, system);
} else if (container.hasComponent("org.eclipse.aether.RepositorySystem")) {
org.eclipse.aether.RepositorySystem system = container.lookup(org.eclipse.aether.RepositorySystem.class);
Object session;
try {
session = MavenSession.class.getMethod("getRepositorySession").invoke(mavenSession);
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}
List<?> repositories = mavenProject.getRemoteProjectRepositories();
return new Dependency31Helper(repositories, session, system);
}
} catch (ComponentLookupException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
throw new MojoExecutionException("Cannot locate either org.sonatype.aether.RepositorySystem or org.eclipse.aether.RepositorySystem");
}
Aggregations