mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-27 02:31:43 +01:00
split tasks
This commit is contained in:
parent
4166e19017
commit
d2721d628f
@ -228,13 +228,13 @@ tasks.compileTestJava {
|
|||||||
options.compilerArgs.add("-parameters")
|
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;")
|
badAnnotations.add("Lio/papermc/paper/annotation/DoNotUse;")
|
||||||
jarToScan.set(tasks.jar.flatMap { it.archiveFile })
|
jarToScan.set(tasks.jar.flatMap { it.archiveFile })
|
||||||
classpath.from(configurations.compileClasspath)
|
classpath.from(configurations.compileClasspath)
|
||||||
}
|
}
|
||||||
tasks.check {
|
tasks.check {
|
||||||
dependsOn(scanJar)
|
dependsOn(scanJarForBadCalls)
|
||||||
}
|
}
|
||||||
|
|
||||||
val scanJarForOldGeneratedCode by tasks.registering(io.papermc.paperweight.tasks.ScanJarForOldGeneratedCode::class) {
|
val scanJarForOldGeneratedCode by tasks.registering(io.papermc.paperweight.tasks.ScanJarForOldGeneratedCode::class) {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import io.papermc.paperweight.util.capitalized
|
||||||
import io.papermc.paperweight.util.defaultJavaLauncher
|
import io.papermc.paperweight.util.defaultJavaLauncher
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
@ -28,33 +29,87 @@ dependencies {
|
|||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.registerGenerationTask("generate") {
|
val rewriteApi = tasks.registerGenerationTask("rewriteApi", "paper-api") {
|
||||||
description = "Generate and rewrite boilerplate content of API and its implementation"
|
description = "Rewrite boilerplate content of API"
|
||||||
dependsOn(tasks.check)
|
dependsOn("testRewriteApi")
|
||||||
mainClass.set("io.papermc.generator.Main")
|
mainClass.set("io.papermc.generator.Main\$Rewriter")
|
||||||
classpath(sourceSets.main.map { it.runtimeClasspath })
|
classpath(sourceSets.main.map { it.runtimeClasspath })
|
||||||
systemProperty("typewriter.lexer.ignoreMarkdownDocComments", true)
|
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"
|
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")
|
mainClass.set("io.papermc.generator.rewriter.OldGeneratedCodeTest")
|
||||||
classpath(sourceSets.test.map { it.runtimeClasspath })
|
classpath(sourceSets.test.map { it.runtimeClasspath })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TaskContainer.registerGenerationTask(
|
fun TaskContainer.registerGenerationTask(
|
||||||
name: String,
|
name: String,
|
||||||
|
vararg args: String,
|
||||||
block: JavaExec.() -> Unit
|
block: JavaExec.() -> Unit
|
||||||
): TaskProvider<JavaExec> = register<JavaExec>(name) {
|
): TaskProvider<JavaExec> = register<JavaExec>(name) {
|
||||||
group = "generation"
|
group = "generation"
|
||||||
javaLauncher = project.javaToolchains.defaultJavaLauncher(project)
|
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)
|
block(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.test {
|
sequenceOf("api", "impl").forEach { side ->
|
||||||
useJUnitPlatform()
|
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"
|
group = "io.papermc.paper"
|
||||||
|
@ -35,7 +35,7 @@ import org.jspecify.annotations.NullMarked;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
@NullMarked
|
@NullMarked
|
||||||
public final class Main {
|
public class Main {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogUtils.getLogger();
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
public static final RegistryAccess.Frozen REGISTRY_ACCESS;
|
public static final RegistryAccess.Frozen REGISTRY_ACCESS;
|
||||||
@ -72,21 +72,29 @@ public final class Main {
|
|||||||
private Main() {
|
private Main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Rewriter extends Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
PatternSourceSetRewriter apiSourceSet = new PaperPatternSourceSetRewriter();
|
boolean isApi = args[0].endsWith("-api");
|
||||||
PatternSourceSetRewriter serverSourceSet = new PaperPatternSourceSetRewriter();
|
PatternSourceSetRewriter sourceSet = new PaperPatternSourceSetRewriter();
|
||||||
Rewriters.bootstrap(apiSourceSet, serverSourceSet);
|
(isApi ? Rewriters.API : Rewriters.SERVER).accept(sourceSet);
|
||||||
|
|
||||||
Path api = Path.of(args[0]);
|
|
||||||
Path server = Path.of(args[1]);
|
|
||||||
try {
|
try {
|
||||||
LOGGER.info("Running API generators...");
|
sourceSet.apply(Path.of(args[0], "src/main/java"));
|
||||||
generate(api, Generators.API);
|
} catch (RuntimeException ex) {
|
||||||
apiSourceSet.apply(api.resolve("src/main/java"));
|
throw ex;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LOGGER.info("Running Server generators...");
|
public static class Generator extends Main {
|
||||||
generate(server, Generators.SERVER);
|
|
||||||
serverSourceSet.apply(server.resolve("src/main/java"));
|
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) {
|
} catch (RuntimeException ex) {
|
||||||
throw ex;
|
throw ex;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -106,3 +114,4 @@ public final class Main {
|
|||||||
LOGGER.info("Files written to {}", output.toAbsolutePath());
|
LOGGER.info("Files written to {}", output.toAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -28,6 +28,7 @@ import io.papermc.paper.datacomponent.item.consumable.ItemUseAnimation;
|
|||||||
import io.papermc.typewriter.preset.EnumCloneRewriter;
|
import io.papermc.typewriter.preset.EnumCloneRewriter;
|
||||||
import io.papermc.typewriter.preset.model.EnumValue;
|
import io.papermc.typewriter.preset.model.EnumValue;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import javax.lang.model.SourceVersion;
|
import javax.lang.model.SourceVersion;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
@ -84,7 +85,15 @@ import static io.papermc.generator.utils.Formatting.quoted;
|
|||||||
public final class Rewriters {
|
public final class Rewriters {
|
||||||
|
|
||||||
public static void bootstrap(PatternSourceSetRewriter apiSourceSet, PatternSourceSetRewriter serverSourceSet) {
|
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("PotionType", PotionType.class, new EnumRegistryRewriter<>(Registries.POTION))
|
||||||
.register("EntityType", EntityType.class, new EntityTypeRewriter())
|
.register("EntityType", EntityType.class, new EntityTypeRewriter())
|
||||||
.register("DisplaySlot", DisplaySlot.class, new EnumCloneRewriter<>(net.minecraft.world.scores.DisplaySlot.class) {
|
.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("FeatureFlag", FeatureFlag.class, new FeatureFlagRewriter())
|
||||||
.register("Tag", Tag.class, new TagRewriter())
|
.register("Tag", Tag.class, new TagRewriter())
|
||||||
.register("MapPalette#colors", MapPalette.class, new MapPaletteRewriter());
|
.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("CraftBlockData#MAP", Types.CRAFT_BLOCK_DATA, new CraftBlockDataMapping())
|
||||||
.register("CraftBlockEntityStates", Types.CRAFT_BLOCK_STATES, new CraftBlockEntityStateMapping())
|
.register("CraftBlockEntityStates", Types.CRAFT_BLOCK_STATES, new CraftBlockEntityStateMapping())
|
||||||
.register(Types.CRAFT_STATISTIC, composite(
|
.register(Types.CRAFT_STATISTIC, composite(
|
||||||
@ -198,6 +210,6 @@ public final class Rewriters {
|
|||||||
holder("CraftPotionUtil#extendable", new CraftPotionUtilRewriter("long"))
|
holder("CraftPotionUtil#extendable", new CraftPotionUtilRewriter("long"))
|
||||||
))
|
))
|
||||||
.register("PaperFeatureFlagProviderImpl#FLAGS", Types.PAPER_FEATURE_FLAG_PROVIDER_IMPL, new PaperFeatureFlagMapping());
|
.register("PaperFeatureFlagProviderImpl#FLAGS", Types.PAPER_FEATURE_FLAG_PROVIDER_IMPL, new PaperFeatureFlagMapping());
|
||||||
RegistryBootstrapper.bootstrap(apiSourceSet, serverSourceSet);
|
RegistryBootstrapper.bootstrapServer(sourceSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,15 @@ public class RegistryBootstrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void bootstrap(PatternSourceSetRewriter apiSourceSet, PatternSourceSetRewriter serverSourceSet) {
|
public static void bootstrap(PatternSourceSetRewriter apiSourceSet, PatternSourceSetRewriter serverSourceSet) {
|
||||||
apiSourceSet.register("RegistryEvents", RegistryEvents.class, new RegistryEventsRewriter());
|
bootstrapApi(apiSourceSet);
|
||||||
serverSourceSet.register("RegistryDefinitions", Types.PAPER_REGISTRIES, new PaperRegistriesRewriter());
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,10 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|||||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Tag;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@Tag("generate-impl")
|
||||||
public class BlockStatePropertyTest {
|
public class BlockStatePropertyTest {
|
||||||
|
|
||||||
private static Set<Class<? extends Comparable<?>>> ENUM_PROPERTY_VALUES;
|
private static Set<Class<? extends Comparable<?>>> ENUM_PROPERTY_VALUES;
|
||||||
|
@ -7,11 +7,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.Mob;
|
import net.minecraft.world.entity.Mob;
|
||||||
|
import org.junit.jupiter.api.Tag;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@Tag("generate-api")
|
||||||
public class MobGoalConverterTest {
|
public class MobGoalConverterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -11,8 +11,10 @@ import net.minecraft.resources.ResourceKey;
|
|||||||
import net.minecraft.server.Bootstrap;
|
import net.minecraft.server.Bootstrap;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Tag;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@Tag("rewrite-impl")
|
||||||
public class RegistryMigrationTest {
|
public class RegistryMigrationTest {
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
|
@ -40,8 +40,8 @@ public class OldGeneratedCodeTest {
|
|||||||
|
|
||||||
Rewriters.bootstrap(apiSourceSet, serverSourceSet);
|
Rewriters.bootstrap(apiSourceSet, serverSourceSet);
|
||||||
|
|
||||||
checkOutdated(apiSourceSet, Path.of(args[0]));
|
checkOutdated(apiSourceSet, Path.of(args[0], "src/main/java"));
|
||||||
checkOutdated(serverSourceSet, Path.of(args[1]));
|
checkOutdated(serverSourceSet, Path.of(args[1], "src/main/java"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkOutdated(PaperPatternSourceSetRewriter sourceSetRewriter, Path sourceSet) throws IOException {
|
private static void checkOutdated(PaperPatternSourceSetRewriter sourceSetRewriter, Path sourceSet) throws IOException {
|
||||||
|
@ -23,13 +23,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
+ // Paper start - Mob goal api
|
+ // Paper start - Mob goal api
|
||||||
+ private com.destroystokyo.paper.entity.ai.PaperVanillaGoal<?> vanillaGoal;
|
+ private com.destroystokyo.paper.entity.ai.PaperGoal<?> paperGoal;
|
||||||
+ public <T extends org.bukkit.entity.Mob> com.destroystokyo.paper.entity.ai.Goal<T> asPaperVanillaGoal() {
|
+ public <T extends org.bukkit.entity.Mob> com.destroystokyo.paper.entity.ai.Goal<T> asPaperGoal() {
|
||||||
+ if (this.vanillaGoal == null) {
|
+ if (this.paperGoal == null) {
|
||||||
+ this.vanillaGoal = new com.destroystokyo.paper.entity.ai.PaperVanillaGoal<>(this);
|
+ this.paperGoal = new com.destroystokyo.paper.entity.ai.PaperGoal<>(this);
|
||||||
+ }
|
+ }
|
||||||
+ //noinspection unchecked
|
+ //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
|
+ // Paper end - Mob goal api
|
||||||
+
|
+
|
||||||
|
Loading…
Reference in New Issue
Block a user