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;
}
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();
}
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;
}
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);
}
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);
}
}
Aggregations