Path: blob/master/test/jdk/tools/jar/ReleaseBeforeFiles.java
41144 views
/*1* Copyright (c) 2016, 2017, 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 816723726* @summary test that both old style command line options and new gnu style27* command line options work with the --release option whether or28* not the --release option is preceded by a file name.29* @library /test/lib30* @modules jdk.jartool/sun.tools.jar31* @build jdk.test.lib.Platform32* jdk.test.lib.util.FileUtils33* @run testng ReleaseBeforeFiles34*/3536import org.testng.Assert;37import org.testng.annotations.AfterMethod;38import org.testng.annotations.BeforeMethod;39import org.testng.annotations.Test;4041import java.io.IOException;42import java.io.UncheckedIOException;43import java.nio.file.Files;44import java.nio.file.Path;45import java.nio.file.Paths;46import java.util.Arrays;47import java.util.stream.Stream;4849import jdk.test.lib.util.FileUtils;5051public class ReleaseBeforeFiles {52private Runnable onCompletion;5354@BeforeMethod55public void reset() {56onCompletion = null;57}5859@AfterMethod60public void run() {61if (onCompletion != null) {62onCompletion.run();63}64}6566@Test // passes before bug fix67public void test1() throws IOException {68mkdir("test1");69touch("test1/testfile1");70jar("cf test.jar --release 9 test1");71jar("tf test.jar");72rm("test.jar test1");73}7475@Test // fails before bug fix76public void test2() throws IOException {77System.out.println("=====");78mkdir("test1");79touch("test1/testfile1");80onCompletion = () -> rm("test.jar test1");81jar("--create --file=test.jar --release 9 test1");82jar("tf test.jar");83}8485@Test // passes before bug fix86public void test3() throws IOException {87System.out.println("=====");88mkdir("test1");89touch("test1/testfile1");90jar("-cf test.jar -C test1 .");91jar("-uf test.jar --release 9 -C test1 .");92jar("tf test.jar");93rm("test.jar test1");94}9596@Test // fails before bug fix97public void test4() throws IOException {98System.out.println("=====");99mkdir("test1");100touch("test1/testfile1");101onCompletion = () -> rm("test.jar test1");102jar("--create --file=test.jar -C test1 .");103jar("--update --file=test.jar --release 9 -C test1 .");104jar("tf test.jar");105}106107@Test // passes before bug fix since test2 precedes --release 9108public void test5() throws IOException {109System.out.println("=====");110mkdir("test1 test2");111touch("test1/testfile1 test2/testfile2");112jar("--create --file=test.jar -C test1 .");113jar("--update --file=test.jar test2 --release 9 -C test1 .");114jar("tf test.jar");115rm("test.jar test1 test2");116}117118private Stream<Path> mkpath(String... args) {119return Arrays.stream(args).map(d -> Paths.get(".", d.split("/")));120}121122private void mkdir(String cmdline) {123System.out.println("mkdir -p " + cmdline);124mkpath(cmdline.split(" +")).forEach(p -> {125try {126Files.createDirectories(p);127} catch (IOException x) {128throw new UncheckedIOException(x);129}130});131}132133private void touch(String cmdline) {134System.out.println("touch " + cmdline);135mkpath(cmdline.split(" +")).forEach(p -> {136try {137Files.createFile(p);138} catch (IOException x) {139throw new UncheckedIOException(x);140}141});142}143144private void rm(String cmdline) {145System.out.println("rm -rf " + cmdline);146mkpath(cmdline.split(" +")).forEach(p -> {147try {148if (Files.isDirectory(p)) {149FileUtils.deleteFileTreeWithRetry(p);150} else {151FileUtils.deleteFileIfExistsWithRetry(p);152}153} catch (IOException x) {154throw new UncheckedIOException(x);155}156});157}158159private void jar(String cmdline) throws IOException {160System.out.println("jar " + cmdline);161boolean ok = new sun.tools.jar.Main(System.out, System.err, "jar")162.run(cmdline.split(" +"));163Assert.assertTrue(ok);164}165}166167168