Search in sources :

Example 56 with Artifact

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);
}
Also used : File(java.io.File) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 57 with Artifact

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"));
}
Also used : PublishArtifact(org.gradle.api.artifacts.PublishArtifact) File(java.io.File) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 58 with Artifact

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);
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Artifact(org.apache.ivy.core.module.descriptor.Artifact) PrepareDownloadEvent(org.apache.ivy.core.event.download.PrepareDownloadEvent) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 59 with Artifact

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;
}
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)

Example 60 with Artifact

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&lt;ArtifactDownloadReport&gt;
 */
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;
            }
        }
    };
}
Also used : ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Comparator(java.util.Comparator)

Aggregations

Artifact (org.apache.ivy.core.module.descriptor.Artifact)106 Test (org.junit.Test)68 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)59 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)55 File (java.io.File)53 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)31 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)30 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)28 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)25 Date (java.util.Date)22 DownloadReport (org.apache.ivy.core.report.DownloadReport)20 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)15 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)13 Configuration (org.apache.ivy.core.module.descriptor.Configuration)10 IOException (java.io.IOException)9 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)9 ParseException (java.text.ParseException)8 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)8 ResolveReport (org.apache.ivy.core.report.ResolveReport)7 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)7