Path: blob/master/test/jdk/sun/net/www/protocol/jar/jarbug/TestDriver.java
41161 views
/*1* Copyright (c) 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 4361044 4388202 4418643 4523159 473064226* @library /test/lib27* @modules jdk.compiler28* @build jdk.test.lib.compiler.CompilerUtils29* jdk.test.lib.Utils30* jdk.test.lib.Asserts31* jdk.test.lib.JDKToolFinder32* jdk.test.lib.JDKToolLauncher33* jdk.test.lib.Platform34* jdk.test.lib.process.*35* jdk.test.lib.util.JarUtils36* src.test.src.TestDriver37* @summary various resource and classloading bugs related to jar files38* @run main/othervm TestDriver39*/4041import java.io.File;42import java.nio.file.Files;43import java.nio.file.Path;44import java.nio.file.Paths;4546import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;47import jdk.test.lib.JDKToolFinder;48import jdk.test.lib.compiler.CompilerUtils;49import jdk.test.lib.process.ProcessTools;50import jdk.test.lib.util.JarUtils;5152public class TestDriver {53public static void main(String[] args) throws Throwable {54Path srcDir = Paths.get(System.getProperty("test.src"));55Path targetDir = Paths.get(System.getProperty("user.dir"));56Path jar1SrcDir = srcDir.resolve("src").resolve("jar1");57Path jar1TargetDir = targetDir.resolve("jar1");58Path ectJar1Dir = srcDir.resolve("etc").resolve("jar1");59Path jarFile = targetDir.resolve("jar1.jar");60Path[] files= new Path[] {61Paths.get("res1.txt"), Paths.get("jar1", "bundle.properties")62};6364// Copy files to target directory and change permission65for (Path file : files) {66Path dest = jar1TargetDir.resolve(file);67Files.createDirectories(dest.getParent());68Files.copy(ectJar1Dir.resolve(file), dest, REPLACE_EXISTING);69}7071// Compile and build jar1.jar72ProcessTools.executeCommand("chmod", "-R", "u+w", "./jar1")73.outputTo(System.out)74.errorTo(System.out)75.shouldHaveExitValue(0);76CompilerUtils.compile(jar1SrcDir, jar1TargetDir);77JarUtils.createJarFile(jarFile, jar1TargetDir);7879// Compile test files80CompilerUtils.compile(srcDir.resolve("src").resolve("test"), targetDir);8182// Run tests83String java = JDKToolFinder.getTestJDKTool("java");84String cp = targetDir.toString() + File.pathSeparator + jarFile;85String[] tests = new String[]{"TestBug4361044", "TestBug4523159"};86for (String test : tests) {87ProcessTools.executeCommand(java, "-cp", cp, test)88.outputTo(System.out)89.errorTo(System.out)90.shouldHaveExitValue(0);91}92}93}949596