geertjanw closed pull request #534: [NETBEANS-721] Jigsaw module system must be initialized in javac befo… URL: https://github.com/apache/incubator-netbeans/pull/534
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/.gitignore b/.gitignore index bcd6d424e..c83ba80d6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ /nbbuild/user.build.properties /nbi/engine/native/*/*/dist/ /nb-javac/ +/java.source.nbjavac/test/test-nb-javac/nbproject/private/ # OS generated files # ###################### diff --git a/java.source.nbjavac/build.xml b/java.source.nbjavac/build.xml index 3beeb845a..42b7359fe 100644 --- a/java.source.nbjavac/build.xml +++ b/java.source.nbjavac/build.xml @@ -22,4 +22,11 @@ <project basedir="." default="build" name="java.source.nbjavac"> <description>Builds, tests, and runs the project org.netbeans.modules.java.source.nbjavac</description> <import file="../nbbuild/templates/projectized.xml"/> + <target name="test-build" depends="projectized-common.test-build"> + <ant dir="test/test-nb-javac" inheritall="false" inheritrefs="false"> + <property name="build.dir" location="${build.dir}/test-nb-javac" /> + <property name="nbplatform.default.netbeans.dest.dir" location="${netbeans.dest.dir}" /> + <property name="nbplatform.default.harness.dir" location="${netbeans.dest.dir}/harness" /> + </ant> + </target> </project> diff --git a/java.source.nbjavac/test/test-nb-javac/build.xml b/java.source.nbjavac/test/test-nb-javac/build.xml new file mode 100644 index 000000000..57ac2f10b --- /dev/null +++ b/java.source.nbjavac/test/test-nb-javac/build.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project name="org.netbeans.modules.java.source.nbjavac.test" default="netbeans" basedir="."> + <description>Builds, tests, and runs the project org.netbeans.modules.java.source.nbjavac.test.</description> + <import file="nbproject/build-impl.xml"/> +</project> diff --git a/java.source.nbjavac/test/test-nb-javac/manifest.mf b/java.source.nbjavac/test/test-nb-javac/manifest.mf new file mode 100644 index 000000000..2965a165f --- /dev/null +++ b/java.source.nbjavac/test/test-nb-javac/manifest.mf @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +AutoUpdate-Show-In-Client: true +OpenIDE-Module: org.netbeans.modules.java.source.nbjavac.test +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/source/nbjavac/test/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 +OpenIDE-Module-Provides: org.netbeans.modules.nbjavac + diff --git a/java.source.nbjavac/test/test-nb-javac/nbproject/build-impl.xml b/java.source.nbjavac/test/test-nb-javac/nbproject/build-impl.xml new file mode 100644 index 000000000..acddd4195 --- /dev/null +++ b/java.source.nbjavac/test/test-nb-javac/nbproject/build-impl.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<!-- +*** GENERATED FROM project.xml - DO NOT EDIT *** +*** EDIT ../build.xml INSTEAD *** +--> +<project name="org.netbeans.modules.java.source.nbjavac.test-impl" basedir=".."> + <fail message="Please build using Ant 1.7.1 or higher."> + <condition> + <not> + <antversion atleast="1.7.1"/> + </not> + </condition> + </fail> + <property file="nbproject/private/platform-private.properties"/> + <property file="nbproject/platform.properties"/> + <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2"> + <attribute name="name"/> + <attribute name="value"/> + <sequential> + <property name="@{name}" value="${@{value}}"/> + </sequential> + </macrodef> + <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2"> + <attribute name="property"/> + <attribute name="value"/> + <sequential> + <property name="@{property}" value="@{value}"/> + </sequential> + </macrodef> + <property file="${user.properties.file}"/> + <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> + <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> + <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> + <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness)."> + <condition> + <not> + <contains string="${cluster.path.evaluated}" substring="platform"/> + </not> + </condition> + </fail> + <import file="${harness.dir}/build.xml"/> +</project> diff --git a/java.source.nbjavac/test/test-nb-javac/nbproject/genfiles.properties b/java.source.nbjavac/test/test-nb-javac/nbproject/genfiles.properties new file mode 100644 index 000000000..866dfa897 --- /dev/null +++ b/java.source.nbjavac/test/test-nb-javac/nbproject/genfiles.properties @@ -0,0 +1,25 @@ +# 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. + +build.xml.data.CRC32=28148287 +build.xml.script.CRC32=1910a213 +build.xml.stylesheet.CRC32=15ca8a54@2.73 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=28148287 +nbproject/build-impl.xml.script.CRC32=d7f101c2 +nbproject/build-impl.xml.stylesheet.CRC32=49aa68b0@2.73 diff --git a/java.source.nbjavac/test/test-nb-javac/nbproject/platform.properties b/java.source.nbjavac/test/test-nb-javac/nbproject/platform.properties new file mode 100644 index 000000000..f51cee7cc --- /dev/null +++ b/java.source.nbjavac/test/test-nb-javac/nbproject/platform.properties @@ -0,0 +1,29 @@ +# 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. + +cluster.path=\ + ${nbplatform.active.dir}/harness:\ + ${nbplatform.active.dir}/platform:\ + ${nbplatform.active.dir}/ide:\ + ${nbplatform.active.dir}/java:\ + ${nbplatform.active.dir}/websvccommon:\ + ${nbplatform.active.dir}/profiler:\ + ${nbplatform.active.dir}/nb:\ + ${nbplatform.active.dir}/javafx:\ + ${nbplatform.active.dir}/apisupport:\ + ${nbplatform.active.dir}/extide +nbplatform.active=default diff --git a/java.source.nbjavac/test/test-nb-javac/nbproject/project.properties b/java.source.nbjavac/test/test-nb-javac/nbproject/project.properties new file mode 100644 index 000000000..7c940c47c --- /dev/null +++ b/java.source.nbjavac/test/test-nb-javac/nbproject/project.properties @@ -0,0 +1,19 @@ +# 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. + +javac.source=1.7 +javac.compilerargs=-Xlint -Xlint:-serial diff --git a/java.source.nbjavac/test/test-nb-javac/nbproject/project.xml b/java.source.nbjavac/test/test-nb-javac/nbproject/project.xml new file mode 100644 index 000000000..348edf082 --- /dev/null +++ b/java.source.nbjavac/test/test-nb-javac/nbproject/project.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.apisupport.project</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> + <code-name-base>org.netbeans.modules.java.source.nbjavac.test</code-name-base> + <standalone/> + <module-dependencies/> + <public-packages/> + </data> + </configuration> +</project> diff --git a/java.source.nbjavac/test/test-nb-javac/src/org/netbeans/modules/java/source/nbjavac/test/Bundle.properties b/java.source.nbjavac/test/test-nb-javac/src/org/netbeans/modules/java/source/nbjavac/test/Bundle.properties new file mode 100644 index 000000000..ff4c65b7f --- /dev/null +++ b/java.source.nbjavac/test/test-nb-javac/src/org/netbeans/modules/java/source/nbjavac/test/Bundle.properties @@ -0,0 +1,18 @@ +# 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. + +OpenIDE-Module-Name=Testing module enabling nb-javac diff --git a/refactoring.java/nbproject/project.properties b/refactoring.java/nbproject/project.properties index 5f0235692..41ad10385 100644 --- a/refactoring.java/nbproject/project.properties +++ b/refactoring.java/nbproject/project.properties @@ -66,3 +66,4 @@ test.config.stableBTD.includes=org/netbeans/modules/refactoring/java/ui/*Test.cl test.config.stableBTD.excludes=org/netbeans/modules/test/* requires.nb.javac=true +test.unit.cp.extra=../java.source.nbjavac/build/test-nb-javac/cluster/modules/org-netbeans-modules-java-source-nbjavac-test.jar diff --git a/refactoring.java/nbproject/project.xml b/refactoring.java/nbproject/project.xml index c544d8171..ba5f6da10 100644 --- a/refactoring.java/nbproject/project.xml +++ b/refactoring.java/nbproject/project.xml @@ -524,6 +524,11 @@ <compile-dependency/> <test/> </test-dependency> + <test-dependency> + <code-name-base>org.netbeans.modules.java.source.nbjavac</code-name-base> + <compile-dependency/> + <test/> + </test-dependency> <test-dependency> <code-name-base>org.netbeans.modules.nbjunit</code-name-base> <recursive/> diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavaWhereUsedQueryPlugin.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavaWhereUsedQueryPlugin.java index 1eb3d94f3..e1b7ec1b0 100644 --- a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavaWhereUsedQueryPlugin.java +++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavaWhereUsedQueryPlugin.java @@ -104,7 +104,7 @@ public Problem preCheck() { @Override protected Problem preCheck(CompilationController javac) throws IOException { - javac.toPhase(JavaSource.Phase.PARSED); + javac.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); TreePathHandle handle = refactoring.getRefactoringSource().lookup(TreePathHandle.class); if (handle.resolveElement(javac) == null) { return new Problem(true, NbBundle.getMessage(FindVisitor.class, "DSC_ElNotAvail")); // NOI18N diff --git a/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/FindUsagesJDK9Test.java b/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/FindUsagesJDK9Test.java new file mode 100644 index 000000000..4a59a13fe --- /dev/null +++ b/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/FindUsagesJDK9Test.java @@ -0,0 +1,167 @@ +/* + * 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.refactoring.java.test; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.ref.SoftReference; +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.logging.Logger; +import javax.lang.model.element.TypeElement; +import junit.framework.Test; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.java.queries.SourceLevelQuery; +import org.netbeans.api.java.source.*; +import org.netbeans.junit.NbModuleSuite; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.java.j2seplatform.platformdefinition.J2SEPlatformImpl; +import org.netbeans.modules.java.source.BootClassPathUtil; +import org.netbeans.modules.java.source.parsing.JavacParser; +import org.netbeans.modules.refactoring.api.RefactoringElement; +import org.netbeans.modules.refactoring.api.RefactoringSession; +import org.netbeans.modules.refactoring.api.WhereUsedQuery; +import org.netbeans.modules.refactoring.java.api.WhereUsedQueryConstants; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.EditableProperties; +import org.openide.util.lookup.Lookups; + +public class FindUsagesJDK9Test extends NbTestCase { + private FileObject projectDir; + private String origSourceLevel; + private static final Logger LOG = Logger.getLogger(FindUsagesTest.class.getName()); + + public FindUsagesJDK9Test(String name) { + super(name); + } + + /** + * Set-up the services and project + */ + @Override + protected void setUp() throws Exception { + clearWorkDir(); + String work = getWorkDirPath(); + System.setProperty("netbeans.user", work); + + JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true; + + //set -source 9 for the test project + origSourceLevel = setSourceLevel("9"); + + //ensure the default platform is "modular": + ClassPath moduleBoot = BootClassPathUtil.getModuleBootPath(); + JavaPlatform defaultPlatform = JavaPlatform.getDefault(); + Field bootstrapField = J2SEPlatformImpl.class.getDeclaredField("bootstrap"); + bootstrapField.setAccessible(true); + bootstrapField.set(defaultPlatform, new SoftReference<ClassPath>(moduleBoot) { + @Override + public ClassPath get() { + return moduleBoot; + } + }); + + projectDir = Utilities.openProject("SimpleJ2SEApp", getDataDir()); + SourceUtils.waitScanFinished(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + //reset source level + setSourceLevel(origSourceLevel); + } + + private String setSourceLevel(String newSourceLevel) throws IOException { + File projectsDir = FileUtil.normalizeFile(getDataDir()); + FileObject projectsDirFO = FileUtil.toFileObject(projectsDir); + FileObject projdir = projectsDirFO.getFileObject("SimpleJ2SEApp"); + + FileObject projectProperties = projdir.getFileObject("/nbproject/project.properties"); + EditableProperties editableProjectProperties = new EditableProperties(false); + try (InputStream in = projectProperties.getInputStream()) { + editableProjectProperties.load(in); + } + String originalJavacSource = editableProjectProperties.put("javac.source", newSourceLevel); + try (OutputStream out = projectProperties.getOutputStream()) { + editableProjectProperties.store(out); + } + return originalJavacSource; + } + + public void testAnotherFileNETBEANS721() throws Exception { + FileObject testFile = projectDir.getFileObject("/src/simplej2seapp/D.java"); + assertEquals("9", SourceLevelQuery.getSourceLevel(testFile)); + JavaSource src = JavaSource.forFileObject(testFile); + final WhereUsedQuery[] wuq = new WhereUsedQuery[1]; + src.runWhenScanFinished(new Task<CompilationController>() { + @Override + public void run(CompilationController controller) throws Exception { + controller.toPhase(JavaSource.Phase.RESOLVED); + TypeElement i = controller.getElements().getTypeElement("simplej2seapp.I"); + TreePathHandle element = TreePathHandle.create(i, controller); + wuq[0] = new WhereUsedQuery(Lookups.singleton(element)); + } + }, false).get(); + setParameters(wuq, true, false, false, false, false, false); + + doRefactoring("testAnotherFileNETBEANS721", wuq, 2); + } + + private void doRefactoring(final String name, final WhereUsedQuery[] wuq, final int amount) throws InterruptedException { + RefactoringSession rs = RefactoringSession.create("Session"); + + assertNull(wuq[0].preCheck()); + assertNull(wuq[0].fastCheckParameters()); + assertNull(wuq[0].checkParameters()); + assertNull(wuq[0].prepare(rs)); + rs.finished(); + rs.doRefactoring(true); + + Collection<RefactoringElement> elems = rs.getRefactoringElements(); + + LOG.fine(name); + for (RefactoringElement refactoringElement : elems) { + LOG.fine(refactoringElement.getParentFile().getNameExt()); + } + + assertEquals("Number of usages", amount, elems.size()); + } + + private void setParameters(final org.netbeans.modules.refactoring.api.WhereUsedQuery[] wuq, + boolean references, boolean comments, boolean subclasses, + boolean directSubclasses, boolean overriding, boolean fromBaseclass) { + wuq[0].putValue(WhereUsedQuery.FIND_REFERENCES, references); + wuq[0].putValue(WhereUsedQuery.SEARCH_IN_COMMENTS, comments); + wuq[0].putValue(WhereUsedQueryConstants.FIND_DIRECT_SUBCLASSES, directSubclasses); + wuq[0].putValue(WhereUsedQueryConstants.FIND_OVERRIDING_METHODS, overriding); + wuq[0].putValue(WhereUsedQueryConstants.FIND_SUBCLASSES, subclasses); + wuq[0].putValue(WhereUsedQueryConstants.SEARCH_FROM_BASECLASS, fromBaseclass); + } + + public static Test suite() throws InterruptedException { + return NbModuleSuite.createConfiguration(FindUsagesJDK9Test.class) + .clusters(".*").enableModules(".*") + .gui(false).suite(); + } +} ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For additional commands, e-mail: notifications-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists