本文整理汇总了Java中org.eclipse.aether.artifact.DefaultArtifact类的典型用法代码示例。如果您正苦于以下问题:Java DefaultArtifact类的具体用法?Java DefaultArtifact怎么用?Java DefaultArtifact使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultArtifact类属于org.eclipse.aether.artifact包,在下文中一共展示了DefaultArtifact类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
@Test
public void update()
throws ValidityException, ParsingException, IOException, MojoExecutionException {
Document pom = new Builder().build(new File(new File("src/it/reflector"), "pom.xml"));
Artifact artifact = new DefaultArtifact(
"net.stickycode",
"sticky-coercion",
"jar",
"",
"[3.1,4)");
new StickyBoundsMojo().updateDependency(pom, artifact, "[3.6,4)");
XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");
Nodes versions = pom.query("//mvn:version", context);
assertThat(versions.size()).isEqualTo(3);
Nodes nodes = pom.query("//mvn:version[text()='[3.6,4)']", context);
assertThat(nodes.size()).isEqualTo(1);
Node node = nodes.get(0);
assertThat(node.getValue()).isEqualTo("[3.6,4)");
}
示例2: updateWithClassifier
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
@Test
public void updateWithClassifier()
throws ValidityException, ParsingException, IOException, MojoExecutionException {
Document pom = new Builder().build(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("classifiers.xml"))));
Artifact artifact = new DefaultArtifact(
"net.stickycode",
"sticky-coercion",
"jar",
"",
"[2.1,4)");
new StickyBoundsMojo().updateDependency(pom, artifact, "[2.6,3)");
XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");
Nodes versions = pom.query("//mvn:version", context);
assertThat(versions.size()).isEqualTo(4);
Nodes nodes = pom.query("//mvn:version[text()='[2.6,3)']", context);
assertThat(nodes.size()).isEqualTo(1);
Node node = nodes.get(0);
assertThat(node.getValue()).isEqualTo("[2.6,3)");
}
示例3: dependencyManagementWins
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
@Test
public void dependencyManagementWins() throws Exception {
Aether aether = mock(Aether.class);
when(aether.requestVersionRange(fromCoords("a:b:[1.0]"))).thenReturn(newArrayList("1.0"));
when(aether.requestVersionRange(fromCoords("a:b:[2.0,)"))).thenReturn(newArrayList("2.0"));
VersionResolver versionResolver = new VersionResolver(aether);
Resolver resolver = new Resolver(mock(DefaultModelResolver.class), versionResolver, ALIASES);
resolver.traverseDeps(
mockDepManagementModel("a:b:[1.0]", "a:b:2.0"),
Sets.newHashSet(),
Sets.newHashSet(),
new Rule(new DefaultArtifact("par:ent:1.2.3")));
Collection<Rule> rules = resolver.getRules();
assertThat(rules).hasSize(1);
Rule actual = rules.iterator().next();
assertThat(actual.version()).isEqualTo("1.0");
}
示例4: nonConflictingDepManagement
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
@Test
public void nonConflictingDepManagement() throws Exception {
Aether aether = mock(Aether.class);
when(aether.requestVersionRange(fromCoords("a:b:[1.0,4.0]")))
.thenReturn(newArrayList("1.0", "2.0", "3.0", "4.0"));
when(aether.requestVersionRange(fromCoords("a:b:[2.0,)")))
.thenReturn(newArrayList("2.0", "3.0"));
VersionResolver versionResolver = new VersionResolver(aether);
Resolver resolver = new Resolver(mock(DefaultModelResolver.class), versionResolver, ALIASES);
resolver.traverseDeps(
mockDepManagementModel("a:b:[1.0, 4.0]", "a:b:2.0"),
Sets.newHashSet(),
Sets.newHashSet(),
new Rule(new DefaultArtifact("par:ent:1.2.3")));
Collection<Rule> rules = resolver.getRules();
assertThat(rules).hasSize(1);
Rule actual = rules.iterator().next();
assertThat(actual.version()).isEqualTo("2.0");
}
示例5: nonConflictingDepManagementRange
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
@Test
public void nonConflictingDepManagementRange() throws Exception {
Aether aether = mock(Aether.class);
when(aether.requestVersionRange(fromCoords("a:b:[1.0,4.0]")))
.thenReturn(newArrayList("1.0", "1.2", "2.0", "3.0", "4.0"));
when(aether.requestVersionRange(fromCoords("a:b:[1.2,3.0]")))
.thenReturn(newArrayList("1.2", "2.0", "3.0"));
VersionResolver versionResolver = new VersionResolver(aether);
Resolver resolver = new Resolver(mock(DefaultModelResolver.class), versionResolver, ALIASES);
resolver.traverseDeps(
mockDepManagementModel("a:b:[1.0,4.0]", "a:b:[1.2,3.0]"),
Sets.newHashSet(),
Sets.newHashSet(),
new Rule(new DefaultArtifact("par:ent:1.2.3")));
Collection<Rule> rules = resolver.getRules();
assertThat(rules).hasSize(1);
Rule actual = rules.iterator().next();
assertThat(actual.version()).isEqualTo("3.0");
}
示例6: depManagementDoesntAddDeps
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
@Test
public void depManagementDoesntAddDeps() throws Exception {
Aether aether = mock(Aether.class);
when(aether.requestVersionRange(fromCoords("c:d:[2.0,)"))).thenReturn(newArrayList("2.0"));
when(aether.requestVersionRange(fromCoords("a:b:[1.0,)")))
.thenReturn(newArrayList("1.0", "2.0"));
VersionResolver versionResolver = new VersionResolver(aether);
Resolver resolver = new Resolver(mock(DefaultModelResolver.class), versionResolver, ALIASES);
resolver.traverseDeps(
mockDepManagementModel("a:b:1.0", "c:d:2.0"),
Sets.newHashSet(),
Sets.newHashSet(),
new Rule(new DefaultArtifact("par:ent:1.2.3")));
Collection<Rule> rules = resolver.getRules();
assertThat(rules).hasSize(1);
Rule actual = rules.iterator().next();
assertThat(actual.name()).isEqualTo("c_d");
}
示例7: aliasWins
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
@Test
public void aliasWins() throws Exception {
Aether aether = mock(Aether.class);
when(aether.requestVersionRange(fromCoords("a:b:[1.0,)"))).thenReturn(newArrayList("1.0"));
VersionResolver versionResolver = new VersionResolver(aether);
Rule aliasedRule = new Rule(fromCoords("a:b:0"), "c");
Model mockModel = mock(Model.class);
when(mockModel.getDependencies()).thenReturn(ImmutableList.of(getDependency("a:b:1.0")));
Resolver resolver =
new Resolver(
mock(DefaultModelResolver.class), versionResolver, ImmutableList.of(aliasedRule));
resolver.traverseDeps(
mockModel,
Sets.newHashSet(),
Sets.newHashSet(),
new Rule(new DefaultArtifact("par:ent:1.2.3")));
Collection<Rule> rules = resolver.getRules();
assertThat(rules).hasSize(2);
rules.iterator().next();
Rule actualRule = rules.iterator().next();
assertThat(actualRule).isSameAs(aliasedRule);
}
示例8: testBuildFile
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
@Test
public void testBuildFile() throws Exception {
Rule rule = new Rule(new DefaultArtifact("x:y:1.2.3"));
Rule dep1 = new Rule(new DefaultArtifact("dep:dep1:4.5.6"));
rule.addDependency(dep1);
Rule dep2 = new Rule(new DefaultArtifact("dep:dep2:7.8.9"));
rule.addDependency(dep2);
Set<Rule> rules = ImmutableSet.of(rule, dep1, dep2);
String content = getBuildFileContent(rules);
assertThat(content).contains("java_library(\n"
+ " name = \"x_y\",\n"
+ " visibility = [\"//visibility:public\"],\n"
+ " exports = [\"@x_y//jar\"],\n"
+ " runtime_deps = [\n"
+ " \":dep_dep1\",\n"
+ " \":dep_dep2\",\n"
+ " ],\n"
+ ")"
);
}
示例9: resolveArtifacts
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
private Stream<? extends Artifact> resolveArtifacts(String coordinator) {
log.debug("resolving {}", coordinator);
try {
// build resolve filters
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(new DefaultArtifact(coordinator), JavaScopes.COMPILE));
DependencyRequest dependencyRequest = new DependencyRequest(
collectRequest,
DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE, JavaScopes.RUNTIME)
);
// resolve
final List<Artifact> artifacts = teslaAether.resolveArtifacts(dependencyRequest);
if (CollectionUtils.isEmpty(artifacts)) {
throw new DependencyResolveException(String.format("cannot resolve %s", coordinator));
}
return artifacts.stream();
} catch (DependencyResolutionException e) {
final String message = String.format("cannot resolve %s : %s", coordinator, e.getLocalizedMessage());
throw new DependencyResolveException(message, e);
}
}
示例10: main
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
for (RemoteRepository repo : Utils.getRepositoryList()) {
System.out.println(repo);
}
Artifact artifactObj = new DefaultArtifact("uk.ac.gate.plugins", "annie", "jar", "8.5-SNAPSHOT");
//artifactObj = artifactObj.setFile(
// new File("/home/mark/.m2/repository/uk/ac/gate/plugins/annie/8.5-SNAPSHOT/annie-8.5-SNAPSHOT.jar"));
SimpleMavenCache reader = new SimpleMavenCache(new File("repo"));
System.out.println(reader.findArtifact(artifactObj));
System.out.println(reader.findVersions(artifactObj));
reader.cacheArtifact(artifactObj);
System.out.println(reader.findArtifact(artifactObj));
System.out.println(reader.findVersions(artifactObj));
reader = new SimpleMavenCache(new File("repo2"), new File("repo"));
System.out.println(reader.findArtifact(artifactObj));
System.out.println(reader.findVersions(artifactObj));
}
示例11: resolveModel
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的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);
}
示例12: fetchPage
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
public Page<URI, Artifact> fetchPage(URI uri)
throws ClientProtocolException, IOException, URISyntaxException, ParseException, NotOkResponseException {
HttpGet request = new HttpGet(uri);
try (CloseableHttpResponse response = this.client.execute(request)) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
return new Page<>(Optional.empty(), Collections.emptyList());
}
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new NotOkResponseException(
String.format("Service response not ok %s %s %s", response.getStatusLine(),
response.getAllHeaders(), EntityUtils.toString(response.getEntity())));
}
Document document = Jsoup.parse(EntityUtils.toString(response.getEntity()), uri.toString());
Optional<URI> next = Optional.empty();
Elements nexts = document.select(".search-nav li:last-child a[href]");
if (!nexts.isEmpty()) {
next = Optional.of(new URI(nexts.first().attr("abs:href")));
}
List<Artifact> artifacts = document.select(".im .im-subtitle").stream()
.map(element -> new DefaultArtifact(element.select("a:nth-child(1)").first().text(),
element.select("a:nth-child(2)").first().text(), null, null))
.collect(Collectors.toList());
return new Page<>(next, artifacts);
}
}
示例13: fillfromExtraDependencies
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的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);
}
}
}
示例14: getLatestVersion
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的package包/类
private String getLatestVersion(String groupId, String artifactId, String range,
RepositorySystemSession session, List<RemoteRepository> remotes)
throws VersionRangeResolutionException {
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(
new DefaultArtifact(String.format("%s:%s:%s", groupId, artifactId, range)));
rangeRequest.setRepositories(remotes);
VersionRangeResult rangeResult = repoSystem.resolveVersionRange(session, rangeRequest);
if (rangeResult.getHighestVersion() != null) {
return rangeResult.getHighestVersion().toString();
}
else {
throw new com.atomist.rug.resolver.maven.DependencyCollectionException(String
.format("Unable to find a version of archive %s:%s.", groupId, artifactId),
properties.repositories());
}
}
示例15: load
import org.eclipse.aether.artifact.DefaultArtifact; //导入依赖的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);
}