List of usage examples for org.apache.maven.artifact.resolver ArtifactResolutionException ArtifactResolutionException
public ArtifactResolutionException(String message, Artifact artifact,
List<ArtifactRepository> remoteRepositories, Throwable cause)
From source file:org.eclipse.che.maven.CheArtifactResolver.java
License:Apache License
private void resolveOrig(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException { if (artifact == null) { return;// w w w . java2s. c om } if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) { File systemFile = artifact.getFile(); if (systemFile == null) { throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact); } if (!systemFile.exists()) { throw new ArtifactNotFoundException( "System artifact: " + artifact + " not found in path: " + systemFile, artifact); } if (!systemFile.isFile()) { throw new ArtifactNotFoundException( "System artifact: " + artifact + " is not a file: " + systemFile, artifact); } artifact.setResolved(true); return; } if (!artifact.isResolved()) { ArtifactResult result; try { ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact)); artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories)); // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not LocalRepositoryManager lrm = session.getLocalRepositoryManager(); String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact()); artifact.setFile(new File(lrm.getRepository().getBasedir(), path)); result = repoSystem.resolveArtifact(session, artifactRequest); } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) { if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) { throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), e); } else { throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e); } } artifact.selectVersion(result.getArtifact().getVersion()); artifact.setFile(result.getArtifact().getFile()); artifact.setResolved(true); if (artifact.isSnapshot()) { Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion()); if (matcher.matches()) { Snapshot snapshot = new Snapshot(); snapshot.setTimestamp(matcher.group(2)); try { snapshot.setBuildNumber(Integer.parseInt(matcher.group(3))); artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot)); } catch (NumberFormatException e) { logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage()); } } } } }
From source file:org.eclipse.che.maven.CheArtifactResolver.java
License:Apache License
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 {/* w w w . j a va2 s.c o m*/ 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(); // The root artifact may, or may not be resolved so we need to check before we attempt to resolve. // This is often an artifact like a POM that is taken from disk and we already have hold of the // file reference. But this may be a Maven Plugin that we need to resolve from a remote repository // as well as its dependencies. 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); // We have metadata retrieval problems, or there are cycles that have been detected // so we give this back to the calling code and let them deal with this information // appropriately. 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)); } } // We want to send the root artifact back in the result but we need to do this after the other dependencies // 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; }
From source file:org.jetbrains.idea.maven.server.embedder.CustomMaven32ArtifactResolver.java
License:Apache License
private void resolveOld(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException { if (artifact == null) { return;/*from w w w . jav a2 s . c o m*/ } if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) { File systemFile = artifact.getFile(); if (systemFile == null) { throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact); } if (!systemFile.exists()) { throw new ArtifactNotFoundException( "System artifact: " + artifact + " not found in path: " + systemFile, artifact); } if (!systemFile.isFile()) { throw new ArtifactNotFoundException( "System artifact: " + artifact + " is not a file: " + systemFile, artifact); } artifact.setResolved(true); return; } if (!artifact.isResolved()) { ArtifactResult result; try { ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact)); artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories)); // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not LocalRepositoryManager lrm = session.getLocalRepositoryManager(); String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact()); artifact.setFile(new File(lrm.getRepository().getBasedir(), path)); result = repoSystem.resolveArtifact(session, artifactRequest); } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) { if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) { throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), e); } else { throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e); } } artifact.selectVersion(result.getArtifact().getVersion()); artifact.setFile(result.getArtifact().getFile()); artifact.setResolved(true); if (artifact.isSnapshot()) { Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion()); if (matcher.matches()) { Snapshot snapshot = new Snapshot(); snapshot.setTimestamp(matcher.group(2)); try { snapshot.setBuildNumber(Integer.parseInt(matcher.group(3))); artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot)); } catch (NumberFormatException e) { logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage()); } } } } }
From source file:org.jetbrains.idea.maven.server.embedder.CustomMaven32ArtifactResolver.java
License:Apache License
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 {/*ww w . j av a2 s . c om*/ 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(); // The root artifact may, or may not be resolved so we need to check before we attempt to resolve. // This is often an artifact like a POM that is taken from disk and we already have hold of the // file reference. But this may be a Maven Plugin that we need to resolve from a remote repository // as well as its dependencies. 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); // We have metadata retrieval problems, or there are cycles that have been detected // so we give this back to the calling code and let them deal with this information // appropriately. 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)); } } // We want to send the root artifact back in the result but we need to do this after the other dependencies // 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; }