You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2020/03/20 06:21:28 UTC

[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #2037: Ignore module-info.java if on jdk1.8 or earlier.

JaroslavTulach commented on a change in pull request #2037: Ignore module-info.java if on jdk1.8 or earlier.
URL: https://github.com/apache/netbeans/pull/2037#discussion_r395454316
 
 

 ##########
 File path: java/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ModuleClassPaths.java
 ##########
 @@ -786,6 +787,12 @@ private static boolean hasModuleInfo(@NonNull final File file) {
                             newModuleInfos.add(moduleInfo);
                             if (found == null) {
                                 found = FileUtil.toFileObject(moduleInfo);
+                                if (found != null) {
+                                    String sourceLevel = SourceLevelQuery.getSourceLevel(found);
+                                    if (sourceLevel != null && sourceLevel.startsWith("1.")) { //NOI18N
+                                        found = null;
 
 Review comment:
   It would be good to cover this change with a test. I am not sure if `java.api.common` tests are actually executed by travis, but following would be my test:
   ```diffdiff --git a/java/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/classpath/ModuleClassPathsTest.java b/java/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/classpath/ModuleClassPathsTest.java
   index b30f8246bdb7..1c0ba04a674a 100644
   --- a/java/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/classpath/ModuleClassPathsTest.java
   +++ b/java/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/classpath/ModuleClassPathsTest.java
   @@ -46,6 +46,7 @@ import java.util.stream.Collectors;
    import java.util.zip.ZipEntry;
    import javax.lang.model.element.ModuleElement;
    import javax.swing.event.ChangeListener;
   +import org.junit.Assume;
    import org.netbeans.api.annotations.common.CheckForNull;
    import org.netbeans.api.annotations.common.NonNull;
    import org.netbeans.api.annotations.common.NullAllowed;
   @@ -63,11 +64,14 @@ import org.netbeans.junit.NbTestCase;
    import org.netbeans.modules.java.api.common.TestJavaPlatform;
    import org.netbeans.modules.java.api.common.TestProject;
    import org.netbeans.modules.java.api.common.project.ProjectProperties;
   +import org.netbeans.modules.java.classpath.SimpleClassPathImplementation;
    import org.netbeans.modules.java.j2seplatform.platformdefinition.Util;
    import org.netbeans.modules.java.source.BootClassPathUtil;
    import org.netbeans.modules.parsing.api.indexing.IndexingManager;
    import org.netbeans.spi.java.classpath.ClassPathFactory;
   +import org.netbeans.spi.java.classpath.ClassPathImplementation;
    import org.netbeans.spi.java.classpath.ClassPathProvider;
   +import org.netbeans.spi.java.classpath.PathResourceImplementation;
    import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation;
    import org.netbeans.spi.project.support.ant.AntProjectHelper;
    import org.netbeans.spi.project.support.ant.EditableProperties;
   @@ -178,6 +182,44 @@ public class ModuleClassPathsTest extends NbTestCase {
            assertEquals(expectedURLs, resURLs);
        }
    
   +    public void testModuleInfoInJDK8Project() throws IOException {
   +        assertNotNull(src);
   +        createModuleInfo(src, "ModuleInfoDebris"); //NOI18N
   +        setSourceLevel(tp, "1.8");   //NOI18N
   +        final ClassPath base = systemModules == null ? ClassPath.EMPTY : systemModules;
   +        final ClassPathImplementation mcp = ModuleClassPaths.createModuleInfoBasedPath(
   +            base,
   +            src,
   +            base,
   +            ClassPath.EMPTY,
   +            null,
   +            null
   +        );
   +        List<? extends PathResourceImplementation> resources = mcp.getResources();
   +        assertEquals("No resources found as module-info.java is ignored: " + resources, 0, resources.size());
   +    }
   +
   +    public void testModuleInfoInJDK11Project() throws IOException {
   +        if (systemModules == null) {
   +            System.out.println("No jdk 9 home configured.");    //NOI18N
   +            return;
   +        }
   +
   +        assertNotNull(src);
   +        createModuleInfo(src, "ModuleInfoUsed"); //NOI18N
   +        final ClassPath base = systemModules;
   +        final ClassPathImplementation mcp = ModuleClassPaths.createModuleInfoBasedPath(
   +            base,
   +            src,
   +            base,
   +            ClassPath.EMPTY,
   +            null,
   +            null
   +        );
   +        List<? extends PathResourceImplementation> one = mcp.getResources();
   +        assertEquals("One resource found as module-info.java is used: " + one, 1, one.size());
   +    }
   +
        public void testModuleInfoBasedCp_SystemModules_in_NamedModule() throws IOException {
            if (systemModules == null) {
                System.out.println("No jdk 9 home configured.");    //NOI18N
   ```
   I was able to successfully run it on JDK8:
   ```bash
   java/java.api.common$ JAVA_HOME=$HOME/bin/jdk1.8.0 ant test -Dtest.includes=**/ModuleClassPathsTest.class
   ```
   as well as on JDK11:
   ```bash
   java/java.api.common$ JAVA_HOME=$HOME/bin/jdk-11 ant test -Dtest.includes=**/ModuleClassPathsTest.class -Dtest.nbjdk.home=$HOME/bin/jdk-11 -Dtest.run.args=--limit-modules=java.base,java.logging,java.xml,java.prefs,java.desktop,java.management,java.instrument,jdk.zipfs,java.scripting,java.naming -Dtest.bootclasspath.prepend.args=-Dno.netbeans.bootclasspath.prepend.needed=true
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists