ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r1375549 - in /ant/ivy/core/trunk: src/java/org/apache/ivy/core/cache/ src/java/org/apache/ivy/core/report/ src/java/org/apache/ivy/core/retrieve/ src/java/org/apache/ivy/plugins/report/ src/java/org/apache/ivy/util/ test/java/org/apache/iv...
Date Tue, 21 Aug 2012 13:58:37 GMT
Author: hibou
Date: Tue Aug 21 13:58:36 2012
New Revision: 1375549

URL: http://svn.apache.org/viewvc?rev=1375549&view=rev
Log:
Add support for retrieve of uncompressed artifacts

Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.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
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportParser.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java?rev=1375549&r1=1375548&r2=1375549&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
Tue Aug 21 13:58:36 2012
@@ -928,9 +928,7 @@ public class DefaultRepositoryCacheManag
         }
 
         // the artifact for the folder of the uncompressed data
-        DefaultArtifact uncompressed = new DefaultArtifact(artifact.getModuleRevisionId(),
-                artifact.getPublicationDate(), artifact.getName(), "_uncompressed", "");
-        adr.setUncompressedArtifact(uncompressed);
+        Artifact uncompressed = adr.buildUncompressedArtifact();
 
         File archiveFile = getArchiveFileInCache(uncompressed, null, false);
         if (archiveFile.exists() && !options.isForce()) {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java?rev=1375549&r1=1375548&r2=1375549&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java Tue
Aug 21 13:58:36 2012
@@ -21,6 +21,7 @@ import java.io.File;
 
 import org.apache.ivy.core.cache.ArtifactOrigin;
 import org.apache.ivy.core.module.descriptor.Artifact;
+import org.apache.ivy.core.module.descriptor.DefaultArtifact;
 
 /**
  * Report on the download of an artifact from a repository to a local (cached) file.
@@ -57,8 +58,6 @@ public class ArtifactDownloadReport {
 
     private File uncompressedLocalDir;
 
-    private Artifact uncompressedArtifact;
-
     public ArtifactDownloadReport(Artifact artifact) {
         this.artifact = artifact;
     }
@@ -159,12 +158,9 @@ public class ArtifactDownloadReport {
         return DownloadStatus.SUCCESSFUL == downloadStatus;
     }
 
-    public void setUncompressedArtifact(Artifact uncompressedArtifact) {
-        this.uncompressedArtifact = uncompressedArtifact;
-    }
-
-    public Artifact getUncompressedArtifact() {
-        return uncompressedArtifact;
+    public Artifact buildUncompressedArtifact() {
+        return new DefaultArtifact(artifact.getModuleRevisionId(), artifact.getPublicationDate(),
+                artifact.getName(), "_uncompressed", "");
     }
 
     public void setUncompressedLocalDir(File uncompressedLocalDir) {

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=1375549&r1=1375548&r2=1375549&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 Aug 21
13:58:36 2012
@@ -111,6 +111,7 @@ public class RetrieveEngine {
 
         try {
             Map/*<File, File>*/ destToSrcMap = null;
+            // Map<ArtifactDownloadReport, Set<String>>
             Map artifactsToCopy = determineArtifactsToCopy(mrid, destFilePattern, options);
             File fileRetrieveRoot = settings.resolveFile(
                 IvyPatternHelper.getTokenRoot(destFilePattern));
@@ -134,6 +135,9 @@ public class RetrieveEngine {
             for (Iterator iter = artifactsToCopy.keySet().iterator(); iter.hasNext();) {
                 ArtifactDownloadReport artifact = (ArtifactDownloadReport) iter.next();
                 File archive = artifact.getLocalFile();
+                if (options.isUncompressed() && artifact.getUncompressedLocalDir()
!= null) {
+                    archive = artifact.getUncompressedLocalDir();
+                }
                 if (archive == null) {
                     Message.verbose("\tno local file available for " + artifact + ": skipping");
                     continue;
@@ -170,7 +174,7 @@ public class RetrieveEngine {
                                         artifact, destFile));
                             }
                         }
-                        totalCopiedSize += destFile.length();
+                        totalCopiedSize += FileUtil.getFileLength(destFile);
                         report.addCopiedFile(destFile, artifact);
                     } else {
                         Message.verbose("\t\tto " + destFile + " [NOT REQUIRED]");
@@ -288,6 +292,9 @@ public class RetrieveEngine {
         }
     }
 
+    /**
+     * @return Map<ArtifactDownloadReport, Set<String>>
+     */
     public Map determineArtifactsToCopy(ModuleRevisionId mrid, String destFilePattern,
             RetrieveOptions options) throws ParseException, IOException {
         ModuleId moduleId = mrid.getModuleId();
@@ -328,22 +335,27 @@ public class RetrieveEngine {
                 }
             }
             for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
-                ArtifactDownloadReport artifact = (ArtifactDownloadReport) iter.next();
-                String destPattern = "ivy".equals(artifact.getType()) ? destIvyPattern
+                ArtifactDownloadReport adr = (ArtifactDownloadReport) iter.next();
+
+                Artifact artifact = adr.getArtifact();
+                if (options.isUncompressed() && adr.getUncompressedLocalDir() !=
null) {
+                    artifact = adr.buildUncompressedArtifact();
+                }
+
+                String destPattern = "ivy".equals(adr.getType()) ? destIvyPattern
                         : destFilePattern;
                 
-                if (!"ivy".equals(artifact.getType())
-                        && !options.getArtifactFilter().accept(artifact.getArtifact()))
{
+                if (!"ivy".equals(adr.getType())
+                        && !options.getArtifactFilter().accept(adr.getArtifact()))
{
                     continue; // skip this artifact, the filter didn't accept it!
                 }
 
                 String destFileName = IvyPatternHelper.substitute(destPattern,
-                            artifact.getArtifact().getModuleRevisionId(), artifact.getArtifact(),
-                            conf, artifact.getArtifactOrigin());
-                Set dest = (Set) artifactsToCopy.get(artifact);
+                    artifact.getModuleRevisionId(), artifact, conf, adr.getArtifactOrigin());
+                Set dest = (Set) artifactsToCopy.get(adr);
                 if (dest == null) {
                     dest = new HashSet();
-                    artifactsToCopy.put(artifact, dest);
+                    artifactsToCopy.put(adr, dest);
                 }
                 String copyDest = settings.resolveFile(destFileName).getAbsolutePath();
 
@@ -370,8 +382,8 @@ public class RetrieveEngine {
                         conflictsConf = new HashSet();
                         conflictsConfMap.put(destinations[j], conflictsConf);
                     }
-                    if (conflicts.add(artifact.getArtifact().getId())) {
-                        conflictsReports.add(artifact);
+                    if (conflicts.add(artifact.getId())) {
+                        conflictsReports.add(adr);
                         conflictsConf.add(conf);
                     }
                 }

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=1375549&r1=1375548&r2=1375549&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 Aug
21 13:58:36 2012
@@ -86,6 +86,7 @@ public class RetrieveOptions extends Log
     private String resolveId;
     
     private FileNameMapper mapper;
+    private boolean uncompressed;
 
     public RetrieveOptions() {
     }
@@ -103,6 +104,7 @@ public class RetrieveOptions extends Log
         this.makeSymlinksInMass = options.makeSymlinksInMass;
         this.resolveId = options.resolveId;
         this.mapper = options.mapper;
+        this.uncompressed = options.uncompressed;
     }
 
     public String getDestArtifactPattern() {
@@ -203,5 +205,13 @@ public class RetrieveOptions extends Log
         this.mapper = mapper;
         return this;
     }
