author | ihse |
Sat, 03 Mar 2018 08:21:47 +0100 | |
branch | ihse-warnings-cflags-branch |
changeset 56230 | 489867818774 |
parent 47855 | 72b6d674bde2 |
permissions | -rw-r--r-- |
47855
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
1 |
/* |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
4 |
* |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
10 |
* |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
15 |
* accompanied this code). |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
16 |
* |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
20 |
* |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
23 |
* questions. |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
24 |
*/ |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
25 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
26 |
package jdk.nashorn.tools.jjs; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
27 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
28 |
import java.io.IOException; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
29 |
import java.io.File; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
30 |
import java.util.Collections; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
31 |
import java.util.EnumSet; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
32 |
import java.util.HashSet; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
33 |
import java.util.List; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
34 |
import java.util.Set; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
35 |
import java.util.stream.Collectors; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
36 |
import java.util.stream.Stream; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
37 |
import javax.tools.JavaCompiler; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
38 |
import javax.tools.JavaFileManager.Location; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
39 |
import javax.tools.JavaFileObject; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
40 |
import javax.tools.StandardJavaFileManager; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
41 |
import javax.tools.StandardLocation; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
42 |
import javax.tools.ToolProvider; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
43 |
import jdk.nashorn.internal.runtime.Context; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
44 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
45 |
/** |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
46 |
* A javac package helper that uses javac to complete package names. |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
47 |
*/ |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
48 |
final class JavacPackagesHelper extends PackagesHelper { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
49 |
// JavaCompiler may be null on certain platforms (eg. JRE) |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
50 |
private static final JavaCompiler compiler; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
51 |
static { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
52 |
// Use javac only if security manager is not around! |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
53 |
compiler = System.getSecurityManager() == null? ToolProvider.getSystemJavaCompiler() : null; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
54 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
55 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
56 |
/** |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
57 |
* Is this class available? |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
58 |
* |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
59 |
* @return true if javac is available |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
60 |
*/ |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
61 |
static boolean isAvailable() { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
62 |
return compiler != null; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
63 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
64 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
65 |
private final boolean modulePathSet; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
66 |
private final StandardJavaFileManager fm; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
67 |
private final Set<JavaFileObject.Kind> fileKinds; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
68 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
69 |
/** |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
70 |
* Construct a new JavacPackagesHelper. |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
71 |
* |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
72 |
* @param context the current Nashorn Context |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
73 |
*/ |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
74 |
JavacPackagesHelper(final Context context) throws IOException { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
75 |
super(context); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
76 |
final String modulePath = context.getEnv()._module_path; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
77 |
this.modulePathSet = modulePath != null && !modulePath.isEmpty(); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
78 |
if (isAvailable()) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
79 |
final String classPath = context.getEnv()._classpath; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
80 |
fm = compiler.getStandardFileManager(null, null, null); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
81 |
fileKinds = EnumSet.of(JavaFileObject.Kind.CLASS); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
82 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
83 |
if (this.modulePathSet) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
84 |
fm.setLocation(StandardLocation.MODULE_PATH, getFiles(modulePath)); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
85 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
86 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
87 |
if (classPath != null && !classPath.isEmpty()) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
88 |
fm.setLocation(StandardLocation.CLASS_PATH, getFiles(classPath)); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
89 |
} else { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
90 |
// no classpath set. Make sure that it is empty and not any default like "." |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
91 |
fm.setLocation(StandardLocation.CLASS_PATH, Collections.<File>emptyList()); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
92 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
93 |
} else { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
94 |
// javac is not available - caller should have checked! |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
95 |
throw new IllegalStateException("JavacPackagesHelper is not available!"); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
96 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
97 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
98 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
99 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
100 |
@Override |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
101 |
void close() throws IOException { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
102 |
if (fm != null) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
103 |
fm.close(); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
104 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
105 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
106 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
107 |
@Override |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
108 |
Set<String> listPackage(final String pkg) throws IOException { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
109 |
final Set<String> props = new HashSet<>(); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
110 |
listPackage(StandardLocation.PLATFORM_CLASS_PATH, pkg, props); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
111 |
if (this.modulePathSet) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
112 |
for (Set<Location> locs : fm.listLocationsForModules(StandardLocation.MODULE_PATH)) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
113 |
for (Location loc : locs) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
114 |
listPackage(loc, pkg, props); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
115 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
116 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
117 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
118 |
listPackage(StandardLocation.CLASS_PATH, pkg, props); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
119 |
return props; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
120 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
121 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
122 |
private void listPackage(final Location loc, final String pkg, final Set<String> props) |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
123 |
throws IOException { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
124 |
for (JavaFileObject file : fm.list(loc, pkg, fileKinds, true)) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
125 |
final String binaryName = fm.inferBinaryName(loc, file); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
126 |
// does not start with the given package prefix |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
127 |
if (!binaryName.startsWith(pkg + ".")) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
128 |
continue; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
129 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
130 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
131 |
final int nextDot = binaryName.indexOf('.', pkg.length() + 1); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
132 |
final int start = pkg.length() + 1; |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
133 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
134 |
if (nextDot != -1) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
135 |
// subpackage - eg. "regex" for "java.util" |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
136 |
final String pkgName = binaryName.substring(start, nextDot); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
137 |
if (isPackageAccessible(binaryName.substring(0, nextDot))) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
138 |
props.add(binaryName.substring(start, nextDot)); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
139 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
140 |
} else { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
141 |
// class - filter out nested, inner, anonymous, local classes. |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
142 |
// Dynalink supported public nested classes as properties of |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
143 |
// StaticClass object anyway. We don't want to expose those |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
144 |
// "$" internal names as properties of package object. |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
145 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
146 |
final String clsName = binaryName.substring(start); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
147 |
if (clsName.indexOf('$') == -1 && isClassAccessible(binaryName)) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
148 |
props.add(clsName); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
149 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
150 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
151 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
152 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
153 |
|
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
154 |
// return list of File objects for the given class path |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
155 |
private static List<File> getFiles(final String classPath) { |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
156 |
return Stream.of(classPath.split(File.pathSeparator)) |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
157 |
.map(File::new) |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
158 |
.collect(Collectors.toList()); |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
159 |
} |
72b6d674bde2
8191468: jdk.scripting.nashorn.shell (jjs) module should use optional dependency for java.compiler module
sundar
parents:
diff
changeset
|
160 |
} |