org.apache.ivy.core.report.ArtifactDownloadReport Java Examples

The following examples show how to use org.apache.ivy.core.report.ArtifactDownloadReport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EndArtifactDownloadEvent.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public EndArtifactDownloadEvent(DependencyResolver resolver, Artifact artifact,
        ArtifactDownloadReport report, File dest) {
    super(NAME, artifact);
    this.resolver = resolver;
    this.report = report;
    addAttribute("resolver", this.resolver.getName());
    addAttribute("status", this.report.getDownloadStatus().toString());
    addAttribute("details", this.report.getDownloadDetails());
    addAttribute("size", String.valueOf(this.report.getSize()));
    addAttribute("file", dest.getAbsolutePath());
    addAttribute("duration", String.valueOf(this.report.getDownloadTimeMillis()));
    ArtifactOrigin origin = report.getArtifactOrigin();
    if (!ArtifactOrigin.isUnknown(origin)) {
        addAttribute("origin", origin.getLocation());
        addAttribute("local", String.valueOf(origin.isLocal()));
    } else {
        addAttribute("origin", "");
        addAttribute("local", "");
    }
}
 
Example #2
Source File: IvyCachePath.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public void doExecute() throws BuildException {
    prepareAndCheck();
    if (pathid == null) {
        if (id == null) {
            throw new BuildException("pathid is required in ivy classpath");
        }
        pathid = id;
        log("ID IS DEPRECATED, PLEASE USE PATHID INSTEAD", Project.MSG_WARN);
    }
    try {
        Path path = new Path(getProject());
        getProject().addReference(pathid, path);
        for (ArtifactDownloadReport adr : getArtifactReports()) {
            File f = adr.getLocalFile();
            if (adr.getUnpackedLocalFile() != null) {
                f = adr.getUnpackedLocalFile();
            }
            addToPath(path, f);
        }
    } catch (Exception ex) {
        throw new BuildException("impossible to build ivy path: " + ex, ex);
    }

}
 
Example #3
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Override
public ArtifactDownloadReport download(final ArtifactOrigin origin, DownloadOptions options) {
    Checks.checkNotNull(origin, "origin");
    return getRepositoryCacheManager().download(origin.getArtifact(),
        new ArtifactResourceResolver() {
            public ResolvedResource resolve(Artifact artifact) {
                try {
                    Resource resource = getResource(origin.getLocation());
                    if (resource != null) {
                        String revision = origin.getArtifact().getModuleRevisionId().getRevision();
                        return new ResolvedResource(resource, revision);
                    }
                } catch (IOException e) {
                    Message.debug(e);
                }
                return null;
            }
        }, downloader, getCacheDownloadOptions(options));
}
 
Example #4
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    RepositoryCacheManager cacheManager = getRepositoryCacheManager();

    clearArtifactAttempts();
    DownloadReport dr = new DownloadReport();
    for (Artifact artifact : artifacts) {
        ArtifactDownloadReport adr = cacheManager.download(artifact, artifactResourceResolver,
            downloader, getCacheDownloadOptions(options));
        if (DownloadStatus.FAILED == adr.getDownloadStatus()) {
            if (!ArtifactDownloadReport.MISSING_ARTIFACT.equals(adr.getDownloadDetails())) {
                Message.warn("\t" + adr);
            }
        } else if (DownloadStatus.NO == adr.getDownloadStatus()) {
            Message.verbose("\t" + adr);
        } else if (LogOptions.LOG_QUIET.equals(options.getLog())) {
            Message.verbose("\t" + adr);
        } else {
            Message.info("\t" + adr);
        }
        dr.addArtifactReport(adr);
        checkInterrupted();
    }
    return dr;
}
 
