2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package gov.nasa.jpf.test.java.net;
23 import gov.nasa.jpf.util.test.TestJPF;
26 * This is used to hide the package "classloader_specific_tests" from JPF
27 * which is need to test costum class loaders
29 * @author Nastaran Shafiei
31 public class LoadUtility extends TestJPF{
33 protected String user_dir = System.getProperty("user.dir");
34 protected String pkg = "classloader_specific_tests";
36 protected String originalPath = user_dir + "/build/tests/" + pkg;
37 protected String tempPath = user_dir + "/build/" + pkg;
39 protected String jarUrl = "jar:file:" + user_dir + "/build/" + pkg + ".jar!/";
40 protected String dirUrl = "file:" + user_dir + "/build";
43 * move the package, to avoid systemClassLoader loading its classes
45 protected void movePkgOut() {
46 if(!TestJPF.isJPFRun()) {
47 movePkg(originalPath, tempPath);
52 * move the package back to its original place
54 protected void movePkgBack() {
55 if(!TestJPF.isJPFRun()) {
56 movePkg(tempPath, originalPath);
60 protected void movePkg(String from, String to) {
61 File dstFile = new File(to);
62 if(!dstFile.exists()) {
63 dstFile = new File(from);
64 assertTrue(dstFile.renameTo(new File(to)));
66 File srcFile = new File(from);
67 if(srcFile.exists()) {
68 // empty the directory
69 for(String name: srcFile.list()) {
70 assertTrue((new File(from + "/" + name)).delete());
72 // remove the directory
73 assertTrue(srcFile.delete());