Skip to content

Commit 39d009a

Browse files
committed
updated 7548 patch
1 parent ef5236b commit 39d009a

File tree

1 file changed

+368
-0
lines changed

1 file changed

+368
-0
lines changed

patches/7548.diff

Lines changed: 368 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,371 @@
1+
diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModules.java b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModules.java
2+
new file mode 100644
3+
index 000000000000..db43c9f7f436
4+
--- /dev/null
5+
+++ b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModules.java
6+
@@ -0,0 +1,117 @@
7+
+/*
8+
+ * Licensed to the Apache Software Foundation (ASF) under one
9+
+ * or more contributor license agreements. See the NOTICE file
10+
+ * distributed with this work for additional information
11+
+ * regarding copyright ownership. The ASF licenses this file
12+
+ * to you under the Apache License, Version 2.0 (the
13+
+ * "License"); you may not use this file except in compliance
14+
+ * with the License. You may obtain a copy of the License at
15+
+ *
16+
+ * http://www.apache.org/licenses/LICENSE-2.0
17+
+ *
18+
+ * Unless required by applicable law or agreed to in writing,
19+
+ * software distributed under the License is distributed on an
20+
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
+ * KIND, either express or implied. See the License for the
22+
+ * specific language governing permissions and limitations
23+
+ * under the License.
24+
+ */
25+
+package org.netbeans.nbbuild.extlibs;
26+
+
27+
+import java.io.File;
28+
+import java.io.FileInputStream;
29+
+import java.io.FileOutputStream;
30+
+import java.io.IOException;
31+
+import java.io.InputStream;
32+
+import java.io.OutputStream;
33+
+import java.lang.ProcessBuilder.Redirect;
34+
+import java.util.ArrayList;
35+
+import java.util.Arrays;
36+
+import java.util.List;
37+
+import java.util.Properties;
38+
+import org.apache.tools.ant.BuildException;
39+
+import org.apache.tools.ant.Task;
40+
+
41+
+/**
42+
+ *
43+
+ */
44+
+public class SetupLimitModules extends Task {
45+
+
46+
+ private String limitModulesProperty;
47+
+ private String releaseVersion;
48+
+ private String excludedModules;
49+
+ private String nbjdkHome;
50+
+ private File cacheFile;
51+
+
52+
+ public void setLimitModulesProperty(String limitModulesProperty) {
53+
+ this.limitModulesProperty = limitModulesProperty;
54+
+ }
55+
+
56+
+ public void setReleaseVersion(String releaseVersion) {
57+
+ this.releaseVersion = releaseVersion;
58+
+ }
59+
+
60+
+ public void setExcludedModules(String excludedModules) {
61+
+ this.excludedModules = excludedModules;
62+
+ }
63+
+
64+
+ public void setNbjdkHome(String nbjdkHome) {
65+
+ this.nbjdkHome = nbjdkHome;
66+
+ }
67+
+
68+
+ public void setCacheFile(File cacheFile) {
69+
+ this.cacheFile = cacheFile;
70+
+ }
71+
+
72+
+ @Override
73+
+ public void execute() throws BuildException {
74+
+ try {
75+
+ Properties cache = new Properties();
76+
+
77+
+ if (cacheFile != null && cacheFile.canRead()) {
78+
+ try (InputStream in = new FileInputStream(cacheFile)) {
79+
+ cache.load(in);
80+
+ }
81+
+ }
82+
+
83+
+ String cacheKey = nbjdkHome + "-" + releaseVersion;
84+
+ String limitedModules = cache.getProperty(cacheKey);
85+
+
86+
+ if (limitedModules == null) {
87+
+ String antlibJar = SetupLimitModules.class
88+
+ .getProtectionDomain()
89+
+ .getCodeSource()
90+
+ .getLocation()
91+
+ .getPath();
92+
+ List<String> command = new ArrayList<>();
93+
+ command.add(new File(new File(nbjdkHome, "bin"), "java").getAbsolutePath());
94+
+ command.add("-classpath");
95+
+ command.add(antlibJar);
96+
+ command.add("org.netbeans.nbbuild.extlibs.SetupLimitModulesProbe");
97+
+ command.add(releaseVersion);
98+
+ command.addAll(Arrays.asList(excludedModules.split(",")));
99+
+ Process p = new ProcessBuilder(command).redirectError(Redirect.INHERIT).start();
100+
+ p.waitFor();
101+
+ StringBuilder limitModulesText = new StringBuilder();
102+
+ InputStream in = p.getInputStream();
103+
+ int r;
104+
+ while ((r = in.read()) != (-1)) {
105+
+ limitModulesText.append((char) r);
106+
+ }
107+
+ limitedModules = limitModulesText.toString().trim();
108+
+ if (cacheFile != null) {
109+
+ cache.put(cacheKey, limitedModules);
110+
+
111+
+ try (OutputStream out = new FileOutputStream(cacheFile)) {
112+
+ cache.store(out, "");
113+
+ }
114+
+ }
115+
+ }
116+
+
117+
+ getProject().setNewProperty(limitModulesProperty, limitedModules);
118+
+ } catch (IOException | InterruptedException ex) {
119+
+ throw new BuildException(ex);
120+
+ }
121+
+ }
122+
+
123+
+}
124+
diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java
125+
new file mode 100644
126+
index 000000000000..1470a49c1743
127+
--- /dev/null
128+
+++ b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java
129+
@@ -0,0 +1,126 @@
130+
+/*
131+
+ * Licensed to the Apache Software Foundation (ASF) under one
132+
+ * or more contributor license agreements. See the NOTICE file
133+
+ * distributed with this work for additional information
134+
+ * regarding copyright ownership. The ASF licenses this file
135+
+ * to you under the Apache License, Version 2.0 (the
136+
+ * "License"); you may not use this file except in compliance
137+
+ * with the License. You may obtain a copy of the License at
138+
+ *
139+
+ * http://www.apache.org/licenses/LICENSE-2.0
140+
+ *
141+
+ * Unless required by applicable law or agreed to in writing,
142+
+ * software distributed under the License is distributed on an
143+
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
144+
+ * KIND, either express or implied. See the License for the
145+
+ * specific language governing permissions and limitations
146+
+ * under the License.
147+
+ */
148+
+package org.netbeans.nbbuild.extlibs;
149+
+
150+
+import com.sun.source.util.JavacTask;
151+
+import java.io.IOException;
152+
+import java.net.URI;
153+
+import java.util.Arrays;
154+
+import java.util.Collections;
155+
+import java.util.HashSet;
156+
+import java.util.LinkedList;
157+
+import java.util.List;
158+
+import java.util.Set;
159+
+import java.util.stream.Collectors;
160+
+import javax.lang.model.element.ModuleElement;
161+
+import javax.lang.model.element.ModuleElement.RequiresDirective;
162+
+import javax.lang.model.util.ElementFilter;
163+
+import javax.tools.SimpleJavaFileObject;
164+
+import javax.tools.ToolProvider;
165+
+
166+
+/**
167+
+ * Please note this class is copied during build into apisupport/apisupport.ant.
168+
+ * When modifying this class, please ensure the module still compiles and works.
169+
+ */
170+
+public class SetupLimitModulesProbe {
171+
+
172+
+ public static void main(String[] args) throws IOException {
173+
+ String release = args[0];
174+
+
175+
+ String[] excludedModules =
176+
+ Arrays.stream(args)
177+
+ .skip(1)
178+
+ .toArray(s -> new String[s]);
179+
+
180+
+ String limitModules = computeLimitModules(release, excludedModules);
181+
+
182+
+ System.out.println(limitModules);
183+
+ }
184+
+
185+
+ public static String computeLimitModules(String release, String... excludedModulesIn) throws IOException {
186+
+ Set<String> excludedModules = new HashSet<>(List.of(excludedModulesIn));
187+
+ List<String> options;
188+
+
189+
+ if ("last".equals(release)) {
190+
+ options = List.of("--add-modules", "ALL-SYSTEM", "-classpath", "");
191+
+ } else {
192+
+ options = List.of("--release", release, "-classpath", "");
193+
+ }
194+
+
195+
+ JavacTask task = (JavacTask)
196+
+ ToolProvider.getSystemJavaCompiler()
197+
+ .getTask(null, null, null, options, null,
198+
+ List.of(new JFOImpl(URI.create("mem://Test.java"), "")));
199+
+
200+
+ task.analyze();
201+
+
202+
+ String limitModules =
203+
+ task.getElements()
204+
+ .getAllModuleElements()
205+
+ .stream()
206+
+ .filter(m -> !m.getQualifiedName().toString().startsWith("jdk.internal."))
207+
+ .filter(m -> !m.isUnnamed())
208+
+ .filter(m -> canInclude(m, excludedModules))
209+
+ .map(m -> m.getQualifiedName())
210+
+ .collect(Collectors.joining(","));
211+
+
212+
+ return limitModules;
213+
+ }
214+
+
215+
+ private static boolean canInclude(ModuleElement m, Set<String> excludes) {
216+
+ return Collections.disjoint(transitiveDependencies(m), excludes);
217+
+ }
218+
+
219+
+ private static Set<String> transitiveDependencies(ModuleElement m) {
220+
+ List<ModuleElement> todo = new LinkedList<>();
221+
+ Set<ModuleElement> seenModules = new HashSet<>();
222+
+
223+
+ todo.add(m);
224+
+
225+
+ while (!todo.isEmpty()) {
226+
+ ModuleElement current = todo.remove(0);
227+
+
228+
+ if (seenModules.add(current)) {
229+
+ for (RequiresDirective rd : ElementFilter.requiresIn(current.getDirectives())) {
230+
+ todo.add(rd.getDependency());
231+
+ }
232+
+ }
233+
+ }
234+
+
235+
+ return seenModules.stream()
236+
+ .map(c -> c.getQualifiedName().toString())
237+
+ .collect(Collectors.toSet());
238+
+ }
239+
+
240+
+ private static final class JFOImpl extends SimpleJavaFileObject {
241+
+
242+
+ private final String content;
243+
+
244+
+ public JFOImpl(URI uri, String content) {
245+
+ super(uri, Kind.SOURCE);
246+
+ this.content = content;
247+
+ }
248+
+
249+
+ @Override
250+
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
251+
+ return content;
252+
+ }
253+
+
254+
+ }
255+
+}
256+
diff --git a/nbbuild/jdk.xml b/nbbuild/jdk.xml
257+
index c47694ecaedd..3109e3f032b4 100644
258+
--- a/nbbuild/jdk.xml
259+
+++ b/nbbuild/jdk.xml
260+
@@ -257,13 +257,8 @@
261+
<os family="windows"/> <!-- #72467 -->
262+
</condition>
263+
<property name=".exe" value=""/>
264+
- <property name="test.nbjdk.home" location="" />
265+
- <condition property="test.nbjdk.java" value="${test.nbjdk.home}/bin/java${.exe}" else="${nbjdk.home}/bin/java${.exe}">
266+
- <and>
267+
- <isset property="test.nbjdk.home" />
268+
- <available file="${test.nbjdk.home}/bin/java${.exe}" type="file"/>
269+
- </and>
270+
- </condition>
271+
+ <property name="test.nbjdk.home" location="${nbjdk.home}" />
272+
+ <property name="test.nbjdk.java" location="${test.nbjdk.home}/bin/java${.exe}"/>
273+
<available property="have-jdk-1.9" file="${nbjdk.home}/bin/jmod${.exe}"/>
274+
<condition property="test-have-jdk-1.9">
275+
<or>
276+
diff --git a/nbbuild/templates/common.xml b/nbbuild/templates/common.xml
277+
index d3b2f613d866..073a2c1ca109 100644
278+
--- a/nbbuild/templates/common.xml
279+
+++ b/nbbuild/templates/common.xml
280+
@@ -139,9 +139,22 @@
281+
<compilerarg value="-Xbootclasspath/p:${bootclasspath.prepend}" />
282+
</custom-javac>
283+
</presetdef>
284+
+ <property name="custom.javac.set" value="true" />
285+
</target>
286+
287+
- <target name="-javac-init-no-bootclasspath-prepend" depends="build-init" unless="bootclasspath.prepend">
288+
+ <target name="-javac-init-limit-modules" depends="build-init" if="limit.modules.option.list">
289+
+ <presetdef name="nb-javac">
290+
+ <custom-javac>
291+
+ <bootclasspath>
292+
+ <path path="${nbjdk.bootclasspath}"/>
293+
+ </bootclasspath>
294+
+ <compilerarg value="--limit-modules=${limit.modules.option.list}" />
295+
+ </custom-javac>
296+
+ </presetdef>
297+
+ <property name="custom.javac.set" value="true" />
298+
+ </target>
299+
+
300+
+ <target name="-javac-init-no-bootclasspath-prepend" depends="build-init,-javac-init-bootclasspath-prepend,-javac-init-limit-modules" unless="custom.javac.set">
301+
<presetdef name="nb-javac">
302+
<custom-javac>
303+
<bootclasspath>
304+
diff --git a/nbbuild/templates/projectized.xml b/nbbuild/templates/projectized.xml
305+
index 10e2b7677739..33d9671b12f0 100644
306+
--- a/nbbuild/templates/projectized.xml
307+
+++ b/nbbuild/templates/projectized.xml
308+
@@ -95,9 +95,43 @@
309+
</path>
310+
</pathconvert>
311+
</target>
312+
- <target name="-init-bootclasspath-prepend-compile" depends="-init-compile-bootclasspath-nb">
313+
+
314+
+ <target name="-check-source-over-8" depends="basic-init">
315+
+ <condition property="limitmodules.release" value="${javac.target}" else="${javac.release}">
316+
+ <equals arg1="${javac.release}" arg2=""/>
317+
+ </condition>
318+
+ <condition property="javac.source.is.8" value="true">
319+
+ <or>
320+
+ <equals arg1="${limitmodules.release}" arg2="1.6" />
321+
+ <equals arg1="${limitmodules.release}" arg2="1.7" />
322+
+ <equals arg1="${limitmodules.release}" arg2="1.8" />
323+
+ </or>
324+
+ </condition>
325+
+ </target>
326+
+
327+
+ <target name="-init-compile-limit-modules-nb" depends="basic-init,jdk-8-check,set-buildnumber,-define-custom-javac-task,-check-source-over-8" unless="javac.source.is.8">
328+
+ <taskdef name="setuplimitmodules" classname="org.netbeans.nbbuild.extlibs.SetupLimitModules" classpath="${nbantext.jar}"/>
329+
+ <setuplimitmodules limitModulesProperty="nb.javac.limit.modules.nb"
330+
+ releaseVersion="${limitmodules.release}"
331+
+ excludedModules="java.compiler,jdk.compiler"
332+
+ nbjdkHome="${nbjdk.home}"
333+
+ cacheFile="${nb_all}/nbbuild/build/limit-modules-cache.properties" />
334+
+ </target>
335+
+
336+
+ <target name="-init-bootclasspath-prepend-compile" depends="-init-compile-bootclasspath-nb,-init-compile-limit-modules-nb,-check-source-over-8">
337+
<condition property="bootclasspath.prepend" value="${bootclasspath.prepend.nb}">
338+
- <istrue value="${requires.nb.javac}"/>
339+
+ <and>
340+
+ <istrue value="${requires.nb.javac}"/>
341+
+ <istrue value="${javac.source.is.8}"/>
342+
+ </and>
343+
+ </condition>
344+
+ <condition property="limit.modules.option.list" value="${nb.javac.limit.modules.nb}">
345+
+ <and>
346+
+ <istrue value="${requires.nb.javac}"/>
347+
+ <not>
348+
+ <istrue value="${javac.source.is.8}"/>
349+
+ </not>
350+
+ </and>
351+
</condition>
352+
</target>
353+
<target name="-init-bootclasspath-prepend-run" depends="-init-bootclasspath-prepend-compile,-init-bootclasspath-prepend-run8,-init-bootclasspath-prepend-run9"/>
354+
@@ -123,7 +157,13 @@
355+
</condition>
356+
</target>
357+
<target name="-init-bootclasspath-prepend-run9" depends="-init-bootclasspath-prepend-compile" if="have-jdk-1.9">
358+
- <condition property="test.bootclasspath.prepend.args" value="--limit-modules=java.base,java.logging,java.xml,java.prefs,java.desktop,java.management,java.instrument,jdk.zipfs,java.scripting,java.naming,jdk.jdi,jdk.unsupported,java.sql">
359+
+ <taskdef name="setuplimitmodules" classname="org.netbeans.nbbuild.extlibs.SetupLimitModules" classpath="${nbantext.jar}"/>
360+
+ <setuplimitmodules limitModulesProperty="run.nb.javac.limit.modules.nb"
361+
+ releaseVersion="last"
362+
+ excludedModules="java.compiler,jdk.compiler"
363+
+ nbjdkHome="${test.nbjdk.home}"
364+
+ cacheFile="${nb_all}/nbbuild/build/limit-modules-cache.properties" />
365+
+ <condition property="test.bootclasspath.prepend.args" value="--limit-modules=${run.nb.javac.limit.modules.nb}">
366+
<and>
367+
<istrue value="${requires.nb.javac}"/>
368+
<not>
1369
diff --git a/java/java.hints/nbproject/project.properties b/java/java.hints/nbproject/project.properties
2370
index 5d2a4f82802e..d47624c2d8ad 100644
3371
--- a/java/java.hints/nbproject/project.properties

0 commit comments

Comments
 (0)