Search in sources :

Example 1 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException in project che by eclipse.

the class CheArtifactResolver method resolve.

// ------------------------------------------------------------------------
//
// ------------------------------------------------------------------------
public ArtifactResolutionResult resolve(ArtifactResolutionRequest request) {
    Artifact rootArtifact = request.getArtifact();
    Set<Artifact> artifacts = request.getArtifactDependencies();
    Map<String, Artifact> managedVersions = request.getManagedVersionMap();
    List<ResolutionListener> listeners = request.getListeners();
    ArtifactFilter collectionFilter = request.getCollectionFilter();
    ArtifactFilter resolutionFilter = request.getResolutionFilter();
    RepositorySystemSession session = getSession(request.getLocalRepository());
    //TODO: hack because metadata isn't generated in m2e correctly and i want to run the maven i have in the workspace
    if (source == null) {
        try {
            source = container.lookup(ArtifactMetadataSource.class);
        } catch (ComponentLookupException e) {
        // won't happen
        }
    }
    if (listeners == null) {
        listeners = new ArrayList<ResolutionListener>();
        if (logger.isDebugEnabled()) {
            listeners.add(new DebugResolutionListener(logger));
        }
        listeners.add(new WarningResolutionListener(logger));
    }
    ArtifactResolutionResult result = new ArtifactResolutionResult();
    if (request.isResolveRoot()) /* && rootArtifact.getFile() == null */
    {
        try {
            resolve(rootArtifact, request.getRemoteRepositories(), session);
        } catch (ArtifactResolutionException e) {
            result.addErrorArtifactException(e);
            return result;
        } catch (ArtifactNotFoundException e) {
            result.addMissingArtifact(request.getArtifact());
            return result;
        }
    }
    ArtifactResolutionRequest collectionRequest = request;
    if (request.isResolveTransitively()) {
        MetadataResolutionRequest metadataRequest = new DefaultMetadataResolutionRequest(request);
        metadataRequest.setArtifact(rootArtifact);
        metadataRequest.setResolveManagedVersions(managedVersions == null);
        try {
            ResolutionGroup resolutionGroup = source.retrieve(metadataRequest);
            if (managedVersions == null) {
                managedVersions = resolutionGroup.getManagedVersions();
            }
            Set<Artifact> directArtifacts = resolutionGroup.getArtifacts();
            if (artifacts == null || artifacts.isEmpty()) {
                artifacts = directArtifacts;
            } else {
                List<Artifact> allArtifacts = new ArrayList<Artifact>();
                allArtifacts.addAll(artifacts);
                allArtifacts.addAll(directArtifacts);
                Map<String, Artifact> mergedArtifacts = new LinkedHashMap<String, Artifact>();
                for (Artifact artifact : allArtifacts) {
                    String conflictId = artifact.getDependencyConflictId();
                    if (!mergedArtifacts.containsKey(conflictId)) {
                        mergedArtifacts.put(conflictId, artifact);
                    }
                }
                artifacts = new LinkedHashSet<Artifact>(mergedArtifacts.values());
            }
            collectionRequest = new ArtifactResolutionRequest(request);
            collectionRequest.setServers(request.getServers());
            collectionRequest.setMirrors(request.getMirrors());
            collectionRequest.setProxies(request.getProxies());
            collectionRequest.setRemoteRepositories(resolutionGroup.getResolutionRepositories());
        } catch (ArtifactMetadataRetrievalException e) {
            ArtifactResolutionException are = new ArtifactResolutionException("Unable to get dependency information for " + rootArtifact.getId() + ": " + e.getMessage(), rootArtifact, metadataRequest.getRemoteRepositories(), e);
            result.addMetadataResolutionException(are);
            return result;
        }
    }
    if (artifacts == null || artifacts.isEmpty()) {
        if (request.isResolveRoot()) {
            result.addArtifact(rootArtifact);
        }
        return result;
    }
    // After the collection we will have the artifact object in the result but they will not be resolved yet.
    result = artifactCollector.collect(artifacts, rootArtifact, managedVersions, collectionRequest, source, collectionFilter, listeners, null);
    if (result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions()) {
        return result;
    }
    if (result.getArtifactResolutionNodes() != null) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        CountDownLatch latch = new CountDownLatch(result.getArtifactResolutionNodes().size());
        for (ResolutionNode node : result.getArtifactResolutionNodes()) {
            Artifact artifact = node.getArtifact();
            if (resolutionFilter == null || resolutionFilter.include(artifact)) {
                executor.execute(new ResolveTask(classLoader, latch, artifact, session, node.getRemoteRepositories(), result));
            } else {
                latch.countDown();
            }
        }
        try {
            latch.await();
        } catch (InterruptedException e) {
            result.addErrorArtifactException(new ArtifactResolutionException("Resolution interrupted", rootArtifact, e));
        }
    }
    // have been resolved.
    if (request.isResolveRoot()) {
        // Add the root artifact (as the first artifact to retain logical order of class path!)
        Set<Artifact> allArtifacts = new LinkedHashSet<Artifact>();
        allArtifacts.add(rootArtifact);
        allArtifacts.addAll(result.getArtifacts());
        result.setArtifacts(allArtifacts);
    }
    return result;
}
Also used : DefaultMetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest) MetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest) LinkedHashSet(java.util.LinkedHashSet) ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException) ArrayList(java.util.ArrayList) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) LinkedHashMap(java.util.LinkedHashMap) DefaultMetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) DebugResolutionListener(org.apache.maven.artifact.resolver.DebugResolutionListener) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ResolutionListener(org.apache.maven.artifact.resolver.ResolutionListener) DebugResolutionListener(org.apache.maven.artifact.resolver.DebugResolutionListener) WarningResolutionListener(org.apache.maven.artifact.resolver.WarningResolutionListener) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ResolutionNode(org.apache.maven.artifact.resolver.ResolutionNode) ResolutionGroup(org.apache.maven.artifact.metadata.ResolutionGroup) CountDownLatch(java.util.concurrent.CountDownLatch) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) WarningResolutionListener(org.apache.maven.artifact.resolver.WarningResolutionListener) ArtifactMetadataSource(org.apache.maven.artifact.metadata.ArtifactMetadataSource)

