Path: blob/master/test/jdk/java/net/URLClassLoader/closetest/Common.java
41153 views
/*1* Copyright (c) 2011, 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*/2223import java.io.*;24import java.net.*;25import java.nio.file.Files;26import jdk.test.lib.util.FileUtils;27import static java.nio.file.StandardCopyOption.*;2829public class Common {3031static void copyFile (String src, String dst) {32copyFile (new File(src), new File(dst));33}3435static void copyDir (String src, String dst) {36copyDir (new File(src), new File(dst));37}3839static void copyFile (File src, File dst) {40try {41if (!src.isFile()) {42throw new RuntimeException ("File not found: " + src.toString());43}44Files.copy(src.toPath(), dst.toPath(), REPLACE_EXISTING);45} catch (IOException e) {46throw new RuntimeException (e);47}48}4950static void rm_minus_rf (File path) throws IOException, InterruptedException {51if (!path.exists())52return;53FileUtils.deleteFileTreeWithRetry(path.toPath());54}5556static void copyDir (File src, File dst) {57if (!src.isDirectory()) {58throw new RuntimeException ("Dir not found: " + src.toString());59}60if (dst.exists()) {61throw new RuntimeException ("Dir exists: " + dst.toString());62}63dst.mkdir();64String[] names = src.list();65File[] files = src.listFiles();66for (int i=0; i<files.length; i++) {67String f = names[i];68if (files[i].isDirectory()) {69copyDir (files[i], new File (dst, f));70} else {71copyFile (new File (src, f), new File (dst, f));72}73}74}7576/* expect is true if you expect to find it, false if you expect not to */77static Class loadClass (String name, URLClassLoader loader, boolean expect){78try {79Class clazz = Class.forName (name, true, loader);80if (!expect) {81throw new RuntimeException ("loadClass: "+name+" unexpected");82}83return clazz;84} catch (ClassNotFoundException e) {85if (expect) {86throw new RuntimeException ("loadClass: " +name + " not found");87}88}89return null;90}91}929394