-    
+
+    public boolean isUncompressed() {
+        return uncompressed;
+    }
+
+    public RetrieveOptions setUncompressed(boolean uncompressed) {
+        this.uncompressed = uncompressed;
+        return this;
+    }
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportParser.java?rev=1375549&r1=1375548&r2=1375549&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportParser.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportParser.java Tue Aug
21 13:58:36 2012
@@ -168,6 +168,10 @@ public class XmlReportParser {
                     if (attributes.getValue("location") != null) {
                         aReport.setLocalFile(new File(attributes.getValue("location")));
                     }
+                    if (attributes.getValue("uncompressedDir") != null) {
+                        aReport.setUncompressedLocalDir(new File(attributes
+                                .getValue("uncompressedDir")));
+                    }
                     revisionArtifacts.add(aReport);
                 } else if ("origin-location".equals(qName)) {
                     if (skip) {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java?rev=1375549&r1=1375548&r2=1375549&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/report/XmlReportWriter.java Tue Aug
21 13:58:36 2012
@@ -302,6 +302,11 @@ public class XmlReportWriter {
                 out.print(" location=\"" 
                     + XMLHelper.escape(adr[i].getLocalFile().getAbsolutePath()) + "\"");
             }
+            if (adr[i].getUncompressedLocalDir() != null) {
+                out.print(" uncompressedDir=\""
+                        + XMLHelper.escape(adr[i].getUncompressedLocalDir().getAbsolutePath())
+                        + "\"");
+            }
 
             ArtifactOrigin origin = adr[i].getArtifactOrigin();
             if (origin != null) {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java?rev=1375549&r1=1375548&r2=1375549&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java Tue Aug 21 13:58:36 2012
@@ -25,10 +25,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -169,6 +168,17 @@ public final class FileUtil {
     }
 
     public static boolean prepareCopy(File src, File dest, boolean overwrite) throws IOException
{
+        if (src.isDirectory()) {
+            if (dest.exists()) {
+                if (!dest.isDirectory()) {
+                    throw new IOException("impossible to copy: destination is not a directory:
" + dest);
+                }
+            } else {
+                dest.mkdirs();
+            }
+            return true;
+        }
+        // else it is a file copy
         if (dest.exists()) {
             if (!dest.isFile()) {
                 throw new IOException("impossible to copy: destination is not a file: " +
dest);
@@ -193,6 +203,10 @@ public final class FileUtil {
         if (!prepareCopy(src, dest, overwrite)) {
             return false;
         }
+        if (src.isDirectory()) {
+            return deepCopy(src, dest, l, overwrite);
+        }
+        // else it is a file copy
         copy(new FileInputStream(src), dest, l);
         long srcLen = src.length();
         long destLen = dest.length();
@@ -206,6 +220,50 @@ public final class FileUtil {
         return true;
     }
 
+    public static boolean deepCopy(File src, File dest, CopyProgressListener l, boolean overwrite)
+            throws IOException {
+        // the list of files which already exist in the destination folder
+        List/* <File> */existingChild = Collections.EMPTY_LIST;
+        if (dest.exists()) {
+            if (!dest.isDirectory()) {
+                // not expected type, remove
+                dest.delete();
+                // and create a folder
+                dest.mkdirs();
+                dest.setLastModified(src.lastModified());
+            } else {
+                // existing folder, gather existing children
+                File[] children = dest.listFiles();
+                if (children != null) {
+                    existingChild = Arrays.asList(children);
+                }
+            }
+        } else {
+            dest.mkdirs();
+            dest.setLastModified(src.lastModified());
+        }
+        // copy files one by one
+        File[] toCopy = src.listFiles();
+        if (toCopy != null) {
+            for (int i = 0; i < toCopy.length; i++) {
+                // compute the destination file
+                File childDest = new File(dest, toCopy[i].getName());
+                // if file existing, 'mark' it as taken care of
+                existingChild.remove(childDest);
+                if (toCopy[i].isDirectory()) {
+                    deepCopy(toCopy[i], childDest, l, overwrite);
+                } else {
+                    copy(toCopy[i], childDest, l, overwrite);
+                }
+            }
+        }
+        // some file exist in the destination but not in the source: delete them
+        for (int i = 0; i < existingChild.size(); i++) {
+            forceDelete((File) existingChild.get(i));
+        }
+        return true;
+    }
+
     public static void copy(URL src, File dest, CopyProgressListener l) throws IOException
{
         URLHandlerRegistry.getDefault().download(src, dest, l);
     }
@@ -548,7 +606,27 @@ public final class FileUtil {
         }
         return new String[] {root, path};
     }
- 
+
+    /**
+     * Get the length of the file, or the sum of the children lengths if it is a directory
+     * 
+     * @param file
+     * @return
+     */
+    public static long getFileLength(File file) {
+        long l = 0;
+        if (file.isDirectory()) {
+            File[] files = file.listFiles();
+            if (files != null) {
+                for (int i = 0; i < files.length; i++) {
+                    l += getFileLength(files[i]);
+                }
+            }
+        } else {
+            l = file.length();
+        }
+        return l;
+    }
 
 
 }

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java?rev=1375549&r1=1375548&r2=1375549&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java Tue Aug 21
13:58:36 2012
@@ -19,6 +19,7 @@ package org.apache.ivy.core.retrieve;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -305,6 +306,35 @@ public class RetrieveTest extends TestCa
         assertEquals(3, artifactsToCopy.size());
     }
 
+    public void testUncompress() throws Exception {
+        ResolveOptions roptions = getResolveOptions(new String[] {"*"});
+        roptions.setExpandCompressed(true);
+
+        URL url = new File("test/repositories/1/compression/module1/ivys/ivy-1.0.xml").toURI()
+                .toURL();
+
+        // normal resolve, the file goes in the cache
+        ResolveReport report = ivy.resolve(url, roptions);
+        assertFalse(report.hasError());
+        ModuleDescriptor md = report.getModuleDescriptor();
+        assertNotNull(md);
+
+        String pattern = "build/test/retrieve/[organization]/[module]/[conf]/[artifact]-[revision](.[ext])";
+
+        RetrieveOptions options = getRetrieveOptions();
+        options.setUncompressed(true);
+        ivy.retrieve(md.getModuleRevisionId(), pattern, options);
+
+        // NB
+        File dest = new File("build/test/retrieve/compression/module2/default/module2-1.0");
+        assertTrue(dest.exists());
+        assertTrue(dest.isDirectory());
+        File[] jarContents = dest.listFiles();
+        assertEquals(new File(dest, "META-INF"), jarContents[0]);
+        assertEquals(new File(dest, "test.txt"), jarContents[1]);
+        assertEquals(new File(dest, "META-INF/MANIFEST.MF"), jarContents[0].listFiles()[0]);
+    }
+
     private RetrieveOptions getRetrieveOptions() {
         return new RetrieveOptions();
     }



Mime
View raw message