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