ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maart...@apache.org
Subject svn commit: r1068587 - in /ant/ivy/core/trunk: ./ doc/use/ src/java/org/apache/ivy/ src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/retrieve/
Date Tue, 08 Feb 2011 21:27:00 GMT
Author: maartenc
Date: Tue Feb  8 21:27:00 2011
New Revision: 1068587

URL: http://svn.apache.org/viewvc?rev=1068587&view=rev
Log:
IMPROVEMENT: ivy:retrieve can now create a path or fileset containing the retrieved artifacts
(IVY-1235)

Added:
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveReport.java   (with props)
Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/doc/use/retrieve.html
    ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=1068587&r1=1068586&r2=1068587&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Tue Feb  8 21:27:00 2011
@@ -118,6 +118,7 @@ for detailed view of each issue, please 
 - NEW: ivy:resolve and post resole task can now have inlined dependencies declaration.
 - NEW: Import Bushel into Ivy core (IVY-1241)
 
+- IMPROVEMENT: ivy:retrieve can now create a path or fileset containing the retrieved artifacts
(IVY-1235)
 - IMPROVEMENT: Improve diagnostics in ssh resolver (IVY-1267) (thanks to Stepan Koltsov)
 - IMPROVEMENT: ivy:retrieve can now convert 'dotted'-organisation names into a directory
tree.
 

