Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component rule for JavaFX components #57

Closed
jjohannes opened this issue Aug 15, 2023 · 6 comments
Closed

Component rule for JavaFX components #57

jjohannes opened this issue Aug 15, 2023 · 6 comments
Labels
wontfix This will not be worked on

Comments

@jjohannes
Copy link
Member

JavaFX published OS/Arch specific Jars with classifiers. Would be great to add the corresponding variants with attributes, like in this example:
https://docs.gradle.org/current/userguide/component_metadata_rules.html#adding_variants_for_native_jars

Then it's straight forward to consume without using a JavaFX specific plugin or anything like that.

The rule looks roughly like this (need to double check OS/Arch values):

@CacheableRule
abstract class JavaFXMetadataRules : ComponentMetadataRule {
    data class NativeVariant(val os: String, val arch: String, val classifier: String)

    private val nativeVariants = listOf(
        NativeVariant(LINUX,   "x86-64",  "linux"),
        NativeVariant(LINUX,   "aarch64",  "linux-aarch64"),
        NativeVariant(LINUX,   "aarch64-monocle",  "linux-aarch64-monocle"),
        NativeVariant(LINUX,   "arm32-monocle",  "linux-arm32-monocle"),
        NativeVariant(LINUX,   "monocle",  "linux-monocle"),
        NativeVariant(MACOS,   "x86-64", "mac"),
        NativeVariant(MACOS,   "aarch64", "mac-aarch64"),
        NativeVariant(MACOS,   "monocle", "mac-monocle"),
        NativeVariant(MACOS,   "aarch64-monocle", "mac-aarch64-monocle"),
        NativeVariant(WINDOWS, "x86-64", "win"),
        NativeVariant(WINDOWS, "monocle", "win-monocle"),
        NativeVariant(WINDOWS, "x86", "win-x86"),
        NativeVariant(WINDOWS, "x86-monocle", "win-x86-monocle"),
    )

    @get:Inject
    abstract val objects: ObjectFactory

    override fun execute(context: ComponentMetadataContext) {
        nativeVariants.forEach { variantDefinition ->
            val name = context.details.id.name
            val version = context.details.id.version

            context.details.addVariant("${variantDefinition.classifier}Compile", "compile") {
                attributes {
                    attributes.attribute(OPERATING_SYSTEM_ATTRIBUTE, objects.named(variantDefinition.os))
                    attributes.attribute(ARCHITECTURE_ATTRIBUTE, objects.named(variantDefinition.arch))
                }
                withFiles {
                    removeAllFiles()
                    addFile("${name}-${version}-${variantDefinition.classifier}.jar")
                }
            }
            context.details.addVariant("${variantDefinition.classifier}Runtime", "runtime") {
                attributes {
                    attributes.attribute(OPERATING_SYSTEM_ATTRIBUTE, objects.named(variantDefinition.os))
                    attributes.attribute(ARCHITECTURE_ATTRIBUTE, objects.named(variantDefinition.arch))
                }
                withFiles {
                    removeAllFiles()
                    addFile("${name}-${version}-${variantDefinition.classifier}.jar")
                }
            }
        }
    }
} 
@jjohannes jjohannes added the a:rule One or more metadata rules that should be added or updated label Aug 15, 2023
@nlisker
Copy link

nlisker commented Aug 25, 2023

Is this something the maintainers of JavaFX need to do?

@jjohannes
Copy link
Member Author

jjohannes commented Aug 25, 2023

Is this something the maintainers of JavaFX need to do?

Eventually yes. JavaFX could publish Gradle Metadata with the information I have sketched in this issue. Then Gradle users can depend on JavaFX components (or libraries building on top of JavaFX) without additional plugins and select the "JavaFX Platform Variant" by using the OPERATING_SYSTEM_ATTRIBUTE and ARCHITECTURE_ATTRIBUTE attributes.

I now think a good start would be to add the rule to the official JavaFX plugin and have that use the attributes as well internally. Then the metadata publishing in JavaFX itself could be proposed as a next step.

I made a proposal: openjfx/javafx-gradle-plugin#151

@nlisker
Copy link

nlisker commented Aug 26, 2023

@johanvos Can you have a look?

@johanvos
Copy link

johanvos commented Sep 2, 2023

Thanks @jjohannes and @nlisker . openjfx/javafx-gradle-plugin#151 is merged. A potential next step is to see if we should do this in the openjfx repository itself.

@jjohannes
Copy link
Member Author

jjohannes commented Sep 5, 2023

This is too interesting to not look at for me. 😄

I had a look at the JavaFX build and something like this should work: openjdk/jfx#1232

@jjohannes
Copy link
Member Author

Closing as this rule has been directly added to org.openjfx.javafxplugin version 0.1.0 - (openjfx/javafx-gradle-plugin#151) and Gradle metadata might potentially be published by JavaFX at some point in the future (openjdk/jfx#1232).

@jjohannes jjohannes removed the a:rule One or more metadata rules that should be added or updated label Sep 19, 2023
@jjohannes jjohannes added the wontfix This will not be worked on label Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants