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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
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;
Expand All @@ -63,11 +64,14 @@
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;
Expand Down Expand Up @@ -178,6 +182,44 @@ public void testModuleInfoBasedCp_SystemModules_in_NamedEmptyModule() throws IOE
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.classpath.JavaClassPathConstants;
import org.netbeans.api.java.platform.JavaPlatform;
import org.netbeans.api.java.queries.SourceLevelQuery;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport;
Expand Down Expand Up @@ -538,9 +539,17 @@ public ClassPath getActiveClassPath() {
if (ret == null) {
// see org.apache.maven.plugin.compiler.CompilerMojo.classpathElements
for (String sourceRoot : proj.getOriginalMavenProject().getCompileSourceRoots()) {
if(new File(sourceRoot, MODULE_INFO_JAVA).exists()) {
ret = hasModuleInfoCP.get();
LOGGER.log(Level.FINER, "ModuleInfoSelector {0} for project {1}: has module-info.java", new Object [] {logDesc, proj.getProjectDirectory().getPath()}); // NOI18N
final File moduleInfoFile = new File(sourceRoot, MODULE_INFO_JAVA);
Comment thread
errael marked this conversation as resolved.
if(moduleInfoFile.exists()) {
FileObject moduleInfo = FileUtil.toFileObject(moduleInfoFile);
String sourceLevel = SourceLevelQuery.getSourceLevel2(moduleInfo).getSourceLevel();
String ide_jdkvers = System.getProperty("java.version"); //NOI18N
if(!sourceLevel.startsWith("1.") && !ide_jdkvers.startsWith("1.")) { //NOI18N
// both sourceLevel and ideJDK are 9+
ret = hasModuleInfoCP.get();
}
final Object retObject = ret;
LOGGER.log(Level.FINER, () -> String.format("ModuleInfoSelector %s for project %s: has module-info.java %s", logDesc, proj.getProjectDirectory().getPath(), retObject == null ? "IGNORED" : "")); // NOI18N
break;
}
}
Expand Down