5120N/A/*
5120N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
5120N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5120N/A *
5120N/A * This code is free software; you can redistribute it and/or modify it
5120N/A * under the terms of the GNU General Public License version 2 only, as
5120N/A * published by the Free Software Foundation.
5120N/A *
5120N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5120N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5120N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5120N/A * version 2 for more details (a copy is included in the LICENSE file that
5120N/A * accompanied this code).
5120N/A *
5120N/A * You should have received a copy of the GNU General Public License version
5120N/A * 2 along with this work; if not, write to the Free Software Foundation,
5120N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5120N/A *
5120N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5120N/A * or visit www.oracle.com if you need additional information or have any
5120N/A * questions.
5120N/A */
5120N/A
5120N/A/**
5120N/A * @test
5120N/A * @bug 7175845
5120N/A * @summary jar -uf should not change file permission
5120N/A */
5120N/A
5120N/Aimport java.io.*;
5120N/Aimport java.nio.file.*;
5120N/Aimport java.nio.file.attribute.*;
5120N/Aimport java.util.Set;
5120N/Aimport sun.tools.jar.Main;
5120N/A
5120N/Apublic class UpdateJar {
5120N/A
5120N/A private static void cleanup(String... fnames) throws Throwable {
5120N/A for (String fname : fnames) {
5120N/A Files.deleteIfExists(Paths.get(fname));
5120N/A }
5120N/A }
5120N/A
5120N/A public static void realMain(String[] args) throws Throwable {
5120N/A if (!System.getProperty("os.name").startsWith("Windows")) {
5120N/A String jar = "testUpdateJar.jar";
5120N/A String e0 = "testUpdateJar_entry0.txt";
5120N/A String e1 = "testUpdateJar_entry1.txt";
5120N/A cleanup(jar, e0, e1);
5120N/A try {
5120N/A try (FileOutputStream fos0 = new FileOutputStream(e0);
5120N/A FileOutputStream fos1 = new FileOutputStream(e1)) {
5120N/A fos0.write(0);
5120N/A fos1.write(0);
5120N/A }
5120N/A String[] jarArgs = new String[] {"cfM0", jar, e0};
5120N/A if (!new Main(System.out, System.err, "jar").run(jarArgs)) {
5120N/A fail("Could not create jar file.");
5120N/A }
5120N/A Set<PosixFilePermission> pm = Files.getPosixFilePermissions(Paths.get(jar));
5120N/A jarArgs = new String[] {"uf", jar, e1};
5120N/A if (!new Main(System.out, System.err, "jar").run(jarArgs)) {
5120N/A fail("Could not create jar file.");
5120N/A }
5120N/A equal(pm, Files.getPosixFilePermissions(Paths.get(jar)));
5120N/A } finally {
5120N/A cleanup(jar, e0, e1);
5120N/A }
5120N/A }
5120N/A }
5120N/A
5120N/A //--------------------- Infrastructure ---------------------------
5120N/A static volatile int passed = 0, failed = 0;
5120N/A static void pass() {passed++;}
5120N/A static void fail() {failed++; Thread.dumpStack();}
5120N/A static void fail(String msg) {System.out.println(msg); fail();}
5120N/A static void unexpected(Throwable t) {failed++; t.printStackTrace();}
5120N/A static void check(boolean cond) {if (cond) pass(); else fail();}
5120N/A static void equal(Object x, Object y) {
5120N/A if (x == null ? y == null : x.equals(y)) pass();
5120N/A else fail(x + " not equal to " + y);}
5120N/A public static void main(String[] args) throws Throwable {
5120N/A try {realMain(args);} catch (Throwable t) {unexpected(t);}
5120N/A System.out.println("\nPassed = " + passed + " failed = " + failed);
5120N/A if (failed > 0) throw new AssertionError("Some tests failed");}
5120N/A}