Search in sources :

Example 1 with MDArtifact

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);
                }
            }
        }
    }
}
Also used : DependencyArtifactDescriptor(org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MDArtifact(org.apache.ivy.core.module.descriptor.MDArtifact)

Example 2 with MDArtifact

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) MDArtifact(org.apache.ivy.core.module.descriptor.MDArtifact) IOException(java.io.IOException) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) MDArtifact(org.apache.ivy.core.module.descriptor.MDArtifact) LinkedHashMap(java.util.LinkedHashMap) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2 MDArtifact (org.apache.ivy.core.module.descriptor.MDArtifact)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Artifact (org.apache.ivy.core.module.descriptor.Artifact)1 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)1 DependencyArtifactDescriptor (org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor)1