Modified: ant/ivy/core/trunk/doc/use/retrieve.html
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/use/retrieve.html?rev=1068587&r1=1068586&r2=1068587&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/use/retrieve.html (original)
+++ ant/ivy/core/trunk/doc/use/retrieve.html Tue Feb  8 21:27:00 2011
@@ -73,6 +73,10 @@ Available options are the same as for [[
 <ul><li><b>default</b></li> the default log settings, where
all usual messages are output to the console
 <li><b>quiet</b></li> disable all usual messages, making the whole
retrieve process quiet unless errors occur
 </ul></td><td>No, defaults to 'default'.</td></tr>
+    <tr><td>pathId</td><td>the id of the path to create containing
the retrieved artifacts. <span class="since">since 2.3.0</span></td>
+        <td>No. No path is created by default.</td></tr>
+    <tr><td>setId</td><td>the id of the fileset to create containing
the retrieved artifacts. <span class="since">since 2.3.0</span></td>
+        <td>No. No fileset is created by default.</td></tr>
 </table>
 <h1>Examples</h1>
 <code type="xml">

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java?rev=1068587&r1=1068586&r2=1068587&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java Tue Feb  8 21:27:00 2011
@@ -51,6 +51,7 @@ import org.apache.ivy.core.resolve.Resol
 import org.apache.ivy.core.resolve.ResolvedModuleRevision;
 import org.apache.ivy.core.retrieve.RetrieveEngine;
 import org.apache.ivy.core.retrieve.RetrieveOptions;
+import org.apache.ivy.core.retrieve.RetrieveReport;
 import org.apache.ivy.core.search.ModuleEntry;
 import org.apache.ivy.core.search.OrganisationEntry;
 import org.apache.ivy.core.search.RevisionEntry;
@@ -543,6 +544,16 @@ public class Ivy {
         }
     }
 
+    public RetrieveReport retrieve(ModuleRevisionId mrid, RetrieveOptions options)
+            throws IOException {
+        pushContext();
+        try {
+            return retrieveEngine.retrieve(mrid, options);
+        } finally {
+            popContext();
+        }
+    }
+
     // ///////////////////////////////////////////////////////////////////////
     // DELIVER
     // ///////////////////////////////////////////////////////////////////////

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java?rev=1068587&r1=1068586&r2=1068587&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyRetrieve.java Tue Feb  8 21:27:00 2011
@@ -17,13 +17,19 @@
  */
 package org.apache.ivy.ant;
 
+import java.io.File;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Iterator;
 
 import org.apache.ivy.core.LogOptions;
 import org.apache.ivy.core.retrieve.RetrieveOptions;
+import org.apache.ivy.core.retrieve.RetrieveReport;
 import org.apache.ivy.util.filter.Filter;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.PatternSet;
 
 /**
  * This task allow to retrieve dependencies from the cache to a local directory like a lib
dir.
@@ -51,6 +57,10 @@ public class IvyRetrieve extends IvyPost
 
     private String dirMode = RetrieveOptions.DIRMODE_FLAT;
 
+    private String pathId = null;
+
+    private String setId = null;
+
     public String getPattern() {
         return pattern;
     }
@@ -59,6 +69,22 @@ public class IvyRetrieve extends IvyPost
         this.pattern = pattern;
     }
 
+    public String getPathId() {
+        return pathId;
+    }
+
+    public void setPathId(String pathId) {
+        this.pathId = pathId;
+    }
+
+    public String getSetId() {
+        return setId;
+    }
+
+    public void setSetId(String setId) {
+        this.setId = setId;
+    }
+
     public void doExecute() throws BuildException {
         prepareAndCheck();
 
@@ -70,23 +96,47 @@ public class IvyRetrieve extends IvyPost
         pattern = getProperty(pattern, getSettings(), "ivy.retrieve.pattern");
         try {
             Filter artifactFilter = getArtifactFilter();
-            int targetsCopied = getIvyInstance().retrieve(
-                getResolvedMrid(),
-                pattern,
-                ((RetrieveOptions) new RetrieveOptions()
-                    .setLog(getLog()))
-                    .setConfs(splitConfs(getConf()))
-                    .setDestIvyPattern(ivypattern)
-                    .setArtifactFilter(artifactFilter)
-                    .setSync(sync)
-                    .setOverwriteMode(getOverwriteMode())
-                    .setDirMode(getDirMode())
-                    .setUseOrigin(isUseOrigin())
-                    .setMakeSymlinks(symlink)
-                    .setResolveId(getResolveId()));
+            RetrieveReport report = getIvyInstance().retrieve(
+                    getResolvedMrid(),
+                    ((RetrieveOptions) new RetrieveOptions()
+                            .setLog(getLog()))
+                            .setConfs(splitConfs(getConf()))
+                            .setDestArtifactPattern(pattern)
+                            .setDestIvyPattern(ivypattern)
+                            .setArtifactFilter(artifactFilter)
+                            .setSync(sync)
+                            .setOverwriteMode(getOverwriteMode())
+                            .setDirMode(getDirMode())
+                            .setUseOrigin(isUseOrigin())
+                            .setMakeSymlinks(symlink)
+                            .setResolveId(getResolveId()));
+
+            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 (Iterator iter = report.getRetrievedFiles().iterator(); iter.hasNext();
) {
+                    path.createPathElement().setLocation((File) iter.next());
+                }
+            }
+
+            if (getSetId() != null) {
+                FileSet fileset = new FileSet();
+                fileset.setProject(getProject());
+                getProject().addReference(getSetId(), fileset);
+
+                fileset.setDir(report.getRetrieveRoot());
+
+                for (Iterator iter = report.getRetrievedFiles().iterator(); iter.hasNext();
) {
+                    PatternSet.NameEntry ne = fileset.createInclude();
+                    ne.setName(getPath(report.getRetrieveRoot(), (File) iter.next()));
+                }
+            }
         } catch (Exception ex) {
             throw new BuildException("impossible to ivy retrieve: " + ex, ex);
         }
@@ -143,4 +193,26 @@ public class IvyRetrieve extends IvyPost
     public String getDirMode() {
         return dirMode;
     }
+
+    /**
+     * Returns the path of the file relative to the given base directory.
+     *
+     * @param base the parent directory to which the file must be evaluated.
+     * @param file the file for which the path should be returned
+     * @return the path of the file relative to the given base directory.
+     */
+    private String getPath(File base, File file) {
+        String absoluteBasePath = base.getAbsolutePath();
+
+        int beginIndex = absoluteBasePath.length();
+
+        // checks if the basePath ends with the file separator (which can for instance
+        // happen if the basePath is the root on unix)
+        if (!absoluteBasePath.endsWith(File.separator)) {
+            beginIndex++; // skip the seperator char as well
+        }
+
+        return file.getAbsolutePath().substring(beginIndex);
+    }
+    
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java?rev=1068587&r1=1068586&r2=1068587&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java Tue Feb 
8 21:27:00 2011
@@ -73,9 +73,20 @@ public class RetrieveEngine {
      * localCacheDirectory to determine an ivy report file, used as input for the copy If
such a
      * file does not exist for any conf (resolve has not been called before ?) then an
      * IllegalStateException is thrown and nothing is copied.
+     *
+     * @deprecated Use {@link #retrieve(org.apache.ivy.core.module.id.ModuleRevisionId, RetrieveOptions)}
instead
      */
-    public int retrieve(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options)
-            throws IOException {
+    public int retrieve(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options)
throws IOException {
+        RetrieveOptions retieveOptions = new RetrieveOptions(options);
+        retieveOptions.setDestArtifactPattern(destFilePattern);
+
+        RetrieveReport result = retrieve(mrid, retieveOptions);
+        return result.getNbrArtifactsCopied();
+    }
+
+    public RetrieveReport retrieve(ModuleRevisionId mrid, RetrieveOptions options) throws
IOException {
+        RetrieveReport report = new RetrieveReport();
+
         ModuleId moduleId = mrid.getModuleId();
         if (LogOptions.LOG_DEFAULT.equals(options.getLog())) {
             Message.info(":: retrieving :: " + moduleId + (options.isSync() ? " [sync]" :
""));
@@ -85,10 +96,8 @@ public class RetrieveEngine {
         Message.verbose("\tcheckUpToDate=" + settings.isCheckUpToDate());
         long start = System.currentTimeMillis();
 
-        destFilePattern = IvyPatternHelper.substituteVariables(destFilePattern, settings
-                .getVariables());
-        String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(),
-            settings.getVariables());
+        String destFilePattern = IvyPatternHelper.substituteVariables(options.getDestArtifactPattern(),
settings.getVariables());
+        String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(),
settings.getVariables());
 
         String[] confs = getConfs(mrid, options);
         if (LogOptions.LOG_DEFAULT.equals(options.getLog())) {
@@ -104,7 +113,8 @@ public class RetrieveEngine {
             Map artifactsToCopy = determineArtifactsToCopy(mrid, destFilePattern, options);
             File fileRetrieveRoot = settings.resolveFile(
                 IvyPatternHelper.getTokenRoot(destFilePattern));
-            File ivyRetrieveRoot = destIvyPattern == null 
+            report.setRetrieveRoot(fileRetrieveRoot);
+            File ivyRetrieveRoot = destIvyPattern == null
                 ? null : settings.resolveFile(IvyPatternHelper.getTokenRoot(destIvyPattern));
             Collection targetArtifactsStructure = new HashSet(); // Set(File) set of all
paths
             // which should be present at
@@ -113,8 +123,6 @@ public class RetrieveEngine {
             Collection targetIvysStructure = new HashSet(); // same for ivy files
 
             // do retrieve
-            int targetsCopied = 0;
-            int targetsUpToDate = 0;
             long totalCopiedSize = 0;
             for (Iterator iter = artifactsToCopy.keySet().iterator(); iter.hasNext();) {
                 ArtifactDownloadReport artifact = (ArtifactDownloadReport) iter.next();
@@ -144,11 +152,12 @@ public class RetrieveEngine {
                                 new EndRetrieveArtifactEvent(artifact, destFile));
                         }
                         totalCopiedSize += destFile.length();
-                        targetsCopied++;
+                        report.addCopiedFile(destFile);
                     } else {
                         Message.verbose("\t\tto " + destFile + " [NOT REQUIRED]");
-                        targetsUpToDate++;
+                        report.addUpToDateFile(destFile);
                     }
+
                     if ("ivy".equals(artifact.getType())) {
                         targetIvysStructure
                                 .addAll(FileUtil.getPathFiles(ivyRetrieveRoot, destFile));
@@ -184,9 +193,9 @@ public class RetrieveEngine {
             }
             long elapsedTime = System.currentTimeMillis() - start;
             String msg = "\t"
-                + targetsCopied
+                + report.getNbrArtifactsCopied()
                 + " artifacts copied"
-                + (settings.isCheckUpToDate() ? (", " + targetsUpToDate + " already retrieved")
+                + (settings.isCheckUpToDate() ? (", " + report.getNbrArtifactsUpToDate()
+ " already retrieved")
                         : "")
                 + " (" + (totalCopiedSize / KILO) + "kB/" + elapsedTime + "ms)";
             if (LogOptions.LOG_DEFAULT.equals(options.getLog())) {
@@ -197,11 +206,11 @@ public class RetrieveEngine {
             Message.verbose("\tretrieve done (" + (elapsedTime) + "ms)");
             if (this.eventManager != null) {
                 this.eventManager.fireIvyEvent(new EndRetrieveEvent(
-                    mrid, confs, elapsedTime, targetsCopied, targetsUpToDate, totalCopiedSize,

+                    mrid, confs, elapsedTime, report.getNbrArtifactsCopied(), report.getNbrArtifactsUpToDate(),
totalCopiedSize,
                     options));
             }
 
-            return targetsCopied;
+            return report;
         } catch (Exception ex) {
             throw new RuntimeException("problem during retrieve of " + moduleId + ": " +
ex, ex);
         }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java?rev=1068587&r1=1068586&r2=1068587&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java Tue Feb
 8 21:27:00 2011
@@ -48,6 +48,11 @@ public class RetrieveOptions extends Log
     private String destIvyPattern = null;
 
     /**
+     * The pattern to which artifacts should be retrieved.
+     */
+    private String destArtifactPattern = null;
+
+    /**
      * The filter to apply before retrieving artifacts.
      */
     private Filter artifactFilter = FilterHelper.NO_FILTER;
@@ -79,6 +84,32 @@ public class RetrieveOptions extends Log
      */
     private String resolveId;
 
+    public RetrieveOptions() {
+    }
+
+    public RetrieveOptions(RetrieveOptions options) {
+        super(options);
+        this.confs = options.confs;
+        this.destIvyPattern = options.destIvyPattern;
+        this.destArtifactPattern = options.destArtifactPattern;
+        this.artifactFilter = options.artifactFilter;
+        this.sync = options.sync;
+        this.overwriteMode = options.overwriteMode;
+        this.useOrigin = options.useOrigin;
+        this.makeSymlinks = options.makeSymlinks;
+        this.dirMode = options.dirMode;
+        this.resolveId = options.resolveId;
+    }
+
+    public String getDestArtifactPattern() {
+        return destArtifactPattern;
+    }
+
+    public RetrieveOptions setDestArtifactPattern(String destArtifactPattern) {
+        this.destArtifactPattern = destArtifactPattern;
+        return this;
+    }
+
     public String getDirMode() {
         return dirMode == null ? DIRMODE_FLAT : dirMode;
     }

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveReport.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveReport.java?rev=1068587&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveReport.java (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveReport.java Tue Feb 
8 21:27:00 2011
@@ -0,0 +1,84 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivy.core.retrieve;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+public class RetrieveReport {
+
+    private Collection/*<File>*/ upToDateFiles = new HashSet();
+    private Collection/*<File>*/ copiedFiles = new HashSet();
+
+    private File retrieveRoot;
+
+    /**
+     * Returns the root directory to where the artifacts are retrieved.
+     */
+    public File getRetrieveRoot() {
+        return retrieveRoot;
+    }
+
+    public void setRetrieveRoot(File retrieveRoot) {
+        this.retrieveRoot = retrieveRoot;
+    }
+
+    public int getNbrArtifactsCopied() {
+        return copiedFiles.size();
+    }
+
+    public int getNbrArtifactsUpToDate() {
+        return upToDateFiles.size();
+    }
+
+    public void addCopiedFile(File file) {
+        copiedFiles.add(file);
+    }
+
+    public void addUpToDateFile(File file) {
+        upToDateFiles.add(file);
+    }
+
+    /**
+     * Returns a collection of <tt>File</tt> objects who were actually copied
during the retrieve process.
+     */
+    public Collection getCopiedFiles() {
+        return new ArrayList(copiedFiles);
+    }
+
+    /**
+     * Returns a collection of <tt>File</tt> objects who were actually copied
during the retrieve process.
+     */
+    public Collection getUpToDateFiles() {
+        return new ArrayList(upToDateFiles);
+    }
+
+    /**
+     * Returns a collection of <tt>File</tt> objects who were retrieved during
the retrieve process. This is
+     * the union of the files being copied and the files that were up-to-date.
+     */
+    public Collection getRetrievedFiles() {
+        Collection result = new ArrayList(upToDateFiles.size() + copiedFiles.size());
+        result.addAll(upToDateFiles);
+        result.addAll(copiedFiles);
+        return result;
+    }
+
+}

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/core/retrieve/RetrieveReport.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message