Example #5
Source File: IvyDependencyResolverAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void resolveArtifact(ComponentArtifactMetaData artifact, ModuleSource moduleSource, BuildableArtifactResolveResult result) {
    Artifact ivyArtifact = ((ModuleVersionArtifactMetaData) artifact).toIvyArtifact();
    ArtifactDownloadReport artifactDownloadReport = resolver.download(new Artifact[]{ivyArtifact}, downloadOptions).getArtifactReport(ivyArtifact);
    if (downloadFailed(artifactDownloadReport)) {
        if (artifactDownloadReport instanceof EnhancedArtifactDownloadReport) {
            EnhancedArtifactDownloadReport enhancedReport = (EnhancedArtifactDownloadReport) artifactDownloadReport;
            result.failed(new ArtifactResolveException(artifact.getId(), enhancedReport.getFailure()));
        } else {
            result.failed(new ArtifactResolveException(artifact.getId(), artifactDownloadReport.getDownloadDetails()));
        }
        return;
    }

    File localFile = artifactDownloadReport.getLocalFile();
    if (localFile != null) {
        result.resolved(localFile);
    } else {
        result.notFound(artifact.getId());
    }
}
 
Example #6
Source File: IvyArtifactReport.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private void writeOriginLocationIfPresent(RepositoryCacheManager cache,
        TransformerHandler saxHandler, ArtifactDownloadReport artifact) throws SAXException {
    ArtifactOrigin origin = artifact.getArtifactOrigin();
    if (!ArtifactOrigin.isUnknown(origin)) {
        String originName = origin.getLocation();
        boolean isOriginLocal = origin.isLocal();

        String originLocation;
        AttributesImpl originLocationAttrs = new AttributesImpl();
        if (isOriginLocal) {
            originLocationAttrs.addAttribute(null, "is-local", "is-local", "CDATA", "true");
            originLocation = originName.replace('\\', '/');
        } else {
            originLocationAttrs.addAttribute(null, "is-local", "is-local", "CDATA", "false");
            originLocation = originName;
        }
        saxHandler
                .startElement(null, "origin-location", "origin-location", originLocationAttrs);
        char[] originLocationAsChars = originLocation.toCharArray();
        saxHandler.characters(originLocationAsChars, 0, originLocationAsChars.length);
        saxHandler.endElement(null, "origin-location", "origin-location");
    }
}
 
Example #7
Source File: CacheResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Override
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    ensureConfigured();
    clearArtifactAttempts();
    DownloadReport dr = new DownloadReport();
    for (Artifact artifact : artifacts) {
        final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact);
        dr.addArtifactReport(adr);
        ResolvedResource artifactRef = getArtifactRef(artifact, null);
        if (artifactRef != null) {
            Message.verbose("\t[NOT REQUIRED] " + artifact);
            ArtifactOrigin origin = new ArtifactOrigin(artifact, true, artifactRef
                    .getResource().getName());
            File archiveFile = ((FileResource) artifactRef.getResource()).getFile();
            adr.setDownloadStatus(DownloadStatus.NO);
            adr.setSize(archiveFile.length());
            adr.setArtifactOrigin(origin);
            adr.setLocalFile(archiveFile);
        } else {
            adr.setDownloadStatus(DownloadStatus.FAILED);
        }
    }
    return dr;
}
 
Example #8
Source File: UpdateSiteLoader.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private UpdateSite loadSite(URI repoUri) throws IOException, SAXException {
    URI siteUri = normalizeSiteUri(repoUri, null);
    URL u = siteUri.resolve("site.xml").toURL();

    final URLResource res = new URLResource(u, this.timeoutConstraint);
    ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res,
        "site", "updatesite", "xml", options, urlRepository);
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        return null;
    }
    try (InputStream in = new FileInputStream(report.getLocalFile())) {
        UpdateSite site = EclipseUpdateSiteParser.parse(in);
        site.setUri(normalizeSiteUri(site.getUri(), siteUri));
        return site;
    }
}
 
