use of org.apache.ivy.core.module.descriptor.MDArtifact in project ant-ivy by apache.
the class IvyNode method addArtifactsFromMergedUsage.
private void addArtifactsFromMergedUsage(String rootModuleConf, Set<Artifact> artifacts) {
for (IvyNodeUsage usage : mergedUsages.values()) {
Set<DependencyArtifactDescriptor> mergedDependencyArtifacts = usage.getDependencyArtifactsSet(rootModuleConf);
if (mergedDependencyArtifacts != null) {
for (DependencyArtifactDescriptor dad : mergedDependencyArtifacts) {
Map<String, String> extraAttributes = new HashMap<>(dad.getQualifiedExtraAttributes());
MDArtifact artifact = new MDArtifact(md, dad.getName(), dad.getType(), dad.getExt(), dad.getUrl(), extraAttributes);
if (!artifacts.contains(artifact)) {
// this is later used to know that this is a merged artifact
extraAttributes.put("ivy:merged", dad.getDependencyDescriptor().getParentRevisionId() + " -> " + usage.getNode().getId());
artifacts.add(artifact);
}
}
}
}
}
use of org.apache.ivy.core.module.descriptor.MDArtifact 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;
}
Aggregations