Another (in-place) bndlib update
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1368464 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Domain.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Domain.java
index bf7a31b..153674e 100644
--- a/bundleplugin/src/main/java/aQute/bnd/osgi/Domain.java
+++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Domain.java
@@ -288,11 +288,15 @@
String url = e.getKey();
if (selected == null)
selected = url;
-
- int size = Converter.cnv(Integer.class, e.getValue().get("size"));
- if (size != 0 && Math.abs(requestedSize - size) < dist) {
- dist = Math.abs(requestedSize - size);
- selected = url;
+ if (e.getValue() != null) {
+ String s = e.getValue().get("size");
+ if (s != null) {
+ int size = Converter.cnv(Integer.class, s);
+ if (size != 0 && Math.abs(requestedSize - size) < dist) {
+ dist = Math.abs(requestedSize - size);
+ selected = url;
+ }
+ }
}
}
return selected;
@@ -300,6 +304,6 @@
public void setConditionalPackage(String string) {
set(CONDITIONAL_PACKAGE, string);
-
+
}
}
diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Processor.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Processor.java
index 17b4df3..b153cb9 100755
--- a/bundleplugin/src/main/java/aQute/bnd/osgi/Processor.java
+++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Processor.java
@@ -358,6 +358,9 @@
Class< ? > c = loader.loadClass(key);
Object plugin = c.newInstance();
customize(plugin, entry.getValue());
+ if ( plugin instanceof Closeable){
+ addClose((Closeable)plugin);
+ }
list.add(plugin);
}
catch (Throwable t) {
diff --git a/bundleplugin/src/main/java/aQute/bnd/service/repository/packageinfo b/bundleplugin/src/main/java/aQute/bnd/service/repository/packageinfo
new file mode 100644
index 0000000..7c8de03
--- /dev/null
+++ b/bundleplugin/src/main/java/aQute/bnd/service/repository/packageinfo
@@ -0,0 +1 @@
+version 1.0
diff --git a/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java b/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java
index 5256594..922b39c 100644
--- a/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java
+++ b/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java
@@ -147,21 +147,26 @@
else
version = new Version(versionString);
- reporter.trace("bsn=%s version=%s", bsn, version);
+ if (reporter != null)
+ reporter.trace("bsn=%s version=%s", bsn, version);
File dir = new File(root, bsn);
dir.mkdirs();
String fName = bsn + "-" + version.getWithoutQualifier() + ".jar";
File file = new File(dir, fName);
- reporter.trace("updating %s ", file.getAbsolutePath());
+ if (reporter != null)
+ reporter.trace("updating %s ", file.getAbsolutePath());
if (!file.exists() || file.lastModified() < jar.lastModified()) {
jar.write(file);
- reporter.progress(-1, "updated " + file.getAbsolutePath());
+ if (reporter != null)
+ reporter.progress(-1, "updated " + file.getAbsolutePath());
fireBundleAdded(jar, file);
} else {
- reporter.progress(-1, "Did not update " + jar + " because repo has a newer version");
- reporter.trace("NOT Updating " + fName + " (repo is newer)");
+ if (reporter != null) {
+ reporter.progress(-1, "Did not update " + jar + " because repo has a newer version");
+ reporter.trace("NOT Updating " + fName + " (repo is newer)");
+ }
}
File latest = new File(dir, bsn + "-latest.jar");
diff --git a/bundleplugin/src/main/java/aQute/lib/io/IO.java b/bundleplugin/src/main/java/aQute/lib/io/IO.java
index 183d92a..616dfa4 100644
--- a/bundleplugin/src/main/java/aQute/lib/io/IO.java
+++ b/bundleplugin/src/main/java/aQute/lib/io/IO.java
@@ -222,6 +222,38 @@
return sw.toString();
}
+ /**
+ * Create a temporary file.
+ *
+ * @param directory
+ * the directory in which to create the file. Can be null, in
+ * which case the system TMP directory is used
+ * @param pattern
+ * the filename prefix pattern. Must be at least 3 characters
+ * long
+ * @param suffix
+ * the filename suffix. Can be null, in which case (system)
+ * default suffix is used
+ * @return
+ * @throws IllegalArgumentException
+ * when pattern is null or too short
+ * @throws IOException
+ * when the specified (non-null) directory is not a directory
+ */
+ public static File createTempFile(File directory, String pattern, String suffix) throws IllegalArgumentException,
+ IOException {
+ if ((pattern == null) || (pattern.length() < 3)) {
+ throw new IllegalArgumentException("Pattern must be at least 3 characters long, got "
+ + ((pattern == null) ? "null" : pattern.length()));
+ }
+
+ if ((directory != null) && !directory.isDirectory()) {
+ throw new FileNotFoundException("Directory " + directory + " is not a directory");
+ }
+
+ return File.createTempFile(pattern, suffix, directory);
+ }
+
public static File getFile(String filename) {
return new File(filename.replace("/", File.separator));
}
diff --git a/bundleplugin/src/main/java/aQute/lib/io/packageinfo b/bundleplugin/src/main/java/aQute/lib/io/packageinfo
index 897578f..71cb898 100644
--- a/bundleplugin/src/main/java/aQute/lib/io/packageinfo
+++ b/bundleplugin/src/main/java/aQute/lib/io/packageinfo
@@ -1 +1 @@
-version 1.2.0
+version 1.3.0
diff --git a/bundleplugin/src/main/java/aQute/lib/json/BooleanHandler.java b/bundleplugin/src/main/java/aQute/lib/json/BooleanHandler.java
index 5dd4990..9dfbaf4 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/BooleanHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/BooleanHandler.java
@@ -12,22 +12,22 @@
}
@Override
- Object decode(boolean s) {
+ Object decode(Decoder dec, boolean s) {
return s;
}
@Override
- Object decode(String s) {
+ Object decode(Decoder dec, String s) {
return Boolean.parseBoolean(s);
}
@Override
- Object decode(Number s) {
+ Object decode(Decoder dec, Number s) {
return s.intValue() != 0;
}
@Override
- Object decode() {
+ Object decode(Decoder dec) {
return false;
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java b/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java
index d956a6c..957369f 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java
@@ -5,12 +5,16 @@
import java.util.*;
import aQute.lib.base64.*;
+import aQute.lib.hex.*;
public class ByteArrayHandler extends Handler {
@Override
void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception {
- StringHandler.string(app, Base64.encodeBase64((byte[]) object));
+ if ( app.codec.isHex())
+ StringHandler.string(app, Hex.toHexString((byte[]) object));
+ else
+ StringHandler.string(app, Base64.encodeBase64((byte[]) object));
}
@Override
@@ -26,7 +30,10 @@
}
@Override
- Object decode(String s) throws Exception {
- return Base64.decodeBase64(s);
+ Object decode(Decoder dec, String s) throws Exception {
+ if ( dec.codec.isHex())
+ return Hex.toByteArray(s);
+ else
+ return Base64.decodeBase64(s);
}
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/CharacterHandler.java b/bundleplugin/src/main/java/aQute/lib/json/CharacterHandler.java
index 23605bf..799f73c 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/CharacterHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/CharacterHandler.java
@@ -13,22 +13,22 @@
}
@Override
- Object decode(boolean s) {
+ Object decode(Decoder dec, boolean s) {
return s ? 't' : 'f';
}
@Override
- Object decode(String s) {
+ Object decode(Decoder dec, String s) {
return (char) Integer.parseInt(s);
}
@Override
- Object decode(Number s) {
+ Object decode(Decoder dec, Number s) {
return (char) s.shortValue();
}
@Override
- Object decode() {
+ Object decode(Decoder dec) {
return 0;
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/DateHandler.java b/bundleplugin/src/main/java/aQute/lib/json/DateHandler.java
index 784fcbe..cb3c27e 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/DateHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/DateHandler.java
@@ -18,14 +18,14 @@
}
@Override
- Object decode(String s) throws Exception {
+ Object decode(Decoder dec, String s) throws Exception {
synchronized (sdf) {
return sdf.parse(s);
}
}
@Override
- Object decode(Number s) throws Exception {
+ Object decode(Decoder dec, Number s) throws Exception {
return new Date(s.longValue());
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/EnumHandler.java b/bundleplugin/src/main/java/aQute/lib/json/EnumHandler.java
index 85aad12..9b5eaf3 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/EnumHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/EnumHandler.java
@@ -17,8 +17,9 @@
StringHandler.string(app, object.toString());
}
+ @Override
@SuppressWarnings("unchecked")
- Object decode(String s) throws Exception {
+ Object decode(Decoder dec, String s) throws Exception {
return Enum.valueOf(type, s);
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/FileHandler.java b/bundleplugin/src/main/java/aQute/lib/json/FileHandler.java
index c024090..b2c0838 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/FileHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/FileHandler.java
@@ -25,7 +25,8 @@
}
}
- Object decode(String s) throws Exception {
+ @Override
+ Object decode(Decoder dec, String s) throws Exception {
File tmp = File.createTempFile("json", ".bin");
FileOutputStream fout = new FileOutputStream(tmp);
try {
diff --git a/bundleplugin/src/main/java/aQute/lib/json/Handler.java b/bundleplugin/src/main/java/aQute/lib/json/Handler.java
index c5e8b17..5738b04 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/Handler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/Handler.java
@@ -15,19 +15,19 @@
throw new UnsupportedOperationException("Cannot be mapped to array " + this);
}
- Object decode(@SuppressWarnings("unused") String s) throws Exception {
+ Object decode(Decoder dec, @SuppressWarnings("unused") String s) throws Exception {
throw new UnsupportedOperationException("Cannot be mapped to string " + this);
}
- Object decode(@SuppressWarnings("unused") Number s) throws Exception {
+ Object decode(Decoder dec, @SuppressWarnings("unused") Number s) throws Exception {
throw new UnsupportedOperationException("Cannot be mapped to number " + this);
}
- Object decode(@SuppressWarnings("unused") boolean s) {
+ Object decode(Decoder dec, @SuppressWarnings("unused") boolean s) {
throw new UnsupportedOperationException("Cannot be mapped to boolean " + this);
}
- Object decode() {
+ Object decode(Decoder dec) {
return null;
}
diff --git a/bundleplugin/src/main/java/aQute/lib/json/JSONCodec.java b/bundleplugin/src/main/java/aQute/lib/json/JSONCodec.java
index 8e608f8..47ad4ab 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/JSONCodec.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/JSONCodec.java
@@ -51,6 +51,7 @@
private static ByteArrayHandler byteh = new ByteArrayHandler();
boolean ignorenull;
+ boolean useHex;
/**
* Create a new Encoder with the state and appropriate API.
@@ -191,7 +192,8 @@
else if (Map.class.isAssignableFrom(rawClass))
h = new MapHandler(rawClass, pt.getActualTypeArguments()[0], pt.getActualTypeArguments()[1]);
else if (Dictionary.class.isAssignableFrom(rawClass))
- h = new MapHandler(Hashtable.class, pt.getActualTypeArguments()[0], pt.getActualTypeArguments()[1]);
+ h = new MapHandler(Hashtable.class, pt.getActualTypeArguments()[0],
+ pt.getActualTypeArguments()[1]);
else
throw new IllegalArgumentException("Found a parameterized type that is not a map or collection");
}
@@ -270,19 +272,19 @@
return h.decodeArray(isr);
case '"' :
- return h.decode(parseString(isr));
+ return h.decode(isr, parseString(isr));
case 'n' :
isr.expect("ull");
- return h.decode();
+ return h.decode(isr);
case 't' :
isr.expect("rue");
- return h.decode(Boolean.TRUE);
+ return h.decode(isr,Boolean.TRUE);
case 'f' :
isr.expect("alse");
- return h.decode(Boolean.FALSE);
+ return h.decode(isr,Boolean.FALSE);
case '0' :
case '1' :
@@ -295,7 +297,7 @@
case '8' :
case '9' :
case '-' :
- return h.decode(parseNumber(isr));
+ return h.decode(isr,parseNumber(isr));
default :
throw new IllegalArgumentException("Unexpected character in input stream: " + (char) c);
@@ -486,4 +488,19 @@
return ignorenull;
}
+ /**
+ * Use hex instead of default base 64 encoding
+ *
+ * @param useHex
+ * @return
+ */
+ public JSONCodec setHex(boolean useHex) {
+ this.useHex = useHex;
+ return this;
+ }
+
+ public boolean isHex() {
+ return useHex;
+ }
+
}
\ No newline at end of file
diff --git a/bundleplugin/src/main/java/aQute/lib/json/MapHandler.java b/bundleplugin/src/main/java/aQute/lib/json/MapHandler.java
index 62bf07f..504bb07 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/MapHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/MapHandler.java
@@ -62,7 +62,7 @@
Object key = r.codec.parseString(r);
if (!(keyType == null || keyType == Object.class)) {
Handler h = r.codec.getHandler(keyType);
- key = h.decode((String) key);
+ key = h.decode(r,(String) key);
}
c = r.skipWs();
diff --git a/bundleplugin/src/main/java/aQute/lib/json/NumberHandler.java b/bundleplugin/src/main/java/aQute/lib/json/NumberHandler.java
index 310ca3e..d8e6160 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/NumberHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/NumberHandler.java
@@ -21,23 +21,23 @@
}
@Override
- Object decode(boolean s) {
- return decode(s ? 1d : 0d);
+ Object decode(Decoder dec, boolean s) {
+ return decode(dec,s ? 1d : 0d);
}
@Override
- Object decode(String s) {
+ Object decode(Decoder dec, String s) {
double d = Double.parseDouble(s);
- return decode(d);
+ return decode(dec, d);
}
@Override
- Object decode() {
- return decode(0d);
+ Object decode(Decoder dec) {
+ return decode(dec,0d);
}
@Override
- Object decode(Number s) {
+ Object decode(Decoder dec, Number s) {
double dd = s.doubleValue();
if (type == double.class || type == Double.class)
diff --git a/bundleplugin/src/main/java/aQute/lib/json/SpecialHandler.java b/bundleplugin/src/main/java/aQute/lib/json/SpecialHandler.java
index bcd05ef..36218c8 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/SpecialHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/SpecialHandler.java
@@ -25,7 +25,7 @@
}
@Override
- Object decode(String s) throws Exception {
+ Object decode(Decoder dec, String s) throws Exception {
if (type == Pattern.class)
return Pattern.compile(s);
diff --git a/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java b/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java
index 0971826..ba62a13 100644
--- a/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java
+++ b/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java
@@ -59,19 +59,23 @@
app.append('"');
}
- Object decode(String s) throws Exception {
+ @Override
+ Object decode(Decoder dec, String s) throws Exception {
return s;
}
- Object decode(Number s) {
+ @Override
+ Object decode(Decoder dec, Number s) {
return s.toString();
}
- Object decode(boolean s) {
+ @Override
+ Object decode(Decoder dec, boolean s) {
return Boolean.toString(s);
}
- Object decode() {
+ @Override
+ Object decode(Decoder dec ) {
return null;
}
@@ -87,6 +91,7 @@
* An array can be assigned to a string. This means that the stream is
* interpreted as the array but stored in its complete in the string.
*/
+ @Override
Object decodeArray(Decoder r) throws Exception {
return collect(r, ']');
}