Search in sources :

Example 6 with ArtifactOrigin

use of org.apache.ivy.core.cache.ArtifactOrigin in project ant-ivy by apache.

the class IvyArtifactReport method writeOriginLocationIfPresent.

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");
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin)

Example 7 with ArtifactOrigin

use of org.apache.ivy.core.cache.ArtifactOrigin in project ant-ivy by apache.

the class PomModuleDescriptorParser method addSourcesAndJavadocArtifactsIfPresent.

private void addSourcesAndJavadocArtifactsIfPresent(PomModuleDescriptorBuilder mdBuilder, ParserSettings ivySettings) {
    if (mdBuilder.getMainArtifact() == null) {
        // no main artifact in pom, we don't need to search for meta artifacts
        return;
    }
    boolean sourcesLookup = !"false".equals(ivySettings.getVariable("ivy.maven.lookup.sources"));
    boolean javadocLookup = !"false".equals(ivySettings.getVariable("ivy.maven.lookup.javadoc"));
    if (!sourcesLookup && !javadocLookup) {
        Message.debug("Sources and javadocs lookup disabled");
        return;
    }
    ModuleDescriptor md = mdBuilder.getModuleDescriptor();
    ModuleRevisionId mrid = md.getModuleRevisionId();
    DependencyResolver resolver = ivySettings.getResolver(mrid);
    if (resolver == null) {
        Message.debug("no resolver found for " + mrid + ": no source or javadoc artifact lookup");
    } else {
        ArtifactOrigin mainArtifact = resolver.locate(mdBuilder.getMainArtifact());
        if (!ArtifactOrigin.isUnknown(mainArtifact)) {
            String mainArtifactLocation = mainArtifact.getLocation();
            if (sourcesLookup) {
                ArtifactOrigin sourceArtifact = resolver.locate(mdBuilder.getSourceArtifact());
                if (!ArtifactOrigin.isUnknown(sourceArtifact) && !sourceArtifact.getLocation().equals(mainArtifactLocation)) {
                    Message.debug("source artifact found for " + mrid);
                    mdBuilder.addSourceArtifact();
                } else {
                    // it seems that sometimes the 'src' classifier is used instead of 'sources'
                    // Cfr. IVY-1138
                    ArtifactOrigin srcArtifact = resolver.locate(mdBuilder.getSrcArtifact());
                    if (!ArtifactOrigin.isUnknown(srcArtifact) && !srcArtifact.getLocation().equals(mainArtifactLocation)) {
                        Message.debug("source artifact found for " + mrid);
                        mdBuilder.addSrcArtifact();
                    } else {
                        Message.debug("no source artifact found for " + mrid);
                    }
                }
            } else {
                Message.debug("sources lookup disabled");
            }
            if (javadocLookup) {
                ArtifactOrigin javadocArtifact = resolver.locate(mdBuilder.getJavadocArtifact());
                if (!ArtifactOrigin.isUnknown(javadocArtifact) && !javadocArtifact.getLocation().equals(mainArtifactLocation)) {
                    Message.debug("javadoc artifact found for " + mrid);
                    mdBuilder.addJavadocArtifact();
                } else {
                    Message.debug("no javadoc artifact found for " + mrid);
                }
            } else {
                Message.debug("javadocs lookup disabled");
            }
        }
    }
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 8 with ArtifactOrigin

use of org.apache.ivy.core.cache.ArtifactOrigin in project ant-ivy by apache.

the class BasicResolver method locate.

@Override
public ArtifactOrigin locate(Artifact artifact) {
    ArtifactOrigin origin = getRepositoryCacheManager().getSavedArtifactOrigin(toSystem(artifact));
    if (!ArtifactOrigin.isUnknown(origin)) {
        return origin;
    }
    ResolvedResource artifactRef = getArtifactRef(artifact, null);
    if (artifactRef != null && artifactRef.getResource().exists()) {
        return new ArtifactOrigin(artifact, artifactRef.getResource().isLocal(), artifactRef.getResource().getName());
    }
    return null;
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin)

Example 9 with ArtifactOrigin

use of org.apache.ivy.core.cache.ArtifactOrigin in project ant-ivy by apache.

the class XmlReportWriter method outputMetadataArtifact.

private void outputMetadataArtifact(PrintWriter out, IvyNode dep) {
    if (dep.getModuleRevision() != null) {
        MetadataArtifactDownloadReport madr = dep.getModuleRevision().getReport();
        out.print("\t\t\t\t<metadata-artifact");
        out.print(" status=\"" + XMLHelper.escape(madr.getDownloadStatus().toString()) + "\"");
        out.print(" details=\"" + XMLHelper.escape(madr.getDownloadDetails()) + "\"");
        out.print(" size=\"" + madr.getSize() + "\"");
        out.print(" time=\"" + madr.getDownloadTimeMillis() + "\"");
        if (madr.getLocalFile() != null) {
            out.print(" location=\"" + XMLHelper.escape(madr.getLocalFile().getAbsolutePath()) + "\"");
        }
        out.print(" searched=\"" + madr.isSearched() + "\"");
        if (madr.getOriginalLocalFile() != null) {
            out.print(" original-local-location=\"" + XMLHelper.escape(madr.getOriginalLocalFile().getAbsolutePath()) + "\"");
        }
        ArtifactOrigin origin = madr.getArtifactOrigin();
        if (origin != null) {
            out.print(" origin-is-local=\"" + String.valueOf(origin.isLocal()) + "\"");
            out.print(" origin-location=\"" + XMLHelper.escape(origin.getLocation()) + "\"");
        }
        out.println("/>");
    }
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin)

Example 10 with ArtifactOrigin

use of org.apache.ivy.core.cache.ArtifactOrigin in project ant-ivy by apache.

the class XmlReportWriter method outputArtifacts.

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().getExtraAttributes(), 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>");
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin)

Aggregations

ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)11 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)6 File (java.io.File)5 Artifact (org.apache.ivy.core.module.descriptor.Artifact)4 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)3 ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)3 JarFile (java.util.jar.JarFile)2 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)2 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)2 ResolveReport (org.apache.ivy.core.report.ResolveReport)2 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 CacheResourceOptions (org.apache.ivy.core.cache.CacheResourceOptions)1 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)1 DownloadListener (org.apache.ivy.core.cache.DownloadListener)1