org.apache.ivy.core.cache.ArtifactOrigin Java Examples

The following examples show how to use org.apache.ivy.core.cache.ArtifactOrigin. 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: 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 #2
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 #3
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 #4
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 #5
Source File: ResolveEngineTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void testLocateThenDownload(ResolveEngine engine, Artifact artifact, File artifactFile) {
    ArtifactOrigin origin = engine.locate(artifact);
    assertNotNull(origin);
    assertTrue(origin.isLocal());
    assertEquals(artifactFile.getAbsolutePath(),
        new File(origin.getLocation()).getAbsolutePath());

    ArtifactDownloadReport r = engine.download(origin, new DownloadOptions());
    assertNotNull(r);
    assertEquals(DownloadStatus.SUCCESSFUL, r.getDownloadStatus());
    assertNotNull(r.getLocalFile());
    assertTrue(r.getLocalFile().exists());
}
 
Example #6
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();
}
 
Example #7
Source File: ChainResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Override
public ArtifactOrigin locate(Artifact artifact) {
    for (DependencyResolver resolver : chain) {
        ArtifactOrigin origin = resolver.locate(artifact);
        if (!ArtifactOrigin.isUnknown(origin)) {
            return origin;
        }
    }
    return ArtifactOrigin.unknown(artifact);
}
 
Example #8
Source File: DualResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Override
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
    if (artifact.getArtifact().isMetadata()) {
        return ivyResolver.download(artifact, options);
    } else {
        return artifactResolver.download(artifact, options);
    }
}
 
Example #9
Source File: DualResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Override
public ArtifactOrigin locate(Artifact artifact) {
    if (artifact.isMetadata()) {
        return ivyResolver.locate(artifact);
    } else {
        return artifactResolver.locate(artifact);
    }
}
 
Example #10
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #11
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 #12
Source File: XmlReportWriter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
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("/>");

    }
}
 
Example #13
Source File: IvyPatternHelper.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public String toString() {
    if (origin == null) {
        ModuleRevisionId revId = ModuleRevisionId.newInstance(org, moduleName, branch,
            revision, extraModuleAttributes);
        Artifact artifact = new DefaultArtifact(revId, null, artifactName, artifactType,
                artifactExt, extraArtifactAttributes);

        // TODO cache: see how we could know which actual cache manager to use, since this
        // will fail when using a resolver in a chain with a specific cache manager
        RepositoryCacheManager cacheManager = IvyContext.getContext().getSettings()
                .getResolver(revId).getRepositoryCacheManager();

        origin = cacheManager.getSavedArtifactOrigin(artifact);

        if (ArtifactOrigin.isUnknown(origin)) {
            Message.debug("no artifact origin found for " + artifact + " in "
                    + cacheManager);
            return null;
        }
    }

    if (ArtifactOrigin.isUnknown(origin)) {
        return null;
    }

    // we assume that the original filename is the last part of the original file location
    String location = origin.getLocation();
    int lastPathIndex = location.lastIndexOf('/');
    if (lastPathIndex == -1) {
        lastPathIndex = location.lastIndexOf('\\');
    }
    int lastColonIndex = location.lastIndexOf('.');

    return location.substring(lastPathIndex + 1, lastColonIndex);
}
 
Example #14
Source File: StartArtifactDownloadEvent.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public StartArtifactDownloadEvent(DependencyResolver resolver, Artifact artifact,
        ArtifactOrigin origin) {
    super(NAME, artifact);
    this.resolver = resolver;
    this.origin = origin;
    addAttribute("resolver", this.resolver.getName());
    addAttribute("origin", origin.getLocation());
    addAttribute("local", String.valueOf(origin.isLocal()));
}
 
Example #15
Source File: AbstractMavenResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactOrigin locate(Artifact artifact) {
    throw new UnsupportedOperationException("A Maven deployer cannot be used to resolve dependencies. It can only be used to publish artifacts.");
}
 
Example #16
Source File: AbstractMavenResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
    throw new UnsupportedOperationException("A Maven deployer cannot be used to resolve dependencies. It can only be used to publish artifacts.");
}
 
Example #17
Source File: IBiblioResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Override
public ArtifactOrigin locate(Artifact artifact) {
    ensureConfigured(getSettings());
    return super.locate(artifact);
}
 
Example #18
Source File: AbstractMavenResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactOrigin locate(Artifact artifact) {
    throw new UnsupportedOperationException("A Maven deployer cannot be used to resolve dependencies. It can only be used to publish artifacts.");
}
 
Example #19
Source File: LoopbackDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
    throw new UnsupportedOperationException();
}
 
