private static Map<String, String> transformArtifactResultToArtifactToPaths(List<ArtifactResult> artifactResults) { Map<String, String> artifactToPath = new LinkedHashMap<>(); for (ArtifactResult artifactResult : artifactResults) { Artifact artifact = artifactResult.getArtifact(); artifactToPath.put(AetherUtils.artifactToString(artifact), artifact.getFile().getAbsolutePath()); } return artifactToPath; }
public Path findMavenArtifact( final Artifact artifact) throws MavenArtifactNotFoundException { final ArtifactResult result; try { result = this.repositorySystem.resolveArtifact( this.repositorySystemSession, new ArtifactRequest().setArtifact(artifact)); } catch (ArtifactResolutionException ex) { throw new MavenArtifactNotFoundException(artifact, this.givenLocalMavenRepositoryPath, this.absoluteLocalMavenRepositoryPath, ex); } return result.getArtifact().getFile().toPath(); }
@Override public ModelSource resolveModel( String groupId, String artifactId, String version ) throws UnresolvableModelException { Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version ); try { ArtifactRequest request = new ArtifactRequest( pomArtifact, repositories, context ); request.setTrace( trace ); pomArtifact = resolver.resolveArtifact( session, request ).getArtifact(); } catch ( ArtifactResolutionException e ) { throw new UnresolvableModelException( e.getMessage(), groupId, artifactId, version, e ); } File pomFile = pomArtifact.getFile(); return new FileModelSource( pomFile ); }
artifact.selectVersion( result.getArtifact().getVersion() ); artifact.setFile( result.getArtifact().getFile() ); artifact.setResolved( true );
pluginArtifact = repoSystem.resolveArtifact( session, request ).getArtifact();
public ModelSource resolveModel( String groupId, String artifactId, String version ) throws UnresolvableModelException { File pomFile = null; if ( modelPool != null ) { pomFile = modelPool.get( groupId, artifactId, version ); } if ( pomFile == null ) { Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version ); try { ArtifactRequest request = new ArtifactRequest( pomArtifact, repositories, context ); request.setTrace( trace ); pomArtifact = resolver.resolveArtifact( session, request ).getArtifact(); } catch ( ArtifactResolutionException e ) { throw new UnresolvableModelException( e.getMessage(), groupId, artifactId, version, e ); } pomFile = pomArtifact.getFile(); } return new FileModelSource( pomFile ); }
ArtifactResult pomResult = repoSystem.resolveArtifact( config.session, pomRequest ); pomArtifact = pomResult.getArtifact(); localProject = pomResult.getRepository() instanceof WorkspaceRepository;
private List<URL> buildApplicationUrlClassification(final ClassPathClassifierContext context, final List<Dependency> directDependencies, final List<RemoteRepository> rootArtifactRemoteRepositories) { List<URL> applicationLibUrls = newArrayList(); List<Dependency> applicationLibDependencies = context.getApplicationLibCoordinates().stream() .map(applicationLibCoords -> findApplicationLibArtifact(applicationLibCoords, context.getRootArtifact(), directDependencies)) .collect(toList()); logger.debug("Application lib artifacts matched with versions from direct dependencies declared: {}", applicationLibDependencies); applicationLibDependencies.stream() .map(pluginSharedLibDependency -> { try { return dependencyResolver.resolveArtifact(pluginSharedLibDependency.getArtifact(), rootArtifactRemoteRepositories) .getArtifact().getFile().toURI().toURL(); } catch (Exception e) { throw new IllegalStateException("Error while resolving dependency '" + pluginSharedLibDependency + "' as application lib", e); } }) .forEach(applicationLibUrls::add); resolveSnapshotVersionsToTimestampedFromClassPath(applicationLibUrls, context.getClassPathURLs()); logger.debug("Classified URLs as application runtime libraries: '{}", applicationLibUrls); return applicationLibUrls; }
/** * Resolves the rootArtifact {@link URL}s resources to be added to class loader. * * @param artifact {@link Artifact} being classified * @return {@link List} of {@link URL}s to be added to class loader * @throws {@link ArtifactResolutionException} if the artifact doesn't have a JAR output file (target/classes when not packaged) */ private URL resolveRootArtifactUrls(Artifact artifact) throws ArtifactResolutionException { final DefaultArtifact jarArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), JAR_EXTENSION, JAR_EXTENSION, artifact.getVersion()); try { return dependencyResolver.resolveArtifact(jarArtifact).getArtifact().getFile().toURI().toURL(); } catch (MalformedURLException e) { throw new IllegalStateException("Couldn't generate the URL for artifact: " + artifact); } } }
public static void main(String[] args) throws ArtifactResolutionException { System.out.println("------------------------------------------------------------"); System.out.println(RemotePluginRepository.class.getSimpleName()); RepositorySystem system = newRepositorySystem(); RepositorySystemSession session = newRepositorySystemSession(system); Artifact artifact = new DefaultArtifact("org.eclipse.aether:aether-util:1.0.0.v20140518"); ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifact); artifactRequest.setRepositories(newRepositories(system, session)); ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest); artifact = artifactResult.getArtifact(); System.out.println(artifact + " resolved to " + artifact.getFile()); }
/** * Searches in the plugin pom.xml for the {@code testExtensionModelLoaderId} property which specifies with which loader the * extension must be loaded. The main use of this is for Test Extensions that don't generate a mule-artifact.json. */ public Optional<ExtensionModelLoader> findLoaderByProperty(Artifact plugin, DependencyResolver dependencyResolver, List<RemoteRepository> rootArtifactRemoteRepositories) { DefaultArtifact artifact = new DefaultArtifact(plugin.getGroupId(), plugin.getArtifactId(), "pom", plugin.getVersion()); try { ArtifactResult artifactResult = dependencyResolver.resolveArtifact(artifact, rootArtifactRemoteRepositories); File pomFile = artifactResult.getArtifact().getFile(); Model mavenProject = MavenModelFactory.createMavenProject(pomFile); String id = mavenProject.getProperties().getProperty("testExtensionModelLoaderId"); return id != null ? Optional.ofNullable(getLoaderById(id)) : Optional.empty(); } catch (ArtifactResolutionException e) { throw new RuntimeException("Cannot load extension, the artifact: [" + plugin.toString() + "] cannot be resolved", e); } } }
public Path getVersionJar(String version) throws ArtifactResolutionException { Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "jar", version.toString()); ArtifactRequest request = new ArtifactRequest(); request.setArtifact(versionArtifact); request.setRepositories(mavenPluginRepository.getRepositories()); ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request); return resolveArtifact.getArtifact().getFile().toPath(); }
public Path getVersionPom(String version) throws ArtifactResolutionException { Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "pom", version.toString()); ArtifactRequest request = new ArtifactRequest(); request.setArtifact(pomArtifact); request.setRepositories(mavenPluginRepository.getRepositories()); ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request); return resolveArtifact.getArtifact().getFile().toPath(); }
/** * Resolves the rootArtifact {@value #JAR_EXTENSION} output {@link File}s to be added to class loader. * * @param rootArtifact {@link Artifact} being classified * @return {@link File} to be added to class loader */ private File resolveRootArtifactFile(Artifact rootArtifact) { final DefaultArtifact jarArtifact = new DefaultArtifact(rootArtifact.getGroupId(), rootArtifact.getArtifactId(), JAR_EXTENSION, JAR_EXTENSION, rootArtifact.getVersion()); try { return dependencyResolver.resolveArtifact(jarArtifact).getArtifact().getFile(); } catch (ArtifactResolutionException e) { logger.warn("'{}' rootArtifact output {} file couldn't be resolved", rootArtifact, JAR_EXTENSION); return null; } }
public byte[] getVersionIcon(String version) throws ArtifactResolutionException, IOException { Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "icon", "png", version.toString()); ArtifactRequest request = new ArtifactRequest(); request.setArtifact(versionArtifact); request.setRepositories(mavenPluginRepository.getRepositories()); ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request); return FileUtils.readFileToByteArray(resolveArtifact.getArtifact().getFile()); }
public byte[] getVersionPluginXml(String version) throws ArtifactResolutionException, IOException { // return getJarContent(version, "plugin/plugin.xml"); Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "plugin", "xml", version.toString()); ArtifactRequest request = new ArtifactRequest(); request.setArtifact(versionArtifact); request.setRepositories(mavenPluginRepository.getRepositories()); ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request); byte[] bytes = FileUtils.readFileToByteArray(resolveArtifact.getArtifact().getFile()); return bytes; }
resolveRequest.setTrace( trace ); resolveResult = artifactResolver.resolveArtifact( session, resolveRequest ); pomArtifact = resolveResult.getArtifact(); result.setRepository( resolveResult.getRepository() );
@Override public File lookupBundle(BundleDependency bundleDependency) { try { if (remoteRepositories.isEmpty()) { throw new RepositoryServiceDisabledException("Repository service has not been configured so it's disabled. " + "To enable it you must configure the set of repositories to use using the system property: " + MULE_REMOTE_REPOSITORIES_PROPERTY); } DefaultArtifact artifact = toArtifact(bundleDependency); ArtifactRequest getArtifactRequest = new ArtifactRequest(); getArtifactRequest.setRepositories(remoteRepositories); getArtifactRequest.setArtifact(artifact); ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, getArtifactRequest); return artifactResult.getArtifact().getFile(); } catch (ArtifactResolutionException e) { if (e.getCause() instanceof ArtifactNotFoundException) { throw new BundleNotFoundException(e); } else { throw new RepositoryConnectionException("There was a problem connecting to one of the repositories", e); } } }
public String getLatestVersionString() { Artifact lastArt = new DefaultArtifact(groupId, artifactId, "jar", "LATEST"); ArtifactRequest request = new ArtifactRequest(); request.setArtifact(lastArt); request.setRepositories(mavenPluginRepository.getRepositories()); try { ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request); return resolveArtifact.getArtifact().getVersion(); } catch (ArtifactResolutionException e1) { e1.printStackTrace(); } return null; }
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request); File pomFile = resolveArtifact.getArtifact().getFile(); MavenXpp3Reader mavenreader = new MavenXpp3Reader();