use of org.apache.ivy.core.module.descriptor.Artifact in project gradle by gradle.
the class DefaultArtifactPomTest method addMainArtifactTwiceShouldThrowInvalidUserDataEx.
@Test(expected = InvalidUserDataException.class)
public void addMainArtifactTwiceShouldThrowInvalidUserDataEx() {
Artifact mainArtifact = createTestArtifact("someName", null, "mainPackaging");
File mainFile = new File("someFile");
artifactPom.addArtifact(mainArtifact, mainFile);
artifactPom.addArtifact(mainArtifact, mainFile);
}
use of org.apache.ivy.core.module.descriptor.Artifact in project gradle by gradle.
the class DefaultArtifactPomTest method pomWithClassifierArtifactsOnly.
@Test
public void pomWithClassifierArtifactsOnly() {
File classifierFile = new File("someClassifierFile");
Artifact classifierArtifact = createTestArtifact("someName", "javadoc", "zip");
artifactPom.addArtifact(classifierArtifact, classifierFile);
assertThat(artifactPom.getArtifact(), nullValue());
PublishArtifact artifact = singleItem(artifactPom.getAttachedArtifacts());
assertThat(artifact.getName(), equalTo("someName"));
assertThat(artifact.getExtension(), equalTo("zip"));
assertThat(artifact.getType(), equalTo("zip"));
assertThat(artifact.getClassifier(), equalTo("javadoc"));
assertThat(artifact.getFile(), equalTo(classifierFile));
assertThat(artifactPom.getPom().getGroupId(), equalTo("org"));
assertThat(artifactPom.getPom().getArtifactId(), equalTo("someName"));
assertThat(artifactPom.getPom().getVersion(), equalTo("1.0"));
assertThat(artifactPom.getPom().getPackaging(), equalTo("jar"));
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class ResolveEngine method downloadArtifacts.
public void downloadArtifacts(ResolveReport report, Filter<Artifact> artifactFilter, DownloadOptions options) {
long start = System.currentTimeMillis();
eventManager.fireIvyEvent(new PrepareDownloadEvent(report.getArtifacts().toArray(new Artifact[report.getArtifacts().size()])));
long totalSize = 0;
for (IvyNode dependency : report.getDependencies()) {
checkInterrupted();
// download artifacts required in all asked configurations
if (!dependency.isCompletelyEvicted() && !dependency.hasProblem() && dependency.getModuleRevision() != null) {
DependencyResolver resolver = dependency.getModuleRevision().getArtifactResolver();
Artifact[] selectedArtifacts = dependency.getSelectedArtifacts(artifactFilter);
DownloadReport dReport = resolver.download(selectedArtifacts, options);
for (ArtifactDownloadReport adr : dReport.getArtifactsReports()) {
if (adr.getDownloadStatus() == DownloadStatus.FAILED) {
if (adr.getArtifact().getExtraAttribute("ivy:merged") != null) {
Message.warn("\tmerged artifact not found: " + adr.getArtifact() + ". It was required in " + adr.getArtifact().getExtraAttribute("ivy:merged"));
} else {
Message.warn("\t" + adr);
resolver.reportFailure(adr.getArtifact());
}
} else if (adr.getDownloadStatus() == DownloadStatus.SUCCESSFUL) {
totalSize += adr.getSize();
}
}
// update concerned reports
for (String dconf : dependency.getRootModuleConfigurations()) {
// (as described by the Dependency object)
if (dependency.isEvicted(dconf) || dependency.isBlacklisted(dconf)) {
report.getConfigurationReport(dconf).addDependency(dependency);
} else {
report.getConfigurationReport(dconf).addDependency(dependency, dReport);
}
}
}
}
report.setDownloadTime(System.currentTimeMillis() - start);
report.setDownloadSize(totalSize);
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class PublishEngine method publish.
public Collection<Artifact> publish(ModuleDescriptor md, Collection<String> srcArtifactPattern, DependencyResolver resolver, PublishOptions options) throws IOException {
Collection<Artifact> missing = new ArrayList<>();
Set<Artifact> artifactsSet = new LinkedHashSet<>();
for (String conf : replaceWildcards(options.getConfs(), md)) {
artifactsSet.addAll(Arrays.asList(md.getArtifacts(conf)));
}
Artifact[] extraArtifacts = options.getExtraArtifacts();
if (extraArtifacts != null) {
for (Artifact extraArtifact : extraArtifacts) {
artifactsSet.add(new MDArtifact(md, extraArtifact.getName(), extraArtifact.getType(), extraArtifact.getExt(), extraArtifact.getUrl(), extraArtifact.getQualifiedExtraAttributes()));
}
}
// now collects artifacts files
Map<Artifact, File> artifactsFiles = new LinkedHashMap<>();
for (Artifact artifact : artifactsSet) {
for (String pattern : srcArtifactPattern) {
File artifactFile = settings.resolveFile(IvyPatternHelper.substitute(settings.substitute(pattern), artifact));
if (artifactFile.exists()) {
artifactsFiles.put(artifact, artifactFile);
break;
}
}
if (!artifactsFiles.containsKey(artifact)) {
StringBuilder sb = new StringBuilder();
sb.append("missing artifact ").append(artifact).append(":\n");
for (String pattern : srcArtifactPattern) {
sb.append("\t").append(settings.resolveFile(IvyPatternHelper.substitute(pattern, artifact))).append(" file does not exist\n");
}
if (options.isWarnOnMissing() || options.isHaltOnMissing()) {
Message.warn(sb.toString());
} else {
Message.verbose(sb.toString());
}
if (options.isHaltOnMissing()) {
throw new IOException("missing artifact " + artifact);
}
missing.add(artifact);
}
}
if (options.getSrcIvyPattern() != null) {
Artifact artifact = MDArtifact.newIvyArtifact(md);
File artifactFile = settings.resolveFile(IvyPatternHelper.substitute(options.getSrcIvyPattern(), artifact));
if (!artifactFile.exists()) {
String msg = "missing ivy file for " + md.getModuleRevisionId() + ": \n" + artifactFile + " file does not exist";
if (options.isWarnOnMissing() || options.isHaltOnMissing()) {
Message.warn(msg);
} else {
Message.verbose(msg);
}
if (options.isHaltOnMissing()) {
throw new IOException("missing ivy artifact " + artifact);
}
missing.add(artifact);
} else {
artifactsFiles.put(artifact, artifactFile);
}
}
// and now do actual publishing
boolean successfullyPublished = false;
try {
resolver.beginPublishTransaction(md.getModuleRevisionId(), options.isOverwrite());
// for each declared published artifact in this descriptor, do:
for (Map.Entry<Artifact, File> entry : artifactsFiles.entrySet()) {
publish(entry.getKey(), entry.getValue(), resolver, options.isOverwrite());
}
resolver.commitPublishTransaction();
successfullyPublished = true;
} finally {
if (!successfullyPublished) {
resolver.abortPublishTransaction();
}
}
return missing;
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class RetrieveEngine method getConflictResolvingPolicy.
/**
* The returned comparator should consider greater the artifact which gains the conflict battle.
* This is used only during retrieve... prefer resolve conflict manager to resolve conflicts.
*
* @return Comparator<ArtifactDownloadReport>
*/
private Comparator<ArtifactDownloadReport> getConflictResolvingPolicy() {
return new Comparator<ArtifactDownloadReport>() {
// younger conflict resolving policy
public int compare(ArtifactDownloadReport o1, ArtifactDownloadReport o2) {
Artifact a1 = o1.getArtifact();
Artifact a2 = o2.getArtifact();
if (a1.getPublicationDate().after(a2.getPublicationDate())) {
// a1 is after a2 <=> a1 is younger than a2 <=> a1 wins the conflict battle
return +1;
} else if (a1.getPublicationDate().before(a2.getPublicationDate())) {
// a1 is before a2 <=> a2 is younger than a1 <=> a2 wins the conflict battle
return -1;
} else {
return 0;
}
}
};
}
Aggregations