Skip to content

Commit

Permalink
feat: swap event generation to source-based generation
Browse files Browse the repository at this point in the history
Still being validated, we have event generation that can run as an
Annotation Processor, which has the benefits of producing closer to usage
events with generics that survive their usages. This enables
CompositeEvent to be near-fully implemented.
  • Loading branch information
gabizou committed Oct 1, 2024
1 parent 2680f76 commit 917991a
Show file tree
Hide file tree
Showing 69 changed files with 165 additions and 95 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ MANIFEST.MF
dependency-reduced-pom.xml
.checkstyle
!.checkstyle/
# We exclude the generated events from git to avoid
# temptation to edit said generated files.
src/main/generated/

# Compiled #
############
Expand Down
35 changes: 7 additions & 28 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import org.jetbrains.gradle.ext.delegateActions
import org.jetbrains.gradle.ext.settings
import org.jetbrains.gradle.ext.taskTriggers

buildscript {
dependencies {
classpath(libs.spoon) // bump for EIG
}
}

plugins {
eclipse
Expand All @@ -21,6 +16,9 @@ plugins {
alias(libs.plugins.nexusPublish)
}

// Enable event generation to be considered part of
// the main source set
val generatedEventSourcesDir = project.file("src/main/generated")
val javaTarget: String by project
val ap by sourceSets.registering {
compileClasspath += sourceSets.main.get().compileClasspath + sourceSets.main.get().output
Expand All @@ -46,7 +44,7 @@ tasks {

sourceSets {
main {
java.srcDirs(layout.buildDirectory.dir("generated/sources/annotationProcessor/java/main"))
java.srcDirs(generatedEventSourcesDir)
}
}

Expand Down Expand Up @@ -150,33 +148,14 @@ dependencies {
tasks {

compileJava {
options.generatedSourceOutputDirectory = generatedEventSourcesDir
options.compilerArgs.addAll(listOf(
"-AeventGenInclusiveFolders=org/spongepowered/api/event",
"-AeventGenExclusiveFolders=org/spongepowered/api/event/cause,org/spongepowered/api/event/filter,org/spongepowered/api/event/impl,org/spongepowered/api/event/lifecycle",
"-AeventGenFactory=org.spongepowered.api.event.SpongeEventFactory",
"-AeventGenDebug=true",
))
}
// genEventImpl {
// sourceCompatibility = javaTarget
// destinationDirectory = project.layout.buildDirectory.dir("generated/event-factory")
//
// outputFactory = "org.spongepowered.api.event.SpongeEventFactory"
// include("org/spongepowered/api/event/*/**/*")
// include("org/spongepowered/api/event/CompositeEvent.java")
// exclude("org/spongepowered/api/event/action/InteractEvent.java")
// exclude("org/spongepowered/api/event/cause/")
// exclude("org/spongepowered/api/event/entity/AffectEntityEvent.java")
// exclude("org/spongepowered/api/event/filter/")
// exclude("org/spongepowered/api/event/impl/")
// exclude("org/spongepowered/api/event/lifecycle/ProvideServiceEvent.java")
// exclude("org/spongepowered/api/event/lifecycle/RegisterBuilderEvent.java")
// exclude("org/spongepowered/api/event/lifecycle/RegisterRegistryEvent.java")
// exclude("org/spongepowered/api/event/lifecycle/RegisterRegistryValueEvent.java")
// exclude("org/spongepowered/api/event/lifecycle/RegisterCommandEvent.java")
// exclude("org/spongepowered/api/event/lifecycle/RegisterFactoryEvent.java")
// exclude("org/spongepowered/api/event/lifecycle/RegisterWorldEvent.java")
// inclusiveAnnotations = setOf("org.spongepowered.api.util.annotation.eventgen.GenerateFactoryMethod")
// exclusiveAnnotations = setOf("org.spongepowered.api.util.annotation.eventgen.NoFactoryMethod")
// }

jar {
from(ap.get().output)
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ eventImplGen-annotations = { module = "org.spongepowered:event-impl-gen-annotati
checkerQual = { module = "org.checkerframework:checker-qual", version.ref = "checker" }
errorprone = { module = "com.google.errorprone:error_prone_core", version.ref = "errorprone" }
errorprone-annotations = { module = "com.google.errorprone:error_prone_annotations", version.ref = "errorprone" }
spoon = { module = "fr.inria.gforge.spoon:spoon-core", version = "10.4.2" } # bump for EIG

# testing

Expand Down
32 changes: 32 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@
<sha256 value="ca6529bd6d79090f0ab6f5da452eb4fbb29377b48e6a806e7612396dcb2998e0" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.dagger" name="dagger" version="2.52">
<artifact name="dagger-2.52.jar">
<sha256 value="dfb8e83020786daefbd64335ce0e0ebf01646a1b407fb77a27e052baf42df458" origin="Generated by Gradle"/>
</artifact>
<artifact name="dagger-2.52.pom">
<sha256 value="5cb60843f46bbccf97bd832d5490d26ab192af2e663fad7e5971969bf20fb94e" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.errorprone" name="error_prone_annotation" version="2.24.1">
<artifact name="error_prone_annotation-2.24.1.jar">
<sha256 value="dc202da451680aa8cdda7c68d959f27c112dca8f8fdeaf7c597de73cb2b1a0a6" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -748,6 +756,22 @@
<sha256 value="5a65e06a159d20d3b4800624a570c646dbee710b2b539b3449a268558c289e9c" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="io.soabase.java-composer" name="java-composer" version="1.0">
<artifact name="java-composer-1.0.jar">
<sha256 value="d914e52079c41509cde32d8fa03b5a865d8a227867ed6fd5d8121639518d28a1" origin="Generated by Gradle"/>
</artifact>
<artifact name="java-composer-1.0.pom">
<sha256 value="741a35966a3055c80c10631736c6cfec82d7b5e4212b3f72ded29f98935bbb5e" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="jakarta.inject" name="jakarta.inject-api" version="2.0.1">
<artifact name="jakarta.inject-api-2.0.1.jar">
<sha256 value="f7dc98062fccf14126abb751b64fab12c312566e8cbdc8483598bffcea93af7c" origin="Generated by Gradle"/>
</artifact>
<artifact name="jakarta.inject-api-2.0.1.pom">
<sha256 value="e7fd7232e96307a575b2494c9367d68cf43ec98244aace3ccc23e1773ffa6fda" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="jakarta.platform" name="jakarta.jakartaee-bom" version="9.1.0">
<artifact name="jakarta.jakartaee-bom-9.1.0.pom">
<sha256 value="df98e0266219fdbb82562826d79a3a20776a8ba02aa787f0f0765a538654c8a4" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -1512,6 +1536,9 @@
<artifact name="apiguardian-api-1.1.2.module">
<sha256 value="e08028131375b357d1d28734e9a4fb4216da84b240641cb3ef7e7c7d628223fc" origin="Generated by Gradle"/>
</artifact>
<artifact name="apiguardian-api-1.1.2.pom">
<sha256 value="32355081d109095c3d5d374d5a43b4f4c1b75d549e983ef50723e2772e5302a0" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.checkerframework" name="checker-qual" version="2.10.0">
<artifact name="checker-qual-2.10.0.jar">
Expand Down Expand Up @@ -1621,6 +1648,11 @@
<sha256 value="5e583878df905b5f33a230ef690a52b8f19dab9cc892bedee069f3d8af4e960a" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.eclipse.ee4j" name="project" version="1.0.6">
<artifact name="project-1.0.6.pom">
<sha256 value="4e7d8329d8da7dcf30779d824241be145f27108932f5a5a24eb907677bc8d72d" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.eclipse.ee4j" name="project" version="1.0.7">
<artifact name="project-1.0.7.pom">
<sha256 value="205c039a42cbae3556efbeb04a483eb3a3cf9550bd75bf84260dc8f28218f105" origin="Generated by Gradle"/>
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ plugins {
}

dependencyResolutionManagement {
repositories {
mavenLocal()
}
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
pluginManagement.repositories.forEach(repositories::add)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.data.value.ValueContainer;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.util.annotation.eventgen.TransformWith;
import org.spongepowered.eventgen.annotations.TransformWith;
import org.spongepowered.api.world.World;

import java.util.Arrays;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/spongepowered/api/event/Cancellable.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
package org.spongepowered.api.event;

import org.spongepowered.api.util.annotation.eventgen.PropertySettings;
import org.spongepowered.eventgen.annotations.PropertySettings;

/**
* Represents an event that can be cancelled.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/spongepowered/api/event/Cause.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.util.CopyableBuilder;
import org.spongepowered.api.util.annotation.DoNotStore;
import org.spongepowered.eventgen.annotations.NoFactoryMethod;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -54,6 +55,7 @@
*/
@DoNotStore
@SuppressWarnings("unchecked")
@NoFactoryMethod
public final class Cause implements Iterable<Object> {

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/spongepowered/api/event/EventContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.util.CopyableBuilder;
import org.spongepowered.api.util.annotation.DoNotStore;
import org.spongepowered.eventgen.annotations.NoFactoryMethod;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -42,6 +43,7 @@
* in the event's {@link Cause}.
*/
@DoNotStore
@NoFactoryMethod
public final class EventContext {

private static final EventContext EMPTY_CONTEXT = new EventContext(Map.of());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.spongepowered.api.world.portal.PortalLogic;
import org.spongepowered.api.world.server.ServerLocation;
import org.spongepowered.api.world.server.ServerWorld;
import org.spongepowered.eventgen.annotations.NoFactoryMethod;
import org.spongepowered.math.vector.Vector3d;
import org.spongepowered.plugin.PluginContainer;

Expand All @@ -62,6 +63,7 @@
* Standard keys for use within {@link EventContext}s.
*/
@SuppressWarnings("unused")
@NoFactoryMethod
public final class EventContextKeys {

// @formatter:off
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/spongepowered/api/event/Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
package org.spongepowered.api.event;

import org.spongepowered.eventgen.annotations.NoFactoryMethod;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -34,6 +36,7 @@
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@NoFactoryMethod
public @interface Listener {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.util.annotation.eventgen.NoFactoryMethod;
import org.spongepowered.eventgen.annotations.NoFactoryMethod;
import org.spongepowered.api.world.server.ServerLocation;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
package org.spongepowered.api.event.action;

import org.spongepowered.api.event.Event;
import org.spongepowered.eventgen.annotations.NoFactoryMethod;

/**
* Base event for all interactions.
*/
@NoFactoryMethod
public interface InteractEvent extends Event {

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.util.Direction;
import org.spongepowered.api.util.Tristate;
import org.spongepowered.api.util.annotation.eventgen.GenerateFactoryMethod;
import org.spongepowered.api.util.annotation.eventgen.ImplementedBy;
import org.spongepowered.eventgen.annotations.ImplementedBy;
import org.spongepowered.api.world.server.ServerLocation;
import org.spongepowered.math.vector.Vector3d;

Expand Down Expand Up @@ -105,7 +104,6 @@ interface Finish extends Primary, Cancellable {
*
* <p>This is usually right-click.</p>
*/
@GenerateFactoryMethod
interface Secondary extends InteractBlockEvent {

Tristate originalUseItemResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.checkerframework.framework.qual.DefaultQualifier(org.checkerframework.checker.nullness.qual.NonNull.class)
@DefaultQualifier(NonNull.class)
package org.spongepowered.api.event.cause.entity.damage;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.checkerframework.framework.qual.DefaultQualifier(org.checkerframework.checker.nullness.qual.NonNull.class)
@DefaultQualifier(NonNull.class)
package org.spongepowered.api.event.cause.entity.damage.source;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.checkerframework.framework.qual.DefaultQualifier(org.checkerframework.checker.nullness.qual.NonNull.class)
@DefaultQualifier(NonNull.class)
package org.spongepowered.api.event.cause.entity;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
@org.checkerframework.framework.qual.DefaultQualifier(org.checkerframework.checker.nullness.qual.NonNull.class)
@DefaultQualifier(NonNull.class)
package org.spongepowered.api.event.cause;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.event.impl.data.AbstractValueChangeEvent;
import org.spongepowered.api.util.annotation.eventgen.ImplementedBy;
import org.spongepowered.api.util.annotation.eventgen.PropertySettings;
import org.spongepowered.eventgen.annotations.ImplementedBy;
import org.spongepowered.eventgen.annotations.PropertySettings;

/**
* An event that is associated with a {@link org.spongepowered.api.data.DataHolder.Mutable} that may have some
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
import org.spongepowered.api.event.Event;
import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.impl.entity.AbstractAffectEntityEvent;
import org.spongepowered.api.util.annotation.eventgen.ImplementedBy;
import org.spongepowered.api.util.annotation.eventgen.PropertySettings;
import org.spongepowered.eventgen.annotations.ImplementedBy;
import org.spongepowered.eventgen.annotations.NoFactoryMethod;
import org.spongepowered.eventgen.annotations.PropertySettings;
import org.spongepowered.api.world.explosion.Explosion;
import org.spongepowered.api.world.server.ServerLocation;

Expand All @@ -48,6 +49,7 @@
* Other cases will be included as necessary.
*/
@ImplementedBy(AbstractAffectEntityEvent.class)
@NoFactoryMethod
public interface AffectEntityEvent extends Event, Cancellable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.util.Tuple;
import org.spongepowered.api.util.annotation.eventgen.ImplementedBy;
import org.spongepowered.api.util.annotation.eventgen.PropertySettings;
import org.spongepowered.eventgen.annotations.ImplementedBy;
import org.spongepowered.eventgen.annotations.PropertySettings;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.difficulty.Difficulties;
import org.spongepowered.api.world.difficulty.Difficulty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.item.inventory.Slot;
import org.spongepowered.api.util.annotation.eventgen.GenerateFactoryMethod;
import org.spongepowered.eventgen.annotations.GenerateFactoryMethod;

/**
* Called when an entity changes an equipped item. This can occur whenever
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.util.annotation.eventgen.AbsoluteSortPosition;
import org.spongepowered.eventgen.annotations.AbsoluteSortPosition;
import org.spongepowered.api.world.server.ServerWorld;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.event.action.CollideEvent;
import org.spongepowered.api.util.annotation.eventgen.GenerateFactoryMethod;
import org.spongepowered.eventgen.annotations.GenerateFactoryMethod;

/**
* Fired when an {@link Entity} collides with one or more {@link Entity}'s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.util.Tuple;
import org.spongepowered.api.util.annotation.eventgen.ImplementedBy;
import org.spongepowered.api.util.annotation.eventgen.PropertySettings;
import org.spongepowered.eventgen.annotations.ImplementedBy;
import org.spongepowered.eventgen.annotations.PropertySettings;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.difficulty.Difficulties;
import org.spongepowered.api.world.difficulty.Difficulty;
Expand Down
Loading

0 comments on commit 917991a

Please sign in to comment.