Example 2 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method resolveTransitively.

@NotNull
@Override
public List<MavenArtifact> resolveTransitively(@NotNull List<MavenArtifactInfo> artifacts, @NotNull List<MavenRemoteRepository> remoteRepositories) throws RemoteException, MavenServerProcessCanceledException {
    try {
        Set<Artifact> toResolve = new LinkedHashSet<Artifact>();
        for (MavenArtifactInfo each : artifacts) {
            toResolve.add(createArtifact(each));
        }
        Artifact project = getComponent(ArtifactFactory.class).createBuildArtifact("temp", "temp", "666", "pom");
        Set<Artifact> res = getComponent(ArtifactResolver.class).resolveTransitively(toResolve, project, Collections.EMPTY_MAP, myLocalRepository, convertRepositories(remoteRepositories), getComponent(ArtifactMetadataSource.class)).getArtifacts();
        return MavenModelConverter.convertArtifacts(res, new THashMap<Artifact, MavenArtifact>(), getLocalRepositoryFile());
    } catch (ArtifactResolutionException e) {
        Maven3ServerGlobals.getLogger().info(e);
    } catch (ArtifactNotFoundException e) {
        Maven3ServerGlobals.getLogger().info(e);
    } catch (Exception e) {
        throw rethrowException(e);
    }
    return Collections.emptyList();
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) RemoteException(java.rmi.RemoteException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException in project maven-plugins by apache.

the class ResourceResolver method resolveBundlesFromArtifacts.

private List<JavadocBundle> resolveBundlesFromArtifacts(final SourceResolverConfig config, final List<Artifact> artifacts) throws IOException {
    final List<Artifact> toResolve = new ArrayList<Artifact>(artifacts.size());
    for (final Artifact artifact : artifacts) {
        if (config.filter() != null && !new ArtifactIncludeFilterTransformer().transform(config.filter()).include(artifact)) {
            continue;
        }
        if (config.includeCompileSources()) {
            toResolve.add(createResourceArtifact(artifact, AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, config));
        }
        if (config.includeTestSources()) {
            toResolve.add(createResourceArtifact(artifact, AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, config));
        }
    }
    List<String> dirs = null;
    try {
        dirs = resolveAndUnpack(toResolve, config, RESOURCE_VALID_CLASSIFIERS, false);
    } catch (ArtifactResolutionException e) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(e.getMessage(), e);
        }
    } catch (ArtifactNotFoundException e) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(e.getMessage(), e);
        }
    }
    List<JavadocBundle> result = new ArrayList<JavadocBundle>();
    if (dirs != null) {
        for (String d : dirs) {
            File dir = new File(d);
            File resources = new File(dir, ResourcesBundleMojo.RESOURCES_DIR_PATH);
            JavadocOptions options = null;
            File javadocOptions = new File(dir, ResourcesBundleMojo.BUNDLE_OPTIONS_PATH);
            if (javadocOptions.exists()) {
                FileInputStream reader = null;
                try {
                    reader = new FileInputStream(javadocOptions);
                    options = new JavadocOptionsXpp3Reader().read(reader);
                } catch (XmlPullParserException e) {
                    IOException error = new IOException("Failed to parse javadoc options: " + e.getMessage());
                    error.initCause(e);
                    throw error;
                } finally {
                    close(reader);
                }
            }
            result.add(new JavadocBundle(options, resources));
        }
    }
    return result;
}
Also used : ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) FileInputStream(java.io.FileInputStream) JavadocOptionsXpp3Reader(org.apache.maven.plugin.javadoc.options.io.xpp3.JavadocOptionsXpp3Reader) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) JavadocOptions(org.apache.maven.plugin.javadoc.options.JavadocOptions) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) File(java.io.File)

