Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/shareClassTests/SCHelperCompatTests/URLClassPathHelperURLHelperCompatibilityTest.java
6004 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
import java.io.FileInputStream;
23
import java.net.URL;
24
import java.util.Properties;
25
26
import CustomCLs.CustomURLClassLoader;
27
import CustomCLs.CustomURLLoader;
28
import Utilities.StringManipulator;
29
import Utilities.URLClassPathCreator;
30
31
/**
32
* @author Matthew Kilner
33
*/
34
public class URLClassPathHelperURLHelperCompatibilityTest {
35
36
StringManipulator manipulator = new StringManipulator();
37
38
public static void main(String[] args) {
39
40
if(args.length != 2){
41
System.out.println("\n Incorrect usage");
42
System.out.println("\n Please specifiy -testfile <filename>");
43
}
44
45
URLClassPathHelperURLHelperCompatibilityTest test = new URLClassPathHelperURLHelperCompatibilityTest();
46
47
String testFile = args[1];
48
49
test.run(testFile);
50
51
}
52
53
public void run(String testFile){
54
55
Properties props = new Properties();
56
try{
57
FileInputStream PropertiesFile = new FileInputStream(testFile);
58
props.load(PropertiesFile);
59
60
PropertiesFile.close();
61
} catch (Exception e){
62
e.printStackTrace();
63
}
64
65
String classPath = props.getProperty("Classpath");
66
67
String ctl = props.getProperty("NumberOfClassesToLoad");
68
Integer intctl = Integer.valueOf(ctl);
69
int numberOfClassesToLoad = intctl.intValue();
70
71
String classesString = props.getProperty("LoadClasses");
72
String [] classesToLoad = new String[numberOfClassesToLoad];
73
for(int index = 0; index < numberOfClassesToLoad; index++){
74
classesToLoad[index] = manipulator.getStringElement(index, classesString);
75
}
76
77
String numberOfUrlsString = props.getProperty("NumberOfUrls");
78
Integer tempNumberOfUrls = Integer.valueOf(numberOfUrlsString);
79
int numberOfUrls = tempNumberOfUrls.intValue();
80
81
int maxClassesToFind = 0;
82
String[] urls = new String[numberOfUrls];
83
for(int index = 0; index < numberOfUrls; index++){
84
urls[index] = props.getProperty("Url"+index);
85
String ctf = props.getProperty("NumberOfClassesToFind"+index);
86
Integer intctf = Integer.valueOf(ctf);
87
maxClassesToFind = ((intctf.intValue() > maxClassesToFind) ? intctf.intValue() : maxClassesToFind);
88
}
89
90
String[][] classesToFind = new String[numberOfUrls][maxClassesToFind];
91
String[][] results = new String[numberOfUrls][maxClassesToFind];
92
93
for(int urlIndex = 0; urlIndex < numberOfUrls; urlIndex++){
94
String findClasses = props.getProperty("FindClasses"+urlIndex);
95
String result = props.getProperty("Results"+urlIndex);
96
String ctf = props.getProperty("NumberOfClassesToFind"+urlIndex);
97
Integer intctf = Integer.valueOf(ctf);
98
int numberOfClassesToFind = intctf.intValue();
99
for(int classToFindIndex = 0; classToFindIndex < numberOfClassesToFind; classToFindIndex++){
100
classesToFind[urlIndex][classToFindIndex] = manipulator.getStringElement(classToFindIndex, findClasses);
101
results[urlIndex][classToFindIndex] = manipulator.getStringElement(classToFindIndex, result);
102
}
103
}
104
105
boolean passed = executeTest(classPath, classesToLoad, urls, classesToFind, results);
106
107
if(passed){
108
System.out.println("\nTEST PASSED");
109
} else {
110
System.out.println("\nTEST FAILED");
111
}
112
}
113
114
private boolean executeTest(String classPath, String[] classesToLoad, String[] urls, String[][] classesToFind, String[][] results) {
115
116
URLClassPathCreator creator = new URLClassPathCreator(classPath);
117
URL[] urlPath;
118
urlPath = creator.createURLClassPath();
119
120
CustomURLClassLoader cl = new CustomURLClassLoader(urlPath, this.getClass().getClassLoader());
121
for(int classIndex = 0; classIndex < classesToLoad.length; classIndex++){
122
String classToLoad = classesToLoad[classIndex];
123
if (classToLoad != null){
124
try{
125
cl.loadClass(classToLoad);
126
} catch (Exception e){
127
e.printStackTrace();
128
}
129
}
130
}
131
132
String urlsString = urls[0];
133
for(int index = 1; index < urls.length; index++){
134
urlsString = new StringBuffer(urls[index].length() + 1).append(urlsString).append(urls[index]).toString();
135
}
136
System.out.println("\n** urlsString: "+urlsString);
137
URLClassPathCreator creator2 = new URLClassPathCreator(urlsString);
138
URL[] urlPath2;
139
urlPath2 = creator2.createURLClassPath();
140
CustomURLLoader urlcl = new CustomURLLoader(urlPath2, this.getClass().getClassLoader());
141
142
boolean result = true;
143
144
for(int urlIndex = 0; urlIndex < urls.length; urlIndex++){
145
for(int classIndex = 0; classIndex < classesToFind[urlIndex].length; classIndex++){
146
String classToFind = classesToFind[urlIndex][classIndex];
147
String expectedResult = results[urlIndex][classIndex];
148
if(classToFind != null){
149
String testResult = String.valueOf(urlcl.isClassInSharedCache(urlIndex, classToFind));
150
if(!(expectedResult.equals(testResult))){
151
System.out.println("\nFailure finding class: "+classToFind+" on path: "+urls[urlIndex]+" which is index: "+urlIndex+" result: "+testResult+" expecting: "+expectedResult);
152
result = false;
153
}
154
}
155
}
156
}
157
return result;
158
}
159
}
160
161