Example #9
Source File: IvyCacheFilesetTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void requireCommonBaseDirNoCommon() {
    final File[] fileSystemRoots = File.listRoots();
    if (fileSystemRoots.length == 1) {
        // single file system root isn't what we are interested in, in this test method
        return;
    }
    // we expect a BuildException when we try to find a (non-existent) common base dir
    // across file system roots
    expExc.expect(BuildException.class);
    List<ArtifactDownloadReport> reports = Arrays.asList(
        artifactDownloadReport(new File(fileSystemRoots[0], "a/b/c/d")),
        artifactDownloadReport(new File(fileSystemRoots[1], "a/b/e/f"))
    );
    fileset.requireCommonBaseDir(reports);
}
 
Example #10
Source File: UpdateSiteLoader.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private UpdateSiteDescriptor loadFromSite(UpdateSite site) throws IOException, SAXException {
    UpdateSiteDescriptor repoDescriptor = new UpdateSiteDescriptor(site.getUri(),
            ExecutionEnvironmentProfileProvider.getInstance());

    for (EclipseFeature feature : site.getFeatures()) {
        URL url = site.getUri().resolve(feature.getUrl()).toURL();

        final URLResource res = new URLResource(url, this.timeoutConstraint);
        ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res,
            feature.getId(), "feature", "jar", options, urlRepository);
        if (report.getDownloadStatus() == DownloadStatus.FAILED) {
            return null;
        }
        try (InputStream in = new FileInputStream(report.getLocalFile())) {
            ZipInputStream zipped = findEntry(in, "feature.xml");
            if (zipped == null) {
                return null;
            }
            EclipseFeature f = FeatureParser.parse(zipped);
            f.setURL(feature.getUrl());
            repoDescriptor.addFeature(f);
        }
    }

    return repoDescriptor;
}
 
Example #11
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that <code>SHA-256</code> algorithm can be used for checksums on resolvers
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testSHA256Checksum() throws Exception {
    final FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("sha256-checksum-resolver");
    resolver.setSettings(settings);

    resolver.addIvyPattern(settings.getBaseDir()
            + "/test/repositories/checksums/[module]/[revision]/[artifact]-[revision].[ext]");
    resolver.addArtifactPattern(settings.getBaseDir()
            + "/test/repositories/checksums/[module]/[revision]/[artifact]-[revision].[ext]");

    resolver.setChecksums("SHA-256");
    final ModuleRevisionId mrid = ModuleRevisionId.newInstance("test", "allright", "2.0");
    final ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull("Resolved module revision was null for " + mrid, rmr);
    final DownloadReport dr = resolver.download(rmr.getDescriptor().getAllArtifacts(), getDownloadOptions());
    final ArtifactDownloadReport[] successfulDownloadReports = dr.getArtifactsReports(DownloadStatus.SUCCESSFUL);
    assertNotNull("No artifacts were downloaded successfully", successfulDownloadReports);
    assertEquals("Unexpected number of successfully downloaded artifacts", 1, successfulDownloadReports.length);
    final ArtifactDownloadReport successfulDownloadReport = successfulDownloadReports[0];
    final Artifact downloadedArtifact = successfulDownloadReport.getArtifact();
    assertEquals("Unexpected organization of downloaded artifact", "test", downloadedArtifact.getModuleRevisionId().getOrganisation());
    assertEquals("Unexpected module of downloaded artifact", "allright", downloadedArtifact.getModuleRevisionId().getModuleId().getName());
    assertEquals("Unexpected revision of downloaded artifact", "2.0", downloadedArtifact.getModuleRevisionId().getRevision());
}
 
Example #12
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private void unpackArtifact(Artifact artifact, ArtifactDownloadReport adr,
        CacheDownloadOptions options) {
    Artifact unpacked = packagingManager.getUnpackedArtifact(artifact);
    if (unpacked == null) {
        // nothing to unpack
        return;
    }

    File archiveFile = getArchiveFileInCache(unpacked, null, false);
    if (archiveFile.exists() && !options.isForce()) {
        adr.setUnpackedLocalFile(archiveFile);
        adr.setUnpackedArtifact(unpacked);
    } else {
        Message.info("\tUnpacking " + artifact.getId());
        try {
            final Artifact unpackedArtifact = packagingManager.unpackArtifact(artifact, adr.getLocalFile(), archiveFile);
            adr.setUnpackedLocalFile(archiveFile);
            adr.setUnpackedArtifact(unpackedArtifact);
        } catch (Exception e) {
            Message.debug(e);
            adr.setDownloadStatus(DownloadStatus.FAILED);
            adr.setDownloadDetails("The packed artifact " + artifact.getId()
                    + " could not be unpacked (" + e.getMessage() + ")");
        }
    }
}
 
Example #13
Source File: IvyDependencyResolverAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void resolveArtifact(ComponentArtifactMetaData artifact, ModuleSource moduleSource, BuildableArtifactResolveResult result) {
    Artifact ivyArtifact = ((ModuleVersionArtifactMetaData) artifact).toIvyArtifact();
    ArtifactDownloadReport artifactDownloadReport = resolver.download(new Artifact[]{ivyArtifact}, downloadOptions).getArtifactReport(ivyArtifact);
    if (downloadFailed(artifactDownloadReport)) {
        if (artifactDownloadReport instanceof EnhancedArtifactDownloadReport) {
            EnhancedArtifactDownloadReport enhancedReport = (EnhancedArtifactDownloadReport) artifactDownloadReport;
            result.failed(new ArtifactResolveException(artifact.getId(), enhancedReport.getFailure()));
        } else {
            result.failed(new ArtifactResolveException(artifact.getId(), artifactDownloadReport.getDownloadDetails()));
        }
        return;
    }

    File localFile = artifactDownloadReport.getLocalFile();
    if (localFile != null) {
        result.resolved(localFile);
    } else {
        result.notFound(artifact.getId());
    }
}
 
Example #14
Source File: RetrieveEngine.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
            }
        }
    };
}
 
Example #15
Source File: DownloadingRepositoryCacheManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ResolvedModuleRevision cacheModuleDescriptor(DependencyResolver resolver, final ResolvedResource resolvedResource, DependencyDescriptor dd, Artifact moduleArtifact, ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException {
    if (!moduleArtifact.isMetadata()) {
        return null;
    }

    ArtifactResourceResolver artifactResourceResolver = new ArtifactResourceResolver() {
        public ResolvedResource resolve(Artifact artifact) {
            return resolvedResource;
        }
    };
    ArtifactDownloadReport report = download(moduleArtifact, artifactResourceResolver, downloader, new CacheDownloadOptions().setListener(options.getListener()).setForce(true));

    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        LOGGER.warn("problem while downloading module descriptor: {}: {} ({} ms)", resolvedResource.getResource(), report.getDownloadDetails(), report.getDownloadTimeMillis());
        return null;
    }

    ModuleDescriptor md = parseModuleDescriptor(resolver, moduleArtifact, options, report.getLocalFile(), resolvedResource.getResource());
    LOGGER.debug("\t{}: parsed downloaded md file for {}; parsed={}" + getName(), moduleArtifact.getModuleRevisionId(), md.getModuleRevisionId());

    MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(md.getMetadataArtifact());
    madr.setSearched(true);
    madr.setDownloadStatus(report.getDownloadStatus());
    madr.setDownloadDetails(report.getDownloadDetails());
    madr.setArtifactOrigin(report.getArtifactOrigin());
    madr.setDownloadTimeMillis(report.getDownloadTimeMillis());
    madr.setOriginalLocalFile(report.getLocalFile());
    madr.setSize(report.getSize());

    return new ResolvedModuleRevision(resolver, resolver, md, madr);
}
 
Example #16
Source File: MockResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    DownloadReport dr = new DownloadReport();
    for (Artifact artifact : artifacts) {
        dr.addArtifactReport(new ArtifactDownloadReport(artifact));
    }
    return dr;
}
 
