Search in sources :

Example 16 with ComponentLookupException

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);
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) MavenSession(org.apache.maven.execution.MavenSession) LegacySupport(org.apache.maven.plugin.LegacySupport) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) DefaultMaven(org.apache.maven.DefaultMaven) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException)

Example 17 with ComponentLookupException

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;
}
Also used : ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) Settings(org.apache.maven.settings.Settings)

Example 18 with ComponentLookupException

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) AbstractMavenLifecycleParticipant(org.apache.maven.AbstractMavenLifecycleParticipant) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 19 with ComponentLookupException

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;
}
Also used : ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File)

Example 20 with ComponentLookupException

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");
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenSession(org.apache.maven.execution.MavenSession) List(java.util.List)

Aggregations

ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)40 IOException (java.io.IOException)11 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 ArrayList (java.util.ArrayList)6 PostConstruct (javax.annotation.PostConstruct)6 File (java.io.File)5 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)5 Artifact (org.apache.maven.artifact.Artifact)4 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)4 MavenSession (org.apache.maven.execution.MavenSession)4 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)4 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)3 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)3 ArtifactMetadataSource (org.apache.maven.artifact.metadata.ArtifactMetadataSource)3 ResolutionGroup (org.apache.maven.artifact.metadata.ResolutionGroup)3 DefaultMetadataResolutionRequest (org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest)3 MetadataResolutionRequest (org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest)3