Example 4 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException in project maven-plugins by apache.

the class RepositoryUtils method getDependencyUrlFromRepository.

/**
     * @param artifact not null
     * @param repo not null
     * @return the artifact url in the given repo for the given artifact. If it is a snapshot artifact, the version
     * will be the timestamp and the build number from the metadata. Could return null if the repo is blacklisted.
     */
public String getDependencyUrlFromRepository(Artifact artifact, ArtifactRepository repo) {
    if (repo.isBlacklisted()) {
        return null;
    }
    Artifact copyArtifact = ArtifactUtils.copyArtifact(artifact);
    // Try to get the last artifact repo name depending the snapshot version
    if ((artifact.isSnapshot() && repo.getSnapshots().isEnabled())) {
        if (artifact.getBaseVersion().equals(artifact.getVersion())) {
            // Try to resolve it if not already done
            if (artifact.getMetadataList() == null || artifact.getMetadataList().isEmpty()) {
                try {
                    resolve(artifact);
                } catch (ArtifactResolutionException e) {
                    log.error("Artifact: " + artifact.getId() + " could not be resolved.");
                } catch (ArtifactNotFoundException e) {
                    log.error("Artifact: " + artifact.getId() + " was not found.");
                }
            }
            for (ArtifactMetadata m : artifact.getMetadataList()) {
                if (m instanceof SnapshotArtifactRepositoryMetadata) {
                    SnapshotArtifactRepositoryMetadata snapshotMetadata = (SnapshotArtifactRepositoryMetadata) m;
                    Metadata metadata = snapshotMetadata.getMetadata();
                    Versioning versioning = metadata.getVersioning();
                    if (versioning == null || versioning.getSnapshot() == null || versioning.getSnapshot().isLocalCopy() || versioning.getSnapshot().getTimestamp() == null) {
                        continue;
                    }
                    // create the version according SnapshotTransformation
                    String version = StringUtils.replace(copyArtifact.getVersion(), Artifact.SNAPSHOT_VERSION, versioning.getSnapshot().getTimestamp()) + "-" + versioning.getSnapshot().getBuildNumber();
                    copyArtifact.setVersion(version);
                }
            }
        }
    }
    return repo.getUrl() + "/" + repo.pathOf(copyArtifact);
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) ArtifactMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ArtifactMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException in project maven-plugins by apache.

the class PdfMojo method getMavenReport.

/**
     * @param mojoDescriptor not null
     * @return the MavenReport instance for the given mojoDescriptor.
     * @throws MojoExecutionException if any
     * @since 1.1
     */
private MavenReport getMavenReport(MojoDescriptor mojoDescriptor) throws MojoExecutionException {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(mojoDescriptor.getPluginDescriptor().getClassRealm().getClassLoader());
        MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
        return pluginManager.getReport(project, mojoExecution, session);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException("ArtifactNotFoundException: " + e.getMessage(), e);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("ArtifactResolutionException: " + e.getMessage(), e);
    } catch (PluginConfigurationException e) {
        throw new MojoExecutionException("PluginConfigurationException: " + e.getMessage(), e);
    } catch (PluginManagerException e) {
        throw new MojoExecutionException("PluginManagerException: " + e.getMessage(), e);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoExecution(org.apache.maven.plugin.MojoExecution) PluginConfigurationException(org.apache.maven.plugin.PluginConfigurationException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) PluginManagerException(org.apache.maven.plugin.PluginManagerException)

Aggregations

ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)20 Artifact (org.apache.maven.artifact.Artifact)15 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 File (java.io.File)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)2 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)2 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)2 SnapshotArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)2 AbstractArtifactResolutionException (org.apache.maven.artifact.resolver.AbstractArtifactResolutionException)2 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 VersionRange (org.apache.maven.artifact.versioning.VersionRange)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 MavenProject (org.apache.maven.project.MavenProject)2 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 TransformableFilter (org.apache.maven.shared.artifact.filter.resolve.TransformableFilter)2