Java Code Examples for org.apache.ivy.Ivy#getWorkingRevision()

The following examples show how to use org.apache.ivy.Ivy#getWorkingRevision() . 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: ResolveEngine.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Resolve dependencies of a module described by an ivy file.
 *
 * @param ivySource URL
 * @param options ResolveOptions
 * @return ResolveReport
 * @throws ParseException if something goes wrong
 * @throws IOException if something goes wrong
 */
public ResolveReport resolve(URL ivySource, ResolveOptions options) throws ParseException,
        IOException {
    URLResource res = new URLResource(ivySource);
    ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(res);
    Message.verbose("using " + parser + " to parse " + ivySource);
    ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, options.isValidate());
    String revision = options.getRevision();
    if (revision == null && md.getResolvedModuleRevisionId().getRevision() == null) {
        revision = Ivy.getWorkingRevision();
    }
    if (revision != null) {
        md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(md.getModuleRevisionId(),
            revision));
    }

    return resolve(md, options);
}
 
Example 2
Source File: ModuleRevisionId.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private ModuleRevisionId(ModuleId moduleId, String branch, String revision,
        Map<String, String> extraAttributes, boolean replaceNullBranchWithDefault) {
    super(null, extraAttributes);
    this.moduleId = moduleId;
    IvyContext context = IvyContext.getContext();
    this.branch = (replaceNullBranchWithDefault && branch == null)
    // we test if there's already an Ivy instance loaded, to avoid loading a default one
    // just to get the default branch
    ? (context.peekIvy() == null ? null : context.getSettings().getDefaultBranch(moduleId))
            : branch;
    this.revision = revision == null ? Ivy.getWorkingRevision() : normalizeRevision(revision);
    setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, this.moduleId.getOrganisation());
    setStandardAttribute(IvyPatternHelper.MODULE_KEY, this.moduleId.getName());
    setStandardAttribute(IvyPatternHelper.BRANCH_KEY, this.branch);
    setStandardAttribute(IvyPatternHelper.REVISION_KEY, this.revision);
}
 
Example 3
Source File: IvyPostResolveTask.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
protected ModuleRevisionId getResolvedMrid() {
    return new ModuleRevisionId(getResolvedModuleId(),
            (getRevision() == null) ? Ivy.getWorkingRevision() : getRevision());
}
 
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);
    }
}