Skip to content

Commit

Permalink
Fix duplicate generated package name
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Jul 9, 2024
1 parent ff5afa7 commit d772734
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
run: ./gradlew clean build --stacktrace
publish:
strategy:
fail-fast: false
matrix:
include:
- name: Maven
Expand Down
11 changes: 8 additions & 3 deletions buildSrc/src/main/kotlin/ffapi.neo-entrypoint.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ masterSourceSets.forEach { sourceSet ->
outputDir.set(targetDir)
fabricModJson.set(modMetadataJson)
testEnvironment = sourceSet.name == "testmod"
includeVersion.set(project.parent?.name == "deprecated")
}
sourceSet.java.srcDir(task)
val cleanTask = tasks.register(sourceSet.getTaskName("clean", baseTaskName), Delete::class.java) {
Expand All @@ -49,21 +50,25 @@ abstract class GenerateForgeModEntrypoint : DefaultTask() {
@get:InputFile
val fabricModJson: RegularFileProperty = project.objects.fileProperty()

@get:Input
val includeVersion: Property<Boolean> = project.objects.property(Boolean::class)

@get:Input
val testEnvironment: Property<Boolean> = project.objects.property(Boolean::class)

@get:OutputDirectory
val outputDir: DirectoryProperty = project.objects.directoryProperty()

private val projectNamePattern = "^fabric_(.+?)(?:_v\\d)?\$".toRegex()
private val projectVersionNamePattern = "^fabric_(.+?_v\\d)?\$".toRegex()

@TaskAction
fun run() {
val modMetadata = parseModMetadata(fabricModJson.asFile.get())
val modid = normalizeModid(modMetadata.id)

val className = "GeneratedEntryPoint"
val packageName = packageNameForEntryPoint(modid)
val packageName = packageNameForEntryPoint(modid, includeVersion.get())
val packagePath = packageName.replace('/', '.')
val packageDir = outputDir.file(packagePath).get().asFile.toPath()
packageDir.createDirectories()
Expand Down Expand Up @@ -141,8 +146,8 @@ abstract class GenerateForgeModEntrypoint : DefaultTask() {
}
}

private fun packageNameForEntryPoint(modid: String): String {
val uniqueName = projectNamePattern.find(modid)?.groups?.get(1)?.value
private fun packageNameForEntryPoint(modid: String, includeVersion: Boolean): String {
val uniqueName = (if (includeVersion) projectVersionNamePattern else projectNamePattern).find(modid)?.groups?.get(1)?.value
?: throw RuntimeException("Unable to determine generated package name for mod $modid")
return "org.sinytra.fabric.$uniqueName.generated"
}
Expand Down
2 changes: 1 addition & 1 deletion ffapi.gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
loom.platform=neoforge
fabric.loom.dontRemap=true

implementationVersion=2.0.0
implementationVersion=2.0.1

versionMc=1.21
versionForge=21.0.57-beta
Expand Down

0 comments on commit d772734

Please sign in to comment.