Merge "Remove EWOULDBLOCK from libcore."
diff --git a/luni/src/main/java/java/util/jar/InitManifest.java b/luni/src/main/java/java/util/jar/InitManifest.java
index ade4790..c82a1e4 100644
--- a/luni/src/main/java/java/util/jar/InitManifest.java
+++ b/luni/src/main/java/java/util/jar/InitManifest.java
@@ -37,8 +37,15 @@
private final UnsafeByteSequence valueBuffer = new UnsafeByteSequence(80);
private int consecutiveLineBreaks = 0;
- InitManifest(byte[] buf, Attributes main) throws IOException {
+ InitManifest(byte[] buf, Attributes main, Attributes.Name ver) throws IOException {
this.buf = buf;
+
+ // check a version attribute
+ if (!readHeader() || (ver != null && !name.equals(ver))) {
+ throw new IOException("Missing version attribute: " + ver);
+ }
+
+ main.put(name, value);
while (readHeader()) {
main.put(name, value);
}
diff --git a/luni/src/main/java/java/util/jar/JarVerifier.java b/luni/src/main/java/java/util/jar/JarVerifier.java
index 81938fa..dc37b72 100644
--- a/luni/src/main/java/java/util/jar/JarVerifier.java
+++ b/luni/src/main/java/java/util/jar/JarVerifier.java
@@ -314,17 +314,12 @@
Attributes attributes = new Attributes();
HashMap<String, Attributes> entries = new HashMap<String, Attributes>();
try {
- InitManifest im = new InitManifest(sfBytes, attributes);
+ InitManifest im = new InitManifest(sfBytes, attributes, Attributes.Name.SIGNATURE_VERSION);
im.initEntries(entries, null);
} catch (IOException e) {
return;
}
- // Do we actually have any signatures to look at?
- if (entries.get(Attributes.Name.SIGNATURE_VERSION) == null) {
- return;
- }
-
boolean createdBySigntool = false;
String createdBy = attributes.getValue("Created-By");
if (createdBy != null) {
diff --git a/luni/src/main/java/java/util/jar/Manifest.java b/luni/src/main/java/java/util/jar/Manifest.java
index 723aa99..d46aea3 100644
--- a/luni/src/main/java/java/util/jar/Manifest.java
+++ b/luni/src/main/java/java/util/jar/Manifest.java
@@ -174,10 +174,11 @@
}
/**
- * Writes this {@code Manifest}'s name/attributes pairs to the given {@code OutputStream}.
- * The {@code MANIFEST_VERSION} or {@code SIGNATURE_VERSION} attribute must be set before
- * calling this method, or no attributes will be written.
+ * Writes out the attribute information of the receiver to the specified
+ * {@code OutputStream}.
*
+ * @param os
+ * The {@code OutputStream} to write to.
* @throws IOException
* If an error occurs writing the {@code Manifest}.
*/
@@ -213,7 +214,9 @@
buf[buf.length - 1] = '\n';
}
- InitManifest im = new InitManifest(buf, mainAttributes);
+ // Attributes.Name.MANIFEST_VERSION is not used for
+ // the second parameter for RI compatibility
+ InitManifest im = new InitManifest(buf, mainAttributes, null);
mainEnd = im.getPos();
im.initEntries(entries, chunks);
}
@@ -305,18 +308,13 @@
CharsetEncoder encoder = Charsets.UTF_8.newEncoder();
ByteBuffer buffer = ByteBuffer.allocate(LINE_LENGTH_LIMIT);
- Attributes.Name versionName = Attributes.Name.MANIFEST_VERSION;
- String version = manifest.mainAttributes.getValue(versionName);
- if (version == null) {
- versionName = Attributes.Name.SIGNATURE_VERSION;
- version = manifest.mainAttributes.getValue(versionName);
- }
+ String version = manifest.mainAttributes.getValue(Attributes.Name.MANIFEST_VERSION);
if (version != null) {
- writeEntry(out, versionName, version, encoder, buffer);
+ writeEntry(out, Attributes.Name.MANIFEST_VERSION, version, encoder, buffer);
Iterator<?> entries = manifest.mainAttributes.keySet().iterator();
while (entries.hasNext()) {
Attributes.Name name = (Attributes.Name) entries.next();
- if (!name.equals(versionName)) {
+ if (!name.equals(Attributes.Name.MANIFEST_VERSION)) {
writeEntry(out, name, manifest.mainAttributes.getValue(name), encoder, buffer);
}
}
@@ -326,11 +324,11 @@
while (i.hasNext()) {
String key = i.next();
writeEntry(out, NAME_ATTRIBUTE, key, encoder, buffer);
- Attributes attributes = manifest.entries.get(key);
- Iterator<?> entries = attributes.keySet().iterator();
+ Attributes attrib = manifest.entries.get(key);
+ Iterator<?> entries = attrib.keySet().iterator();
while (entries.hasNext()) {
Attributes.Name name = (Attributes.Name) entries.next();
- writeEntry(out, name, attributes.getValue(name), encoder, buffer);
+ writeEntry(out, name, attrib.getValue(name), encoder, buffer);
}
out.write(LINE_SEPARATOR);
}
diff --git a/luni/src/test/java/libcore/java/util/jar/OldManifestTest.java b/luni/src/test/java/libcore/java/util/jar/OldManifestTest.java
index e5c3bdb..9552aef 100644
--- a/luni/src/test/java/libcore/java/util/jar/OldManifestTest.java
+++ b/luni/src/test/java/libcore/java/util/jar/OldManifestTest.java
@@ -141,44 +141,4 @@
assertTrue(manifest1.equals(manifest2));
}
- public void test_write_no_version() throws Exception {
- // If you write a manifest with no MANIFEST_VERSION, your attributes don't get written out.
- assertEquals(null, doRoundTrip(null));
- // But they do if you supply a MANIFEST_VERSION.
- assertEquals("image/pr0n", doRoundTrip(Attributes.Name.MANIFEST_VERSION));
- assertEquals("image/pr0n", doRoundTrip("Signature-Version"));
- assertEquals(null, doRoundTrip("Random-String-Version"));
- }
-
- private String doRoundTrip(Object versionName) throws Exception {
- Manifest m1 = new Manifest();
- m1.getMainAttributes().put(Attributes.Name.CONTENT_TYPE, "image/pr0n");
- if (versionName != null) {
- m1.getMainAttributes().putValue(versionName.toString(), "1.2.3");
- }
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- m1.write(os);
-
- ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
- Manifest m2 = new Manifest();
- m2.read(is);
- return (String) m2.getMainAttributes().get(Attributes.Name.CONTENT_TYPE);
- }
-
- public void test_write_two_versions() throws Exception {
- // It's okay to have two versions.
- Manifest m1 = new Manifest();
- m1.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
- m1.getMainAttributes().put(Attributes.Name.SIGNATURE_VERSION, "2.0");
- m1.getMainAttributes().putValue("Aardvark-Version", "3.0");
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- m1.write(os);
-
- // The Manifest-Version takes precedence,
- // and the Signature-Version gets no special treatment.
- String[] lines = new String(os.toByteArray(), "UTF-8").split("\r\n");
- assertEquals("Manifest-Version: 1.0", lines[0]);
- assertEquals("Aardvark-Version: 3.0", lines[1]);
- assertEquals("Signature-Version: 2.0", lines[2]);
- }
}