8188035: JavaFileManager.listLocationsForModules does not always reflect values set through StandardJavaFileManager.setLocationForModule
Prepending explictely set module locations in listLocationsForModules. Reviewed-by: jjg
This commit is contained in:
parent
6f27933eb4
commit
d84d8f1cc5
src/jdk.compiler/share/classes/com/sun/tools/javac/file
test/langtools/tools/javac/file
@ -88,7 +88,7 @@ import com.sun.tools.javac.util.JDK9Wrappers;
|
|||||||
import com.sun.tools.javac.util.ListBuffer;
|
import com.sun.tools.javac.util.ListBuffer;
|
||||||
import com.sun.tools.javac.util.Log;
|
import com.sun.tools.javac.util.Log;
|
||||||
import com.sun.tools.javac.jvm.ModuleNameReader;
|
import com.sun.tools.javac.jvm.ModuleNameReader;
|
||||||
import com.sun.tools.javac.util.Assert;
|
import com.sun.tools.javac.util.Iterators;
|
||||||
import com.sun.tools.javac.util.Pair;
|
import com.sun.tools.javac.util.Pair;
|
||||||
import com.sun.tools.javac.util.StringUtils;
|
import com.sun.tools.javac.util.StringUtils;
|
||||||
|
|
||||||
@ -964,6 +964,7 @@ public class Locations {
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final String moduleName;
|
private final String moduleName;
|
||||||
private final boolean output;
|
private final boolean output;
|
||||||
|
boolean explicit;
|
||||||
Collection<Path> searchPath;
|
Collection<Path> searchPath;
|
||||||
|
|
||||||
ModuleLocationHandler(LocationHandler parent, String name, String moduleName,
|
ModuleLocationHandler(LocationHandler parent, String name, String moduleName,
|
||||||
@ -1083,6 +1084,14 @@ public class Locations {
|
|||||||
Set<Location> locations() {
|
Set<Location> locations() {
|
||||||
return Collections.unmodifiableSet(nameMap.values().stream().collect(Collectors.toSet()));
|
return Collections.unmodifiableSet(nameMap.values().stream().collect(Collectors.toSet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<Location> explicitLocations() {
|
||||||
|
return Collections.unmodifiableSet(nameMap.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(e -> e.getValue().explicit)
|
||||||
|
.map(e -> e.getValue())
|
||||||
|
.collect(Collectors.toSet()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1119,10 +1128,20 @@ public class Locations {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
Iterable<Set<Location>> listLocationsForModules() {
|
Iterable<Set<Location>> listLocationsForModules() {
|
||||||
if (searchPath == null)
|
Set<Location> explicitLocations = moduleTable != null ?
|
||||||
return Collections.emptyList();
|
moduleTable.explicitLocations() : Collections.emptySet();
|
||||||
|
Iterable<Set<Location>> explicitLocationsList = !explicitLocations.isEmpty()
|
||||||
|
? Collections.singletonList(explicitLocations)
|
||||||
|
: Collections.emptyList();
|
||||||
|
|
||||||
return ModulePathIterator::new;
|
if (searchPath == null)
|
||||||
|
return explicitLocationsList;
|
||||||
|
|
||||||
|
Iterable<Set<Location>> searchPathLocations =
|
||||||
|
() -> new ModulePathIterator();
|
||||||
|
return () -> Iterators.createCompoundIterator(Arrays.asList(explicitLocationsList,
|
||||||
|
searchPathLocations),
|
||||||
|
Iterable::iterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1159,6 +1178,7 @@ public class Locations {
|
|||||||
l.searchPath = checkedPaths;
|
l.searchPath = checkedPaths;
|
||||||
moduleTable.updatePaths(l);
|
moduleTable.updatePaths(l);
|
||||||
}
|
}
|
||||||
|
l.explicit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Path> checkPaths(Iterable<? extends Path> paths) throws IOException {
|
private List<Path> checkPaths(Iterable<? extends Path> paths) throws IOException {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8173914
|
* @bug 8173914 8188035
|
||||||
* @summary JavaFileManager.setLocationForModule
|
* @summary JavaFileManager.setLocationForModule
|
||||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||||
* jdk.compiler/com.sun.tools.javac.main
|
* jdk.compiler/com.sun.tools.javac.main
|
||||||
@ -42,8 +42,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.tools.JavaCompiler;
|
import javax.tools.JavaCompiler;
|
||||||
|
import javax.tools.JavaFileManager;
|
||||||
import javax.tools.JavaFileManager.Location;
|
import javax.tools.JavaFileManager.Location;
|
||||||
import javax.tools.StandardJavaFileManager;
|
import javax.tools.StandardJavaFileManager;
|
||||||
import javax.tools.StandardLocation;
|
import javax.tools.StandardLocation;
|
||||||
@ -112,14 +114,35 @@ public class SetLocationForModule extends TestRunner {
|
|||||||
checkEqual("override setting 1",
|
checkEqual("override setting 1",
|
||||||
fm.getLocationAsPaths(m), override1);
|
fm.getLocationAsPaths(m), override1);
|
||||||
|
|
||||||
|
checkEqual("override setting 1b",
|
||||||
|
fm.getLocationAsPaths(fm.listLocationsForModules(locn).iterator().next().iterator().next()),
|
||||||
|
override1);
|
||||||
|
|
||||||
|
try (StandardJavaFileManager fm2 = comp.getStandardFileManager(null, null, null)) {
|
||||||
|
fm2.setLocationForModule(locn, "m", List.of(override1));
|
||||||
|
checkEqual("override setting 2",
|
||||||
|
fm2.getLocationAsPaths(m), override1);
|
||||||
|
|
||||||
|
checkEqual("override setting 2b",
|
||||||
|
fm2.getLocationAsPaths(fm2.listLocationsForModules(locn).iterator().next().iterator().next()),
|
||||||
|
override1);
|
||||||
|
}
|
||||||
|
|
||||||
Path override2 = Files.createDirectories(base.resolve("override2"));
|
Path override2 = Files.createDirectories(base.resolve("override2"));
|
||||||
fm.setLocationFromPaths(m, List.of(override2));
|
fm.setLocationFromPaths(m, List.of(override2));
|
||||||
checkEqual("override setting 2",
|
checkEqual("override setting 3",
|
||||||
fm.getLocationAsPaths(m), override2);
|
fm.getLocationAsPaths(m), override2);
|
||||||
|
|
||||||
Path modules2 = Files.createDirectories(base.resolve("modules2"));
|
Path modules2 = Files.createDirectories(base.resolve("modules2"));
|
||||||
|
new JavacTask(tb)
|
||||||
|
.outdir(modules2)
|
||||||
|
.options("--module-source-path", src.toString())
|
||||||
|
.files(tb.findJavaFiles(src))
|
||||||
|
.run();
|
||||||
fm.setLocationFromPaths(locn, List.of(modules2));
|
fm.setLocationFromPaths(locn, List.of(modules2));
|
||||||
|
|
||||||
|
m = fm.getLocationForModule(locn, "m");
|
||||||
|
|
||||||
checkEqual("updated setting",
|
checkEqual("updated setting",
|
||||||
fm.getLocationAsPaths(m), modules2.resolve("m"));
|
fm.getLocationAsPaths(m), modules2.resolve("m"));
|
||||||
}
|
}
|
||||||
@ -147,6 +170,10 @@ public class SetLocationForModule extends TestRunner {
|
|||||||
checkEqual("override setting 1",
|
checkEqual("override setting 1",
|
||||||
fm.getLocationAsPaths(m), override1);
|
fm.getLocationAsPaths(m), override1);
|
||||||
|
|
||||||
|
checkEqual("override setting 1b",
|
||||||
|
fm.getLocationAsPaths(fm.listLocationsForModules(locn).iterator().next().iterator().next()),
|
||||||
|
override1);
|
||||||
|
|
||||||
Path override2 = Files.createDirectories(base.resolve("override2"));
|
Path override2 = Files.createDirectories(base.resolve("override2"));
|
||||||
tb.writeJavaFiles(override2, "module m { }");
|
tb.writeJavaFiles(override2, "module m { }");
|
||||||
fm.setLocationFromPaths(m, List.of(override2));
|
fm.setLocationFromPaths(m, List.of(override2));
|
||||||
@ -159,6 +186,8 @@ public class SetLocationForModule extends TestRunner {
|
|||||||
// fm.setLocationFromPaths(locn, List.of(src2));
|
// fm.setLocationFromPaths(locn, List.of(src2));
|
||||||
fm.handleOption("--module-source-path", List.of(src2.toString()).iterator());
|
fm.handleOption("--module-source-path", List.of(src2.toString()).iterator());
|
||||||
|
|
||||||
|
m = fm.getLocationForModule(locn, "m");
|
||||||
|
|
||||||
checkEqual("updated setting",
|
checkEqual("updated setting",
|
||||||
fm.getLocationAsPaths(m), src2.resolve("m"));
|
fm.getLocationAsPaths(m), src2.resolve("m"));
|
||||||
}
|
}
|
||||||
@ -181,6 +210,10 @@ public class SetLocationForModule extends TestRunner {
|
|||||||
checkEqual("override setting 1",
|
checkEqual("override setting 1",
|
||||||
fm.getLocationAsPaths(m), override1);
|
fm.getLocationAsPaths(m), override1);
|
||||||
|
|
||||||
|
checkEqual("override setting 1b",
|
||||||
|
fm.getLocationAsPaths(fm.listLocationsForModules(locn).iterator().next().iterator().next()),
|
||||||
|
override1);
|
||||||
|
|
||||||
Path override2 = Files.createDirectories(base.resolve("override2"));
|
Path override2 = Files.createDirectories(base.resolve("override2"));
|
||||||
fm.setLocationFromPaths(m, List.of(override2));
|
fm.setLocationFromPaths(m, List.of(override2));
|
||||||
checkEqual("override setting 2",
|
checkEqual("override setting 2",
|
||||||
@ -189,6 +222,8 @@ public class SetLocationForModule extends TestRunner {
|
|||||||
Path out2 = Files.createDirectories(base.resolve("out2"));
|
Path out2 = Files.createDirectories(base.resolve("out2"));
|
||||||
fm.setLocationFromPaths(locn, List.of(out2));
|
fm.setLocationFromPaths(locn, List.of(out2));
|
||||||
|
|
||||||
|
m = fm.getLocationForModule(locn, "m");
|
||||||
|
|
||||||
checkEqual("updated setting",
|
checkEqual("updated setting",
|
||||||
fm.getLocationAsPaths(m), out2.resolve("m"));
|
fm.getLocationAsPaths(m), out2.resolve("m"));
|
||||||
}
|
}
|
||||||
@ -259,6 +294,10 @@ public class SetLocationForModule extends TestRunner {
|
|||||||
checkEqual("override setting 1",
|
checkEqual("override setting 1",
|
||||||
fm.getLocationAsPaths(javaCompiler), override1);
|
fm.getLocationAsPaths(javaCompiler), override1);
|
||||||
|
|
||||||
|
checkEqual("override setting 1b",
|
||||||
|
fm.getLocationAsPaths(findLocation(fm, fm.listLocationsForModules(locn), "java.compiler")),
|
||||||
|
override1);
|
||||||
|
|
||||||
Path override2 = Files.createDirectories(base.resolve("override2"));
|
Path override2 = Files.createDirectories(base.resolve("override2"));
|
||||||
fm.setLocationFromPaths(javaCompiler, List.of(override2));
|
fm.setLocationFromPaths(javaCompiler, List.of(override2));
|
||||||
checkEqual("override setting 2",
|
checkEqual("override setting 2",
|
||||||
@ -266,6 +305,22 @@ public class SetLocationForModule extends TestRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Location findLocation(JavaFileManager fm, Iterable<Set<Location>> locations, String moduleName) {
|
||||||
|
for (Set<Location> locs : locations) {
|
||||||
|
for (Location loc : locs) {
|
||||||
|
try {
|
||||||
|
if (moduleName.equals(fm.inferModuleName(loc))) {
|
||||||
|
return loc;
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new IllegalStateException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTemplate(Path base) {
|
public void testTemplate(Path base) {
|
||||||
// set a top default
|
// set a top default
|
||||||
@ -302,7 +357,7 @@ public class SetLocationForModule extends TestRunner {
|
|||||||
void checkEqual(String message, Iterable<? extends Path> found, Path... expect) {
|
void checkEqual(String message, Iterable<? extends Path> found, Path... expect) {
|
||||||
List<Path> fList = asList(found);
|
List<Path> fList = asList(found);
|
||||||
List<Path> eList = List.of(expect);
|
List<Path> eList = List.of(expect);
|
||||||
if (!Objects.equals(fList, fList)) {
|
if (!Objects.equals(fList, eList)) {
|
||||||
error(message + ": lists not equal\n"
|
error(message + ": lists not equal\n"
|
||||||
+ "expect: " + eList + "\n"
|
+ "expect: " + eList + "\n"
|
||||||
+ " found: " + fList);
|
+ " found: " + fList);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user