Example #17
Source File: P2DescriptorTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveNotZipped() throws Exception {
    settings.setDefaultResolver("p2-zipped");

    ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE,
        "org.eclipse.e4.core.services", "1.0.0.v20120521-2346");

    ResolvedModuleRevision rmr = p2ZippedResolver.getDependency(
        new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());

    assertEquals(1, rmr.getDescriptor().getAllArtifacts().length);

    DownloadOptions options = new DownloadOptions();
    DownloadReport report = p2ZippedResolver.download(rmr.getDescriptor().getAllArtifacts(),
        options);
    assertNotNull(report);

    assertEquals(1, report.getArtifactsReports().length);

    Artifact artifact = rmr.getDescriptor().getAllArtifacts()[0];
    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);

    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    assertNull(ar.getUnpackedLocalFile());
}
 
Example #18
Source File: P2DescriptorTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveZipped() throws Exception {
    settings.setDefaultResolver("p2-zipped");

    ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE,
        "org.apache.ant", "1.8.3.v20120321-1730");

    ResolvedModuleRevision rmr = p2ZippedResolver.getDependency(
        new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());

    assertEquals(2, rmr.getDescriptor().getAllArtifacts().length);

    DownloadOptions options = new DownloadOptions();
    DownloadReport report = p2ZippedResolver.download(rmr.getDescriptor().getAllArtifacts(),
        options);
    assertNotNull(report);

    assertEquals(2, report.getArtifactsReports().length);

    for (int i = 0; i < 2; i++) {
        Artifact artifact = rmr.getDescriptor().getAllArtifacts()[i];
        ArtifactDownloadReport ar = report.getArtifactReport(artifact);
        assertNotNull(ar);

        assertEquals(artifact, ar.getArtifact());
        assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
        // only the binary get unpacked
        if (ar.getArtifact().getType().equals("source")) {
            assertNull(ar.getUnpackedLocalFile());
        } else {
            assertNotNull(ar.getUnpackedLocalFile());
        }
    }
}
 
Example #19
Source File: IvyArtifactReport.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void writeCacheLocationIfPresent(RepositoryCacheManager cache,
        TransformerHandler saxHandler, ArtifactDownloadReport artifact) throws SAXException {
    File archiveInCache = artifact.getLocalFile();

    if (archiveInCache != null) {
        saxHandler.startElement(null, "cache-location", "cache-location", new AttributesImpl());
        char[] archiveInCacheAsChars = archiveInCache.getPath().replace('\\', '/')
                .toCharArray();
        saxHandler.characters(archiveInCacheAsChars, 0, archiveInCacheAsChars.length);
        saxHandler.endElement(null, "cache-location", "cache-location");
    }
}
 
Example #20
Source File: Ivy14.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public Map<ArtifactDownloadReport, Set<String>> determineArtifactsToCopy(ModuleId moduleId,
        String[] confs, File cache, String destFilePattern, String destIvyPattern,
        Filter<Artifact> artifactFilter) throws ParseException, IOException {
    return ivy.getRetrieveEngine().determineArtifactsToCopy(
        new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), destFilePattern,
        new RetrieveOptions().setConfs(confs).setDestIvyPattern(destIvyPattern)
                .setArtifactFilter(artifactFilter));
}
 
Example #21
Source File: IvyCacheFilesetTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void requireCommonBaseDirEmptyList() {
    // we expect a BuildException when we try to find a (non-existent) common base dir
    // across file system roots
    expExc.expect(BuildException.class);
    List<ArtifactDownloadReport> reports = Collections.emptyList();
    fileset.requireCommonBaseDir(reports);
}
 
Example #22
Source File: IvyCacheTask.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
protected List<ArtifactDownloadReport> getArtifactReports() throws BuildException,
        ParseException {
    List<ArtifactDownloadReport> ret = new ArrayList<>();
    for (ArtifactDownloadReport artifactReport : getAllArtifactReports()) {
        if (getArtifactFilter().accept(artifactReport.getArtifact())) {
            ret.add(artifactReport);
        }
    }

    return ret;
}
 
