Java Code Examples for org.apache.ivy.core.module.descriptor.Artifact#getModuleRevisionId()

The following examples show how to use org.apache.ivy.core.module.descriptor.Artifact#getModuleRevisionId() . 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: IBiblioResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Override
public ResolvedResource findArtifactRef(Artifact artifact, Date date) {
    ensureConfigured(getSettings());
    ModuleRevisionId mrid = artifact.getModuleRevisionId();
    if (isM2compatible()) {
        mrid = convertM2IdForResourceSearch(mrid);
    }
    final String revision = artifact.getId().getRevision();
    final MavenTimedSnapshotVersionMatcher.MavenSnapshotRevision snapshotRevision = MavenTimedSnapshotVersionMatcher.computeIfSnapshot(revision);
    if (snapshotRevision != null) {
        final ResolvedResource rres = findSnapshotArtifact(artifact, date, mrid, snapshotRevision);
        if (rres != null) {
            return rres;
        }
    }
    return findResourceUsingPatterns(mrid, getArtifactPatterns(), artifact,
            getDefaultRMDParser(artifact.getModuleRevisionId().getModuleId()), date);
}
 
Example 2
Source File: RepositoryResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public void publish(Artifact artifact, File src, boolean overwrite) throws IOException {
    String destPattern;
    if ("ivy".equals(artifact.getType()) && !getIvyPatterns().isEmpty()) {
        destPattern = getIvyPatterns().get(0);
    } else if (!getArtifactPatterns().isEmpty()) {
        destPattern = getArtifactPatterns().get(0);
    } else {
        throw new IllegalStateException("impossible to publish " + artifact + " using " + this
                + ": no artifact pattern defined");
    }
    // Check for m2 compatibility
    ModuleRevisionId mrid = artifact.getModuleRevisionId();
    if (isM2compatible()) {
        mrid = convertM2IdForResourceSearch(mrid);
    }

    String dest = getDestination(destPattern, artifact, mrid);

    put(artifact, src, dest, overwrite);
    Message.info("\tpublished " + artifact.getName() + " to "
            + hidePassword(repository.standardize(dest)));
}
 
Example 3
Source File: AbstractPatternsBasedResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Override
public ResolvedResource findArtifactRef(Artifact artifact, Date date) {
    ModuleRevisionId mrid = artifact.getModuleRevisionId();
    if (isM2compatible()) {
        mrid = convertM2IdForResourceSearch(mrid);
    }
    return findResourceUsingPatterns(mrid, artifactPatterns, artifact,
        getDefaultRMDParser(artifact.getModuleRevisionId().getModuleId()), date);
}
 
Example 4
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 5
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;
}
 
Example 6
Source File: BundleInfoAdapter.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public static URI buildIvyURI(Artifact artifact) {
    ModuleRevisionId mrid = artifact.getModuleRevisionId();
    return asIvyURI(mrid.getOrganisation(), mrid.getName(), mrid.getBranch(),
        mrid.getRevision(), artifact.getType(), artifact.getName(), artifact.getExt());
}
 
