You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/08/06 23:16:54 UTC

[02/11] git commit: code tidy of ArchiveBuilder

code tidy of ArchiveBuilder


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/4bbf3b4f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/4bbf3b4f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/4bbf3b4f

Branch: refs/heads/master
Commit: 4bbf3b4f075c4e6bb3af284081dc84fe24f13004
Parents: 98a37f0
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Aug 1 16:27:27 2014 -0400
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Aug 5 10:40:37 2014 -0400

----------------------------------------------------------------------
 .../java/brooklyn/util/file/ArchiveBuilder.java | 45 ++++++++++----------
 .../brooklyn/util/file/ArchiveBuilderTest.java  |  2 +-
 2 files changed, 24 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4bbf3b4f/core/src/main/java/brooklyn/util/file/ArchiveBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/file/ArchiveBuilder.java b/core/src/main/java/brooklyn/util/file/ArchiveBuilder.java
index b5c98f5..9c01b35 100644
--- a/core/src/main/java/brooklyn/util/file/ArchiveBuilder.java
+++ b/core/src/main/java/brooklyn/util/file/ArchiveBuilder.java
@@ -37,6 +37,7 @@ import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.file.ArchiveUtils.ArchiveType;
 import brooklyn.util.os.Os;
 
+import com.google.common.annotations.Beta;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.LinkedHashMultimap;
 import com.google.common.collect.Multimap;
@@ -50,21 +51,17 @@ import com.google.common.io.Files;
  * specified. The created file must be a Java archive type, with the extension {@code .zip},
  * {@code .jar}, {@code .war} or {@code .ear}.
  * <p>
- * Examples:
+ * Example:
  * <pre> File zip = ArchiveBuilder.archive("data/archive.zip")
- *         .entry("src", applicationDir + "/deploy/" + version + "/src/")
- *         .entry("lib", applicationDir + "/deploy/" + version + "/lib/")
- *         .entry("etc/config.ini", applicationDir + "/config.ini")
+ *         .addAt(new File("./pom.xml"), "")
+ *         .addDirContentsAt(new File("./src"), "src/")
+ *         .addAt(new File("/tmp/Extra.java"), "src/main/java/")
+ *         .addDirContentsAt(new File("/tmp/overlay/"), "")
  *         .create();
  * </pre>
- * <pre> OutputStream remote = ...;
- * Map&lt;String, File&gt; entries = ...;
- * ArchiveBuilder.zip()
- *         .add("resources/data.csv")
- *         .addAll(entries)
- *         .stream(remote);
- * </pre>
+ * <p>
  */
+@Beta
 public class ArchiveBuilder {
 
     /**
@@ -178,28 +175,32 @@ public class ArchiveBuilder {
     }
 
     /**
-     * Add the file located at the {@code filePath}, relative to the {@code baseDir},
+     * Add the file located at the {@code fileSubPath}, relative to the {@code baseDir} on the local system,
      * to the archive.
      * <p>
-     * Uses the {@code filePath} as the name of the file in the archive. Note that the
-     * file is found by concatenating the two path components using {@link Os#mergePaths(String...)}
-     * which may not behave as expected if the {@code filePath} is absolute or points to
-     * a location above the current directory.
+     * Uses the {@code fileSubPath} as the name of the file in the archive. Note that the
+     * file is found by concatenating the two path components using {@link Os#mergePaths(String...)},
+     * thus {@code fileSubPath} should not be absolute or point to a location above the current directory.
      * <p>
      * Use {@link #entry(String, String)} directly or {@link #entries(Map)} for complete
      * control over file locations and names in the archive.
      *
      * @see #entry(String, String)
      */
-    public ArchiveBuilder addRelativeToBaseDir(String baseDir, String filePath) {
+    public ArchiveBuilder addFromLocalBaseDir(File baseDir, String fileSubPath) {
         checkNotNull(baseDir, "baseDir");
-        checkNotNull(filePath, "filePath");
-        return entry(Os.mergePaths(".", filePath), Os.mergePaths(baseDir, filePath));
+        checkNotNull(fileSubPath, "filePath");
+        return entry(Os.mergePaths(".", fileSubPath), Os.mergePaths(baseDir.getPath(), fileSubPath));
+    }
+    /** @deprecated since 0.7.0 use {@link #addFromLocalBaseDir(File, String)}, or
+     * one of the other add methods if adding relative to baseDir was not intended */ @Deprecated
+    public ArchiveBuilder addFromLocalBaseDir(String baseDir, String fileSubPath) {
+        return addFromLocalBaseDir(new File(baseDir), fileSubPath);
     }
-    /** @deprecated since 0.7.0 use {@link #addRelativeToBaseDir(String, String)}, or
+    /** @deprecated since 0.7.0 use {@link #addFromLocalBaseDir(File, String)}, or
      * one of the other add methods if adding relative to baseDir was not intended */ @Deprecated
-    public ArchiveBuilder add(String baseDir, String filePath) {
-        return addRelativeToBaseDir(baseDir, filePath);
+    public ArchiveBuilder add(String baseDir, String fileSubPath) {
+        return addFromLocalBaseDir(baseDir, fileSubPath);
     }
      
     /** adds the given file to the archive, preserving its name but putting under the given directory in the archive (may be <code>""</code> or <code>"./"</code>) */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4bbf3b4f/core/src/test/java/brooklyn/util/file/ArchiveBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/file/ArchiveBuilderTest.java b/core/src/test/java/brooklyn/util/file/ArchiveBuilderTest.java
index 222a312..6469f5a 100644
--- a/core/src/test/java/brooklyn/util/file/ArchiveBuilderTest.java
+++ b/core/src/test/java/brooklyn/util/file/ArchiveBuilderTest.java
@@ -167,7 +167,7 @@ public class ArchiveBuilderTest {
         ArchiveBuilder builder = ArchiveBuilder.zip();
         String baseDir = tmpDir.getName();
         for (String fileName : Arrays.asList("data01.txt", "data02.txt", "data03.txt")) {
-            builder.addRelativeToBaseDir(parentDir.getPath(), Os.mergePaths(baseDir, fileName));
+            builder.addFromLocalBaseDir(parentDir, Os.mergePaths(baseDir, fileName));
         }
         File archive = builder.create();
         archive.deleteOnExit();