Latest bnd code
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1350613 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/aQute/libg/asn1/BER.java b/bundleplugin/src/main/java/aQute/libg/asn1/BER.java
index 4416dd4..bde15aa 100644
--- a/bundleplugin/src/main/java/aQute/libg/asn1/BER.java
+++ b/bundleplugin/src/main/java/aQute/libg/asn1/BER.java
@@ -5,468 +5,463 @@
import java.util.*;
public class BER implements Types {
- DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss\\Z");
-
- final DataInputStream xin;
- long position;
+ DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss\\Z");
- public BER(InputStream in) {
- this.xin = new DataInputStream(in);
- }
+ final DataInputStream xin;
+ long position;
- public void dump(PrintStream out) throws Exception {
- int type = readByte();
- long length = readLength();
- if (type == -1 || length == -1)
- throw new EOFException("Empty file");
- dump(out, type, length, "");
- }
+ public BER(InputStream in) {
+ this.xin = new DataInputStream(in);
+ }
- void dump(PrintStream out, int type, long length, String indent)
- throws Exception {
- int clss = type >> 6;
- int nmbr = type & 0x1F;
- boolean cnst = (type & 0x20) != 0;
+ public void dump(PrintStream out) throws Exception {
+ int type = readByte();
+ long length = readLength();
+ if (type == -1 || length == -1)
+ throw new EOFException("Empty file");
+ dump(out, type, length, "");
+ }
- String tag = "[" + nmbr + "]";
- if (clss == 0)
- tag = TAGS[nmbr];
+ void dump(PrintStream out, int type, long length, String indent) throws Exception {
+ int clss = type >> 6;
+ int nmbr = type & 0x1F;
+ boolean cnst = (type & 0x20) != 0;
- if (cnst) {
- System.err.printf("%5d %s %s %s%n", length, indent, CLASSES[clss],
- tag);
- while (length > 1) {
- long atStart = getPosition();
- int t2 = read();
- long l2 = readLength();
- dump(out, t2, l2, indent + " ");
- length -= getPosition() - atStart;
- }
- } else {
- assert length < Integer.MAX_VALUE;
- assert length >= 0;
- byte[] data = new byte[(int) length];
- readFully(data);
- String summary;
+ String tag = "[" + nmbr + "]";
+ if (clss == 0)
+ tag = TAGS[nmbr];
- switch (nmbr) {
- case BOOLEAN:
- assert length == 1;
- summary = data[0] != 0 ? "true" : "false";
- break;
+ if (cnst) {
+ System.err.printf("%5d %s %s %s%n", length, indent, CLASSES[clss], tag);
+ while (length > 1) {
+ long atStart = getPosition();
+ int t2 = read();
+ long l2 = readLength();
+ dump(out, t2, l2, indent + " ");
+ length -= getPosition() - atStart;
+ }
+ } else {
+ assert length < Integer.MAX_VALUE;
+ assert length >= 0;
+ byte[] data = new byte[(int) length];
+ readFully(data);
+ String summary;
- case INTEGER:
- long n = toLong(data);
- summary = n + "";
- break;
+ switch (nmbr) {
+ case BOOLEAN :
+ assert length == 1;
+ summary = data[0] != 0 ? "true" : "false";
+ break;
- case UTF8_STRING:
- case IA5STRING:
- case VISIBLE_STRING:
- case UNIVERSAL_STRING:
- case PRINTABLE_STRING:
- case UTCTIME:
- summary = new String(data, "UTF-8");
- break;
+ case INTEGER :
+ long n = toLong(data);
+ summary = n + "";
+ break;
- case OBJECT_IDENTIFIER:
- summary = readOID(data);
- break;
+ case UTF8_STRING :
+ case IA5STRING :
+ case VISIBLE_STRING :
+ case UNIVERSAL_STRING :
+ case PRINTABLE_STRING :
+ case UTCTIME :
+ summary = new String(data, "UTF-8");
+ break;
- case GENERALIZED_TIME:
- case GRAPHIC_STRING:
- case GENERAL_STRING:
- case CHARACTER_STRING:
+ case OBJECT_IDENTIFIER :
+ summary = readOID(data);
+ break;
- case REAL:
- case EOC:
- case BIT_STRING:
- case OCTET_STRING:
- case NULL:
- case OBJECT_DESCRIPTOR:
- case EXTERNAL:
- case ENUMERATED:
- case EMBEDDED_PDV:
- case RELATIVE_OID:
- case NUMERIC_STRING:
- case T61_STRING:
- case VIDEOTEX_STRING:
- case BMP_STRING:
- default:
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 10 && i < data.length; i++) {
- sb.append(Integer.toHexString(data[i]));
- }
- if (data.length > 10) {
- sb.append("...");
- }
- summary = sb.toString();
- break;
- }
- out.printf("%5d %s %s %s %s\n", length, indent, CLASSES[clss], tag,
- summary);
- }
- }
+ case GENERALIZED_TIME :
+ case GRAPHIC_STRING :
+ case GENERAL_STRING :
+ case CHARACTER_STRING :
- long toLong(byte[] data) {
- if (data[0] < 0) {
- for (int i = 0; i < data.length; i++)
- data[i] = (byte) (0xFF ^ data[i]);
+ case REAL :
+ case EOC :
+ case BIT_STRING :
+ case OCTET_STRING :
+ case NULL :
+ case OBJECT_DESCRIPTOR :
+ case EXTERNAL :
+ case ENUMERATED :
+ case EMBEDDED_PDV :
+ case RELATIVE_OID :
+ case NUMERIC_STRING :
+ case T61_STRING :
+ case VIDEOTEX_STRING :
+ case BMP_STRING :
+ default :
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < 10 && i < data.length; i++) {
+ sb.append(Integer.toHexString(data[i]));
+ }
+ if (data.length > 10) {
+ sb.append("...");
+ }
+ summary = sb.toString();
+ break;
+ }
+ out.printf("%5d %s %s %s %s\n", length, indent, CLASSES[clss], tag, summary);
+ }
+ }
- return -(toLong(data) + 1);
- }
- long n = 0;
- for (int i = 0; i < data.length; i++) {
- n = n * 256 + data[i];
- }
- return n;
- }
+ long toLong(byte[] data) {
+ if (data[0] < 0) {
+ for (int i = 0; i < data.length; i++)
+ data[i] = (byte) (0xFF ^ data[i]);
- /**
- * 8.1.3.3 For the definite form, the length octets shall consist of one or
- * more octets, and shall represent the number of octets in the contents
- * octets using either the short form (see 8.1.3.4) or the long form (see
- * 8.1.3.5) as a sender's option. NOTE – The short form can only be used if
- * the number of octets in the contents octets is less than or equal to 127.
- * 8.1.3.4 In the short form, the length octets shall consist of a single
- * octet in which bit 8 is zero and bits 7 to 1 encode the number of octets
- * in the contents octets (which may be zero), as an unsigned binary integer
- * with bit 7 as the most significant bit. EXAMPLE L = 38 can be encoded as
- * 001001102 8.1.3.5 In the long form, the length octets shall consist of an
- * initial octet and one or more subsequent octets. The initial octet shall
- * be encoded as follows: a) bit 8 shall be one; b) bits 7 to 1 shall encode
- * the number of subsequent octets in the length octets, as an unsigned
- * binary integer with bit 7 as the most significant bit; c) the value
- * 111111112 shall not be used. ISO/IEC 8825-1:2003 (E) NOTE 1 – This
- * restriction is introduced for possible future extension. Bits 8 to 1 of
- * the first subsequent octet, followed by bits 8 to 1 of the second
- * subsequent octet, followed in turn by bits 8 to 1 of each further octet
- * up to and including the last subsequent octet, shall be the encoding of
- * an unsigned binary integer equal to the number of octets in the contents
- * octets, with bit 8 of the first subsequent octet as the most significant
- * bit. EXAMPLE L = 201 can be encoded as: 100000012 110010012 NOTE 2 – In
- * the long form, it is a sender's option whether to use more length octets
- * than the minimum necessary. 8.1.3.6 For the indefinite form, the length
- * octets indicate that the contents octets are terminated by
- * end-of-contents octets (see 8.1.5), and shall consist of a single octet.
- * 8.1.3.6.1 The single octet shall have bit 8 set to one, and bits 7 to 1
- * set to zero. 8.1.3.6.2 If this form of length is used, then
- * end-of-contents octets (see 8.1.5) shall be present in the encoding
- * following the contents octets. 8.1.4 Contents octets The contents octets
- * shall consist of zero, one or more octets, and shall encode the data
- * value as specified in subsequent clauses. NOTE – The contents octets
- * depend on the type of the data value; subsequent clauses follow the same
- * sequence as the definition of types in ASN.1. 8.1.5 End-of-contents
- * octets The end-of-contents octets shall be present if the length is
- * encoded as specified in 8.1.3.6, otherwise they shall not be present. The
- * end-of-contents octets shall consist of two zero octets. NOTE – The
- * end-of-contents octets can be considered as the encoding of a value whose
- * tag is universal class, whose form is primitive, whose number of the tag
- * is zero, and whose contents are absent, thus:
- *
- * End-of-contents Length Contents 0016 0016 Absent
- *
- * @return
- */
- private long readLength() throws IOException {
- long n = readByte();
- if (n > 0) {
- // short form
- return n;
- }
+ return -(toLong(data) + 1);
+ }
+ long n = 0;
+ for (int i = 0; i < data.length; i++) {
+ n = n * 256 + data[i];
+ }
+ return n;
+ }
+
+ /**
+ * 8.1.3.3 For the definite form, the length octets shall consist of one or
+ * more octets, and shall represent the number of octets in the contents
+ * octets using either the short form (see 8.1.3.4) or the long form (see
+ * 8.1.3.5) as a sender's option. NOTE – The short form can only be used if
+ * the number of octets in the contents octets is less than or equal to 127.
+ * 8.1.3.4 In the short form, the length octets shall consist of a single
+ * octet in which bit 8 is zero and bits 7 to 1 encode the number of octets
+ * in the contents octets (which may be zero), as an unsigned binary integer
+ * with bit 7 as the most significant bit. EXAMPLE L = 38 can be encoded as
+ * 001001102 8.1.3.5 In the long form, the length octets shall consist of an
+ * initial octet and one or more subsequent octets. The initial octet shall
+ * be encoded as follows: a) bit 8 shall be one; b) bits 7 to 1 shall encode
+ * the number of subsequent octets in the length octets, as an unsigned
+ * binary integer with bit 7 as the most significant bit; c) the value
+ * 111111112 shall not be used. ISO/IEC 8825-1:2003 (E) NOTE 1 – This
+ * restriction is introduced for possible future extension. Bits 8 to 1 of
+ * the first subsequent octet, followed by bits 8 to 1 of the second
+ * subsequent octet, followed in turn by bits 8 to 1 of each further octet
+ * up to and including the last subsequent octet, shall be the encoding of
+ * an unsigned binary integer equal to the number of octets in the contents
+ * octets, with bit 8 of the first subsequent octet as the most significant
+ * bit. EXAMPLE L = 201 can be encoded as: 100000012 110010012 NOTE 2 – In
+ * the long form, it is a sender's option whether to use more length octets
+ * than the minimum necessary. 8.1.3.6 For the indefinite form, the length
+ * octets indicate that the contents octets are terminated by
+ * end-of-contents octets (see 8.1.5), and shall consist of a single octet.
+ * 8.1.3.6.1 The single octet shall have bit 8 set to one, and bits 7 to 1
+ * set to zero. 8.1.3.6.2 If this form of length is used, then
+ * end-of-contents octets (see 8.1.5) shall be present in the encoding
+ * following the contents octets. 8.1.4 Contents octets The contents octets
+ * shall consist of zero, one or more octets, and shall encode the data
+ * value as specified in subsequent clauses. NOTE – The contents octets
+ * depend on the type of the data value; subsequent clauses follow the same
+ * sequence as the definition of types in ASN.1. 8.1.5 End-of-contents
+ * octets The end-of-contents octets shall be present if the length is
+ * encoded as specified in 8.1.3.6, otherwise they shall not be present. The
+ * end-of-contents octets shall consist of two zero octets. NOTE – The
+ * end-of-contents octets can be considered as the encoding of a value whose
+ * tag is universal class, whose form is primitive, whose number of the tag
+ * is zero, and whose contents are absent, thus: End-of-contents Length
+ * Contents 0016 0016 Absent
+ *
+ * @return
+ */
+ private long readLength() throws IOException {
+ long n = readByte();
+ if (n > 0) {
+ // short form
+ return n;
+ }
// long form
int count = (int) (n & 0x7F);
if (count == 0) {
- // indefinite form
- return 0;
+ // indefinite form
+ return 0;
}
n = 0;
while (count-- > 0) {
- n = n * 256 + read();
+ n = n * 256 + read();
}
return n;
- }
+ }
- private int readByte() throws IOException {
- position++;
- return xin.readByte();
- }
+ private int readByte() throws IOException {
+ position++;
+ return xin.readByte();
+ }
- private void readFully(byte[] data) throws IOException {
- position += data.length;
- xin.readFully(data);
- }
+ private void readFully(byte[] data) throws IOException {
+ position += data.length;
+ xin.readFully(data);
+ }
- private long getPosition() {
- return position;
- }
+ private long getPosition() {
+ return position;
+ }
- private int read() throws IOException {
- position++;
- return xin.read();
- }
+ private int read() throws IOException {
+ position++;
+ return xin.read();
+ }
- String readOID(byte[] data) {
- StringBuilder sb = new StringBuilder();
- sb.append((0xFF & data[0]) / 40);
- sb.append(".");
- sb.append((0xFF & data[0]) % 40);
+ String readOID(byte[] data) {
+ StringBuilder sb = new StringBuilder();
+ sb.append((0xFF & data[0]) / 40);
+ sb.append(".");
+ sb.append((0xFF & data[0]) % 40);
- int i = 0;
- while (++i < data.length) {
- int n = 0;
- while (data[i] < 0) {
- n = n * 128 + (0x7F & data[i]);
- i++;
- }
- n = n * 128 + data[i];
- sb.append(".");
- sb.append(n);
- }
+ int i = 0;
+ while (++i < data.length) {
+ int n = 0;
+ while (data[i] < 0) {
+ n = n * 128 + (0x7F & data[i]);
+ i++;
+ }
+ n = n * 128 + data[i];
+ sb.append(".");
+ sb.append(n);
+ }
- return sb.toString();
- }
+ return sb.toString();
+ }
- int getPayloadLength(PDU pdu) throws Exception {
- switch (pdu.getTag() & 0x1F) {
- case EOC:
- return 1;
+ int getPayloadLength(PDU pdu) throws Exception {
+ switch (pdu.getTag() & 0x1F) {
+ case EOC :
+ return 1;
- case BOOLEAN:
- return 1;
+ case BOOLEAN :
+ return 1;
- case INTEGER:
- return size(pdu.getInt());
+ case INTEGER :
+ return size(pdu.getInt());
- case UTF8_STRING:
- String s = pdu.getString();
- byte[] encoded = s.getBytes("UTF-8");
- return encoded.length;
+ case UTF8_STRING :
+ String s = pdu.getString();
+ byte[] encoded = s.getBytes("UTF-8");
+ return encoded.length;
- case IA5STRING:
- case VISIBLE_STRING:
- case UNIVERSAL_STRING:
- case PRINTABLE_STRING:
- case GENERALIZED_TIME:
- case GRAPHIC_STRING:
- case GENERAL_STRING:
- case CHARACTER_STRING:
- case UTCTIME:
- case NUMERIC_STRING: {
- String str = pdu.getString();
- encoded = str.getBytes("ASCII");
- return encoded.length;
- }
+ case IA5STRING :
+ case VISIBLE_STRING :
+ case UNIVERSAL_STRING :
+ case PRINTABLE_STRING :
+ case GENERALIZED_TIME :
+ case GRAPHIC_STRING :
+ case GENERAL_STRING :
+ case CHARACTER_STRING :
+ case UTCTIME :
+ case NUMERIC_STRING : {
+ String str = pdu.getString();
+ encoded = str.getBytes("ASCII");
+ return encoded.length;
+ }
- case OBJECT_IDENTIFIER:
- case REAL:
- case BIT_STRING:
- return pdu.getBytes().length;
+ case OBJECT_IDENTIFIER :
+ case REAL :
+ case BIT_STRING :
+ return pdu.getBytes().length;
- case OCTET_STRING:
- case NULL:
- case OBJECT_DESCRIPTOR:
- case EXTERNAL:
- case ENUMERATED:
- case EMBEDDED_PDV:
- case RELATIVE_OID:
- case T61_STRING:
- case VIDEOTEX_STRING:
- case BMP_STRING:
- return pdu.getBytes().length;
+ case OCTET_STRING :
+ case NULL :
+ case OBJECT_DESCRIPTOR :
+ case EXTERNAL :
+ case ENUMERATED :
+ case EMBEDDED_PDV :
+ case RELATIVE_OID :
+ case T61_STRING :
+ case VIDEOTEX_STRING :
+ case BMP_STRING :
+ return pdu.getBytes().length;
- default:
- throw new IllegalArgumentException("Invalid type: " + pdu);
- }
- }
+ default :
+ throw new IllegalArgumentException("Invalid type: " + pdu);
+ }
+ }
- int size(long value) {
- if (value < 128)
- return 1;
+ int size(long value) {
+ if (value < 128)
+ return 1;
- if (value <= 0xFF)
- return 2;
+ if (value <= 0xFF)
+ return 2;
- if (value <= 0xFFFF)
- return 3;
+ if (value <= 0xFFFF)
+ return 3;
- if (value <= 0xFFFFFF)
- return 4;
+ if (value <= 0xFFFFFF)
+ return 4;
- if (value <= 0xFFFFFFFF)
- return 5;
+ if (value <= 0xFFFFFFFF)
+ return 5;
- if (value <= 0xFFFFFFFFFFL)
- return 6;
+ if (value <= 0xFFFFFFFFFFL)
+ return 6;
- if (value <= 0xFFFFFFFFFFFFL)
- return 7;
+ if (value <= 0xFFFFFFFFFFFFL)
+ return 7;
- if (value <= 0xFFFFFFFFFFFFFFL)
- return 8;
+ if (value <= 0xFFFFFFFFFFFFFFL)
+ return 8;
- if (value <= 0xFFFFFFFFFFFFFFFFL)
- return 9;
+ if (value <= 0xFFFFFFFFFFFFFFFFL)
+ return 9;
- throw new IllegalArgumentException("length too long");
- }
+ throw new IllegalArgumentException("length too long");
+ }
- public void write(OutputStream out, PDU pdu) throws Exception {
- byte id = 0;
+ public void write(OutputStream out, PDU pdu) throws Exception {
+ byte id = 0;
- switch (pdu.getClss()) {
- case UNIVERSAL:
- id |= 0;
- break;
- case APPLICATION:
- id |= 0x40;
- break;
- case CONTEXT:
- id |= 0x80;
- break;
- case PRIVATE:
- id |= 0xC0;
- break;
- }
+ switch (pdu.getClss()) {
+ case UNIVERSAL :
+ id |= 0;
+ break;
+ case APPLICATION :
+ id |= 0x40;
+ break;
+ case CONTEXT :
+ id |= 0x80;
+ break;
+ case PRIVATE :
+ id |= 0xC0;
+ break;
+ }
- if (pdu.isConstructed())
- id |= 0x20;
+ if (pdu.isConstructed())
+ id |= 0x20;
- int tag = pdu.getTag();
- if (tag >= 0 && tag < 31) {
- id |= tag;
- } else {
- throw new UnsupportedOperationException("Cant do tags > 30");
- }
+ int tag = pdu.getTag();
+ if (tag >= 0 && tag < 31) {
+ id |= tag;
+ } else {
+ throw new UnsupportedOperationException("Cant do tags > 30");
+ }
- out.write(id);
+ out.write(id);
- int length = getPayloadLength(pdu);
- int size = size(length);
- if (size == 1) {
- out.write(length);
- } else {
- out.write(size);
- while (--size >= 0) {
- byte data = (byte) ((length >> (size * 8)) & 0xFF);
- out.write(data);
- }
- }
- writePayload(out, pdu);
- }
+ int length = getPayloadLength(pdu);
+ int size = size(length);
+ if (size == 1) {
+ out.write(length);
+ } else {
+ out.write(size);
+ while (--size >= 0) {
+ byte data = (byte) ((length >> (size * 8)) & 0xFF);
+ out.write(data);
+ }
+ }
+ writePayload(out, pdu);
+ }
- void writePayload(OutputStream out, PDU pdu) throws Exception {
- switch (pdu.getTag()) {
- case EOC:
- out.write(0);
- break;
+ void writePayload(OutputStream out, PDU pdu) throws Exception {
+ switch (pdu.getTag()) {
+ case EOC :
+ out.write(0);
+ break;
- case BOOLEAN:
- if (pdu.getBoolean())
- out.write(-1);
- else
- out.write(0);
- break;
+ case BOOLEAN :
+ if (pdu.getBoolean())
+ out.write(-1);
+ else
+ out.write(0);
+ break;
- case ENUMERATED:
- case INTEGER: {
- long value = pdu.getInt();
- int size = size(value);
- for (int i = size; i >= 0; i--) {
- byte b = (byte) ((value >> (i * 8)) & 0xFF);
- out.write(b);
- }
- }
+ case ENUMERATED :
+ case INTEGER : {
+ long value = pdu.getInt();
+ int size = size(value);
+ for (int i = size; i >= 0; i--) {
+ byte b = (byte) ((value >> (i * 8)) & 0xFF);
+ out.write(b);
+ }
+ }
- case BIT_STRING: {
- byte bytes[] = pdu.getBytes();
- int unused = bytes[0];
- assert unused <= 7;
- int[] mask = { 0xFF, 0x7F, 0x3F, 0x1F, 0xF, 0x7, 0x3, 0x1 };
- bytes[bytes.length - 1] &= (byte) mask[unused];
- out.write(bytes);
- break;
- }
+ case BIT_STRING : {
+ byte bytes[] = pdu.getBytes();
+ int unused = bytes[0];
+ assert unused <= 7;
+ int[] mask = {
+ 0xFF, 0x7F, 0x3F, 0x1F, 0xF, 0x7, 0x3, 0x1
+ };
+ bytes[bytes.length - 1] &= (byte) mask[unused];
+ out.write(bytes);
+ break;
+ }
- case RELATIVE_OID:
- case OBJECT_IDENTIFIER: {
- int[] oid = pdu.getOID();
- assert oid.length > 2;
- assert oid[0] < 4;
- assert oid[1] < 40;
- byte top = (byte) (oid[0] * 40 + oid[1]);
- out.write(top);
- for (int i = 2; i < oid.length; i++) {
- putOid(out,oid[i]);
- }
- break;
- }
+ case RELATIVE_OID :
+ case OBJECT_IDENTIFIER : {
+ int[] oid = pdu.getOID();
+ assert oid.length > 2;
+ assert oid[0] < 4;
+ assert oid[1] < 40;
+ byte top = (byte) (oid[0] * 40 + oid[1]);
+ out.write(top);
+ for (int i = 2; i < oid.length; i++) {
+ putOid(out, oid[i]);
+ }
+ break;
+ }
- case OCTET_STRING: {
- byte bytes[] = pdu.getBytes();
- out.write(bytes);
- break;
- }
+ case OCTET_STRING : {
+ byte bytes[] = pdu.getBytes();
+ out.write(bytes);
+ break;
+ }
- case NULL:
- break;
+ case NULL :
+ break;
- case BMP_STRING:
- case GRAPHIC_STRING:
- case VISIBLE_STRING:
- case GENERAL_STRING:
- case UNIVERSAL_STRING:
- case CHARACTER_STRING:
- case NUMERIC_STRING:
- case PRINTABLE_STRING:
- case VIDEOTEX_STRING:
- case T61_STRING:
- case REAL:
- case EMBEDDED_PDV:
- case EXTERNAL:
- throw new UnsupportedEncodingException("dont know real, embedded PDV or external");
-
- case UTF8_STRING: {
- String s = pdu.getString();
- byte [] data = s.getBytes("UTF-8");
- out.write(data);
- break;
- }
-
- case OBJECT_DESCRIPTOR:
- case IA5STRING:
- String s = pdu.getString();
- byte [] data = s.getBytes("ASCII");
- out.write(data);
- break;
-
-
- case SEQUENCE:
- case SET: {
- PDU pdus[] = pdu.getChildren();
- for ( PDU p : pdus ) {
- write(out, p);
- }
- }
-
-
- case UTCTIME:
- case GENERALIZED_TIME:
- Date date = pdu.getDate();
- String ss= df.format(date);
- byte d[] = ss.getBytes("ASCII");
- out.write(d);
- break;
-
- }
- }
-
+ case BMP_STRING :
+ case GRAPHIC_STRING :
+ case VISIBLE_STRING :
+ case GENERAL_STRING :
+ case UNIVERSAL_STRING :
+ case CHARACTER_STRING :
+ case NUMERIC_STRING :
+ case PRINTABLE_STRING :
+ case VIDEOTEX_STRING :
+ case T61_STRING :
+ case REAL :
+ case EMBEDDED_PDV :
+ case EXTERNAL :
+ throw new UnsupportedEncodingException("dont know real, embedded PDV or external");
- private void putOid(OutputStream out, int i) throws IOException {
- if (i > 127) {
- putOid(out, i >> 7);
- out.write(0x80 + (i & 0x7F));
- } else
- out.write(i & 0x7F);
- }
+ case UTF8_STRING : {
+ String s = pdu.getString();
+ byte[] data = s.getBytes("UTF-8");
+ out.write(data);
+ break;
+ }
+
+ case OBJECT_DESCRIPTOR :
+ case IA5STRING :
+ String s = pdu.getString();
+ byte[] data = s.getBytes("ASCII");
+ out.write(data);
+ break;
+
+ case SEQUENCE :
+ case SET : {
+ PDU pdus[] = pdu.getChildren();
+ for (PDU p : pdus) {
+ write(out, p);
+ }
+ }
+
+ case UTCTIME :
+ case GENERALIZED_TIME :
+ Date date = pdu.getDate();
+ String ss = df.format(date);
+ byte d[] = ss.getBytes("ASCII");
+ out.write(d);
+ break;
+
+ }
+ }
+
+ private void putOid(OutputStream out, int i) throws IOException {
+ if (i > 127) {
+ putOid(out, i >> 7);
+ out.write(0x80 + (i & 0x7F));
+ } else
+ out.write(i & 0x7F);
+ }
}
diff --git a/bundleplugin/src/main/java/aQute/libg/asn1/PDU.java b/bundleplugin/src/main/java/aQute/libg/asn1/PDU.java
index 033928c..2fb29fb 100644
--- a/bundleplugin/src/main/java/aQute/libg/asn1/PDU.java
+++ b/bundleplugin/src/main/java/aQute/libg/asn1/PDU.java
@@ -3,112 +3,109 @@
import java.util.*;
public class PDU implements Types, Iterable<PDU> {
- final int identifier;
- final Object payload;
- byte data[] = new byte[100];
+ final int identifier;
+ final Object payload;
+ byte data[] = new byte[100];
+ public PDU(int id, Object payload) {
+ identifier = id;
+ this.payload = payload;
+ }
- public PDU(int id, Object payload) {
- identifier = id;
- this.payload = payload;
- }
+ public PDU(Date payload) {
+ identifier = UTCTIME;
+ this.payload = payload;
+ }
- public PDU(Date payload) {
- identifier = UTCTIME;
- this.payload = payload;
- }
+ public PDU(int n) {
+ this(UNIVERSAL + INTEGER, n);
+ }
- public PDU(int n) {
- this(UNIVERSAL+INTEGER, n);
- }
+ public PDU(boolean value) {
+ this(UNIVERSAL + BOOLEAN, value);
+ }
- public PDU(boolean value) {
- this(UNIVERSAL+BOOLEAN, value);
- }
+ public PDU(String s) throws Exception {
+ this(UNIVERSAL + IA5STRING, s);
+ }
- public PDU(String s) throws Exception {
- this(UNIVERSAL+IA5STRING, s);
- }
-
- public PDU(byte[] data) {
- this(UNIVERSAL+OCTET_STRING, data);
- }
-
- public PDU(BitSet bits) {
- this(UNIVERSAL+BIT_STRING, bits);
- }
+ public PDU(byte[] data) {
+ this(UNIVERSAL + OCTET_STRING, data);
+ }
- public PDU(int top, int l1, int... remainder) {
- identifier = UNIVERSAL+OBJECT_IDENTIFIER;
- int[] ids = new int[remainder.length + 2];
- ids[0] = top;
- ids[1] = l1;
- System.arraycopy(remainder, 0, ids, 2, remainder.length);
- payload = ids;
- }
+ public PDU(BitSet bits) {
+ this(UNIVERSAL + BIT_STRING, bits);
+ }
- public PDU(int tag, PDU... set) {
- this(tag,(Object)set);
- }
+ public PDU(int top, int l1, int... remainder) {
+ identifier = UNIVERSAL + OBJECT_IDENTIFIER;
+ int[] ids = new int[remainder.length + 2];
+ ids[0] = top;
+ ids[1] = l1;
+ System.arraycopy(remainder, 0, ids, 2, remainder.length);
+ payload = ids;
+ }
- public PDU(PDU... set) {
- this(SEQUENCE+CONSTRUCTED,set);
- }
+ public PDU(int tag, PDU... set) {
+ this(tag, (Object) set);
+ }
+ public PDU(PDU... set) {
+ this(SEQUENCE + CONSTRUCTED, set);
+ }
- public int getTag() {
- return identifier & TAGMASK;
- }
+ public int getTag() {
+ return identifier & TAGMASK;
+ }
- int getClss() {
- return identifier & CLASSMASK;
- }
+ int getClss() {
+ return identifier & CLASSMASK;
+ }
- public boolean isConstructed() {
- return (identifier & CONSTRUCTED) != 0;
- }
+ public boolean isConstructed() {
+ return (identifier & CONSTRUCTED) != 0;
+ }
- public String getString() {
- return (String) payload;
- }
+ public String getString() {
+ return (String) payload;
+ }
- public Iterator<PDU> iterator() {
- return Arrays.asList((PDU[]) payload).iterator();
- }
+ public Iterator<PDU> iterator() {
+ return Arrays.asList((PDU[]) payload).iterator();
+ }
-
- public int[] getOID() {
- assert getTag() == OBJECT_IDENTIFIER;
- return (int[]) payload;
- }
+ public int[] getOID() {
+ assert getTag() == OBJECT_IDENTIFIER;
+ return (int[]) payload;
+ }
- public Boolean getBoolean() {
- assert getTag() == BOOLEAN;
- return (Boolean) payload;
- }
+ public Boolean getBoolean() {
+ assert getTag() == BOOLEAN;
+ return (Boolean) payload;
+ }
- public BitSet getBits() {
- assert getTag() == BIT_STRING;
- return (BitSet) payload;
- }
+ public BitSet getBits() {
+ assert getTag() == BIT_STRING;
+ return (BitSet) payload;
+ }
- public int getInt() {
- assert getTag() == INTEGER || getTag() == ENUMERATED;
- return (Integer) payload;
- }
+ public int getInt() {
+ assert getTag() == INTEGER || getTag() == ENUMERATED;
+ return (Integer) payload;
+ }
- public byte[] getBytes() {
- return (byte[]) payload;
- }
+ public byte[] getBytes() {
+ return (byte[]) payload;
+ }
- public PDU[] getChildren() {
- assert isConstructed();
- return (PDU[]) payload;
- }
+ public PDU[] getChildren() {
+ assert isConstructed();
+ return (PDU[]) payload;
+ }
- public Date getDate() {
- assert getTag() == UTCTIME || getTag() == GENERALIZED_TIME;
- return (Date) payload;
- }
+ public Date getDate() {
+ assert getTag() == UTCTIME || getTag() == GENERALIZED_TIME;
+ return (Date) payload;
+ }
}
diff --git a/bundleplugin/src/main/java/aQute/libg/asn1/Types.java b/bundleplugin/src/main/java/aQute/libg/asn1/Types.java
index 630ed1c..8f189ed 100644
--- a/bundleplugin/src/main/java/aQute/libg/asn1/Types.java
+++ b/bundleplugin/src/main/java/aQute/libg/asn1/Types.java
@@ -1,65 +1,66 @@
package aQute.libg.asn1;
public interface Types {
- int UNIVERSAL = 0x00000000;
- int APPLICATION = 0x40000000;
- int CONTEXT = 0x80000000;
- int PRIVATE = 0xC0000000;
- int CLASSMASK = 0xC0000000;
- int CONSTRUCTED = 0x20000000;
- int TAGMASK = 0x1FFFFFFF;
+ int UNIVERSAL = 0x00000000;
+ int APPLICATION = 0x40000000;
+ int CONTEXT = 0x80000000;
+ int PRIVATE = 0xC0000000;
+ int CLASSMASK = 0xC0000000;
+ int CONSTRUCTED = 0x20000000;
+ int TAGMASK = 0x1FFFFFFF;
- String [] CLASSES = {"U", "A", "C", "P"};
-
- // Payload Primitve
- int EOC = 0; // null
- // x
- int BOOLEAN = 1; // Boolean
- // x
- int INTEGER = 2; // Long
- // x
- int BIT_STRING = 3; // byte
- // [] -
- int OCTET_STRING = 4; // byte
- // [] -
- int NULL = 5; // null
- // x
- int OBJECT_IDENTIFIER = 6; // int[]
- // x
- int OBJECT_DESCRIPTOR = 7; //
- int EXTERNAL = 8; //
- int REAL = 9; // double
- // x
- int ENUMERATED = 10; //
- int EMBEDDED_PDV = 11; //
- int UTF8_STRING = 12; // String
- int RELATIVE_OID = 13; //
- int SEQUENCE = 16; //
- int SET = 17;
- int NUMERIC_STRING = 18; // String
- int PRINTABLE_STRING = 19; // String
- int T61_STRING = 20; // String
- int VIDEOTEX_STRING = 21; // String
- int IA5STRING = 22; // String
- int UTCTIME = 23; // Date
- int GENERALIZED_TIME = 24; // Date
- int GRAPHIC_STRING = 25; // String
- int VISIBLE_STRING = 26; // String
- int GENERAL_STRING = 27; // String
- int UNIVERSAL_STRING = 28; // String
- int CHARACTER_STRING = 29; // String
- int BMP_STRING = 30; // byte[]
+ String[] CLASSES = {
+ "U", "A", "C", "P"
+ };
- String[] TAGS = { "EOC ",
- "BOOLEAN ", "INTEGER ", "BIT_STRING ",
- "OCTET_STRING ", "NULL ", "OBJECT_IDENTIFIER ",
- "OBJECT_DESCRIPTOR ", "EXTERNAL ", "REAL ",
- "ENUMERATED ", "EMBEDDED_PDV ", "UTF8_STRING ",
- "RELATIVE_OID ", "?(14) ", "?(15) ",
- "SEQUENCE ", "SET ", "NUMERIC_STRING ",
- "PRINTABLE_STRING ", "T61_STRING ", "VIDEOTEX_STRING ",
- "IA5STRING ", "UTCTIME ", "GENERALIZED_TIME ",
- "GRAPHIC_STRING ", "VISIBLE_STRING ", "GENERAL_STRING ",
- "UNIVERSAL_STRING ", "CHARACTER_STRING ", "BMP_STRING ", };
+ // Payload Primitve
+ int EOC = 0; // null
+ // x
+ int BOOLEAN = 1; // Boolean
+ // x
+ int INTEGER = 2; // Long
+ // x
+ int BIT_STRING = 3; // byte
+ // [] -
+ int OCTET_STRING = 4; // byte
+ // [] -
+ int NULL = 5; // null
+ // x
+ int OBJECT_IDENTIFIER = 6; // int[]
+ // x
+ int OBJECT_DESCRIPTOR = 7; //
+ int EXTERNAL = 8; //
+ int REAL = 9; // double
+ // x
+ int ENUMERATED = 10; //
+ int EMBEDDED_PDV = 11; //
+ int UTF8_STRING = 12; // String
+ int RELATIVE_OID = 13; //
+ int SEQUENCE = 16; //
+ int SET = 17;
+ int NUMERIC_STRING = 18; // String
+ int PRINTABLE_STRING = 19; // String
+ int T61_STRING = 20; // String
+ int VIDEOTEX_STRING = 21; // String
+ int IA5STRING = 22; // String
+ int UTCTIME = 23; // Date
+ int GENERALIZED_TIME = 24; // Date
+ int GRAPHIC_STRING = 25; // String
+ int VISIBLE_STRING = 26; // String
+ int GENERAL_STRING = 27; // String
+ int UNIVERSAL_STRING = 28; // String
+ int CHARACTER_STRING = 29; // String
+ int BMP_STRING = 30; // byte[]
+
+ String[] TAGS = {
+ "EOC ", "BOOLEAN ", "INTEGER ", "BIT_STRING ",
+ "OCTET_STRING ", "NULL ", "OBJECT_IDENTIFIER ", "OBJECT_DESCRIPTOR ",
+ "EXTERNAL ", "REAL ", "ENUMERATED ", "EMBEDDED_PDV ",
+ "UTF8_STRING ", "RELATIVE_OID ", "?(14) ", "?(15) ",
+ "SEQUENCE ", "SET ", "NUMERIC_STRING ", "PRINTABLE_STRING ",
+ "T61_STRING ", "VIDEOTEX_STRING ", "IA5STRING ", "UTCTIME ",
+ "GENERALIZED_TIME ", "GRAPHIC_STRING ", "VISIBLE_STRING ", "GENERAL_STRING ",
+ "UNIVERSAL_STRING ", "CHARACTER_STRING ", "BMP_STRING ",
+ };
}
diff --git a/bundleplugin/src/main/java/aQute/libg/cafs/CAFS.java b/bundleplugin/src/main/java/aQute/libg/cafs/CAFS.java
index 0bb8d7b..38e67be 100644
--- a/bundleplugin/src/main/java/aQute/libg/cafs/CAFS.java
+++ b/bundleplugin/src/main/java/aQute/libg/cafs/CAFS.java
@@ -17,7 +17,6 @@
* in the universe has a unique SHA-1. Hard to believe but people smarter than
* me have come to that conclusion. This class maintains a compressed store of
* SHA-1 identified files. So if you have the SHA-1, you can get the contents.
- *
* This makes it easy to store a SHA-1 instead of the whole file or maintain a
* naming scheme. An added advantage is that it is always easy to verify you get
* the right stuff. The SHA-1 Content Addressable File Store is the core
@@ -34,9 +33,9 @@
+ 4 // flags
+ 4 // compressed length
+ 4 // uncompressed length
- + KEYLENGTH // key
+ + KEYLENGTH // key
+ 2 // header checksum
- ;
+ ;
final File home;
Index index;
@@ -69,8 +68,7 @@
store.writeInt(0);
channel.force(true);
} else
- throw new IllegalArgumentException("Invalid store file, length is too short "
- + store);
+ throw new IllegalArgumentException("Invalid store file, length is too short " + store);
System.err.println(store.length());
}
store.seek(0);
@@ -101,7 +99,7 @@
synchronized (store) {
// First check if it already exists
SHA1 sha1 = new SHA1(md.digest());
-
+
long search = index.search(sha1.digest());
if (search > 0)
return sha1;
@@ -136,7 +134,8 @@
update(sha1.digest(), compressed, totalLength);
index.insert(sha1.digest(), insertPoint);
return sha1;
- } finally {
+ }
+ finally {
if (lock != null)
lock.release();
}
@@ -163,20 +162,20 @@
if (!verifySignature(store, CAFE))
throw new IllegalArgumentException("No signature");
- int flags =store.readInt();
+ int flags = store.readInt();
int compressedLength = store.readInt();
int uncompressedLength = store.readInt();
readSha1 = new byte[KEYLENGTH];
store.read(readSha1);
SHA1 rsha1 = new SHA1(readSha1);
-
+
if (!sha1.equals(rsha1))
throw new IOException("SHA1 read and asked mismatch: " + sha1 + " " + rsha1);
short crc = store.readShort(); // Read CRC
- if ( crc != checksum(flags,compressedLength, uncompressedLength, readSha1))
+ if (crc != checksum(flags, compressedLength, uncompressedLength, readSha1))
throw new IllegalArgumentException("Invalid header checksum: " + sha1);
-
+
buffer = new byte[compressedLength];
store.readFully(buffer);
return getSha1Stream(sha1, buffer, uncompressedLength);
@@ -192,8 +191,7 @@
synchronized (store) {
length = store.length();
if (length < 0x100)
- throw new IllegalArgumentException(
- "Store file is too small, need to be at least 256 bytes: " + store);
+ throw new IllegalArgumentException("Store file is too small, need to be at least 256 bytes: " + store);
}
RandomAccessFile in = new RandomAccessFile(new File(home, STOREFILE), "r");
@@ -219,7 +217,8 @@
ixf.renameTo(indexFile);
this.index = new Index(indexFile, KEYLENGTH);
}
- } finally {
+ }
+ finally {
in.close();
}
}
@@ -228,7 +227,8 @@
synchronized (store) {
try {
store.close();
- } finally {
+ }
+ finally {
index.close();
}
}
@@ -246,7 +246,7 @@
byte[] key = new byte[KEYLENGTH];
in.readFully(key);
SHA1 sha1 = new SHA1(key);
-
+
byte[] buffer = new byte[compressedSize];
in.readFully(buffer);
@@ -262,20 +262,20 @@
return Arrays.equals(read, org);
}
- private InputStream getSha1Stream(final SHA1 sha1, byte[] buffer, final int total)
- throws NoSuchAlgorithmException {
+ private InputStream getSha1Stream(final SHA1 sha1, byte[] buffer, final int total) throws NoSuchAlgorithmException {
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
InflaterInputStream iin = new InflaterInputStream(in) {
- int count = 0;
- final MessageDigest digestx = MessageDigest.getInstance(ALGORITHM);
- final AtomicBoolean calculated = new AtomicBoolean();
-
- @Override public int read(byte[] data, int offset, int length) throws IOException {
+ int count = 0;
+ final MessageDigest digestx = MessageDigest.getInstance(ALGORITHM);
+ final AtomicBoolean calculated = new AtomicBoolean();
+
+ @Override
+ public int read(byte[] data, int offset, int length) throws IOException {
int size = super.read(data, offset, length);
if (size <= 0)
eof();
else {
- count+=size;
+ count += size;
this.digestx.update(data, offset, size);
}
return size;
@@ -293,16 +293,17 @@
}
void eof() throws IOException {
- if ( calculated.getAndSet(true))
+ if (calculated.getAndSet(true))
return;
-
- if ( count != total )
- throw new IOException("Counts do not match. Expected to read: " + total + " Actually read: " + count);
-
+
+ if (count != total)
+ throw new IOException("Counts do not match. Expected to read: " + total + " Actually read: "
+ + count);
+
SHA1 calculatedSha1 = new SHA1(digestx.digest());
if (!sha1.equals(calculatedSha1))
- throw ( new IOException("SHA1 caclulated and asked mismatch, asked: "
- + sha1 + ", \nfound: " +calculatedSha1));
+ throw (new IOException("SHA1 caclulated and asked mismatch, asked: " + sha1 + ", \nfound: "
+ + calculatedSha1));
}
public void close() throws IOException {
@@ -327,87 +328,86 @@
* The exception
*/
private void update(byte[] sha1, byte[] compressed, int totalLength) throws IOException {
- //System.err.println("pos: " + store.getFilePointer());
+ // System.err.println("pos: " + store.getFilePointer());
store.write(CAFE); // 00-03 Signature
store.writeInt(0); // 04-07 Flags for the future
store.writeInt(compressed.length); // 08-11 Length deflated data
store.writeInt(totalLength); // 12-15 Length
store.write(sha1); // 16-35
- store.writeShort( checksum(0,compressed.length, totalLength, sha1));
+ store.writeShort(checksum(0, compressed.length, totalLength, sha1));
store.write(compressed);
channel.force(false);
}
-
-
private short checksum(int flags, int compressedLength, int totalLength, byte[] sha1) {
CRC32 crc = new CRC32();
crc.update(flags);
- crc.update(flags>>8);
- crc.update(flags>>16);
- crc.update(flags>>24);
+ crc.update(flags >> 8);
+ crc.update(flags >> 16);
+ crc.update(flags >> 24);
crc.update(compressedLength);
- crc.update(compressedLength>>8);
- crc.update(compressedLength>>16);
- crc.update(compressedLength>>24);
+ crc.update(compressedLength >> 8);
+ crc.update(compressedLength >> 16);
+ crc.update(compressedLength >> 24);
crc.update(totalLength);
- crc.update(totalLength>>8);
- crc.update(totalLength>>16);
- crc.update(totalLength>>24);
+ crc.update(totalLength >> 8);
+ crc.update(totalLength >> 16);
+ crc.update(totalLength >> 24);
crc.update(sha1);
return (short) crc.getValue();
}
public Iterator<SHA1> iterator() {
-
+
return new Iterator<SHA1>() {
- long position = 0x100;
-
+ long position = 0x100;
+
public boolean hasNext() {
- synchronized(store) {
+ synchronized (store) {
try {
return position < store.length();
- } catch (IOException e) {
+ }
+ catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public SHA1 next() {
- synchronized(store) {
+ synchronized (store) {
try {
store.seek(position);
- byte [] signature = new byte[4];
+ byte[] signature = new byte[4];
store.readFully(signature);
- if ( !Arrays.equals(CAFE, signature))
+ if (!Arrays.equals(CAFE, signature))
throw new IllegalArgumentException("No signature");
int flags = store.readInt();
int compressedLength = store.readInt();
int totalLength = store.readInt();
- byte []sha1 = new byte[KEYLENGTH];
+ byte[] sha1 = new byte[KEYLENGTH];
store.readFully(sha1);
short crc = store.readShort();
- if ( crc != checksum(flags,compressedLength, totalLength, sha1))
+ if (crc != checksum(flags, compressedLength, totalLength, sha1))
throw new IllegalArgumentException("Header checksum fails");
-
+
position += HEADERLENGTH + compressedLength;
return new SHA1(sha1);
- } catch (IOException e) {
+ }
+ catch (IOException e) {
throw new RuntimeException(e);
- }
+ }
}
}
public void remove() {
throw new UnsupportedOperationException("Remvoe not supported, CAFS is write once");
- }
+ }
};
}
-
public boolean isEmpty() throws IOException {
- synchronized(store) {
+ synchronized (store) {
return store.getFilePointer() <= 256;
}
}
diff --git a/bundleplugin/src/main/java/aQute/libg/classdump/ClassDumper.java b/bundleplugin/src/main/java/aQute/libg/classdump/ClassDumper.java
index e45cd39..adf9824 100755
--- a/bundleplugin/src/main/java/aQute/libg/classdump/ClassDumper.java
+++ b/bundleplugin/src/main/java/aQute/libg/classdump/ClassDumper.java
@@ -6,693 +6,645 @@
import java.lang.reflect.*;
public class ClassDumper {
- /**
- * <pre>
- * ACC_PUBLIC 0x0001 Declared public; may be accessed from outside its
- * package.
- * ACC_FINAL 0x0010 Declared final; no subclasses allowed.
- * ACC_SUPER 0x0020 Treat superclass methods specially when invoked by the
- * invokespecial instruction.
- * ACC_INTERFACE 0x0200 Is an interface, not a
- * class.
- * ACC_ABSTRACT 0x0400 Declared abstract; may not be instantiated.
- * </pre>
- *
- * @param mod
- */
- final static int ACC_PUBLIC = 0x0001; // Declared public; may be accessed
- // from outside its package.
- final static int ACC_FINAL = 0x0010; // Declared final; no subclasses
- // allowed.
- final static int ACC_SUPER = 0x0020; // Treat superclass methods
- // specially when invoked by the
- // invokespecial instruction.
- final static int ACC_INTERFACE = 0x0200; // Is an interface, not a classs
- final static int ACC_ABSTRACT = 0x0400; // Declared abstract; may not be
- // instantiated.
-
- final static class Assoc {
- Assoc(byte tag, int a, int b) {
- this.tag = tag;
- this.a = a;
- this.b = b;
- }
+ /**
+ * <pre>
+ * ACC_PUBLIC 0x0001 Declared public; may be accessed from outside its
+ * package.
+ * ACC_FINAL 0x0010 Declared final; no subclasses allowed.
+ * ACC_SUPER 0x0020 Treat superclass methods specially when invoked by the
+ * invokespecial instruction.
+ * ACC_INTERFACE 0x0200 Is an interface, not a
+ * class.
+ * ACC_ABSTRACT 0x0400 Declared abstract; may not be instantiated.
+ * </pre>
+ *
+ * @param mod
+ */
+ final static int ACC_PUBLIC = 0x0001; // Declared public; may be
+ // accessed
+ // from outside its package.
+ final static int ACC_FINAL = 0x0010; // Declared final; no
+ // subclasses
+ // allowed.
+ final static int ACC_SUPER = 0x0020; // Treat superclass methods
+ // specially when invoked by the
+ // invokespecial instruction.
+ final static int ACC_INTERFACE = 0x0200; // Is an interface, not a
+ // classs
+ final static int ACC_ABSTRACT = 0x0400; // Declared abstract; may
+ // not be
+ // instantiated.
- byte tag;
- int a;
- int b;
+ final static class Assoc {
+ Assoc(byte tag, int a, int b) {
+ this.tag = tag;
+ this.a = a;
+ this.b = b;
+ }
- }
+ byte tag;
+ int a;
+ int b;
- final String path;
- final static String NUM_COLUMN = "%-30s %d\n";
- final static String HEX_COLUMN = "%-30s %x\n";
- final static String STR_COLUMN = "%-30s %s\n";
+ }
- PrintStream ps = System.err;
- Object[] pool;
- InputStream in;
+ final String path;
+ final static String NUM_COLUMN = "%-30s %d\n";
+ final static String HEX_COLUMN = "%-30s %x\n";
+ final static String STR_COLUMN = "%-30s %s\n";
- public ClassDumper(String path) throws Exception {
- this(path, new FileInputStream(new File(path)));
- }
+ PrintStream ps = System.err;
+ Object[] pool;
+ InputStream in;
- public ClassDumper(String path, InputStream in) throws IOException {
- this.path = path;
- this.in = in;
- }
+ public ClassDumper(String path) throws Exception {
+ this(path, new FileInputStream(new File(path)));
+ }
- public void dump(PrintStream ps) throws Exception {
- if (ps != null)
- this.ps = ps;
- DataInputStream din = new DataInputStream(in);
- parseClassFile(din);
- din.close();
- }
+ public ClassDumper(String path, InputStream in) throws IOException {
+ this.path = path;
+ this.in = in;
+ }
- void parseClassFile(DataInputStream in) throws IOException {
- int magic = in.readInt();
- if (magic != 0xCAFEBABE)
- throw new IOException("Not a valid class file (no CAFEBABE header)");
+ public void dump(PrintStream ps) throws Exception {
+ if (ps != null)
+ this.ps = ps;
+ DataInputStream din = new DataInputStream(in);
+ parseClassFile(din);
+ din.close();
+ }
- ps.printf(HEX_COLUMN, "magic", magic);
- int minor = in.readUnsignedShort(); // minor version
- int major = in.readUnsignedShort(); // major version
- ps.printf(STR_COLUMN, "version", "" + major + "." + minor);
- int pool_size = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, "pool size", pool_size);
- pool = new Object[pool_size];
+ void parseClassFile(DataInputStream in) throws IOException {
+ int magic = in.readInt();
+ if (magic != 0xCAFEBABE)
+ throw new IOException("Not a valid class file (no CAFEBABE header)");
- process: for (int poolIndex = 1; poolIndex < pool_size; poolIndex++) {
- byte tag = in.readByte();
+ ps.printf(HEX_COLUMN, "magic", magic);
+ int minor = in.readUnsignedShort(); // minor version
+ int major = in.readUnsignedShort(); // major version
+ ps.printf(STR_COLUMN, "version", "" + major + "." + minor);
+ int pool_size = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, "pool size", pool_size);
+ pool = new Object[pool_size];
- switch (tag) {
- case 0:
- ps.printf("%30d tag (0)\n", poolIndex);
- break process;
+ process: for (int poolIndex = 1; poolIndex < pool_size; poolIndex++) {
+ byte tag = in.readByte();
- case 1:
- String name = in.readUTF();
- pool[poolIndex] = name;
- ps.printf("%30d tag(1) utf8 '%s'\n", poolIndex, name);
- break;
+ switch (tag) {
+ case 0 :
+ ps.printf("%30d tag (0)\n", poolIndex);
+ break process;
- case 2:
- throw new IOException("Invalid tag " + tag);
+ case 1 :
+ String name = in.readUTF();
+ pool[poolIndex] = name;
+ ps.printf("%30d tag(1) utf8 '%s'\n", poolIndex, name);
+ break;
- case 3:
- int i = in.readInt();
- pool[poolIndex] = Integer.valueOf(i);
- ps.printf("%30d tag(3) int %s\n", poolIndex, i);
- break;
+ case 2 :
+ throw new IOException("Invalid tag " + tag);
- case 4:
- float f = in.readFloat();
- pool[poolIndex] = new Float(f);
- ps.printf("%30d tag(4) float %s\n", poolIndex, f);
- break;
+ case 3 :
+ int i = in.readInt();
+ pool[poolIndex] = Integer.valueOf(i);
+ ps.printf("%30d tag(3) int %s\n", poolIndex, i);
+ break;
- // For some insane optimization reason are
- // the long and the double two entries in the
- // constant pool. See 4.4.5
- case 5:
- long l = in.readLong();
- pool[poolIndex] = Long.valueOf(l);
- ps.printf("%30d tag(5) long %s\n", poolIndex, l);
- poolIndex++;
- break;
+ case 4 :
+ float f = in.readFloat();
+ pool[poolIndex] = new Float(f);
+ ps.printf("%30d tag(4) float %s\n", poolIndex, f);
+ break;
- case 6:
- double d = in.readDouble();
- pool[poolIndex] = new Double(d);
- ps.printf("%30d tag(6) double %s\n", poolIndex, d);
- poolIndex++;
- break;
+ // For some insane optimization reason are
+ // the long and the double two entries in the
+ // constant pool. See 4.4.5
+ case 5 :
+ long l = in.readLong();
+ pool[poolIndex] = Long.valueOf(l);
+ ps.printf("%30d tag(5) long %s\n", poolIndex, l);
+ poolIndex++;
+ break;
- case 7:
- int class_index = in.readUnsignedShort();
- pool[poolIndex] = Integer.valueOf(class_index);
- ps.printf("%30d tag(7) constant classs %d\n", poolIndex,
- class_index);
- break;
+ case 6 :
+ double d = in.readDouble();
+ pool[poolIndex] = new Double(d);
+ ps.printf("%30d tag(6) double %s\n", poolIndex, d);
+ poolIndex++;
+ break;
- case 8:
- int string_index = in.readUnsignedShort();
- pool[poolIndex] = Integer.valueOf(string_index);
- ps.printf("%30d tag(8) constant string %d\n", poolIndex,
- string_index);
- break;
+ case 7 :
+ int class_index = in.readUnsignedShort();
+ pool[poolIndex] = Integer.valueOf(class_index);
+ ps.printf("%30d tag(7) constant classs %d\n", poolIndex, class_index);
+ break;
- case 9: // Field ref
- class_index = in.readUnsignedShort();
- int name_and_type_index = in.readUnsignedShort();
- pool[poolIndex] = new Assoc((byte) 9, class_index,
- name_and_type_index);
- ps.printf("%30d tag(9) field ref %d/%d\n", poolIndex,
- class_index, name_and_type_index);
- break;
+ case 8 :
+ int string_index = in.readUnsignedShort();
+ pool[poolIndex] = Integer.valueOf(string_index);
+ ps.printf("%30d tag(8) constant string %d\n", poolIndex, string_index);
+ break;
- case 10: // Method ref
- class_index = in.readUnsignedShort();
- name_and_type_index = in.readUnsignedShort();
- pool[poolIndex] = new Assoc((byte) 10, class_index,
- name_and_type_index);
- ps.printf("%30d tag(10) method ref %d/%d\n", poolIndex,
- class_index, name_and_type_index);
- break;
+ case 9 : // Field ref
+ class_index = in.readUnsignedShort();
+ int name_and_type_index = in.readUnsignedShort();
+ pool[poolIndex] = new Assoc((byte) 9, class_index, name_and_type_index);
+ ps.printf("%30d tag(9) field ref %d/%d\n", poolIndex, class_index, name_and_type_index);
+ break;
- case 11: // Interface and Method ref
- class_index = in.readUnsignedShort();
- name_and_type_index = in.readUnsignedShort();
- pool[poolIndex] = new Assoc((byte) 11, class_index,
- name_and_type_index);
- ps.printf("%30d tag(11) interface and method ref %d/%d\n",
- poolIndex, class_index, name_and_type_index);
- break;
+ case 10 : // Method ref
+ class_index = in.readUnsignedShort();
+ name_and_type_index = in.readUnsignedShort();
+ pool[poolIndex] = new Assoc((byte) 10, class_index, name_and_type_index);
+ ps.printf("%30d tag(10) method ref %d/%d\n", poolIndex, class_index, name_and_type_index);
+ break;
- // Name and Type
- case 12:
- int name_index = in.readUnsignedShort();
- int descriptor_index = in.readUnsignedShort();
- pool[poolIndex] = new Assoc(tag, name_index, descriptor_index);
- ps.printf("%30d tag(12) name and type %d/%d\n", poolIndex,
- name_index, descriptor_index);
- break;
+ case 11 : // Interface and Method ref
+ class_index = in.readUnsignedShort();
+ name_and_type_index = in.readUnsignedShort();
+ pool[poolIndex] = new Assoc((byte) 11, class_index, name_and_type_index);
+ ps.printf("%30d tag(11) interface and method ref %d/%d\n", poolIndex, class_index,
+ name_and_type_index);
+ break;
- default:
- throw new IllegalArgumentException("Unknown tag: " + tag);
- }
- }
+ // Name and Type
+ case 12 :
+ int name_index = in.readUnsignedShort();
+ int descriptor_index = in.readUnsignedShort();
+ pool[poolIndex] = new Assoc(tag, name_index, descriptor_index);
+ ps.printf("%30d tag(12) name and type %d/%d\n", poolIndex, name_index, descriptor_index);
+ break;
- int access = in.readUnsignedShort(); // access
- printAccess(access);
- int this_class = in.readUnsignedShort();
- int super_class = in.readUnsignedShort();
- ps.printf("%-30s %x %s(#%d)\n", "this_class", access, pool[this_class],
- this_class);
- ps.printf("%-30s %s(#%d)\n", "super_class", pool[super_class],
- super_class);
+ default :
+ throw new IllegalArgumentException("Unknown tag: " + tag);
+ }
+ }
- int interfaces_count = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, "interface count", interfaces_count);
- for (int i = 0; i < interfaces_count; i++) {
- int interface_index = in.readUnsignedShort();
- ps.printf("%-30s interface %s(#%d)", "interface count",
- pool[interface_index], interfaces_count);
- }
+ int access = in.readUnsignedShort(); // access
+ printAccess(access);
+ int this_class = in.readUnsignedShort();
+ int super_class = in.readUnsignedShort();
+ ps.printf("%-30s %x %s(#%d)\n", "this_class", access, pool[this_class], this_class);
+ ps.printf("%-30s %s(#%d)\n", "super_class", pool[super_class], super_class);
- int field_count = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, "field count", field_count);
- for (int i = 0; i < field_count; i++) {
- access = in.readUnsignedShort(); // access
- printAccess(access);
- int name_index = in.readUnsignedShort();
- int descriptor_index = in.readUnsignedShort();
- ps.printf("%-30s %x %s(#%d) %s(#%d)\n", "field def", access,
- pool[name_index], name_index, pool[descriptor_index],
- descriptor_index);
- doAttributes(in, " ");
- }
+ int interfaces_count = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, "interface count", interfaces_count);
+ for (int i = 0; i < interfaces_count; i++) {
+ int interface_index = in.readUnsignedShort();
+ ps.printf("%-30s interface %s(#%d)", "interface count", pool[interface_index], interfaces_count);
+ }
- int method_count = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, "method count", method_count);
- for (int i = 0; i < method_count; i++) {
- int access_flags = in.readUnsignedShort();
- printAccess(access_flags);
- int name_index = in.readUnsignedShort();
- int descriptor_index = in.readUnsignedShort();
- ps.printf("%-30s %x %s(#%d) %s(#%d)\n", "method def", access_flags,
- pool[name_index], name_index, pool[descriptor_index],
- descriptor_index);
- doAttributes(in, " ");
- }
+ int field_count = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, "field count", field_count);
+ for (int i = 0; i < field_count; i++) {
+ access = in.readUnsignedShort(); // access
+ printAccess(access);
+ int name_index = in.readUnsignedShort();
+ int descriptor_index = in.readUnsignedShort();
+ ps.printf("%-30s %x %s(#%d) %s(#%d)\n", "field def", access, pool[name_index], name_index,
+ pool[descriptor_index], descriptor_index);
+ doAttributes(in, " ");
+ }
- doAttributes(in, "");
- if (in.read() >= 0)
- ps.printf("Extra bytes follow ...");
- }
+ int method_count = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, "method count", method_count);
+ for (int i = 0; i < method_count; i++) {
+ int access_flags = in.readUnsignedShort();
+ printAccess(access_flags);
+ int name_index = in.readUnsignedShort();
+ int descriptor_index = in.readUnsignedShort();
+ ps.printf("%-30s %x %s(#%d) %s(#%d)\n", "method def", access_flags, pool[name_index], name_index,
+ pool[descriptor_index], descriptor_index);
+ doAttributes(in, " ");
+ }
- /**
- * Called for each attribute in the class, field, or method.
- *
- * @param in
- * The stream
- * @throws IOException
- */
- private void doAttributes(DataInputStream in, String indent)
- throws IOException {
- int attribute_count = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, indent + "attribute count", attribute_count);
- for (int j = 0; j < attribute_count; j++) {
- doAttribute(in, indent + j + ": ");
- }
- }
+ doAttributes(in, "");
+ if (in.read() >= 0)
+ ps.printf("Extra bytes follow ...");
+ }
- /**
- * Process a single attribute, if not recognized, skip it.
- *
- * @param in
- * the data stream
- * @throws IOException
- */
- private void doAttribute(DataInputStream in, String indent)
- throws IOException {
- int attribute_name_index = in.readUnsignedShort();
- long attribute_length = in.readInt();
- attribute_length &= 0xFFFF;
- String attributeName = (String) pool[attribute_name_index];
- ps.printf("%-30s %s(#%d)\n", indent + "attribute", attributeName,
- attribute_name_index);
- if ("RuntimeVisibleAnnotations".equals(attributeName))
- doAnnotations(in, indent);
- else if ("SourceFile".equals(attributeName))
- doSourceFile(in, indent);
- else if ("Code".equals(attributeName))
- doCode(in, indent);
- else if ("LineNumberTable".equals(attributeName))
- doLineNumberTable(in, indent);
- else if ("LocalVariableTable".equals(attributeName))
- doLocalVariableTable(in, indent);
- else if ("InnerClasses".equals(attributeName))
- doInnerClasses(in, indent);
- else if ("Exceptions".equals(attributeName))
- doExceptions(in, indent);
- else if ("EnclosingMethod".equals(attributeName))
- doEnclosingMethod(in, indent);
- else if ("Signature".equals(attributeName))
- doSignature(in, indent);
- else if ("Synthetic".equals(attributeName))
- ; // Is empty!
- else if ("Deprecated".equals(attributeName))
- ; // Is Empty
- else {
- ps.printf("%-30s %d\n", indent + "Unknown attribute, skipping",
- attribute_length);
- if (attribute_length > 0x7FFFFFFF) {
- throw new IllegalArgumentException("Attribute > 2Gb");
- }
- byte buffer[] = new byte[(int) attribute_length];
- in.readFully(buffer);
- printHex(buffer);
- }
- }
+ /**
+ * Called for each attribute in the class, field, or method.
+ *
+ * @param in
+ * The stream
+ * @throws IOException
+ */
+ private void doAttributes(DataInputStream in, String indent) throws IOException {
+ int attribute_count = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, indent + "attribute count", attribute_count);
+ for (int j = 0; j < attribute_count; j++) {
+ doAttribute(in, indent + j + ": ");
+ }
+ }
- /**
- * <pre>
- * Signature_attribute {
- * u2 attribute_name_index;
- * u4 attribute_length;
- * u2 signature_index;
- * }
- * </pre>
- *
- * @param in
- * @param indent
- */
- void doSignature(DataInputStream in, String indent) throws IOException {
- int signature_index = in.readUnsignedShort();
- ps.printf("%-30s %s(#%d)\n", indent + "signature",
- pool[signature_index], signature_index);
- }
+ /**
+ * Process a single attribute, if not recognized, skip it.
+ *
+ * @param in
+ * the data stream
+ * @throws IOException
+ */
+ private void doAttribute(DataInputStream in, String indent) throws IOException {
+ int attribute_name_index = in.readUnsignedShort();
+ long attribute_length = in.readInt();
+ attribute_length &= 0xFFFF;
+ String attributeName = (String) pool[attribute_name_index];
+ ps.printf("%-30s %s(#%d)\n", indent + "attribute", attributeName, attribute_name_index);
+ if ("RuntimeVisibleAnnotations".equals(attributeName))
+ doAnnotations(in, indent);
+ else if ("SourceFile".equals(attributeName))
+ doSourceFile(in, indent);
+ else if ("Code".equals(attributeName))
+ doCode(in, indent);
+ else if ("LineNumberTable".equals(attributeName))
+ doLineNumberTable(in, indent);
+ else if ("LocalVariableTable".equals(attributeName))
+ doLocalVariableTable(in, indent);
+ else if ("InnerClasses".equals(attributeName))
+ doInnerClasses(in, indent);
+ else if ("Exceptions".equals(attributeName))
+ doExceptions(in, indent);
+ else if ("EnclosingMethod".equals(attributeName))
+ doEnclosingMethod(in, indent);
+ else if ("Signature".equals(attributeName))
+ doSignature(in, indent);
+ else if ("Synthetic".equals(attributeName))
+ ; // Is empty!
+ else if ("Deprecated".equals(attributeName))
+ ; // Is Empty
+ else {
+ ps.printf("%-30s %d\n", indent + "Unknown attribute, skipping", attribute_length);
+ if (attribute_length > 0x7FFFFFFF) {
+ throw new IllegalArgumentException("Attribute > 2Gb");
+ }
+ byte buffer[] = new byte[(int) attribute_length];
+ in.readFully(buffer);
+ printHex(buffer);
+ }
+ }
- /**
- * <pre>
- * EnclosingMethod_attribute {
- * u2 attribute_name_index;
- * u4 attribute_length;
- * u2 class_index
- * u2 method_index;
- * }
- *
- * </pre>
- */
- void doEnclosingMethod(DataInputStream in, String indent)
- throws IOException {
- int class_index = in.readUnsignedShort();
- int method_index = in.readUnsignedShort();
- ps.printf("%-30s %s(#%d/c) %s\n", //
- indent + "enclosing method", //
- pool[((Integer) pool[class_index]).intValue()], //
- class_index, //
- (method_index == 0 ? "<>" : pool[method_index]));
- }
+ /**
+ * <pre>
+ * Signature_attribute {
+ * u2 attribute_name_index;
+ * u4 attribute_length;
+ * u2 signature_index;
+ * }
+ * </pre>
+ *
+ * @param in
+ * @param indent
+ */
+ void doSignature(DataInputStream in, String indent) throws IOException {
+ int signature_index = in.readUnsignedShort();
+ ps.printf("%-30s %s(#%d)\n", indent + "signature", pool[signature_index], signature_index);
+ }
- /**
- * <pre>
- * Exceptions_attribute {
- * u2 attribute_name_index;
- * u4 attribute_length;
- * u2 number_of_exceptions;
- * u2 exception_index_table[number_of_exceptions];
- * }
- * </pre>
- *
- * @param in
- * @param indent
- */
- private void doExceptions(DataInputStream in, String indent)
- throws IOException {
- int number_of_exceptions = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, indent + "number of exceptions",
- number_of_exceptions);
- StringBuilder sb = new StringBuilder();
- String del = "";
- for (int i = 0; i < number_of_exceptions; i++) {
- int exception_index_table = in.readUnsignedShort();
- sb.append(del);
- sb.append(pool[((Integer) pool[exception_index_table])]);
- sb.append("(#");
- sb.append(exception_index_table);
- sb.append("/c)");
- del = ", ";
- }
- ps.printf("%-30s %d: %s\n", indent + "exceptions",
- number_of_exceptions, sb);
- }
+ /**
+ * <pre>
+ * EnclosingMethod_attribute {
+ * u2 attribute_name_index;
+ * u4 attribute_length;
+ * u2 class_index
+ * u2 method_index;
+ * }
+ *
+ * </pre>
+ */
+ void doEnclosingMethod(DataInputStream in, String indent) throws IOException {
+ int class_index = in.readUnsignedShort();
+ int method_index = in.readUnsignedShort();
+ ps.printf("%-30s %s(#%d/c) %s\n", //
+ indent + "enclosing method", //
+ pool[((Integer) pool[class_index]).intValue()], //
+ class_index, //
+ (method_index == 0 ? "<>" : pool[method_index]));
+ }
- /**
- * <pre>
- * Code_attribute {
- * u2 attribute_name_index;
- * u4 attribute_length;
- * u2 max_stack;
- * u2 max_locals;
- * u4 code_length;
- * u1 code[code_length];
- * u2 exception_table_length;
- * { u2 start_pc;
- * u2 end_pc;
- * u2 handler_pc;
- * u2 catch_type;
- * } exception_table[exception_table_length];
- * u2 attributes_count;
- * attribute_info attributes[attributes_count];
- * }
- * </pre>
- *
- * @param in
- * @param pool
- * @throws IOException
- */
- private void doCode(DataInputStream in, String indent) throws IOException {
- int max_stack = in.readUnsignedShort();
- int max_locals = in.readUnsignedShort();
- int code_length = in.readInt();
- ps.printf(NUM_COLUMN, indent + "max_stack", max_stack);
- ps.printf(NUM_COLUMN, indent + "max_locals", max_locals);
- ps.printf(NUM_COLUMN, indent + "code_length", code_length);
- byte code[] = new byte[code_length];
- in.readFully(code);
- printHex(code);
- int exception_table_length = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, indent + "exception_table_length",
- exception_table_length);
+ /**
+ * <pre>
+ * Exceptions_attribute {
+ * u2 attribute_name_index;
+ * u4 attribute_length;
+ * u2 number_of_exceptions;
+ * u2 exception_index_table[number_of_exceptions];
+ * }
+ * </pre>
+ *
+ * @param in
+ * @param indent
+ */
+ private void doExceptions(DataInputStream in, String indent) throws IOException {
+ int number_of_exceptions = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, indent + "number of exceptions", number_of_exceptions);
+ StringBuilder sb = new StringBuilder();
+ String del = "";
+ for (int i = 0; i < number_of_exceptions; i++) {
+ int exception_index_table = in.readUnsignedShort();
+ sb.append(del);
+ sb.append(pool[((Integer) pool[exception_index_table])]);
+ sb.append("(#");
+ sb.append(exception_index_table);
+ sb.append("/c)");
+ del = ", ";
+ }
+ ps.printf("%-30s %d: %s\n", indent + "exceptions", number_of_exceptions, sb);
+ }
- for (int i = 0; i < exception_table_length; i++) {
- int start_pc = in.readUnsignedShort();
- int end_pc = in.readUnsignedShort();
- int handler_pc = in.readUnsignedShort();
- int catch_type = in.readUnsignedShort();
- ps.printf("%-30s %d/%d/%d/%d\n", indent + "exception_table",
- start_pc, end_pc, handler_pc, catch_type);
- }
- doAttributes(in, indent + " ");
- }
+ /**
+ * <pre>
+ * Code_attribute {
+ * u2 attribute_name_index;
+ * u4 attribute_length;
+ * u2 max_stack;
+ * u2 max_locals;
+ * u4 code_length;
+ * u1 code[code_length];
+ * u2 exception_table_length;
+ * { u2 start_pc;
+ * u2 end_pc;
+ * u2 handler_pc;
+ * u2 catch_type;
+ * } exception_table[exception_table_length];
+ * u2 attributes_count;
+ * attribute_info attributes[attributes_count];
+ * }
+ * </pre>
+ *
+ * @param in
+ * @param pool
+ * @throws IOException
+ */
+ private void doCode(DataInputStream in, String indent) throws IOException {
+ int max_stack = in.readUnsignedShort();
+ int max_locals = in.readUnsignedShort();
+ int code_length = in.readInt();
+ ps.printf(NUM_COLUMN, indent + "max_stack", max_stack);
+ ps.printf(NUM_COLUMN, indent + "max_locals", max_locals);
+ ps.printf(NUM_COLUMN, indent + "code_length", code_length);
+ byte code[] = new byte[code_length];
+ in.readFully(code);
+ printHex(code);
+ int exception_table_length = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, indent + "exception_table_length", exception_table_length);
- /**
- * We must find Class.forName references ...
- *
- * @param code
- */
- protected void printHex(byte[] code) {
- int index = 0;
- while (index < code.length) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 16 && index < code.length; i++) {
- String s = Integer.toHexString((0xFF & code[index++]))
- .toUpperCase();
- if (s.length() == 1)
- sb.append("0");
- sb.append(s);
- sb.append(" ");
- }
- ps.printf(STR_COLUMN, "", sb.toString());
- }
- }
+ for (int i = 0; i < exception_table_length; i++) {
+ int start_pc = in.readUnsignedShort();
+ int end_pc = in.readUnsignedShort();
+ int handler_pc = in.readUnsignedShort();
+ int catch_type = in.readUnsignedShort();
+ ps.printf("%-30s %d/%d/%d/%d\n", indent + "exception_table", start_pc, end_pc, handler_pc, catch_type);
+ }
+ doAttributes(in, indent + " ");
+ }
- private void doSourceFile(DataInputStream in, String indent)
- throws IOException {
- int sourcefile_index = in.readUnsignedShort();
- ps.printf("%-30s %s(#%d)\n", indent + "Source file",
- pool[sourcefile_index], sourcefile_index);
- }
+ /**
+ * We must find Class.forName references ...
+ *
+ * @param code
+ */
+ protected void printHex(byte[] code) {
+ int index = 0;
+ while (index < code.length) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < 16 && index < code.length; i++) {
+ String s = Integer.toHexString((0xFF & code[index++])).toUpperCase();
+ if (s.length() == 1)
+ sb.append("0");
+ sb.append(s);
+ sb.append(" ");
+ }
+ ps.printf(STR_COLUMN, "", sb.toString());
+ }
+ }
- private void doAnnotations(DataInputStream in, String indent)
- throws IOException {
- int num_annotations = in.readUnsignedShort(); // # of annotations
- ps
- .printf(NUM_COLUMN, indent + "Number of annotations",
- num_annotations);
- for (int a = 0; a < num_annotations; a++) {
- doAnnotation(in, indent);
- }
- }
+ private void doSourceFile(DataInputStream in, String indent) throws IOException {
+ int sourcefile_index = in.readUnsignedShort();
+ ps.printf("%-30s %s(#%d)\n", indent + "Source file", pool[sourcefile_index], sourcefile_index);
+ }
- private void doAnnotation(DataInputStream in, String indent)
- throws IOException {
- int type_index = in.readUnsignedShort();
- ps.printf("%-30s %s(#%d)", indent + "type", pool[type_index],
- type_index);
- int num_element_value_pairs = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, indent + "num_element_value_pairs",
- num_element_value_pairs);
- for (int v = 0; v < num_element_value_pairs; v++) {
- int element_name_index = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, indent + "element_name_index",
- element_name_index);
- doElementValue(in, indent);
- }
- }
+ private void doAnnotations(DataInputStream in, String indent) throws IOException {
+ int num_annotations = in.readUnsignedShort(); // # of annotations
+ ps.printf(NUM_COLUMN, indent + "Number of annotations", num_annotations);
+ for (int a = 0; a < num_annotations; a++) {
+ doAnnotation(in, indent);
+ }
+ }
- private void doElementValue(DataInputStream in, String indent)
- throws IOException {
- int tag = in.readUnsignedByte();
- switch (tag) {
- case 'B':
- case 'C':
- case 'D':
- case 'F':
- case 'I':
- case 'J':
- case 'S':
- case 'Z':
- case 's':
- int const_value_index = in.readUnsignedShort();
- ps.printf("%-30s %c %s(#%d)\n", indent + "element value", tag,
- pool[const_value_index], const_value_index);
- break;
+ private void doAnnotation(DataInputStream in, String indent) throws IOException {
+ int type_index = in.readUnsignedShort();
+ ps.printf("%-30s %s(#%d)", indent + "type", pool[type_index], type_index);
+ int num_element_value_pairs = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, indent + "num_element_value_pairs", num_element_value_pairs);
+ for (int v = 0; v < num_element_value_pairs; v++) {
+ int element_name_index = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, indent + "element_name_index", element_name_index);
+ doElementValue(in, indent);
+ }
+ }
- case 'e':
- int type_name_index = in.readUnsignedShort();
- int const_name_index = in.readUnsignedShort();
- ps.printf("%-30s %c %s(#%d) %s(#%d)\n", indent + "type+const", tag,
- pool[type_name_index], type_name_index,
- pool[const_name_index], const_name_index);
- break;
+ private void doElementValue(DataInputStream in, String indent) throws IOException {
+ int tag = in.readUnsignedByte();
+ switch (tag) {
+ case 'B' :
+ case 'C' :
+ case 'D' :
+ case 'F' :
+ case 'I' :
+ case 'J' :
+ case 'S' :
+ case 'Z' :
+ case 's' :
+ int const_value_index = in.readUnsignedShort();
+ ps.printf("%-30s %c %s(#%d)\n", indent + "element value", tag, pool[const_value_index],
+ const_value_index);
+ break;
- case 'c':
- int class_info_index = in.readUnsignedShort();
- ps.printf("%-30s %c %s(#%d)\n", indent + "element value", tag,
- pool[class_info_index], class_info_index);
- break;
+ case 'e' :
+ int type_name_index = in.readUnsignedShort();
+ int const_name_index = in.readUnsignedShort();
+ ps.printf("%-30s %c %s(#%d) %s(#%d)\n", indent + "type+const", tag, pool[type_name_index],
+ type_name_index, pool[const_name_index], const_name_index);
+ break;
- case '@':
- ps.printf("%-30s %c\n", indent + "sub annotation", tag);
- doAnnotation(in, indent);
- break;
+ case 'c' :
+ int class_info_index = in.readUnsignedShort();
+ ps.printf("%-30s %c %s(#%d)\n", indent + "element value", tag, pool[class_info_index], class_info_index);
+ break;
- case '[':
- int num_values = in.readUnsignedShort();
- ps.printf("%-30s %c num_values=%d\n", indent + "sub element value",
- tag, num_values);
- for (int i = 0; i < num_values; i++) {
- doElementValue(in, indent);
- }
- break;
+ case '@' :
+ ps.printf("%-30s %c\n", indent + "sub annotation", tag);
+ doAnnotation(in, indent);
+ break;
- default:
- throw new IllegalArgumentException(
- "Invalid value for Annotation ElementValue tag " + tag);
- }
- }
+ case '[' :
+ int num_values = in.readUnsignedShort();
+ ps.printf("%-30s %c num_values=%d\n", indent + "sub element value", tag, num_values);
+ for (int i = 0; i < num_values; i++) {
+ doElementValue(in, indent);
+ }
+ break;
- /**
- * <pre>
- * LineNumberTable_attribute {
- * u2 attribute_name_index;
- * u4 attribute_length;
- * u2 line_number_table_length;
- * { u2 start_pc;
- * u2 line_number;
- * } line_number_table[line_number_table_length];
- * }
- *
- * </pre>
- */
- void doLineNumberTable(DataInputStream in, String indent)
- throws IOException {
- int line_number_table_length = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, indent + "line number table length",
- line_number_table_length);
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < line_number_table_length; i++) {
- int start_pc = in.readUnsignedShort();
- int line_number = in.readUnsignedShort();
- sb.append(start_pc);
- sb.append("/");
- sb.append(line_number);
- sb.append(" ");
- }
- ps.printf("%-30s %d: %s\n", indent + "line number table",
- line_number_table_length, sb);
- }
+ default :
+ throw new IllegalArgumentException("Invalid value for Annotation ElementValue tag " + tag);
+ }
+ }
- /**
- *
- * <pre>
- * LocalVariableTable_attribute {
- * u2 attribute_name_index;
- * u4 attribute_length;
- * u2 local_variable_table_length;
- * { u2 start_pc;
- * u2 length;
- * u2 name_index;
- * u2 descriptor_index;
- * u2 index;
- * } local_variable_table[local_variable_table_length];
- * }
- * </pre>
- */
+ /**
+ * <pre>
+ * LineNumberTable_attribute {
+ * u2 attribute_name_index;
+ * u4 attribute_length;
+ * u2 line_number_table_length;
+ * { u2 start_pc;
+ * u2 line_number;
+ * } line_number_table[line_number_table_length];
+ * }
+ *
+ * </pre>
+ */
+ void doLineNumberTable(DataInputStream in, String indent) throws IOException {
+ int line_number_table_length = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, indent + "line number table length", line_number_table_length);
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < line_number_table_length; i++) {
+ int start_pc = in.readUnsignedShort();
+ int line_number = in.readUnsignedShort();
+ sb.append(start_pc);
+ sb.append("/");
+ sb.append(line_number);
+ sb.append(" ");
+ }
+ ps.printf("%-30s %d: %s\n", indent + "line number table", line_number_table_length, sb);
+ }
- void doLocalVariableTable(DataInputStream in, String indent)
- throws IOException {
- int local_variable_table_length = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, indent + "local variable table length",
- local_variable_table_length);
- for (int i = 0; i < local_variable_table_length; i++) {
- int start_pc = in.readUnsignedShort();
- int length = in.readUnsignedShort();
- int name_index = in.readUnsignedShort();
- int descriptor_index = in.readUnsignedShort();
- int index = in.readUnsignedShort();
- ps.printf("%-30s %d: %d/%d %s(#%d) %s(#%d)\n", indent, index,
- start_pc, length, pool[name_index], name_index,
- pool[descriptor_index], descriptor_index);
- }
- }
+ /**
+ * <pre>
+ * LocalVariableTable_attribute {
+ * u2 attribute_name_index;
+ * u4 attribute_length;
+ * u2 local_variable_table_length;
+ * { u2 start_pc;
+ * u2 length;
+ * u2 name_index;
+ * u2 descriptor_index;
+ * u2 index;
+ * } local_variable_table[local_variable_table_length];
+ * }
+ * </pre>
+ */
- /**
- * <pre>
- * InnerClasses_attribute {
- * u2 attribute_name_index;
- * u4 attribute_length;
- * u2 number_of_classes;
- * { u2 inner_class_info_index;
- * u2 outer_class_info_index;
- * u2 inner_name_index;
- * u2 inner_class_access_flags;
- * } classes[number_of_classes];
- * }
- * </pre>
- *
- */
- void doInnerClasses(DataInputStream in, String indent) throws IOException {
- int number_of_classes = in.readUnsignedShort();
- ps.printf(NUM_COLUMN, indent + "number of classes", number_of_classes);
- for (int i = 0; i < number_of_classes; i++) {
- int inner_class_info_index = in.readUnsignedShort();
- int outer_class_info_index = in.readUnsignedShort();
- int inner_name_index = in.readUnsignedShort();
- int inner_class_access_flags = in.readUnsignedShort();
- printAccess(inner_class_access_flags);
+ void doLocalVariableTable(DataInputStream in, String indent) throws IOException {
+ int local_variable_table_length = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, indent + "local variable table length", local_variable_table_length);
+ for (int i = 0; i < local_variable_table_length; i++) {
+ int start_pc = in.readUnsignedShort();
+ int length = in.readUnsignedShort();
+ int name_index = in.readUnsignedShort();
+ int descriptor_index = in.readUnsignedShort();
+ int index = in.readUnsignedShort();
+ ps.printf("%-30s %d: %d/%d %s(#%d) %s(#%d)\n", indent, index, start_pc, length, pool[name_index],
+ name_index, pool[descriptor_index], descriptor_index);
+ }
+ }
- String iname = "<>";
- String oname = iname;
+ /**
+ * <pre>
+ * InnerClasses_attribute {
+ * u2 attribute_name_index;
+ * u4 attribute_length;
+ * u2 number_of_classes;
+ * { u2 inner_class_info_index;
+ * u2 outer_class_info_index;
+ * u2 inner_name_index;
+ * u2 inner_class_access_flags;
+ * } classes[number_of_classes];
+ * }
+ * </pre>
+ */
+ void doInnerClasses(DataInputStream in, String indent) throws IOException {
+ int number_of_classes = in.readUnsignedShort();
+ ps.printf(NUM_COLUMN, indent + "number of classes", number_of_classes);
+ for (int i = 0; i < number_of_classes; i++) {
+ int inner_class_info_index = in.readUnsignedShort();
+ int outer_class_info_index = in.readUnsignedShort();
+ int inner_name_index = in.readUnsignedShort();
+ int inner_class_access_flags = in.readUnsignedShort();
+ printAccess(inner_class_access_flags);
- if (inner_class_info_index != 0)
- iname = (String) pool[((Integer) pool[inner_class_info_index])
- .intValue()];
- if (outer_class_info_index != 0)
- oname = (String) pool[((Integer) pool[outer_class_info_index])
- .intValue()];
+ String iname = "<>";
+ String oname = iname;
- ps.printf("%-30s %d: %x %s(#%d/c) %s(#%d/c) %s(#%d) \n", indent, i,
- inner_class_access_flags, iname, inner_class_info_index,
- oname, outer_class_info_index, pool[inner_name_index],
- inner_name_index);
- }
- }
+ if (inner_class_info_index != 0)
+ iname = (String) pool[((Integer) pool[inner_class_info_index]).intValue()];
+ if (outer_class_info_index != 0)
+ oname = (String) pool[((Integer) pool[outer_class_info_index]).intValue()];
+ ps.printf("%-30s %d: %x %s(#%d/c) %s(#%d/c) %s(#%d) \n", indent, i, inner_class_access_flags, iname,
+ inner_class_info_index, oname, outer_class_info_index, pool[inner_name_index], inner_name_index);
+ }
+ }
- void printClassAccess(int mod) {
- ps.printf("%-30s", "Class Access");
- if ((ACC_PUBLIC&mod)!= 0)
- ps.print(" public");
- if ((ACC_FINAL&mod)!= 0)
- ps.print(" final");
- if ((ACC_SUPER&mod)!= 0)
- ps.print(" super");
- if ((ACC_INTERFACE&mod)!= 0)
- ps.print(" interface");
- if ((ACC_ABSTRACT&mod)!= 0)
- ps.print(" abstract");
+ void printClassAccess(int mod) {
+ ps.printf("%-30s", "Class Access");
+ if ((ACC_PUBLIC & mod) != 0)
+ ps.print(" public");
+ if ((ACC_FINAL & mod) != 0)
+ ps.print(" final");
+ if ((ACC_SUPER & mod) != 0)
+ ps.print(" super");
+ if ((ACC_INTERFACE & mod) != 0)
+ ps.print(" interface");
+ if ((ACC_ABSTRACT & mod) != 0)
+ ps.print(" abstract");
- ps.println();
- }
+ ps.println();
+ }
- void printAccess(int mod) {
- ps.printf("%-30s", "Access");
- if (Modifier.isStatic(mod))
- ps.print(" static");
- if (Modifier.isAbstract(mod))
- ps.print(" abstract");
- if (Modifier.isPublic(mod))
- ps.print(" public");
- if (Modifier.isFinal(mod))
- ps.print(" final");
- if (Modifier.isInterface(mod))
- ps.print(" interface");
- if (Modifier.isNative(mod))
- ps.print(" native");
- if (Modifier.isPrivate(mod))
- ps.print(" private");
- if (Modifier.isProtected(mod))
- ps.print(" protected");
- if (Modifier.isStrict(mod))
- ps.print(" strict");
- if (Modifier.isSynchronized(mod))
- ps.print(" synchronized");
- if (Modifier.isTransient(mod))
- ps.print(" transient");
- if (Modifier.isVolatile(mod))
- ps.print(" volatile");
+ void printAccess(int mod) {
+ ps.printf("%-30s", "Access");
+ if (Modifier.isStatic(mod))
+ ps.print(" static");
+ if (Modifier.isAbstract(mod))
+ ps.print(" abstract");
+ if (Modifier.isPublic(mod))
+ ps.print(" public");
+ if (Modifier.isFinal(mod))
+ ps.print(" final");
+ if (Modifier.isInterface(mod))
+ ps.print(" interface");
+ if (Modifier.isNative(mod))
+ ps.print(" native");
+ if (Modifier.isPrivate(mod))
+ ps.print(" private");
+ if (Modifier.isProtected(mod))
+ ps.print(" protected");
+ if (Modifier.isStrict(mod))
+ ps.print(" strict");
+ if (Modifier.isSynchronized(mod))
+ ps.print(" synchronized");
+ if (Modifier.isTransient(mod))
+ ps.print(" transient");
+ if (Modifier.isVolatile(mod))
+ ps.print(" volatile");
- ps.println();
- }
+ ps.println();
+ }
- public static void main(String args[]) throws Exception {
- if (args.length == 0) {
- System.err.println("clsd <class file>+");
- }
- for (int i = 0; i < args.length; i++) {
- File f = new File(args[i]);
- if (!f.isFile())
- System.err.println("File does not exist or is directory " + f);
- else {
- ClassDumper cd = new ClassDumper(args[i]);
- cd.dump(null);
- }
- }
- }
+ public static void main(String args[]) throws Exception {
+ if (args.length == 0) {
+ System.err.println("clsd <class file>+");
+ }
+ for (int i = 0; i < args.length; i++) {
+ File f = new File(args[i]);
+ if (!f.isFile())
+ System.err.println("File does not exist or is directory " + f);
+ else {
+ ClassDumper cd = new ClassDumper(args[i]);
+ cd.dump(null);
+ }
+ }
+ }
}
diff --git a/bundleplugin/src/main/java/aQute/libg/classloaders/URLClassLoaderWrapper.java b/bundleplugin/src/main/java/aQute/libg/classloaders/URLClassLoaderWrapper.java
index 10ddca5..c199a92 100644
--- a/bundleplugin/src/main/java/aQute/libg/classloaders/URLClassLoaderWrapper.java
+++ b/bundleplugin/src/main/java/aQute/libg/classloaders/URLClassLoaderWrapper.java
@@ -4,24 +4,25 @@
import java.net.*;
public class URLClassLoaderWrapper {
- final URLClassLoader loader;
- final Method addURL;
-
+ final URLClassLoader loader;
+ final Method addURL;
+
public URLClassLoaderWrapper(ClassLoader loader) throws Exception {
this.loader = (URLClassLoader) loader;
addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addURL.setAccessible(true);
}
-
- public void addURL(URL url) throws Exception {
+
+ public void addURL(URL url) throws Exception {
try {
- addURL.invoke(loader, url);
- } catch( InvocationTargetException ite) {
+ addURL.invoke(loader, url);
+ }
+ catch (InvocationTargetException ite) {
throw (Exception) ite.getTargetException();
}
}
-
- public Class<?> loadClass(String name) throws Exception {
+
+ public Class< ? > loadClass(String name) throws Exception {
return loader.loadClass(name);
}
}
diff --git a/bundleplugin/src/main/java/aQute/libg/clauses/Clauses.java b/bundleplugin/src/main/java/aQute/libg/clauses/Clauses.java
index 12eba4f..5701bab 100755
--- a/bundleplugin/src/main/java/aQute/libg/clauses/Clauses.java
+++ b/bundleplugin/src/main/java/aQute/libg/clauses/Clauses.java
@@ -5,15 +5,14 @@
import aQute.libg.log.*;
import aQute.libg.qtokens.*;
-public class Clauses extends LinkedHashMap<String,Map<String,String>>{
+public class Clauses extends LinkedHashMap<String,Map<String,String>> {
private static final long serialVersionUID = 1L;
-
+
/**
* Standard OSGi header parser. This parser can handle the format clauses
* ::= clause ( ',' clause ) + clause ::= name ( ';' name ) (';' key '='
- * value )
- *
- * This is mapped to a Map { name => Map { attr|directive => value } }
+ * value ) This is mapped to a Map { name => Map { attr|directive => value }
+ * }
*
* @param value
* @return
@@ -36,9 +35,8 @@
String adname = qt.nextToken();
if ((del = qt.getSeparator()) != '=') {
if (hadAttribute)
- throw new IllegalArgumentException(
- "Header contains name field after attribute or directive: "
- + adname + " from " + value);
+ throw new IllegalArgumentException("Header contains name field after attribute or directive: "
+ + adname + " from " + value);
aliases.add(adname);
} else {
String advalue = qt.nextToken();
@@ -51,10 +49,8 @@
String packageName = i.next();
if (result.containsKey(packageName)) {
if (logger != null)
- logger
- .warning("Duplicate package name in header: "
- + packageName
- + ". Multiple package names in one clause not supported in Bnd.");
+ logger.warning("Duplicate package name in header: " + packageName
+ + ". Multiple package names in one clause not supported in Bnd.");
} else
result.put(packageName, clause);
}
diff --git a/bundleplugin/src/main/java/aQute/libg/clauses/Selector.java b/bundleplugin/src/main/java/aQute/libg/clauses/Selector.java
index eaa806c..a2a9699 100755
--- a/bundleplugin/src/main/java/aQute/libg/clauses/Selector.java
+++ b/bundleplugin/src/main/java/aQute/libg/clauses/Selector.java
@@ -65,18 +65,18 @@
StringBuilder sb = new StringBuilder();
for (int c = 0; c < string.length(); c++) {
switch (string.charAt(c)) {
- case '.':
- sb.append("\\.");
- break;
- case '*':
- sb.append(".*");
- break;
- case '?':
- sb.append(".?");
- break;
- default:
- sb.append(string.charAt(c));
- break;
+ case '.' :
+ sb.append("\\.");
+ break;
+ case '*' :
+ sb.append(".*");
+ break;
+ case '?' :
+ sb.append(".?");
+ break;
+ default :
+ sb.append(string.charAt(c));
+ break;
}
}
string = sb.toString();
@@ -101,17 +101,16 @@
public static List<Selector> getInstructions(Clauses clauses) {
List<Selector> result = new ArrayList<Selector>();
- for (Map.Entry<String, Map<String, String>> entry : clauses.entrySet()) {
+ for (Map.Entry<String,Map<String,String>> entry : clauses.entrySet()) {
Selector instruction = getPattern(entry.getKey());
result.add(instruction);
}
return result;
}
-
- public static <T> List<T> select(Collection<T> domain,
- List<Selector> instructions) {
+
+ public static <T> List<T> select(Collection<T> domain, List<Selector> instructions) {
List<T> result = new ArrayList<T>();
- Iterator<T> iterator = domain.iterator();
+ Iterator<T> iterator = domain.iterator();
value: while (iterator.hasNext()) {
T value = iterator.next();
for (Selector instruction : instructions) {
@@ -124,6 +123,5 @@
}
return result;
}
-
}
diff --git a/bundleplugin/src/main/java/aQute/libg/command/Command.java b/bundleplugin/src/main/java/aQute/libg/command/Command.java
index 209be52..3feb702 100644
--- a/bundleplugin/src/main/java/aQute/libg/command/Command.java
+++ b/bundleplugin/src/main/java/aQute/libg/command/Command.java
@@ -12,7 +12,7 @@
boolean trace;
Reporter reporter;
List<String> arguments = new ArrayList<String>();
- Map<String, String> variables = new LinkedHashMap<String, String>();
+ Map<String,String> variables = new LinkedHashMap<String,String>();
long timeout = 0;
File cwd = new File("").getAbsoluteFile();
static Timer timer = new Timer(Command.class.getName(), true);
@@ -24,8 +24,7 @@
this.fullCommand = fullCommand;
}
- public Command() {
- }
+ public Command() {}
public int execute(Appendable stdout, Appendable stderr) throws Exception {
return execute((InputStream) null, stdout, stderr);
@@ -44,7 +43,7 @@
String args[] = arguments.toArray(new String[arguments.size()]);
String vars[] = new String[variables.size()];
int i = 0;
- for (Entry<String, String> s : variables.entrySet()) {
+ for (Entry<String,String> s : variables.entrySet()) {
vars[i++] = s.getKey() + "=" + s.getValue();
}
@@ -53,7 +52,6 @@
else
process = Runtime.getRuntime().exec(fullCommand, vars.length == 0 ? null : vars, cwd);
-
// Make sure the command will not linger when we go
Runnable r = new Runnable() {
public void run() {
@@ -83,12 +81,12 @@
cout.start();
Collector cerr = new Collector(err, stderr);
cerr.start();
-
+
try {
int c = in.read();
while (c >= 0) {
stdin.write(c);
- if ( c == '\n')
+ if (c == '\n')
stdin.flush();
c = in.read();
}
@@ -98,13 +96,14 @@
}
catch (Exception e) {
// Who cares?
- } finally {
+ }
+ finally {
stdin.close();
}
-
+
if (reporter != null)
reporter.trace("exited process");
-
+
cerr.join();
cout.join();
if (reporter != null)
@@ -120,15 +119,15 @@
timer.cancel();
Runtime.getRuntime().removeShutdownHook(hook);
}
-
+
byte exitValue = (byte) process.waitFor();
if (reporter != null)
- reporter.trace("cmd %s executed with result=%d, result: %s/%s, timedout=%s", arguments, exitValue,
- stdout, stderr, timedout);
+ reporter.trace("cmd %s executed with result=%d, result: %s/%s, timedout=%s", arguments, exitValue, stdout,
+ stderr, timedout);
if (timedout)
return Integer.MIN_VALUE;
-
+
return exitValue;
}
@@ -182,7 +181,7 @@
c = in.read();
}
}
- catch( IOException e) {
+ catch (IOException e) {
// We assume the socket is closed
}
catch (Exception e) {
@@ -191,8 +190,7 @@
sb.append(e.toString());
sb.append("\n**************************************\n");
}
- catch (IOException e1) {
- }
+ catch (IOException e1) {}
if (reporter != null) {
reporter.trace("cmd exec: %s", e);
}
@@ -217,7 +215,7 @@
public void inherit() {
ProcessBuilder pb = new ProcessBuilder();
- for (Entry<String, String> e : pb.environment().entrySet()) {
+ for (Entry<String,String> e : pb.environment().entrySet()) {
var(e.getKey(), e.getValue());
}
}
diff --git a/bundleplugin/src/main/java/aQute/libg/cryptography/Crypto.java b/bundleplugin/src/main/java/aQute/libg/cryptography/Crypto.java
index ff971e8..22eac45 100644
--- a/bundleplugin/src/main/java/aQute/libg/cryptography/Crypto.java
+++ b/bundleplugin/src/main/java/aQute/libg/cryptography/Crypto.java
@@ -7,61 +7,57 @@
import java.util.regex.*;
public class Crypto {
- static final Pattern RSA_PRIVATE = Pattern
- .compile("\\s*RSA\\.Private\\((\\p{XDigit})+:(\\p{XDigit})+\\)\\s*");
- static final Pattern RSA_PUBLIC = Pattern
- .compile("\\s*RSA\\.Public\\((\\p{XDigit})+:(\\p{XDigit})+\\)\\s*");
+ static final Pattern RSA_PRIVATE = Pattern.compile("\\s*RSA\\.Private\\((\\p{XDigit})+:(\\p{XDigit})+\\)\\s*");
+ static final Pattern RSA_PUBLIC = Pattern.compile("\\s*RSA\\.Public\\((\\p{XDigit})+:(\\p{XDigit})+\\)\\s*");
/**
- *
* @param <T>
* @param spec
* @return
* @throws Exception
*/
- @SuppressWarnings("unchecked") public static <T> T fromString(String spec, Class<T> c) throws Exception {
- if ( PrivateKey.class.isAssignableFrom(c)) {
- Matcher m = RSA_PRIVATE.matcher(spec);
- if ( m.matches()) {
- return (T) RSA.createPrivate(
- new BigInteger(m.group(1)), new BigInteger(m.group(2)));
+ @SuppressWarnings("unchecked")
+ public static <T> T fromString(String spec, Class<T> c) throws Exception {
+ if (PrivateKey.class.isAssignableFrom(c)) {
+ Matcher m = RSA_PRIVATE.matcher(spec);
+ if (m.matches()) {
+ return (T) RSA.createPrivate(new BigInteger(m.group(1)), new BigInteger(m.group(2)));
}
- throw new IllegalArgumentException("No such private key " + spec );
+ throw new IllegalArgumentException("No such private key " + spec);
}
-
- if ( PublicKey.class.isAssignableFrom(c)) {
- Matcher m = RSA_PUBLIC.matcher(spec);
- if ( m.matches()) {
- return (T) RSA.create( new RSAPublicKeySpec(
- new BigInteger(m.group(1)), new BigInteger(m.group(2))));
+
+ if (PublicKey.class.isAssignableFrom(c)) {
+ Matcher m = RSA_PUBLIC.matcher(spec);
+ if (m.matches()) {
+ return (T) RSA.create(new RSAPublicKeySpec(new BigInteger(m.group(1)), new BigInteger(m.group(2))));
}
- throw new IllegalArgumentException("No such public key " + spec );
+ throw new IllegalArgumentException("No such public key " + spec);
}
return null;
}
- public static String toString( Object key ) {
- if ( key instanceof RSAPrivateKey ) {
+ public static String toString(Object key) {
+ if (key instanceof RSAPrivateKey) {
RSAPrivateKey pk = (RSAPrivateKey) key;
return "RSA.Private(" + pk.getModulus() + ":" + pk.getPrivateExponent() + ")";
}
- if ( key instanceof RSAPublicKey ) {
+ if (key instanceof RSAPublicKey) {
RSAPublicKey pk = (RSAPublicKey) key;
return "RSA.Private(" + pk.getModulus() + ":" + pk.getPublicExponent() + ")";
}
return null;
}
-
-// public static <T extends Digest> Signer<T> signer(PrivateKey key, Digester<T> digester) throws NoSuchAlgorithmException {
-// Signature s = Signature.getInstance(key.getAlgorithm() + "with" + digester.getAlgorithm());
-// return new Signer<T>(s,digester);
-// }
+ // public static <T extends Digest> Signer<T> signer(PrivateKey key,
+ // Digester<T> digester) throws NoSuchAlgorithmException {
+ // Signature s = Signature.getInstance(key.getAlgorithm() + "with" +
+ // digester.getAlgorithm());
+ // return new Signer<T>(s,digester);
+ // }
public static Verifier verifier(PublicKey key, Digest digest) throws NoSuchAlgorithmException {
Signature s = Signature.getInstance(key.getAlgorithm() + "with" + digest.getAlgorithm());
- return new Verifier(s,digest);
+ return new Verifier(s, digest);
}
-
}
diff --git a/bundleplugin/src/main/java/aQute/libg/cryptography/Digest.java b/bundleplugin/src/main/java/aQute/libg/cryptography/Digest.java
index 90e7b1a..93d48ad 100644
--- a/bundleplugin/src/main/java/aQute/libg/cryptography/Digest.java
+++ b/bundleplugin/src/main/java/aQute/libg/cryptography/Digest.java
@@ -10,30 +10,28 @@
protected Digest(byte[] checksum, int width) {
this.digest = checksum;
if (digest.length != width)
- throw new IllegalArgumentException("Invalid width for digest: " + digest.length
- + " expected " + width);
+ throw new IllegalArgumentException("Invalid width for digest: " + digest.length + " expected " + width);
}
-
public byte[] digest() {
return digest;
}
- @Override public String toString() {
+ @Override
+ public String toString() {
return String.format("%s(d=%s)", getAlgorithm(), Hex.toHexString(digest));
}
public abstract String getAlgorithm();
-
-
+
public boolean equals(Object other) {
- if ( !(other instanceof Digest))
+ if (!(other instanceof Digest))
return false;
Digest d = (Digest) other;
return Arrays.equals(d.digest, digest);
}
-
+
public int hashCode() {
return Arrays.hashCode(digest);
}
diff --git a/bundleplugin/src/main/java/aQute/libg/cryptography/Digester.java b/bundleplugin/src/main/java/aQute/libg/cryptography/Digester.java
index eeb2c8f..2785c3d 100644
--- a/bundleplugin/src/main/java/aQute/libg/cryptography/Digester.java
+++ b/bundleplugin/src/main/java/aQute/libg/cryptography/Digester.java
@@ -7,41 +7,45 @@
public abstract class Digester<T extends Digest> extends OutputStream {
protected MessageDigest md;
- OutputStream out[];
-
- public Digester(MessageDigest instance, OutputStream ... out) {
+ OutputStream out[];
+
+ public Digester(MessageDigest instance, OutputStream... out) {
md = instance;
this.out = out;
}
-
+
@Override
- public void write( byte[] buffer, int offset, int length) throws IOException{
- md.update(buffer,offset,length);
- for ( OutputStream o : out ) {
+ public void write(byte[] buffer, int offset, int length) throws IOException {
+ md.update(buffer, offset, length);
+ for (OutputStream o : out) {
o.write(buffer, offset, length);
}
}
+
@Override
- public void write( int b) throws IOException{
+ public void write(int b) throws IOException {
md.update((byte) b);
- for ( OutputStream o : out ) {
+ for (OutputStream o : out) {
o.write(b);
}
}
-
+
public MessageDigest getMessageDigest() throws Exception {
return md;
}
-
+
public T from(InputStream in) throws Exception {
- IO.copy(in,this);
+ IO.copy(in, this);
return digest();
}
-
- public void setOutputs(OutputStream ...out) {
+
+ public void setOutputs(OutputStream... out) {
this.out = out;
}
+
public abstract T digest() throws Exception;
- public abstract T digest( byte [] bytes) throws Exception;
+
+ public abstract T digest(byte[] bytes) throws Exception;
+
public abstract String getAlgorithm();
}
diff --git a/bundleplugin/src/main/java/aQute/libg/cryptography/Key.java b/bundleplugin/src/main/java/aQute/libg/cryptography/Key.java
index 160ec05..f4fc217 100644
--- a/bundleplugin/src/main/java/aQute/libg/cryptography/Key.java
+++ b/bundleplugin/src/main/java/aQute/libg/cryptography/Key.java
@@ -1,8 +1,6 @@
package aQute.libg.cryptography;
-
public abstract class Key implements java.security.Key {
private static final long serialVersionUID = 1L;
-
}
diff --git a/bundleplugin/src/main/java/aQute/libg/cryptography/MD5.java b/bundleplugin/src/main/java/aQute/libg/cryptography/MD5.java
index 84b53ee..05a6bdd 100644
--- a/bundleplugin/src/main/java/aQute/libg/cryptography/MD5.java
+++ b/bundleplugin/src/main/java/aQute/libg/cryptography/MD5.java
@@ -3,32 +3,36 @@
import java.io.*;
import java.security.*;
-
-
public class MD5 extends Digest {
- public final static String ALGORITHM = "MD5";
-
- public static Digester<MD5> getDigester(OutputStream ... out) throws Exception {
+ public final static String ALGORITHM = "MD5";
+
+ public static Digester<MD5> getDigester(OutputStream... out) throws Exception {
return new Digester<MD5>(MessageDigest.getInstance(ALGORITHM), out) {
-
- @Override public MD5 digest() throws Exception {
+
+ @Override
+ public MD5 digest() throws Exception {
return new MD5(md.digest());
}
- @Override public MD5 digest(byte[] bytes) {
+ @Override
+ public MD5 digest(byte[] bytes) {
return new MD5(bytes);
}
- @Override public String getAlgorithm() {
+
+ @Override
+ public String getAlgorithm() {
return ALGORITHM;
}
};
}
-
-
+
public MD5(byte[] digest) {
- super(digest,16);
+ super(digest, 16);
}
- @Override public String getAlgorithm() { return ALGORITHM; }
+ @Override
+ public String getAlgorithm() {
+ return ALGORITHM;
+ }
}
\ No newline at end of file
diff --git a/bundleplugin/src/main/java/aQute/libg/cryptography/RSA.java b/bundleplugin/src/main/java/aQute/libg/cryptography/RSA.java
index 61bafb5..c1aa2ee 100644
--- a/bundleplugin/src/main/java/aQute/libg/cryptography/RSA.java
+++ b/bundleplugin/src/main/java/aQute/libg/cryptography/RSA.java
@@ -15,7 +15,8 @@
static private KeyFactory getKeyFactory() {
try {
return KeyFactory.getInstance(ALGORITHM);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
// built in
}
return null;
@@ -24,20 +25,23 @@
public static RSAPrivateKey create(RSAPrivateKeySpec keyspec) throws InvalidKeySpecException {
return (RSAPrivateKey) factory.generatePrivate(keyspec);
}
+
public static RSAPublicKey create(RSAPublicKeySpec keyspec) throws InvalidKeySpecException {
return (RSAPublicKey) factory.generatePrivate(keyspec);
}
-
+
public static RSAPublicKey createPublic(BigInteger m, BigInteger e) throws InvalidKeySpecException {
- return create( new RSAPublicKeySpec(m,e));
+ return create(new RSAPublicKeySpec(m, e));
}
+
public static RSAPrivateKey createPrivate(BigInteger m, BigInteger e) throws InvalidKeySpecException {
- return create( new RSAPrivateKeySpec(m,e));
+ return create(new RSAPrivateKeySpec(m, e));
}
-
- public static Pair<RSAPrivateKey, RSAPublicKey> generate() throws NoSuchAlgorithmException {
+
+ public static Pair<RSAPrivateKey,RSAPublicKey> generate() throws NoSuchAlgorithmException {
KeyPairGenerator kpg = KeyPairGenerator.getInstance(ALGORITHM);
KeyPair keypair = kpg.generateKeyPair();
- return new Pair<RSAPrivateKey,RSAPublicKey>( (RSAPrivateKey) keypair.getPrivate(), (RSAPublicKey) keypair.getPublic());
+ return new Pair<RSAPrivateKey,RSAPublicKey>((RSAPrivateKey) keypair.getPrivate(),
+ (RSAPublicKey) keypair.getPublic());
}
}
diff --git a/bundleplugin/src/main/java/aQute/libg/cryptography/SHA1.java b/bundleplugin/src/main/java/aQute/libg/cryptography/SHA1.java
index a01f112..d0a486c 100644
--- a/bundleplugin/src/main/java/aQute/libg/cryptography/SHA1.java
+++ b/bundleplugin/src/main/java/aQute/libg/cryptography/SHA1.java
@@ -3,33 +3,36 @@
import java.io.*;
import java.security.*;
-
-
public class SHA1 extends Digest {
- public final static String ALGORITHM = "SHA1";
-
-
- public static Digester<SHA1> getDigester(OutputStream ... out ) throws NoSuchAlgorithmException {
+ public final static String ALGORITHM = "SHA1";
+
+ public static Digester<SHA1> getDigester(OutputStream... out) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance(ALGORITHM);
return new Digester<SHA1>(md, out) {
- @Override public SHA1 digest() throws Exception {
+ @Override
+ public SHA1 digest() throws Exception {
return new SHA1(md.digest());
}
- @Override public SHA1 digest(byte[] bytes) {
+ @Override
+ public SHA1 digest(byte[] bytes) {
return new SHA1(bytes);
}
- @Override public String getAlgorithm() {
+
+ @Override
+ public String getAlgorithm() {
return ALGORITHM;
}
};
}
-
+
public SHA1(byte[] b) {
super(b, 20);
}
-
- @Override public String getAlgorithm() { return ALGORITHM; }
+ @Override
+ public String getAlgorithm() {
+ return ALGORITHM;
+ }
}
\ No newline at end of file
diff --git a/bundleplugin/src/main/java/aQute/libg/cryptography/SHA256.java b/bundleplugin/src/main/java/aQute/libg/cryptography/SHA256.java
index 5b25cf3..b6eeacc 100644
--- a/bundleplugin/src/main/java/aQute/libg/cryptography/SHA256.java
+++ b/bundleplugin/src/main/java/aQute/libg/cryptography/SHA256.java
@@ -3,33 +3,36 @@
import java.io.*;
import java.security.*;
-
-
public class SHA256 extends Digest {
- public final static String ALGORITHM = "SHA256";
-
-
- public static Digester<SHA256> getDigester(OutputStream ... out ) throws NoSuchAlgorithmException {
+ public final static String ALGORITHM = "SHA256";
+
+ public static Digester<SHA256> getDigester(OutputStream... out) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance(ALGORITHM);
return new Digester<SHA256>(md, out) {
- @Override public SHA256 digest() throws Exception {
+ @Override
+ public SHA256 digest() throws Exception {
return new SHA256(md.digest());
}
- @Override public SHA256 digest(byte[] bytes) {
+ @Override
+ public SHA256 digest(byte[] bytes) {
return new SHA256(bytes);
}
- @Override public String getAlgorithm() {
+
+ @Override
+ public String getAlgorithm() {
return ALGORITHM;
}
};
}
-
+
public SHA256(byte[] b) {
super(b, 32);
}
-
- @Override public String getAlgorithm() { return ALGORITHM; }
+ @Override
+ public String getAlgorithm() {
+ return ALGORITHM;
+ }
}
\ No newline at end of file
diff --git a/bundleplugin/src/main/java/aQute/libg/cryptography/Signer.java b/bundleplugin/src/main/java/aQute/libg/cryptography/Signer.java
index 5218e2d..977eda6 100644
--- a/bundleplugin/src/main/java/aQute/libg/cryptography/Signer.java
+++ b/bundleplugin/src/main/java/aQute/libg/cryptography/Signer.java
@@ -5,36 +5,39 @@
public class Signer<D extends Digest> extends OutputStream {
Signature signature;
- Digester<D> digester;
-
+ Digester<D> digester;
+
Signer(Signature s, Digester<D> digester) {
this.signature = s;
- this.digester = digester;
+ this.digester = digester;
}
- @Override public void write(byte[] buffer, int offset, int length) throws IOException {
+ @Override
+ public void write(byte[] buffer, int offset, int length) throws IOException {
try {
signature.update(buffer, offset, length);
digester.write(buffer, offset, length);
- } catch (SignatureException e) {
+ }
+ catch (SignatureException e) {
throw new IOException(e.getLocalizedMessage());
}
}
- @Override public void write(int b) throws IOException {
+ @Override
+ public void write(int b) throws IOException {
try {
signature.update((byte) b);
digester.write(b);
- } catch (SignatureException e) {
+ }
+ catch (SignatureException e) {
throw new IOException(e.getLocalizedMessage());
}
}
-
public Signature signature() throws Exception {
return signature;
}
-
+
public D digest() throws Exception {
return digester.digest();
}
diff --git a/bundleplugin/src/main/java/aQute/libg/cryptography/Verifier.java b/bundleplugin/src/main/java/aQute/libg/cryptography/Verifier.java
index 5506ece..1005e0a 100644
--- a/bundleplugin/src/main/java/aQute/libg/cryptography/Verifier.java
+++ b/bundleplugin/src/main/java/aQute/libg/cryptography/Verifier.java
@@ -3,30 +3,31 @@
import java.io.*;
import java.security.*;
-
public class Verifier extends OutputStream {
- final Signature signature;
- final Digest d;
-
+ final Signature signature;
+ final Digest d;
+
Verifier(Signature s, Digest d) {
this.signature = s;
this.d = d;
}
-
+
@Override
- public void write( byte[] buffer, int offset, int length) throws IOException {
+ public void write(byte[] buffer, int offset, int length) throws IOException {
try {
signature.update(buffer, offset, length);
- } catch (SignatureException e) {
+ }
+ catch (SignatureException e) {
throw new IOException(e.getLocalizedMessage());
}
}
@Override
- public void write( int b) throws IOException {
+ public void write(int b) throws IOException {
try {
signature.update((byte) b);
- } catch (SignatureException e) {
+ }
+ catch (SignatureException e) {
throw new IOException(e.getLocalizedMessage());
}
}
@@ -34,5 +35,5 @@
public boolean verify() throws Exception {
return signature.verify(d.digest());
}
-
+
}
diff --git a/bundleplugin/src/main/java/aQute/libg/fileiterator/FileIterator.java b/bundleplugin/src/main/java/aQute/libg/fileiterator/FileIterator.java
index 7cd73a2..2c988e6 100644
--- a/bundleplugin/src/main/java/aQute/libg/fileiterator/FileIterator.java
+++ b/bundleplugin/src/main/java/aQute/libg/fileiterator/FileIterator.java
@@ -4,40 +4,39 @@
import java.util.*;
public class FileIterator implements Iterator<File> {
- File dir;
- int n = 0;
- FileIterator next;
+ File dir;
+ int n = 0;
+ FileIterator next;
- public FileIterator(File nxt) {
- assert nxt.isDirectory();
- this.dir = nxt;
- }
+ public FileIterator(File nxt) {
+ assert nxt.isDirectory();
+ this.dir = nxt;
+ }
- public boolean hasNext() {
- if (next != null)
- return next.hasNext();
+ public boolean hasNext() {
+ if (next != null)
+ return next.hasNext();
return n < dir.list().length;
- }
+ }
- public File next() {
- if (next != null) {
- File answer = next.next();
- if (!next.hasNext())
- next = null;
- return answer;
- }
+ public File next() {
+ if (next != null) {
+ File answer = next.next();
+ if (!next.hasNext())
+ next = null;
+ return answer;
+ }
File nxt = dir.listFiles()[n++];
if (nxt.isDirectory()) {
- next = new FileIterator(nxt);
- return nxt;
+ next = new FileIterator(nxt);
+ return nxt;
} else if (nxt.isFile()) {
- return nxt;
+ return nxt;
} else
- throw new IllegalStateException("File disappeared");
- }
+ throw new IllegalStateException("File disappeared");
+ }
- public void remove() {
- throw new UnsupportedOperationException(
- "Cannot remove from a file iterator");
- }
+ public void remove() {
+ throw new UnsupportedOperationException("Cannot remove from a file iterator");
+ }
}
diff --git a/bundleplugin/src/main/java/aQute/libg/filelock/DirectoryLock.java b/bundleplugin/src/main/java/aQute/libg/filelock/DirectoryLock.java
index 6e6b11e..9f82899 100644
--- a/bundleplugin/src/main/java/aQute/libg/filelock/DirectoryLock.java
+++ b/bundleplugin/src/main/java/aQute/libg/filelock/DirectoryLock.java
@@ -3,9 +3,9 @@
import java.io.*;
public class DirectoryLock {
- final File lock;
- final long timeout;
- final public static String LOCKNAME = ".lock";
+ final File lock;
+ final long timeout;
+ final public static String LOCKNAME = ".lock";
public DirectoryLock(File directory, long timeout) {
this.lock = new File(directory, LOCKNAME);
@@ -13,7 +13,6 @@
this.timeout = timeout;
}
-
public void release() {
lock.delete();
}
@@ -22,10 +21,10 @@
if (lock.mkdir())
return;
- long deadline = System.currentTimeMillis()+ timeout;
- while ( System.currentTimeMillis() < deadline) {
+ long deadline = System.currentTimeMillis() + timeout;
+ while (System.currentTimeMillis() < deadline) {
if (lock.mkdir())
- return;
+ return;
Thread.sleep(50);
}
}
diff --git a/bundleplugin/src/main/java/aQute/libg/filerepo/FileRepo.java b/bundleplugin/src/main/java/aQute/libg/filerepo/FileRepo.java
index a0149bc..e278a74 100644
--- a/bundleplugin/src/main/java/aQute/libg/filerepo/FileRepo.java
+++ b/bundleplugin/src/main/java/aQute/libg/filerepo/FileRepo.java
@@ -39,9 +39,9 @@
Matcher m = REPO_FILE.matcher(name);
if (!m.matches())
return false;
- if ( versionRange == null)
+ if (versionRange == null)
return true;
-
+
Version v = new Version(m.group(2));
return versionRange.includes(v);
}
@@ -97,10 +97,11 @@
}
public File put(String bsn, Version version) {
- File dir = new File(root,bsn);
+ File dir = new File(root, bsn);
dir.mkdirs();
- File file = new File(dir, bsn + "-" + version.getMajor() + "." + version.getMinor() + "." + version.getMicro() + ".jar");
+ File file = new File(dir, bsn + "-" + version.getMajor() + "." + version.getMinor() + "." + version.getMicro()
+ + ".jar");
return file;
}
-
+
}
diff --git a/bundleplugin/src/main/java/aQute/libg/forker/Forker.java b/bundleplugin/src/main/java/aQute/libg/forker/Forker.java
index 2559fad..3929ca4 100644
--- a/bundleplugin/src/main/java/aQute/libg/forker/Forker.java
+++ b/bundleplugin/src/main/java/aQute/libg/forker/Forker.java
@@ -12,12 +12,11 @@
* have ran their associated runnable.
*
* @author aqute
- *
* @param <T>
*/
public class Forker<T> {
final Executor executor;
- final Map<T, Job> waiting = new HashMap<T, Job>();
+ final Map<T,Job> waiting = new HashMap<T,Job>();
final Set<Job> executing = new HashSet<Job>();
final AtomicBoolean canceled = new AtomicBoolean();
private int count;
@@ -48,10 +47,12 @@
t = Thread.currentThread();
}
runnable.run();
- } catch (Exception e) {
+ }
+ catch (Exception e) {
exception = e;
e.printStackTrace();
- } finally {
+ }
+ finally {
synchronized (this) {
t = null;
}
@@ -84,7 +85,6 @@
/**
* Constructor
- *
*/
public Forker() {
this.executor = Executors.newFixedThreadPool(4);
@@ -101,8 +101,7 @@
* @param runnable
* the runnable to run
*/
- public synchronized void doWhen(Collection<? extends T> dependencies, T target,
- Runnable runnable) {
+ public synchronized void doWhen(Collection< ? extends T> dependencies, T target, Runnable runnable) {
if (waiting.containsKey(target))
throw new IllegalArgumentException("You can only add a target once to the forker");
@@ -130,8 +129,7 @@
dependencies.removeAll(waiting.keySet());
if (dependencies.size() > 0)
throw new IllegalArgumentException(
- "There are dependencies in the jobs that are not present in the targets: "
- + dependencies);
+ "There are dependencies in the jobs that are not present in the targets: " + dependencies);
}
@@ -181,8 +179,9 @@
for (Job job : waiting.values()) {
// boolean x =
- job.dependencies.remove(done.target);
- //System.err.println( "Removing " + done.target + " from " + job.target + " ?" + x + " " + job.dependencies.size());
+ job.dependencies.remove(done.target);
+ // System.err.println( "Removing " + done.target + " from " +
+ // job.target + " ?" + x + " " + job.dependencies.size());
}
}
schedule();
diff --git a/bundleplugin/src/main/java/aQute/libg/generics/Create.java b/bundleplugin/src/main/java/aQute/libg/generics/Create.java
index ee708fd..3e071b3 100644
--- a/bundleplugin/src/main/java/aQute/libg/generics/Create.java
+++ b/bundleplugin/src/main/java/aQute/libg/generics/Create.java
@@ -3,52 +3,51 @@
import java.util.*;
public class Create {
-
- public static <K,V> Map<K, V> map() {
- return new LinkedHashMap<K,V>();
- }
- public static <K,V> Map<K, V> map(Class<K> key, Class<V> value) {
- return Collections.checkedMap(new LinkedHashMap<K,V>(), key,value);
- }
+ public static <K, V> Map<K,V> map() {
+ return new LinkedHashMap<K,V>();
+ }
- public static <T> List<T> list() {
- return new ArrayList<T>();
- }
+ public static <K, V> Map<K,V> map(Class<K> key, Class<V> value) {
+ return Collections.checkedMap(new LinkedHashMap<K,V>(), key, value);
+ }
- public static <T> List<T> list(Class<T> c) {
- return Collections.checkedList(new ArrayList<T>(),c) ;
- }
+ public static <T> List<T> list() {
+ return new ArrayList<T>();
+ }
- public static <T> Set<T> set() {
- return new HashSet<T>();
- }
+ public static <T> List<T> list(Class<T> c) {
+ return Collections.checkedList(new ArrayList<T>(), c);
+ }
- public static <T> Set<T> set(Class<T> c) {
- return Collections.checkedSet(new HashSet<T>(),c);
- }
+ public static <T> Set<T> set() {
+ return new HashSet<T>();
+ }
- public static <T> List<T> list(T[] source) {
- return new ArrayList<T>(Arrays.asList(source));
- }
+ public static <T> Set<T> set(Class<T> c) {
+ return Collections.checkedSet(new HashSet<T>(), c);
+ }
- public static <T> Set<T> set(T[]source) {
- return new HashSet<T>(Arrays.asList(source));
- }
+ public static <T> List<T> list(T[] source) {
+ return new ArrayList<T>(Arrays.asList(source));
+ }
- public static <K,V> Map<K, V> copy(Map<K,V> source) {
- return new LinkedHashMap<K,V>(source);
- }
+ public static <T> Set<T> set(T[] source) {
+ return new HashSet<T>(Arrays.asList(source));
+ }
- public static <T> List<T> copy(List<T> source) {
- return new ArrayList<T>(source);
- }
+ public static <K, V> Map<K,V> copy(Map<K,V> source) {
+ return new LinkedHashMap<K,V>(source);
+ }
- public static <T> Set<T> copy(Collection<T> source) {
- if ( source == null )
- return set();
- return new HashSet<T>(source);
- }
+ public static <T> List<T> copy(List<T> source) {
+ return new ArrayList<T>(source);
+ }
-
+ public static <T> Set<T> copy(Collection<T> source) {
+ if (source == null)
+ return set();
+ return new HashSet<T>(source);
+ }
+
}
diff --git a/bundleplugin/src/main/java/aQute/libg/glob/Glob.java b/bundleplugin/src/main/java/aQute/libg/glob/Glob.java
index c4d06a7..b48c147 100644
--- a/bundleplugin/src/main/java/aQute/libg/glob/Glob.java
+++ b/bundleplugin/src/main/java/aQute/libg/glob/Glob.java
@@ -1,22 +1,21 @@
package aQute.libg.glob;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import java.util.regex.*;
public class Glob {
- private final String glob;
- private final Pattern pattern;
-
+ private final String glob;
+ private final Pattern pattern;
+
public Glob(String globString) {
this.glob = globString;
this.pattern = Pattern.compile(convertGlobToRegEx(globString));
}
-
+
public Matcher matcher(CharSequence input) {
return pattern.matcher(input);
}
-
+
@Override
public String toString() {
return glob;
@@ -39,70 +38,70 @@
int inCurlies = 0;
for (char currentChar : line.toCharArray()) {
switch (currentChar) {
- case '*':
- if (escaping)
- sb.append("\\*");
- else
- sb.append(".*");
- escaping = false;
- break;
- case '?':
- if (escaping)
- sb.append("\\?");
- else
- sb.append('.');
- escaping = false;
- break;
- case '.':
- case '(':
- case ')':
- case '+':
- case '|':
- case '^':
- case '$':
- case '@':
- case '%':
- sb.append('\\');
- sb.append(currentChar);
- escaping = false;
- break;
- case '\\':
- if (escaping) {
- sb.append("\\\\");
+ case '*' :
+ if (escaping)
+ sb.append("\\*");
+ else
+ sb.append(".*");
escaping = false;
- } else
- escaping = true;
- break;
- case '{':
- if (escaping) {
- sb.append("\\{");
- } else {
- sb.append('(');
- inCurlies++;
- }
- escaping = false;
- break;
- case '}':
- if (inCurlies > 0 && !escaping) {
- sb.append(')');
- inCurlies--;
- } else if (escaping)
- sb.append("\\}");
- else
- sb.append("}");
- escaping = false;
- break;
- case ',':
- if (inCurlies > 0 && !escaping) {
- sb.append('|');
- } else if (escaping)
- sb.append("\\,");
- else
- sb.append(",");
- break;
- default:
- escaping = false;
- sb.append(currentChar);
+ break;
+ case '?' :
+ if (escaping)
+ sb.append("\\?");
+ else
+ sb.append('.');
+ escaping = false;
+ break;
+ case '.' :
+ case '(' :
+ case ')' :
+ case '+' :
+ case '|' :
+ case '^' :
+ case '$' :
+ case '@' :
+ case '%' :
+ sb.append('\\');
+ sb.append(currentChar);
+ escaping = false;
+ break;
+ case '\\' :
+ if (escaping) {
+ sb.append("\\\\");
+ escaping = false;
+ } else
+ escaping = true;
+ break;
+ case '{' :
+ if (escaping) {
+ sb.append("\\{");
+ } else {
+ sb.append('(');
+ inCurlies++;
+ }
+ escaping = false;
+ break;
+ case '}' :
+ if (inCurlies > 0 && !escaping) {
+ sb.append(')');
+ inCurlies--;
+ } else if (escaping)
+ sb.append("\\}");
+ else
+ sb.append("}");
+ escaping = false;
+ break;
+ case ',' :
+ if (inCurlies > 0 && !escaping) {
+ sb.append('|');
+ } else if (escaping)
+ sb.append("\\,");
+ else
+ sb.append(",");
+ break;
+ default :
+ escaping = false;
+ sb.append(currentChar);
}
}
return sb.toString();
diff --git a/bundleplugin/src/main/java/aQute/libg/gzip/GZipUtils.java b/bundleplugin/src/main/java/aQute/libg/gzip/GZipUtils.java
index 6606d0e..81c9785 100644
--- a/bundleplugin/src/main/java/aQute/libg/gzip/GZipUtils.java
+++ b/bundleplugin/src/main/java/aQute/libg/gzip/GZipUtils.java
@@ -1,13 +1,10 @@
package aQute.libg.gzip;
-import java.io.BufferedInputStream;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.GZIPInputStream;
+import java.io.*;
+import java.util.zip.*;
public class GZipUtils {
-
+
/**
* Determines whether the specified stream contains gzipped data, by
* checking for the GZIP magic number, and returns a stream capable of
@@ -21,11 +18,11 @@
buffered = stream;
else
buffered = new BufferedInputStream(stream);
-
+
buffered.mark(2);
int magic = readUShort(buffered);
buffered.reset();
-
+
InputStream result;
if (magic == GZIPInputStream.GZIP_MAGIC)
result = new GZIPInputStream(buffered);
@@ -34,27 +31,27 @@
return result;
}
- /*
- * Reads unsigned short in Intel byte order.
- */
+ /*
+ * Reads unsigned short in Intel byte order.
+ */
private static int readUShort(InputStream in) throws IOException {
int b = readUByte(in);
return (readUByte(in) << 8) | b;
}
-
- /*
- * Reads unsigned byte.
- */
- private static int readUByte(InputStream in) throws IOException {
- int b = in.read();
- if (b == -1) {
- throw new EOFException();
+
+ /*
+ * Reads unsigned byte.
+ */
+ private static int readUByte(InputStream in) throws IOException {
+ int b = in.read();
+ if (b == -1) {
+ throw new EOFException();
+ }
+ if (b < -1 || b > 255) {
+ // Report on this.in, not argument in; see read{Header, Trailer}.
+ throw new IOException(in.getClass().getName() + ".read() returned value out of range -1..255: " + b);
+ }
+ return b;
}
- if (b < -1 || b > 255) {
- // Report on this.in, not argument in; see read{Header, Trailer}.
- throw new IOException(in.getClass().getName() + ".read() returned value out of range -1..255: " + b);
- }
- return b;
- }
}
diff --git a/bundleplugin/src/main/java/aQute/libg/header/Attrs.java b/bundleplugin/src/main/java/aQute/libg/header/Attrs.java
index d11b6d1..8ff65dd 100644
--- a/bundleplugin/src/main/java/aQute/libg/header/Attrs.java
+++ b/bundleplugin/src/main/java/aQute/libg/header/Attrs.java
@@ -6,9 +6,10 @@
import aQute.lib.collections.*;
import aQute.libg.version.*;
-public class Attrs implements Map<String, String> {
+public class Attrs implements Map<String,String> {
public enum Type {
- STRING(null), LONG(null), VERSION(null), DOUBLE(null), STRINGS(STRING), LONGS(LONG), VERSIONS(VERSION), DOUBLES(DOUBLE);
+ STRING(null), LONG(null), VERSION(null), DOUBLE(null), STRINGS(STRING), LONGS(LONG), VERSIONS(VERSION), DOUBLES(
+ DOUBLE);
Type sub;
@@ -33,14 +34,15 @@
* ’List<’ scalar ’>’
* </pre>
*/
- static String EXTENDED = "[\\-0-9a-zA-Z\\._]+";
- static String SCALAR = "String|Version|Long|Double";
- static String LIST = "List\\s*<\\s*(" + SCALAR + ")\\s*>";
- public static final Pattern TYPED = Pattern.compile("\\s*(" + EXTENDED + ")\\s*:\\s*("+ SCALAR + "|" + LIST + ")\\s*");
+ static String EXTENDED = "[\\-0-9a-zA-Z\\._]+";
+ static String SCALAR = "String|Version|Long|Double";
+ static String LIST = "List\\s*<\\s*(" + SCALAR + ")\\s*>";
+ public static final Pattern TYPED = Pattern.compile("\\s*(" + EXTENDED + ")\\s*:\\s*(" + SCALAR
+ + "|" + LIST + ")\\s*");
- private LinkedHashMap<String, String> map;
- private Map<String, Type> types;
- static Map<String, String> EMPTY = Collections.emptyMap();
+ private LinkedHashMap<String,String> map;
+ private Map<String,Type> types;
+ static Map<String,String> EMPTY = Collections.emptyMap();
public Attrs(Attrs... attrs) {
for (Attrs a : attrs) {
@@ -62,7 +64,8 @@
}
@SuppressWarnings("cast")
- @Deprecated public boolean containsKey(Object name) {
+ @Deprecated
+ public boolean containsKey(Object name) {
assert name instanceof String;
if (map == null)
return false;
@@ -78,7 +81,8 @@
}
@SuppressWarnings("cast")
- @Deprecated public boolean containsValue(Object value) {
+ @Deprecated
+ public boolean containsValue(Object value) {
assert value instanceof String;
if (map == null)
return false;
@@ -86,7 +90,7 @@
return map.containsValue((String) value);
}
- public Set<java.util.Map.Entry<String, String>> entrySet() {
+ public Set<java.util.Map.Entry<String,String>> entrySet() {
if (map == null)
return EMPTY.entrySet();
@@ -94,7 +98,8 @@
}
@SuppressWarnings("cast")
- @Deprecated public String get(Object key) {
+ @Deprecated
+ public String get(Object key) {
assert key instanceof String;
if (map == null)
return null;
@@ -129,7 +134,7 @@
public String put(String key, String value) {
if (map == null)
- map = new LinkedHashMap<String, String>();
+ map = new LinkedHashMap<String,String>();
Matcher m = TYPED.matcher(key);
if (m.matches()) {
@@ -137,28 +142,28 @@
String type = m.group(2);
Type t = Type.STRING;
- if ( type.startsWith("List")) {
+ if (type.startsWith("List")) {
type = m.group(3);
- if ( "String".equals(type))
+ if ("String".equals(type))
t = Type.STRINGS;
- else if ( "Long".equals(type))
+ else if ("Long".equals(type))
t = Type.LONGS;
- else if ( "Double".equals(type))
+ else if ("Double".equals(type))
t = Type.DOUBLES;
- else if ( "Version".equals(type))
- t = Type.VERSIONS;
+ else if ("Version".equals(type))
+ t = Type.VERSIONS;
} else {
- if ( "String".equals(type))
+ if ("String".equals(type))
t = Type.STRING;
- else if ( "Long".equals(type))
+ else if ("Long".equals(type))
t = Type.LONG;
- else if ( "Double".equals(type))
+ else if ("Double".equals(type))
t = Type.DOUBLE;
- else if ( "Version".equals(type))
+ else if ("Version".equals(type))
t = Type.VERSION;
}
if (types == null)
- types = new LinkedHashMap<String, Type>();
+ types = new LinkedHashMap<String,Type>();
types.put(key, t);
// TODO verify value?
@@ -176,13 +181,14 @@
return t;
}
- public void putAll(Map<? extends String, ? extends String> map) {
- for (Map.Entry<? extends String, ? extends String> e : map.entrySet())
+ public void putAll(Map< ? extends String, ? extends String> map) {
+ for (Map.Entry< ? extends String, ? extends String> e : map.entrySet())
put(e.getKey(), e.getValue());
}
@SuppressWarnings("cast")
- @Deprecated public String remove(Object var0) {
+ @Deprecated
+ public String remove(Object var0) {
assert var0 instanceof String;
if (map == null)
return null;
@@ -221,7 +227,7 @@
public void append(StringBuilder sb) {
String del = "";
- for (Map.Entry<String, String> e : entrySet()) {
+ for (Map.Entry<String,String> e : entrySet()) {
sb.append(del);
sb.append(e.getKey());
sb.append("=");
@@ -230,11 +236,13 @@
}
}
- @Deprecated public boolean equals(Object other) {
+ @Deprecated
+ public boolean equals(Object other) {
return super.equals(other);
}
- @Deprecated public int hashCode() {
+ @Deprecated
+ public int hashCode() {
return super.hashCode();
}
@@ -275,12 +283,12 @@
private Object convert(Type t, String s) {
if (t.sub == null) {
switch (t) {
- case STRING:
- return s;
- case LONG:
- return Long.parseLong(s.trim());
- case VERSION:
- return Version.parseVersion(s);
+ case STRING :
+ return s;
+ case LONG :
+ return Long.parseLong(s.trim());
+ case VERSION :
+ return Version.parseVersion(s);
}
return null;
}
diff --git a/bundleplugin/src/main/java/aQute/libg/header/OSGiHeader.java b/bundleplugin/src/main/java/aQute/libg/header/OSGiHeader.java
index 7b26f6f..6be995a 100755
--- a/bundleplugin/src/main/java/aQute/libg/header/OSGiHeader.java
+++ b/bundleplugin/src/main/java/aQute/libg/header/OSGiHeader.java
@@ -15,9 +15,8 @@
/**
* Standard OSGi header parser. This parser can handle the format clauses
* ::= clause ( ',' clause ) + clause ::= name ( ';' name ) (';' key '='
- * value )
- *
- * This is mapped to a Map { name => Map { attr|directive => value } }
+ * value ) This is mapped to a Map { name => Map { attr|directive => value }
+ * }
*
* @param value
* A string
@@ -56,10 +55,8 @@
if ((del = qt.getSeparator()) != '=') {
if (hadAttribute)
if (logger != null) {
- logger.error("Header contains name field after attribute or directive: "
- + adname
- + " from "
- + value
+ logger.error("Header contains name field after attribute or directive: " + adname
+ + " from " + value
+ ". Name fields must be consecutive, separated by a ';' like a;b;c;x=3;y=4");
}
if (adname != null && adname.length() > 0)
@@ -68,8 +65,7 @@
String advalue = qt.nextToken();
if (clause.containsKey(adname)) {
if (logger != null && logger.isPedantic())
- logger.warning("Duplicate attribute/directive name " + adname
- + " in " + value
+ logger.warning("Duplicate attribute/directive name " + adname + " in " + value
+ ". This attribute/directive will be ignored");
}
if (advalue == null) {
diff --git a/bundleplugin/src/main/java/aQute/libg/header/Parameters.java b/bundleplugin/src/main/java/aQute/libg/header/Parameters.java
index 96f0d08..f2354c4 100644
--- a/bundleplugin/src/main/java/aQute/libg/header/Parameters.java
+++ b/bundleplugin/src/main/java/aQute/libg/header/Parameters.java
@@ -5,13 +5,12 @@
import aQute.lib.collections.*;
import aQute.libg.reporter.*;
-public class Parameters implements Map<String, Attrs> {
- private LinkedHashMap<String, Attrs> map;
- static Map<String, Attrs> EMPTY = Collections.emptyMap();
- String error;
+public class Parameters implements Map<String,Attrs> {
+ private LinkedHashMap<String,Attrs> map;
+ static Map<String,Attrs> EMPTY = Collections.emptyMap();
+ String error;
- public Parameters() {
- }
+ public Parameters() {}
public Parameters(String header) {
OSGiHeader.parseHeader(header, null, this);
@@ -33,7 +32,8 @@
}
@SuppressWarnings("cast")
- @Deprecated public boolean containsKey(Object name) {
+ @Deprecated
+ public boolean containsKey(Object name) {
assert name instanceof String;
if (map == null)
return false;
@@ -49,7 +49,8 @@
}
@SuppressWarnings("cast")
- @Deprecated public boolean containsValue(Object value) {
+ @Deprecated
+ public boolean containsValue(Object value) {
assert value instanceof Attrs;
if (map == null)
return false;
@@ -57,7 +58,7 @@
return map.containsValue((Attrs) value);
}
- public Set<java.util.Map.Entry<String, Attrs>> entrySet() {
+ public Set<java.util.Map.Entry<String,Attrs>> entrySet() {
if (map == null)
return EMPTY.entrySet();
@@ -65,7 +66,8 @@
}
@SuppressWarnings("cast")
- @Deprecated public Attrs get(Object key) {
+ @Deprecated
+ public Attrs get(Object key) {
assert key instanceof String;
if (map == null)
return null;
@@ -96,28 +98,30 @@
assert value != null;
if (map == null)
- map = new LinkedHashMap<String, Attrs>();
+ map = new LinkedHashMap<String,Attrs>();
return map.put(key, value);
}
- public void putAll(Map<? extends String, ? extends Attrs> map) {
+ public void putAll(Map< ? extends String, ? extends Attrs> map) {
if (this.map == null) {
if (map.isEmpty())
return;
- this.map = new LinkedHashMap<String, Attrs>();
+ this.map = new LinkedHashMap<String,Attrs>();
}
this.map.putAll(map);
}
+
public void putAllIfAbsent(Map<String, ? extends Attrs> map) {
- for(Map.Entry<String, ? extends Attrs> entry : map.entrySet() ) {
- if ( !containsKey(entry.getKey()))
+ for (Map.Entry<String, ? extends Attrs> entry : map.entrySet()) {
+ if (!containsKey(entry.getKey()))
put(entry.getKey(), entry.getValue());
}
}
@SuppressWarnings("cast")
- @Deprecated public Attrs remove(Object var0) {
+ @Deprecated
+ public Attrs remove(Object var0) {
assert var0 instanceof String;
if (map == null)
return null;
@@ -152,7 +156,7 @@
public void append(StringBuilder sb) {
String del = "";
- for (Map.Entry<String, Attrs> s : entrySet()) {
+ for (Map.Entry<String,Attrs> s : entrySet()) {
sb.append(del);
sb.append(s.getKey());
if (!s.getValue().isEmpty()) {
@@ -168,12 +172,11 @@
public boolean equals(Object other) {
return super.equals(other);
}
-
+
@Deprecated
public int hashCode() {
return super.hashCode();
}
-
public boolean isEqual(Parameters other) {
if (this == other)
@@ -197,7 +200,7 @@
return true;
}
- public Map<String,? extends Map<String,String>> asMapMap() {
+ public Map<String, ? extends Map<String,String>> asMapMap() {
return this;
}
}
diff --git a/bundleplugin/src/main/java/aQute/libg/log/Logger.java b/bundleplugin/src/main/java/aQute/libg/log/Logger.java
index bb87707..05d869f 100755
--- a/bundleplugin/src/main/java/aQute/libg/log/Logger.java
+++ b/bundleplugin/src/main/java/aQute/libg/log/Logger.java
@@ -2,15 +2,18 @@
import java.util.*;
-
public interface Logger {
- void error(String s, Object ... args);
- void warning(String s, Object ... args);
- void progress(String s, Object ... args);
-
+ void error(String s, Object... args);
+
+ void warning(String s, Object... args);
+
+ void progress(String s, Object... args);
+
List<String> getWarnings();
+
List<String> getErrors();
+
List<String> getProgress();
-
+
boolean isPedantic();
}
diff --git a/bundleplugin/src/main/java/aQute/libg/map/MAP.java b/bundleplugin/src/main/java/aQute/libg/map/MAP.java
index 41c588b..e4776f7 100644
--- a/bundleplugin/src/main/java/aQute/libg/map/MAP.java
+++ b/bundleplugin/src/main/java/aQute/libg/map/MAP.java
@@ -3,42 +3,40 @@
import java.util.*;
/**
- * Easy way to build a map:
- *
- * Map<String,Integer> s = MAP.$("a",2).$("b",3);
- *
+ * Easy way to build a map: Map<String,Integer> s = MAP.$("a",2).$("b",3);
*/
public class MAP {
- static public class MAPX<K, V> extends LinkedHashMap<K, V> {
+ static public class MAPX<K, V> extends LinkedHashMap<K,V> {
private static final long serialVersionUID = 1L;
- public MAPX<K, V> $(K key, V value) {
+
+ public MAPX<K,V> $(K key, V value) {
put(key, value);
return this;
}
- public MAPX<K, V> $(Map<K,V> all) {
+ public MAPX<K,V> $(Map<K,V> all) {
putAll(all);
return this;
}
+
public Hashtable<K,V> asHashtable() {
return new Hashtable<K,V>(this);
}
}
- public static <Kx, Vx> MAPX<Kx, Vx> $(Kx key, Vx value) {
- MAPX<Kx, Vx> map = new MAPX<Kx, Vx>();
+ public static <Kx, Vx> MAPX<Kx,Vx> $(Kx key, Vx value) {
+ MAPX<Kx,Vx> map = new MAPX<Kx,Vx>();
map.put(key, value);
return map;
}
-
-
- public <K,V> Map<K,V> dictionary(Dictionary<K,V> dict ) {
- Map<K,V> map = new LinkedHashMap<K, V>();
- for ( Enumeration<K> e = dict.keys(); e.hasMoreElements(); ) {
+
+ public <K, V> Map<K,V> dictionary(Dictionary<K,V> dict) {
+ Map<K,V> map = new LinkedHashMap<K,V>();
+ for (Enumeration<K> e = dict.keys(); e.hasMoreElements();) {
K k = e.nextElement();
V v = dict.get(k);
- map.put(k,v);
+ map.put(k, v);
}
return map;
}
diff --git a/bundleplugin/src/main/java/aQute/libg/qtokens/QuotedTokenizer.java b/bundleplugin/src/main/java/aQute/libg/qtokens/QuotedTokenizer.java
index 58ea539..c8dcb41 100755
--- a/bundleplugin/src/main/java/aQute/libg/qtokens/QuotedTokenizer.java
+++ b/bundleplugin/src/main/java/aQute/libg/qtokens/QuotedTokenizer.java
@@ -13,40 +13,41 @@
String peek;
char separator;
- public QuotedTokenizer(String string, String separators, boolean returnTokens ) {
- if ( string == null )
+ public QuotedTokenizer(String string, String separators, boolean returnTokens) {
+ if (string == null)
throw new IllegalArgumentException("string argument must be not null");
this.string = string;
this.separators = separators;
this.returnTokens = returnTokens;
}
+
public QuotedTokenizer(String string, String separators) {
- this(string,separators,false);
+ this(string, separators, false);
}
public String nextToken(String separators) {
separator = 0;
- if ( peek != null ) {
+ if (peek != null) {
String tmp = peek;
peek = null;
return tmp;
}
-
- if ( index == string.length())
+
+ if (index == string.length())
return null;
-
+
StringBuilder sb = new StringBuilder();
while (index < string.length()) {
char c = string.charAt(index++);
- if ( Character.isWhitespace(c)) {
- if ( index == string.length())
+ if (Character.isWhitespace(c)) {
+ if (index == string.length())
break;
sb.append(c);
continue;
}
-
+
if (separators.indexOf(c) >= 0) {
if (returnTokens)
peek = Character.toString(c);
@@ -66,7 +67,7 @@
}
}
String result = sb.toString().trim();
- if ( result.length()==0 && index==string.length())
+ if (result.length() == 0 && index == string.length())
return null;
return result;
}
@@ -81,8 +82,7 @@
c = string.charAt(index++);
if (c == quote)
break;
- if (c == '\\' && index < string.length()
- && string.charAt(index + 1) == quote)
+ if (c == '\\' && index < string.length() && string.charAt(index + 1) == quote)
c = string.charAt(index++);
sb.append(c);
}
@@ -92,22 +92,24 @@
return getTokens(0);
}
- private String [] getTokens(int cnt){
+ private String[] getTokens(int cnt) {
String token = nextToken();
- if ( token == null )
+ if (token == null)
return new String[cnt];
-
- String result[] = getTokens(cnt+1);
- result[cnt]=token;
+
+ String result[] = getTokens(cnt + 1);
+ result[cnt] = token;
return result;
}
- public char getSeparator() { return separator; }
-
+ public char getSeparator() {
+ return separator;
+ }
+
public List<String> getTokenSet() {
List<String> list = Create.list();
String token = nextToken();
- while ( token != null ) {
+ while (token != null) {
list.add(token);
token = nextToken();
}
diff --git a/bundleplugin/src/main/java/aQute/libg/reporter/Message.java b/bundleplugin/src/main/java/aQute/libg/reporter/Message.java
new file mode 100644
index 0000000..28386c0
--- /dev/null
+++ b/bundleplugin/src/main/java/aQute/libg/reporter/Message.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) OSGi Alliance (2012). All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package aQute.libg.reporter;
+
+public @interface Message {
+ String value();
+}
diff --git a/bundleplugin/src/main/java/aQute/libg/reporter/Messages.java b/bundleplugin/src/main/java/aQute/libg/reporter/Messages.java
new file mode 100644
index 0000000..504c10a
--- /dev/null
+++ b/bundleplugin/src/main/java/aQute/libg/reporter/Messages.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) OSGi Alliance (2012). All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package aQute.libg.reporter;
+
+import java.io.*;
+
+public interface Messages {
+ static public class ERROR {}
+
+ static public class WARNING {}
+
+ ERROR NoSuchFile_(File f);
+
+ ERROR Unexpected_Error_(String context, Exception e);
+
+}
diff --git a/bundleplugin/src/main/java/aQute/libg/reporter/Reporter.java b/bundleplugin/src/main/java/aQute/libg/reporter/Reporter.java
index c6179af..1ad0c31 100755
--- a/bundleplugin/src/main/java/aQute/libg/reporter/Reporter.java
+++ b/bundleplugin/src/main/java/aQute/libg/reporter/Reporter.java
@@ -2,14 +2,20 @@
import java.util.*;
-
public interface Reporter {
- void error(String s, Object ... args);
- void warning(String s, Object ... args);
- void progress(String s, Object ... args);
- void trace(String s, Object ... args);
+ void error(String s, Object... args);
+
+ void warning(String s, Object... args);
+
+ void progress(String s, Object... args);
+
+ void trace(String s, Object... args);
+
List<String> getWarnings();
+
List<String> getErrors();
-
+
boolean isPedantic();
+
+ boolean isExceptions();
}
diff --git a/bundleplugin/src/main/java/aQute/libg/reporter/ReporterAdapter.java b/bundleplugin/src/main/java/aQute/libg/reporter/ReporterAdapter.java
index 249b776..676fb1b 100644
--- a/bundleplugin/src/main/java/aQute/libg/reporter/ReporterAdapter.java
+++ b/bundleplugin/src/main/java/aQute/libg/reporter/ReporterAdapter.java
@@ -8,7 +8,6 @@
/**
* Mainly used for testing where reporters are needed.
- *
*/
public class ReporterAdapter implements Reporter {
final List<String> errors = new ArrayList<String>();
@@ -74,7 +73,7 @@
errors.add(e);
trace("ERROR: %s", e);
if (isExceptions() || isTrace())
- if ( t instanceof InvocationTargetException )
+ if (t instanceof InvocationTargetException)
t.getCause().printStackTrace(System.err);
else
t.printStackTrace(System.err);
@@ -89,14 +88,14 @@
public void progress(String s, Object... args) {
if (out != null) {
out.format(s, args);
- if ( !s.endsWith("\n"))
+ if (!s.endsWith("\n"))
out.format("\n");
}
}
public void trace(String s, Object... args) {
if (trace && out != null) {
- out.format("# "+s+"\n", args);
+ out.format("# " + s + "\n", args);
out.flush();
}
}
@@ -172,8 +171,8 @@
void report(String title, Collection<String> list, Formatter f) {
if (list.isEmpty())
return;
- f.format(title + (list.size() > 1 ? "s" : "")+"\n");
- int n=0;
+ f.format(title + (list.size() > 1 ? "s" : "") + "\n");
+ int n = 0;
for (String s : list) {
f.format("%3s. %s\n", n++, s);
}
diff --git a/bundleplugin/src/main/java/aQute/libg/reporter/ReporterMessages.java b/bundleplugin/src/main/java/aQute/libg/reporter/ReporterMessages.java
new file mode 100644
index 0000000..8d782cf
--- /dev/null
+++ b/bundleplugin/src/main/java/aQute/libg/reporter/ReporterMessages.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) OSGi Alliance (2012). All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package aQute.libg.reporter;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import aQute.libg.reporter.Messages.ERROR;
+import aQute.libg.reporter.Messages.WARNING;
+
+public class ReporterMessages {
+
+ @SuppressWarnings("unchecked")
+ public static <T> T base(final Reporter reporter, Class<T> messages) {
+ return (T) Proxy.newProxyInstance(messages.getClassLoader(), new Class[] {
+ messages
+ }, new InvocationHandler() {
+
+ public Object invoke(Object target, Method method, Object[] args) throws Throwable {
+ if (reporter.isExceptions()) {
+ for (Object o : args) {
+ if (o instanceof Throwable)
+ ((Throwable) o).printStackTrace();
+ }
+ }
+ String format;
+ Message d = method.getAnnotation(Message.class);
+ if (d == null) {
+ String name = method.getName();
+ StringBuilder sb = new StringBuilder();
+ sb.append(name.charAt(0));
+ for (int i = 1; i < name.length(); i++) {
+ char c = name.charAt(i);
+ switch (c) {
+ case '_' :
+ sb.append(" %s, ");
+ break;
+
+ default :
+ if (Character.isUpperCase(c)) {
+ sb.append(" ");
+ c = Character.toLowerCase(c);
+ }
+ sb.append(c);
+ }
+ }
+ format = sb.toString();
+ } else
+ format = d.value();
+
+ try {
+ if (method.getReturnType() == ERROR.class) {
+ reporter.error(format, args);
+ } else if (method.getReturnType() == WARNING.class) {
+ reporter.warning(format, args);
+ } else
+ reporter.trace(format, args);
+ }
+ catch (IllegalFormatException e) {
+ reporter.error("Formatter failed: %s %s %s", method.getName(), format, Arrays.toString(args));
+ }
+ return null;
+ }
+ });
+ }
+}
diff --git a/bundleplugin/src/main/java/aQute/libg/sax/ContentFilter.java b/bundleplugin/src/main/java/aQute/libg/sax/ContentFilter.java
index 62ca259..e08f4de 100644
--- a/bundleplugin/src/main/java/aQute/libg/sax/ContentFilter.java
+++ b/bundleplugin/src/main/java/aQute/libg/sax/ContentFilter.java
@@ -1,8 +1,9 @@
package aQute.libg.sax;
-import org.xml.sax.ContentHandler;
+import org.xml.sax.*;
public interface ContentFilter extends ContentHandler {
void setParent(ContentHandler parent);
+
ContentHandler getParent();
}
diff --git a/bundleplugin/src/main/java/aQute/libg/sax/ContentFilterImpl.java b/bundleplugin/src/main/java/aQute/libg/sax/ContentFilterImpl.java
index 7f71568..3bfb6b5 100644
--- a/bundleplugin/src/main/java/aQute/libg/sax/ContentFilterImpl.java
+++ b/bundleplugin/src/main/java/aQute/libg/sax/ContentFilterImpl.java
@@ -1,17 +1,14 @@
package aQute.libg.sax;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
+import org.xml.sax.*;
public class ContentFilterImpl implements ContentFilter {
- private ContentHandler parent;
+ private ContentHandler parent;
public void setParent(ContentHandler parent) {
this.parent = parent;
-
+
}
public ContentHandler getParent() {
@@ -30,8 +27,7 @@
parent.endDocument();
}
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException {
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
parent.startPrefixMapping(prefix, uri);
}
@@ -39,28 +35,23 @@
parent.endPrefixMapping(prefix);
}
- public void startElement(String uri, String localName, String qName,
- Attributes atts) throws SAXException {
+ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
parent.startElement(uri, localName, qName, atts);
}
- public void endElement(String uri, String localName, String qName)
- throws SAXException {
+ public void endElement(String uri, String localName, String qName) throws SAXException {
parent.endElement(uri, localName, qName);
}
- public void characters(char[] ch, int start, int length)
- throws SAXException {
+ public void characters(char[] ch, int start, int length) throws SAXException {
parent.characters(ch, start, length);
}
- public void ignorableWhitespace(char[] ch, int start, int length)
- throws SAXException {
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
parent.ignorableWhitespace(ch, start, length);
}
- public void processingInstruction(String target, String data)
- throws SAXException {
+ public void processingInstruction(String target, String data) throws SAXException {
parent.processingInstruction(target, data);
}
diff --git a/bundleplugin/src/main/java/aQute/libg/sax/SAXElement.java b/bundleplugin/src/main/java/aQute/libg/sax/SAXElement.java
index b7ce35e..0b7e914 100644
--- a/bundleplugin/src/main/java/aQute/libg/sax/SAXElement.java
+++ b/bundleplugin/src/main/java/aQute/libg/sax/SAXElement.java
@@ -1,16 +1,15 @@
package aQute.libg.sax;
-import org.xml.sax.Attributes;
+import org.xml.sax.*;
public class SAXElement {
- private final String uri;
- private final String localName;
- private final String qName;
- private final Attributes atts;
+ private final String uri;
+ private final String localName;
+ private final String qName;
+ private final Attributes atts;
- public SAXElement(String uri, String localName, String qName,
- Attributes atts) {
+ public SAXElement(String uri, String localName, String qName, Attributes atts) {
this.uri = uri;
this.localName = localName;
this.qName = qName;
diff --git a/bundleplugin/src/main/java/aQute/libg/sax/SAXUtil.java b/bundleplugin/src/main/java/aQute/libg/sax/SAXUtil.java
index 87b058e..ab7b470 100644
--- a/bundleplugin/src/main/java/aQute/libg/sax/SAXUtil.java
+++ b/bundleplugin/src/main/java/aQute/libg/sax/SAXUtil.java
@@ -1,29 +1,28 @@
package aQute.libg.sax;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.transform.Result;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.parsers.*;
+import javax.xml.transform.*;
+import javax.xml.transform.sax.*;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.XMLReader;
+import org.xml.sax.*;
public class SAXUtil {
-
+
public static XMLReader buildPipeline(Result output, ContentFilter... filters) throws Exception {
SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
TransformerHandler handler = factory.newTransformerHandler();
handler.setResult(output);
-
+
ContentHandler last = handler;
- if (filters != null) for (ContentFilter filter : filters) {
- filter.setParent(last);
- last = filter;
- }
+ if (filters != null)
+ for (ContentFilter filter : filters) {
+ filter.setParent(last);
+ last = filter;
+ }
XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
reader.setContentHandler(last);
-
+
return reader;
}
-
+
}
diff --git a/bundleplugin/src/main/java/aQute/libg/sax/filters/ElementSelectionFilter.java b/bundleplugin/src/main/java/aQute/libg/sax/filters/ElementSelectionFilter.java
index 4411db9..3ba7f5a 100644
--- a/bundleplugin/src/main/java/aQute/libg/sax/filters/ElementSelectionFilter.java
+++ b/bundleplugin/src/main/java/aQute/libg/sax/filters/ElementSelectionFilter.java
@@ -1,17 +1,16 @@
package aQute.libg.sax.filters;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
+import org.xml.sax.*;
-import aQute.libg.sax.ContentFilterImpl;
+import aQute.libg.sax.*;
-public abstract class ElementSelectionFilter extends ContentFilterImpl{
-
- int depth = 0;
- int hiddenDepth = -1;
-
+public abstract class ElementSelectionFilter extends ContentFilterImpl {
+
+ int depth = 0;
+ int hiddenDepth = -1;
+
protected abstract boolean select(int depth, String uri, String localName, String qName, Attributes attribs);
-
+
@Override
public final void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
if (hiddenDepth < 0) {
@@ -21,29 +20,31 @@
else
hiddenDepth = 0;
} else {
- hiddenDepth ++;
+ hiddenDepth++;
}
depth++;
}
-
+
@Override
public final void endElement(String uri, String localName, String qName) throws SAXException {
if (hiddenDepth < 0) {
super.endElement(uri, localName, qName);
} else {
- hiddenDepth --;
+ hiddenDepth--;
}
- depth --;
+ depth--;
}
-
+
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
- if (hiddenDepth < 0) super.characters(ch, start, length);
+ if (hiddenDepth < 0)
+ super.characters(ch, start, length);
}
-
+
@Override
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
- if (hiddenDepth < 0) super.ignorableWhitespace(ch, start, length);
+ if (hiddenDepth < 0)
+ super.ignorableWhitespace(ch, start, length);
}
-
+
}
diff --git a/bundleplugin/src/main/java/aQute/libg/sax/filters/MergeContentFilter.java b/bundleplugin/src/main/java/aQute/libg/sax/filters/MergeContentFilter.java
index acf5d12..b0d4df8 100644
--- a/bundleplugin/src/main/java/aQute/libg/sax/filters/MergeContentFilter.java
+++ b/bundleplugin/src/main/java/aQute/libg/sax/filters/MergeContentFilter.java
@@ -1,28 +1,26 @@
package aQute.libg.sax.filters;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
+import org.xml.sax.*;
-import aQute.libg.sax.ContentFilterImpl;
-import aQute.libg.sax.SAXElement;
+import aQute.libg.sax.*;
public class MergeContentFilter extends ContentFilterImpl {
- private int elementDepth = 0;
-
- private final List<SAXElement> rootElements = new LinkedList<SAXElement>();
-
+ private int elementDepth = 0;
+
+ private final List<SAXElement> rootElements = new LinkedList<SAXElement>();
+
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
if (elementDepth++ == 0) {
if (rootElements.isEmpty())
super.startElement(uri, localName, qName, atts);
else if (!rootElements.get(0).getqName().equals(qName))
- throw new SAXException(String.format("Documents have inconsistent root element names: first was %s, current is %s.", rootElements.get(0).getqName(), qName));
+ throw new SAXException(String.format(
+ "Documents have inconsistent root element names: first was %s, current is %s.", rootElements
+ .get(0).getqName(), qName));
rootElements.add(new SAXElement(uri, localName, qName, atts));
} else {
super.startElement(uri, localName, qName, atts);
@@ -35,13 +33,13 @@
super.endElement(uri, localName, qName);
}
}
-
+
@Override
public void processingInstruction(String target, String data) throws SAXException {
if (rootElements.isEmpty())
super.processingInstruction(target, data);
}
-
+
public void closeRootAndDocument() throws SAXException {
if (!rootElements.isEmpty()) {
SAXElement root = rootElements.get(0);
@@ -49,7 +47,7 @@
}
super.endDocument();
}
-
+
public List<SAXElement> getRootElements() {
return Collections.unmodifiableList(rootElements);
}
diff --git a/bundleplugin/src/main/java/aQute/libg/sed/Replacer.java b/bundleplugin/src/main/java/aQute/libg/sed/Replacer.java
index fa181f4..3c02aaf 100644
--- a/bundleplugin/src/main/java/aQute/libg/sed/Replacer.java
+++ b/bundleplugin/src/main/java/aQute/libg/sed/Replacer.java
@@ -1,5 +1,5 @@
package aQute.libg.sed;
public interface Replacer {
- String process(String line);
+ String process(String line);
}
diff --git a/bundleplugin/src/main/java/aQute/libg/sed/Sed.java b/bundleplugin/src/main/java/aQute/libg/sed/Sed.java
index 74f4756..4642c92 100644
--- a/bundleplugin/src/main/java/aQute/libg/sed/Sed.java
+++ b/bundleplugin/src/main/java/aQute/libg/sed/Sed.java
@@ -4,96 +4,98 @@
import java.util.*;
import java.util.regex.*;
+import aQute.lib.io.IO;
+
public class Sed {
- final File file;
- final Replacer macro;
- File output;
- boolean backup = true;
+ final File file;
+ final Replacer macro;
+ File output;
+ boolean backup = true;
- final Map<Pattern, String> replacements = new LinkedHashMap<Pattern, String>();
+ final Map<Pattern,String> replacements = new LinkedHashMap<Pattern,String>();
- public Sed(Replacer macro, File file) {
- assert file.isFile();
- this.file = file;
- this.macro = macro;
- }
-
- public Sed(File file) {
- assert file.isFile();
- this.file = file;
- this.macro = null;
- }
+ public Sed(Replacer macro, File file) {
+ assert file.isFile();
+ this.file = file;
+ this.macro = macro;
+ }
- public void setOutput(File f) {
- output = f;
- }
+ public Sed(File file) {
+ assert file.isFile();
+ this.file = file;
+ this.macro = null;
+ }
- public void replace(String pattern, String replacement) {
- replacements.put(Pattern.compile(pattern), replacement);
- }
+ public void setOutput(File f) {
+ output = f;
+ }
- public int doIt() throws IOException {
- int actions = 0;
- BufferedReader brdr = new BufferedReader(new InputStreamReader( new FileInputStream(file),"UTF-8"));
- File out;
- if (output != null)
- out = output;
- else
- out = new File(file.getAbsolutePath() + ".tmp");
- PrintWriter pw = new PrintWriter(new OutputStreamWriter( new FileOutputStream(out),"UTF-8"));
- try {
- String line;
- while ((line = brdr.readLine()) != null) {
- for (Pattern p : replacements.keySet()) {
- String replace = replacements.get(p);
- Matcher m = p.matcher(line);
+ public void replace(String pattern, String replacement) {
+ replacements.put(Pattern.compile(pattern), replacement);
+ }
- StringBuffer sb = new StringBuffer();
- while (m.find()) {
- String tmp = setReferences(m, replace);
- if ( macro != null)
- tmp = Matcher.quoteReplacement(macro.process(tmp));
- m.appendReplacement(sb, tmp);
- actions++;
- }
- m.appendTail(sb);
+ public int doIt() throws IOException {
+ int actions = 0;
+ BufferedReader brdr = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
+ File out;
+ if (output != null)
+ out = output;
+ else
+ out = new File(file.getAbsolutePath() + ".tmp");
+ PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(out), "UTF-8"));
+ try {
+ String line;
+ while ((line = brdr.readLine()) != null) {
+ for (Pattern p : replacements.keySet()) {
+ String replace = replacements.get(p);
+ Matcher m = p.matcher(line);
- line = sb.toString();
- }
- pw.println(line);
- }
- pw.close();
- if (output == null) {
- if ( backup ) {
- File bak = new File(file.getAbsolutePath() + ".bak");
- file.renameTo(bak);
- }
- out.renameTo(file);
- }
+ StringBuffer sb = new StringBuffer();
+ while (m.find()) {
+ String tmp = setReferences(m, replace);
+ if (macro != null)
+ tmp = Matcher.quoteReplacement(macro.process(tmp));
+ m.appendReplacement(sb, tmp);
+ actions++;
+ }
+ m.appendTail(sb);
+
+ line = sb.toString();
+ }
+ pw.println(line);
+ }
} finally {
- brdr.close();
- pw.close();
+ brdr.close();
+ pw.close();
}
- return actions;
- }
+
+ if (output == null) {
+ if (backup) {
+ File bak = new File(file.getAbsolutePath() + ".bak");
+ IO.rename(file, bak);
+ }
+ IO.rename(out, file);
+ }
+
+ return actions;
+ }
+
+ private String setReferences(Matcher m, String replace) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < replace.length(); i++) {
+ char c = replace.charAt(i);
+ if (c == '$' && i < replace.length() - 1 && Character.isDigit(replace.charAt(i + 1))) {
+ int n = replace.charAt(i + 1) - '0';
+ if (n <= m.groupCount())
+ sb.append(m.group(n));
+ i++;
+ } else
+ sb.append(c);
+ }
+ return sb.toString();
+ }
- private String setReferences(Matcher m, String replace) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < replace.length(); i++) {
- char c = replace.charAt(i);
- if (c == '$' && i < replace.length() - 1
- && Character.isDigit(replace.charAt(i + 1))) {
- int n = replace.charAt(i + 1) - '0';
- if ( n <= m.groupCount() )
- sb.append(m.group(n));
- i++;
- } else
- sb.append(c);
- }
- return sb.toString();
- }
-
- public void setBackup(boolean b) {
- this.backup=b;
- }
+ public void setBackup(boolean b) {
+ this.backup = b;
+ }
}
diff --git a/bundleplugin/src/main/java/aQute/libg/tarjan/Tarjan.java b/bundleplugin/src/main/java/aQute/libg/tarjan/Tarjan.java
index 3d05b76..cef8b23 100644
--- a/bundleplugin/src/main/java/aQute/libg/tarjan/Tarjan.java
+++ b/bundleplugin/src/main/java/aQute/libg/tarjan/Tarjan.java
@@ -15,43 +15,42 @@
public Node(T name) {
this.name = name;
}
-
+
public String toString() {
return name + "{" + index + "," + low + "}";
}
}
- private int index = 0;
- private List<Node> stack = new ArrayList<Node>();
+ private int index = 0;
+ private List<Node> stack = new ArrayList<Node>();
private Set<Set<T>> scc = new HashSet<Set<T>>();
- private Node root = new Node(null);
+ private Node root = new Node(null);
-
-// public ArrayList<ArrayList<Node>> tarjan(Node v, AdjacencyList list){
-// v.index = index;
-// v.lowlink = index;
-// index++;
-// stack.add(0, v);
-// for(Edge e : list.getAdjacent(v)){
-// Node n = e.to;
-// if(n.index == -1){
-// tarjan(n, list);
-// v.lowlink = Math.min(v.lowlink, n.lowlink);
-// }else if(stack.contains(n)){
-// v.lowlink = Math.min(v.lowlink, n.index);
-// }
-// }
-// if(v.lowlink == v.index){
-// Node n;
-// ArrayList<Node> component = new ArrayList<Node>();
-// do{
-// n = stack.remove(0);
-// component.add(n);
-// }while(n != v);
-// SCC.add(component);
-// }
-// return SCC;
-// }
+ // public ArrayList<ArrayList<Node>> tarjan(Node v, AdjacencyList list){
+ // v.index = index;
+ // v.lowlink = index;
+ // index++;
+ // stack.add(0, v);
+ // for(Edge e : list.getAdjacent(v)){
+ // Node n = e.to;
+ // if(n.index == -1){
+ // tarjan(n, list);
+ // v.lowlink = Math.min(v.lowlink, n.lowlink);
+ // }else if(stack.contains(n)){
+ // v.lowlink = Math.min(v.lowlink, n.index);
+ // }
+ // }
+ // if(v.lowlink == v.index){
+ // Node n;
+ // ArrayList<Node> component = new ArrayList<Node>();
+ // do{
+ // n = stack.remove(0);
+ // component.add(n);
+ // }while(n != v);
+ // SCC.add(component);
+ // }
+ // return SCC;
+ // }
void tarjan(Node v) {
v.index = index;
@@ -68,7 +67,7 @@
}
}
- if (v!=root && v.low == v.index) {
+ if (v != root && v.low == v.index) {
Set<T> component = new HashSet<T>();
Node n;
do {
@@ -80,7 +79,7 @@
}
Set<Set<T>> getResult(Map<T, ? extends Collection<T>> graph) {
- Map<T, Node> index = new HashMap<T, Node>();
+ Map<T,Node> index = new HashMap<T,Node>();
for (Map.Entry<T, ? extends Collection<T>> entry : graph.entrySet()) {
Node node = getNode(index, entry.getKey());
@@ -92,7 +91,7 @@
return scc;
}
- private Node getNode(Map<T, Node> index, T key) {
+ private Node getNode(Map<T,Node> index, T key) {
Node node = index.get(key);
if (node == null) {
node = new Node(key);
@@ -101,7 +100,7 @@
return node;
}
- public static <T> Collection<? extends Collection<T>> tarjan(Map<T, ? extends Collection<T>> graph) {
+ public static <T> Collection< ? extends Collection<T>> tarjan(Map<T, ? extends Collection<T>> graph) {
Tarjan<T> tarjan = new Tarjan<T>();
return tarjan.getResult(graph);
}
diff --git a/bundleplugin/src/main/java/aQute/libg/tuple/Pair.java b/bundleplugin/src/main/java/aQute/libg/tuple/Pair.java
index efb2298..d86d6c8 100644
--- a/bundleplugin/src/main/java/aQute/libg/tuple/Pair.java
+++ b/bundleplugin/src/main/java/aQute/libg/tuple/Pair.java
@@ -1,9 +1,9 @@
package aQute.libg.tuple;
-public class Pair<A,B> {
- final public A a;
- final public B b;
-
+public class Pair<A, B> {
+ final public A a;
+ final public B b;
+
public Pair(A a, B b) {
this.a = a;
this.b = b;
diff --git a/bundleplugin/src/main/java/aQute/libg/version/Version.java b/bundleplugin/src/main/java/aQute/libg/version/Version.java
index d326ec4..77d21e4 100755
--- a/bundleplugin/src/main/java/aQute/libg/version/Version.java
+++ b/bundleplugin/src/main/java/aQute/libg/version/Version.java
@@ -3,150 +3,148 @@
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");
+ 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 static final Version emptyVersion = LOWEST;
+ public static final Version ONE = new Version(1, 0, 0);
- public Version() {
- this(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, 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, int micro) {
+ this(major, minor, micro, null);
+ }
- public Version(int major, int minor) {
- this(major, minor, 0, null);
- }
+ public Version(int major, int minor) {
+ this(major, minor, 0, null);
+ }
- public Version(int major) {
- this(major, 0, 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);
+ 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;
+ 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;
+ if (m.group(5) != null)
+ micro = Integer.parseInt(m.group(5));
+ else
+ micro = 0;
- qualifier = m.group(7);
- }
+ qualifier = m.group(7);
+ }
- public int getMajor() {
- return major;
- }
+ public int getMajor() {
+ return major;
+ }
- public int getMinor() {
- return minor;
- }
+ public int getMinor() {
+ return minor;
+ }
- public int getMicro() {
- return micro;
- }
+ public int getMicro() {
+ return micro;
+ }
- public String getQualifier() {
- return qualifier;
- }
+ public String getQualifier() {
+ return qualifier;
+ }
- public int compareTo(Version other) {
- if (other == this)
- return 0;
+ public int compareTo(Version other) {
+ if (other == this)
+ return 0;
- Version o = other;
- if (major != o.major)
- return major - o.major;
+ Version o = other;
+ if (major != o.major)
+ return major - o.major;
- if (minor != o.minor)
- return minor - o.minor;
+ if (minor != o.minor)
+ return minor - o.minor;
- if (micro != o.micro)
- return micro - o.micro;
+ if (micro != o.micro)
+ return micro - o.micro;
- int c = 0;
- if (qualifier != null)
- c = 1;
- if (o.qualifier != null)
- c += 2;
+ 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);
- }
+ 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 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 boolean equals(Object ot) {
+ if (!(ot instanceof Version))
+ return false;
- public int hashCode() {
- return major * 97 ^ minor * 13 ^ micro
- + (qualifier == null ? 97 : qualifier.hashCode());
- }
+ return compareTo((Version) ot) == 0;
+ }
- 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) {
+ 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;
}
@@ -158,9 +156,9 @@
return new Version(version);
- }
-
- public Version getWithoutQualifier() {
- return new Version(major,minor,micro);
- }
+ }
+
+ public Version getWithoutQualifier() {
+ return new Version(major, minor, micro);
+ }
}
diff --git a/bundleplugin/src/main/java/aQute/libg/version/VersionRange.java b/bundleplugin/src/main/java/aQute/libg/version/VersionRange.java
index 46f9e94..3e00c76 100755
--- a/bundleplugin/src/main/java/aQute/libg/version/VersionRange.java
+++ b/bundleplugin/src/main/java/aQute/libg/version/VersionRange.java
@@ -9,9 +9,8 @@
char start = '[';
char end = ']';
- static Pattern RANGE = Pattern.compile("(\\(|\\[)\\s*(" +
- Version.VERSION_STRING + ")\\s*,\\s*(" +
- Version.VERSION_STRING + ")\\s*(\\)|\\])");
+ static Pattern RANGE = Pattern.compile("(\\(|\\[)\\s*(" + Version.VERSION_STRING + ")\\s*,\\s*("
+ + Version.VERSION_STRING + ")\\s*(\\)|\\])");
public VersionRange(String string) {
string = string.trim();
@@ -24,9 +23,7 @@
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);
+ throw new IllegalArgumentException("Low Range is higher than High Range: " + low + "-" + high);
} else
high = low = new Version(string);
@@ -66,8 +63,8 @@
}
public boolean includes(Version v) {
- if ( !isRange() ) {
- return low.compareTo(v) <=0;
+ if (!isRange()) {
+ return low.compareTo(v) <= 0;
}
if (includeLow()) {
if (v.compareTo(low) < 0)
@@ -80,17 +77,17 @@
return false;
} else if (v.compareTo(high) >= 0)
return false;
-
+
return true;
}
-
- public Iterable<Version> filter( final Iterable<Version> versions) {
+
+ public Iterable<Version> filter(final Iterable<Version> versions) {
List<Version> list = new ArrayList<Version>();
- for ( Version v : versions) {
- if ( includes(v))
+ 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/libg/xslt/Transform.java b/bundleplugin/src/main/java/aQute/libg/xslt/Transform.java
index ea0fcd0..4d5835b 100644
--- a/bundleplugin/src/main/java/aQute/libg/xslt/Transform.java
+++ b/bundleplugin/src/main/java/aQute/libg/xslt/Transform.java
@@ -9,36 +9,35 @@
import javax.xml.transform.stream.*;
public class Transform {
- static TransformerFactory transformerFactory = TransformerFactory
- .newInstance();
+ static TransformerFactory transformerFactory = TransformerFactory.newInstance();
- static Map<URL, Templates> cache = new ConcurrentHashMap<URL, Templates>();
+ static Map<URL,Templates> cache = new ConcurrentHashMap<URL,Templates>();
- public static void transform(TransformerFactory transformerFactory, URL xslt, InputStream in, OutputStream out)
- throws Exception {
- if ( xslt == null )
- throw new IllegalArgumentException("No source template specified");
-
- Templates templates = cache.get(xslt);
- if (templates == null) {
- InputStream xsltIn = xslt.openStream();
- try {
- templates = transformerFactory
- .newTemplates(new StreamSource(xsltIn));
+ public static void transform(TransformerFactory transformerFactory, URL xslt, InputStream in, OutputStream out)
+ throws Exception {
+ if (xslt == null)
+ throw new IllegalArgumentException("No source template specified");
- cache.put(xslt, templates);
- } finally {
- in.close();
- }
- }
- Result xmlResult = new StreamResult(out);
- Source xmlSource = new StreamSource(in);
- Transformer t = templates.newTransformer();
- t.transform(xmlSource, xmlResult);
- out.flush();
- }
+ Templates templates = cache.get(xslt);
+ if (templates == null) {
+ InputStream xsltIn = xslt.openStream();
+ try {
+ templates = transformerFactory.newTemplates(new StreamSource(xsltIn));
- public static void transform(URL xslt, InputStream in, OutputStream out) throws Exception {
- transform(transformerFactory,xslt, in, out);
- }
+ cache.put(xslt, templates);
+ }
+ finally {
+ in.close();
+ }
+ }
+ Result xmlResult = new StreamResult(out);
+ Source xmlSource = new StreamSource(in);
+ Transformer t = templates.newTransformer();
+ t.transform(xmlSource, xmlResult);
+ out.flush();
+ }
+
+ public static void transform(URL xslt, InputStream in, OutputStream out) throws Exception {
+ transform(transformerFactory, xslt, in, out);
+ }
}