Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/shareClassTests/utils/src/Utilities/Loader.java
6005 views
1
/*******************************************************************************
2
* Copyright (c) 2005, 2020 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package Utilities;
23
24
import java.io.FileInputStream;
25
import java.net.URL;
26
import java.util.Properties;
27
28
import CustomCLs.CustomURLClassLoader;
29
import Utilities.StringManipulator;
30
import Utilities.URLClassPathCreator;
31
32
/**
33
* @author Matthew Kilner
34
*/
35
public class Loader {
36
37
StringManipulator manipulator = new StringManipulator();
38
39
public static void main(String[] args) {
40
41
if(args.length != 2){
42
System.out.println("\n Incorrect usage");
43
System.out.println("\n Please specifiy -testfile <filename>");
44
}
45
46
Loader test = new Loader();
47
48
String testFile = args[1];
49
50
test.testWrapper(testFile);
51
}
52
53
public void testWrapper(String testFileName){
54
55
System.out.println("\n** Running loader for properties: "+testFileName+"\n");
56
57
Properties props = new Properties();
58
try{
59
FileInputStream PropertiesFile = new FileInputStream(testFileName);
60
props.load(PropertiesFile);
61
62
PropertiesFile.close();
63
} catch (Exception e){
64
e.printStackTrace();
65
}
66
67
String classPath = props.getProperty("ClassPath");
68
69
String nctls = props.getProperty("NumberOfClassesToLoad");
70
Integer i = Integer.valueOf(nctls);
71
int classesToLoadCount = i.intValue();
72
73
String[] classesToLoad = new String[classesToLoadCount];
74
String classesString = props.getProperty("ClassesToLoad");
75
for(int index = 0; index < classesToLoadCount; index ++){
76
classesToLoad[index] = manipulator.getStringElement(index, classesString);
77
}
78
79
executeTest(classPath, classesToLoad);
80
}
81
82
public void executeTest(String classpath, String[] classes){
83
84
System.out.println("\nLoading Classes.....");
85
URLClassPathCreator creator = new URLClassPathCreator(classpath);
86
URL[] urlPath;
87
urlPath = creator.createURLClassPath();
88
CustomURLClassLoader cl = new CustomURLClassLoader(urlPath, this.getClass().getClassLoader());
89
for(int index = 0; index < classes.length; index++){
90
String classToLoad = classes[index];
91
if (classToLoad != null){
92
try{
93
cl.loadClass(classToLoad);
94
} catch (Exception e){
95
e.printStackTrace();
96
}
97
}
98
}
99
}
100
101
}
102
103