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

The following examples show how to use org.apache.ivy.core.report.ArtifactDownloadReport#getArtifactOrigin() . 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: 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 2
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 3
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 4
Source File: AbstractResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Default implementation actually download the artifact Subclasses should overwrite this to
 * avoid the download
 *
 * @param artifact ArtifactOrigin
 * @return ArtifactOrigin
 */
public ArtifactOrigin locate(Artifact artifact) {
    DownloadReport dr = download(new Artifact[] {artifact}, new DownloadOptions());
    if (dr == null) {
        /*
         * according to IVY-831, it seems that this actually happen sometime, while the
         * contract of DependencyResolver says that it should never return null
         */
        throw new IllegalStateException("null download report returned by " + getName() + " ("
                + getClass().getName() + ")" + " when trying to download " + artifact);
    }
    ArtifactDownloadReport adr = dr.getArtifactReport(artifact);
    return adr.getDownloadStatus() == DownloadStatus.FAILED ? null : adr.getArtifactOrigin();
}