Example #20
Source File: DownloadingRepositoryCacheManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public EnhancedArtifactDownloadReport download(Artifact artifact, ArtifactResourceResolver resourceResolver,
                                               ResourceDownloader resourceDownloader, CacheDownloadOptions options) {
    EnhancedArtifactDownloadReport adr = new EnhancedArtifactDownloadReport(artifact);

    DownloadListener listener = options.getListener();
    if (listener != null) {
        listener.needArtifact(this, artifact);
    }

    long start = System.currentTimeMillis();
    try {
        ResolvedResource artifactRef = resourceResolver.resolve(artifact);
        if (artifactRef != null) {
            final Resource resource = artifactRef.getResource();
            ArtifactOrigin origin = new ArtifactOrigin(artifact, resource.isLocal(), resource.getName());
            if (listener != null) {
                listener.startArtifactDownload(this, artifactRef, artifact, origin);
            }

            ModuleRevisionId moduleRevisionId = artifact.getModuleRevisionId();
            ModuleComponentIdentifier componentIdentifier = DefaultModuleComponentIdentifier.newId(moduleRevisionId.getOrganisation(), moduleRevisionId.getName(), moduleRevisionId.getRevision());
            File artifactFile = downloadAndCacheArtifactFile(new DefaultModuleVersionArtifactMetaData(componentIdentifier, artifact), artifact, resourceDownloader, artifactRef.getResource());

            adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
            adr.setSize(artifactFile.length());
            adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
            adr.setArtifactOrigin(origin);
            adr.setLocalFile(artifactFile);
        } else {
            adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
            adr.setDownloadStatus(DownloadStatus.FAILED);
            adr.setDownloadDetails(ArtifactDownloadReport.MISSING_ARTIFACT);
        }
    } catch (Throwable throwable) {
        adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
        adr.failed(throwable);
    }
    if (listener != null) {
        listener.endArtifactDownload(this, artifact, adr, adr.getLocalFile());
    }
    return adr;
}
 
Example #21
Source File: AbstractRepositoryCacheManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactOrigin getSavedArtifactOrigin(Artifact artifact) {
    return null;
}
 
Example #22
Source File: LegacyDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactOrigin locate(Artifact artifact) {
    // This is never used
    throw new UnsupportedOperationException();
}
 
Example #23
Source File: LegacyDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactDownloadReport download(ArtifactOrigin origin, DownloadOptions options) {
    // This is never used
    throw new UnsupportedOperationException();
}
 
Example #24
Source File: CacheResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Override
public ArtifactOrigin locate(Artifact artifact) {
    ensureConfigured();
    return super.locate(artifact);
}
 
Example #25
Source File: AbstractMavenResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
    throw new UnsupportedOperationException("A Maven deployer cannot be used to resolve dependencies. It can only be used to publish artifacts.");
}
 
Example #26
Source File: IvyRepResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Override
public ArtifactOrigin locate(Artifact artifact) {
    ensureArtifactConfigured(getSettings());
    return super.locate(artifact);
}
 
Example #27
Source File: LegacyDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactDownloadReport download(ArtifactOrigin origin, DownloadOptions options) {
    // This is never used
    throw new UnsupportedOperationException();
}
 
Example #28
Source File: LoopbackDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactDownloadReport download(ArtifactOrigin artifact, DownloadOptions options) {
    throw new UnsupportedOperationException();
}
 
Example #29
Source File: PomModuleDescriptorParser.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
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");
            }
        }
    }
}
 
Example #30
Source File: DownloadingRepositoryCacheManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public EnhancedArtifactDownloadReport download(Artifact artifact, ArtifactResourceResolver resourceResolver,
                                               ResourceDownloader resourceDownloader, CacheDownloadOptions options) {
    EnhancedArtifactDownloadReport adr = new EnhancedArtifactDownloadReport(artifact);

    DownloadListener listener = options.getListener();
    if (listener != null) {
        listener.needArtifact(this, artifact);
    }

    long start = System.currentTimeMillis();
    try {
        ResolvedResource artifactRef = resourceResolver.resolve(artifact);
        if (artifactRef != null) {
            final Resource resource = artifactRef.getResource();
            ArtifactOrigin origin = new ArtifactOrigin(artifact, resource.isLocal(), resource.getName());
            if (listener != null) {
                listener.startArtifactDownload(this, artifactRef, artifact, origin);
            }

            ModuleRevisionId moduleRevisionId = artifact.getModuleRevisionId();
            ModuleComponentIdentifier componentIdentifier = DefaultModuleComponentIdentifier.newId(moduleRevisionId.getOrganisation(), moduleRevisionId.getName(), moduleRevisionId.getRevision());
            File artifactFile = downloadAndCacheArtifactFile(new DefaultModuleVersionArtifactMetaData(componentIdentifier, artifact), artifact, resourceDownloader, artifactRef.getResource());

            adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
            adr.setSize(artifactFile.length());
            adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
            adr.setArtifactOrigin(origin);
            adr.setLocalFile(artifactFile);
        } else {
            adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
            adr.setDownloadStatus(DownloadStatus.FAILED);
            adr.setDownloadDetails(ArtifactDownloadReport.MISSING_ARTIFACT);
        }
    } catch (Throwable throwable) {
        adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
        adr.failed(throwable);
    }
    if (listener != null) {
        listener.endArtifactDownload(this, artifact, adr, adr.getLocalFile());
    }
    return adr;
}