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