Search in sources :

Example 1 with RetrieveReport

use of org.apache.ivy.core.retrieve.RetrieveReport in project ant-ivy by apache.

the class IvyRetrieve method doExecute.

@SuppressWarnings("deprecation")
@Override
public void doExecute() throws BuildException {
    prepareAndCheck();
    if (!getAllowedLogOptions().contains(getLog())) {
        throw new BuildException("invalid option for 'log': " + getLog() + ". Available options are " + getAllowedLogOptions());
    }
    pattern = getProperty(pattern, getSettings(), "ivy.retrieve.pattern");
    try {
        final Filter<Artifact> artifactFilter = getArtifactFilter();
        final RetrieveOptions retrieveOptions = (RetrieveOptions) new RetrieveOptions().setLog(getLog());
        retrieveOptions.setConfs(splitToArray(getConf())).setDestArtifactPattern(pattern).setDestIvyPattern(ivypattern).setArtifactFilter(artifactFilter).setSync(sync).setOverwriteMode(getOverwriteMode()).setUseOrigin(isUseOrigin()).setMakeSymlinks(symlink).setResolveId(getResolveId()).setMapper(mapper == null ? null : new MapperAdapter(mapper));
        // only set this if the user has explicitly enabled this deprecated option
        if (symlinkmass) {
            retrieveOptions.setMakeSymlinksInMass(symlinkmass);
        }
        final RetrieveReport report = getIvyInstance().retrieve(getResolvedMrid(), retrieveOptions);
        int targetsCopied = report.getNbrArtifactsCopied();
        boolean haveTargetsBeenCopied = targetsCopied > 0;
        getProject().setProperty("ivy.nb.targets.copied", String.valueOf(targetsCopied));
        getProject().setProperty("ivy.targets.copied", String.valueOf(haveTargetsBeenCopied));
        if (getPathId() != null) {
            Path path = new Path(getProject());
            getProject().addReference(getPathId(), path);
            for (File file : report.getRetrievedFiles()) {
                path.createPathElement().setLocation(file);
            }
        }
        if (getSetId() != null) {
            FileSet fileset = new FileSet();
            fileset.setProject(getProject());
            getProject().addReference(getSetId(), fileset);
            fileset.setDir(report.getRetrieveRoot());
            for (File file : report.getRetrievedFiles()) {
                PatternSet.NameEntry ne = fileset.createInclude();
                ne.setName(getPath(report.getRetrieveRoot(), file));
            }
        }
    } catch (Exception ex) {
        throw new BuildException("impossible to ivy retrieve: " + ex, ex);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) FileSet(org.apache.tools.ant.types.FileSet) RetrieveOptions(org.apache.ivy.core.retrieve.RetrieveOptions) Artifact(org.apache.ivy.core.module.descriptor.Artifact) BuildException(org.apache.tools.ant.BuildException) RetrieveReport(org.apache.ivy.core.retrieve.RetrieveReport) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) PatternSet(org.apache.tools.ant.types.PatternSet)

Aggregations

File (java.io.File)1 Artifact (org.apache.ivy.core.module.descriptor.Artifact)1 RetrieveOptions (org.apache.ivy.core.retrieve.RetrieveOptions)1 RetrieveReport (org.apache.ivy.core.retrieve.RetrieveReport)1 BuildException (org.apache.tools.ant.BuildException)1 FileSet (org.apache.tools.ant.types.FileSet)1 Path (org.apache.tools.ant.types.Path)1 PatternSet (org.apache.tools.ant.types.PatternSet)1