-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix component metadata rules trying to use classifiers
- Loading branch information
Showing
8 changed files
with
188 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...kotlin/net/msrandom/minecraftcodev/forge/MinecraftForgeComponentClassifierMetadataRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package net.msrandom.minecraftcodev.forge | ||
|
||
import org.gradle.api.artifacts.CacheableRule | ||
import org.gradle.api.artifacts.ComponentMetadataContext | ||
import org.gradle.api.artifacts.ComponentMetadataDetails | ||
import org.gradle.api.artifacts.ComponentMetadataRule | ||
import org.gradle.api.artifacts.repositories.RepositoryResourceAccessor | ||
import org.gradle.api.attributes.Attribute | ||
import org.gradle.api.attributes.Category | ||
import org.gradle.api.model.ObjectFactory | ||
import javax.inject.Inject | ||
|
||
@JvmField | ||
val CLASSIFIER_ATTRIBUTE: Attribute<String> = | ||
Attribute.of("net.msrandom.minecraftcodev.forge-library-classifier", String::class.java) | ||
|
||
@CacheableRule | ||
abstract class MinecraftForgeComponentClassifierMetadataRule @Inject constructor(private val userdevs: List<UserdevPath>) : | ||
ComponentMetadataRule { | ||
abstract val repositoryResourceAccessor: RepositoryResourceAccessor | ||
@Inject get | ||
|
||
private fun ComponentMetadataDetails.addClassifier(classifier: String) { | ||
withVariant("compile") { | ||
it.attributes.attribute(CLASSIFIER_ATTRIBUTE, "") | ||
} | ||
|
||
withVariant("runtime") { | ||
it.attributes.attribute(CLASSIFIER_ATTRIBUTE, "") | ||
} | ||
|
||
addVariant("${classifier}-compile", "compile") { | ||
it.attributes.attribute(CLASSIFIER_ATTRIBUTE, classifier) | ||
|
||
it.withFiles { | ||
it.removeAllFiles() | ||
|
||
it.addFile("${id.name}-${id.version}-$classifier.jar") | ||
} | ||
} | ||
|
||
addVariant("${classifier}-runtime", "runtime") { | ||
it.attributes.attribute(CLASSIFIER_ATTRIBUTE, classifier) | ||
|
||
it.withFiles { | ||
it.removeAllFiles() | ||
|
||
it.addFile("${id.name}-${id.version}-$classifier.jar") | ||
} | ||
} | ||
} | ||
|
||
override fun execute(context: ComponentMetadataContext) { | ||
val id = context.details.id | ||
|
||
val currentUserdev = userdevs.firstOrNull { | ||
it.group == id.group && it.name == id.name && it.version == id.version | ||
} | ||
|
||
if (currentUserdev != null) { | ||
context.details.addClassifier(currentUserdev.classifier) | ||
} | ||
|
||
val userdevLibraries = userdevs.flatMapTo(hashSetOf()) { | ||
getUserdev(it, repositoryResourceAccessor)?.libraries ?: emptyList() | ||
} | ||
|
||
val library = userdevLibraries.firstOrNull { "${id.group}:${id.name}:${id.version}" in it } ?: return | ||
|
||
val classifier = getClassifier(library) | ||
|
||
if (classifier != null) { | ||
context.details.addClassifier(classifier) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.