本文整理汇总了Java中org.eclipse.aether.resolution.ArtifactRequest类的典型用法代码示例。如果您正苦于以下问题:Java ArtifactRequest类的具体用法?Java ArtifactRequest怎么用?Java ArtifactRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ArtifactRequest类属于org.eclipse.aether.resolution包,在下文中一共展示了ArtifactRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveModel
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
@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, null);
pomArtifact = system.resolveArtifact(session, request).getArtifact();
} catch (org.eclipse.aether.resolution.ArtifactResolutionException ex) {
throw new UnresolvableModelException(ex.getMessage(), groupId, artifactId, version, ex);
}
File pomFile = pomArtifact.getFile();
return new FileModelSource(pomFile);
}
示例2: fillfromExtraDependencies
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
protected void fillfromExtraDependencies(final Manifest manifest, final Map<String, File> files)
throws IOException, MojoExecutionException {
if (this.additionalDependencies != null) {
try {
final Collection<ArtifactRequest> requests = new ArrayList<>(this.additionalDependencies.length);
for (final Dependency dep : this.additionalDependencies) {
final DefaultArtifact art = new DefaultArtifact(dep.getGroupId(), dep.getArtifactId(),
dep.getClassifier(), dep.getType(), dep.getVersion());
final org.eclipse.aether.graph.Dependency adep = new org.eclipse.aether.graph.Dependency(art,
JavaScopes.RUNTIME);
requests.add(new ArtifactRequest(new DefaultDependencyNode(adep)));
}
final List<ArtifactResult> result = this.resolver.resolveArtifacts(this.repositorySession, requests);
for (final ArtifactResult ares : result) {
getLog().debug("Additional dependency: " + ares);
processArtifact(manifest, files, ares.getArtifact().getFile());
}
} catch (final ArtifactResolutionException e) {
throw new MojoExecutionException("Failed to resolve additional dependencies", e);
}
}
}
示例3: load
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
@Override
public Optional<ArtifactResult> load(ArtifactCoordinates coordinates) throws Exception {
Artifact artifact = new DefaultArtifact(coordinates.toString());
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
artifactRequest.setRepositories(this.remoteProjectRepos);
ArtifactResult artifactResult;
try {
artifactResult = this.repoSystem.resolveArtifact(this.repoSession, artifactRequest);
} catch (ArtifactResolutionException e) {
// must not throw the error or log as an error since this is an expected behavior
artifactResult = null;
}
return Optional.fromNullable(artifactResult);
}
示例4: resolvePluginDependency
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
/**
* Uses the aether to resolve a plugin dependency and returns the file for further processing.
*
* @param d the dependency to resolve.
* @param pluginRepos the plugin repositories to use for dependency resolution.
* @param resolver the resolver for aether access.
* @param repoSystemSession the session for the resolver.
* @return optionally a file which is the resolved dependency.
*/
public static Optional<File> resolvePluginDependency(Dependency d, List<RemoteRepository> pluginRepos,
ArtifactResolver resolver, RepositorySystemSession repoSystemSession) {
Artifact a = new DefaultArtifact(d.getGroupId(), d.getArtifactId(), d.getClassifier(), d.getType(), d.getVersion());
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(a);
artifactRequest.setRepositories(pluginRepos);
try {
ArtifactResult artifactResult = resolver.resolveArtifact(repoSystemSession, artifactRequest);
if (artifactResult.getArtifact() != null) {
return Optional.fromNullable(artifactResult.getArtifact().getFile());
}
return Optional.absent();
} catch (ArtifactResolutionException e) {
return Optional.absent();
}
}
示例5: download
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
public List<ArtifactDescriptor> download(List<ArtifactInfo> unresolvedArtifacts) throws IOException {
List<RemoteRepository> repositories = this.remoteRepositories;
List<ArtifactRequest> artifactRequests = unresolvedArtifacts.stream()
.map(dependency -> {
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(dependency.artifact);
artifactRequest.setRepositories(repositories);
return artifactRequest;
})
.collect(Collectors.toList());
List<ArtifactResult> artifactResults;
try {
artifactResults = system.resolveArtifacts(session, artifactRequests);
} catch (ArtifactResolutionException e) {
throw new IOException(e);
}
return artifactResults.stream()
.map(result -> new ArtifactDescriptor(result.getArtifact()))
.collect(Collectors.toList());
}
示例6: getArtifact
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
private File getArtifact(final String groupId, final String artifactId, final String classifier, final String extension, final String version) throws MojoExecutionException {
final DefaultArtifact artifact = new DefaultArtifact(groupId, artifactId, classifier, extension, version);
final LocalArtifactRequest localRequest = new LocalArtifactRequest(artifact, projectRepoList, null);
final LocalRepositoryManager localManager = repoSession.getLocalRepositoryManager();
final LocalArtifactResult localResult = localManager.find(repoSession, localRequest);
if (localResult.isAvailable()) {
return localResult.getFile();
}
try {
final ArtifactRequest remoteRequest = new ArtifactRequest(artifact, projectRepoList, null);
final ArtifactResult remoteResult = repoSystem.resolveArtifact(repoSession, remoteRequest);
return remoteResult.getArtifact().getFile();
}
catch (final ArtifactResolutionException e) {
throw new MojoExecutionException("Could not retrieve artifact", e);
}
}
示例7: resolve
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
private URL resolve( Artifact artifact )
throws MojoExecutionException
{
ArtifactRequest request = new ArtifactRequest( artifact, remoteRepository, null );
try
{
return
repositorySystem
.resolveArtifact( repositorySession, request )
.getArtifact()
.getFile()
.toURI()
.toURL();
}
catch ( ArtifactResolutionException | MalformedURLException e )
{
throw new MojoExecutionException( "Cannot resolve artifact: " + artifact, e );
}
}
示例8: preparePlain
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
/**
* Prepare a plain import process
* <p>
* Prepare a simple import request with a specific list of coordinates
* </p>
*/
public static AetherResult preparePlain ( final Path tmpDir, final ImportConfiguration cfg ) throws ArtifactResolutionException
{
Objects.requireNonNull ( tmpDir );
Objects.requireNonNull ( cfg );
final RepositoryContext ctx = new RepositoryContext ( tmpDir, cfg.getRepositoryUrl (), cfg.isAllOptional () );
// extend
final List<ArtifactRequest> requests = extendRequests ( cfg.getCoordinates ().stream ().map ( c -> {
final DefaultArtifact artifact = new DefaultArtifact ( c.toString () );
return makeRequest ( ctx.getRepositories (), artifact );
} ), ctx, cfg );
// process
return asResult ( resolve ( ctx, requests ), cfg, empty () );
}
示例9: processImport
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
/**
* Process the actual import request
* <p>
* This method takes the import configuration as is and simply tries to
* import it. Not manipulating the list of coordinates any more
* </p>
*/
public static Collection<ArtifactResult> processImport ( final Path tmpDir, final ImportConfiguration cfg ) throws ArtifactResolutionException
{
Objects.requireNonNull ( tmpDir );
Objects.requireNonNull ( cfg );
final RepositoryContext ctx = new RepositoryContext ( tmpDir, cfg.getRepositoryUrl () );
final Collection<ArtifactRequest> requests = new LinkedList<> ();
for ( final MavenCoordinates coords : cfg.getCoordinates () )
{
// main artifact
final DefaultArtifact main = new DefaultArtifact ( coords.toString () );
requests.add ( makeRequest ( ctx.getRepositories (), main ) );
}
// process
return ctx.getSystem ().resolveArtifacts ( ctx.getSession (), requests );
}
示例10: resolveArtifact
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
private File resolveArtifact(final String group,
final String name,
final String version,
final String classifier,
final String type) throws ArtifactResolutionException {
final DefaultArtifact artifact = new DefaultArtifact(group, name, classifier, type, version);
final LocalArtifactResult localResult = this.repositorySystemSession.getLocalRepositoryManager()
.find(this.repositorySystemSession, new LocalArtifactRequest(artifact, this.remoteRepositories, null));
File file = null;
if (localResult.isAvailable()) {
file = localResult.getFile();
} else {
final ArtifactResult result;
result = resolver.resolveArtifact(this.repositorySystemSession,
new ArtifactRequest(artifact, this.remoteRepositories, null));
if (result.isResolved()) {
file = result.getArtifact().getFile();
}
}
return file;
}
示例11: resolveDependencies
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
private Map<Artifact, Dependency> resolveDependencies(BomImport bom) throws Exception {
org.eclipse.aether.artifact.Artifact artifact = new org.eclipse.aether.artifact.DefaultArtifact(bom.getGroupId(), bom.getArtifactId(), "pom", bom.getVersion());
List<RemoteRepository> repositories = remoteRepositories;
if (bom.getRepository() != null) {
// Include the additional repository into the copy
repositories = new LinkedList<RemoteRepository>(repositories);
RemoteRepository repo = new RemoteRepository.Builder(bom.getArtifactId() + "-repository", "default", bom.getRepository()).build();
repositories.add(0, repo);
}
ArtifactRequest artifactRequest = new ArtifactRequest(artifact, repositories, null);
system.resolveArtifact(session, artifactRequest); // To get an error when the artifact does not exist
ArtifactDescriptorRequest req = new ArtifactDescriptorRequest(artifact, repositories, null);
ArtifactDescriptorResult res = system.readArtifactDescriptor(session, req);
Map<Artifact, Dependency> mavenDependencies = new LinkedHashMap<Artifact, Dependency>();
if (res.getManagedDependencies() != null) {
for (org.eclipse.aether.graph.Dependency dep : res.getManagedDependencies()) {
mavenDependencies.put(toMavenArtifact(dep), toMavenDependency(dep));
}
}
return mavenDependencies;
}
示例12: containsArtifact
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
@Override
public boolean containsArtifact(final GAV gav) {
ArtifactRequest request = createArtifactRequest(gav);
try {
Aether aether = Aether.getAether();
aether.getSystem().resolveArtifact(aether.getSession(),
request);
} catch (ArtifactResolutionException e) {
logger.trace("Artifact {} not found.",
gav,
e);
return false;
}
logger.trace("Artifact {} found.",
gav);
return true;
}
示例13: getArtifactFileFromRepository
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
@Override
public File getArtifactFileFromRepository(final GAV gav) {
ArtifactRequest request = createArtifactRequest(gav);
ArtifactResult result = null;
try {
result = Aether.getAether().getSystem().resolveArtifact(
Aether.getAether().getSession(),
request);
} catch (ArtifactResolutionException e) {
logger.warn(e.getMessage(),
e);
}
if (result == null) {
return null;
}
File artifactFile = null;
if (result.isResolved() && !result.isMissing()) {
artifactFile = result.getArtifact().getFile();
}
return artifactFile;
}
示例14: fetchDependency
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
private Path fetchDependency(final String artifactIdentifier) throws MojoExecutionException {
ArtifactRequest request = new ArtifactRequest();
final DefaultArtifact artifact = new DefaultArtifact(artifactIdentifier);
request.setArtifact(artifact);
request.setRepositories(remoteRepos);
LogProvider.debug("Resolving artifact " + artifact + " from " + remoteRepos);
ArtifactResult result;
try {
result = repoSystem.resolveArtifact(repoSession, request);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
LogProvider.debug("Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
return result.getArtifact().getFile().toPath();
}
示例15: resolveDevServerJar
import org.eclipse.aether.resolution.ArtifactRequest; //导入依赖的package包/类
public String resolveDevServerJar() {
String version = getYawpVersion();
List<RemoteRepository> allRepos = ImmutableList.copyOf(Iterables.concat(getProjectRepos()));
ArtifactRequest request = new ArtifactRequest(new DefaultArtifact(YAWP_GROUP_ID, YAWP_DEVSERVER_ARTIFACT_ID, "jar", version), allRepos,
null);
ArtifactResult result;
try {
result = repoSystem.resolveArtifact(repoSession, request);
} catch (ArtifactResolutionException e) {
throw new RuntimeException("Could not resolve DevServer artifact in Maven.");
}
return result.getArtifact().getFile().getPath();
}