Path: blob/master/test/jdk/java/net/URLClassLoader/sealing/CheckSealedTest.java
41154 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 424497026* @summary Test to see if sealing violation is detected correctly27* @library /test/lib28* @build jdk.test.lib.Utils29* jdk.test.lib.Asserts30* jdk.test.lib.JDKToolFinder31* jdk.test.lib.JDKToolLauncher32* jdk.test.lib.Platform33* jdk.test.lib.process.*34* @run main CheckSealedTest35*/3637import jdk.test.lib.JDKToolFinder;38import jdk.test.lib.process.ProcessTools;3940import java.io.File;41import java.io.IOException;42import java.nio.file.Files;43import java.nio.file.Path;44import java.nio.file.Paths;45import java.util.List;4647import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;4849public class CheckSealedTest {50private static final String ARCHIVE_NAME = "b.jar";51private static final String TEST_NAME = "CheckSealed";52public static void main(String[] args)53throws Throwable {5455String baseDir = System.getProperty("user.dir") + File.separator;56String javac = JDKToolFinder.getTestJDKTool("javac");57String java = JDKToolFinder.getTestJDKTool("java");5859setup(baseDir);60String srcDir = System.getProperty("test.src");61String cp = srcDir + File.separator + "a" + File.pathSeparator62+ srcDir + File.separator + "b.jar" + File.pathSeparator63+ ".";64List<String[]> allCMDs = List.of(65// Compile command66new String[]{67javac, "-cp", cp, "-d", ".",68srcDir + File.separator + TEST_NAME + ".java"69},70// Run test the first time71new String[]{72java, "-cp", cp, TEST_NAME, "1"73},74// Run test the second time75new String[]{76java, "-cp", cp, TEST_NAME, "2"77}78);7980for (String[] cmd : allCMDs) {81ProcessTools.executeCommand(cmd)82.outputTo(System.out)83.errorTo(System.out)84.shouldHaveExitValue(0);85}86}8788private static void setup(String baseDir) throws IOException {89Path testJar = Paths.get(System.getProperty("test.src"), ARCHIVE_NAME);90Files.copy(testJar, Paths.get(baseDir, ARCHIVE_NAME), REPLACE_EXISTING);91}92}939495