本文整理汇总了Java中org.eclipse.aether.artifact.Artifact类的典型用法代码示例。如果您正苦于以下问题:Java Artifact类的具体用法?Java Artifact怎么用?Java Artifact使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Artifact类属于org.eclipse.aether.artifact包,在下文中一共展示了Artifact类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolve
import org.eclipse.aether.artifact.Artifact; //导入依赖的package包/类
@Override
public Artifact resolve(Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session) throws PluginResolutionException {
WorkspaceReader wr = session.getWorkspaceReader();
NbWorkspaceReader nbwr = null;
if (wr instanceof NbWorkspaceReader) {
nbwr = (NbWorkspaceReader)wr;
//this only works reliably because the NbWorkspaceReader is part of the session, not a component
nbwr.silence();
}
try {
return super.resolve(plugin, repositories, session);
} finally {
if (nbwr != null) {
nbwr.normal();
}
}
}
示例2: getRemoteURLs
import org.eclipse.aether.artifact.Artifact; //导入依赖的package包/类
private List<URL> getRemoteURLs(final List<DependencyNode> nodes) throws IOException {
final List<URL> urls = new ArrayList<URL>();
for (DependencyNode node : nodes) {
final Artifact artifact = node.getArtifact();
boolean added = false;
for (RemoteRepository repository : node.getRepositories()) {
if (!added) {
final URL url = constructRemoteURL(artifact, repository);
added |= URLUtils.ping(url, URL_PING_TIMEOUT_MILLIS) && urls.add(url);
}
}
if (!added) { throw new IOException("unable to resolve the remote ural of artifact " + artifact); }
}
return urls;
}
示例3: constructRemoteURL
import org.eclipse.aether.artifact.Artifact; //导入依赖的package包/类
private URL constructRemoteURL(final Artifact artifact, final RemoteRepository repository) throws MalformedURLException {
final StringBuilder url_as_string = new StringBuilder();
final String artifact_id = artifact.getArtifactId();
final String repo_url = repository.getUrl();
url_as_string.append(repo_url.endsWith("/") ? repo_url : repo_url + "/");
url_as_string.append(artifact.getGroupId().replaceAll("\\.", "/"));
url_as_string.append("/");
url_as_string.append(artifact_id);
url_as_string.append("/");
url_as_string.append(artifact.getBaseVersion());
url_as_string.append("/");
url_as_string.append(artifact_id);
url_as_string.append("-");
url_as_string.append(artifact.getVersion());
url_as_string.append(".");
url_as_string.append(artifact.getExtension());
return new URL(url_as_string.toString());
}
示例4: resolveArtifact
import org.eclipse.aether.artifact.Artifact; //导入依赖的package包/类
/** Resolves an artifact as a root of a dependency graph. */
public void resolveArtifact(String artifactCoord) {
Artifact artifact;
ModelSource modelSource;
try {
artifact = ArtifactBuilder.fromCoords(artifactCoord);
modelSource = modelResolver.resolveModel(artifact);
} catch (UnresolvableModelException | InvalidArtifactCoordinateException e) {
logger.warning(e.getMessage());
return;
}
Rule rule = new Rule(artifact);
rule.setRepository(modelSource.getLocation());
rule.setSha1(downloadSha1(rule));
deps.put(rule.name(), rule); // add the artifact rule to the workspace
Model model = modelResolver.getEffectiveModel(modelSource);
if (model != null) {
traverseDeps(model, Sets.newHashSet(), Sets.newHashSet(), rule);
}
}
示例5: moveToTargetDir
import org.eclipse.aether.artifact.Artifact; //导入依赖的package包/类
/**
* move artifact to target directory, return the moved artifact file path
*
* @param targetDirectory
* @param artifact
*
* @return
*/
private Path moveToTargetDir(Path targetDirectory, Artifact artifact) {
final File artifactFile = artifact.getFile();
final String artifactFileName = artifactFile.getName();
final Path targetFile = targetDirectory.resolve(artifactFileName);
log.debug("copy {} to {}", artifactFileName, targetFile);
if (!targetDirectory.toFile().exists()) {
targetDirectory.toFile().mkdirs();
}
try {
Files.copy(artifactFile.toPath(), targetFile, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
final String message = String.format(
"dependency %s:%s:%s resolved but cannot be moved to target dir: %s",
artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion(),
e.getMessage()
);
throw new DependencyResolveException(message, e);
}
return targetFile;
}
示例6: resolveArtifacts
import org.eclipse.aether.artifact.Artifact; //导入依赖的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);
}
}
示例7: findVersions
import org.eclipse.aether.artifact.Artifact; //导入依赖的package包/类
@Override
public List<String> findVersions(Artifact artifact) {
List<String> versions = new ArrayList<String>();
if (tail != null) {
versions.addAll(tail.findVersions(artifact));
}
File file = getArtifactFile(artifact).getParentFile().getParentFile();
if (!file.exists() || !file.isDirectory())
return versions;
for (File version : file.listFiles()) {
if (version.isDirectory())
versions.add(version.getName());
}
return versions;
}
示例8: main
import org.eclipse.aether.artifact.Artifact; //导入依赖的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));
}
示例9: resolveModel
import org.eclipse.aether.artifact.Artifact; //导入依赖的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);
}
示例10: writeDeploymentRecorderFile
import org.eclipse.aether.artifact.Artifact; //导入依赖的package包/类
private void writeDeploymentRecorderFile()
{
// TODO: Make it configurable?
File target = new File( this.rootDirectory, "target" );
if ( !target.exists() )
{
target.mkdirs();
}
// TODO: Make this name configurable?
File recorderFile = new File( target, "deploy-recorder.lst" );
try ( FileWriter fw = new FileWriter( recorderFile ); BufferedWriter bos = new BufferedWriter( fw ) )
{
for ( Artifact artifact : recordedDeploys )
{
bos.write( getId( artifact ) );
bos.newLine();
}
}
catch ( IOException e )
{
LOGGER.error( "IOException", e );
}
}
示例11: process
import org.eclipse.aether.artifact.Artifact; //导入依赖的package包/类
@Override
public Result process(Page<Artifact, Artifact> page) throws Exception {
Artifact artifact = this.attributeWithTimestamp(page.getKey().get());
List<Artifact> dependencies = page.getElements().stream().map(this::attributeWithTimestamp)
.collect(Collectors.toList());
List<Artifact> classPathArtifacts = this.newClassPathArtifacts(artifact, dependencies);
Map<Method, Set<Invocation>> data = this.runAnalysis(artifact, classPathArtifacts);
Set<Method> methods = this.extractAllMethods(data);
Set<Class> classes = this.extractAllClasses(methods);
Map<Class, Artifact> classArtifacts = this.mapArtifactToClasses(classPathArtifacts, classes);
// filter artifacts
Map<Class, Artifact> invokedClassArtifacts = classArtifacts.entrySet().stream()
.filter(entry -> entry.getValue().getGroupId().matches(this.groupIdFilter))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
data = data.entrySet().stream().map(entry -> {
entry.setValue(entry.getValue().stream()
.filter(invocation -> invokedClassArtifacts.containsKey(invocation.getMethod().getClazz()))
.collect(Collectors.toSet()));
return entry;
}).filter(entry -> !entry.getValue().isEmpty())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
methods = this.extractAllMethods(data);
classes = this.extractAllClasses(methods);
classArtifacts = this.mapArtifactToClasses(classPathArtifacts, classes);
return new Result(artifact, data, classArtifacts, classes, methods);
}
示例12: fetchPage
import org.eclipse.aether.artifact.Artifact; //导入依赖的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: newMapper
import org.eclipse.aether.artifact.Artifact; //导入依赖的package包/类
private Function<Object, Object> newMapper(String mapper) {
if (mapper.equals(MAPPER_NEW_URI)) {
return object -> {
try {
return Dependent.newUri((Artifact) object);
} catch (URISyntaxException exception) {
throw new RuntimeException(exception);
}
};
}
if (mapper.equals(MAPPER_NEW_ARTIFACT_WITH_VERSION)) {
return object -> Match.newArtifactWithVersion((SolrDocument) object);
}
if (mapper.equals(MAPPER_NEW_ARTIFACT_WITH_LATEST_VERSION)) {
return object -> Match.newArtifactWithLatestVersion((SolrDocument) object);
}
if (mapper.equals(MAPPER_NEW_SOLR_QUERY_FOR_ALL_VERSIONS)) {
return object -> Match.newSolrQueryForAllVersions((Artifact) object);
}
if (mapper.equals(MAPPER_NEW_SOLR_QUERY_FOR_LATEST_VERSION)) {
return object -> Match.newSolrQueryForLatestVersion((Artifact) object);
}
throw new IllegalArgumentException(
"Mapper must be one of newUri, newArtifactWithVersion, newArtifactWithLatestVersion or newSolrQuery");
}
示例14: testJob
import org.eclipse.aether.artifact.Artifact; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testJob() throws Exception {
ActiveMQQueue destinationInput = new ActiveMQQueue("input");
ActiveMQQueue destinationOutput = new ActiveMQQueue("output");
this.application.start(new String[] { "g:com.google.code.gson", destinationInput.getQueueName() });
Page<Artifact, Artifact> output = (Page<Artifact, Artifact>) this.jmsTemplate
.receiveAndConvert(destinationOutput);
Assert.assertTrue(output.getKey().get() instanceof Artifact);
Assert.assertNotNull(output.getKey().get().getProperties().get("timestamp"));
Assert.assertEquals(output.getElements().size(), 209);
Assert.assertTrue(output.getElements().get(0) instanceof Artifact);
output = (Page<Artifact, Artifact>) this.jmsTemplate.receiveAndConvert(destinationOutput);
Assert.assertTrue(output.getKey().get() instanceof Artifact);
Assert.assertEquals(output.getElements().size(), 207);
Assert.assertTrue(output.getElements().get(0) instanceof Artifact);
this.jmsTemplate.setReceiveTimeout(100);
Assert.assertNull(this.jmsTemplate.receive(destinationOutput));
}
示例15: toHash
import org.eclipse.aether.artifact.Artifact; //导入依赖的package包/类
private int toHash(Object object) {
// FIXME ugly af..
if (object instanceof Artifact) {
return ((Artifact) object).hashCode();
} else if (object instanceof URI) {
return ((URI) object).hashCode();
} else if (object instanceof SolrQuery) {
return ((SolrQuery) object).toString().hashCode();
} else if (object instanceof Page) {
Page<?, ?> page = ((Page<?, ?>) object);
Optional<?> keyOptional = page.getKey();
if (keyOptional.isPresent()) {
return this.toHash(keyOptional.get());
}
return page.getElements().stream().map(element -> this.toHash(element))
.collect(Collectors.reducing((a, b) -> a + b)).orElse(page.hashCode());
}
throw new IllegalArgumentException(
String.format("Must be of ARtifact, URI, SolrQuery or Page, but was '%s'", object.toString()));
}