Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for requires.nb.javac modules with javac.source/target > 8. #7201

Merged
merged 2 commits into from
May 27, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,10 @@ jobs:
if: ${{ matrix.java == '17' }}
run: ant $OPTS -f extide/o.apache.tools.ant.module test

- name: apisupport.ant
if: ${{ matrix.java == '17' }}
run: ant $OPTS -f apisupport/apisupport.ant test

- name: Create Test Summary
uses: test-summary/action@v2
if: failure()
Expand Down Expand Up @@ -1454,9 +1458,6 @@ jobs:
- name: Extract
run: tar --zstd -xf build.tar.zst

- name: apisupport.ant
run: ant $OPTS -f apisupport/apisupport.ant test

- name: apisupport.project
run: ant $OPTS -f apisupport/apisupport.project test

Expand Down
16 changes: 16 additions & 0 deletions apisupport/apisupport.ant/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@
</target>

<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"/>

<!-- Generate suite 3 platform -->
<target name="test-preinit">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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();
}
}
37 changes: 8 additions & 29 deletions apisupport/apisupport.ant/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,19 @@ antsrc.cp=\
${ant.core.lib}:\
${core.startup.dir}/core/core.jar

cp.extra=${basedir}/build/copyap.jar
requires.nb.javac=true
javac.compilerargs=-Xlint -Xlint:-serial
javac.compilerargs=-Xlint -Xlint:-serial -Acopy.files=org.netbeans.nbbuild.extlibs.SetupLimitModulesProbe=${nb_all}/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java
javac.source=1.8
javac.release=17
javadoc.arch=${basedir}/arch.xml

test-unit-sys-prop.test.nbroot=${nb_all}
test-unit-sys-prop.test.netbeans.dest.dir=${netbeans.dest.dir}
test-unit-sys-prop.java.awt.headless=true

test.config.stableBTD.includes=**/*Test.class
test.config.stableBTD.excludes=\
**/AccessibilityQueryImplTest.class,\
**/AntArtifactProviderImplTest.class,\
**/ApisupportAntUtilsTest.class,\
**/AvoidModuleListInProjectConstructorTest.class,\
**/BrandingSupportTest.class,\
**/BuildZipDistributionTest.class,\
**/ClassPathProviderImplTest.class,\
**/CustomizerLibrariesTest.class,\
**/EvaluatorTest.class,\
**/GlobalJavadocForBinaryImplTest.class,\
**/GlobalSourceForBinaryImplTest.class,\
**/Issue167725DeadlockTest.class,\
**/JavadocForBinaryImplTest.class,\
**/ModuleActionsTest.class,\
**/ModuleListTest.class,\
**/ModuleTypePanelTest.class,\
**/NbModuleProjectTest.class,\
**/ProjectXMLManagerTest.class,\
**/SingleModulePropertiesTest.class,\
**/SourceForBinaryImplTest.class,\
**/SourceLevelQueryImplTest.class,\
**/SubprojectProviderImplTest.class,\
**/SuiteOperationsTest.class,\
**/TestEntryTest.class,\
**/UnitTestForSourceQueryImplTest.class,\
**/UpdateTrackingFileOwnerQueryTest.class
test.config.default.includes=**/*Test.class
test.config.default.excludes=\
**/ExternalBuildDirTest.class,\
**/UseHtml4JavaTest.class

