< prev index next >
test/lib/jdk/test/lib/util/JarUtils.java
Print this page
rev 58207 : 8240235: jdk.test.lib.util.JarUtils updates jar files incorrectly
Reviewed-by: martin, clanger
*** 1,7 ****
/*
! * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 156,166 ****
try (JarFile jf = new JarFile(jarfile.toString())) {
Enumeration<JarEntry> jentries = jf.entries();
while (jentries.hasMoreElements()) {
JarEntry jentry = jentries.nextElement();
if (!names.contains(jentry.getName())) {
! jos.putNextEntry(jentry);
jf.getInputStream(jentry).transferTo(jos);
}
}
}
--- 156,166 ----
try (JarFile jf = new JarFile(jarfile.toString())) {
Enumeration<JarEntry> jentries = jf.entries();
while (jentries.hasMoreElements()) {
JarEntry jentry = jentries.nextElement();
if (!names.contains(jentry.getName())) {
! jos.putNextEntry(copyEntry(jentry));
jf.getInputStream(jentry).transferTo(jos);
}
}
}
*** 289,299 ****
System.out.println(String.format("- Update %s", name));
updateEntry(jos, name, changes.get(name));
changes.remove(name);
} else {
System.out.println(String.format("- Copy %s", name));
! jos.putNextEntry(entry);
srcJarFile.getInputStream(entry).transferTo(jos);
}
}
}
for (Map.Entry<String, Object> e : changes.entrySet()) {
--- 289,299 ----
System.out.println(String.format("- Update %s", name));
updateEntry(jos, name, changes.get(name));
changes.remove(name);
} else {
System.out.println(String.format("- Copy %s", name));
! jos.putNextEntry(copyEntry(entry));
srcJarFile.getInputStream(entry).transferTo(jos);
}
}
}
for (Map.Entry<String, Object> e : changes.entrySet()) {
*** 359,364 ****
--- 359,377 ----
.forEach(entries::add);
}
}
return entries;
}
+
+ private static JarEntry copyEntry(JarEntry e1) {
+ JarEntry e2 = new JarEntry(e1.getName());
+ e2.setMethod(e1.getMethod());
+ e2.setTime(e1.getTime());
+ e2.setComment(e1.getComment());
+ e2.setExtra(e1.getExtra());
+ if (e1.getMethod() == JarEntry.STORED) {
+ e2.setSize(e1.getSize());
+ e2.setCrc(e1.getCrc());
+ }
+ return e2;
+ }
}
< prev index next >