org.apache.ivy.plugins.repository.Repository Java Examples

The following examples show how to use org.apache.ivy.plugins.repository.Repository. 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: IvyPublisherForMaven.java    From jeka with Apache License 2.0 6 votes vote down vote up
private void putInRepo(Path source, String destination, boolean overwrite) {
    final Repository repository = this.resolver.getRepository();
    final String dest = completePath(destination);
    JkLog.info("Publish file " + dest);
    try {
        repository.put(null, source.toFile(), dest, overwrite);
        for (final String algo : checksumAlgos) {
            final Path temp = Files.createTempFile("jk-checksum-", algo);
            final String checkSum = ChecksumHelper.computeAsString(source.toFile(), algo);
            Files.write(temp, checkSum.getBytes());
            final String csDest = dest + "." + algo;
            JkLog.info("Publish file " + csDest);
            repository.put(null, temp.toFile(), csDest, overwrite);
            Files.deleteIfExists(temp);
        }
        if (this.signer != null) {
            final Path signed = signer.apply(source);
            final String signedDest = dest + ".asc";
            JkLog.info("Publish file " + signedDest);
            repository.put(null, signed.toFile(), signedDest, overwrite);
        }
    } catch (final IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #2
Source File: ChainedRepository.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public Resource getResource(String source) throws IOException {
    for (Repository repository : repositories) {
        logTry(repository);
        try {
            Resource r = repository.getResource(source);
            if (r != null && r.exists()) {
                logSuccess(repository);
                return r;
            }
        } catch (Exception e) {
            logFailed(repository, e);
        }
    }
    // resource that basically doesn't exists
    return new BasicResource(source, false, 0, 0, true);
}
 
Example #3
Source File: ChainedRepository.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public void get(String source, File destination) throws IOException {
    for (Repository repository : repositories) {
        logTry(repository);
        boolean ok = false;
        try {
            repository.get(source, destination);
            ok = true;
        } catch (Exception e) {
            logFailed(repository, e);
        }
        if (ok) {
            logSuccess(repository);
            return;
        }
    }
    throw newIOEFail("copy " + source + " into " + destination);
}
 
Example #4
Source File: DefaultRepositoryCacheManager.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public ArtifactDownloadReport downloadRepositoryResource(final Resource resource, String name,
        String type, String extension, CacheResourceOptions options, Repository repository) {

    String hash = computeResourceNameHash(resource);
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("_repository_metadata_", hash,
        Ivy.getWorkingRevision());
    Artifact artifact = new DefaultArtifact(mrid, null, name, type, extension);
    final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact);
    boolean useOrigin = isUseOrigin();

    try {
        DownloadListener listener = options.getListener();
        if (listener != null) {
            listener.needArtifact(this, artifact);
        }
        ArtifactOrigin savedOrigin = getSavedArtifactOrigin(artifact);
        File archiveFile = getArchiveFileInCache(artifact, savedOrigin, useOrigin);

        ArtifactOrigin origin = new ArtifactOrigin(artifact, resource.isLocal(),
                resource.getName());

        if (!options.isForce()
        // if the local file has been checked to be up to date enough recently, don't download
                && checkCacheUptodate(archiveFile, resource, savedOrigin, origin,
                    options.getTtl())) {
            if (archiveFile.exists()) {
                saveArtifactOrigin(artifact, origin);
                adr.setDownloadStatus(DownloadStatus.NO);
                adr.setSize(archiveFile.length());
                adr.setArtifactOrigin(savedOrigin);
                adr.setLocalFile(archiveFile);
            } else {
                // we trust the cache to says that the resource doesn't exist
                adr.setDownloadStatus(DownloadStatus.FAILED);
                adr.setDownloadDetails("Remote resource is known to not exist");
            }
        } else {
            long start = System.currentTimeMillis();
            origin.setLastChecked(start);
            try {
                ResolvedResource artifactRef = new ResolvedResource(resource,
                        Ivy.getWorkingRevision());
                if (useOrigin && resource.isLocal()) {
                    saveArtifactOrigin(artifact, origin);
                    archiveFile = getArchiveFileInCache(artifact, origin);
                    adr.setDownloadStatus(DownloadStatus.NO);
                    adr.setSize(archiveFile.length());
                    adr.setArtifactOrigin(origin);
                    adr.setLocalFile(archiveFile);
                } else {
                    if (listener != null) {
                        listener.startArtifactDownload(this, artifactRef, artifact, origin);
                    }

                    // actual download
                    if (archiveFile.exists()) {
                        archiveFile.delete();
                    }
                    File part = new File(archiveFile.getAbsolutePath() + ".part");
                    repository.get(resource.getName(), part);
                    if (!part.renameTo(archiveFile)) {
                        throw new IOException(
                                "impossible to move part file to definitive one: " + part
                                        + " -> " + archiveFile);
                    }

                    adr.setSize(archiveFile.length());
                    saveArtifactOrigin(artifact, origin);
                    adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
                    adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
                    adr.setArtifactOrigin(origin);
                    adr.setLocalFile(archiveFile);
                }
            } catch (Exception ex) {
                Message.debug(ex);
                origin.setExist(false);
                saveArtifactOrigin(artifact, origin);
                adr.setDownloadStatus(DownloadStatus.FAILED);
                adr.setDownloadDetails(ex.getMessage());
                adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
            }
        }
        if (listener != null) {
            listener.endArtifactDownload(this, artifact, adr, archiveFile);
        }
        return adr;
    } finally {
        unlockMetadataArtifact(mrid);
    }
}
 
Example #5
Source File: ChainedRepository.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public void setRepositories(List<Repository> repositories) {
    this.repositories = repositories;
}
 
Example #6
Source File: ChainedRepository.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private void logTry(Repository repository) {
    Message.debug("Mirrored repository " + getName() + ": trying " + repository.getName());
}
 
Example #7
Source File: ChainedRepository.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private void logFailed(Repository repository, Exception e) {
    Message.warn("Mirrored repository " + getName() + ": " + repository.getName()
            + " is not available", e);
    Message.warn("Trying the next one in the mirror list...");
}
 
Example #8
Source File: ChainedRepository.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private void logSuccess(Repository repository) {
    Message.debug("Mirrored repository " + getName() + ": success with " + repository.getName());
}
 
Example #9
Source File: IBiblioResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Override
protected ResolvedResource[] listResources(Repository repository, ModuleRevisionId mrid,
                                           String pattern, Artifact artifact) {
    if (shouldUseMavenMetadata(pattern)) {
        List<String> revs = listRevisionsWithMavenMetadata(repository, mrid.getModuleId()
                .getAttributes());
        if (revs != null) {
            Message.debug("\tfound revs: " + revs);
            List<ResolvedResource> rres = new ArrayList<>();
            for (String rev : revs) {
                ModuleRevisionId historicalMrid = ModuleRevisionId.newInstance(mrid, rev);

                String patternForRev = pattern;
                if (rev.endsWith("SNAPSHOT")) {
                    String snapshotVersion = findTimestampedSnapshotVersion(historicalMrid);
                    if (snapshotVersion != null) {
                        patternForRev = pattern.replaceFirst("\\-\\[revision\\]", "-"
                                + snapshotVersion);
                    }
                }
                String resolvedPattern = IvyPatternHelper.substitute(patternForRev,
                        historicalMrid, artifact);
                try {
                    Resource res = repository.getResource(resolvedPattern);
                    if (res != null) {
                        // we do not test if the resource actually exist here, it would cause
                        // a lot of checks which are not always necessary depending on the usage
                        // which is done of the returned ResolvedResource array
                        rres.add(new ResolvedResource(res, rev));
                    }
                } catch (IOException e) {
                    Message.warn(
                            "impossible to get resource from name listed by maven-metadata.xml:"
                                    + rres, e);
                }
            }
            return rres.toArray(new ResolvedResource[rres.size()]);
        } else {
            // maven metadata not available or something went wrong,
            // use default listing capability
            return super.listResources(repository, mrid, pattern, artifact);
        }
    } else {
        return super.listResources(repository, mrid, pattern, artifact);
    }
}
 
Example #10
Source File: IBiblioResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private List<String> listRevisionsWithMavenMetadata(Repository repository,
                                                    Map<String, String> tokenValues) {
    String metadataLocation = IvyPatternHelper.substituteTokens(root
            + "[organisation]/[module]/maven-metadata.xml", tokenValues);
    return listRevisionsWithMavenMetadata(repository, metadataLocation);
}
 
Example #11
Source File: RepositoryResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public Repository getRepository() {
    return repository;
}
 
Example #12
Source File: RepositoryResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public void setRepository(Repository repository) {
    this.repository = repository;
}
 
Example #13
Source File: RepositoryManifestIterable.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * Default constructor
 *
 * @param repo
 *            the root directory of the file system to lookup
 */
public RepositoryManifestIterable(Repository repo) {
    super("");
    this.repo = repo;
}
 
Example #14
Source File: RepositoryCacheManager.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * Download some repository resource and put it in the cache.
 * <p>
 * If the cached version is considered enough up to date, no downloading is done.
 *
 * @param resource   the resource of the file to put in cache
 * @param name       the descriptive name of the resource (helps while manually looking into the
 *                   cache files)
 * @param type       the type of the resource (helps while manually looking into the cache files)
 * @param extension  the extension of the resource (helps while manually looking into the cache
 *                   files)
 * @param options    a set of options to adjust the download
 * @param repository the repository which resolve the content of the resource
 * @return a report indicating how the download was performed
 */
ArtifactDownloadReport downloadRepositoryResource(Resource resource, String name,
                                                  String type, String extension,
                                                  CacheResourceOptions options,
                                                  Repository repository);
 
Example #15
Source File: RepositoryResolver.java    From ant-ivy with Apache License 2.0 2 votes vote down vote up
/**
 * List all revisions as resolved resources for the given artifact in the given repository using
 * the given pattern, and using the given mrid except its revision.
 *
 * @param repository
 *            the repository in which revisions should be located
 * @param mrid
 *            the module revision id to look for (except revision)
 * @param pattern
 *            the pattern to use to locate the revisions
 * @param artifact
 *            the artifact to find
 * @return an array of ResolvedResource, all pointing to a different revision of the given
 *         Artifact.
 */
protected ResolvedResource[] listResources(Repository repository, ModuleRevisionId mrid,
        String pattern, Artifact artifact) {
    return ResolverHelper.findAll(repository, mrid, pattern, artifact);
}