Skip to content

Commit

Permalink
wip: update to the new event generator
Browse files Browse the repository at this point in the history
  • Loading branch information
gabizou committed Sep 30, 2024
1 parent 55f8113 commit 85b7ed7
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 522 deletions.
72 changes: 48 additions & 24 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ plugins {
alias(libs.plugins.indra.crossdoc)
alias(libs.plugins.indra.publishing)
alias(libs.plugins.indra.publishing.sonatype)
alias(libs.plugins.eventImplGen)
alias(libs.plugins.ideaExt)
alias(libs.plugins.errorprone)
alias(libs.plugins.nexusPublish)
Expand All @@ -34,12 +33,30 @@ configurations {
}
}
}
tasks {
register("printSourceDirs") {
doLast {
sourceSets.forEach { set ->
println("SourceSet: ${set.name}")
println("Java Source Dirs: ${set.java.srcDirs}" )
}
}
}
}

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

// Project dependencies
dependencies {
// Directly tied to what's available from Minecraft
api(libs.log4j.api)
api(libs.gson)
api(libs.eventImplGen.annotations)
annotationProcessor(libs.eventImplGen.processor)

// Adventure
api(platform(libs.adventure.bom))
Expand Down Expand Up @@ -131,28 +148,35 @@ dependencies {
}

tasks {
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")

compileJava {
options.compilerArgs.addAll(listOf(
"-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 Expand Up @@ -217,14 +241,14 @@ idea {
testRunner = org.jetbrains.gradle.ext.ActionDelegationConfig.TestRunner.PLATFORM
}
taskTriggers {
beforeBuild(tasks.genEventImpl)
// beforeBuild(tasks.genEventImpl)
}
}
}
}

eclipse {
synchronizationTasks(tasks.genEventImpl)
// synchronizationTasks(tasks.genEventImpl)
}

val organization: String by project
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ guice = { module = "com.google.inject:guice", version.ref = "guice" }
log4j-api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" }
math = { module = "org.spongepowered:math", version.ref = "math" }
pluginSpi = { module = "org.spongepowered:plugin-spi", version.ref = "pluginSpi" }
eventImplGen-processor = {module = "org.spongepowered:event-impl-gen", version = "8.0.0-SNAPSHOT"}
eventImplGen-annotations = { module = "org.spongepowered:event-impl-gen-annotations", version = "8.0.0-SNAPSHOT"}

# build-time/annotations

Expand Down
20 changes: 20 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<configuration>
<verify-metadata>true</verify-metadata>
<verify-signatures>false</verify-signatures>
<trusted-artifacts>
<trust group="org.spongepowered" name="event-impl-gen" reason="SNAPSHOT"/>
<trust group="org.spongepowered" name="event-impl-gen-annotations" reason="SNAPSHOT"/>
</trusted-artifacts>
</configuration>
<components>
<component group="aopalliance" name="aopalliance" version="1.0">
Expand Down Expand Up @@ -221,6 +225,14 @@
<sha256 value="893d56afcea1b22f83220fd7e49a6668c5b8901e39bd59dc57b42f55673721ce" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.dagger" name="dagger" version="2.42">
<artifact name="dagger-2.42.jar">
<sha256 value="7ad8147fdb5dfb481b7cde8c70da73afbaa21430ce757fcd96709fcfb6a4d56b" origin="Generated by Gradle"/>
</artifact>
<artifact name="dagger-2.42.pom">
<sha256 value="ca6529bd6d79090f0ab6f5da452eb4fbb29377b48e6a806e7612396dcb2998e0" 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 @@ -526,6 +538,14 @@
<sha256 value="f6ac2b6de9ed3823c8d68977df6352f3936af5db7baeb12303cdc9d3c4f46590" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup" name="javapoet" version="1.13.0">
<artifact name="javapoet-1.13.0.jar">
<sha256 value="4c7517e848a71b36d069d12bb3bf46a70fd4cda3105d822b0ed2e19c00b69291" origin="Generated by Gradle"/>
</artifact>
<artifact name="javapoet-1.13.0.pom">
<sha256 value="54a34fa8502a46bc90efdb49262600591fa80bf9a34f5a4c798311aec16ca977" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okhttp3" name="okhttp" version="4.10.0">
<artifact name="okhttp-4.10.0.jar">
<sha256 value="7580f14fa1691206e37081ad3f92063b1603b328da0bb316f2fef02e0562e7ec" origin="Generated by Gradle"/>
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/spongepowered/api/event/CompositeEvent.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.spongepowered.api.event;

import org.spongepowered.api.event.impl.AbstractCompositeEvent;
import org.spongepowered.api.event.impl.entity.AbstractDamageEntityEvent;
import org.spongepowered.api.util.annotation.eventgen.GenerateFactoryMethod;
import org.spongepowered.api.util.annotation.eventgen.ImplementedBy;
import org.spongepowered.api.util.annotation.eventgen.NoFactoryMethod;
import org.spongepowered.api.util.annotation.eventgen.PropertySettings;
import org.spongepowered.eventgen.annotations.GenerateFactoryMethod;
import org.spongepowered.eventgen.annotations.ImplementedBy;
import org.spongepowered.eventgen.annotations.PropertySettings;

import java.util.List;
import java.util.function.Consumer;
Expand All @@ -25,18 +23,19 @@
@ImplementedBy(AbstractCompositeEvent.class)
public interface CompositeEvent<E extends Event> extends Event, Cancellable {

@PropertySettings(useInToString = false)
E baseEvent();

List<Event> children();

default <E extends Event> List<? extends E> event(Class<E> type) {
default <A extends Event> List<? extends A> event(Class<A> type) {
return this.children().stream()
.filter(type::isInstance)
.map(type::cast)
.toList();
}

default <E extends Event> void applyTo(Class<E> type, Consumer<? super E> consumer) {
default <A extends Event> void applyTo(Class<A> type, Consumer<? super A> consumer) {
this.children().stream()
.filter(type::isInstance)
.map(type::cast)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spongepowered/api/event/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

import org.spongepowered.api.event.impl.AbstractEvent;
import org.spongepowered.api.util.annotation.DoNotStore;
import org.spongepowered.api.util.annotation.eventgen.AbsoluteSortPosition;
import org.spongepowered.api.util.annotation.eventgen.ImplementedBy;
import org.spongepowered.eventgen.annotations.AbsoluteSortPosition;
import org.spongepowered.eventgen.annotations.ImplementedBy;

/**
* An event called within Sponge.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.CompositeEvent;
import org.spongepowered.api.event.action.InteractEvent;
import org.spongepowered.api.event.impl.AbstractCompositeEvent;
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.api.world.server.ServerLocation;
import org.spongepowered.math.vector.Vector3d;

Expand Down Expand Up @@ -187,5 +190,10 @@ interface Pre extends Secondary, Cancellable {
void setUseBlockResult(Tristate result);
}

@ImplementedBy(AbstractCompositeEvent.class)
interface Post extends Secondary, CompositeEvent<Secondary> {

}

}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 85b7ed7

Please sign in to comment.