Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions apisupport/apisupport.ant/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,7 @@

<target name="netbeans-extra" depends="nblib"/>

<target name="-compile-copyap" depends="projectized.init">
<mkdir dir="build/copyapclasses"/>
<nb-javac srcdir="copyapsrc" destdir="build/copyapclasses" source="${javac.source}" release="${javac.release}" debug="true" deprecation="true">
<classpath refid="cp"/>
<processorpath refid="processor.cp"/>
</nb-javac>
<copy todir="build/copyapclasses">
<fileset dir="copyapsrc" excludes="${jar-excludes}"/>
</copy>
<nb-ext-jar jarfile="build/copyap.jar" compress="false">
<fileset dir="build/copyapclasses"/>
</nb-ext-jar>
</target>

<target name="init" depends="projectized.init,-compile-copyap"/>
<target name="init" depends="projectized.init"/>

<!-- Generate suite 3 platform -->
<target name="test-preinit">
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion apisupport/apisupport.ant/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions apisupport/apisupport.ant/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,6 @@
<built-to>build/antclasses</built-to>
<built-to>${cluster}/ant/nblib/${code.name.base.dashes}.jar</built-to>
</extra-compilation-unit>
<extra-compilation-unit>
<package-root>copyapsrc</package-root>
<classpath>${cp}</classpath>
<built-to>build/copyapclasses</built-to>
</extra-compilation-unit>
</data>
</configuration>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
* <code>nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java</code>
* 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<String> excludedModules = new HashSet<>(List.of(excludedModulesIn));
List<String> 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<String> excludes) {
return Collections.disjoint(transitiveDependencies(m), excludes);
}

private static Set<String> transitiveDependencies(ModuleElement m) {
List<ModuleElement> todo = new LinkedList<>();
Set<ModuleElement> 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;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <code>apisupport/apisupport.ant/src/org/netbeans/modules/apisupport/project/SetupLimitModulesProbe.java</code>
* When modifying this class, please ensure that your changes are synchronized there as well.
*/
public class SetupLimitModulesProbe {

Expand Down
Loading