Skip to content

Commit

Permalink
[WFCORE-6498] Correct the LayersTest handling of alias modules
Browse files Browse the repository at this point in the history
  • Loading branch information
bstansberry committed Nov 7, 2023
1 parent 4d54569 commit 20596a3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
<module name="java.xml"/>
<!-- Workaround for ELY-1561 -->
<module name="jdk.security.auth"/>
<module name="io.smallrye.jandex"/>
<!--this needs to remain here until common-beans is fixed to use passed classloader -->
<module name="org.jboss.common-beans" services="export" optional="true"/>

<module name="org.jboss.staxmapper"/>
<module name="org.jboss.dmr"/>
<module name="org.jboss.classfilewriter"/>
<module name="org.jboss.invocation"/>
<module name="org.jboss.jandex"/>
<module name="org.jboss.marshalling"/>
<module name="org.jboss.marshalling.river" services="import"/>
<module name="org.jboss.modules"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ public static void testLayersModuleUse(Set<String> unused, ScanContext scanConte
appendResult(k, layers.get(k), builder, reference);
}


// The only modules that are expected to be not provisioned are the un-used ones.
// If more are not provisioned, then we are missing some modules.
String missingRequired = listModules(deltaModules, m -> !unused.contains(m));
final Set<String> referenceAliases = reference.getAliases(); // don't require callers to include alias modules in 'unused'
String missingRequired = listModules(deltaModules, m -> !unused.contains(m) && !referenceAliases.contains(m));
if (!missingRequired.isEmpty()) {
String error = "Some expected modules have not been provisioned in " + ALL_LAYERS;
builder.append("#!!!!!ERROR ").append(error).append("\n");
Expand Down Expand Up @@ -198,11 +200,18 @@ public static void testUnreferencedModules(Set<String> unreferenced, ScanContext
// Check that the reference has no more un-referenced modules than the expected ones.
Set<String> allUnReferenced = new HashSet<>(unreferenced);
final Set<String> refUnreferenced = reference.getNotReferenced();
String invalidUnref = listModules(refUnreferenced, m -> !allUnReferenced.contains(m));
final Set<String> referenceAliases = reference.getAliases(); // don't require callers to include alias modules in 'unreferenced'
String invalidUnref = listModules(refUnreferenced, m -> !allUnReferenced.contains(m) && !referenceAliases.contains(m));
if (!invalidUnref.isEmpty()) {
appendExceptionMsg(exceptionBuilder, "Some unreferenced modules are unexpected " + invalidUnref, empty);
}

// Check that alias modules are not referenced
String referencedAlias = listModules(referenceAliases, m -> !refUnreferenced.contains(m));
if (!referencedAlias.isEmpty()) {
appendExceptionMsg(exceptionBuilder, "Some alias modules are referenced " + referencedAlias, empty);
}

if (VALIDATE_INPUTS) {

// Confirm that 'unreferenced' modules actually exist in the reference installation
Expand Down Expand Up @@ -463,6 +472,11 @@ private static Set<String> appendResult(String title, Result result, StringBuild
notReferenced.append(s).append(",");
}
builder.append("unreferenced_modules=").append(notReferenced).append("\n");
StringBuilder aliases = new StringBuilder();
for (String s : result.getAliases()) {
aliases.append(s).append(",");
}
builder.append("alias_modules=").append(aliases).append("\n");
builder.append("num_unresolved=").append(optionals.size()).append("\n");
}
for (Map.Entry<String, Set<String>> entry : optionals.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ public String getModule() {
private final Map<String, Set<String>> unresolvedOptional;
private final Set<String> modules;
private final Set<String> notReferenced;
private final Set<String> aliases;
private final List<ExtensionResult> extensions;

Result(long size, Set<String> modules, Map<String, Set<String>> unresolvedOptional, Set<String> notReferenced, List<ExtensionResult> extensions) {
Result(long size, Set<String> modules, Map<String, Set<String>> unresolvedOptional, Set<String> notReferenced,
Set<String> aliases, List<ExtensionResult> extensions) {
this.size = size;
this.modules = modules;
this.unresolvedOptional = unresolvedOptional;
this.notReferenced = notReferenced;
this.aliases = aliases;
this.extensions = extensions;
}

Expand Down Expand Up @@ -98,6 +101,13 @@ public Set<String> getNotReferenced() {
return notReferenced;
}

/**
* @return the aliases
*/
public Set<String> getAliases() {
return aliases;
}

/**
* @return the extensions
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Result scan(Path homePath, Path configFile) throws Exception {
Map<String, Set<String>> optionalDependencies = new TreeMap<>();
List<Long> size = new ArrayList<>();
size.add((long) 0);
Files.walkFileTree(homePath, new SimpleFileVisitor<Path>() {
Files.walkFileTree(homePath, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
size.set(0, size.get(0) + attrs.size());
Expand All @@ -50,7 +50,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
});
Map<String, Set<String>> modulesReference = new HashMap<>();
Set<String> modules = new HashSet<>();
Files.walkFileTree(modulePath, new SimpleFileVisitor<Path>() {
Set<String> aliases = new HashSet<>();
Files.walkFileTree(modulePath, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
Expand All @@ -63,13 +64,13 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
Document document = documentBuilder.parse(file.toFile());
Element elemAlias = (Element) document.getElementsByTagName("module-alias").item(0);
if (elemAlias != null) {
// Track both the alias and the target, with the alias treated as a ref to target
String moduleName = elemAlias.getAttribute("name");
aliases.add(moduleName);
modules.add(moduleName);
modulesReference.computeIfAbsent(moduleName, k -> new HashSet<>());
String target = elemAlias.getAttribute("target-name");
Set<String> referencing = modulesReference.get(target);
if (referencing == null) {
referencing = new HashSet<>();
modulesReference.put(target, referencing);
}
Set<String> referencing = modulesReference.computeIfAbsent(target, k -> new HashSet<>());
referencing.add(moduleName);
return FileVisitResult.CONTINUE;
}
Expand All @@ -93,11 +94,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
optionals.add(mod);
}
}
Set<String> referencing = modulesReference.get(mod);
if (referencing == null) {
referencing = new HashSet<>();
modulesReference.put(mod, referencing);
}
Set<String> referencing = modulesReference.computeIfAbsent(mod, k -> new HashSet<>());
referencing.add(moduleName);
}
}
Expand All @@ -112,8 +109,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e)
throws IOException {
public FileVisitResult postVisitDirectory(Path dir, IOException e) {
return FileVisitResult.CONTINUE;
}
}
Expand All @@ -123,11 +119,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e)
for (Map.Entry<String, Set<String>> entry : optionalDependencies.entrySet()) {
for (String opt : entry.getValue()) {
if (!modules.contains(opt)) {
Set<String> roots = missing.get(opt);
if (roots == null) {
roots = new TreeSet<>();
missing.put(opt, roots);
}
Set<String> roots = missing.computeIfAbsent(opt, k -> new TreeSet<>());
roots.add(entry.getKey());
}
}
Expand Down Expand Up @@ -198,7 +190,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e)
extensionResults.add(new Result.ExtensionResult(ex, extSize.get(0) / 1024, deps, unresolved));
}

return new Result(size.get(0) / 1024, modules, missing, allNotReferenced, extensionResults);
return new Result(size.get(0) / 1024, modules, missing, allNotReferenced, aliases, extensionResults);
}

private static Set<String> retrieveExtensionModules(Path conf) throws Exception {
Expand Down Expand Up @@ -240,7 +232,7 @@ private static void getDependencies(Path modulePath, String module, Set<String>
return;
}
// Add content size.
Files.walkFileTree(path.getParent(), new SimpleFileVisitor<Path>() {
Files.walkFileTree(path.getParent(), new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
size.set(0, size.get(0) + attrs.size());
Expand Down

0 comments on commit 20596a3

Please sign in to comment.