Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.base/windows/classes/jdk/internal/loader/ClassLoaderHelper.java
67769 views
1
/*
2
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package jdk.internal.loader;
27
28
import java.io.File;
29
30
class ClassLoaderHelper {
31
32
private ClassLoaderHelper() {}
33
34
/**
35
* Returns true if loading a native library only if
36
* it's present on the file system.
37
*/
38
static boolean loadLibraryOnlyIfPresent() {
39
return true;
40
}
41
42
/**
43
* Returns an alternate path name for the given file
44
* such that if the original pathname did not exist, then the
45
* file may be located at the alternate location.
46
* For most platforms, this behavior is not supported and returns null.
47
*/
48
static File mapAlternativeName(File lib) {
49
return null;
50
}
51
52
/**
53
* Parse a PATH env variable. Windows allows quoted elements in a PATH,
54
* so special care needs to be taken.
55
*
56
* Empty elements will be replaced by dot.
57
*/
58
static String[] parsePath(String ldPath) {
59
int ldLen = ldPath.length();
60
char ps = File.pathSeparatorChar;
61
int psCount = 0;
62
63
if (ldPath.indexOf('\"') >= 0) {
64
// First, remove quotes put around quoted parts of paths.
65
// Second, use a quotation mark as a new path separator.
66
// This will preserve any quoted old path separators.
67
char[] buf = new char[ldLen];
68
int bufLen = 0;
69
for (int i = 0; i < ldLen; ++i) {
70
char ch = ldPath.charAt(i);
71
if (ch == '\"') {
72
while (++i < ldLen &&
73
(ch = ldPath.charAt(i)) != '\"') {
74
buf[bufLen++] = ch;
75
}
76
} else {
77
if (ch == ps) {
78
psCount++;
79
ch = '\"';
80
}
81
buf[bufLen++] = ch;
82
}
83
}
84
ldPath = new String(buf, 0, bufLen);
85
ldLen = bufLen;
86
ps = '\"';
87
} else {
88
for (int i = ldPath.indexOf(ps); i >= 0;
89
i = ldPath.indexOf(ps, i + 1)) {
90
psCount++;
91
}
92
}
93
94
String[] paths = new String[psCount + 1];
95
int pathStart = 0;
96
for (int j = 0; j < psCount; ++j) {
97
int pathEnd = ldPath.indexOf(ps, pathStart);
98
paths[j] = (pathStart < pathEnd) ?
99
ldPath.substring(pathStart, pathEnd) : ".";
100
pathStart = pathEnd + 1;
101
}
102
paths[psCount] = (pathStart < ldLen) ?
103
ldPath.substring(pathStart, ldLen) : ".";
104
return paths;
105
}
106
}
107
108