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 @@ -676,7 +676,7 @@ public List<? extends PathResourceImplementation> getResources() {
bestSoFar[1] = Boolean.TRUE;
return (List<? extends PathResourceImplementation>) bestSoFar[0];
}
final Collection<File> newModuleInfos = new ArrayDeque<>();
final Collection<File> newModuleInfos = new LinkedHashSet<>();
final List<URL> newActiveProjectSourceRoots = new ArrayList<>();
collectProjectSourceRoots(systemModules, newActiveProjectSourceRoots);
collectProjectSourceRoots(userModules, newActiveProjectSourceRoots);
Expand Down Expand Up @@ -922,9 +922,9 @@ public List<? extends PathResourceImplementation> getResources() {
newModuleInfos
});
setCache(res);
final Collection<File> added = new ArrayList<>(newModuleInfos);
final Collection<File> added = new LinkedHashSet<>(newModuleInfos);
added.removeAll(moduleInfos);
final Collection<File> removed = new ArrayList<>(moduleInfos);
final Collection<File> removed = new LinkedHashSet<>(moduleInfos);
removed.removeAll(newModuleInfos);
removed.stream().forEach((f) -> FileUtil.removeFileChangeListener(this, f));
added.stream().forEach((f) -> FileUtil.addFileChangeListener(this, f));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.netbeans.modules.java.api.common.TestProject;
import org.netbeans.modules.java.api.common.project.ProjectProperties;
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.ClassPathProvider;
Expand Down Expand Up @@ -583,6 +584,25 @@ public void testPatchModuleWithSourcePatch_UnscannedBaseModule() throws Exceptio
collectEntries(cp));
}

public void testDuplicateSourceDirsNETBEANS_817() throws Exception {
if (systemModules == null) {
System.out.println("No jdk 9 home configured."); //NOI18N
return;
}
assertNotNull(src);
final FileObject moduleInfo = createModuleInfo(src, "Modle", "java.logging"); //NOI18N
final ClassPath cp = ClassPathFactory.createClassPath(ModuleClassPaths.createModuleInfoBasedPath(
systemModules,
org.netbeans.spi.java.classpath.support.ClassPathSupport.createProxyClassPath(src, src),
systemModules,
ClassPath.EMPTY,
null,
null));
final Collection<URL> resURLs = collectEntries(cp);
final Collection<URL> expectedURLs = reads(systemModules, NamePredicate.create("java.logging")); //NOI18N
assertEquals(expectedURLs, resURLs);
}

private static void setSourceLevel(
@NonNull final Project prj,
@NonNull final String sourceLevel) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ boolean verifyAttributes(FileObject fo, boolean checkOnly) {
return vote;
}
}
final String cmpOptsStr = JavacParser.validateCompilerOptions(compilerOptions.getArguments())
final String cmpOptsStr = JavacParser.validateCompilerOptions(compilerOptions.getArguments(), null)
.stream()
.collect(Collectors.joining(" ")); //NOI18N
if (JavaIndex.ensureAttributeValue(url, COMPILER_OPTIONS, cmpOptsStr, checkOnly)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ private static JavacTaskImpl createJavacTask(
options.add("-proc:none"); // NOI18N, Disable annotation processors
}
if (compilerOptions != null) {
for (String compilerOption : validateCompilerOptions(compilerOptions.getArguments())) {
for (String compilerOption : validateCompilerOptions(compilerOptions.getArguments(), validatedSourceLevel)) {
options.add(compilerOption);
}
}
Expand Down Expand Up @@ -1029,8 +1029,9 @@ public static com.sun.tools.javac.code.Source validateSourceLevel(
}

@NonNull
public static List<? extends String> validateCompilerOptions(@NonNull final List<? extends String> options) {
public static List<? extends String> validateCompilerOptions(@NonNull final List<? extends String> options, @NullAllowed com.sun.tools.javac.code.Source sourceLevel) {
final List<String> res = new ArrayList<>();
boolean allowModularOptions = sourceLevel == null || com.sun.tools.javac.code.Source.lookup("9").compareTo(sourceLevel) <= 0;
boolean xmoduleSeen = false;
for (int i = 0; i < options.size(); i++) {
String option = options.get(i);
Expand All @@ -1047,12 +1048,13 @@ public static List<? extends String> validateCompilerOptions(@NonNull final List
xmoduleSeen = true;
} else if (option.equals("-parameters") || option.startsWith("-Xlint")) { //NOI18N
res.add(option);
} else if (
} else if ((
option.startsWith("--add-modules") || //NOI18N
option.startsWith("--limit-modules") || //NOI18N
option.startsWith("--add-exports") || //NOI18N
option.startsWith("--add-reads") ||
option.startsWith(OPTION_PATCH_MODULE)) {
option.startsWith(OPTION_PATCH_MODULE)) &&
allowModularOptions) {
int idx = option.indexOf('=');
if (idx > 0) {
res.add(option);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -393,7 +395,18 @@ private Source guessSourceLevel(boolean objectOnBCP, boolean sbOnCP, boolean acO

return JavacParser.validateSourceLevel("1.7", info, false);
}


public void testValidateCompilerOptions() {
List<String> input = Arrays.asList("--add-exports", "foo/bar=foobar",
"--add-exports=foo2/bar=foobar",
"--limit-modules", "foo",
"--add-modules", "foo",
"--add-reads", "foo=foo2");
assertEquals(Collections.emptyList(), JavacParser.validateCompilerOptions(input, com.sun.tools.javac.code.Source.lookup("1.8")));
assertEquals(input, JavacParser.validateCompilerOptions(input, com.sun.tools.javac.code.Source.lookup("9")));
assertEquals(input, JavacParser.validateCompilerOptions(input, com.sun.tools.javac.code.Source.lookup("10")));
}

private FileObject createFile(String path, String content) throws Exception {
FileObject file = FileUtil.createData(sourceRoot, path);
TestUtilities.copyStringToFile(file, content);
Expand Down