7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 7175845 27 * @modules jdk.jartool/sun.tools.jar 28 * @summary jar -uf should not change file permission 29 */ 30 31 import java.io.*; 32 import java.nio.file.*; 33 import java.nio.file.attribute.*; 34 import java.util.Set; 35 import sun.tools.jar.Main; 36 37 public class UpdateJar { 38 39 private static void cleanup(String... fnames) throws Throwable { 40 for (String fname : fnames) { 41 Files.deleteIfExists(Paths.get(fname)); 42 } 43 } 44 45 public static void realMain(String[] args) throws Throwable { 46 if (!System.getProperty("os.name").startsWith("Windows")) { 47 String jar = "testUpdateJar.jar"; 48 String e0 = "testUpdateJar_entry0.txt"; 49 String e1 = "testUpdateJar_entry1.txt"; 50 cleanup(jar, e0, e1); 51 try { 52 try (FileOutputStream fos0 = new FileOutputStream(e0); 53 FileOutputStream fos1 = new FileOutputStream(e1)) { 54 fos0.write(0); 55 fos1.write(0); 56 } 57 String[] jarArgs = new String[] {"cfM0", jar, e0}; 58 if (!new Main(System.out, System.err, "jar").run(jarArgs)) { 59 fail("Could not create jar file."); 60 } 61 Set<PosixFilePermission> pm = Files.getPosixFilePermissions(Paths.get(jar)); 62 jarArgs = new String[] {"uf", jar, e1}; 63 if (!new Main(System.out, System.err, "jar").run(jarArgs)) { 64 fail("Could not create jar file."); 65 } 66 equal(pm, Files.getPosixFilePermissions(Paths.get(jar))); 67 } finally { 68 cleanup(jar, e0, e1); 69 } 70 } 71 } 72 73 //--------------------- Infrastructure --------------------------- 74 static volatile int passed = 0, failed = 0; 75 static void pass() {passed++;} 76 static void fail() {failed++; Thread.dumpStack();} 77 static void fail(String msg) {System.out.println(msg); fail();} 78 static void unexpected(Throwable t) {failed++; t.printStackTrace();} 79 static void check(boolean cond) {if (cond) pass(); else fail();} 80 static void equal(Object x, Object y) { 81 if (x == null ? y == null : x.equals(y)) pass(); 82 else fail(x + " not equal to " + y);} 83 public static void main(String[] args) throws Throwable { | 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 7175845 27 * @modules jdk.jartool 28 * @summary jar -uf should not change file permission 29 */ 30 31 import java.io.*; 32 import java.nio.file.*; 33 import java.nio.file.attribute.*; 34 import java.util.Set; 35 import java.util.spi.ToolProvider; 36 37 public class UpdateJar { 38 private static final ToolProvider JAR_TOOL = 39 ToolProvider.findFirst("jar").get(); 40 41 private static void cleanup(String... fnames) throws Throwable { 42 for (String fname : fnames) { 43 Files.deleteIfExists(Paths.get(fname)); 44 } 45 } 46 47 public static void realMain(String[] args) throws Throwable { 48 if (!System.getProperty("os.name").startsWith("Windows")) { 49 String jar = "testUpdateJar.jar"; 50 String e0 = "testUpdateJar_entry0.txt"; 51 String e1 = "testUpdateJar_entry1.txt"; 52 cleanup(jar, e0, e1); 53 try { 54 try (FileOutputStream fos0 = new FileOutputStream(e0); 55 FileOutputStream fos1 = new FileOutputStream(e1)) { 56 fos0.write(0); 57 fos1.write(0); 58 } 59 String[] jarArgs = new String[] {"cfM0", jar, e0}; 60 if (JAR_TOOL.run(System.out, System.err, jarArgs) != 0) { 61 fail("Could not create jar file."); 62 } 63 Set<PosixFilePermission> pm = Files.getPosixFilePermissions(Paths.get(jar)); 64 jarArgs = new String[] {"uf", jar, e1}; 65 if (JAR_TOOL.run(System.out, System.err, jarArgs) != 0) { 66 fail("Could not create jar file."); 67 } 68 equal(pm, Files.getPosixFilePermissions(Paths.get(jar))); 69 } finally { 70 cleanup(jar, e0, e1); 71 } 72 } 73 } 74 75 //--------------------- Infrastructure --------------------------- 76 static volatile int passed = 0, failed = 0; 77 static void pass() {passed++;} 78 static void fail() {failed++; Thread.dumpStack();} 79 static void fail(String msg) {System.out.println(msg); fail();} 80 static void unexpected(Throwable t) {failed++; t.printStackTrace();} 81 static void check(boolean cond) {if (cond) pass(); else fail();} 82 static void equal(Object x, Object y) { 83 if (x == null ? y == null : x.equals(y)) pass(); 84 else fail(x + " not equal to " + y);} 85 public static void main(String[] args) throws Throwable { |