Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/shareClassTests/utils/src/Utilities/URLClassPathCreator.java
6005 views
1
/*******************************************************************************
2
* Copyright (c) 2005, 2018 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.File;
25
import java.io.IOException;
26
import java.net.MalformedURLException;
27
import java.net.URL;
28
29
/**
30
* @author Matthew Kilner
31
*/
32
public class URLClassPathCreator {
33
34
String classpathString;
35
36
/**
37
*
38
*/
39
public URLClassPathCreator(String cp) {
40
super();
41
42
classpathString = prepareString(cp);
43
}
44
45
private String prepareString(String string){
46
String newString = null;
47
newString = string.replace(';',File.pathSeparatorChar);
48
return newString;
49
}
50
51
public URL[] createURLClassPath(){
52
int index = 0, count = 0, end = classpathString.length();
53
while (index < end) {
54
int next = classpathString.indexOf(File.pathSeparatorChar, index);
55
if (next == -1) next = end;
56
if (next - index > 0) count++;
57
index = next + 1;
58
}
59
URL[] urlPath = new URL[count];
60
index = count = 0;
61
while (index < end) {
62
int next = classpathString.indexOf(File.pathSeparatorChar, index);
63
if (next == -1) next = end;
64
if (next - index > 0) {
65
String path = classpathString.substring(index, next);
66
try {
67
File f = new File(path);
68
path = f.getCanonicalPath();
69
if (File.separatorChar != '/')
70
path = path.replace(File.separatorChar, '/');
71
if (f.isDirectory()) {
72
if (!path.endsWith("/"))
73
path = new StringBuffer(path.length() + 1).
74
append(path).append('/').toString();
75
}
76
if (!path.startsWith("/"))
77
path = new StringBuffer(path.length() + 1).
78
append('/').append(path).toString();
79
if (!path.startsWith("//")) {
80
try {
81
urlPath[count++] = new URL("file", null, -1, path, null);
82
} catch (MalformedURLException e) {}
83
index = next + 1;
84
continue;
85
}
86
path = new StringBuffer(path.length() + 5).
87
append("file:").append(path).toString();
88
89
urlPath[count] = new URL(path);
90
count++;
91
} catch (IOException e) {}
92
}
93
index = next + 1;
94
}
95
if (count < urlPath.length) {
96
URL[] paths = new URL[count];
97
System.arraycopy(urlPath, 0, paths, 0, count);
98
urlPath = paths;
99
}
100
return urlPath;
101
}
102
}
103
104