diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6857639..181ad71 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,8 +41,7 @@ jobs: uses: mikepenz/gradle-dependency-submission@v0.9.0 with: gradle-build-module: |- - :opensesame-annotations - :opensesame-runtime + :opensesame-core :opensesame-compile :opensesame-groovy :opensesame-javac diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index f5978fa..3432b45 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -53,8 +53,7 @@ jobs: uses: mikepenz/gradle-dependency-submission@v0.9.0 with: gradle-build-module: |- - :opensesame-annotations - :opensesame-runtime + :opensesame-core :opensesame-compile :opensesame-groovy :opensesame-javac diff --git a/README.md b/README.md index ca1c07b..0124231 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # OpenSesame - [![javadoc](https://img.shields.io/maven-central/v/dev.lukebemish.opensesame/opensesame-annotations?style=for-the-badge&label=javadoc%20(annotations)&color=green)](https://javadoc.io/doc/dev.lukebemish.opensesame/opensesame-annotations) + [![javadoc](https://img.shields.io/maven-central/v/dev.lukebemish.opensesame/opensesame-core?style=for-the-badge&label=javadoc&color=green)](https://javadoc.io/doc/dev.lukebemish.opensesame/opensesame-core) OpenSesame provides a tool to break through basically any form of encapsulation in the JVM, in a way that allows you to work with simple accessor method in your code, instead of worrying about `MethodHandle`s or reflection. These accessors are turned into `INVOKEDYNAMIC` instructions at compile time which call a lightweight runtime component; the use of `INVOKEDYNAMIC` allows the runtime dependency to be extremely lightweight, and for the JVM to inline calls to members you are accessing when the call site is first evaluated, assuring that your code runs as fast as code accessing your target without breaking encapsulation. Normally, OpenSesame simply breaks though access control, but it can be told to break through module boundaries as well. +OpenSesame requires Java 17 or higher. ## Setup @@ -26,12 +27,12 @@ dependencies { } ``` -If you do not need the ASTT present at runtime, you may split the dependency and at runtime depend only on `opensesame-runtime`: +If you do not need the ASTT present at runtime, you may split the dependency and at runtime depend only on `opensesame-core`: ```gradle dependencies { compileOnly 'dev.lukebemish.opensesame:opensesame-groovy:' - runtimeOnly 'dev.lukebemish.opensesame:opensesame-runtime:' + runtimeOnly 'dev.lukebemish.opensesame:opensesame-core:' } ``` @@ -43,7 +44,7 @@ plugin present at runtime, you will likely want to split it into its runtime and ```gradle dependencies { compileOnly 'dev.lukebemish.opensesame:opensesame-javac:' - runtimeOnly 'dev.lukebemish.opensesame:opensesame-runtime:' + runtimeOnly 'dev.lukebemish.opensesame:opensesame-core:' } tasks.named('compileJava', JavaCompile).configure { @@ -87,7 +88,7 @@ can use `@Coerce` annotation to specify the real type of an argument or return t If you are using Groovy, OpenSesame has several useful additional features. The first is `@OpenClass`, which gets rid of the need for accessor methods when accessing public classes: -```java +```groovy class Target { private static void someMethod() { ... diff --git a/annotations/build.gradle b/annotations/build.gradle deleted file mode 100644 index 40dd9f0..0000000 --- a/annotations/build.gradle +++ /dev/null @@ -1,44 +0,0 @@ -plugins { - id 'opensesame.conventions' -} - -java.withSourcesJar() -java.withJavadocJar() - -dependencies { - api project(':opensesame-runtime') -} - -publishing { - publications { - mavenJava(MavenPublication) { - pom { - name = "OpenSesame - Annotations" - packaging = 'jar' - description = 'Annotations for OpenSesame, a tool for typesafe access normally inacessible members' - url = 'https://github.com/lukebemish/OpenSesame' - inceptionYear = '2023' - - licenses { - license { - name = '3-Clause BSD License' - url = 'https://opensource.org/license/bsd-3-clause/' - } - } - developers { - developer { - id = 'lukebemish' - name = 'Luke Bemish' - email = 'lukebemish@lukebemish.dev' - url = 'https://github.com/lukebemish/' - } - } - scm { - connection='scm:git:git://github.com/lukebemish/OpenSesame.git' - developerConnection='scm:git:ssh://github.com/lukebemish/OpenSesame.git' - url='https://github.com/lukebemish/OpenSesame' - } - } - } - } -} diff --git a/buildSrc/src/main/groovy/opensesame.conventions.gradle b/buildSrc/src/main/groovy/opensesame.conventions.gradle index 93388ed..9a43f9f 100644 --- a/buildSrc/src/main/groovy/opensesame.conventions.gradle +++ b/buildSrc/src/main/groovy/opensesame.conventions.gradle @@ -110,7 +110,8 @@ jar { 'Specification-Version' : rootProject.version, 'Implementation-Commit-Time': managedVersioning.timestamp.get(), 'Implementation-Commit': managedVersioning.hash.get(), - 'Automatic-Module-Name' : "dev.lukebemish.opensesame.${project.name.replace("opensesame-", "")}".toString() + 'Automatic-Module-Name' : "dev.lukebemish.opensesame.${project.name.replace("opensesame-", "")}".toString(), + 'FMLModType': 'LIBRARY' ]) } } diff --git a/compile/build.gradle b/compile/build.gradle index 3a75851..69367ea 100644 --- a/compile/build.gradle +++ b/compile/build.gradle @@ -6,7 +6,7 @@ java.withSourcesJar() java.withJavadocJar() dependencies { - implementation project(':opensesame-annotations') + implementation project(':opensesame-core') } tasks.named('compileJava', JavaCompile).configure { @@ -19,7 +19,7 @@ publishing { pom { name = "OpenSesame - Compile" packaging = 'jar' - description = 'Compile-time abstractions for OpenSesame, a tool for typesafe access normally inacessible members' + description = 'Compile-time abstractions for OpenSesame, a tool for typesafe access to normally inacessible members' url = 'https://github.com/lukebemish/OpenSesame' inceptionYear = '2023' diff --git a/runtime/build.gradle b/core/build.gradle similarity index 85% rename from runtime/build.gradle rename to core/build.gradle index 329226a..fd7aecc 100644 --- a/runtime/build.gradle +++ b/core/build.gradle @@ -9,9 +9,9 @@ publishing { publications { mavenJava(MavenPublication) { pom { - name = "OpenSesame - Runtime" + name = "OpenSesame - Core" packaging = 'jar' - description = 'Runtime metafactory used for OpenSesame, a tool for typesafe access normally inacessible members' + description = 'Core annotations and runtime metafactory used for OpenSesame, a tool for typesafe access to normally inacessible members' url = 'https://github.com/lukebemish/OpenSesame' inceptionYear = '2023' diff --git a/annotations/src/main/java/dev/lukebemish/opensesame/annotations/Coerce.java b/core/src/main/java/dev/lukebemish/opensesame/annotations/Coerce.java similarity index 72% rename from annotations/src/main/java/dev/lukebemish/opensesame/annotations/Coerce.java rename to core/src/main/java/dev/lukebemish/opensesame/annotations/Coerce.java index 434064f..b828126 100644 --- a/annotations/src/main/java/dev/lukebemish/opensesame/annotations/Coerce.java +++ b/core/src/main/java/dev/lukebemish/opensesame/annotations/Coerce.java @@ -16,19 +16,19 @@ @Target({ElementType.METHOD, ElementType.PARAMETER}) public @interface Coerce { /** - * @return the internal name or descriptor of the target class, or the name ot be passed to {@link #targetProvider()} + * {@return the internal name or descriptor of the target class, or the name ot be passed to {@link #targetProvider()}} */ String targetName() default ""; /** - * @return the target class + * {@return the target class} */ - Class targetClass() default Void.class; + Class targetClass() default void.class; /** - * @return a class implementing {@link dev.lukebemish.opensesame.runtime.ClassProvider} with a no-arg constructor + * {@return a class implementing {@link dev.lukebemish.opensesame.runtime.ClassProvider} with a no-arg constructor * that returns the target class. This function will be passed {@link #targetName()} if it is specified, or - * null otherwise. On groovy, may be a closure + * null otherwise. On groovy, may be a closure} */ Class targetProvider() default ErrorProvider.class; } diff --git a/annotations/src/main/java/dev/lukebemish/opensesame/annotations/Open.java b/core/src/main/java/dev/lukebemish/opensesame/annotations/Open.java similarity index 79% rename from annotations/src/main/java/dev/lukebemish/opensesame/annotations/Open.java rename to core/src/main/java/dev/lukebemish/opensesame/annotations/Open.java index add6075..db64f6f 100644 --- a/annotations/src/main/java/dev/lukebemish/opensesame/annotations/Open.java +++ b/core/src/main/java/dev/lukebemish/opensesame/annotations/Open.java @@ -19,34 +19,34 @@ @Target(ElementType.METHOD) public @interface Open { /** - * @return the name of the target method, constructor, or field operation + * {@return the name of the target method, constructor, or field operation} */ String name() default ""; /** - * @return the internal name or descriptor of the target class, or the name ot be passed to {@link #targetProvider()} + * {@return the internal name or descriptor of the target class, or the name ot be passed to {@link #targetProvider()}} */ String targetName() default ""; /** - * @return the target class + * {@return the target class} */ - Class targetClass() default Void.class; + Class targetClass() default void.class; /** - * @return a class implementing {@link dev.lukebemish.opensesame.runtime.ClassProvider} with a no-arg constructor + * {@return a class implementing {@link dev.lukebemish.opensesame.runtime.ClassProvider} with a no-arg constructor * that returns the target class. This function will be passed {@link #targetName()} if it is specified, or - * null otherwise. On groovy, may be a closure + * null otherwise. On groovy, may be a closure} */ Class targetProvider() default ErrorProvider.class; /** - * @return the type of member o the target class to invoke + * {@return the type of member o the target class to invoke} */ Type type(); /** - * @return whether this invocation should be done unsafely, breaking module boundaries + * {@return whether this invocation should be done unsafely, breaking module boundaries} */ boolean unsafe() default false; diff --git a/runtime/src/main/java/dev/lukebemish/opensesame/runtime/ClassProvider.java b/core/src/main/java/dev/lukebemish/opensesame/runtime/ClassProvider.java similarity index 100% rename from runtime/src/main/java/dev/lukebemish/opensesame/runtime/ClassProvider.java rename to core/src/main/java/dev/lukebemish/opensesame/runtime/ClassProvider.java diff --git a/runtime/src/main/java/dev/lukebemish/opensesame/runtime/ErrorProvider.java b/core/src/main/java/dev/lukebemish/opensesame/runtime/ErrorProvider.java similarity index 100% rename from runtime/src/main/java/dev/lukebemish/opensesame/runtime/ErrorProvider.java rename to core/src/main/java/dev/lukebemish/opensesame/runtime/ErrorProvider.java diff --git a/runtime/src/main/java/dev/lukebemish/opensesame/runtime/LookupProvider.java b/core/src/main/java/dev/lukebemish/opensesame/runtime/LookupProvider.java similarity index 100% rename from runtime/src/main/java/dev/lukebemish/opensesame/runtime/LookupProvider.java rename to core/src/main/java/dev/lukebemish/opensesame/runtime/LookupProvider.java diff --git a/runtime/src/main/java/dev/lukebemish/opensesame/runtime/LookupProviderFallback.java b/core/src/main/java/dev/lukebemish/opensesame/runtime/LookupProviderFallback.java similarity index 100% rename from runtime/src/main/java/dev/lukebemish/opensesame/runtime/LookupProviderFallback.java rename to core/src/main/java/dev/lukebemish/opensesame/runtime/LookupProviderFallback.java diff --git a/runtime/src/main/java/dev/lukebemish/opensesame/runtime/LookupProviderUnsafe.java b/core/src/main/java/dev/lukebemish/opensesame/runtime/LookupProviderUnsafe.java similarity index 91% rename from runtime/src/main/java/dev/lukebemish/opensesame/runtime/LookupProviderUnsafe.java rename to core/src/main/java/dev/lukebemish/opensesame/runtime/LookupProviderUnsafe.java index 63f044c..5ccf8d6 100644 --- a/runtime/src/main/java/dev/lukebemish/opensesame/runtime/LookupProviderUnsafe.java +++ b/core/src/main/java/dev/lukebemish/opensesame/runtime/LookupProviderUnsafe.java @@ -48,9 +48,11 @@ private MethodHandles.Lookup getImplLookup() throws Exception { var implLookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP"); Method staticFieldBase = unsafe.getDeclaredMethod("staticFieldBase", Field.class); Method staticFieldOffset = unsafe.getDeclaredMethod("staticFieldOffset", Field.class); + Object base = staticFieldBase.invoke(theUnsafe, implLookupField); + long offset = (long) staticFieldOffset.invoke(theUnsafe, implLookupField); Method getObject = unsafe.getDeclaredMethod("getObject", Object.class, long.class); return (MethodHandles.Lookup) - getObject.invoke(theUnsafe, staticFieldBase.invoke(theUnsafe, implLookupField), staticFieldOffset.invoke(theUnsafe, implLookupField)); + getObject.invoke(theUnsafe, base, offset); } @Override diff --git a/runtime/src/main/java/dev/lukebemish/opensesame/runtime/OpeningException.java b/core/src/main/java/dev/lukebemish/opensesame/runtime/OpeningException.java similarity index 100% rename from runtime/src/main/java/dev/lukebemish/opensesame/runtime/OpeningException.java rename to core/src/main/java/dev/lukebemish/opensesame/runtime/OpeningException.java diff --git a/runtime/src/main/java/dev/lukebemish/opensesame/runtime/OpeningMetafactory.java b/core/src/main/java/dev/lukebemish/opensesame/runtime/OpeningMetafactory.java similarity index 100% rename from runtime/src/main/java/dev/lukebemish/opensesame/runtime/OpeningMetafactory.java rename to core/src/main/java/dev/lukebemish/opensesame/runtime/OpeningMetafactory.java diff --git a/runtime/src/main/java/dev/lukebemish/opensesame/runtime/RuntimeRemapper.java b/core/src/main/java/dev/lukebemish/opensesame/runtime/RuntimeRemapper.java similarity index 100% rename from runtime/src/main/java/dev/lukebemish/opensesame/runtime/RuntimeRemapper.java rename to core/src/main/java/dev/lukebemish/opensesame/runtime/RuntimeRemapper.java diff --git a/runtime/src/main/java/module-info.java b/core/src/main/java/module-info.java similarity index 81% rename from runtime/src/main/java/module-info.java rename to core/src/main/java/module-info.java index 0ff963d..cb88c90 100644 --- a/runtime/src/main/java/module-info.java +++ b/core/src/main/java/module-info.java @@ -3,6 +3,7 @@ requires static org.jetbrains.annotations; exports dev.lukebemish.opensesame.runtime; + exports dev.lukebemish.opensesame.annotations; uses dev.lukebemish.opensesame.runtime.RuntimeRemapper; } \ No newline at end of file diff --git a/groovy/build.gradle b/groovy/build.gradle index 4c7d0a7..0e740bc 100644 --- a/groovy/build.gradle +++ b/groovy/build.gradle @@ -15,7 +15,7 @@ tasks.register('groovydocJar', Jar) { dependencies { implementation libs.groovy.core implementation project(':opensesame-compile') - api project(':opensesame-annotations') + api project(':opensesame-core') } tasks.named('compileGroovy', GroovyCompile).configure { @@ -89,7 +89,7 @@ publishing { pom { name = "OpenSesame - Groovy Transform" packaging = 'jar' - description = 'Compile-time groovy ASTT used for OpenSesame, a tool for typesafe access normally inacessible members' + description = 'Compile-time groovy ASTT used for OpenSesame, a tool for typesafe access to normally inacessible members' url = 'https://github.com/lukebemish/OpenSesame' inceptionYear = '2023' diff --git a/groovy/src/main/groovy/dev/lukebemish/opensesame/annotations/groovy/OpenClass.java b/groovy/src/main/groovy/dev/lukebemish/opensesame/annotations/groovy/OpenClass.java index 8130134..8f28f52 100644 --- a/groovy/src/main/groovy/dev/lukebemish/opensesame/annotations/groovy/OpenClass.java +++ b/groovy/src/main/groovy/dev/lukebemish/opensesame/annotations/groovy/OpenClass.java @@ -21,7 +21,7 @@ }) public @interface OpenClass { /** - * The classes to open. + * {@return The classes to open.} */ Class[] value(); } diff --git a/javac/build.gradle b/javac/build.gradle index 04728ca..f146120 100644 --- a/javac/build.gradle +++ b/javac/build.gradle @@ -7,7 +7,7 @@ java.withJavadocJar() dependencies { implementation project(':opensesame-compile') - api project(':opensesame-annotations') + api project(':opensesame-core') implementation libs.asm } @@ -81,7 +81,7 @@ publishing { pom { name = "OpenSesame - Javac Compiler Plugin" packaging = 'jar' - description = 'javac compiler plugin for OpenSesame, a tool for typesafe access normally inacessible members' + description = 'javac compiler plugin for OpenSesame, a tool for typesafe access to normally inacessible members' url = 'https://github.com/lukebemish/OpenSesame' inceptionYear = '2023' diff --git a/settings.gradle b/settings.gradle index 1c0195f..cdb9bf9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -25,8 +25,7 @@ gradleEnterprise { rootProject.name = 'opensesame' def subprojects = [ - 'annotations', - 'runtime', + 'core', 'compile', 'groovy', 'javac'