split tasks

This commit is contained in:
Lulu13022002 2025-01-06 13:23:47 +01:00
parent 4166e19017
commit d2721d628f
No known key found for this signature in database
GPG Key ID: 491C8F0B8ACDEB01
10 changed files with 138 additions and 48 deletions

View File

@ -228,13 +228,13 @@ tasks.compileTestJava {
options.compilerArgs.add("-parameters")
}
val scanJar = tasks.register("scanJarForBadCalls", io.papermc.paperweight.tasks.ScanJarForBadCalls::class) {
val scanJarForBadCalls by tasks.registering(io.papermc.paperweight.tasks.ScanJarForBadCalls::class) {
badAnnotations.add("Lio/papermc/paper/annotation/DoNotUse;")
jarToScan.set(tasks.jar.flatMap { it.archiveFile })
classpath.from(configurations.compileClasspath)
}
tasks.check {
dependsOn(scanJar)
dependsOn(scanJarForBadCalls)
}
val scanJarForOldGeneratedCode by tasks.registering(io.papermc.paperweight.tasks.ScanJarForOldGeneratedCode::class) {

View File

@ -1,3 +1,4 @@
import io.papermc.paperweight.util.capitalized
import io.papermc.paperweight.util.defaultJavaLauncher
plugins {
@ -28,33 +29,87 @@ dependencies {
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
tasks.registerGenerationTask("generate") {
description = "Generate and rewrite boilerplate content of API and its implementation"
dependsOn(tasks.check)
mainClass.set("io.papermc.generator.Main")
val rewriteApi = tasks.registerGenerationTask("rewriteApi", "paper-api") {
description = "Rewrite boilerplate content of API"
dependsOn("testRewriteApi")
mainClass.set("io.papermc.generator.Main\$Rewriter")
classpath(sourceSets.main.map { it.runtimeClasspath })
systemProperty("typewriter.lexer.ignoreMarkdownDocComments", true)
}
tasks.registerGenerationTask("scanOldGeneratedSourceCode") {
val rewriteImpl = tasks.registerGenerationTask("rewriteImpl", "paper-server") {
description = "Rewrite boilerplate content of API implementation"
dependsOn("testRewriteImpl")
mainClass.set("io.papermc.generator.Main\$Rewriter")
classpath(sourceSets.main.map { it.runtimeClasspath })
systemProperty("typewriter.lexer.ignoreMarkdownDocComments", true)
}
tasks.register("rewrite") {
group = "generation"
description = "Rewrite boilerplate content of API and its implementation"
dependsOn(rewriteApi, rewriteImpl)
}
val generateApi = tasks.registerGenerationTask("generateApi", "paper-api") {
description = "Generate boilerplate content of API"
dependsOn("testGenerateApi")
mainClass.set("io.papermc.generator.Main\$Generator")
classpath(sourceSets.main.map { it.runtimeClasspath })
}
val generateImpl = tasks.registerGenerationTask("generateImpl", "paper-server") {
description = "Generate boilerplate content of API implementation"
dependsOn("testGenerateImpl")
mainClass.set("io.papermc.generator.Main\$Generator")
classpath(sourceSets.main.map { it.runtimeClasspath })
}
tasks.register("generate") {
group = "generation"
description = "Generate boilerplate content of API and its implementation"
dependsOn(generateApi, generateImpl)
}
tasks.register<JavaExec>("scanOldGeneratedSourceCode") {
group = "verification"
javaLauncher = project.javaToolchains.defaultJavaLauncher(project)
description = "Scan source code to detect outdated generated code"
args(project(":paper-api").projectDir.toString(), project(":paper-server").projectDir.toString())
mainClass.set("io.papermc.generator.rewriter.OldGeneratedCodeTest")
classpath(sourceSets.test.map { it.runtimeClasspath })
}
fun TaskContainer.registerGenerationTask(
name: String,
vararg args: String,
block: JavaExec.() -> Unit
): TaskProvider<JavaExec> = register<JavaExec>(name) {
group = "generation"
javaLauncher = project.javaToolchains.defaultJavaLauncher(project)
args(project(":paper-api").projectDir.toString(), project(":paper-server").projectDir.toString())
if (args.isNotEmpty()) {
val projectDirs = args.map { project.rootProject.findProject(it)?.projectDir }
args(projectDirs.map { it.toString() })
inputs.files(projectDirs)
}
block(this)
}
tasks.test {
useJUnitPlatform()
sequenceOf("api", "impl").forEach { side ->
sequenceOf("generate", "rewrite").forEach { type ->
val task = tasks.register<Test>("test${type.capitalized()}${side.capitalized()}") {
group = "verification"
javaLauncher = project.javaToolchains.defaultJavaLauncher(project)
useJUnitPlatform {
includeTags.add("${type}-${side}")
}
}
tasks.check {
dependsOn(task)
}
}
}
group = "io.papermc.paper"

View File

@ -35,7 +35,7 @@ import org.jspecify.annotations.NullMarked;
import org.slf4j.Logger;
@NullMarked
public final class Main {
public class Main {
private static final Logger LOGGER = LogUtils.getLogger();
public static final RegistryAccess.Frozen REGISTRY_ACCESS;
@ -72,37 +72,46 @@ public final class Main {
private Main() {
}
public static void main(String[] args) {
PatternSourceSetRewriter apiSourceSet = new PaperPatternSourceSetRewriter();
PatternSourceSetRewriter serverSourceSet = new PaperPatternSourceSetRewriter();
Rewriters.bootstrap(apiSourceSet, serverSourceSet);
public static class Rewriter extends Main {
Path api = Path.of(args[0]);
Path server = Path.of(args[1]);
try {
LOGGER.info("Running API generators...");
generate(api, Generators.API);
apiSourceSet.apply(api.resolve("src/main/java"));
LOGGER.info("Running Server generators...");
generate(server, Generators.SERVER);
serverSourceSet.apply(server.resolve("src/main/java"));
} catch (RuntimeException ex) {
throw ex;
} catch (Exception e) {
throw new RuntimeException(e);
public static void main(String[] args) {
boolean isApi = args[0].endsWith("-api");
PatternSourceSetRewriter sourceSet = new PaperPatternSourceSetRewriter();
(isApi ? Rewriters.API : Rewriters.SERVER).accept(sourceSet);
try {
sourceSet.apply(Path.of(args[0], "src/main/java"));
} catch (RuntimeException ex) {
throw ex;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
private static void generate(Path sourceSet, Collection<SourceGenerator> generators) throws IOException {
Path output = sourceSet.resolve("src/main/generated");
if (Files.exists(output)) {
PathUtils.deleteDirectory(output);
public static class Generator extends Main {
public static void main(String[] args) {
boolean isApi = args[0].endsWith("-api");
try {
generate(Path.of(args[0]), isApi ? Generators.API : Generators.SERVER);
} catch (RuntimeException ex) {
throw ex;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
for (SourceGenerator generator : generators) {
generator.writeToFile(output);
private static void generate(Path sourceSet, Collection<SourceGenerator> generators) throws IOException {
Path output = sourceSet.resolve("src/main/generated");
if (Files.exists(output)) {
PathUtils.deleteDirectory(output);
}
for (SourceGenerator generator : generators) {
generator.writeToFile(output);
}
LOGGER.info("Files written to {}", output.toAbsolutePath());
}
LOGGER.info("Files written to {}", output.toAbsolutePath());
}
}

View File

@ -28,6 +28,7 @@ import io.papermc.paper.datacomponent.item.consumable.ItemUseAnimation;
import io.papermc.typewriter.preset.EnumCloneRewriter;
import io.papermc.typewriter.preset.model.EnumValue;
import java.util.Map;
import java.util.function.Consumer;
import javax.lang.model.SourceVersion;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minecraft.core.Holder;
@ -84,7 +85,15 @@ import static io.papermc.generator.utils.Formatting.quoted;
public final class Rewriters {
public static void bootstrap(PatternSourceSetRewriter apiSourceSet, PatternSourceSetRewriter serverSourceSet) {
apiSourceSet
bootstrapApi(apiSourceSet);
bootstrapServer(serverSourceSet);
}
public static final Consumer<PatternSourceSetRewriter> API = Rewriters::bootstrapApi;
public static final Consumer<PatternSourceSetRewriter> SERVER = Rewriters::bootstrapServer;
private static void bootstrapApi(PatternSourceSetRewriter sourceSet) {
sourceSet
.register("PotionType", PotionType.class, new EnumRegistryRewriter<>(Registries.POTION))
.register("EntityType", EntityType.class, new EntityTypeRewriter())
.register("DisplaySlot", DisplaySlot.class, new EnumCloneRewriter<>(net.minecraft.world.scores.DisplaySlot.class) {
@ -185,8 +194,11 @@ public final class Rewriters {
.register("FeatureFlag", FeatureFlag.class, new FeatureFlagRewriter())
.register("Tag", Tag.class, new TagRewriter())
.register("MapPalette#colors", MapPalette.class, new MapPaletteRewriter());
RegistryBootstrapper.bootstrapApi(sourceSet);
}
serverSourceSet
private static void bootstrapServer(PatternSourceSetRewriter sourceSet) {
sourceSet
.register("CraftBlockData#MAP", Types.CRAFT_BLOCK_DATA, new CraftBlockDataMapping())
.register("CraftBlockEntityStates", Types.CRAFT_BLOCK_STATES, new CraftBlockEntityStateMapping())
.register(Types.CRAFT_STATISTIC, composite(
@ -198,6 +210,6 @@ public final class Rewriters {
holder("CraftPotionUtil#extendable", new CraftPotionUtilRewriter("long"))
))
.register("PaperFeatureFlagProviderImpl#FLAGS", Types.PAPER_FEATURE_FLAG_PROVIDER_IMPL, new PaperFeatureFlagMapping());
RegistryBootstrapper.bootstrap(apiSourceSet, serverSourceSet);
RegistryBootstrapper.bootstrapServer(sourceSet);
}
}

View File

@ -31,7 +31,15 @@ public class RegistryBootstrapper {
}
public static void bootstrap(PatternSourceSetRewriter apiSourceSet, PatternSourceSetRewriter serverSourceSet) {
apiSourceSet.register("RegistryEvents", RegistryEvents.class, new RegistryEventsRewriter());
serverSourceSet.register("RegistryDefinitions", Types.PAPER_REGISTRIES, new PaperRegistriesRewriter());
bootstrapApi(apiSourceSet);
bootstrapServer(serverSourceSet);
}
public static void bootstrapApi(PatternSourceSetRewriter sourceSet) {
sourceSet.register("RegistryEvents", RegistryEvents.class, new RegistryEventsRewriter());
}
public static void bootstrapServer(PatternSourceSetRewriter sourceSet) {
sourceSet.register("RegistryDefinitions", Types.PAPER_REGISTRIES, new PaperRegistriesRewriter());
}
}

View File

@ -20,8 +20,10 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@Tag("generate-impl")
public class BlockStatePropertyTest {
private static Set<Class<? extends Comparable<?>>> ENUM_PROPERTY_VALUES;

View File

@ -7,11 +7,13 @@ import java.util.ArrayList;
import java.util.List;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Tag("generate-api")
public class MobGoalConverterTest {
@Test

View File

@ -11,8 +11,10 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.server.Bootstrap;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@Tag("rewrite-impl")
public class RegistryMigrationTest {
@BeforeAll

View File

@ -40,8 +40,8 @@ public class OldGeneratedCodeTest {
Rewriters.bootstrap(apiSourceSet, serverSourceSet);
checkOutdated(apiSourceSet, Path.of(args[0]));
checkOutdated(serverSourceSet, Path.of(args[1]));
checkOutdated(apiSourceSet, Path.of(args[0], "src/main/java"));
checkOutdated(serverSourceSet, Path.of(args[1], "src/main/java"));
}
private static void checkOutdated(PaperPatternSourceSetRewriter sourceSetRewriter, Path sourceSet) throws IOException {

View File

@ -23,13 +23,13 @@
}
+ // Paper start - Mob goal api
+ private com.destroystokyo.paper.entity.ai.PaperVanillaGoal<?> vanillaGoal;
+ public <T extends org.bukkit.entity.Mob> com.destroystokyo.paper.entity.ai.Goal<T> asPaperVanillaGoal() {
+ if (this.vanillaGoal == null) {
+ this.vanillaGoal = new com.destroystokyo.paper.entity.ai.PaperVanillaGoal<>(this);
+ private com.destroystokyo.paper.entity.ai.PaperGoal<?> paperGoal;
+ public <T extends org.bukkit.entity.Mob> com.destroystokyo.paper.entity.ai.Goal<T> asPaperGoal() {
+ if (this.paperGoal == null) {
+ this.paperGoal = new com.destroystokyo.paper.entity.ai.PaperGoal<>(this);
+ }
+ //noinspection unchecked
+ return (com.destroystokyo.paper.entity.ai.Goal<T>) this.vanillaGoal;
+ return (com.destroystokyo.paper.entity.ai.Goal<T>) this.paperGoal;
+ }
+ // Paper end - Mob goal api
+