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 2017/09/26 12:17:11 UTC
[6/9] brooklyn-server git commit: improve making bundle from folders
improve making bundle from folders
needed for tests now that we do more with bundles supplied in brooklyn.libraries
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/dcde6806
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/dcde6806
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/dcde6806
Branch: refs/heads/master
Commit: dcde6806264904ea31a71bf8565994d01b0e8d69
Parents: 69ea984
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Sep 21 14:08:40 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Sep 21 14:41:03 2017 +0100
----------------------------------------------------------------------
.../brooklyn/util/core/osgi/BundleMaker.java | 29 +++++++++++++++-----
1 file changed, 22 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/dcde6806/core/src/main/java/org/apache/brooklyn/util/core/osgi/BundleMaker.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/osgi/BundleMaker.java b/core/src/main/java/org/apache/brooklyn/util/core/osgi/BundleMaker.java
index 9116c0e..65b3aec 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/osgi/BundleMaker.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/osgi/BundleMaker.java
@@ -23,6 +23,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.net.URL;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;
@@ -298,16 +299,29 @@ public class BundleMaker {
return false;
}
- if (!addUrlDirToZipRecursively(zout, root, item, itemFound, filter)) {
- // can't reliably tell if item a file or a folder (listing files), esp w classpath where folder is just a list of files,
- // so try the latter and see if it succeeds
- // slightly inefficient but should work fine
- // only issue is that an empty dir and a file of size 0 will appear identical?
+ if (isKnownNotToBeADirectoryListing(item) || !
+ // can't reliably tell if item a file or a folder (listing files), esp w classpath where folder is treated as a list of files,
+ // so if we can't tell try it as a list of files; not guaranteed, and empty dir and a file of size 0 will appear identical, but better than was
+ // (mainly used for tests)
+ addUrlDirToZipRecursively(zout, root, item, itemFound, filter)) {
addUrlFileToZip(zout, root, item, filter);
}
return true;
}
+ private boolean isKnownNotToBeADirectoryListing(String item) {
+ try {
+ URL url = new URL(item);
+ if (url.getProtocol().equals("file")) {
+ return !new File(url.getFile()).isDirectory();
+ }
+ } catch (Exception e) {
+ Exceptions.propagateIfFatal(e);
+ // ignore otherwise -- probably unknown protocol
+ }
+ return false;
+ }
+
private boolean addUrlDirToZipRecursively(ZipOutputStream zout, String root, String item, InputStream itemFound, Predicate<? super String> filter) throws IOException {
LineReader lr = new LineReader(new InputStreamReader(itemFound));
boolean readSubdirFile = false;
@@ -325,7 +339,8 @@ public class BundleMaker {
// not a folder
return false;
} else {
- // previous entry made clear it was a folder, but this one didn't work!
+ // previous entry suggested it was a folder, but this one didn't work! -- was a false positive
+ // but zip will be in inconsistent state, so throw
throw new IllegalStateException("Failed to read entry "+line+" in "+item+" but previous entry implied it was a directory");
}
}
@@ -364,7 +379,7 @@ public class BundleMaker {
zout = mf!=null ? new JarOutputStream(new FileOutputStream(f2), mf) : new ZipOutputStream(new FileOutputStream(f2));
writeZipEntries(zout, files);
} catch (IOException e) {
- throw Exceptions.propagate("Unable to read/write for "+nameHint, e);
+ throw Exceptions.propagateAnnotated("Unable to read/write for "+nameHint, e);
} finally {
Streams.closeQuietly(zf);
Streams.closeQuietly(zout);