Skip to content

Commit

Permalink
[GR-47777] Support @AddModules annotations in unit tests
Browse files Browse the repository at this point in the history
PullRequest: mx/1650
  • Loading branch information
gergo- committed Aug 5, 2023
2 parents 76312a4 + abf0d59 commit a35a315
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 11 deletions.
24 changes: 17 additions & 7 deletions ci/common.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,17 @@ local common_json = import "../common.json";
mount_modules: true,
},
},
local ol9 = {
docker+: {
image: "buildslave_ol9",
mount_modules: true,
},
},
local ubuntu22 = {
docker: {
image: "buildslave_ubuntu22",
mount_modules: true,
},
docker+: {
image: "buildslave_ubuntu22",
mount_modules: true,
},
},
local deps_linux = {
},
Expand All @@ -256,17 +262,21 @@ local common_json = import "../common.json";

local amd64 = { arch:: "amd64", capabilities+: [self.arch] },
local aarch64 = { arch:: "aarch64", capabilities+: [self.arch] },
local ol_distro = {os_distro:: "ol"},

linux_amd64: linux + amd64 + ol7,
linux_amd64_ubuntu: linux + amd64 + ubuntu22,
linux_aarch64: linux + aarch64,
linux_amd64: linux + amd64 + ol7 + ol_distro,
linux_amd64_ubuntu: linux + amd64 + ubuntu22 + {os_distro:: "ubuntu"},
linux_amd64_ol9: linux + amd64 + ol9 + ol_distro,
linux_aarch64: linux + aarch64 + ol_distro,
linux_aarch64_ol9: linux + aarch64 + ol9 + ol_distro,

darwin_amd64: darwin + amd64,
darwin_aarch64: darwin + aarch64,

windows_amd64: windows + amd64,
windows_server_2016_amd64: windows_server_2016 + amd64,


# Utils
disable_proxies: {
setup+: [
Expand Down
2 changes: 1 addition & 1 deletion common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Jsonnet files should not include this file directly but use ci/common.jsonnet instead."
],

"mx_version": "6.34.0",
"mx_version": "6.35.1",

"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
"jdks": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,29 @@ void processAddExportsAnnotations(Set<Class<?>> classes, Set<String> opened, Set
}
}

void processAddModulesAnnotations(Set<Class<?>> classes) {
Set<Class<?>> types = new HashSet<>();
for (Class<?> cls : classes) {
gatherSupertypes(cls, types);
}
for (Class<?> cls : types) {
Annotation[] annos = cls.getAnnotations();
for (Annotation a : annos) {
Class<? extends Annotation> annotationType = a.annotationType();
if (annotationType.getSimpleName().equals("AddModules")) {
Optional<String[]> value = getElement("value", String[].class, a);
if (value.isPresent()) {
for (String spec : value.get()) {
Modules.loadModule(spec);
}
} else {
out.printf("%s: Ignoring \"AddModules\" annotation without `String value` element: %s%n", cls.getName(), a);
}
}
}
}
}

public static List<Module> findModules(String spec) {
ModuleLayer bootLayer = ModuleLayer.boot();
Set<Module> modules = bootLayer.modules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ void openPackages(String spec, Object context, Set<String> opened, Set<String> e
void processAddExportsAnnotations(Set<Class<?>> classes, Set<String> opened, Set<String> exported) {
// Nop on JDK 8
}

/**
* Loads modules specified in {@code AddModules} annotations on {@code classes}.
*
* @param classes the list of classes whose annotations are to be processed
*/
@SuppressWarnings("unused")
public void processAddModulesAnnotations(Set<Class<?>> classes) {
// Nop on JDK 8
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,9 @@ public MxJUnitRequest build() {
}
return new MxJUnitRequest(request, classes, methodName, missingClasses);
}

protected Set<Class<?>> getClasses() {
return classes;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.util.zip.GZIPOutputStream;
import java.io.OutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -39,6 +38,7 @@
import java.util.ServiceLoader;
import java.util.Set;
import java.util.TreeSet;
import java.util.zip.GZIPOutputStream;

import org.junit.internal.JUnitSystem;
import org.junit.internal.RealSystem;
Expand Down Expand Up @@ -213,6 +213,7 @@ public static void main(String... args) {
}
}

moduleSupport.processAddModulesAnnotations(builder.getClasses());
MxJUnitRequest request = builder.build();
moduleSupport.processAddExportsAnnotations(request.classes, opened, exported);

Expand Down
2 changes: 1 addition & 1 deletion mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18559,7 +18559,7 @@ def alarm_handler(signum, frame):
abort(1, killsig=signal.SIGINT)

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("6.37.0") # Add meta-POM distribution for artefacts with pom packaging.
version = VersionSpec("6.38.0") # Allow loading extra modules in unit tests

_mx_start_datetime = datetime.utcnow()
_last_timestamp = _mx_start_datetime
Expand Down

0 comments on commit a35a315

Please sign in to comment.