Example #23
Source File: IvyCacheFileset.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public void doExecute() throws BuildException {
    prepareAndCheck();
    if (setid == null) {
        throw new BuildException("setid is required in ivy cachefileset");
    }
    try {
        final List<ArtifactDownloadReport> artifactDownloadReports = getArtifactReports();
        if (artifactDownloadReports.isEmpty()) {
            // generate an empty fileset
            final FileSet emptyFileSet = new EmptyFileSet();
            emptyFileSet.setProject(getProject());
            getProject().addReference(setid, emptyFileSet);
            return;
        }
        // find a common base dir of the resolved artifacts
        final File baseDir = this.requireCommonBaseDir(artifactDownloadReports);
        final FileSet fileset = new FileSet();
        fileset.setDir(baseDir);
        fileset.setProject(getProject());
        // enroll each of the artifact files into the fileset
        for (final ArtifactDownloadReport artifactDownloadReport : artifactDownloadReports) {
            if (artifactDownloadReport.getLocalFile() == null) {
                continue;
            }
            final NameEntry ne = fileset.createInclude();
            ne.setName(getPath(baseDir, artifactDownloadReport.getLocalFile()));
        }
        getProject().addReference(setid, fileset);
    } catch (Exception ex) {
        throw new BuildException("impossible to build ivy cache fileset: " + ex, ex);
    }
}
 
Example #24
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDownloadWithUseOriginIsTrue() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    ((DefaultRepositoryCacheManager) resolver.getRepositoryCacheManager()).setUseOrigin(true);
    assertEquals("test", resolver.getName());

    resolver.addIvyPattern(IVY_PATTERN);
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/"
            + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");

    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
            false), data);
    assertNotNull(rmr);

    assertEquals(mrid, rmr.getId());
    Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
    assertEquals(pubdate, rmr.getPublicationDate());

    // test to ask to download
    DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar");
    DownloadReport report = resolver.download(new Artifact[] {artifact}, getDownloadOptions());
    assertNotNull(report);

    assertEquals(1, report.getArtifactsReports().length);

    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);

    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
 
Example #25
Source File: IvyResources.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private Collection<Resource> resolveResources(String id) throws BuildException {
    prepareAndCheck();
    try {
        List<Resource> resources = new ArrayList<>();
        if (id != null) {
            getProject().addReference(id, this);
        }
        for (ArtifactDownloadReport adr : getArtifactReports()) {
            resources.add(new FileResource(adr.getLocalFile()));
        }
        return resources;
    } catch (Exception ex) {
        throw new BuildException("impossible to build ivy resources: " + ex, ex);
    }
}
 
Example #26
Source File: ArtifactReportManifestIterable.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public ArtifactReportManifestIterable(List<ArtifactDownloadReport> reports,
        List<String> sourceTypes) {
    this.sourceTypes = sourceTypes;
    for (ArtifactDownloadReport report : reports) {
        ModuleRevisionId mrid = report.getArtifact().getModuleRevisionId();
        List<ArtifactDownloadReport> moduleReports = artifactReports.get(mrid);
        if (moduleReports == null) {
            moduleReports = new ArrayList<>();
            artifactReports.put(mrid, moduleReports);
        }
        moduleReports.add(report);
    }
}
 
Example #27
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetrieveReport() throws Exception {
    // mod1.1 depends on mod1.2
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org20/mod20.1/ivys/ivy-1.2.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    ModuleRevisionId mrid = md.getModuleRevisionId();
    RetrieveOptions options = getRetrieveOptions();
    options.setConfs(new String[] {"A"});
    Map<ArtifactDownloadReport, Set<String>> artifactsToCopy = ivy.getRetrieveEngine()
            .determineArtifactsToCopy(mrid,
                "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]", options);
    assertEquals(2, artifactsToCopy.size());

    options.setConfs(new String[] {"B"});
    artifactsToCopy = ivy.getRetrieveEngine().determineArtifactsToCopy(mrid,
        "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]", options);
    assertEquals(2, artifactsToCopy.size());

    options.setConfs(new String[] {"A", "B"});
    artifactsToCopy = ivy.getRetrieveEngine().determineArtifactsToCopy(mrid,
        "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]", options);
    assertEquals(3, artifactsToCopy.size());
}
 
