Search in sources :

Example 11 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 12 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)

Example 13 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project maven-plugins by apache.

the class AbstractSiteRenderingMojo method getReports.

protected List<MavenReportExecution> getReports() throws MojoExecutionException {
    List<MavenReportExecution> allReports;
    if (isMaven3OrMore()) {
        // Maven 3
        MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
        mavenReportExecutorRequest.setLocalRepository(localRepository);
        mavenReportExecutorRequest.setMavenSession(mavenSession);
        mavenReportExecutorRequest.setProject(project);
        mavenReportExecutorRequest.setReportPlugins(reportingPlugins);
        MavenReportExecutor mavenReportExecutor;
        try {
            mavenReportExecutor = (MavenReportExecutor) container.lookup(MavenReportExecutor.class.getName());
        } catch (ComponentLookupException e) {
            throw new MojoExecutionException("could not get MavenReportExecutor component", e);
        }
        allReports = mavenReportExecutor.buildMavenReports(mavenReportExecutorRequest);
    } else {
        // Maven 2
        allReports = new ArrayList<MavenReportExecution>(reports.size());
        for (MavenReport report : reports) {
            allReports.add(new MavenReportExecution(report));
        }
    }
    // filter out reports that can't be generated
    List<MavenReportExecution> reportExecutions = new ArrayList<MavenReportExecution>(allReports.size());
    for (MavenReportExecution exec : allReports) {
        if (exec.canGenerateReport()) {
            reportExecutions.add(exec);
        }
    }
    return reportExecutions;
}
Also used : MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) MavenReport(org.apache.maven.reporting.MavenReport) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) MavenReportExecutor(org.apache.maven.reporting.exec.MavenReportExecutor) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenReportExecutorRequest(org.apache.maven.reporting.exec.MavenReportExecutorRequest)

Example 14 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project maven-plugins by apache.

the class DefaultAssemblyArchiver method configureArchiver.

private void configureArchiver(final Archiver archiver, final AssemblerConfigurationSource configSource) {
    Xpp3Dom config;
    try {
        config = Xpp3DomBuilder.build(new StringReader(configSource.getArchiverConfig()));
    } catch (final XmlPullParserException e) {
        throw new ArchiverException("Failed to parse archiver configuration for: " + archiver.getClass().getName(), e);
    } catch (final IOException e) {
        throw new ArchiverException("Failed to parse archiver configuration for: " + archiver.getClass().getName(), e);
    }
    getLogger().debug("Configuring archiver: '" + archiver.getClass().getName() + "' -->");
    try {
        configureComponent(archiver, config, configSource);
    } catch (final ComponentConfigurationException e) {
        throw new ArchiverException("Failed to configure archiver: " + archiver.getClass().getName(), e);
    } catch (final ComponentLookupException e) {
        throw new ArchiverException("Failed to lookup configurator for setup of archiver: " + archiver.getClass().getName(), e);
    }
    getLogger().debug("-- end configuration --");
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) StringReader(java.io.StringReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) IOException(java.io.IOException) ComponentConfigurationException(org.codehaus.plexus.component.configurator.ComponentConfigurationException)

Example 15 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project maven-plugins by apache.

the class PdfMojo method getReports.

protected List<MavenReportExecution> getReports() throws MojoExecutionException {
    if (isMaven3OrMore()) {
        MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
        mavenReportExecutorRequest.setLocalRepository(localRepository);
        mavenReportExecutorRequest.setMavenSession(session);
        mavenReportExecutorRequest.setProject(project);
        mavenReportExecutorRequest.setReportPlugins(reportPlugins);
        MavenReportExecutor mavenReportExecutor;
        try {
            mavenReportExecutor = (MavenReportExecutor) container.lookup(MavenReportExecutor.class.getName());
        } catch (ComponentLookupException e) {
            throw new MojoExecutionException("could not get MavenReportExecutor component", e);
        }
        return mavenReportExecutor.buildMavenReports(mavenReportExecutorRequest);
    }
    List<MavenReportExecution> reportExecutions = new ArrayList<MavenReportExecution>(reports.length);
    for (MavenReport report : reports) {
        if (report.canGenerateReport()) {
            reportExecutions.add(new MavenReportExecution(report));
        }
    }
    return reportExecutions;
}
Also used : MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) MavenReport(org.apache.maven.reporting.MavenReport) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) MavenReportExecutor(org.apache.maven.reporting.exec.MavenReportExecutor) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenReportExecutorRequest(org.apache.maven.reporting.exec.MavenReportExecutorRequest)

Aggregations

ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)15 ArrayList (java.util.ArrayList)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 IOException (java.io.IOException)3 LinkedHashSet (java.util.LinkedHashSet)3 Artifact (org.apache.maven.artifact.Artifact)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 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)3 DefaultMetadataResolutionRequest (org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest)3 MetadataResolutionRequest (org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest)3 ComponentConfigurationException (org.codehaus.plexus.component.configurator.ComponentConfigurationException)3 LinkedHashMap (java.util.LinkedHashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)2 MavenReport (org.apache.maven.reporting.MavenReport)2 MavenReportExecution (org.apache.maven.reporting.exec.MavenReportExecution)2