@Override public List<Dependency> resolveVersions( final Dependency dep, final List<DependencyRepository> repositories) { List<Dependency> result = new ArrayList<Dependency>(); List<RemoteRepository> remoteRepos = convertToMavenRepos(repositories); VersionRangeResult r = getVersions(dep, remoteRepos); for (Version v : r.getVersions()) { result.add(DependencyBuilder.create(dep).setVersion(v.toString())); } return result; }
@Override public List<DependencyResource> resolveArtifacts( Dependency dep, final List<DependencyRepository> repositories) { List<DependencyResource> result = new ArrayList<DependencyResource>(); try { RepositorySystem system = container.lookup(RepositorySystem.class); MavenRepositorySystemSession session = setupRepoSession(system); session.setIgnoreInvalidArtifactDescriptor(true); session.setIgnoreMissingArtifactDescriptor(true); VersionRangeResult versions = getVersions(dep, convertToMavenRepos(repositories)); VERSION: for (Version version : versions.getVersions()) { ArtifactRequest request = new ArtifactRequest(); ArtifactRepository ar = versions.getRepository(version); if (ar instanceof RemoteRepository) { RemoteRepository remoteRepo = new RemoteRepository( ar.getId(), ar.getContentType(), ((RemoteRepository) ar).getUrl()); request.addRepository(remoteRepo); DependencyBuilder currentVersion = DependencyBuilder.create(dep).setVersion(version.toString()); request.setArtifact(new DefaultArtifact(currentVersion.toCoordinates())); try { ArtifactResult a = system.resolveArtifact(session, request); File file = a.getArtifact().getFile(); DependencyResource resource = new DependencyResource(factory, file, currentVersion); if (!result.contains(resource)) { result.add(resource); continue VERSION; } } catch (ArtifactResolutionException e) { System.out.println(e.getMessage()); } } } } catch (ComponentLookupException e) { throw new ProjectModelException("Error in dependency resolution container", e); } return result; }