Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/tools/jar/UpdateJar.java
38833 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 717584526* @summary jar -uf should not change file permission27*/2829import java.io.*;30import java.nio.file.*;31import java.nio.file.attribute.*;32import java.util.Set;33import sun.tools.jar.Main;3435public class UpdateJar {3637private static void cleanup(String... fnames) throws Throwable {38for (String fname : fnames) {39Files.deleteIfExists(Paths.get(fname));40}41}4243public static void realMain(String[] args) throws Throwable {44if (!System.getProperty("os.name").startsWith("Windows")) {45String jar = "testUpdateJar.jar";46String e0 = "testUpdateJar_entry0.txt";47String e1 = "testUpdateJar_entry1.txt";48cleanup(jar, e0, e1);49try {50try (FileOutputStream fos0 = new FileOutputStream(e0);51FileOutputStream fos1 = new FileOutputStream(e1)) {52fos0.write(0);53fos1.write(0);54}55String[] jarArgs = new String[] {"cfM0", jar, e0};56if (!new Main(System.out, System.err, "jar").run(jarArgs)) {57fail("Could not create jar file.");58}59Set<PosixFilePermission> pm = Files.getPosixFilePermissions(Paths.get(jar));60jarArgs = new String[] {"uf", jar, e1};61if (!new Main(System.out, System.err, "jar").run(jarArgs)) {62fail("Could not create jar file.");63}64equal(pm, Files.getPosixFilePermissions(Paths.get(jar)));65} finally {66cleanup(jar, e0, e1);67}68}69}7071//--------------------- Infrastructure ---------------------------72static volatile int passed = 0, failed = 0;73static void pass() {passed++;}74static void fail() {failed++; Thread.dumpStack();}75static void fail(String msg) {System.out.println(msg); fail();}76static void unexpected(Throwable t) {failed++; t.printStackTrace();}77static void check(boolean cond) {if (cond) pass(); else fail();}78static void equal(Object x, Object y) {79if (x == null ? y == null : x.equals(y)) pass();80else fail(x + " not equal to " + y);}81public static void main(String[] args) throws Throwable {82try {realMain(args);} catch (Throwable t) {unexpected(t);}83System.out.println("\nPassed = " + passed + " failed = " + failed);84if (failed > 0) throw new AssertionError("Some tests failed");}85}868788