diff --git a/apisupport/apisupport.ant/build.xml b/apisupport/apisupport.ant/build.xml
index 23233785e099..d84b3bea8214 100644
--- a/apisupport/apisupport.ant/build.xml
+++ b/apisupport/apisupport.ant/build.xml
@@ -41,21 +41,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/apisupport/apisupport.ant/copyapsrc/org/netbeans/modules/apisupport/project/copyap/CopyAP.java b/apisupport/apisupport.ant/copyapsrc/org/netbeans/modules/apisupport/project/copyap/CopyAP.java
deleted file mode 100644
index ebc204a116ee..000000000000
--- a/apisupport/apisupport.ant/copyapsrc/org/netbeans/modules/apisupport/project/copyap/CopyAP.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.netbeans.modules.apisupport.project.copyap;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.Set;
-import javax.annotation.processing.AbstractProcessor;
-import javax.annotation.processing.Processor;
-import javax.annotation.processing.RoundEnvironment;
-import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.annotation.processing.SupportedOptions;
-import javax.lang.model.SourceVersion;
-import javax.lang.model.element.TypeElement;
-import javax.tools.Diagnostic.Kind;
-import org.openide.util.lookup.ServiceProvider;
-
-@ServiceProvider(service=Processor.class)
-@SupportedAnnotationTypes("*")
-@SupportedOptions("copy.files")
-public class CopyAP extends AbstractProcessor {
-
- private boolean firstRound = true;
-
- @Override
- public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
- if (firstRound) {
- for (String toCopy : processingEnv.getOptions().getOrDefault("copy.files", "").split(",")) {
- if (toCopy.isEmpty()) {
- continue;
- }
- String[] nameAndFile = toCopy.split("=", 2);
- try (OutputStream target = processingEnv.getFiler()
- .createSourceFile(nameAndFile[0])
- .openOutputStream()) {
- Files.copy(Paths.get(nameAndFile[1]), target);
- } catch (IOException ex) {
- processingEnv.getMessager().printMessage(Kind.ERROR, "Error occurred: " + ex.getMessage());
- }
- }
- firstRound = false;
- }
-
- return false;
- }
-
- @Override
- public SourceVersion getSupportedSourceVersion() {
- return SourceVersion.latestSupported();
- }
-}
diff --git a/apisupport/apisupport.ant/nbproject/project.properties b/apisupport/apisupport.ant/nbproject/project.properties
index 6905d24d36bd..cebb34120651 100644
--- a/apisupport/apisupport.ant/nbproject/project.properties
+++ b/apisupport/apisupport.ant/nbproject/project.properties
@@ -21,7 +21,7 @@ antsrc.cp=\
cp.extra=${basedir}/build/copyap.jar
requires.nb.javac=true
-javac.compilerargs=-Xlint -Xlint:-serial -Acopy.files=org.netbeans.nbbuild.extlibs.SetupLimitModulesProbe=${nb_all}/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java
+javac.compilerargs=-Xlint -Xlint:-serial
javac.source=1.8
javac.release=17
javadoc.arch=${basedir}/arch.xml
diff --git a/apisupport/apisupport.ant/nbproject/project.xml b/apisupport/apisupport.ant/nbproject/project.xml
index 2e47b993ce0b..b492273a8ea0 100644
--- a/apisupport/apisupport.ant/nbproject/project.xml
+++ b/apisupport/apisupport.ant/nbproject/project.xml
@@ -514,11 +514,6 @@
build/antclasses
${cluster}/ant/nblib/${code.name.base.dashes}.jar
-
- copyapsrc
- ${cp}
- build/copyapclasses
-
diff --git a/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/Evaluator.java b/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/Evaluator.java
index 72af92e26ea1..a7ecee41b15e 100644
--- a/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/Evaluator.java
+++ b/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/Evaluator.java
@@ -60,8 +60,6 @@
import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
import org.netbeans.modules.apisupport.project.universe.ModuleList;
import org.netbeans.modules.apisupport.project.universe.TestModuleDependency;
-import org.netbeans.nbbuild.extlibs.SetupLimitModulesProbe;
-import org.netbeans.spi.java.project.support.ProjectPlatform;
import org.netbeans.spi.project.support.ant.AntProjectEvent;
import org.netbeans.spi.project.support.ant.AntProjectHelper;
import org.netbeans.spi.project.support.ant.AntProjectListener;
@@ -76,7 +74,6 @@
import org.openide.util.Exceptions;
import org.openide.util.Mutex;
import org.openide.util.RequestProcessor;
-import org.openide.util.Utilities;
import org.openide.util.WeakListeners;
import org.openide.xml.XMLUtil;
import org.w3c.dom.Element;
diff --git a/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/SetupLimitModulesProbe.java b/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/SetupLimitModulesProbe.java
new file mode 100644
index 000000000000..fbfb3dd8725d
--- /dev/null
+++ b/apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/SetupLimitModulesProbe.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.apisupport.project;
+
+import com.sun.source.util.JavacTask;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import javax.lang.model.element.ModuleElement;
+import javax.lang.model.element.ModuleElement.RequiresDirective;
+import javax.lang.model.util.ElementFilter;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+
+/**
+ * Please note this class is a copy from
+ * nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java
+ * When modifying this class, please ensure that your changes are synchronized there as well.
+ */
+class SetupLimitModulesProbe {
+
+ public static void main(String[] args) throws IOException {
+ String release = args[0];
+
+ String[] excludedModules =
+ Arrays.stream(args)
+ .skip(1)
+ .toArray(s -> new String[s]);
+
+ String limitModules = computeLimitModules(release, excludedModules);
+
+ System.out.println(limitModules);
+ }
+
+ public static String computeLimitModules(String release, String... excludedModulesIn) throws IOException {
+ Set excludedModules = new HashSet<>(List.of(excludedModulesIn));
+ List options;
+
+ if ("last".equals(release)) {
+ options = List.of("--add-modules", "ALL-SYSTEM", "-classpath", "");
+ } else {
+ options = List.of("--release", release, "-classpath", "");
+ }
+
+ JavacTask task = (JavacTask)
+ ToolProvider.getSystemJavaCompiler()
+ .getTask(null, null, null, options, null,
+ List.of(new JFOImpl(URI.create("mem://Test.java"), "")));
+
+ task.analyze();
+
+ String limitModules =
+ task.getElements()
+ .getAllModuleElements()
+ .stream()
+ .filter(m -> !m.getQualifiedName().toString().startsWith("jdk.internal."))
+ .filter(m -> !m.isUnnamed())
+ .filter(m -> canInclude(m, excludedModules))
+ .map(m -> m.getQualifiedName())
+ .collect(Collectors.joining(","));
+
+ return limitModules;
+ }
+
+ private static boolean canInclude(ModuleElement m, Set excludes) {
+ return Collections.disjoint(transitiveDependencies(m), excludes);
+ }
+
+ private static Set transitiveDependencies(ModuleElement m) {
+ List todo = new LinkedList<>();
+ Set seenModules = new HashSet<>();
+
+ todo.add(m);
+
+ while (!todo.isEmpty()) {
+ ModuleElement current = todo.remove(0);
+
+ if (seenModules.add(current)) {
+ for (RequiresDirective rd : ElementFilter.requiresIn(current.getDirectives())) {
+ todo.add(rd.getDependency());
+ }
+ }
+ }
+
+ return seenModules.stream()
+ .map(c -> c.getQualifiedName().toString())
+ .collect(Collectors.toSet());
+ }
+
+ private static final class JFOImpl extends SimpleJavaFileObject {
+
+ private final String content;
+
+ public JFOImpl(URI uri, String content) {
+ super(uri, Kind.SOURCE);
+ this.content = content;
+ }
+
+ @Override
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
+ return content;
+ }
+
+ }
+}
diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java
index 1470a49c1743..182433336712 100644
--- a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java
+++ b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java
@@ -35,8 +35,9 @@
import javax.tools.ToolProvider;
/**
- * Please note this class is copied during build into apisupport/apisupport.ant.
- * When modifying this class, please ensure the module still compiles and works.
+ * Please note this class has a copy at
+ * apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/SetupLimitModulesProbe.java
+ * When modifying this class, please ensure that your changes are synchronized there as well.
*/
public class SetupLimitModulesProbe {