Java Code Examples for org.apache.ivy.core.report.ArtifactDownloadReport#getLocalFile()

The following examples show how to use org.apache.ivy.core.report.ArtifactDownloadReport#getLocalFile() . 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: 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 2
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 3
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 4
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 5
Source File: UpdateSiteLoader.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private UpdateSiteDescriptor loadFromDigest(UpdateSite site) throws IOException,
        SAXException {
    URI digestBaseUri = site.getDigestUri();
    if (digestBaseUri == null) {
        digestBaseUri = site.getUri();
    } else if (!digestBaseUri.isAbsolute()) {
        digestBaseUri = site.getUri().resolve(digestBaseUri);
    }
    URL digest = digestBaseUri.resolve("digest.zip").toURL();
    Message.verbose("\tReading " + digest);

    final URLResource res = new URLResource(digest, this.timeoutConstraint);
    ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res,
        "digest", "digest", "zip", options, urlRepository);
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        return null;
    }
    try (InputStream in = new FileInputStream(report.getLocalFile())) {
        ZipInputStream zipped = findEntry(in, "digest.xml");
        if (zipped == null) {
            return null;
        }
        return UpdateSiteDigestParser.parse(zipped, site);
    }
}
 
Example 6
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 7
Source File: IvyArtifactContainer.java    From jeka with Apache License 2.0 5 votes vote down vote up
static IvyArtifactContainer of(ArtifactDownloadReport[] artifactDownloadReports) {
    IvyArtifactContainer result = new IvyArtifactContainer();
    for (ArtifactDownloadReport report : artifactDownloadReports) {
        if (report.getLocalFile() == null) {
            JkLog.warn("File for " + report.getArtifact() + " hasn't been downloaded.");
            continue;
            //throw new IllegalStateException("File for " + report.getArtifact() + " hasn't been downloaded.");
        }
        result.put(report.getArtifact().getModuleRevisionId(), report.getLocalFile().toPath());
    }
    return result;
}
 
Example 8
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 9
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 10
Source File: IvyCacheFileset.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a common base directory, determined from the
 * {@link ArtifactDownloadReport#getLocalFile() local files} of the passed
 * <code>artifactDownloadReports</code>. If no common base directory can be determined, this
 * method throws a {@link BuildException}
 *
 * @param artifactDownloadReports The artifact download reports for which the common base
 *                                directory of the artifacts has to be determined
 * @return File
 */
File requireCommonBaseDir(final List<ArtifactDownloadReport> artifactDownloadReports) {
    File base = null;
    for (final ArtifactDownloadReport artifactDownloadReport : artifactDownloadReports) {
        if (artifactDownloadReport.getLocalFile() == null) {
            continue;
        }
        if (base == null) {
            // use the parent dir of the artifact as the base
            base = artifactDownloadReport.getLocalFile().getParentFile().getAbsoluteFile();
        } else {
            // try and find a common base directory between the current base
            // directory and the artifact's file
            base = getBaseDir(base, artifactDownloadReport.getLocalFile());
            if (base == null) {
                // fail fast - we couldn't determine a common base directory, throw an error
                throw new BuildException("Cannot find a common base directory, from resolved "
                        + "artifacts, for generating a cache fileset");
            }
        }
    }
    if (base == null) {
        // finally, we couldn't determine a common base directory, throw an error
        throw new BuildException("Cannot find a common base directory, from resolved "
                + "artifacts, for generating a cache fileset");
    }
    return base;
}
 
Example 11
Source File: Main.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private static void outputCachePath(Ivy ivy, File cache, ModuleDescriptor md, String[] confs,
        String outFile) {
    try {
        StringBuilder buf = new StringBuilder();
        Collection<ArtifactDownloadReport> all = new LinkedHashSet<>();
        ResolutionCacheManager cacheMgr = ivy.getResolutionCacheManager();
        XmlReportParser parser = new XmlReportParser();
        for (String conf : confs) {
            String resolveId = ResolveOptions.getDefaultResolveId(md);
            File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);
            parser.parse(report);

            all.addAll(Arrays.asList(parser.getArtifactReports()));
        }
        for (ArtifactDownloadReport artifact : all) {
            if (artifact.getLocalFile() != null) {
                buf.append(artifact.getLocalFile().getCanonicalPath());
                buf.append(File.pathSeparator);
            }
        }

        PrintWriter writer = new PrintWriter(new FileOutputStream(outFile));
        if (buf.length() > 0) {
            buf.setLength(buf.length() - File.pathSeparator.length());
            writer.println(buf);
        }
        writer.close();
        System.out.println("cachepath output to " + outFile);

    } catch (Exception ex) {
        throw new RuntimeException("impossible to build ivy cache path: " + ex.getMessage(), ex);
    }
}
 
Example 12
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 13
Source File: MirroredURLResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private File downloadMirrorList() {
    final URLRepository urlRepository = new URLRepository(this.getTimeoutConstraint());
    if (getEventManager() != null) {
        urlRepository.addTransferListener(getEventManager());
    }
    final URLResource mirrorResource = new URLResource(mirrorListUrl, this.getTimeoutConstraint());
    CacheResourceOptions options = new CacheResourceOptions();
    ArtifactDownloadReport report = getRepositoryCacheManager().downloadRepositoryResource(
        mirrorResource, "mirrorlist", "text", "txt", options, urlRepository);
    return report.getLocalFile();
}