5 changes: 5 additions & 0 deletions apisupport/apisupport.ant/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@
<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 @@ -44,6 +44,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.lang.model.SourceVersion;
import javax.swing.event.ChangeListener;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.platform.JavaPlatform;
Expand All @@ -58,6 +59,7 @@
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;
Expand All @@ -70,6 +72,7 @@
import org.openide.filesystems.FileUtil;
import org.openide.modules.SpecificationVersion;
import org.openide.util.ChangeSupport;
import org.openide.util.Exceptions;
import org.openide.util.Mutex;
import org.openide.util.RequestProcessor;
import org.openide.util.Utilities;
Expand Down Expand Up @@ -421,32 +424,43 @@ private PropertyEvaluator createEvaluator(ModuleList ml) {
if (ml != null) {
providers.add(PropertyUtils.fixedPropertyProvider(Collections.singletonMap("module.classpath", computeModuleClasspath(ml)))); // NOI18N
providers.add(PropertyUtils.fixedPropertyProvider(Collections.singletonMap("module.run.classpath", computeRuntimeModuleClasspath(ml)))); // NOI18N

baseEval = PropertyUtils.sequentialPropertyEvaluator(predefs, providers.toArray(new PropertyProvider[0]));

Map<String,String> buildDefaults = new HashMap<String,String>();
buildDefaults.put("cp.extra", ""); // NOI18N
buildDefaults.put(CP, "${module.classpath}:${cp.extra}"); // NOI18N
buildDefaults.put(RUN_CP, "${module.run.classpath}:${cp.extra}:${build.classes.dir}"); // NOI18N
if (type == NbModuleType.NETBEANS_ORG && "true".equals(projectProperties.getProperties().get("requires.nb.javac"))) {
ModuleEntry javacLibrary = ml.getEntry(JAVACAPI_CNB);
if (javacLibrary != null) {
boolean implDependencyOnJavac =
projectDependencies().filter(dep -> JAVACAPI_CNB.equals(dependencyCNB(dep)))
.map(dep -> XMLUtil.findElement(dep, "run-dependency", NbModuleProject.NAMESPACE_SHARED)) // NOI18N
.filter(runDep -> runDep != null)
.anyMatch(runDep -> XMLUtil.findElement(runDep, "implementation-version", NbModuleProject.NAMESPACE_SHARED) != null); // NOI18N
String bootcpPrepend;
if (implDependencyOnJavac) {
bootcpPrepend = javacLibrary.getClassPathExtensions();
} else {
bootcpPrepend = Stream.of(javacLibrary.getClassPathExtensions().split(Pattern.quote(File.pathSeparator)))
.filter(ext -> ext.endsWith("-api.jar"))
.collect(Collectors.joining(File.pathSeparator));
String javacRelease = baseEval.getProperty(SingleModuleProperties.JAVAC_RELEASE);
if (javacRelease == null || javacRelease.isEmpty()) {
javacRelease = baseEval.getProperty(SingleModuleProperties.JAVAC_SOURCE);
}
if (javacRelease.equals("1.6") ||
javacRelease.equals("1.7") ||
javacRelease.equals("1.8")) {
ModuleEntry javacLibrary = ml.getEntry(JAVACAPI_CNB);
if (javacLibrary != null) {
boolean implDependencyOnJavac =
projectDependencies().filter(dep -> JAVACAPI_CNB.equals(dependencyCNB(dep)))
.map(dep -> XMLUtil.findElement(dep, "run-dependency", NbModuleProject.NAMESPACE_SHARED)) // NOI18N
.filter(runDep -> runDep != null)
.anyMatch(runDep -> XMLUtil.findElement(runDep, "implementation-version", NbModuleProject.NAMESPACE_SHARED) != null); // NOI18N
String bootcpPrepend;
if (implDependencyOnJavac) {
bootcpPrepend = javacLibrary.getClassPathExtensions();
} else {
bootcpPrepend = Stream.of(javacLibrary.getClassPathExtensions().split(Pattern.quote(File.pathSeparator)))
.filter(ext -> ext.endsWith("-api.jar"))
.collect(Collectors.joining(File.pathSeparator));
}
buildDefaults.put(ClassPathProviderImpl.BOOTCLASSPATH_PREPEND, bootcpPrepend);
}
buildDefaults.put(ClassPathProviderImpl.BOOTCLASSPATH_PREPEND, bootcpPrepend);
} else {
buildDefaults.put(SingleModuleProperties.JAVAC_COMPILERARGS_INTERNAL_EXTRA, getLimitModules(javacRelease));
}
}

baseEval = PropertyUtils.sequentialPropertyEvaluator(predefs, providers.toArray(new PropertyProvider[0]));

Map<String,TestClasspath> testsCPs = computeTestingClassPaths(ml, baseEval, testTypes);
testTypes.addAll(testsCPs.keySet());
for (String testType : testTypes) {
Expand Down Expand Up @@ -874,5 +888,31 @@ private String mergePaths(Set<String> cnbs, boolean test,String testtype,File te
}
return cps.toString();
}


private static final Map<String, String> limitModulesCache = new HashMap<>();
private static String getLimitModules(String javacRelease) {
return limitModulesCache.computeIfAbsent(javacRelease, release -> {
int maxSupportedSourceVersion = SourceVersion.latest().ordinal();
try {
int javacReleaseValue = Integer.parseInt(release);
if (javacReleaseValue > maxSupportedSourceVersion) {
release = String.valueOf(maxSupportedSourceVersion);
}
} catch (NumberFormatException ex) {
//ignore
release = String.valueOf(maxSupportedSourceVersion);
}

try {
String limitModules =
SetupLimitModulesProbe.computeLimitModules(release,
"java.compiler",
"jdk.compiler");
return "--limit-modules=" + limitModules;
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
return null;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.netbeans.modules.apisupport.project.queries.AntArtifactProviderImpl;
import org.netbeans.modules.apisupport.project.queries.BinaryForSourceImpl;
import org.netbeans.modules.apisupport.project.queries.ClassPathProviderImpl;
import org.netbeans.modules.apisupport.project.queries.CompilerOptionsQueryImpl;
import org.netbeans.modules.apisupport.project.queries.FileEncodingQueryImpl;
import org.netbeans.modules.apisupport.project.queries.JavadocForBinaryImpl;
import org.netbeans.modules.apisupport.project.queries.ModuleProjectClassPathExtender;
Expand Down Expand Up @@ -309,6 +310,7 @@ private Lookup createLookup(ProjectInformation info, AuxiliaryConfiguration aux,
ic.add(new FileEncodingQueryImpl());
ic.add(new AnnotationProcessingQueryImpl(this));
ic.add(new PlatformJarProviderImpl());
ic.add(new CompilerOptionsQueryImpl(this));

if (getModuleType() == NbModuleType.SUITE_COMPONENT) {
ic.add(new SuiteProviderImpl());
Expand Down