From 752a040a0774025e5bc1a3d00fe073958860a449 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Tue, 17 Mar 2026 12:42:18 -0500 Subject: [PATCH 1/2] Convert to SmallRye project --- .github/dependabot.yml | 10 + .github/project.yml | 5 + .github/workflows/build.yml | 79 ++++ .github/workflows/pre-release.yml | 31 ++ .github/workflows/release-perform.yml | 29 ++ .github/workflows/release-prepare.yml | 21 + .github/workflows/update-milestone.yml | 17 + pom.xml | 63 ++- .../modules/DefinedModule.java | 28 +- .../modules/DelegatingModuleLoader.java | 5 +- .../modules/FoundModule.java | 2 +- .../modules/JarFileModuleFinder.java | 16 +- .../modules/Launcher.java | 82 ++-- .../modules/LinkState.java | 55 +-- .../modules/LoadedDependency.java | 4 +- .../modules/LoadedModule.java | 4 +- .../modules/ModuleClassLoader.java | 202 ++++----- .../modules/ModuleDescriptorLoader.java | 16 +- .../modules/ModuleFinder.java | 9 +- .../modules/ModuleLoadException.java | 12 +- .../modules/ModuleLoader.java | 11 +- .../modules/ModuleNotFoundException.java | 10 +- .../modules/ResourceLoaderOpener.java | 2 +- .../modules/desc/Dependency.java | 63 +-- .../modules/desc/ModifierFlag.java | 2 +- .../modules/desc/Modifiers.java | 2 +- .../modules/desc/ModuleDescriptor.java | 388 +++++++++--------- .../modules/desc/PackageAccess.java | 2 +- .../modules/desc/PackageInfo.java | 41 +- .../modules/impl/Access.java | 34 +- .../modules/impl/TextIter.java | 8 +- .../modules/impl/Util.java | 30 +- src/main/java/module-info.java | 6 +- .../modules/test/BasicTests.java | 40 +- src/test/java/module-info.java | 6 +- 35 files changed, 807 insertions(+), 528 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/project.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/pre-release.yml create mode 100644 .github/workflows/release-perform.yml create mode 100644 .github/workflows/release-prepare.yml create mode 100644 .github/workflows/update-milestone.yml rename src/main/java/io/{github/dmlloyd => smallrye}/modules/DefinedModule.java (83%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/DelegatingModuleLoader.java (93%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/FoundModule.java (95%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/JarFileModuleFinder.java (70%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/Launcher.java (82%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/LinkState.java (80%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/LoadedDependency.java (78%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/LoadedModule.java (98%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/ModuleClassLoader.java (90%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/ModuleDescriptorLoader.java (84%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/ModuleFinder.java (96%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/ModuleLoadException.java (82%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/ModuleLoader.java (97%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/ModuleNotFoundException.java (89%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/ResourceLoaderOpener.java (98%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/desc/Dependency.java (76%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/desc/ModifierFlag.java (78%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/desc/Modifiers.java (98%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/desc/ModuleDescriptor.java (81%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/desc/PackageAccess.java (94%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/desc/PackageInfo.java (75%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/impl/Access.java (80%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/impl/TextIter.java (93%) rename src/main/java/io/{github/dmlloyd => smallrye}/modules/impl/Util.java (91%) rename src/test/java/io/{github/dmlloyd => smallrye}/modules/test/BasicTests.java (62%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..a20575a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "maven" + directory: "/" # Location of package manifests + schedule: + interval: "daily" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/project.yml b/.github/project.yml new file mode 100644 index 0000000..7074e73 --- /dev/null +++ b/.github/project.yml @@ -0,0 +1,5 @@ +name: SmallRye Modules +# for this project, always set next-version to the next *minor* unless it's on a stable branch! +release: + current-version: 1.0.alpha1-SNAPSHOT + next-version: 1.0.alpha2-SNAPSHOT diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..50287a5 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,79 @@ +name: SmallRye Build +env: + MAVEN_VERSION: 3.9.12 + IO_TAKARI_MAVEN_WRAPPER_VERSION: 0.7.7 + +on: + push: + branches: + - main + - jakarta + paths-ignore: + - '.gitattributes' + - '.gitignore' + - 'LICENSE' + - 'NOTICE' + - 'README*' + pull_request: + paths-ignore: + - '.gitattributes' + - '.gitignore' + - 'LICENSE' + - 'NOTICE' + - 'README*' + +jobs: + build: + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + fail-fast: false + runs-on: ${{ matrix.os }} + name: build + + steps: + - uses: actions/checkout@v6 + name: checkout + + - uses: actions/setup-java@v5 + name: set up JDKs + with: + distribution: temurin + java-version: | + 25 + cache: 'maven' + cache-dependency-path: '**/pom.xml' + + - name: build with maven + run: | + mvn -q -N "io.takari:maven:${{env.IO_TAKARI_MAVEN_WRAPPER_VERSION}}:wrapper" "-Dmaven=${{env.MAVEN_VERSION}}" + ./mvnw -B -ntp formatter:validate verify javadoc:javadoc --file pom.xml "-Djava25.home=${{env.JAVA_HOME_25_X64}}${{env.JAVA_HOME_25_ARM64}}" + + quality: + needs: [ build ] + if: false && github.event_name == 'push' && github.repository_owner == 'smallrye' + runs-on: ubuntu-latest + name: quality + + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 25 + cache: 'maven' + cache-dependency-path: '**/pom.xml' + + - name: build with coverage + run: | + mvn -q -N "io.takari:maven:${{env.IO_TAKARI_MAVEN_WRAPPER_VERSION}}:wrapper" "-Dmaven=${{env.MAVEN_VERSION}}" + ./mvnw -B -ntp verify -Pcoverage + + - uses: actions/setup-java@v5 + with: + distribution: 'temurin' + java-version: 25 + + - name: sonar + run: ./mvnw -B -ntp sonar:sonar -Dsonar.projectKey=smallrye_smallrye-modules -Dsonar.token=${{secrets.SONAR_TOKEN}} diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 0000000..343d47e --- /dev/null +++ b/.github/workflows/pre-release.yml @@ -0,0 +1,31 @@ +name: SmallRye Pre Release + +on: + pull_request: + paths: + - '.github/project.yml' + +jobs: + release: + runs-on: ubuntu-latest + name: pre release + + steps: + - uses: radcortez/project-metadata-action@main + name: retrieve project metadata + id: metadata + with: + github-token: ${{secrets.GITHUB_TOKEN}} + metadata-file-path: '.github/project.yml' + + - name: Validate version + if: contains(steps.metadata.outputs.current-version, 'SNAPSHOT') + run: | + echo '::error::Cannot release a SNAPSHOT version.' + exit 1 + + - uses: radcortez/milestone-review-action@main + name: milestone review + with: + github-token: ${{secrets.GITHUB_TOKEN}} + milestone-title: ${{steps.metadata.outputs.current-version}} diff --git a/.github/workflows/release-perform.yml b/.github/workflows/release-perform.yml new file mode 100644 index 0000000..d74fa9b --- /dev/null +++ b/.github/workflows/release-perform.yml @@ -0,0 +1,29 @@ +name: SmallRye Release +run-name: Perform ${{github.event.inputs.tag || github.ref_name}} Release +on: + push: + tags: + - '*' + workflow_dispatch: + inputs: + tag: + description: 'Tag to release' + required: true + +permissions: + attestations: write + id-token: write + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + perform-release: + name: Perform Release + uses: smallrye/.github/.github/workflows/perform-release.yml@main + secrets: inherit + with: + version: ${{github.event.inputs.tag || github.ref_name}} + java_version: 25 diff --git a/.github/workflows/release-prepare.yml b/.github/workflows/release-prepare.yml new file mode 100644 index 0000000..9fae85d --- /dev/null +++ b/.github/workflows/release-prepare.yml @@ -0,0 +1,21 @@ +name: SmallRye Prepare Release + +on: + workflow_dispatch: + pull_request: + types: [ closed ] + paths: + - '.github/project.yml' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + prepare-release: + name: Prepare Release + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true}} + uses: smallrye/.github/.github/workflows/prepare-release.yml@main + secrets: inherit + with: + java_version: 25 diff --git a/.github/workflows/update-milestone.yml b/.github/workflows/update-milestone.yml new file mode 100644 index 0000000..5a1f335 --- /dev/null +++ b/.github/workflows/update-milestone.yml @@ -0,0 +1,17 @@ +name: Update Milestone + +on: + pull_request_target: + types: [closed] + +jobs: + update: + runs-on: ubuntu-latest + name: update-milestone + if: ${{github.event.pull_request.merged == true}} + + steps: + - uses: radcortez/milestone-set-action@main + name: milestone set + with: + github-token: ${{secrets.GITHUB_TOKEN}} diff --git a/pom.xml b/pom.xml index fc2bb7c..5c0cee6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - io.github.dmlloyd.modules - modules3 - 1.0-SNAPSHOT + io.smallrye.modules + smallrye-modules + 1.0-alpha1-SNAPSHOT - org.jboss - jboss-parent - 51 + io.smallrye + smallrye-parent + 45 @@ -56,7 +56,7 @@ org.junit.jupiter - junit-jupiter-api + junit-jupiter 5.11.1 test @@ -67,7 +67,7 @@ maven-surefire-plugin - --add-exports java.base/jdk.internal.module=io.github.dmlloyd.modules + --add-exports java.base/jdk.internal.module=io.smallrye.modules @@ -75,11 +75,56 @@ - io.github.dmlloyd.modules.Launcher + io.smallrye.modules.Launcher + + net.revelc.code + impsort-maven-plugin + 1.13.0 + + + com.github.javaparser + javaparser-core + 3.28.0 + + + + + sort-imports + + sort + + + 17 + + + + + + net.revelc.code.formatter + formatter-maven-plugin + + + format-sources + process-sources + + format + + + 17 + + + + + + maven-javadoc-plugin + + 17 + + diff --git a/src/main/java/io/github/dmlloyd/modules/DefinedModule.java b/src/main/java/io/smallrye/modules/DefinedModule.java similarity index 83% rename from src/main/java/io/github/dmlloyd/modules/DefinedModule.java rename to src/main/java/io/smallrye/modules/DefinedModule.java index 9bdb6e0..981b4c7 100644 --- a/src/main/java/io/github/dmlloyd/modules/DefinedModule.java +++ b/src/main/java/io/smallrye/modules/DefinedModule.java @@ -1,11 +1,11 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.util.List; import java.util.concurrent.locks.ReentrantLock; -import io.github.dmlloyd.modules.desc.ModuleDescriptor; import io.smallrye.common.constraint.Assert; import io.smallrye.common.resource.ResourceLoader; +import io.smallrye.modules.desc.ModuleDescriptor; /** * A defined module. @@ -18,7 +18,8 @@ static final class New extends DefinedModule { private final ReentrantLock loadLock = new ReentrantLock(); private volatile DefinedModule result; - New(final String moduleName, final List resourceLoaderOpeners, final ModuleDescriptorLoader descriptorLoader) { + New(final String moduleName, final List resourceLoaderOpeners, + final ModuleDescriptorLoader descriptorLoader) { this.moduleName = moduleName; this.resourceLoaderOpeners = List.copyOf(resourceLoaderOpeners); this.descriptorLoader = descriptorLoader; @@ -42,9 +43,11 @@ ModuleClassLoader moduleClassLoader(final ModuleLoader moduleLoader) { for (int i = 0; i < cnt; i++) { ResourceLoaderOpener opener = openers.get(i); try { - loaderArray[i] = Assert.checkNotNullArrayParam("returned loader from openers", i, opener.open()); + loaderArray[i] = Assert.checkNotNullArrayParam("returned loader from openers", i, + opener.open()); } catch (Throwable t) { - ModuleLoadException mle = new ModuleLoadException("Failed to open a resource loader for `" + moduleName + "`", t); + ModuleLoadException mle = new ModuleLoadException( + "Failed to open a resource loader for `" + moduleName + "`", t); for (int j = i - 1; j >= 0; j--) { try { loaderArray[j].close(); @@ -58,14 +61,14 @@ ModuleClassLoader moduleClassLoader(final ModuleLoader moduleLoader) { List loaders = List.of(loaderArray); try { ModuleDescriptor desc = descriptorLoader.loadDescriptor(moduleName, loaders); - if (! desc.name().equals(moduleName)) { - throw new ModuleLoadException("Module descriptor for `" + moduleName + "` has unexpected name `" + desc.name() + "`"); + if (!desc.name().equals(moduleName)) { + throw new ModuleLoadException( + "Module descriptor for `" + moduleName + "` has unexpected name `" + desc.name() + "`"); } ModuleClassLoader.ClassLoaderConfiguration config = new ModuleClassLoader.ClassLoaderConfiguration( - moduleLoader, - loaders, - desc - ); + moduleLoader, + loaders, + desc); ModuleClassLoader mcl; try { mcl = moduleLoader.createClassLoader(config); @@ -76,7 +79,8 @@ ModuleClassLoader moduleClassLoader(final ModuleLoader moduleLoader) { this.result = result; moduleLoader.replace(this, result); } catch (Throwable t) { - ModuleLoadException mle = new ModuleLoadException("Failed to load module descriptor for for " + moduleName, t); + ModuleLoadException mle = new ModuleLoadException( + "Failed to load module descriptor for for " + moduleName, t); for (int j = cnt - 1; j >= 0; j--) { try { loaders.get(j).close(); diff --git a/src/main/java/io/github/dmlloyd/modules/DelegatingModuleLoader.java b/src/main/java/io/smallrye/modules/DelegatingModuleLoader.java similarity index 93% rename from src/main/java/io/github/dmlloyd/modules/DelegatingModuleLoader.java rename to src/main/java/io/smallrye/modules/DelegatingModuleLoader.java index d9d9556..445b12c 100644 --- a/src/main/java/io/github/dmlloyd/modules/DelegatingModuleLoader.java +++ b/src/main/java/io/smallrye/modules/DelegatingModuleLoader.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.util.function.Function; @@ -17,7 +17,8 @@ public final class DelegatingModuleLoader extends ModuleLoader { * @param moduleFinder the module finder (must not be {@code null}) * @param delegateFn the function which yields the delegate to use when the module is not found (must not be {@code null}) */ - public DelegatingModuleLoader(final String name, final ModuleFinder moduleFinder, final Function delegateFn) { + public DelegatingModuleLoader(final String name, final ModuleFinder moduleFinder, + final Function delegateFn) { super(name, moduleFinder); this.delegateFn = Assert.checkNotNullParam("delegateFn", delegateFn); } diff --git a/src/main/java/io/github/dmlloyd/modules/FoundModule.java b/src/main/java/io/smallrye/modules/FoundModule.java similarity index 95% rename from src/main/java/io/github/dmlloyd/modules/FoundModule.java rename to src/main/java/io/smallrye/modules/FoundModule.java index 1509bd6..3265550 100644 --- a/src/main/java/io/github/dmlloyd/modules/FoundModule.java +++ b/src/main/java/io/smallrye/modules/FoundModule.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.util.List; diff --git a/src/main/java/io/github/dmlloyd/modules/JarFileModuleFinder.java b/src/main/java/io/smallrye/modules/JarFileModuleFinder.java similarity index 70% rename from src/main/java/io/github/dmlloyd/modules/JarFileModuleFinder.java rename to src/main/java/io/smallrye/modules/JarFileModuleFinder.java index c9907da..ada98d0 100644 --- a/src/main/java/io/github/dmlloyd/modules/JarFileModuleFinder.java +++ b/src/main/java/io/smallrye/modules/JarFileModuleFinder.java @@ -1,14 +1,14 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.io.IOException; import java.util.List; import java.util.Map; -import io.github.dmlloyd.modules.desc.ModuleDescriptor; -import io.github.dmlloyd.modules.desc.PackageAccess; -import io.github.dmlloyd.modules.impl.TextIter; -import io.github.dmlloyd.modules.impl.Util; import io.smallrye.common.resource.ResourceLoader; +import io.smallrye.modules.desc.ModuleDescriptor; +import io.smallrye.modules.desc.PackageAccess; +import io.smallrye.modules.impl.TextIter; +import io.smallrye.modules.impl.Util; /** * A module finder which finds a single module in the given JAR file. @@ -18,9 +18,11 @@ final class JarFileModuleFinder implements ModuleFinder { private final ModuleDescriptor descriptor; private final ResourceLoaderOpener opener; - JarFileModuleFinder(final ResourceLoader jarLoader, final String name, final Map> extraAccesses) throws IOException { + JarFileModuleFinder(final ResourceLoader jarLoader, final String name, + final Map> extraAccesses) throws IOException { this.jarLoader = jarLoader; - descriptor = ModuleDescriptorLoader.basic(extraAccesses).loadDescriptor(Util.autoModuleName(TextIter.of(name)), List.of(jarLoader)); + descriptor = ModuleDescriptorLoader.basic(extraAccesses).loadDescriptor(Util.autoModuleName(TextIter.of(name)), + List.of(jarLoader)); opener = ResourceLoaderOpener.forLoader(jarLoader); } diff --git a/src/main/java/io/github/dmlloyd/modules/Launcher.java b/src/main/java/io/smallrye/modules/Launcher.java similarity index 82% rename from src/main/java/io/github/dmlloyd/modules/Launcher.java rename to src/main/java/io/smallrye/modules/Launcher.java index a2a5415..b45f1d9 100644 --- a/src/main/java/io/github/dmlloyd/modules/Launcher.java +++ b/src/main/java/io/smallrye/modules/Launcher.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.io.File; import java.io.IOException; @@ -14,7 +14,6 @@ import java.util.List; import java.util.Map; import java.util.NoSuchElementException; -import java.util.Objects; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.Set; @@ -22,11 +21,11 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import io.github.dmlloyd.modules.desc.Dependency; -import io.github.dmlloyd.modules.desc.PackageAccess; -import io.github.dmlloyd.modules.impl.Util; import io.smallrye.common.constraint.Assert; import io.smallrye.common.resource.JarFileResourceLoader; +import io.smallrye.modules.desc.Dependency; +import io.smallrye.modules.desc.PackageAccess; +import io.smallrye.modules.impl.Util; /** * The main entry point to bootstrap a basic modular environment. @@ -127,7 +126,8 @@ public void run() { } MethodHandle mainMethod; try { - mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); + mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", + MethodType.methodType(void.class, String[].class)); } catch (NoSuchMethodException e) { System.err.printf("No main method found on %s", mainClass); System.err.flush(); @@ -154,7 +154,7 @@ public void run() { private void printModuleInfo(final Module module, final Set visited, final Set path, final String prefix) { System.out.print(module.getName()); module.getDescriptor().rawVersion().ifPresent(v -> System.out.print("@" + v)); - boolean wasVisited = ! visited.add(module); + boolean wasVisited = !visited.add(module); if (path.add(module)) { try { // not a loop @@ -162,7 +162,9 @@ private void printModuleInfo(final Module module, final Set visited, fin if (cl instanceof ModuleClassLoader mcl) { System.out.println(); List dependencies = mcl.linkDependencies().dependencies(); - Iterator iter = Util.mapped(Util.filtered(dependencies.iterator(), Dependency::isNonSynthetic), d -> d.moduleLoader().orElse(mcl.moduleLoader()).loadModule(d.moduleName())); + Iterator iter = Util.mapped( + Util.filtered(dependencies.iterator(), Dependency::isNonSynthetic), + d -> d.moduleLoader().orElse(mcl.moduleLoader()).loadModule(d.moduleName())); if (iter.hasNext()) { if (wasVisited) { return; @@ -212,11 +214,13 @@ public static void main(List args) { // force logging initialization ServiceLoader logManagerLoader = ServiceLoader.load(LogManager.class); Iterator lmIter = logManagerLoader.iterator(); - while (true) try { - if (! lmIter.hasNext()) break; - lmIter.next(); - } catch (ServiceConfigurationError ignored) { - } + while (true) + try { + if (!lmIter.hasNext()) + break; + lmIter.next(); + } catch (ServiceConfigurationError ignored) { + } args = List.copyOf(args); Iterator iterator = args.iterator(); List modulePath = List.of(Path.of(".")); @@ -228,20 +232,20 @@ public static void main(List args) { switch (argument) { case "-h", "--help" -> { System.out.printf(""" - Usage: java [...] -m io.github.dmlloyd.modules [] [/] - java [...] -m io.github.dmlloyd.modules [] --jar - where is a valid module name, is a JAR file, and is any of: - --help Display this message - -mp,--module-path Specifies the location of the module root(s) - as a list of paths separated by `%s` characters - --jar Run a modular JAR in the modular environment - --info Display information about the module instead of running it - - Additionally, it is recommended to pass --enable-native-access=%s on - Java 22 or later to ensure that permitted submodules can also have native access enabled. - Granting this capability will transitively grant the capability to any module which is configured - for native access. - """, File.pathSeparator, Objects.requireNonNullElse(Util.myModule.getName(), "ALL-UNNAMED")); + Usage: java [...] -m %s [] [/] + java [...] -m %1$s [] --jar + where is a valid module name, is a JAR file, and is any of: + --help Display this message + -mp,--module-path Specifies the location of the module root(s) + as a list of paths separated by `%2$s` characters + --jar Run a modular JAR in the modular environment + --info Display information about the module instead of running it + + Additionally, it is recommended to pass --enable-native-access=%1$s on + Java 22 or later to ensure that permitted submodules can also have native access enabled. + Granting this capability will transitively grant the capability to any module which is configured + for native access. + """, Util.myModule.getName(), File.pathSeparator); System.out.flush(); System.exit(0); } @@ -258,7 +262,7 @@ public static void main(List args) { System.exit(0); } case "-mp", "--module-path" -> { - if (! iterator.hasNext()) { + if (!iterator.hasNext()) { System.err.printf("Option `%s` requires an argument%n", argument); System.err.flush(); System.exit(1); @@ -287,7 +291,7 @@ public static void main(List args) { case "--add-exports", "--add-opens" -> { // export to the main module // format: module/packageName - if (! iterator.hasNext()) { + if (!iterator.hasNext()) { System.err.printf("Option `%s` requires an argument%n", argument); System.err.flush(); System.exit(1); @@ -306,18 +310,22 @@ public static void main(List args) { } switch (argument) { // use putIfAbsent for exports so it doesn't override opens - case "--add-exports" -> accesses.computeIfAbsent(moduleName, Util::newHashMap).putIfAbsent(packageName, PackageAccess.EXPORTED); + case "--add-exports" -> accesses.computeIfAbsent(moduleName, Util::newHashMap).putIfAbsent(packageName, + PackageAccess.EXPORTED); // use put for opens so it always overrides exports - case "--add-opens" -> accesses.computeIfAbsent(moduleName, Util::newHashMap).put(packageName, PackageAccess.OPEN); + case "--add-opens" -> + accesses.computeIfAbsent(moduleName, Util::newHashMap).put(packageName, PackageAccess.OPEN); } } default -> { if (argument.startsWith("-")) { - System.err.printf("Unrecognized option `%s`. Try `--help` for a list of supported options.%n", argument); + System.err.printf("Unrecognized option `%s`. Try `--help` for a list of supported options.%n", + argument); System.err.flush(); System.exit(1); } - Configuration conf = new Configuration(argument, mode, infoOnly, modulePath, Util.listOf(iterator), accesses); + Configuration conf = new Configuration(argument, mode, infoOnly, modulePath, Util.listOf(iterator), + accesses); Launcher launcher = new Launcher(conf); launcher.run(); return; @@ -343,14 +351,16 @@ public enum Mode { JAR, } - public record Configuration(String launchName, Mode launchMode, boolean infoOnly, List modulePath, List arguments, - Map> accesses) { + public record Configuration(String launchName, Mode launchMode, boolean infoOnly, List modulePath, + List arguments, + Map> accesses) { public Configuration { Assert.checkNotNullParam("launchName", launchName); Assert.checkNotNullParam("launchMode", launchMode); modulePath = List.copyOf(modulePath); arguments = List.copyOf(arguments); - accesses = accesses.entrySet().stream().collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, e -> Map.copyOf(e.getValue()))); + accesses = accesses.entrySet().stream() + .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, e -> Map.copyOf(e.getValue()))); } } } diff --git a/src/main/java/io/github/dmlloyd/modules/LinkState.java b/src/main/java/io/smallrye/modules/LinkState.java similarity index 80% rename from src/main/java/io/github/dmlloyd/modules/LinkState.java rename to src/main/java/io/smallrye/modules/LinkState.java index dba0fab..ca10d04 100644 --- a/src/main/java/io/github/dmlloyd/modules/LinkState.java +++ b/src/main/java/io/smallrye/modules/LinkState.java @@ -1,6 +1,6 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; -import static io.github.dmlloyd.modules.impl.Access.*; +import static io.smallrye.modules.impl.Access.*; import java.net.URI; import java.security.CodeSigner; @@ -11,26 +11,28 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import io.github.dmlloyd.modules.desc.Dependency; -import io.github.dmlloyd.modules.desc.Modifiers; -import io.github.dmlloyd.modules.desc.ModuleDescriptor; -import io.github.dmlloyd.modules.desc.PackageInfo; -import io.github.dmlloyd.modules.impl.Access; -import io.github.dmlloyd.modules.impl.Util; import io.smallrye.common.resource.Resource; import io.smallrye.common.resource.ResourceLoader; +import io.smallrye.modules.desc.Dependency; +import io.smallrye.modules.desc.Modifiers; +import io.smallrye.modules.desc.ModuleDescriptor; +import io.smallrye.modules.desc.PackageInfo; +import io.smallrye.modules.impl.Access; +import io.smallrye.modules.impl.Util; /** * The enclosing class for all link states. */ abstract class LinkState { - private LinkState() {} + private LinkState() { + } /** * The singleton closed state. */ static final class Closed extends LinkState { - private Closed() {} + private Closed() { + } static final Closed INSTANCE = new Closed(); } @@ -46,7 +48,10 @@ static class New extends LinkState { private final Map> provides; private final URI location; - New(final String moduleVersion, final String mainClass, final List dependencies, final List resourceLoaders, final Map packages, final Modifiers modifiers, final Set uses, final Map> provides, final URI location) { + New(final String moduleVersion, final String mainClass, final List dependencies, + final List resourceLoaders, final Map packages, + final Modifiers modifiers, final Set uses, + final Map> provides, final URI location) { this.moduleVersion = moduleVersion; this.mainClass = mainClass; this.dependencies = dependencies; @@ -59,7 +64,8 @@ static class New extends LinkState { } New(final New other) { - this(other.moduleVersion, other.mainClass, other.dependencies, other.resourceLoaders, other.packages, other.modifiers, other.uses, other.provides, other.location); + this(other.moduleVersion, other.mainClass, other.dependencies, other.resourceLoaders, other.packages, + other.modifiers, other.uses, other.provides, other.location); } List dependencies() { @@ -114,11 +120,10 @@ static class Defined extends Dependencies { private final ConcurrentHashMap, ProtectionDomain> pdCache; private Defined( - final Dependencies other, - final Module module, - final ModuleLayer.Controller layerController, - final ConcurrentHashMap, ProtectionDomain> pdCache - ) { + final Dependencies other, + final Module module, + final ModuleLayer.Controller layerController, + final ConcurrentHashMap, ProtectionDomain> pdCache) { super(other); this.module = module; this.layerController = layerController; @@ -126,10 +131,9 @@ private Defined( } Defined( - final Dependencies other, - final Module module, - final ModuleLayer.Controller layerController - ) { + final Dependencies other, + final Module module, + final ModuleLayer.Controller layerController) { this(other, module, layerController, new ConcurrentHashMap<>()); Util.myModule.addReads(module); } @@ -153,7 +157,8 @@ void addExports(final String pn, final Module target) { try { layerController.addExports(module, pn, target); } catch (IllegalArgumentException e) { - IllegalArgumentException e2 = new IllegalArgumentException("Failed to export " + module + " to " + target + ": " + e.getMessage()); + IllegalArgumentException e2 = new IllegalArgumentException( + "Failed to export " + module + " to " + target + ": " + e.getMessage()); e2.setStackTrace(e.getStackTrace()); throw e2; } @@ -165,7 +170,8 @@ void addOpens(final String pn, final Module target) { try { layerController.addOpens(module, pn, target); } catch (IllegalArgumentException e) { - IllegalArgumentException e2 = new IllegalArgumentException("Failed to open " + module + " to " + target + ": " + e.getMessage()); + IllegalArgumentException e2 = new IllegalArgumentException( + "Failed to open " + module + " to " + target + ": " + e.getMessage()); e2.setStackTrace(e.getStackTrace()); throw e2; } @@ -188,7 +194,8 @@ ProtectionDomain cachedProtectionDomain(final Resource resource) { List codeSigners = List.copyOf(resource.codeSigners()); ProtectionDomain pd = pdCache.get(codeSigners); if (pd == null) { - pd = new ProtectionDomain(new CodeSource(resource.url(), codeSigners.toArray(CodeSigner[]::new)), Util.allPermissions); + pd = new ProtectionDomain(new CodeSource(resource.url(), codeSigners.toArray(CodeSigner[]::new)), + Util.allPermissions); ProtectionDomain appearing = pdCache.putIfAbsent(codeSigners, pd); if (appearing != null) { pd = appearing; diff --git a/src/main/java/io/github/dmlloyd/modules/LoadedDependency.java b/src/main/java/io/smallrye/modules/LoadedDependency.java similarity index 78% rename from src/main/java/io/github/dmlloyd/modules/LoadedDependency.java rename to src/main/java/io/smallrye/modules/LoadedDependency.java index dde1809..f35c663 100644 --- a/src/main/java/io/github/dmlloyd/modules/LoadedDependency.java +++ b/src/main/java/io/smallrye/modules/LoadedDependency.java @@ -1,7 +1,7 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; -import io.github.dmlloyd.modules.desc.Dependency; import io.smallrye.common.constraint.Assert; +import io.smallrye.modules.desc.Dependency; /** * A loaded dependency. diff --git a/src/main/java/io/github/dmlloyd/modules/LoadedModule.java b/src/main/java/io/smallrye/modules/LoadedModule.java similarity index 98% rename from src/main/java/io/github/dmlloyd/modules/LoadedModule.java rename to src/main/java/io/smallrye/modules/LoadedModule.java index 2b17f2c..e335029 100644 --- a/src/main/java/io/github/dmlloyd/modules/LoadedModule.java +++ b/src/main/java/io/smallrye/modules/LoadedModule.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.util.Objects; import java.util.Optional; @@ -99,6 +99,7 @@ public String toString() { /** * {@return a loaded module for the given module} + * * @param module the module to encapsulate (must not be {@code null}) */ public static LoadedModule forModule(Module module) { @@ -107,6 +108,7 @@ public static LoadedModule forModule(Module module) { /** * {@return a loaded module for the given module class loader} + * * @param cl the class loader of the module to encapsulate (must not be {@code null}) */ public static LoadedModule forModuleClassLoader(ModuleClassLoader cl) { diff --git a/src/main/java/io/github/dmlloyd/modules/ModuleClassLoader.java b/src/main/java/io/smallrye/modules/ModuleClassLoader.java similarity index 90% rename from src/main/java/io/github/dmlloyd/modules/ModuleClassLoader.java rename to src/main/java/io/smallrye/modules/ModuleClassLoader.java index e8be3b7..e0f9eea 100644 --- a/src/main/java/io/github/dmlloyd/modules/ModuleClassLoader.java +++ b/src/main/java/io/smallrye/modules/ModuleClassLoader.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.io.IOException; import java.io.InputStream; @@ -34,13 +34,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import io.github.dmlloyd.modules.desc.Dependency; -import io.github.dmlloyd.modules.desc.Modifiers; -import io.github.dmlloyd.modules.desc.ModuleDescriptor; -import io.github.dmlloyd.modules.desc.PackageAccess; -import io.github.dmlloyd.modules.desc.PackageInfo; -import io.github.dmlloyd.modules.impl.Access; -import io.github.dmlloyd.modules.impl.Util; +import org.jboss.logging.Logger; + import io.smallrye.classfile.ClassFile; import io.smallrye.classfile.attribute.ModuleAttribute; import io.smallrye.classfile.attribute.ModulePackagesAttribute; @@ -55,14 +50,20 @@ import io.smallrye.common.resource.Resource; import io.smallrye.common.resource.ResourceLoader; import io.smallrye.common.resource.ResourceUtils; -import org.jboss.logging.Logger; +import io.smallrye.modules.desc.Dependency; +import io.smallrye.modules.desc.Modifiers; +import io.smallrye.modules.desc.ModuleDescriptor; +import io.smallrye.modules.desc.PackageAccess; +import io.smallrye.modules.desc.PackageInfo; +import io.smallrye.modules.impl.Access; +import io.smallrye.modules.impl.Util; /** * A class loader for a module. */ public class ModuleClassLoader extends ClassLoader { static { - if (! ClassLoader.registerAsParallelCapable()) { + if (!ClassLoader.registerAsParallelCapable()) { throw new InternalError("Class loader cannot be made parallel-capable"); } } @@ -110,7 +111,7 @@ private static void populateIndex(Map map, ModuleLayer layer) { public ModuleClassLoader(ClassLoaderConfiguration config, String name) { super(name, null); config.checkAndClear(); - if (! isRegisteredAsParallelCapable()) { + if (!isRegisteredAsParallelCapable()) { throw new IllegalStateException("Class loader is not registered as parallel-capable"); } this.moduleLoader = config.moduleLoader(); @@ -119,16 +120,15 @@ public ModuleClassLoader(ClassLoaderConfiguration config, String name) { this.moduleVersion = descriptor.version().orElse(null); this.mainClassName = descriptor.mainClass().orElse(null); this.linkState = new LinkState.New( - moduleName, - mainClassName, - descriptor.dependencies(), - config.resourceLoaders(), - descriptor.packages(), - descriptor.modifiers(), - descriptor.uses(), - descriptor.provides(), - descriptor.location().orElse(null) - ); + moduleName, + mainClassName, + descriptor.dependencies(), + config.resourceLoaders(), + descriptor.packages(), + descriptor.modifiers(), + descriptor.uses(), + descriptor.provides(), + descriptor.location().orElse(null)); } /** @@ -220,8 +220,9 @@ protected final Class loadClass(final String name, final boolean resolve) thr } // -> BootLoader.loadClass(...) Module module = bootModuleIndex.get(packageName); - if (! module.isExported(packageName, module())) { - throw new ClassNotFoundException("Cannot load " + name + ": package " + packageName + " not exported from " + module + " to " + module()); + if (!module.isExported(packageName, module())) { + throw new ClassNotFoundException("Cannot load " + name + ": package " + packageName + " not exported from " + + module + " to " + module()); } Class result = Class.forName(module, dotName); if (result != null) { @@ -231,7 +232,8 @@ protected final Class loadClass(final String name, final boolean resolve) thr } LoadedModule lm = linkPackages().modulesByPackage().get(packageName); if (lm == null) { - throw new ClassNotFoundException("Class loader for " + this + " does not link against package `" + packageName + "`"); + throw new ClassNotFoundException( + "Class loader for " + this + " does not link against package `" + packageName + "`"); } Class loaded; ClassLoader cl = lm.classLoader(); @@ -246,7 +248,8 @@ protected final Class loadClass(final String name, final boolean resolve) thr loaded = Class.forName(dotName, false, cl); } } else { - throw new ClassNotFoundException(lm.name().map(n -> "Module " + n).orElse("Unnamed module") + " does not export package " + packageName + " to " + module().getName()); + throw new ClassNotFoundException(lm.name().map(n -> "Module " + n).orElse("Unnamed module") + + " does not export package " + packageName + " to " + module().getName()); } } if (resolve) { @@ -379,10 +382,11 @@ private R getExportedResource0(Class caller, String pathName, R resource, return resource; } String pkgName = Util.resourcePackageName(pathName); - if (pkgName.isEmpty() || ! linkDefined().packages().containsKey(pkgName)) { + if (pkgName.isEmpty() || !linkDefined().packages().containsKey(pkgName)) { return resource; } - if (linkDefined().packages().getOrDefault(pkgName, PackageInfo.PRIVATE).packageAccess().isAtLeast(PackageAccess.EXPORTED)) { + if (linkDefined().packages().getOrDefault(pkgName, PackageInfo.PRIVATE).packageAccess() + .isAtLeast(PackageAccess.EXPORTED)) { return resource; } if (module().isOpen(pkgName, caller.getModule())) { @@ -409,7 +413,7 @@ final Class loadClassDirect(String name) throws ClassNotFoundException { } LinkState.Defined linked = linkDefined(); String packageName = Util.packageName(binaryName); - if (! packageName.isEmpty() && ! linked.packages().containsKey(packageName)) { + if (!packageName.isEmpty() && !linked.packages().containsKey(packageName)) { throw new ClassNotFoundException("Class `" + name + "` is not in a package that is reachable from " + moduleName); } @@ -490,7 +494,8 @@ private Resource loadServicesFileDirect(final String name) { return new MemoryResource(name, result.getBytes(StandardCharsets.UTF_8)); } - private static String getAttribute(Attributes.Name name, Attributes packageAttribute, Attributes mainAttribute, String defVal) { + private static String getAttribute(Attributes.Name name, Attributes packageAttribute, Attributes mainAttribute, + String defVal) { String value = null; if (packageAttribute != null) { value = packageAttribute.getValue(name); @@ -552,15 +557,14 @@ final Package loadPackageDirect(final String name) { } try { return definePackage( - name, - specTitle, - specVersion, - specVendor, - implTitle, - implVersion, - implVendor, - sealed ? loader.baseUrl() : null - ); + name, + specTitle, + specVersion, + specVendor, + implTitle, + implVersion, + implVendor, + sealed ? loader.baseUrl() : null); } catch (IllegalArgumentException e) { // double check pkg = getDefinedPackage(name); @@ -578,7 +582,7 @@ private boolean locked() { } private O doLocked(Function operation) { - assert ! locked(); + assert !locked(); ReentrantLock lock = linkLock; lock.lock(); try { @@ -589,7 +593,7 @@ private O doLocked(Function operation) { } private O doLocked(BiFunction operation, I input) { - assert ! locked(); + assert !locked(); ReentrantLock lock = linkLock; lock.lock(); try { @@ -651,7 +655,8 @@ private LinkState.Dependencies linkDependenciesLocked(List loa return newState; } - private static Set toJlmModifiers(Modifiers modifiers) { + private static Set toJlmModifiers( + Modifiers modifiers) { if (modifiers.contains(ModuleDescriptor.Modifier.AUTOMATIC)) { return Set.of(java.lang.module.ModuleDescriptor.Modifier.AUTOMATIC); } else if (modifiers.contains(ModuleDescriptor.Modifier.OPEN)) { @@ -662,8 +667,7 @@ private static Set toJlmModifiers(Mo } private static final Set justStatic = Set.of( - java.lang.module.ModuleDescriptor.Requires.Modifier.STATIC - ); + java.lang.module.ModuleDescriptor.Requires.Modifier.STATIC); LinkState.Defined linkDefined() { // fast path @@ -679,9 +683,8 @@ LinkState.Defined linkDefined() { descriptor = null; } else { java.lang.module.ModuleDescriptor.Builder builder = java.lang.module.ModuleDescriptor.newModule( - moduleName, - toJlmModifiers(linkState.modifiers()) - ); + moduleName, + toJlmModifiers(linkState.modifiers())); try { java.lang.module.ModuleDescriptor.Version v = java.lang.module.ModuleDescriptor.Version.parse(moduleVersion); builder.version(v); @@ -692,7 +695,7 @@ LinkState.Defined linkDefined() { // not actually used, but for completeness... builder.mainClass(mainClassName); } - if (! linkState.modifiers().contains(ModuleDescriptor.Modifier.AUTOMATIC)) { + if (!linkState.modifiers().contains(ModuleDescriptor.Modifier.AUTOMATIC)) { linkState.packages().forEach((name, pkg) -> { switch (pkg.packageAccess()) { case EXPORTED -> builder.exports(name); @@ -728,11 +731,10 @@ public ModuleReader open() { } }; final Configuration cf = Configuration.resolve( - new SingleModuleFinder(modRef), - PARENT_CONFIGS, - Util.EMPTY_MF, - List.of(moduleName) - ); + new SingleModuleFinder(modRef), + PARENT_CONFIGS, + Util.EMPTY_MF, + List.of(moduleName)); ModuleLayer.Controller ctl = ModuleLayer.defineModules(cf, BOOT_LAYER_ONLY, ignored -> this); ModuleLayer moduleLayer = ctl.layer(); Module module = moduleLayer.findModule(moduleName).orElseThrow(IllegalStateException::new); @@ -740,10 +742,9 @@ public ModuleReader open() { Access.enableNativeAccess(module); } defined = new LinkState.Defined( - linkState, - module, - ctl - ); + linkState, + module, + ctl); defined.addReads(Util.myModule); Util.myModule.addReads(module); } @@ -796,8 +797,7 @@ LinkState.Packages linkPackages() { } } else { log.warnf("Module %s requested access to package %s in %s, but the package is not present in that module", - moduleName(), pn, dependency.moduleName() - ); + moduleName(), pn, dependency.moduleName()); } if (linked) { modulesByPackage.putIfAbsent(pn, lm); @@ -834,9 +834,8 @@ private LinkState.Packages linkPackagesLocked(final Map mo } log.debugf("Linking module %s to packages state", moduleName); LinkState.Packages linked = new LinkState.Packages( - defined, - Map.copyOf(modulesByPackage) - ); + defined, + Map.copyOf(modulesByPackage)); linkState = linked; return linked; } @@ -851,7 +850,8 @@ private LinkState.Packages linkPackagesLocked(final Map mo * @param modulesByPackage the map being populated (must not be {@code null}) * @param visited the visited module set (must not be {@code null}) */ - private void linkTransitive(LinkState.Defined linkState, boolean read, boolean linked, LoadedModule loadedModule, Map modulesByPackage, Set visited) { + private void linkTransitive(LinkState.Defined linkState, boolean read, boolean linked, LoadedModule loadedModule, + Map modulesByPackage, Set visited) { if (visited.add(loadedModule)) { if (loadedModule.classLoader() instanceof ModuleClassLoader mcl) { if (linked) { @@ -874,7 +874,7 @@ private void linkTransitive(LinkState.Defined linkState, boolean read, boolean l Module module = loadedModule.module(); java.lang.module.ModuleDescriptor descriptor = module.getDescriptor(); if (descriptor != null) { - if (linked && ! ModuleLayer.boot().modules().contains(module)) { + if (linked && !ModuleLayer.boot().modules().contains(module)) { loadedModule.forEachExportedPackage(linkState.module(), pn -> { modulesByPackage.putIfAbsent(pn, loadedModule); }); @@ -886,8 +886,9 @@ private void linkTransitive(LinkState.Defined linkState, boolean read, boolean l if (require.modifiers().contains(java.lang.module.ModuleDescriptor.Requires.Modifier.STATIC)) { continue; } - throw new ModuleLoadException("Failed to link " + moduleName + ": dependency from " + module.getName() - + " to " + require.name() + " is missing"); + throw new ModuleLoadException( + "Failed to link " + moduleName + ": dependency from " + module.getName() + + " to " + require.name() + " is missing"); } Module subModule = optDep.get(); LoadedModule subLm = LoadedModule.forModule(subModule); @@ -940,8 +941,7 @@ private LinkState.Provides linkProvidesLocked() { } log.debugf("Linking module %s to provides state", moduleName); LinkState.Provides newState = new LinkState.Provides( - linkState - ); + linkState); this.linkState = newState; return newState; } @@ -977,8 +977,7 @@ private LinkState.Uses linkUsesLocked() { } log.debugf("Linking module %s to uses state", moduleName); LinkState.Uses newState = new LinkState.Uses( - linkState - ); + linkState); this.linkState = newState; return newState; } @@ -1009,26 +1008,24 @@ private Resource loadModuleInfo() { zb.withVersion(ClassFile.JAVA_9_VERSION, 0); zb.withFlags(flagsOfModule(linkNew().modifiers())); zb.with(ModuleAttribute.of( - ModuleDesc.of(moduleName), - mab -> { - mab.moduleName(ModuleDesc.of(moduleName)); - mab.moduleVersion(moduleVersion); - // java.base is always required - mab.requires(ModuleDesc.of("java.base"), Set.of(AccessFlag.MANDATED, AccessFlag.SYNTHETIC), null); - // list unqualified exports & opens - linkNew().packages() - .forEach((name, pkg) -> { - switch (pkg.packageAccess()) { - case EXPORTED -> mab.exports(PackageDesc.of(name), List.of()); - case OPEN -> mab.opens(PackageDesc.of(name), List.of()); - } - }); - } - )); + ModuleDesc.of(moduleName), + mab -> { + mab.moduleName(ModuleDesc.of(moduleName)); + mab.moduleVersion(moduleVersion); + // java.base is always required + mab.requires(ModuleDesc.of("java.base"), Set.of(AccessFlag.MANDATED, AccessFlag.SYNTHETIC), null); + // list unqualified exports & opens + linkNew().packages() + .forEach((name, pkg) -> { + switch (pkg.packageAccess()) { + case EXPORTED -> mab.exports(PackageDesc.of(name), List.of()); + case OPEN -> mab.opens(PackageDesc.of(name), List.of()); + } + }); + })); zb.with(ModulePackagesAttribute.of(linkNew().packages().keySet().stream() - .map(n -> zb.constantPool().packageEntry(PackageDesc.of(n))) - .collect(Util.toList()) - )); + .map(n -> zb.constantPool().packageEntry(PackageDesc.of(n))) + .collect(Util.toList()))); }); return new MemoryResource("module-info.class", bytes); } @@ -1049,13 +1046,14 @@ private Class loadClassFromDescriptor(String descriptor, int idx) throws Clas }; } - private Class defineOrGetClass(final String binaryName, final Resource resource, final ProtectionDomain pd) throws IOException { + private Class defineOrGetClass(final String binaryName, final Resource resource, final ProtectionDomain pd) + throws IOException { return defineOrGetClass(binaryName, resource.asBuffer(), pd); } private Class defineOrGetClass(final String binaryName, final ByteBuffer buffer, final ProtectionDomain pd) { String packageName = Util.packageName(binaryName); - if (! packageName.isEmpty()) { + if (!packageName.isEmpty()) { loadPackageDirect(packageName); } Class clazz = findLoadedClass(binaryName); @@ -1084,7 +1082,8 @@ private Class defineOrGetClass(final String binaryName, final ByteBuffer buff // Somewhat unsupported operations protected final Object getClassLoadingLock(final String className) { - /* this is tricky: we know that something is trying to load the class + /* + * this is tricky: we know that something is trying to load the class * under the lock; so instead load the class outside the lock, and use the * class itself as the class loading lock. * If the class is not found, return a new object, because no conflict will be possible anyway. @@ -1123,12 +1122,12 @@ private Package loadPackage(LoadedModule module, String pkg) { protected final Package[] getPackages() { return linkPackages().modulesByPackage() - .entrySet() - .stream() - .sorted() - .map(e -> loadPackage(e.getValue(), e.getKey())) - .filter(Objects::nonNull) - .toArray(Package[]::new); + .entrySet() + .stream() + .sorted() + .map(e -> loadPackage(e.getValue(), e.getKey())) + .filter(Objects::nonNull) + .toArray(Package[]::new); } // Fully unsupported operations @@ -1160,7 +1159,6 @@ protected final Enumeration findResources(final String name) { throw new UnsupportedOperationException(); } - String mainClassName() { return mainClassName; } @@ -1222,7 +1220,8 @@ public static final class ClassLoaderConfiguration { private final List resourceLoaders; private final ModuleDescriptor descriptor; - ClassLoaderConfiguration(final ModuleLoader moduleLoader, final List resourceLoaders, final ModuleDescriptor descriptor) { + ClassLoaderConfiguration(final ModuleLoader moduleLoader, final List resourceLoaders, + final ModuleDescriptor descriptor) { valid = Thread.currentThread(); this.moduleLoader = moduleLoader; this.resourceLoaders = resourceLoaders; @@ -1268,7 +1267,8 @@ public Set findAll() { } } - private static final Logger log = Logger.getLogger("io.github.dmlloyd.modules"); + private static final Logger log = Logger.getLogger(ModuleClassLoader.class.getModule().getName()); private static final StackWalker stackWalker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); - private static final Function, Class> callerFinder = s -> s.map(StackWalker.StackFrame::getDeclaringClass).filter(c -> c.getClassLoader() != null).findFirst().orElse(null); + private static final Function, Class> callerFinder = s -> s + .map(StackWalker.StackFrame::getDeclaringClass).filter(c -> c.getClassLoader() != null).findFirst().orElse(null); } diff --git a/src/main/java/io/github/dmlloyd/modules/ModuleDescriptorLoader.java b/src/main/java/io/smallrye/modules/ModuleDescriptorLoader.java similarity index 84% rename from src/main/java/io/github/dmlloyd/modules/ModuleDescriptorLoader.java rename to src/main/java/io/smallrye/modules/ModuleDescriptorLoader.java index 9ed78d0..08ccc74 100644 --- a/src/main/java/io/github/dmlloyd/modules/ModuleDescriptorLoader.java +++ b/src/main/java/io/smallrye/modules/ModuleDescriptorLoader.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.io.IOException; import java.io.InputStream; @@ -6,10 +6,10 @@ import java.util.Map; import java.util.jar.Manifest; -import io.github.dmlloyd.modules.desc.ModuleDescriptor; -import io.github.dmlloyd.modules.desc.PackageAccess; import io.smallrye.common.resource.Resource; import io.smallrye.common.resource.ResourceLoader; +import io.smallrye.modules.desc.ModuleDescriptor; +import io.smallrye.modules.desc.PackageAccess; /** * A loader for a module descriptor. @@ -26,14 +26,17 @@ public interface ModuleDescriptorLoader { ModuleDescriptor loadDescriptor(String moduleName, List loaders) throws IOException; /** - * {@return a module opener which looks for a {@code module-info.class} file, or otherwise constructs an automatic module, possibly with no dependencies} + * {@return a module opener which looks for a {@code module-info.class} file, or otherwise constructs an automatic module, + * possibly with no dependencies} */ static ModuleDescriptorLoader basic() { return ModuleDescriptorLoader::loadDescriptorBasic; } /** - * {@return a module opener which looks for a {@code module-info.class} file, or otherwise constructs an automatic module, possibly with no dependencies} + * {@return a module opener which looks for a {@code module-info.class} file, or otherwise constructs an automatic module, + * possibly with no dependencies} + * * @param extraAccesses extra accesses to add (must not be {@code null}) */ static ModuleDescriptorLoader basic(Map> extraAccesses) { @@ -44,7 +47,8 @@ private static ModuleDescriptor loadDescriptorBasic(String moduleName, List loaders, Map> extraAccesses) throws IOException { + private static ModuleDescriptor loadDescriptorBasic(String moduleName, List loaders, + Map> extraAccesses) throws IOException { for (ResourceLoader loader : loaders) { Resource resource = loader.findResource("module-info.class"); if (resource != null) { diff --git a/src/main/java/io/github/dmlloyd/modules/ModuleFinder.java b/src/main/java/io/smallrye/modules/ModuleFinder.java similarity index 96% rename from src/main/java/io/github/dmlloyd/modules/ModuleFinder.java rename to src/main/java/io/smallrye/modules/ModuleFinder.java index a3fcdd9..aaf98ec 100644 --- a/src/main/java/io/github/dmlloyd/modules/ModuleFinder.java +++ b/src/main/java/io/smallrye/modules/ModuleFinder.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.io.BufferedReader; import java.io.Closeable; @@ -15,9 +15,9 @@ import javax.xml.stream.XMLStreamException; -import io.github.dmlloyd.modules.desc.ModuleDescriptor; import io.smallrye.common.resource.Resource; import io.smallrye.common.resource.ResourceLoader; +import io.smallrye.modules.desc.ModuleDescriptor; /** * A module definition finder. @@ -35,7 +35,8 @@ default ModuleFinder andThen(ModuleFinder other) { }; } - default void close() {} + default void close() { + } ModuleFinder EMPTY = __ -> null; @@ -49,7 +50,7 @@ interface XMLCloser extends AutoCloseable { } for (Path realPath : paths) { realPath = realPath.resolve(name); - if (! Files.isDirectory(realPath)) { + if (!Files.isDirectory(realPath)) { return null; } List items = null; diff --git a/src/main/java/io/github/dmlloyd/modules/ModuleLoadException.java b/src/main/java/io/smallrye/modules/ModuleLoadException.java similarity index 82% rename from src/main/java/io/github/dmlloyd/modules/ModuleLoadException.java rename to src/main/java/io/smallrye/modules/ModuleLoadException.java index b99d742..a886bb3 100644 --- a/src/main/java/io/github/dmlloyd/modules/ModuleLoadException.java +++ b/src/main/java/io/smallrye/modules/ModuleLoadException.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.io.Serial; @@ -7,17 +7,17 @@ */ public class ModuleLoadException extends RuntimeException { @Serial - private static final long serialVersionUID = - 8455560757184556454L; + private static final long serialVersionUID = -8455560757184556454L; /** - * Constructs a new {@code ModuleLoadException} instance. The message is left blank ({@code null}), and no + * Constructs a new {@code ModuleLoadException} instance. The message is left blank ({@code null}), and no * cause is specified. */ public ModuleLoadException() { } /** - * Constructs a new {@code ModuleLoadException} instance with an initial message. No + * Constructs a new {@code ModuleLoadException} instance with an initial message. No * cause is specified. * * @param msg the message @@ -27,7 +27,7 @@ public ModuleLoadException(final String msg) { } /** - * Constructs a new {@code ModuleLoadException} instance with an initial cause. If + * Constructs a new {@code ModuleLoadException} instance with an initial cause. If * a non-{@code null} cause is specified, its message is used to initialize the message of this * {@code ModuleLoadException}; otherwise the message is left blank ({@code null}). * @@ -40,7 +40,7 @@ public ModuleLoadException(final Throwable cause) { /** * Constructs a new {@code ModuleLoadException} instance with an initial message and cause. * - * @param msg the message + * @param msg the message * @param cause the cause */ public ModuleLoadException(final String msg, final Throwable cause) { diff --git a/src/main/java/io/github/dmlloyd/modules/ModuleLoader.java b/src/main/java/io/smallrye/modules/ModuleLoader.java similarity index 97% rename from src/main/java/io/github/dmlloyd/modules/ModuleLoader.java rename to src/main/java/io/smallrye/modules/ModuleLoader.java index 82e438a..7b661fc 100644 --- a/src/main/java/io/github/dmlloyd/modules/ModuleLoader.java +++ b/src/main/java/io/smallrye/modules/ModuleLoader.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.io.Closeable; import java.io.IOException; @@ -138,13 +138,12 @@ protected ModuleClassLoader findModule(String moduleName) { * @param descriptorLoader the module descriptor opener (must not be {@code null}) * @return the defined module, or {@code null} if the module was already defined * @throws ModuleLoadException if the module cannot be defined due to an error, or a previous module definition - * for this name has failed + * for this name has failed */ protected final ModuleClassLoader tryDefineModule( - String moduleName, - List loaderOpeners, - ModuleDescriptorLoader descriptorLoader - ) throws ModuleLoadException { + String moduleName, + List loaderOpeners, + ModuleDescriptorLoader descriptorLoader) throws ModuleLoadException { ConcurrentHashMap loadedModules = this.definedModules; checkClosed(); DefinedModule existing = loadedModules.get(moduleName); diff --git a/src/main/java/io/github/dmlloyd/modules/ModuleNotFoundException.java b/src/main/java/io/smallrye/modules/ModuleNotFoundException.java similarity index 89% rename from src/main/java/io/github/dmlloyd/modules/ModuleNotFoundException.java rename to src/main/java/io/smallrye/modules/ModuleNotFoundException.java index 0d92d6d..be6a318 100644 --- a/src/main/java/io/github/dmlloyd/modules/ModuleNotFoundException.java +++ b/src/main/java/io/smallrye/modules/ModuleNotFoundException.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.io.Serial; @@ -10,14 +10,14 @@ public class ModuleNotFoundException extends ModuleLoadException { private static final long serialVersionUID = 1537142487227363108L; /** - * Constructs a new {@code ModuleNotFoundException} instance. The message is left blank ({@code null}), and no + * Constructs a new {@code ModuleNotFoundException} instance. The message is left blank ({@code null}), and no * cause is specified. */ public ModuleNotFoundException() { } /** - * Constructs a new {@code ModuleNotFoundException} instance with an initial message. No + * Constructs a new {@code ModuleNotFoundException} instance with an initial message. No * cause is specified. * * @param msg the message @@ -27,7 +27,7 @@ public ModuleNotFoundException(final String msg) { } /** - * Constructs a new {@code ModuleNotFoundException} instance with an initial cause. If + * Constructs a new {@code ModuleNotFoundException} instance with an initial cause. If * a non-{@code null} cause is specified, its message is used to initialize the message of this * {@code ModuleNotFoundException}; otherwise the message is left blank ({@code null}). * @@ -40,7 +40,7 @@ public ModuleNotFoundException(final Throwable cause) { /** * Constructs a new {@code ModuleNotFoundException} instance with an initial message and cause. * - * @param msg the message + * @param msg the message * @param cause the cause */ public ModuleNotFoundException(final String msg, final Throwable cause) { diff --git a/src/main/java/io/github/dmlloyd/modules/ResourceLoaderOpener.java b/src/main/java/io/smallrye/modules/ResourceLoaderOpener.java similarity index 98% rename from src/main/java/io/github/dmlloyd/modules/ResourceLoaderOpener.java rename to src/main/java/io/smallrye/modules/ResourceLoaderOpener.java index b6c9801..bb34462 100644 --- a/src/main/java/io/github/dmlloyd/modules/ResourceLoaderOpener.java +++ b/src/main/java/io/smallrye/modules/ResourceLoaderOpener.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules; +package io.smallrye.modules; import java.io.IOException; import java.net.URL; diff --git a/src/main/java/io/github/dmlloyd/modules/desc/Dependency.java b/src/main/java/io/smallrye/modules/desc/Dependency.java similarity index 76% rename from src/main/java/io/github/dmlloyd/modules/desc/Dependency.java rename to src/main/java/io/smallrye/modules/desc/Dependency.java index 3441674..69226dd 100644 --- a/src/main/java/io/github/dmlloyd/modules/desc/Dependency.java +++ b/src/main/java/io/smallrye/modules/desc/Dependency.java @@ -1,29 +1,28 @@ -package io.github.dmlloyd.modules.desc; +package io.smallrye.modules.desc; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.IntStream; -import io.github.dmlloyd.modules.ModuleLoader; -import io.github.dmlloyd.modules.impl.Util; import io.smallrye.common.constraint.Assert; +import io.smallrye.modules.ModuleLoader; +import io.smallrye.modules.impl.Util; /** * A dependency description. * If no optional dependency resolver is given, the module's own dependency resolver will be used. * - * @param moduleName the dependency name (must not be {@code null}) - * @param modifiers the dependency modifiers (must not be {@code null}) - * @param moduleLoader the optional module loader to use for this dependency (must not be {@code null}) - * @param packageAccesses extra package access to the given dependency (must not be {@code null}) + * @param moduleName the dependency name (must not be {@code null}) + * @param modifiers the dependency modifiers (must not be {@code null}) + * @param moduleLoader the optional module loader to use for this dependency (must not be {@code null}) + * @param packageAccesses extra package access to the given dependency (must not be {@code null}) */ public record Dependency( - String moduleName, - Modifiers modifiers, - Optional moduleLoader, - Map packageAccesses -) { + String moduleName, + Modifiers modifiers, + Optional moduleLoader, + Map packageAccesses) { public Dependency { Assert.checkNotNullParam("moduleName", moduleName); Assert.checkNotNullParam("modifiers", modifiers); @@ -56,7 +55,8 @@ public Dependency(String moduleName, Modifier modifier) { public Dependency withAdditionalPackageAccesses(Map packageAccesses) { Assert.checkNotNullParam("packageAccesses", packageAccesses); - return new Dependency(this.moduleName, this.modifiers, this.moduleLoader, Util.merge(this.packageAccesses, packageAccesses, PackageAccess::max)); + return new Dependency(this.moduleName, this.modifiers, this.moduleLoader, + Util.merge(this.packageAccesses, packageAccesses, PackageAccess::max)); } /** @@ -70,7 +70,7 @@ public boolean isSynthetic() { * {@return {@code true} if the dependency is not synthetic} */ public boolean isNonSynthetic() { - return ! modifiers.contains(Modifier.SYNTHETIC); + return !modifiers.contains(Modifier.SYNTHETIC); } /** @@ -84,7 +84,7 @@ public boolean isMandated() { * {@return {@code true} if the dependency is not mandated} */ public boolean isNonMandated() { - return ! modifiers.contains(Modifier.MANDATED); + return !modifiers.contains(Modifier.MANDATED); } /** @@ -98,7 +98,7 @@ public boolean isOptional() { * {@return {@code true} if the dependency is not optional} */ public boolean isNonOptional() { - return ! modifiers.contains(Modifier.OPTIONAL); + return !modifiers.contains(Modifier.OPTIONAL); } /** @@ -112,7 +112,7 @@ public boolean isTransitive() { * {@return {@code true} if the dependency is not transitive} */ public boolean isNonTransitive() { - return ! modifiers.contains(Modifier.TRANSITIVE); + return !modifiers.contains(Modifier.TRANSITIVE); } public boolean isLinked() { @@ -120,7 +120,7 @@ public boolean isLinked() { } public boolean isNonLinked() { - return ! modifiers.contains(Modifier.LINKED); + return !modifiers.contains(Modifier.LINKED); } public boolean isRead() { @@ -128,7 +128,7 @@ public boolean isRead() { } public boolean isNonRead() { - return ! modifiers.contains(Modifier.READ); + return !modifiers.contains(Modifier.READ); } public boolean isServices() { @@ -136,7 +136,7 @@ public boolean isServices() { } public boolean isNonServices() { - return ! modifiers.contains(Modifier.SERVICES); + return !modifiers.contains(Modifier.SERVICES); } /** @@ -182,9 +182,8 @@ public enum Modifier implements ModifierFlag { public static final List values = List.of(values()); private static final List> sets = List.copyOf(IntStream.range(0, 128) - .mapToObj(bits -> new Modifiers(values, Modifier::forBits, bits)) - .toList() - ); + .mapToObj(bits -> new Modifiers(values, Modifier::forBits, bits)) + .toList()); public static Modifiers set() { return sets.get(0); @@ -206,16 +205,21 @@ public static Modifiers set(Modifier modifier0, Modifier modifier1, Mo return sets.get(bit(modifier0) | bit(modifier1) | bit(modifier2) | bit(modifier3)); } - public static Modifiers set(Modifier modifier0, Modifier modifier1, Modifier modifier2, Modifier modifier3, Modifier modifier4) { + public static Modifiers set(Modifier modifier0, Modifier modifier1, Modifier modifier2, Modifier modifier3, + Modifier modifier4) { return sets.get(bit(modifier0) | bit(modifier1) | bit(modifier2) | bit(modifier3) | bit(modifier4)); } - public static Modifiers set(Modifier modifier0, Modifier modifier1, Modifier modifier2, Modifier modifier3, Modifier modifier4, Modifier modifier5) { - return sets.get(bit(modifier0) | bit(modifier1) | bit(modifier2) | bit(modifier3) | bit(modifier4) | bit(modifier5)); + public static Modifiers set(Modifier modifier0, Modifier modifier1, Modifier modifier2, Modifier modifier3, + Modifier modifier4, Modifier modifier5) { + return sets + .get(bit(modifier0) | bit(modifier1) | bit(modifier2) | bit(modifier3) | bit(modifier4) | bit(modifier5)); } - public static Modifiers set(Modifier modifier0, Modifier modifier1, Modifier modifier2, Modifier modifier3, Modifier modifier4, Modifier modifier5, Modifier modifier6) { - return sets.get(bit(modifier0) | bit(modifier1) | bit(modifier2) | bit(modifier3) | bit(modifier4) | bit(modifier5) | bit(modifier6)); + public static Modifiers set(Modifier modifier0, Modifier modifier1, Modifier modifier2, Modifier modifier3, + Modifier modifier4, Modifier modifier5, Modifier modifier6) { + return sets.get(bit(modifier0) | bit(modifier1) | bit(modifier2) | bit(modifier3) | bit(modifier4) | bit(modifier5) + | bit(modifier6)); } private static int bit(final Modifier item) { @@ -230,5 +234,6 @@ private static Modifiers forBits(int bits) { /** * The standard {@code java.base} dependency, for convenience. */ - public static final Dependency JAVA_BASE = new Dependency("java.base", Modifier.set(Modifier.SYNTHETIC, Modifier.MANDATED), Optional.empty(), Map.of()); + public static final Dependency JAVA_BASE = new Dependency("java.base", Modifier.set(Modifier.SYNTHETIC, Modifier.MANDATED), + Optional.empty(), Map.of()); } diff --git a/src/main/java/io/github/dmlloyd/modules/desc/ModifierFlag.java b/src/main/java/io/smallrye/modules/desc/ModifierFlag.java similarity index 78% rename from src/main/java/io/github/dmlloyd/modules/desc/ModifierFlag.java rename to src/main/java/io/smallrye/modules/desc/ModifierFlag.java index 0952747..ffeba5b 100644 --- a/src/main/java/io/github/dmlloyd/modules/desc/ModifierFlag.java +++ b/src/main/java/io/smallrye/modules/desc/ModifierFlag.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules.desc; +package io.smallrye.modules.desc; /** * A modifier for a module descriptor item. diff --git a/src/main/java/io/github/dmlloyd/modules/desc/Modifiers.java b/src/main/java/io/smallrye/modules/desc/Modifiers.java similarity index 98% rename from src/main/java/io/github/dmlloyd/modules/desc/Modifiers.java rename to src/main/java/io/smallrye/modules/desc/Modifiers.java index 170fd18..76b9d7c 100644 --- a/src/main/java/io/github/dmlloyd/modules/desc/Modifiers.java +++ b/src/main/java/io/smallrye/modules/desc/Modifiers.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules.desc; +package io.smallrye.modules.desc; import java.util.List; import java.util.function.IntFunction; diff --git a/src/main/java/io/github/dmlloyd/modules/desc/ModuleDescriptor.java b/src/main/java/io/smallrye/modules/desc/ModuleDescriptor.java similarity index 81% rename from src/main/java/io/github/dmlloyd/modules/desc/ModuleDescriptor.java rename to src/main/java/io/smallrye/modules/desc/ModuleDescriptor.java index 26a6ea9..8419f3c 100644 --- a/src/main/java/io/github/dmlloyd/modules/desc/ModuleDescriptor.java +++ b/src/main/java/io/smallrye/modules/desc/ModuleDescriptor.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules.desc; +package io.smallrye.modules.desc; import java.io.BufferedReader; import java.io.IOException; @@ -30,8 +30,6 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; -import io.github.dmlloyd.modules.impl.TextIter; -import io.github.dmlloyd.modules.impl.Util; import io.smallrye.classfile.Annotation; import io.smallrye.classfile.AnnotationElement; import io.smallrye.classfile.AnnotationValue; @@ -52,22 +50,23 @@ import io.smallrye.common.constraint.Assert; import io.smallrye.common.resource.Resource; import io.smallrye.common.resource.ResourceLoader; +import io.smallrye.modules.impl.TextIter; +import io.smallrye.modules.impl.Util; /** * A descriptor for initially defining a module. */ // todo: write XML, read/write binary public record ModuleDescriptor( - String name, - Optional version, - Modifiers modifiers, - Optional mainClass, - Optional location, - List dependencies, - Set uses, - Map> provides, - Map packages -) { + String name, + Optional version, + Modifiers modifiers, + Optional mainClass, + Optional location, + List dependencies, + Set uses, + Map> provides, + Map packages) { public ModuleDescriptor { Assert.checkNotNullParam("name", name); @@ -84,34 +83,31 @@ public record ModuleDescriptor( public ModuleDescriptor withName(final String name) { return new ModuleDescriptor( - name, - version, - modifiers, - mainClass, - location, - dependencies, - uses, - provides, - packages - ); - } - - - public ModuleDescriptor withAdditionalDependencies(final List list) { - if (list.isEmpty()) { - return this; - } else { - return new ModuleDescriptor( name, version, modifiers, mainClass, location, - Util.concat(dependencies, list), + dependencies, uses, provides, - packages - ); + packages); + } + + public ModuleDescriptor withAdditionalDependencies(final List list) { + if (list.isEmpty()) { + return this; + } else { + return new ModuleDescriptor( + name, + version, + modifiers, + mainClass, + location, + Util.concat(dependencies, list), + uses, + provides, + packages); } } @@ -120,16 +116,15 @@ public ModuleDescriptor withPackages(final Map packages) { return this; } else { return new ModuleDescriptor( - name, - version, - modifiers, - mainClass, - location, - dependencies, - uses, - provides, - packages - ); + name, + version, + modifiers, + mainClass, + location, + dependencies, + uses, + provides, + packages); } } @@ -156,9 +151,8 @@ public ModuleDescriptor withDiscoveredPackages(final List loader public ModuleDescriptor withDiscoveredPackages(final ResourceLoader loader) throws IOException { return withDiscoveredPackages(loader, (pn, existing) -> { if (pn.contains(".impl.") || pn.endsWith(".impl") - || pn.contains(".private_.") || pn.endsWith(".private_") - || pn.contains("._private.") || pn.endsWith("._private") - ) { + || pn.contains(".private_.") || pn.endsWith(".private_") + || pn.contains("._private.") || pn.endsWith("._private")) { return existing == null ? PackageInfo.PRIVATE : existing; } else { return existing == null ? PackageInfo.EXPORTED : existing.withAccessAtLeast(PackageAccess.EXPORTED); @@ -167,25 +161,27 @@ public ModuleDescriptor withDiscoveredPackages(final ResourceLoader loader) thro } public ModuleDescriptor withDiscoveredPackages(final ResourceLoader loader, final PackageAccess access) throws IOException { - return withDiscoveredPackages(loader, (ignored0, existing) -> existing == null ? PackageInfo.forAccess(access) : existing.withAccessAtLeast(access)); + return withDiscoveredPackages(loader, + (ignored0, existing) -> existing == null ? PackageInfo.forAccess(access) : existing.withAccessAtLeast(access)); } - public ModuleDescriptor withDiscoveredPackages(final ResourceLoader loader, final BiFunction packageFunction) throws IOException { - Map packages = searchPackages(loader.findResource("/"), packageFunction, this.packages, new HashSet<>()); + public ModuleDescriptor withDiscoveredPackages(final ResourceLoader loader, + final BiFunction packageFunction) throws IOException { + Map packages = searchPackages(loader.findResource("/"), packageFunction, this.packages, + new HashSet<>()); if (packages == this.packages) { return this; } else { return new ModuleDescriptor( - name, - version, - modifiers, - mainClass, - location, - dependencies, - uses, - provides, - packages - ); + name, + version, + modifiers, + mainClass, + location, + dependencies, + uses, + provides, + packages); } } @@ -194,20 +190,21 @@ public ModuleDescriptor withAdditionalServiceProviders(Map> return this; } else { return new ModuleDescriptor( - name, - version, - modifiers, - mainClass, - location, - dependencies, - uses, - Util.merge(provides(), provides, Util::concat), - packages - ); + name, + version, + modifiers, + mainClass, + location, + dependencies, + uses, + Util.merge(provides(), provides, Util::concat), + packages); } } - private Map searchPackages(final Resource dir, final BiFunction packageFunction, Map map, Set found) throws IOException { + private Map searchPackages(final Resource dir, + final BiFunction packageFunction, Map map, Set found) + throws IOException { try (DirectoryStream ds = dir.openDirectoryStream()) { for (Resource child : ds) { if (child.isDirectory()) { @@ -264,12 +261,12 @@ public enum Modifier implements ModifierFlag { */ UNNAMED, ; + public static final List values = List.of(values()); private static final List> sets = List.copyOf(IntStream.range(0, 16) - .mapToObj(bits -> new Modifiers(values, Modifier::forBits, bits)) - .toList() - ); + .mapToObj(bits -> new Modifiers(values, Modifier::forBits, bits)) + .toList()); public static Modifiers set() { return sets.get(0); @@ -304,13 +301,13 @@ private static Modifiers forBits(int bits) { * Obtain a module descriptor from a {@code module-info.class} file's contents. * * @param moduleInfo the bytes of the {@code module-info.class} (must not be {@code null}) - * @param resourceLoaders the loaders from which packages may be discovered if not given in the descriptor (must not be {@code null}) + * @param resourceLoaders the loaders from which packages may be discovered if not given in the descriptor (must not be + * {@code null}) * @return the module descriptor (not {@code null}) */ public static ModuleDescriptor fromModuleInfo( - Resource moduleInfo, - List resourceLoaders - ) throws IOException { + Resource moduleInfo, + List resourceLoaders) throws IOException { return fromModuleInfo(moduleInfo, resourceLoaders, Map.of()); } @@ -318,21 +315,21 @@ public static ModuleDescriptor fromModuleInfo( * Obtain a module descriptor from a {@code module-info.class} file's contents. * * @param moduleInfo the bytes of the {@code module-info.class} (must not be {@code null}) - * @param resourceLoaders the loaders from which packages may be discovered if not given in the descriptor (must not be {@code null}) + * @param resourceLoaders the loaders from which packages may be discovered if not given in the descriptor (must not be + * {@code null}) * @param extraAccesses extra package accesses to merge into dependencies (must not be {@code null}) * @return the module descriptor (not {@code null}) */ public static ModuleDescriptor fromModuleInfo( - Resource moduleInfo, - List resourceLoaders, - Map> extraAccesses - ) throws IOException { + Resource moduleInfo, + List resourceLoaders, + Map> extraAccesses) throws IOException { final Map> modifiedExtraAccesses = new HashMap<>(extraAccesses); ClassModel classModel; try (InputStream is = moduleInfo.openStream()) { classModel = ClassFile.of().parse(is.readAllBytes()); } - if (! classModel.isModuleInfo()) { + if (!classModel.isModuleInfo()) { throw new IllegalArgumentException("Not a valid module descriptor"); } ModuleAttribute ma = classModel.findAttribute(Attributes.module()).orElseThrow(ModuleDescriptor::noModuleAttribute); @@ -350,12 +347,13 @@ public static ModuleDescriptor fromModuleInfo( switch (ann.className().stringValue()) { case "io.smallrye.common.annotation.AddExports", "io.smallrye.common.annotation.AddOpens" -> processAccessAnnotation(ann, modifiedExtraAccesses); - case "io.smallrye.common.annotation.AddExports$List", "io.smallrye.common.annotation.AddOpens$List" -> { + case "io.smallrye.common.annotation.AddExports$List", "io.smallrye.common.annotation.AddOpens$List" -> { for (AnnotationElement element : ann.elements()) { if (element.name().stringValue().equals("value")) { AnnotationValue.OfArray val = (AnnotationValue.OfArray) element.value(); for (AnnotationValue value : val.values()) { - processAccessAnnotation(((AnnotationValue.OfAnnotation)value).annotation(), modifiedExtraAccesses); + processAccessAnnotation(((AnnotationValue.OfAnnotation) value).annotation(), + modifiedExtraAccesses); } } } @@ -367,16 +365,15 @@ public static ModuleDescriptor fromModuleInfo( Map packagesMap = new HashMap<>(); for (ModuleOpenInfo moduleOpenInfo : ma.opens()) { String packageName = moduleOpenInfo.openedPackage().name().stringValue().replace('/', '.').intern(); - packagesMap.put(packageName, open ? PackageInfo.OPEN : PackageInfo.of( - PackageAccess.PRIVATE, - Set.of(), - moduleOpenInfo.opensTo().stream() - .map(ModuleEntry::name) - .map(Utf8Entry::stringValue) - .map(String::intern) - .collect(Collectors.toUnmodifiableSet() - ) - )); + packagesMap.put(packageName, open ? PackageInfo.OPEN + : PackageInfo.of( + PackageAccess.PRIVATE, + Set.of(), + moduleOpenInfo.opensTo().stream() + .map(ModuleEntry::name) + .map(Utf8Entry::stringValue) + .map(String::intern) + .collect(Collectors.toUnmodifiableSet()))); } for (ModuleExportInfo e : ma.exports()) { String packageName = e.exportedPackage().name().stringValue().replace('/', '.').intern(); @@ -394,57 +391,54 @@ public static ModuleDescriptor fromModuleInfo( } else { // exports to some, otherwise whatever the existing level was Set exportTargets = e.exportsTo().stream() - .map(ModuleEntry::name) - .map(Utf8Entry::stringValue) - .map(String::intern) - .collect(Collectors.toUnmodifiableSet()); - packagesMap.put(packageName, packagesMap.getOrDefault(packageName, PackageInfo.PRIVATE).withExportTargets(exportTargets)); + .map(ModuleEntry::name) + .map(Utf8Entry::stringValue) + .map(String::intern) + .collect(Collectors.toUnmodifiableSet()); + packagesMap.put(packageName, + packagesMap.getOrDefault(packageName, PackageInfo.PRIVATE).withExportTargets(exportTargets)); } } mpa.ifPresent(modulePackagesAttribute -> modulePackagesAttribute.packages().stream() - .map(PackageEntry::name) - .map(Utf8Entry::stringValue) - .map(s -> s.replace('/', '.')) - .map(String::intern) - .forEach(name -> packagesMap.putIfAbsent(name, PackageInfo.PRIVATE)) - ); - String moduleName = ma.moduleName().name().stringValue(); - ModuleDescriptor desc = new ModuleDescriptor( - moduleName, - ma.moduleVersion().map(Utf8Entry::stringValue), - mods, - mca.map(ModuleMainClassAttribute::mainClass) - .map(ClassEntry::name) - .map(Utf8Entry::stringValue) - .map(s -> s.replace('/', '.')) - .map(String::intern), - Optional.empty(), - ma.requires().stream().map( - r -> new Dependency( - r.requires().name().stringValue(), - toModifiers(r.requiresFlags()), - Optional.empty(), - modifiedExtraAccesses.getOrDefault(r.requires().name().stringValue(), Map.of()) - ) - ).collect(Util.toList()), - ma.uses().stream() - .map(ClassEntry::name) + .map(PackageEntry::name) .map(Utf8Entry::stringValue) .map(s -> s.replace('/', '.')) .map(String::intern) - .collect(Collectors.toUnmodifiableSet() - ), - ma.provides().stream().map( - mpi -> Map.entry(mpi.provides().name().stringValue().replace('/', '.').intern(), - mpi.providesWith().stream() + .forEach(name -> packagesMap.putIfAbsent(name, PackageInfo.PRIVATE))); + String moduleName = ma.moduleName().name().stringValue(); + ModuleDescriptor desc = new ModuleDescriptor( + moduleName, + ma.moduleVersion().map(Utf8Entry::stringValue), + mods, + mca.map(ModuleMainClassAttribute::mainClass) + .map(ClassEntry::name) + .map(Utf8Entry::stringValue) + .map(s -> s.replace('/', '.')) + .map(String::intern), + Optional.empty(), + ma.requires().stream().map( + r -> new Dependency( + r.requires().name().stringValue(), + toModifiers(r.requiresFlags()), + Optional.empty(), + modifiedExtraAccesses.getOrDefault(r.requires().name().stringValue(), Map.of()))) + .collect(Util.toList()), + ma.uses().stream() .map(ClassEntry::name) .map(Utf8Entry::stringValue) .map(s -> s.replace('/', '.')) .map(String::intern) - .collect(Util.toList())) - ).collect(Util.toMap()), - packagesMap - ); + .collect(Collectors.toUnmodifiableSet()), + ma.provides().stream().map( + mpi -> Map.entry(mpi.provides().name().stringValue().replace('/', '.').intern(), + mpi.providesWith().stream() + .map(ClassEntry::name) + .map(Utf8Entry::stringValue) + .map(s -> s.replace('/', '.')) + .map(String::intern) + .collect(Util.toList()))) + .collect(Util.toMap()), + packagesMap); if (mpa.isEmpty()) { desc = desc.withDiscoveredPackages(resourceLoaders); } @@ -456,8 +450,9 @@ private static void processAccessAnnotation(Annotation ann, Map packages = null; for (AnnotationElement element : ann.elements()) { switch (element.name().stringValue()) { - case "module" -> moduleName = ((AnnotationValue.OfString)element.value()).stringValue(); - case "packages" -> packages = ((AnnotationValue.OfArray)element.value()).values().stream().map(AnnotationValue.OfString.class::cast).map(AnnotationValue.OfString::stringValue).toList(); + case "module" -> moduleName = ((AnnotationValue.OfString) element.value()).stringValue(); + case "packages" -> packages = ((AnnotationValue.OfArray) element.value()).values().stream() + .map(AnnotationValue.OfString.class::cast).map(AnnotationValue.OfString::stringValue).toList(); } } if (moduleName == null || moduleName.equals("ALL-UNNAMED") || packages == null) { @@ -481,11 +476,13 @@ private static void processAccessAnnotation(Annotation ann, Map resourceLoaders) throws IOException { + public static ModuleDescriptor fromManifest(String defaultName, String defaultVersion, Manifest manifest, + List resourceLoaders) throws IOException { return fromManifest(defaultName, defaultVersion, manifest, resourceLoaders, Map.of()); } - public static ModuleDescriptor fromManifest(String defaultName, String defaultVersion, Manifest manifest, List resourceLoaders, Map> extraAccesses) throws IOException { + public static ModuleDescriptor fromManifest(String defaultName, String defaultVersion, Manifest manifest, + List resourceLoaders, Map> extraAccesses) throws IOException { var mainAttributes = manifest.getMainAttributes(); String moduleName = mainAttributes.getValue("Automatic-Module-Name"); String version = mainAttributes.getValue("Module-Version"); @@ -495,7 +492,8 @@ public static ModuleDescriptor fromManifest(String defaultName, String defaultVe if (version == null) { version = defaultVersion; } - boolean enableNativeAccess = ! Objects.requireNonNullElse(mainAttributes.getValue("Enable-Native-Access"), "").trim().isEmpty(); + boolean enableNativeAccess = !Objects.requireNonNullElse(mainAttributes.getValue("Enable-Native-Access"), "").trim() + .isEmpty(); String mainClass = mainAttributes.getValue(Name.MAIN_CLASS); String depString = mainAttributes.getValue("Dependencies"); Map> addOpens = parseManifestAdd(mainAttributes.getValue("Add-Opens")); @@ -527,12 +525,11 @@ public static ModuleDescriptor fromManifest(String defaultName, String defaultVe Map accesses; if (addOpens.containsKey(depName) || addExports.containsKey(depName)) { accesses = Stream.concat( - Stream.concat( - addExports.get(depName).stream().map(pkg -> Map.entry(pkg, PackageAccess.EXPORTED)), - addOpens.get(depName).stream().map(pkg -> Map.entry(pkg, PackageAccess.OPEN)) - ), - extraAccesses.getOrDefault(depName, Map.of()).entrySet().stream() - ).collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, PackageAccess::max)); + Stream.concat( + addExports.get(depName).stream().map(pkg -> Map.entry(pkg, PackageAccess.EXPORTED)), + addOpens.get(depName).stream().map(pkg -> Map.entry(pkg, PackageAccess.OPEN))), + extraAccesses.getOrDefault(depName, Map.of()).entrySet().stream()) + .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, PackageAccess::max)); } else { accesses = Map.of(); } @@ -553,16 +550,15 @@ public static ModuleDescriptor fromManifest(String defaultName, String defaultVe mods = mods.with(Modifier.NATIVE_ACCESS); } return new ModuleDescriptor( - moduleName, - Optional.ofNullable(version), - mods, - Optional.ofNullable(mainClass), - Optional.empty(), - dependencies, - Set.of(), - Map.of(), - Map.of() - ).withDiscoveredPackages(resourceLoaders); + moduleName, + Optional.ofNullable(version), + mods, + Optional.ofNullable(mainClass), + Optional.empty(), + dependencies, + Set.of(), + Map.of(), + Map.of()).withDiscoveredPackages(resourceLoaders); } interface XMLCloser extends AutoCloseable { @@ -590,6 +586,7 @@ public static ModuleDescriptor fromXml(Reader r) throws IOException { } } } + public static ModuleDescriptor fromXml(BufferedReader br) throws IOException { XMLInputFactory xmlInputFactory = XMLInputFactory.newDefaultFactory(); try { @@ -645,7 +642,8 @@ private static Map> parseManifestAdd(String value) { } private static IllegalArgumentException invalidChar(final String str, final int cp, final int idx) { - return new IllegalArgumentException("Invalid character '%s' at index %d of \"%s\"".formatted(Character.toString(cp), Integer.valueOf(idx), str)); + return new IllegalArgumentException( + "Invalid character '%s' at index %d of \"%s\"".formatted(Character.toString(cp), Integer.valueOf(idx), str)); } private static String dotName(TextIter iter) { @@ -655,7 +653,7 @@ private static String dotName(TextIter iter) { iter.next(); // consume while (iter.hasNext()) { cp = iter.peekNext(); - if (! Character.isJavaIdentifierPart(cp)) { + if (!Character.isJavaIdentifierPart(cp)) { // done return iter.substring(start); } @@ -677,7 +675,7 @@ private static ModuleDescriptor parseModuleElement(final XMLStreamReader xml) th Map packages = Map.of(); // attributes int cnt = xml.getAttributeCount(); - for (int i = 0; i < cnt; i ++) { + for (int i = 0; i < cnt; i++) { final String attrVal = xml.getAttributeValue(i); switch (xml.getAttributeLocalName(i)) { case "name" -> name = attrVal; @@ -723,16 +721,15 @@ private static ModuleDescriptor parseModuleElement(final XMLStreamReader xml) th } case XMLStreamConstants.END_ELEMENT -> { return new ModuleDescriptor( - name, - version, - mods, - mainClass, - Optional.empty(), - dependencies, - uses, - provides, - packages - ); + name, + version, + mods, + mainClass, + Optional.empty(), + dependencies, + uses, + provides, + packages); } } } @@ -759,10 +756,11 @@ private static List parseDependenciesElement(final XMLStreamReader x private static Dependency parseDependencyElement(final XMLStreamReader xml) throws XMLStreamException { String name = null; - Modifiers modifiers = Dependency.Modifier.set(Dependency.Modifier.SERVICES, Dependency.Modifier.LINKED, Dependency.Modifier.READ); + Modifiers modifiers = Dependency.Modifier.set(Dependency.Modifier.SERVICES, + Dependency.Modifier.LINKED, Dependency.Modifier.READ); Map packageAccesses = Map.of(); int cnt = xml.getAttributeCount(); - for (int i = 0; i < cnt; i ++) { + for (int i = 0; i < cnt; i++) { switch (xml.getAttributeLocalName(i)) { case "name" -> name = xml.getAttributeValue(i); case "transitive" -> { @@ -776,17 +774,17 @@ private static Dependency parseDependencyElement(final XMLStreamReader xml) thro } } case "linked" -> { - if (! Boolean.parseBoolean(xml.getAttributeValue(i))) { + if (!Boolean.parseBoolean(xml.getAttributeValue(i))) { modifiers = modifiers.without(Dependency.Modifier.LINKED); } } case "read" -> { - if (! Boolean.parseBoolean(xml.getAttributeValue(i))) { + if (!Boolean.parseBoolean(xml.getAttributeValue(i))) { modifiers = modifiers.without(Dependency.Modifier.READ); } } case "services" -> { - if (! Boolean.parseBoolean(xml.getAttributeValue(i))) { + if (!Boolean.parseBoolean(xml.getAttributeValue(i))) { modifiers = modifiers.without(Dependency.Modifier.SERVICES); } } @@ -823,10 +821,11 @@ private static Dependency parseDependencyElement(final XMLStreamReader xml) thro } } - private static void parseAccessElement(final XMLStreamReader xml, final Map packageAccesses, PackageAccess access) throws XMLStreamException { + private static void parseAccessElement(final XMLStreamReader xml, final Map packageAccesses, + PackageAccess access) throws XMLStreamException { String name = null; int cnt = xml.getAttributeCount(); - for (int i = 0; i < cnt; i ++) { + for (int i = 0; i < cnt; i++) { switch (xml.getAttributeLocalName(i)) { case "name" -> name = xml.getAttributeValue(i); default -> throw unknownAttribute(xml, i); @@ -865,10 +864,11 @@ private static Map parsePackagesElement(final XMLStreamRead } } - private static void parsePrivatePackageElement(final XMLStreamReader xml, final Map packages) throws XMLStreamException { + private static void parsePrivatePackageElement(final XMLStreamReader xml, final Map packages) + throws XMLStreamException { String pkg = null; int cnt = xml.getAttributeCount(); - for (int i = 0; i < cnt; i ++) { + for (int i = 0; i < cnt; i++) { final String attrVal = xml.getAttributeValue(i); switch (xml.getAttributeLocalName(i)) { case "package" -> pkg = attrVal; @@ -920,10 +920,11 @@ private static void parsePrivatePackageElement(final XMLStreamReader xml, final } } - private static void parseExportPackageElement(final XMLStreamReader xml, final Map packages) throws XMLStreamException { + private static void parseExportPackageElement(final XMLStreamReader xml, final Map packages) + throws XMLStreamException { String pkg = null; int cnt = xml.getAttributeCount(); - for (int i = 0; i < cnt; i ++) { + for (int i = 0; i < cnt; i++) { final String attrVal = xml.getAttributeValue(i); switch (xml.getAttributeLocalName(i)) { case "package" -> pkg = attrVal; @@ -964,10 +965,11 @@ private static void parseExportPackageElement(final XMLStreamReader xml, final M } } - private static void parseOpenPackageElement(final XMLStreamReader xml, final Map packages) throws XMLStreamException { + private static void parseOpenPackageElement(final XMLStreamReader xml, final Map packages) + throws XMLStreamException { String pkg = null; int cnt = xml.getAttributeCount(); - for (int i = 0; i < cnt; i ++) { + for (int i = 0; i < cnt; i++) { final String attrVal = xml.getAttributeValue(i); switch (xml.getAttributeLocalName(i)) { case "package" -> pkg = attrVal; @@ -986,7 +988,7 @@ private static void parseOpenPackageElement(final XMLStreamReader xml, final Map private static String parsePackageToElement(final XMLStreamReader xml) throws XMLStreamException { String mod = null; int cnt = xml.getAttributeCount(); - for (int i = 0; i < cnt; i ++) { + for (int i = 0; i < cnt; i++) { final String attrVal = xml.getAttributeValue(i); switch (xml.getAttributeLocalName(i)) { case "module" -> mod = attrVal; @@ -1023,7 +1025,7 @@ private static Set parseUsesElement(final XMLStreamReader xml) throws XM private static String parseUseElement(final XMLStreamReader xml) throws XMLStreamException { String name = null; int cnt = xml.getAttributeCount(); - for (int i = 0; i < cnt; i ++) { + for (int i = 0; i < cnt; i++) { final String attrVal = xml.getAttributeValue(i); switch (xml.getAttributeLocalName(i)) { case "name" -> name = attrVal; @@ -1057,11 +1059,12 @@ private static Map> parseProvidesElement(final XMLStreamRea } } - private static void parseProvideElement(final XMLStreamReader xml, final Map> provides) throws XMLStreamException { + private static void parseProvideElement(final XMLStreamReader xml, final Map> provides) + throws XMLStreamException { String name = null; List impls = new ArrayList<>(); int cnt = xml.getAttributeCount(); - for (int i = 0; i < cnt; i ++) { + for (int i = 0; i < cnt; i++) { final String attrVal = xml.getAttributeValue(i); switch (xml.getAttributeLocalName(i)) { case "name" -> name = attrVal; @@ -1091,7 +1094,7 @@ private static void parseProvideElement(final XMLStreamReader xml, final Map name = attrVal; @@ -1110,7 +1113,7 @@ private static String parseWithElement(final XMLStreamReader xml) throws XMLStre private static String parseMainClassElement(final XMLStreamReader xml) throws XMLStreamException { String name = null; int cnt = xml.getAttributeCount(); - for (int i = 0; i < cnt; i ++) { + for (int i = 0; i < cnt; i++) { final String attrVal = xml.getAttributeValue(i); switch (xml.getAttributeLocalName(i)) { case "name" -> name = attrVal; @@ -1140,7 +1143,7 @@ private static Modifiers toModifiers(final Set } private static void checkNamespace(final XMLStreamReader xml) throws XMLStreamException { - if (! "urn:jboss:module:3.0".equals(xml.getNamespaceURI())) { + if (!"urn:jboss:module:3.0".equals(xml.getNamespaceURI())) { throw unknownElement(xml); } } @@ -1162,7 +1165,8 @@ private static XMLStreamException unknownAttribute(final XMLStreamReader xml, fi } private static XMLStreamException unknownAttributeValue(final XMLStreamReader xml, final int idx) { - return new XMLStreamException("Unknown attribute value \"" + xml.getAttributeValue(idx) + "\" for attribute \"" + xml.getAttributeName(idx) + "\"", xml.getLocation()); + return new XMLStreamException("Unknown attribute value \"" + xml.getAttributeValue(idx) + "\" for attribute \"" + + xml.getAttributeName(idx) + "\"", xml.getLocation()); } private static IllegalArgumentException noModuleAttribute() { diff --git a/src/main/java/io/github/dmlloyd/modules/desc/PackageAccess.java b/src/main/java/io/smallrye/modules/desc/PackageAccess.java similarity index 94% rename from src/main/java/io/github/dmlloyd/modules/desc/PackageAccess.java rename to src/main/java/io/smallrye/modules/desc/PackageAccess.java index 34f4c11..ca98c58 100644 --- a/src/main/java/io/github/dmlloyd/modules/desc/PackageAccess.java +++ b/src/main/java/io/smallrye/modules/desc/PackageAccess.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules.desc; +package io.smallrye.modules.desc; import java.util.List; diff --git a/src/main/java/io/github/dmlloyd/modules/desc/PackageInfo.java b/src/main/java/io/smallrye/modules/desc/PackageInfo.java similarity index 75% rename from src/main/java/io/github/dmlloyd/modules/desc/PackageInfo.java rename to src/main/java/io/smallrye/modules/desc/PackageInfo.java index 126821d..33cdf61 100644 --- a/src/main/java/io/github/dmlloyd/modules/desc/PackageInfo.java +++ b/src/main/java/io/smallrye/modules/desc/PackageInfo.java @@ -1,9 +1,9 @@ -package io.github.dmlloyd.modules.desc; +package io.smallrye.modules.desc; import java.util.Set; -import io.github.dmlloyd.modules.impl.Util; import io.smallrye.common.constraint.Assert; +import io.smallrye.modules.impl.Util; /** * Information about a package in the module. @@ -11,21 +11,23 @@ * the package described by this information. * * @param packageAccess the outbound access level of the package (must not be {@code null}) - * @param exportTargets specific export targets in addition to those implied by {@link #packageAccess()} or {@link #openTargets()} (must not be {@code null}) + * @param exportTargets specific export targets in addition to those implied by {@link #packageAccess()} or + * {@link #openTargets()} (must not be {@code null}) * @param openTargets specific open targets in addition to those implied by {@link #packageAccess()} (must not be {@code null}) */ public record PackageInfo( - PackageAccess packageAccess, - Set exportTargets, - Set openTargets -) { + PackageAccess packageAccess, + Set exportTargets, + Set openTargets) { /** * Default record constructor (but use {@link #of} instead, whenever possible). * * @param packageAccess the outbound access level of the package (must not be {@code null}) - * @param exportTargets specific export targets in addition to those implied by {@link #packageAccess()} or {@link #openTargets()} (must not be {@code null}) - * @param openTargets specific open targets in addition to those implied by {@link #packageAccess()} (must not be {@code null}) + * @param exportTargets specific export targets in addition to those implied by {@link #packageAccess()} or + * {@link #openTargets()} (must not be {@code null}) + * @param openTargets specific open targets in addition to those implied by {@link #packageAccess()} (must not be + * {@code null}) */ public PackageInfo { Assert.checkNotNullParam("packageAccess", packageAccess); @@ -62,10 +64,9 @@ public static PackageInfo of(PackageAccess packageAccess, Set exportTarg public PackageInfo mergedWith(PackageInfo other) { return of( - PackageAccess.max(packageAccess(), other.packageAccess()), - Util.merge(exportTargets(), other.exportTargets()), - Util.merge(openTargets(), other.openTargets()) - ); + PackageAccess.max(packageAccess(), other.packageAccess()), + Util.merge(exportTargets(), other.exportTargets()), + Util.merge(openTargets(), other.openTargets())); } public static PackageInfo merge(PackageInfo a, PackageInfo b) { @@ -74,17 +75,15 @@ public static PackageInfo merge(PackageInfo a, PackageInfo b) { public PackageInfo withAccessAtLeast(PackageAccess newAccess) { return of( - PackageAccess.max(packageAccess(), newAccess), - exportTargets, - openTargets - ); + PackageAccess.max(packageAccess(), newAccess), + exportTargets, + openTargets); } public PackageInfo withExportTargets(final Set exportTargets) { return of( - packageAccess(), - Util.merge(exportTargets(), exportTargets), - openTargets() - ); + packageAccess(), + Util.merge(exportTargets(), exportTargets), + openTargets()); } } diff --git a/src/main/java/io/github/dmlloyd/modules/impl/Access.java b/src/main/java/io/smallrye/modules/impl/Access.java similarity index 80% rename from src/main/java/io/github/dmlloyd/modules/impl/Access.java rename to src/main/java/io/smallrye/modules/impl/Access.java index 26212de..c37bb26 100644 --- a/src/main/java/io/github/dmlloyd/modules/impl/Access.java +++ b/src/main/java/io/smallrye/modules/impl/Access.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules.impl; +package io.smallrye.modules.impl; import static java.lang.invoke.MethodHandles.*; @@ -6,13 +6,14 @@ import java.lang.invoke.MethodType; import java.lang.reflect.Constructor; -import io.github.dmlloyd.modules.ModuleClassLoader; +import io.smallrye.modules.ModuleClassLoader; /** * Access utilities for the runtime. */ public final class Access { - private Access() {} + private Access() { + } // ↓↓↓↓↓↓↓ private ↓↓↓↓↓↓↓ @@ -29,13 +30,18 @@ private Access() {} // initialize method handles try { Class modules = Class.forName("jdk.internal.module.Modules", true, null); - addOpens = lookup.findStatic(modules, "addOpens", MethodType.methodType(void.class, Module.class, String.class, Module.class)); - addExports = lookup.findStatic(modules, "addExports", MethodType.methodType(void.class, Module.class, String.class, Module.class)); + addOpens = lookup.findStatic(modules, "addOpens", + MethodType.methodType(void.class, Module.class, String.class, Module.class)); + addExports = lookup.findStatic(modules, "addExports", + MethodType.methodType(void.class, Module.class, String.class, Module.class)); addUses = lookup.findStatic(modules, "addUses", MethodType.methodType(void.class, Module.class, Class.class)); - addProvides = lookup.findStatic(modules, "addProvides", MethodType.methodType(void.class, Module.class, Class.class, Class.class)); + addProvides = lookup.findStatic(modules, "addProvides", + MethodType.methodType(void.class, Module.class, Class.class, Class.class)); addOpens(Object.class.getModule(), "java.lang", Util.myModule); Lookup lookup = privateLookupIn(Module.class, Access.lookup); - moduleLayerBindToLoader = lookup.findVirtual(ModuleLayer.class, "bindToLoader", MethodType.methodType(void.class, ClassLoader.class)).asType(MethodType.methodType(void.class, ModuleLayer.class, ModuleClassLoader.class)); + moduleLayerBindToLoader = lookup + .findVirtual(ModuleLayer.class, "bindToLoader", MethodType.methodType(void.class, ClassLoader.class)) + .asType(MethodType.methodType(void.class, ModuleLayer.class, ModuleClassLoader.class)); addOpens(Object.class.getModule(), "java.lang.invoke", Util.myModule); Constructor dc = Lookup.class.getDeclaredConstructor(Class.class, Class.class, int.class); dc.setAccessible(true); @@ -45,23 +51,23 @@ private Access() {} } catch (ClassNotFoundException e) { throw toError(e); } catch (IllegalAccessException | IllegalAccessError e) { - IllegalAccessError error = new IllegalAccessError(e.getMessage() + " -- use: --add-exports java.base/jdk.internal.module=" + Util.myModule.getName()); + IllegalAccessError error = new IllegalAccessError( + e.getMessage() + " -- use: --add-exports java.base/jdk.internal.module=" + Util.myModule.getName()); error.setStackTrace(e.getStackTrace()); throw error; } MethodType methodType = MethodType.methodType( - Module.class - ); + Module.class); MethodType toMethodType = MethodType.methodType( - void.class, - Module.class - ); + void.class, + Module.class); // this one is flexible: it's only since Java 22 (otherwise, ignore) MethodHandle h = empty(toMethodType); try { if (Runtime.version().feature() >= 22) { //java.lang.Module.implAddEnableNativeAccess - h = privateLookupIn(Module.class, lookup).findVirtual(Module.class, "implAddEnableNativeAccess", methodType).asType(toMethodType); + h = privateLookupIn(Module.class, lookup).findVirtual(Module.class, "implAddEnableNativeAccess", methodType) + .asType(toMethodType); } } catch (NoSuchMethodException | IllegalAccessException ignored) { } diff --git a/src/main/java/io/github/dmlloyd/modules/impl/TextIter.java b/src/main/java/io/smallrye/modules/impl/TextIter.java similarity index 93% rename from src/main/java/io/github/dmlloyd/modules/impl/TextIter.java rename to src/main/java/io/smallrye/modules/impl/TextIter.java index ac60d88..74e92ed 100644 --- a/src/main/java/io/github/dmlloyd/modules/impl/TextIter.java +++ b/src/main/java/io/smallrye/modules/impl/TextIter.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules.impl; +package io.smallrye.modules.impl; import java.util.function.IntPredicate; @@ -29,16 +29,16 @@ public int skipWhiteSpace() { int cnt = 0; while (hasNext() && Character.isWhitespace(peekNext())) { next(); - cnt ++; + cnt++; } return cnt; } public int skipUntil(IntPredicate predicate) { int cnt = 0; - while (hasNext() && ! predicate.test(peekNext())) { + while (hasNext() && !predicate.test(peekNext())) { next(); - cnt ++; + cnt++; } return cnt; } diff --git a/src/main/java/io/github/dmlloyd/modules/impl/Util.java b/src/main/java/io/smallrye/modules/impl/Util.java similarity index 91% rename from src/main/java/io/github/dmlloyd/modules/impl/Util.java rename to src/main/java/io/smallrye/modules/impl/Util.java index 66cd971..8d5b19f 100644 --- a/src/main/java/io/github/dmlloyd/modules/impl/Util.java +++ b/src/main/java/io/smallrye/modules/impl/Util.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules.impl; +package io.smallrye.modules.impl; import java.lang.module.ModuleFinder; import java.lang.module.ModuleReference; @@ -29,10 +29,9 @@ public final class Util { public static final Module myModule = Access.class.getModule(); public static final ModuleLayer myLayer = Objects.requireNonNullElse(myModule.getLayer(), ModuleLayer.boot()); public static final Map myLayerModules = myLayer.modules().stream() - .collect(Collectors.toUnmodifiableMap( - Module::getName, - Function.identity() - )); + .collect(Collectors.toUnmodifiableMap( + Module::getName, + Function.identity())); public static final ModuleFinder EMPTY_MF = new ModuleFinder() { public Optional find(final String name) { return Optional.empty(); @@ -57,12 +56,12 @@ public Set findAll() { public static String packageName(String binaryName) { int idx = binaryName.lastIndexOf('.'); - return idx == - 1 ? "" : binaryName.substring(0, idx); + return idx == -1 ? "" : binaryName.substring(0, idx); } public static String resourcePackageName(String resourcePath) { int idx = resourcePath.lastIndexOf('/'); - return idx == - 1 ? "" : resourcePath.substring(0, idx).replace('/', '.'); + return idx == -1 ? "" : resourcePath.substring(0, idx).replace('/', '.'); } public static String autoModuleName(TextIter iter) { @@ -82,7 +81,7 @@ public static String autoModuleName(TextIter iter) { } // version starts here return sb.toString(); - } else if (! dot) { + } else if (!dot) { iter.next(); dot = true; sb.append('.'); @@ -146,12 +145,10 @@ public static Map merge(Map map1, Map map2, BinaryOpera return map1; } else { return Stream.concat(map1.entrySet().stream(), map2.entrySet().stream()) - .collect(Collectors.toUnmodifiableMap( - Map.Entry::getKey, - Map.Entry::getValue, - merge - ) - ); + .collect(Collectors.toUnmodifiableMap( + Map.Entry::getKey, + Map.Entry::getValue, + merge)); } } @@ -196,7 +193,7 @@ public static Iterator filtered(Iterator orig, Predicate test) { public boolean hasNext() { while (next == null) { - if (! orig.hasNext()) { + if (!orig.hasNext()) { return false; } E next = orig.next(); @@ -212,7 +209,8 @@ public boolean hasNext() { } public E next() { - if (! hasNext()) throw new NoSuchElementException(); + if (!hasNext()) + throw new NoSuchElementException(); try { return next; } finally { diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 443a5ac..1fd4ffb 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,5 +1,5 @@ -module io.github.dmlloyd.modules { +module io.smallrye.modules { requires transitive java.xml; requires java.logging; @@ -12,8 +12,8 @@ requires io.smallrye.common.os; requires transitive io.smallrye.common.resource; - exports io.github.dmlloyd.modules; - exports io.github.dmlloyd.modules.desc; + exports io.smallrye.modules; + exports io.smallrye.modules.desc; uses java.util.logging.LogManager; } diff --git a/src/test/java/io/github/dmlloyd/modules/test/BasicTests.java b/src/test/java/io/smallrye/modules/test/BasicTests.java similarity index 62% rename from src/test/java/io/github/dmlloyd/modules/test/BasicTests.java rename to src/test/java/io/smallrye/modules/test/BasicTests.java index ed60e07..38aeb81 100644 --- a/src/test/java/io/github/dmlloyd/modules/test/BasicTests.java +++ b/src/test/java/io/smallrye/modules/test/BasicTests.java @@ -1,4 +1,4 @@ -package io.github.dmlloyd.modules.test; +package io.smallrye.modules.test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -11,17 +11,18 @@ import java.util.Set; import java.util.random.RandomGenerator; -import io.github.dmlloyd.modules.DelegatingModuleLoader; -import io.github.dmlloyd.modules.FoundModule; -import io.github.dmlloyd.modules.LoadedModule; -import io.github.dmlloyd.modules.ModuleFinder; -import io.github.dmlloyd.modules.ModuleLoader; -import io.github.dmlloyd.modules.desc.Dependency; -import io.github.dmlloyd.modules.desc.ModuleDescriptor; -import io.github.dmlloyd.modules.desc.PackageInfo; -import io.smallrye.common.resource.MemoryResource; import org.junit.jupiter.api.Test; +import io.smallrye.common.resource.MemoryResource; +import io.smallrye.modules.DelegatingModuleLoader; +import io.smallrye.modules.FoundModule; +import io.smallrye.modules.LoadedModule; +import io.smallrye.modules.ModuleFinder; +import io.smallrye.modules.ModuleLoader; +import io.smallrye.modules.desc.Dependency; +import io.smallrye.modules.desc.ModuleDescriptor; +import io.smallrye.modules.desc.PackageInfo; + public final class BasicTests { @Test @@ -29,16 +30,15 @@ public void basics() throws ClassNotFoundException { ModuleLoader ml = new DelegatingModuleLoader("test", new ModuleFinder() { public FoundModule findModule(final String name) { return name.equals("hello") ? new FoundModule(List.of(), (moduleName, loaders) -> new ModuleDescriptor( - "hello", - Optional.of("1.2.3"), - ModuleDescriptor.Modifier.set(), - Optional.of("test.foobar.Main"), - Optional.empty(), - List.of(Dependency.JAVA_BASE), - Set.of(RandomGenerator.class.getName(), "java.lang.Unknown"), - Map.of("java.lang.Nothing", List.of("test.foobar.NonExistent")), - Map.of("test.foobar", PackageInfo.EXPORTED, "test.foobar.impl", PackageInfo.PRIVATE) - )) : null; + "hello", + Optional.of("1.2.3"), + ModuleDescriptor.Modifier.set(), + Optional.of("test.foobar.Main"), + Optional.empty(), + List.of(Dependency.JAVA_BASE), + Set.of(RandomGenerator.class.getName(), "java.lang.Unknown"), + Map.of("java.lang.Nothing", List.of("test.foobar.NonExistent")), + Map.of("test.foobar", PackageInfo.EXPORTED, "test.foobar.impl", PackageInfo.PRIVATE))) : null; } }, ModuleLoader.BOOT); LoadedModule resolved = ml.loadModule("hello"); diff --git a/src/test/java/module-info.java b/src/test/java/module-info.java index 2f5e5bc..1da4499 100644 --- a/src/test/java/module-info.java +++ b/src/test/java/module-info.java @@ -1,7 +1,7 @@ -open module io.github.dmlloyd.modules.test { - requires io.github.dmlloyd.modules; +open module io.smallrye.modules.test { + requires io.smallrye.modules; requires io.smallrye.common.resource; requires org.junit.jupiter.api; - exports io.github.dmlloyd.modules.test; + exports io.smallrye.modules.test; } From 97371c7e243f21e21c6e4e16b976f86e12f03f35 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 17 Mar 2026 17:43:16 +0000 Subject: [PATCH 2/2] Bump io.smallrye.common:smallrye-common-bom from 2.15.0 to 2.17.0 Bumps [io.smallrye.common:smallrye-common-bom](https://github.com/smallrye/smallrye-common) from 2.15.0 to 2.17.0. - [Release notes](https://github.com/smallrye/smallrye-common/releases) - [Commits](https://github.com/smallrye/smallrye-common/compare/2.15.0...2.17.0) --- updated-dependencies: - dependency-name: io.smallrye.common:smallrye-common-bom dependency-version: 2.17.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5c0cee6..4de8b03 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ io.smallrye.common smallrye-common-bom - 2.15.0 + 2.17.0 import pom