author | jjg |
Thu, 02 Apr 2015 15:56:07 -0700 | |
changeset 29780 | 8f8e54a1fa20 |
parent 29291 | 076c277565f7 |
child 34752 | 9c262a013456 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
25 |
package com.sun.tools.javac.file; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
26 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
27 |
import java.io.File; |
10818 | 28 |
import java.io.FileNotFoundException; |
10 | 29 |
import java.io.IOException; |
27579 | 30 |
import java.io.UncheckedIOException; |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
31 |
import java.net.MalformedURLException; |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
32 |
import java.net.URL; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
33 |
import java.nio.file.Files; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
34 |
import java.nio.file.Path; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
35 |
import java.nio.file.Paths; |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
36 |
import java.util.ArrayList; |
10818 | 37 |
import java.util.Arrays; |
38 |
import java.util.Collection; |
|
39 |
import java.util.Collections; |
|
40 |
import java.util.EnumMap; |
|
41 |
import java.util.EnumSet; |
|
10 | 42 |
import java.util.HashMap; |
43 |
import java.util.HashSet; |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
44 |
import java.util.Iterator; |
10818 | 45 |
import java.util.LinkedHashSet; |
10 | 46 |
import java.util.Map; |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
29053
diff
changeset
|
47 |
import java.util.Objects; |
10 | 48 |
import java.util.Set; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
49 |
import java.util.regex.Pattern; |
27579 | 50 |
import java.util.stream.Collectors; |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
51 |
import java.util.stream.Stream; |
10 | 52 |
import java.util.zip.ZipFile; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
53 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
54 |
import javax.tools.JavaFileManager; |
10 | 55 |
import javax.tools.JavaFileManager.Location; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
56 |
import javax.tools.StandardJavaFileManager; |
10818 | 57 |
import javax.tools.StandardLocation; |
10 | 58 |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
59 |
import com.sun.tools.javac.code.Lint; |
11314 | 60 |
import com.sun.tools.javac.main.Option; |
1486 | 61 |
import com.sun.tools.javac.util.ListBuffer; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
62 |
import com.sun.tools.javac.util.Log; |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
14360
diff
changeset
|
63 |
import com.sun.tools.javac.util.StringUtils; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
171
diff
changeset
|
64 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
65 |
import static javax.tools.StandardLocation.CLASS_PATH; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
66 |
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
67 |
import static javax.tools.StandardLocation.SOURCE_PATH; |
10 | 68 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
69 |
import static com.sun.tools.javac.main.Option.BOOTCLASSPATH; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
70 |
import static com.sun.tools.javac.main.Option.DJAVA_ENDORSED_DIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
71 |
import static com.sun.tools.javac.main.Option.DJAVA_EXT_DIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
72 |
import static com.sun.tools.javac.main.Option.ENDORSEDDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
73 |
import static com.sun.tools.javac.main.Option.EXTDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
74 |
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
75 |
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_APPEND; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
76 |
import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH_PREPEND; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
77 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
78 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
79 |
* This class converts command line arguments, environment variables and system properties (in |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
80 |
* File.pathSeparator-separated String form) into a boot class path, user class path, and source |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
81 |
* path (in {@code Collection<String>} form). |
10 | 82 |
* |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
83 |
* <p> |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
84 |
* <b>This is NOT part of any supported API. If you write code that depends on this, you do so at |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
85 |
* your own risk. This code and its internal interfaces are subject to change or deletion without |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
86 |
* notice.</b> |
10 | 87 |
*/ |
10818 | 88 |
public class Locations { |
10 | 89 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
90 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
91 |
* The log to use for warning output |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
92 |
*/ |
10 | 93 |
private Log log; |
94 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
95 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
96 |
* Access to (possibly cached) file info |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
97 |
*/ |
1208 | 98 |
private FSInfo fsInfo; |
10 | 99 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
100 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
101 |
* Whether to warn about non-existent path elements |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
102 |
*/ |
10818 | 103 |
private boolean warn; |
104 |
||
27579 | 105 |
// Used by Locations(for now) to indicate that the PLATFORM_CLASS_PATH |
106 |
// should use the jrt: file system. |
|
107 |
// When Locations has been converted to use java.nio.file.Path, |
|
108 |
// Locations can use Paths.get(URI.create("jrt:")) |
|
27858 | 109 |
static final Path JRT_MARKER_FILE = Paths.get("JRT_MARKER_FILE"); |
27579 | 110 |
|
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
111 |
Locations() { |
10818 | 112 |
initHandlers(); |
10 | 113 |
} |
114 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
115 |
// could replace Lint by "boolean warn" |
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
116 |
void update(Log log, Lint lint, FSInfo fsInfo) { |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8424
diff
changeset
|
117 |
this.log = log; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
118 |
warn = lint.isEnabled(Lint.LintCategory.PATH); |
10813
95b39a692cd0
7101146: Paths should more directly managed by BaseFileManager
jjg
parents:
8424
diff
changeset
|
119 |
this.fsInfo = fsInfo; |
10 | 120 |
} |
121 |
||
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
122 |
boolean isDefaultBootClassPath() { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
123 |
BootClassPathLocationHandler h |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
124 |
= (BootClassPathLocationHandler) getHandler(PLATFORM_CLASS_PATH); |
10818 | 125 |
return h.isDefault(); |
10 | 126 |
} |
127 |
||
1486 | 128 |
/** |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
129 |
* Split a search path into its elements. Empty path elements will be ignored. |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
130 |
* |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
131 |
* @param searchPath The search path to be split |
1486 | 132 |
* @return The elements of the path |
133 |
*/ |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
134 |
private static Iterable<Path> getPathEntries(String searchPath) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
135 |
return getPathEntries(searchPath, null); |
1486 | 136 |
} |
10 | 137 |
|
1486 | 138 |
/** |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
139 |
* Split a search path into its elements. If emptyPathDefault is not null, all empty elements in the |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
140 |
* path, including empty elements at either end of the path, will be replaced with the value of |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
141 |
* emptyPathDefault. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
142 |
* |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
143 |
* @param searchPath The search path to be split |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
144 |
* @param emptyPathDefault The value to substitute for empty path elements, or null, to ignore |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
145 |
* empty path elements |
1486 | 146 |
* @return The elements of the path |
147 |
*/ |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
148 |
private static Iterable<Path> getPathEntries(String searchPath, Path emptyPathDefault) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
149 |
ListBuffer<Path> entries = new ListBuffer<>(); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
150 |
for (String s: searchPath.split(Pattern.quote(File.pathSeparator), -1)) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
151 |
if (s.isEmpty()) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
152 |
if (emptyPathDefault != null) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
153 |
entries.add(emptyPathDefault); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
154 |
} |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
155 |
} else { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
156 |
entries.add(Paths.get(s)); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
157 |
} |
10 | 158 |
} |
1486 | 159 |
return entries; |
10 | 160 |
} |
161 |
||
10818 | 162 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
163 |
* Utility class to help evaluate a path option. Duplicate entries are ignored, jar class paths |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
164 |
* can be expanded. |
10818 | 165 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
166 |
private class SearchPath extends LinkedHashSet<Path> { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
167 |
|
10 | 168 |
private static final long serialVersionUID = 0; |
169 |
||
170 |
private boolean expandJarClassPaths = false; |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
171 |
private final Set<Path> canonicalValues = new HashSet<>(); |
10 | 172 |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
173 |
public SearchPath expandJarClassPaths(boolean x) { |
10 | 174 |
expandJarClassPaths = x; |
175 |
return this; |
|
176 |
} |
|
177 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
178 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
179 |
* What to use when path element is the empty string |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
180 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
181 |
private Path emptyPathDefault = null; |
10 | 182 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
183 |
public SearchPath emptyPathDefault(Path x) { |
10 | 184 |
emptyPathDefault = x; |
185 |
return this; |
|
186 |
} |
|
187 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
188 |
public SearchPath addDirectories(String dirs, boolean warn) { |
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
189 |
boolean prev = expandJarClassPaths; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
190 |
expandJarClassPaths = true; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
191 |
try { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
192 |
if (dirs != null) { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
193 |
for (Path dir : getPathEntries(dirs)) { |
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
194 |
addDirectory(dir, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
195 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
196 |
} |
8424
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
197 |
return this; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
198 |
} finally { |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
199 |
expandJarClassPaths = prev; |
5e31b2eb5aa3
6485027: javac incorrectly handles relative paths in manifest classpath
jjg
parents:
8034
diff
changeset
|
200 |
} |
10 | 201 |
} |
202 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
203 |
public SearchPath addDirectories(String dirs) { |
10 | 204 |
return addDirectories(dirs, warn); |
205 |
} |
|
206 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
207 |
private void addDirectory(Path dir, boolean warn) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
208 |
if (!Files.isDirectory(dir)) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
209 |
if (warn) { |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
210 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
211 |
"dir.path.element.not.found", dir); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
212 |
} |
10 | 213 |
return; |
214 |
} |
|
215 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
216 |
try (Stream<Path> s = Files.list(dir)) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
217 |
s.filter(dirEntry -> isArchive(dirEntry)) |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
218 |
.forEach(dirEntry -> addFile(dirEntry, warn)); |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
219 |
} catch (IOException ignore) { |
10 | 220 |
} |
221 |
} |
|
222 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
223 |
public SearchPath addFiles(String files, boolean warn) { |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
224 |
if (files != null) { |
10818 | 225 |
addFiles(getPathEntries(files, emptyPathDefault), warn); |
226 |
} |
|
227 |
return this; |
|
228 |
} |
|
229 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
230 |
public SearchPath addFiles(String files) { |
10818 | 231 |
return addFiles(files, warn); |
232 |
} |
|
233 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
234 |
public SearchPath addFiles(Iterable<? extends Path> files, boolean warn) { |
10818 | 235 |
if (files != null) { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
236 |
for (Path file : files) { |
10 | 237 |
addFile(file, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
238 |
} |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
239 |
} |
10 | 240 |
return this; |
241 |
} |
|
242 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
243 |
public SearchPath addFiles(Iterable<? extends Path> files) { |
10 | 244 |
return addFiles(files, warn); |
245 |
} |
|
246 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
247 |
public void addFile(Path file, boolean warn) { |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
248 |
if (contains(file)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
249 |
// discard duplicates |
10 | 250 |
return; |
251 |
} |
|
252 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
253 |
if (!fsInfo.exists(file)) { |
10 | 254 |
/* No such file or directory exists */ |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
255 |
if (warn) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
256 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
257 |
"path.element.not.found", file); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
258 |
} |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
259 |
super.add(file); |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
260 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
261 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
262 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
263 |
Path canonFile = fsInfo.getCanonicalFile(file); |
7839
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
264 |
if (canonicalValues.contains(canonFile)) { |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
265 |
/* Discard duplicates and avoid infinite recursion */ |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
266 |
return; |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
267 |
} |
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
268 |
|
a1ca72d05b20
6999460: Glassfish build with JDK 6 / 7 is 5x-10x slower on Windows than on Linux
jjh
parents:
7336
diff
changeset
|
269 |
if (fsInfo.isFile(file)) { |
10 | 270 |
/* File is an ordinary file. */ |
27858 | 271 |
if (!isArchive(file) && !file.getFileName().toString().endsWith(".jimage")) { |
10 | 272 |
/* Not a recognized extension; open it to see if |
273 |
it looks like a valid zip file. */ |
|
274 |
try { |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
275 |
ZipFile z = new ZipFile(file.toFile()); |
10 | 276 |
z.close(); |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
277 |
if (warn) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
278 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
279 |
"unexpected.archive.file", file); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
280 |
} |
10 | 281 |
} catch (IOException e) { |
282 |
// FIXME: include e.getLocalizedMessage in warning |
|
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
283 |
if (warn) { |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
284 |
log.warning(Lint.LintCategory.PATH, |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
285 |
"invalid.archive.file", file); |
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
5847
diff
changeset
|
286 |
} |
10 | 287 |
return; |
288 |
} |
|
289 |
} |
|
290 |
} |
|
291 |
||
292 |
/* Now what we have left is either a directory or a file name |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
293 |
conforming to archive naming convention */ |
10 | 294 |
super.add(file); |
1208 | 295 |
canonicalValues.add(canonFile); |
10 | 296 |
|
27858 | 297 |
if (expandJarClassPaths && fsInfo.isFile(file) && !file.getFileName().toString().endsWith(".jimage")) { |
10 | 298 |
addJarClassPath(file, warn); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
299 |
} |
10 | 300 |
} |
301 |
||
302 |
// Adds referenced classpath elements from a jar's Class-Path |
|
303 |
// Manifest entry. In some future release, we may want to |
|
304 |
// update this code to recognize URLs rather than simple |
|
305 |
// filenames, but if we do, we should redo all path-related code. |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
306 |
private void addJarClassPath(Path jarFile, boolean warn) { |
10 | 307 |
try { |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
308 |
for (Path f : fsInfo.getJarClassPath(jarFile)) { |
1208 | 309 |
addFile(f, warn); |
10 | 310 |
} |
311 |
} catch (IOException e) { |
|
5007
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
4937
diff
changeset
|
312 |
log.error("error.reading.file", jarFile, JavacFileManager.getMessage(e)); |
10 | 313 |
} |
314 |
} |
|
315 |
} |
|
316 |
||
10818 | 317 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
318 |
* Base class for handling support for the representation of Locations. Implementations are |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
319 |
* responsible for handling the interactions between the command line options for a location, |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
320 |
* and API access via setLocation. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
321 |
* |
10818 | 322 |
* @see #initHandlers |
323 |
* @see #getHandler |
|
324 |
*/ |
|
325 |
protected abstract class LocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
326 |
|
10818 | 327 |
final Location location; |
11314 | 328 |
final Set<Option> options; |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
6151
diff
changeset
|
329 |
|
10818 | 330 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
331 |
* Create a handler. The location and options provide a way to map from a location or an |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
332 |
* option to the corresponding handler. |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
333 |
* |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
334 |
* @param location the location for which this is the handler |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
335 |
* @param options the options affecting this location |
10818 | 336 |
* @see #initHandlers |
337 |
*/ |
|
11314 | 338 |
protected LocationHandler(Location location, Option... options) { |
10818 | 339 |
this.location = location; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
340 |
this.options = options.length == 0 |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
341 |
? EnumSet.noneOf(Option.class) |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
342 |
: EnumSet.copyOf(Arrays.asList(options)); |
10818 | 343 |
} |
10 | 344 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
345 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
346 |
* @see JavaFileManager#handleOption |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
347 |
*/ |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
348 |
abstract boolean handleOption(Option option, String value); |
10 | 349 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
350 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
351 |
* @see StandardJavaFileManager#getLocation |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
352 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
353 |
abstract Collection<Path> getLocation(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
354 |
|
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
355 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
356 |
* @see StandardJavaFileManager#setLocation |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
357 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
358 |
abstract void setLocation(Iterable<? extends Path> files) throws IOException; |
10818 | 359 |
} |
360 |
||
361 |
/** |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
362 |
* General purpose implementation for output locations, such as -d/CLASS_OUTPUT and |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
363 |
* -s/SOURCE_OUTPUT. All options are treated as equivalent (i.e. aliases.) The value is a single |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
364 |
* file, possibly null. |
10818 | 365 |
*/ |
366 |
private class OutputLocationHandler extends LocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
367 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
368 |
private Path outputDir; |
10818 | 369 |
|
11314 | 370 |
OutputLocationHandler(Location location, Option... options) { |
10818 | 371 |
super(location, options); |
372 |
} |
|
373 |
||
374 |
@Override |
|
11314 | 375 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
376 |
if (!options.contains(option)) { |
10818 | 377 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
378 |
} |
10 | 379 |
|
10818 | 380 |
// TODO: could/should validate outputDir exists and is a directory |
381 |
// need to decide how best to report issue for benefit of |
|
382 |
// direct API call on JavaFileManager.handleOption(specifies IAE) |
|
383 |
// vs. command line decoding. |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
384 |
outputDir = (value == null) ? null : Paths.get(value); |
10818 | 385 |
return true; |
386 |
} |
|
387 |
||
388 |
@Override |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
389 |
Collection<Path> getLocation() { |
10818 | 390 |
return (outputDir == null) ? null : Collections.singleton(outputDir); |
391 |
} |
|
10 | 392 |
|
10818 | 393 |
@Override |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
394 |
void setLocation(Iterable<? extends Path> files) throws IOException { |
10818 | 395 |
if (files == null) { |
396 |
outputDir = null; |
|
397 |
} else { |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
398 |
Iterator<? extends Path> pathIter = files.iterator(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
399 |
if (!pathIter.hasNext()) { |
10818 | 400 |
throw new IllegalArgumentException("empty path for directory"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
401 |
} |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
402 |
Path dir = pathIter.next(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
403 |
if (pathIter.hasNext()) { |
10818 | 404 |
throw new IllegalArgumentException("path too long for directory"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
405 |
} |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
406 |
if (!Files.exists(dir)) { |
10818 | 407 |
throw new FileNotFoundException(dir + ": does not exist"); |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
408 |
} else if (!Files.isDirectory(dir)) { |
10818 | 409 |
throw new IOException(dir + ": not a directory"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
410 |
} |
10818 | 411 |
outputDir = dir; |
412 |
} |
|
413 |
} |
|
10 | 414 |
} |
415 |
||
10818 | 416 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
417 |
* General purpose implementation for search path locations, such as -sourcepath/SOURCE_PATH and |
28332
cd3ea1087d2b
8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents:
27858
diff
changeset
|
418 |
* -processorPath/ANNOTATION_PROCESSOR_PATH. All options are treated as equivalent (i.e. aliases.) |
10818 | 419 |
* The value is an ordered set of files and/or directories. |
420 |
*/ |
|
421 |
private class SimpleLocationHandler extends LocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
422 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
423 |
protected Collection<Path> searchPath; |
10 | 424 |
|
11314 | 425 |
SimpleLocationHandler(Location location, Option... options) { |
10818 | 426 |
super(location, options); |
427 |
} |
|
10 | 428 |
|
10818 | 429 |
@Override |
11314 | 430 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
431 |
if (!options.contains(option)) { |
10818 | 432 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
433 |
} |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
434 |
searchPath = value == null ? null |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
435 |
: Collections.unmodifiableCollection(createPath().addFiles(value)); |
10818 | 436 |
return true; |
437 |
} |
|
438 |
||
439 |
@Override |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
440 |
Collection<Path> getLocation() { |
10818 | 441 |
return searchPath; |
442 |
} |
|
10 | 443 |
|
10818 | 444 |
@Override |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
445 |
void setLocation(Iterable<? extends Path> files) { |
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
446 |
SearchPath p; |
10818 | 447 |
if (files == null) { |
448 |
p = computePath(null); |
|
449 |
} else { |
|
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
450 |
p = createPath().addFiles(files); |
10818 | 451 |
} |
452 |
searchPath = Collections.unmodifiableCollection(p); |
|
453 |
} |
|
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
454 |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
455 |
protected SearchPath computePath(String value) { |
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
456 |
return createPath().addFiles(value); |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
457 |
} |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
458 |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
459 |
protected SearchPath createPath() { |
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
460 |
return new SearchPath(); |
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
461 |
} |
10 | 462 |
} |
463 |
||
10818 | 464 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
465 |
* Subtype of SimpleLocationHandler for -classpath/CLASS_PATH. If no value is given, a default |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
466 |
* is provided, based on system properties and other values. |
10818 | 467 |
*/ |
468 |
private class ClassPathLocationHandler extends SimpleLocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
469 |
|
10818 | 470 |
ClassPathLocationHandler() { |
471 |
super(StandardLocation.CLASS_PATH, |
|
11314 | 472 |
Option.CLASSPATH, Option.CP); |
10818 | 473 |
} |
474 |
||
475 |
@Override |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
476 |
Collection<Path> getLocation() { |
10818 | 477 |
lazy(); |
478 |
return searchPath; |
|
479 |
} |
|
480 |
||
481 |
@Override |
|
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
482 |
protected SearchPath computePath(String value) { |
10818 | 483 |
String cp = value; |
10 | 484 |
|
10818 | 485 |
// CLASSPATH environment variable when run from `javac'. |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
486 |
if (cp == null) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
487 |
cp = System.getProperty("env.class.path"); |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
488 |
} |
10818 | 489 |
|
490 |
// If invoked via a java VM (not the javac launcher), use the |
|
491 |
// platform class path |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
492 |
if (cp == null && System.getProperty("application.home") == null) { |
10818 | 493 |
cp = System.getProperty("java.class.path"); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
494 |
} |
10818 | 495 |
|
496 |
// Default to current working directory. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
497 |
if (cp == null) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
498 |
cp = "."; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
499 |
} |
10818 | 500 |
|
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
501 |
return createPath().addFiles(cp); |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
502 |
} |
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
503 |
|
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
504 |
@Override |
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
505 |
protected SearchPath createPath() { |
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
506 |
return new SearchPath() |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
507 |
.expandJarClassPaths(true) // Only search user jars for Class-Paths |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
508 |
.emptyPathDefault(Paths.get(".")); // Empty path elt ==> current directory |
14360
2a8304e421ed
6725230: Java Compilation with Jsr199 ignores Class-Path in manifest
jjg
parents:
14259
diff
changeset
|
509 |
} |
10818 | 510 |
|
511 |
private void lazy() { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
512 |
if (searchPath == null) { |
10818 | 513 |
setLocation(null); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
514 |
} |
10818 | 515 |
} |
10 | 516 |
} |
517 |
||
10818 | 518 |
/** |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
519 |
* Custom subtype of LocationHandler for PLATFORM_CLASS_PATH. Various options are supported for |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
520 |
* different components of the platform class path. Setting a value with setLocation overrides |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
521 |
* all existing option values. Setting any option overrides any value set with setLocation, and |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
522 |
* reverts to using default values for options that have not been set. Setting -bootclasspath or |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
523 |
* -Xbootclasspath overrides any existing value for -Xbootclasspath/p: and -Xbootclasspath/a:. |
10818 | 524 |
*/ |
525 |
private class BootClassPathLocationHandler extends LocationHandler { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
526 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
527 |
private Collection<Path> searchPath; |
22163 | 528 |
final Map<Option, String> optionValues = new EnumMap<>(Option.class); |
10818 | 529 |
|
530 |
/** |
|
27579 | 531 |
* Is the bootclasspath the default? |
10818 | 532 |
*/ |
27579 | 533 |
private boolean isDefault; |
10818 | 534 |
|
535 |
BootClassPathLocationHandler() { |
|
536 |
super(StandardLocation.PLATFORM_CLASS_PATH, |
|
11314 | 537 |
Option.BOOTCLASSPATH, Option.XBOOTCLASSPATH, |
538 |
Option.XBOOTCLASSPATH_PREPEND, |
|
539 |
Option.XBOOTCLASSPATH_APPEND, |
|
540 |
Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS, |
|
541 |
Option.EXTDIRS, Option.DJAVA_EXT_DIRS); |
|
10818 | 542 |
} |
543 |
||
544 |
boolean isDefault() { |
|
545 |
lazy(); |
|
27579 | 546 |
return isDefault; |
10818 | 547 |
} |
548 |
||
549 |
@Override |
|
11314 | 550 |
boolean handleOption(Option option, String value) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
551 |
if (!options.contains(option)) { |
10818 | 552 |
return false; |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
553 |
} |
10 | 554 |
|
10818 | 555 |
option = canonicalize(option); |
556 |
optionValues.put(option, value); |
|
557 |
if (option == BOOTCLASSPATH) { |
|
558 |
optionValues.remove(XBOOTCLASSPATH_PREPEND); |
|
559 |
optionValues.remove(XBOOTCLASSPATH_APPEND); |
|
560 |
} |
|
561 |
searchPath = null; // reset to "uninitialized" |
|
562 |
return true; |
|
563 |
} |
|
564 |
// where |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
565 |
// TODO: would be better if option aliasing was handled at a higher |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
566 |
// level |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
567 |
private Option canonicalize(Option option) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
568 |
switch (option) { |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
569 |
case XBOOTCLASSPATH: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
570 |
return Option.BOOTCLASSPATH; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
571 |
case DJAVA_ENDORSED_DIRS: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
572 |
return Option.ENDORSEDDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
573 |
case DJAVA_EXT_DIRS: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
574 |
return Option.EXTDIRS; |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
575 |
default: |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
576 |
return option; |
10818 | 577 |
} |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
578 |
} |
10 | 579 |
|
10818 | 580 |
@Override |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
581 |
Collection<Path> getLocation() { |
10 | 582 |
lazy(); |
10818 | 583 |
return searchPath; |
584 |
} |
|
585 |
||
586 |
@Override |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
587 |
void setLocation(Iterable<? extends Path> files) { |
10818 | 588 |
if (files == null) { |
589 |
searchPath = null; // reset to "uninitialized" |
|
590 |
} else { |
|
27579 | 591 |
isDefault = false; |
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
592 |
SearchPath p = new SearchPath().addFiles(files, false); |
10818 | 593 |
searchPath = Collections.unmodifiableCollection(p); |
594 |
optionValues.clear(); |
|
595 |
} |
|
10 | 596 |
} |
10818 | 597 |
|
27579 | 598 |
SearchPath computePath() throws IOException { |
599 |
String java_home = System.getProperty("java.home"); |
|
600 |
||
27118
3c8314271af7
8060043: Rename Locations.Path to Locations.SearchPath
jjg
parents:
25874
diff
changeset
|
601 |
SearchPath path = new SearchPath(); |
10818 | 602 |
|
603 |
String bootclasspathOpt = optionValues.get(BOOTCLASSPATH); |
|
604 |
String endorseddirsOpt = optionValues.get(ENDORSEDDIRS); |
|
605 |
String extdirsOpt = optionValues.get(EXTDIRS); |
|
606 |
String xbootclasspathPrependOpt = optionValues.get(XBOOTCLASSPATH_PREPEND); |
|
607 |
String xbootclasspathAppendOpt = optionValues.get(XBOOTCLASSPATH_APPEND); |
|
608 |
path.addFiles(xbootclasspathPrependOpt); |
|
609 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
610 |
if (endorseddirsOpt != null) { |
10818 | 611 |
path.addDirectories(endorseddirsOpt); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
612 |
} else { |
10818 | 613 |
path.addDirectories(System.getProperty("java.endorsed.dirs"), false); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
614 |
} |
10818 | 615 |
|
616 |
if (bootclasspathOpt != null) { |
|
617 |
path.addFiles(bootclasspathOpt); |
|
618 |
} else { |
|
619 |
// Standard system classes for this compiler's release. |
|
27858 | 620 |
Collection<Path> systemClasses = systemClasses(java_home); |
27579 | 621 |
if (systemClasses != null) { |
622 |
path.addFiles(systemClasses, false); |
|
623 |
} else { |
|
624 |
// fallback to the value of sun.boot.class.path |
|
625 |
String files = System.getProperty("sun.boot.class.path"); |
|
626 |
path.addFiles(files, false); |
|
10818 | 627 |
} |
628 |
} |
|
629 |
||
630 |
path.addFiles(xbootclasspathAppendOpt); |
|
631 |
||
632 |
// Strictly speaking, standard extensions are not bootstrap |
|
633 |
// classes, but we treat them identically, so we'll pretend |
|
634 |
// that they are. |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
635 |
if (extdirsOpt != null) { |
10818 | 636 |
path.addDirectories(extdirsOpt); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
637 |
} else { |
27579 | 638 |
// Add lib/jfxrt.jar to the search path |
27858 | 639 |
Path jfxrt = Paths.get(java_home, "lib", "jfxrt.jar"); |
640 |
if (Files.exists(jfxrt)) { |
|
27579 | 641 |
path.addFile(jfxrt, false); |
642 |
} |
|
10818 | 643 |
path.addDirectories(System.getProperty("java.ext.dirs"), false); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
644 |
} |
10818 | 645 |
|
27579 | 646 |
isDefault = |
647 |
(xbootclasspathPrependOpt == null) |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
648 |
&& (bootclasspathOpt == null) |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
649 |
&& (xbootclasspathAppendOpt == null); |
10818 | 650 |
|
651 |
return path; |
|
652 |
} |
|
653 |
||
27579 | 654 |
/** |
655 |
* Return a collection of files containing system classes. |
|
656 |
* Returns {@code null} if not running on a modular image. |
|
657 |
* |
|
658 |
* @throws UncheckedIOException if an I/O errors occurs |
|
659 |
*/ |
|
27858 | 660 |
private Collection<Path> systemClasses(String java_home) throws IOException { |
27579 | 661 |
// Return .jimage files if available |
662 |
Path libModules = Paths.get(java_home, "lib", "modules"); |
|
663 |
if (Files.exists(libModules)) { |
|
664 |
try (Stream<Path> files = Files.list(libModules)) { |
|
665 |
boolean haveJImageFiles = |
|
666 |
files.anyMatch(f -> f.getFileName().toString().endsWith(".jimage")); |
|
667 |
if (haveJImageFiles) { |
|
29053
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
668 |
return addAdditionalBootEntries(Collections.singleton(JRT_MARKER_FILE)); |
27579 | 669 |
} |
670 |
} |
|
671 |
} |
|
672 |
||
673 |
// Exploded module image |
|
674 |
Path modules = Paths.get(java_home, "modules"); |
|
675 |
if (Files.isDirectory(modules.resolve("java.base"))) { |
|
29053
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
676 |
try (Stream<Path> listedModules = Files.list(modules)) { |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
677 |
return addAdditionalBootEntries(listedModules.collect(Collectors.toList())); |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
678 |
} |
27579 | 679 |
} |
680 |
||
681 |
// not a modular image that we know about |
|
682 |
return null; |
|
683 |
} |
|
684 |
||
29053
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
685 |
//ensure bootclasspath prepends/appends are reflected in the systemClasses |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
686 |
private Collection<Path> addAdditionalBootEntries(Collection<Path> modules) throws IOException { |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
687 |
String files = System.getProperty("sun.boot.class.path"); |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
688 |
|
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
689 |
if (files == null) |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
690 |
return modules; |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
691 |
|
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
692 |
Set<Path> paths = new LinkedHashSet<>(); |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
693 |
|
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
694 |
for (String s : files.split(Pattern.quote(File.pathSeparator))) { |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
695 |
if (s.endsWith(".jimage")) { |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
696 |
paths.addAll(modules); |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
697 |
} else if (!s.isEmpty()) { |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
698 |
paths.add(Paths.get(s)); |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
699 |
} |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
700 |
} |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
701 |
|
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
702 |
return paths; |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
703 |
} |
5c1f1d6b40f6
8067445: New modular image-based file manager skips boot classes
jlahoda
parents:
28707
diff
changeset
|
704 |
|
10818 | 705 |
private void lazy() { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
706 |
if (searchPath == null) { |
27579 | 707 |
try { |
10818 | 708 |
searchPath = Collections.unmodifiableCollection(computePath()); |
27579 | 709 |
} catch (IOException e) { |
710 |
// TODO: need better handling here, e.g. javac Abort? |
|
711 |
throw new UncheckedIOException(e); |
|
712 |
} |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
713 |
} |
10818 | 714 |
} |
10 | 715 |
} |
716 |
||
10818 | 717 |
Map<Location, LocationHandler> handlersForLocation; |
11314 | 718 |
Map<Option, LocationHandler> handlersForOption; |
10818 | 719 |
|
720 |
void initHandlers() { |
|
22163 | 721 |
handlersForLocation = new HashMap<>(); |
722 |
handlersForOption = new EnumMap<>(Option.class); |
|
10818 | 723 |
|
724 |
LocationHandler[] handlers = { |
|
725 |
new BootClassPathLocationHandler(), |
|
726 |
new ClassPathLocationHandler(), |
|
11314 | 727 |
new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCEPATH), |
728 |
new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSORPATH), |
|
729 |
new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), Option.D), |
|
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
11314
diff
changeset
|
730 |
new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), Option.S), |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
11314
diff
changeset
|
731 |
new OutputLocationHandler((StandardLocation.NATIVE_HEADER_OUTPUT), Option.H) |
10818 | 732 |
}; |
10 | 733 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
734 |
for (LocationHandler h : handlers) { |
10818 | 735 |
handlersForLocation.put(h.location, h); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
736 |
for (Option o : h.options) { |
10818 | 737 |
handlersForOption.put(o, h); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
738 |
} |
10 | 739 |
} |
10818 | 740 |
} |
741 |
||
29780
8f8e54a1fa20
8076420: Consolidate javac file handling in javac.file package
jjg
parents:
29291
diff
changeset
|
742 |
boolean handleOption(Option option, String value) { |
10818 | 743 |
LocationHandler h = handlersForOption.get(option); |
744 |
return (h == null ? false : h.handleOption(option, value)); |
|
745 |
} |
|
746 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
747 |
Collection<Path> getLocation(Location location) { |
10818 | 748 |
LocationHandler h = getHandler(location); |
749 |
return (h == null ? null : h.getLocation()); |
|
10 | 750 |
} |
751 |
||
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
752 |
Path getOutputLocation(Location location) { |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
753 |
if (!location.isOutputLocation()) { |
10818 | 754 |
throw new IllegalArgumentException(); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
755 |
} |
10818 | 756 |
LocationHandler h = getHandler(location); |
757 |
return ((OutputLocationHandler) h).outputDir; |
|
758 |
} |
|
10 | 759 |
|
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
760 |
void setLocation(Location location, Iterable<? extends Path> files) throws IOException { |
10818 | 761 |
LocationHandler h = getHandler(location); |
762 |
if (h == null) { |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
763 |
if (location.isOutputLocation()) { |
10818 | 764 |
h = new OutputLocationHandler(location); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
765 |
} else { |
10818 | 766 |
h = new SimpleLocationHandler(location); |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
767 |
} |
10818 | 768 |
handlersForLocation.put(location, h); |
769 |
} |
|
770 |
h.setLocation(files); |
|
771 |
} |
|
772 |
||
773 |
protected LocationHandler getHandler(Location location) { |
|
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
29053
diff
changeset
|
774 |
Objects.requireNonNull(location); |
10818 | 775 |
return handlersForLocation.get(location); |
776 |
} |
|
777 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
778 |
/** |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
779 |
* Is this the name of an archive file? |
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
780 |
*/ |
27852
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
781 |
private boolean isArchive(Path file) { |
2e6ad0e4fe20
8061876: replace java.io.File with java.nio.file.Path (again)
jjg
parents:
27226
diff
changeset
|
782 |
String n = StringUtils.toLowerCase(file.getFileName().toString()); |
1208 | 783 |
return fsInfo.isFile(file) |
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
22163
diff
changeset
|
784 |
&& (n.endsWith(".jar") || n.endsWith(".zip")); |
10 | 785 |
} |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4548
diff
changeset
|
786 |
|
10 | 787 |
} |