Skip to content

Commit

Permalink
Update gradle deps and switch to a maintained version of javapoet
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Jan 18, 2025
1 parent eef90c7 commit 560b0f5
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 84 deletions.
6 changes: 3 additions & 3 deletions annotation-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ plugins {
id 'java'
}

group 'mekanism.annotation-processor'
version '2.0.0'
group = 'mekanism.annotation-processor'
version = '2.0.0'
java.toolchain.languageVersion = JavaLanguageVersion.of("${java_version}")

repositories {
Expand All @@ -24,5 +24,5 @@ dependencies {
implementation('org.openzen.zencode:JavaAnnotations:0.3.8')
//Version of GSON used by vanilla (and thus packed and already downloaded)
implementation('com.google.code.gson:gson:2.10.1')
implementation('com.squareup:javapoet:1.13.0')
implementation('com.palantir.javapoet:javapoet:0.6.0')
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mekanism;

import com.squareup.javapoet.JavaFile;
import com.palantir.javapoet.JavaFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mekanism;

import com.squareup.javapoet.ClassName;
import com.palantir.javapoet.ClassName;

public class MekAnnotationProcessors {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package mekanism;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeSpec;
import com.palantir.javapoet.ClassName;
import com.palantir.javapoet.CodeBlock;
import com.palantir.javapoet.JavaFile;
import com.palantir.javapoet.MethodSpec;
import com.palantir.javapoet.TypeSpec;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
Expand Down Expand Up @@ -56,6 +56,7 @@ public boolean process(Set<? extends TypeElement> annotatedTypes, RoundEnvironme
TypeSpec.Builder registryType = TypeSpec.classBuilder("ComputerMethodRegistry_" + mekModule)
.addModifiers(Modifier.PUBLIC)
.addSuperinterface(methodRegistryInterface);
boolean hasOriginatingElements = false;

//this should only ever be 1 annotation
for (Element element : roundEnvironment.getElementsAnnotatedWithAny(annotatedTypes.toArray(new TypeElement[0]))) {
Expand All @@ -73,12 +74,13 @@ public boolean process(Set<? extends TypeElement> annotatedTypes, RoundEnvironme
continue;
}
registryType.addOriginatingElement(factoryTypeEl);
hasOriginatingElements = true;
AnnotationHelper helper = new AnnotationHelper(processingEnv.getElementUtils(), annotationMirror);
addHandlerToRegistry((TypeElement) typeUtils().asElement(helper.getClassValue("target")), ClassName.get(factoryTypeEl));
}
}

if (!registryType.originatingElements.isEmpty()) {
if (hasOriginatingElements) {
registryType.addMethod(registryInit.build());
TypeSpec registrySpec = registryType.build();
String packageName = "mekanism.generated." + mekModule;
Expand All @@ -88,7 +90,7 @@ public boolean process(Set<? extends TypeElement> annotatedTypes, RoundEnvironme
throw new RuntimeException(e);
}
try (Writer serviceWriter = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/services/" + methodRegistryInterface.canonicalName()).openWriter()) {
serviceWriter.write(packageName + "." + registrySpec.name);
serviceWriter.write(packageName + "." + registrySpec.name());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package mekanism.builder;

import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import com.palantir.javapoet.AnnotationSpec;
import com.palantir.javapoet.ClassName;
import com.palantir.javapoet.CodeBlock;
import com.palantir.javapoet.FieldSpec;
import com.palantir.javapoet.JavaFile;
import com.palantir.javapoet.MethodSpec;
import com.palantir.javapoet.ParameterSpec;
import com.palantir.javapoet.ParameterizedTypeName;
import com.palantir.javapoet.TypeName;
import com.palantir.javapoet.TypeSpec;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.WrongMethodTypeException;
import java.util.ArrayList;
Expand Down Expand Up @@ -451,7 +451,7 @@ private MethodSpec getMethodProxy(String annotatedName, ExecutableElement execut
.returns(returnType)
.beginControlFlow("try")
//invoke the method handle
.addStatement("return ($T)$N.invokeExact($L)", returnType, methodHandleField, proxyParams.stream().map(param -> param.name).collect(Collectors.joining(", ")))
.addStatement("return ($T)$N.invokeExact($L)", returnType, methodHandleField, proxyParams.stream().map(ParameterSpec::name).collect(Collectors.joining(", ")))
//catch a failing method handle (throw as RuntimeException)
.nextControlFlow("catch ($T wmte)", WrongMethodTypeException.class)
.addStatement("throw new $T($S, wmte)", RuntimeException.class, "Method not bound correctly")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mekanism.visitors;

import com.squareup.javapoet.CodeBlock;
import com.palantir.javapoet.CodeBlock;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mekanism.visitors;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.palantir.javapoet.ClassName;
import com.palantir.javapoet.CodeBlock;
import java.util.List;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package mekanism.visitors;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.ParameterSpec;
import com.palantir.javapoet.ClassName;
import com.palantir.javapoet.CodeBlock;
import com.palantir.javapoet.ParameterSpec;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
Expand Down
95 changes: 47 additions & 48 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.function.Consumer

plugins {
id('org.ajoberstar.grgit.service')//Version declared in buildSrc
id('net.darkhax.curseforgegradle') version('1.1.25')
id('net.darkhax.curseforgegradle') version('1.1.26')
id('com.modrinth.minotaur') version('2.8.7')
id('java')
id('eclipse')
Expand All @@ -23,9 +23,9 @@ plugins {
id('net.neoforged.gradle.userdev') version('7.0.154')//https://projects.neoforged.net/neoforged/neogradle
}

tasks.named('wrapper', Wrapper).configure {
tasks.named('wrapper', Wrapper) {
//Define wrapper values here so as to not have to always do so when updating gradlew.properties
gradleVersion = '8.10'
gradleVersion = '8.12'
distributionType = Wrapper.DistributionType.ALL
}

Expand Down Expand Up @@ -184,43 +184,42 @@ for (String name : secondaryModules) {
}

def setupTasks(SourceSet sourceSet) {
def compileTask = tasks.named(sourceSet.compileJavaTaskName, JavaCompile)
def compileTask = tasks.named(sourceSet.compileJavaTaskName, JavaCompile) {
//Configure specific compile tasks to have the proper annotation processor info
setGroup('compile')
options.annotationProcessorPath = configurations.annotationProcessor
options.compilerArgs.addAll([
"-AmekanismModule=mekanism${sourceSet == sourceSets.main ? '' : sourceSet.name}",//annotation processor param
'-parameters'
])
}
//Set the various variables/settings for the different process resources tasks
tasks.named(sourceSet.processResourcesTaskName, ProcessResources).configure { ProcessResources process ->
process.setGroup('process resources')
process.duplicatesStrategy(DuplicatesStrategy.FAIL)
tasks.named(sourceSet.processResourcesTaskName, ProcessResources) {
setGroup('process resources')
duplicatesStrategy = DuplicatesStrategy.FAIL
var versionProperties = ['version': mod_version, 'mc_version': minecraft_version_range, 'forge_version': forge_version_range, 'loader_version': loader_version_range,
'jei_version': jei_version_range]
//Mark the properties as inputs so that when they change things update
process.inputs.properties(versionProperties)
process.filesMatching('META-INF/neoforge.mods.toml') { expand(versionProperties) }
process.from("${projectDir}") { include('logo.png') }
inputs.properties(versionProperties)
filesMatching('META-INF/neoforge.mods.toml') { expand(versionProperties) }
from("${projectDir}") { include('logo.png') }
//Depend on the compile task so that we can map the computer methods as needed
process.dependsOn(compileTask)
dependsOn(compileTask)
def files = fileTree(dir: outputs.files.asPath, includes: ['**/*.json', '**/*.mcmeta'])
process.doLast {
doLast {
for (def file : files) {
file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
}
}
}
tasks.named(sourceSet.compileJavaTaskName, JavaCompile).configure { setGroup('compile') }
tasks.named(sourceSet.compileJavaTaskName, JavaCompile) { setGroup('compile') }
for (String extraType : extraTypes) {
def extraSourceSet = getExtraSourceSet(sourceSet, extraType).get()
tasks.named(extraSourceSet.processResourcesTaskName, ProcessResources).configure {
tasks.named(extraSourceSet.processResourcesTaskName, ProcessResources) {
setGroup('process resources')
dependsOn(compileTask)
}
tasks.named(extraSourceSet.compileJavaTaskName, JavaCompile).configure { setGroup('compile') }
}
//Configure specific compile tasks to have the proper annotation processor info
compileTask.configure { JavaCompile task ->
setGroup('compile')
task.options.annotationProcessorPath = configurations.annotationProcessor
task.options.compilerArgs.addAll([
"-AmekanismModule=mekanism${sourceSet == sourceSets.main ? '' : sourceSet.name}",//annotation processor param
'-parameters'
])
tasks.named(extraSourceSet.compileJavaTaskName, JavaCompile) { setGroup('compile') }
}
}

Expand Down Expand Up @@ -342,9 +341,9 @@ repositories { RepositoryHandler handler ->
exclusiveRepo(handler, 'https://maven.parchmentmc.org/', 'org.parchmentmc.data')
}

tasks.named('test').configure {
tasks.named('test') {
//Disable builtin test task as we use and build uses testJunit so there is no point in having it also attempt to run an empty test task
enabled(false)
enabled = false
}

dependencies {
Expand Down Expand Up @@ -438,39 +437,39 @@ def getManifestAttributes(String title) {
]
}

tasks.named('jar', Jar).configure { Jar jar ->
jar.duplicatesStrategy(DuplicatesStrategy.FAIL)
jar.from([sourceSets.api.output, sourceSets.main.output])
jar.exclude('crafttweaker_parameter_names.json')
jar.manifest.attributes(getManifestAttributes('Mekanism'))
tasks.named('jar', Jar) {
duplicatesStrategy = DuplicatesStrategy.FAIL
from([sourceSets.api.output, sourceSets.main.output])
exclude('crafttweaker_parameter_names.json')
manifest.attributes(getManifestAttributes('Mekanism'))
}

tasks.named('sourcesJar', Jar).configure { Jar jar ->
tasks.named('sourcesJar', Jar) {
dependsOn(classes, apiClasses, additionsClasses, generatorsClasses, toolsClasses)
jar.duplicatesStrategy(DuplicatesStrategy.FAIL)
duplicatesStrategy = DuplicatesStrategy.FAIL
//Note: Already contains main source set's sources by default
jar.from(sourceSets.api.allJava, sourceSets.additions.allJava, sourceSets.generators.allJava, sourceSets.tools.allJava)
jar.manifest.attributes(getManifestAttributes('Mekanism'))
from(sourceSets.api.allJava, sourceSets.additions.allJava, sourceSets.generators.allJava, sourceSets.tools.allJava)
manifest.attributes(getManifestAttributes('Mekanism'))
}

def secondaryJar(SourceSet sourceSet, String title) {
return tasks.register(sourceSet.jarTaskName, Jar, {
duplicatesStrategy(DuplicatesStrategy.FAIL)
return tasks.register(sourceSet.jarTaskName, Jar) {
duplicatesStrategy = DuplicatesStrategy.FAIL
archiveClassifier.set(sourceSet.name)
from(sourceSet.output)
if (!title.isEmpty()) {
archiveFileName.set("${title}-${project.version}.jar")
}
manifest.attributes(getManifestAttributes(title.isEmpty() ? 'Mekanism' : title))
})
}
}

def apiJar = secondaryJar(sourceSets.api, '')
def additionsJar = secondaryJar(sourceSets.additions, 'MekanismAdditions')
def generatorsJar = secondaryJar(sourceSets.generators, 'MekanismGenerators')
def toolsJar = secondaryJar(sourceSets.tools, 'MekanismTools')

def mergeModuleResources = tasks.register('mergeModuleResources', MergeModuleResources, {
def mergeModuleResources = tasks.register('mergeModuleResources', MergeModuleResources) {
dependsOn('classes', 'apiClasses', 'additionsClasses', 'generatorsClasses', 'toolsClasses')
mustRunAfter('clean')
//Note: Get the resources from the output of process resources, so that any expands that need to happen we know have already happened
Expand All @@ -485,11 +484,11 @@ def mergeModuleResources = tasks.register('mergeModuleResources', MergeModuleRes
}
//Only look at generated service files as a restriction for our input
annotationGenerated = annotationGenerated.asFileTree.matching(serviceFilter)
})
}

def allJar = tasks.register('allJar', AllJar, {
def allJar = tasks.register('allJar', AllJar) {
dependsOn(mergeModuleResources)
duplicatesStrategy(DuplicatesStrategy.FAIL)
duplicatesStrategy = DuplicatesStrategy.FAIL
archiveClassifier.set('all')
manifest.attributes(getManifestAttributes('MekanismAll'))
pathsToExclude.set(mergeModuleResources.flatMap(m -> m.pathsToExclude))
Expand All @@ -498,7 +497,7 @@ def allJar = tasks.register('allJar', AllJar, {
for (String name : secondaryModules) {
secondaryModuleOutputs += sourceSets.named(name).get().output
}
})
}

tasks.withType(JavaCompile).configureEach({
options.encoding = 'UTF-8'
Expand Down Expand Up @@ -603,7 +602,7 @@ outputChangelog.configure { OutputChangelog out ->

if (System.getenv('CURSEFORGE_KEY') != null || project.hasProperty('curseforgeKey')) {
logger.lifecycle('Enabling Curseforge config')
tasks.register('curseforge', TaskPublishCurseForge, { task ->
tasks.register('curseforge', TaskPublishCurseForge) { task ->
dependsOn(outputChangelog)
setGroup('publishing')
setDescription('Upload Mekanism to CurseForge')
Expand Down Expand Up @@ -655,7 +654,7 @@ if (System.getenv('CURSEFORGE_KEY') != null || project.hasProperty('curseforgeKe
logger.quiet('https://www.curseforge.com/minecraft/mc-mods/mekanism-generators/files/{}', (Object) generatorsCfUpload.curseFileId)
logger.quiet('https://www.curseforge.com/minecraft/mc-mods/mekanism-tools/files/{}', (Object) toolsCfUpload.curseFileId)
}
})
}
}

void setGenericCurseArtifactData(UploadArtifact artifact, Provider<RegularFile> changelog) {
Expand All @@ -679,7 +678,7 @@ if (System.getenv('MODRINTH_TOKEN') != null || project.hasProperty('modrinthToke
def additionsModrinth = createSecondaryModrinthUpload('additions', 'a6F3uASn', additionsJar)
def generatorsModrinth = createSecondaryModrinthUpload('generators', 'OFVYKsAk', generatorsJar)
def toolsModrinth = createSecondaryModrinthUpload('tools', 'tqQpq1lt', toolsJar)
tasks.named('modrinth').configure {
tasks.named('modrinth') {
dependsOn(jar, apiJar, outputChangelog)
finalizedBy(additionsModrinth, generatorsModrinth, toolsModrinth)
notCompatibleWithConfigurationCache('Not yet compatible')//TODO: Remove when possible
Expand Down Expand Up @@ -725,7 +724,7 @@ if (System.getenv('MODRINTH_TOKEN') != null || project.hasProperty('modrinthToke
}

def createSecondaryModrinthUpload(String output, String targetProjectId, TaskProvider<Jar> sourceSetJar) {
return tasks.register("${output}Modrinth", TaskModrinthUpload, {
return tasks.register("${output}Modrinth", TaskModrinthUpload) {
setGroup('publishing')
setDescription("Upload Mekanism ${output} to Modrinth")
dependsOn(tasks.named('modrinth'), sourceSetJar)
Expand All @@ -747,5 +746,5 @@ def createSecondaryModrinthUpload(String output, String targetProjectId, TaskPro
}
logger.lifecycle('Updated Modrinth extension')
}
})
}
}
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ repositories {
}

dependencies {
implementation('org.ajoberstar.grgit:grgit-gradle:5.2.2')
implementation('org.ajoberstar.grgit:grgit-gradle:5.3.0')
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ junit_version=5.11.0
jqwik_version=1.9.0

#NeoGradle Settings
neogradle.subsystems.parchment.minecraftVersion=1.21
neogradle.subsystems.parchment.mappingsVersion=2024.07.28
neogradle.subsystems.parchment.minecraftVersion=1.21.1
neogradle.subsystems.parchment.mappingsVersion=2024.11.17
neogradle.subsystems.conventions.sourcesets.enabled=false

#misc settings
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Loading

0 comments on commit 560b0f5

Please sign in to comment.