Example 7
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ArtifactDownloadReport download(Artifact artifact,
        ArtifactResourceResolver resourceResolver, ResourceDownloader resourceDownloader,
        CacheDownloadOptions options) {
    final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact);
    boolean useOrigin = isUseOrigin();

    // TODO: see if we could lock on the artifact to download only, instead of the module
    // metadata artifact. We'd need to store artifact origin and is local in artifact specific
    // file to do so, or lock the metadata artifact only to update artifact origin, which would
    // mean acquiring nested locks, which can be a dangerous thing
    ModuleRevisionId mrid = artifact.getModuleRevisionId();
    if (!lockMetadataArtifact(mrid)) {
        adr.setDownloadStatus(DownloadStatus.FAILED);
        adr.setDownloadDetails("impossible to get lock for " + mrid);
        return adr;
    }
    try {
        DownloadListener listener = options.getListener();
        if (listener != null) {
            listener.needArtifact(this, artifact);
        }
        ArtifactOrigin origin = getSavedArtifactOrigin(artifact);
        // if we can use origin file, we just ask ivy for the file in cache, and it will
        // return the original one if possible. If we are not in useOrigin mode, we use the
        // getArchivePath method which always return a path in the actual cache
        File archiveFile = getArchiveFileInCache(artifact, origin, useOrigin);

        if (archiveFile.exists() && !options.isForce()) {
            adr.setDownloadStatus(DownloadStatus.NO);
            adr.setSize(archiveFile.length());
            adr.setArtifactOrigin(origin);
            adr.setLocalFile(archiveFile);
        } else {
            long start = System.currentTimeMillis();
            try {
                ResolvedResource artifactRef = resourceResolver.resolve(artifact);
                if (artifactRef != null) {
                    Resource artifactRes = artifactRef.getResource();
                    origin = new ArtifactOrigin(artifact, artifactRes.isLocal(),
                            artifactRes.getName());
                    if (useOrigin && artifactRes.isLocal()) {
                        if (artifactRes instanceof LocalizableResource) {
                            origin.setLocation(((LocalizableResource) artifactRes).getFile()
                                    .getAbsolutePath());
                        }
                        saveArtifactOrigin(artifact, origin);
                        archiveFile = getArchiveFileInCache(artifact, origin);
                        adr.setDownloadStatus(DownloadStatus.NO);
                        adr.setSize(archiveFile.length());
                        adr.setArtifactOrigin(origin);
                        adr.setLocalFile(archiveFile);
                    } else {
                        // refresh archive file now that we better now its origin
                        archiveFile = getArchiveFileInCache(artifact, origin, useOrigin);
                        if (ResourceHelper.equals(artifactRes, archiveFile)) {
                            throw new IllegalStateException("invalid settings for '"
                                    + resourceResolver
                                    + "': pointing repository to ivy cache is forbidden !");
                        }
                        if (listener != null) {
                            listener.startArtifactDownload(this, artifactRef, artifact, origin);
                        }

                        resourceDownloader.download(artifact, artifactRes, archiveFile);
                        adr.setSize(archiveFile.length());
                        saveArtifactOrigin(artifact, origin);
                        adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
                        adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
                        adr.setArtifactOrigin(origin);
                        adr.setLocalFile(archiveFile);
                    }
                } else {
                    adr.setDownloadStatus(DownloadStatus.FAILED);
                    adr.setDownloadDetails(ArtifactDownloadReport.MISSING_ARTIFACT);
                    adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
                }
            } catch (Exception ex) {
                Message.debug(ex);
                adr.setDownloadStatus(DownloadStatus.FAILED);
                adr.setDownloadDetails(ex.getMessage());
                adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
            }
        }
        if (adr.getDownloadStatus() != DownloadStatus.FAILED) {
            unpackArtifact(artifact, adr, options);
        }
        if (listener != null) {
            listener.endArtifactDownload(this, artifact, adr, archiveFile);
        }
        return adr;
    } finally {
        unlockMetadataArtifact(mrid);
    }
}
 
Example 8
Source File: PackagerResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public synchronized ResolvedResource findArtifactRef(Artifact artifact, Date date) {

        // For our special packager.xml file, defer to superclass
        if (PACKAGER_ARTIFACT_NAME.equals(artifact.getName())
                && PACKAGER_ARTIFACT_TYPE.equals(artifact.getType())
                && PACKAGER_ARTIFACT_EXT.equals(artifact.getExt())) {
            return super.findArtifactRef(artifact, date);
        }

        // Check the cache
        ModuleRevisionId mr = artifact.getModuleRevisionId();
        PackagerCacheEntry entry = packagerCache.get(mr);

        // Ignore invalid entries
        if (entry != null && !entry.isBuilt()) {
            packagerCache.remove(mr);
            entry.cleanup();
            entry = null;
        }

        // Build the artifacts (if not done already)
        if (entry == null) {
            ResolvedResource packager = findArtifactRef(new DefaultArtifact(mr, null,
                    PACKAGER_ARTIFACT_NAME, PACKAGER_ARTIFACT_TYPE, PACKAGER_ARTIFACT_EXT), date);
            if (packager == null) {
                return null;
            }
            entry = new PackagerCacheEntry(mr, this.buildRoot, this.resourceCache,
                    this.resourceURL, this.validate, this.preserve, this.restricted, this.verbose,
                    this.quiet);
            try {
                entry.build(packager.getResource(), properties);
            } catch (IOException e) {
                throw new RuntimeException("can't build artifact " + artifact, e);
            }
            packagerCache.put(mr, entry);
        }

        // Return reference to desired artifact
        return entry.getBuiltArtifact(artifact);
    }