Sync with latest bnd code
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1363322 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Analyzer.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Analyzer.java
index 09c494f..d4e68ce 100755
--- a/bundleplugin/src/main/java/aQute/bnd/osgi/Analyzer.java
+++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Analyzer.java
@@ -35,6 +35,7 @@
import aQute.bnd.osgi.Descriptors.PackageRef;
import aQute.bnd.osgi.Descriptors.TypeRef;
import aQute.bnd.service.*;
+import aQute.bnd.version.Version;
import aQute.lib.base64.*;
import aQute.lib.collections.*;
import aQute.lib.filter.*;
diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Builder.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Builder.java
index a5bb7f6..d6fa2ba 100755
--- a/bundleplugin/src/main/java/aQute/bnd/osgi/Builder.java
+++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Builder.java
@@ -117,6 +117,8 @@
dot.updateModified(lastModified(), "Last Modified Processor");
dot.setName(getBsn());
+ doDigests(dot);
+
sign(dot);
doSaveManifest(dot);
@@ -138,7 +140,7 @@
return;
trace("digests %s", ps);
String[] digests = ps.keySet().toArray(new String[ps.size()]);
- dot.calcChecksums(digests);
+ dot.setDigestAlgorithms(digests);
}
/**
diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Domain.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Domain.java
index 828f1cf..bf7a31b 100644
--- a/bundleplugin/src/main/java/aQute/bnd/osgi/Domain.java
+++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Domain.java
@@ -7,6 +7,7 @@
import java.util.jar.*;
import aQute.bnd.header.*;
+import aQute.bnd.version.*;
import aQute.lib.converter.*;
import aQute.service.reporter.*;
diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Jar.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Jar.java
index b864297..11c0dab 100755
--- a/bundleplugin/src/main/java/aQute/bnd/osgi/Jar.java
+++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Jar.java
@@ -34,6 +34,7 @@
boolean nomanifest;
Compression compression = Compression.DEFLATE;
boolean closed;
+ String[] algorithms;
public Jar(String name) {
this.name = name;
@@ -241,6 +242,40 @@
public void write(OutputStream out) throws Exception {
check();
+
+ if (!doNotTouchManifest && !nomanifest && algorithms != null) {
+
+ // ok, we have a request to create digests
+ // of the resources. Since we have to output
+ // the manifest first, we have a slight problem.
+ // We can also not make multiple passes over the resource
+ // because some resources are not idempotent and/or can
+ // take significant time. So we just copy the jar
+ // to a temporary file, read it in again, calculate
+ // the checksums and save.
+
+ String[] algs = algorithms;
+ algorithms = null;
+ try {
+ File f = File.createTempFile(getName(), ".jar");
+ System.out.println("Created tmp file " + f);
+ write(f);
+ Jar tmp = new Jar(f);
+ try {
+ tmp.calcChecksums(algorithms);
+ tmp.write(out);
+ }
+ finally {
+ f.delete();
+ tmp.close();
+ }
+ }
+ finally {
+ algorithms = algs;
+ }
+ return;
+ }
+
ZipOutputStream jout = nomanifest || doNotTouchManifest ? new ZipOutputStream(out) : new JarOutputStream(out);
switch (compression) {
@@ -278,6 +313,7 @@
return;
JarEntry ze = new JarEntry("META-INF/MANIFEST.MF");
+
jout.putNextEntry(ze);
writeManifest(jout);
jout.closeEntry();
@@ -810,4 +846,8 @@
din.close();
}
}
+
+ public void setDigestAlgorithms(String[] algorithms) {
+ this.algorithms = algorithms;
+ }
}
diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Macro.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Macro.java
index f8474f4..4ac92d0 100755
--- a/bundleplugin/src/main/java/aQute/bnd/osgi/Macro.java
+++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Macro.java
@@ -7,6 +7,7 @@
import java.util.*;
import java.util.regex.*;
+import aQute.bnd.version.*;
import aQute.lib.collections.*;
import aQute.lib.io.*;
@@ -230,7 +231,7 @@
if (e.getCause() instanceof IllegalArgumentException) {
domain.error("%s, for cmd: %s, arguments; %s", e.getMessage(), method, Arrays.toString(args));
} else {
- domain.warning("Exception in replace: " + e.getCause());
+ domain.warning("Exception in replace: %s", e.getCause());
e.getCause().printStackTrace();
}
}
diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/TagResource.java b/bundleplugin/src/main/java/aQute/bnd/osgi/TagResource.java
deleted file mode 100644
index 183f1cd..0000000
--- a/bundleplugin/src/main/java/aQute/bnd/osgi/TagResource.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package aQute.bnd.osgi;
-
-import java.io.*;
-
-import aQute.lib.tag.*;
-
-public class TagResource extends WriteResource {
- final Tag tag;
-
- public TagResource(Tag tag) {
- this.tag = tag;
- }
-
- public void write(OutputStream out) throws UnsupportedEncodingException {
- OutputStreamWriter ow = new OutputStreamWriter(out, "UTF-8");
- PrintWriter pw = new PrintWriter(ow);
- pw.println("<?xml version='1.1'?>");
- try {
- tag.print(0, pw);
- }
- finally {
- pw.flush();
- }
- }
-
- public long lastModified() {
- return 0;
- }
-
-}
diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Version.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Version.java
deleted file mode 100755
index 951ad25..0000000
--- a/bundleplugin/src/main/java/aQute/bnd/osgi/Version.java
+++ /dev/null
@@ -1,164 +0,0 @@
-package aQute.bnd.osgi;
-
-import java.util.regex.*;
-
-public class Version implements Comparable<Version> {
- final int major;
- final int minor;
- final int micro;
- final String qualifier;
- public final static String VERSION_STRING = "(\\d+)(\\.(\\d+)(\\.(\\d+)(\\.([-_\\da-zA-Z]+))?)?)?";
- public final static Pattern VERSION = Pattern.compile(VERSION_STRING);
- public final static Version LOWEST = new Version();
- public final static Version HIGHEST = new Version(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE,
- "\uFFFF");
-
- public static final Version emptyVersion = LOWEST;
- public static final Version ONE = new Version(1, 0, 0);
-
- public Version() {
- this(0);
- }
-
- public Version(int major, int minor, int micro, String qualifier) {
- this.major = major;
- this.minor = minor;
- this.micro = micro;
- this.qualifier = qualifier;
- }
-
- public Version(int major, int minor, int micro) {
- this(major, minor, micro, null);
- }
-
- public Version(int major, int minor) {
- this(major, minor, 0, null);
- }
-
- public Version(int major) {
- this(major, 0, 0, null);
- }
-
- public Version(String version) {
- version = version.trim();
- Matcher m = VERSION.matcher(version);
- if (!m.matches())
- throw new IllegalArgumentException("Invalid syntax for version: " + version);
-
- major = Integer.parseInt(m.group(1));
- if (m.group(3) != null)
- minor = Integer.parseInt(m.group(3));
- else
- minor = 0;
-
- if (m.group(5) != null)
- micro = Integer.parseInt(m.group(5));
- else
- micro = 0;
-
- qualifier = m.group(7);
- }
-
- public int getMajor() {
- return major;
- }
-
- public int getMinor() {
- return minor;
- }
-
- public int getMicro() {
- return micro;
- }
-
- public String getQualifier() {
- return qualifier;
- }
-
- public int compareTo(Version other) {
- if (other == this)
- return 0;
-
- Version o = other;
- if (major != o.major)
- return major - o.major;
-
- if (minor != o.minor)
- return minor - o.minor;
-
- if (micro != o.micro)
- return micro - o.micro;
-
- int c = 0;
- if (qualifier != null)
- c = 1;
- if (o.qualifier != null)
- c += 2;
-
- switch (c) {
- case 0 :
- return 0;
- case 1 :
- return 1;
- case 2 :
- return -1;
- }
- return qualifier.compareTo(o.qualifier);
- }
-
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append(major);
- sb.append(".");
- sb.append(minor);
- sb.append(".");
- sb.append(micro);
- if (qualifier != null) {
- sb.append(".");
- sb.append(qualifier);
- }
- return sb.toString();
- }
-
- public boolean equals(Object ot) {
- if (!(ot instanceof Version))
- return false;
-
- return compareTo((Version) ot) == 0;
- }
-
- public int hashCode() {
- return major * 97 ^ minor * 13 ^ micro + (qualifier == null ? 97 : qualifier.hashCode());
- }
-
- public int get(int i) {
- switch (i) {
- case 0 :
- return major;
- case 1 :
- return minor;
- case 2 :
- return micro;
- default :
- throw new IllegalArgumentException("Version can only get 0 (major), 1 (minor), or 2 (micro)");
- }
- }
-
- public static Version parseVersion(String version) {
- if (version == null) {
- return LOWEST;
- }
-
- version = version.trim();
- if (version.length() == 0) {
- return LOWEST;
- }
-
- return new Version(version);
-
- }
-
- public Version getWithoutQualifier() {
- return new Version(major, minor, micro);
- }
-}
diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/VersionRange.java b/bundleplugin/src/main/java/aQute/bnd/osgi/VersionRange.java
deleted file mode 100755
index 8ff69a3..0000000
--- a/bundleplugin/src/main/java/aQute/bnd/osgi/VersionRange.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package aQute.bnd.osgi;
-
-import java.util.*;
-import java.util.regex.*;
-
-public class VersionRange {
- Version high;
- Version low;
- char start = '[';
- char end = ']';
-
- static Pattern RANGE = Pattern.compile("(\\(|\\[)\\s*(" + Version.VERSION_STRING + ")\\s*,\\s*("
- + Version.VERSION_STRING + ")\\s*(\\)|\\])");
-
- public VersionRange(String string) {
- string = string.trim();
- Matcher m = RANGE.matcher(string);
- if (m.matches()) {
- start = m.group(1).charAt(0);
- String v1 = m.group(2);
- String v2 = m.group(10);
- low = new Version(v1);
- high = new Version(v2);
- end = m.group(18).charAt(0);
- if (low.compareTo(high) > 0)
- throw new IllegalArgumentException("Low Range is higher than High Range: " + low + "-" + high);
-
- } else
- high = low = new Version(string);
- }
-
- public boolean isRange() {
- return high != low;
- }
-
- public boolean includeLow() {
- return start == '[';
- }
-
- public boolean includeHigh() {
- return end == ']';
- }
-
- public String toString() {
- if (high == low)
- return high.toString();
-
- StringBuilder sb = new StringBuilder();
- sb.append(start);
- sb.append(low);
- sb.append(',');
- sb.append(high);
- sb.append(end);
- return sb.toString();
- }
-
- public Version getLow() {
- return low;
- }
-
- public Version getHigh() {
- return high;
- }
-
- public boolean includes(Version v) {
- if (!isRange()) {
- return low.compareTo(v) <= 0;
- }
- if (includeLow()) {
- if (v.compareTo(low) < 0)
- return false;
- } else if (v.compareTo(low) <= 0)
- return false;
-
- if (includeHigh()) {
- if (v.compareTo(high) > 0)
- return false;
- } else if (v.compareTo(high) >= 0)
- return false;
-
- return true;
- }
-
- public Iterable<Version> filter(final Iterable<Version> versions) {
- List<Version> list = new ArrayList<Version>();
- for (Version v : versions) {
- if (includes(v))
- list.add(v);
- }
- return list;
- }
-
-}
\ No newline at end of file
diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/resource/Filters.java b/bundleplugin/src/main/java/aQute/bnd/osgi/resource/Filters.java
index 3194146..b8c7836 100644
--- a/bundleplugin/src/main/java/aQute/bnd/osgi/resource/Filters.java
+++ b/bundleplugin/src/main/java/aQute/bnd/osgi/resource/Filters.java
@@ -3,6 +3,7 @@
import org.osgi.framework.namespace.*;
import aQute.bnd.osgi.*;
+import aQute.bnd.version.*;
import aQute.libg.filters.*;
public class Filters {