Example #28
Source File: XmlReportParser.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public void endElement(String uri, String localName, String qname) throws SAXException {
    if ("dependencies".equals(qname)) {
        // add the artifacts in the correct order
        for (List<ArtifactDownloadReport> artifactReports : revisionsMap.values()) {
            SaxXmlReportParser.this.artifactReports.addAll(artifactReports);
            for (ArtifactDownloadReport artifactReport : artifactReports) {
                if (artifactReport.getDownloadStatus() != DownloadStatus.FAILED) {
                    artifacts.add(artifactReport.getArtifact());
                }
            }

        }
    }
}
 
Example #29
Source File: XmlReportWriter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void outputArtifacts(ConfigurationResolveReport report, PrintWriter out, IvyNode dep) {
    out.println("\t\t\t\t<artifacts>");
    for (ArtifactDownloadReport adr : report.getDownloadReports(dep.getResolvedId())) {
        out.print("\t\t\t\t\t<artifact name=\"" + XMLHelper.escape(adr.getName())
                + "\" type=\"" + XMLHelper.escape(adr.getType()) + "\" ext=\""
                + XMLHelper.escape(adr.getExt()) + "\"");
        out.print(extraToString(adr.getArtifact().getQualifiedExtraAttributes(), SEPARATOR));
        out.print(" status=\"" + XMLHelper.escape(adr.getDownloadStatus().toString()) + "\"");
        out.print(" details=\"" + XMLHelper.escape(adr.getDownloadDetails()) + "\"");
        out.print(" size=\"" + adr.getSize() + "\"");
        out.print(" time=\"" + adr.getDownloadTimeMillis() + "\"");
        if (adr.getLocalFile() != null) {
            out.print(" location=\""
                    + XMLHelper.escape(adr.getLocalFile().getAbsolutePath()) + "\"");
        }
        if (adr.getUnpackedLocalFile() != null) {
            out.print(" unpackedFile=\""
                    + XMLHelper.escape(adr.getUnpackedLocalFile().getAbsolutePath()) + "\"");
        }

        ArtifactOrigin origin = adr.getArtifactOrigin();
        if (origin != null) {
            out.println(">");
            out.println("\t\t\t\t\t\t<origin-location is-local=\""
                    + String.valueOf(origin.isLocal()) + "\"" + " location=\""
                    + XMLHelper.escape(origin.getLocation()) + "\"/>");
            out.println("\t\t\t\t\t</artifact>");
        } else {
            out.println("/>");
        }
    }
    out.println("\t\t\t\t</artifacts>");
}
 
Example #30
Source File: BintrayResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testBintray() throws Exception {
    BintrayResolver resolver = new BintrayResolver();
    resolver.setSettings(settings);
    ModuleRevisionId mrid = ModuleRevisionId
            .newInstance("org.apache.ant", "ant-antunit", "1.2");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid,
            false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());

    DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(),
            "ant-antunit", "jar", "jar");
    DownloadReport report = resolver.download(new Artifact[] {artifact}, downloadOptions());
    assertNotNull(report);

    assertEquals(1, report.getArtifactsReports().length);

    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);

    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());

    // test to ask to download again, should use cache
    report = resolver.download(new Artifact[] {artifact}, downloadOptions());
    assertNotNull(report);

    assertEquals(1, report.getArtifactsReports().length);

    ar = report.getArtifactReport(artifact);
    assertNotNull(ar);

    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}