Skip to content

Commit

Permalink
Fixing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
lahodaj committed Oct 27, 2023
1 parent f59bc65 commit 9de10d1
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ private void loadVersionClasses(ClassList classes,
}
}

ExcludeIncludeList currentEIList = excludesIncludes;
ExcludeIncludeList currentEIList;

if (!currentVersionModules.isEmpty()) {
Set<String> privateIncludes =
Expand All @@ -1523,22 +1523,72 @@ private void loadVersionClasses(ClassList classes,
currentEIList = new ExcludeIncludeList(includes,
privateIncludes,
Collections.emptySet());
} else {
currentEIList = excludesIncludes;
}

ClassList currentVersionClasses = new ClassList();
Map<String, String> extraModulesPackagesToDerive = new HashMap<>();

for (byte[] classFileData : classData) {
try (InputStream in = new ByteArrayInputStream(classFileData)) {
inspectClassFile(in, currentVersionClasses,
currentEIList, version);
currentEIList, version,
cf -> {
PermittedSubclasses_attribute permitted = (PermittedSubclasses_attribute) cf.getAttribute(Attribute.PermittedSubclasses);
if (permitted != null) {
try {
String currentPack = cf.getName().substring(0, cf.getName().lastIndexOf('/'));

for (int i = 0; i < permitted.subtypes.length; i++) {
String permittedClassName = cf.constant_pool.getClassInfo(permitted.subtypes[i]).getName();
if (!currentEIList.accepts(permittedClassName, false)) {
String permittedPack = permittedClassName.substring(0, permittedClassName.lastIndexOf('/'));

extraModulesPackagesToDerive.put(permittedPack, currentPack);
}
}
} catch (ConstantPoolException ex) {
throw new IllegalStateException(ex);
}
}
});
} catch (IOException | ConstantPoolException ex) {
throw new IllegalStateException(ex);
}
}

//derive extra module packages for permitted types based on on their supertypes:
boolean modified;

do {
modified = false;

for (Iterator<Entry<String, String>> it = extraModulesPackagesToDerive.entrySet().iterator(); it.hasNext();) {
Entry<String, String> e = it.next();
Optional<ModuleHeaderDescription> module = currentVersionModules.values().stream().map(md -> md.header.get(0)).filter(d -> containsPackage(d, e.getValue())).findAny();
if (module.isPresent()) {
if (!module.get().extraModulePackages.contains(e.getKey())) {
module.get().extraModulePackages.add(e.getKey());
}
it.remove();
modified = true;
}
}
} while (modified);

if (!extraModulesPackagesToDerive.isEmpty()) {
throw new AssertionError("Cannot derive some owning modules: " + extraModulesPackagesToDerive);
}

finishClassLoading(classes, modules, currentVersionModules, currentVersionClasses, currentEIList, version, baseline);
}

private boolean containsPackage(ModuleHeaderDescription module, String pack) {
return module.exports.stream().filter(ed -> ed.packageName().equals(pack)).findAny().isPresent() ||
module.extraModulePackages.contains(pack);
}

private void loadVersionClassesFromDirectory(ClassList classes,
Map<String, ModuleDescription> modules,
Path modulesDirectory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
var createSymbolsClass = Class.forName("build.tools.symbolgenerator.CreateSymbols", false, cl);
var main = createSymbolsClass.getMethod("main", String[].class);
var symbols = targetDir.resolve("symbols");
var systemModules = targetDir.resolve("system-modules");
var modules = targetDir.resolve("modules");

try (Writer w = Files.newBufferedWriter(symbols)) {}
try (Writer w = Files.newBufferedWriter(systemModules)) {}
Files.createDirectories(modules);

main.invoke(null,
(Object) new String[] {"build-description-incremental",
Expand All @@ -126,7 +126,7 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
targetDir.resolve("ct.sym").toAbsolutePath().toString(),
Long.toString(System.currentTimeMillis() / 1000),
"" + SourceVersion.latest().ordinal(),
systemModules.toAbsolutePath().toString()});
modules.toAbsolutePath().toString()});
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NonExportedPermittedTypes.java:41:9: compiler.err.not.exhaustive.statement
NonExportedPermittedTypes.java:40:9: compiler.err.not.exhaustive.statement
1 error
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,14 @@ void doTestComplex(String printClass,
};
new CreateSymbols().createBaseLine(versions, acceptAll, ctSym, new String[0]);
Path symbolsDesc = ctSym.resolve("symbols");
Path systemModules = ctSym.resolve("systemModules");
Path modules = ctSym.resolve("modules");

Files.newBufferedWriter(systemModules).close();
Files.createDirectories(modules);

Path classesZip = output.resolve("classes.zip");
Path classesDir = output.resolve("classes");

new CreateSymbols().createSymbols(null, symbolsDesc.toAbsolutePath().toString(), classesZip.toAbsolutePath().toString(), 0, "9", systemModules.toString());
new CreateSymbols().createSymbols(null, symbolsDesc.toAbsolutePath().toString(), classesZip.toAbsolutePath().toString(), 0, "9", modules.toString());

try (JarFile jf = new JarFile(classesZip.toFile())) {
Enumeration<JarEntry> en = jf.entries();
Expand Down Expand Up @@ -1037,12 +1037,12 @@ protected boolean includeEffectiveAccess(ClassList classes, ClassDescription cla
}
}.createBaseLine(versions, acceptAll, descDest, new String[0]);
Path symbolsDesc = descDest.resolve("symbols");
Path systemModules = descDest.resolve("systemModules");
Path modules = descDest.resolve("modules");

Files.newBufferedWriter(systemModules).close();
Files.createDirectories(modules);

try {
new CreateSymbols().createSymbols(null, symbolsDesc.toAbsolutePath().toString(), classDest, 0, "8", systemModules.toString());
new CreateSymbols().createSymbols(null, symbolsDesc.toAbsolutePath().toString(), classDest, 0, "8", modules.toString());
} catch (Throwable t) {
t.printStackTrace();
throw t;
Expand Down

0 comments on commit 9de10d1

Please sign in to comment.