Commits

shemnon committed 24a7c26

provide platform specific overrides

Comments (0)

Files changed (3)

gradle-javafx-plugin/src/main/groovy/org/bitbucket/shemnon/javafxplugin/JavaFXPlugin.groovy

 
     private Project project
 
+    protected basicExtensionMapping = {prop, convention = null, aware = null ->
+        JavaFXPluginExtension ext = project.javafx;
+        JavaFXPluginExtension override = ext.getCurrentOverride();
+        def val = override == null ? null : override[prop]
+        return val ?: ext[prop]
+    }
+
+
     @Override
     void apply(Project project) {
         this.project = project
             project.configurations.archives.artifacts*.builtBy task
         }
 
-        task.conventionMapping.mainClass = {convention, aware -> project.javafx.mainClass }
-        task.conventionMapping.embedLauncher = {convention, aware -> project.javafx.embedLauncher }
-        task.conventionMapping.arguments = {convention, aware -> project.javafx.arguments}
+        [
+                'mainClass',
+                'embedLauncher',
+                'arguments'
+        ].each {prop -> task.conventionMapping[prop] = basicExtensionMapping.curry(prop) }
 
         task.conventionMapping.jarFile = {convention, aware ->
             project.tasks.getByName("jar").archivePath
                 'updateMode',
                 'vendor',
                 'width',
-        ].each {prop ->
-            task.conventionMapping[prop] = {convention, aware -> project.javafx[prop] }
+        ].each {prop -> task.conventionMapping[prop] = basicExtensionMapping.curry(prop) }
 
-        }
         // version is special
         task.conventionMapping.version = {convention, aware -> ('unspecified' == project.version) ? '0.0.0' : project.version }
 
             description: 'Runs the application.',
             group: 'Execution')
 
+        configureRunParams(project, task)
+    }
+
+    protected void configureRunParams(Project project, JavaExec task) {
         task.classpath = project.sourceSets.main.runtimeClasspath
-        task.conventionMapping.main = {convention, aware -> project.javafx.mainClass }
+        task.conventionMapping.main = basicExtensionMapping.curry('mainClass')
         task.doFirst {
-            task.jvmArgs project.javafx.jvmArgs
-            task.systemProperties project.javafx.systemProperties
-            if (!task.args) task.args = project.javafx.arguments
+            task.jvmArgs basicExtensionMapping('jvmArgs')
+            task.systemProperties basicExtensionMapping('systemProperties')
+            if (!task.args) task.args = basicExtensionMapping('arguments')
         }
     }
 
             description: 'Runs the applicaiton and sets up debugging on port 5005.',
             group: 'Execution')
 
-        task.classpath = project.sourceSets.main.runtimeClasspath
-        task.conventionMapping.main = {convention, aware -> project.javafx.mainClass }
-        task.doFirst {
-            task.jvmArgs project.javafx.jvmArgs
-            task.systemProperties project.javafx.systemProperties
-            if (!task.args) task.args = project.javafx.arguments
-        }
+        configureRunParams(project, task)
         task.debug = true
     }
 

gradle-javafx-plugin/src/main/groovy/org/bitbucket/shemnon/javafxplugin/JavaFXPluginExtension.groovy

 package org.bitbucket.shemnon.javafxplugin
 
 import com.sun.javafx.tools.packager.DeployParams
+import org.gradle.internal.os.OperatingSystem
 import org.gradle.util.ConfigureUtil
 import org.gradle.api.file.FileCollection
 
 
 class JavaFXPluginExtension { //extends BasePluginConvention {
 
+    protected Map<String, JavaFXPluginExtension> overrides = [:]
+
     // preliminaries
     FileCollection jfxrtJar
     FileCollection antJavaFXJar
         }
     }
 
+    def windows(Closure closure) {
+        if (!overrides.containsKey('windows')) {
+             overrides.windows = new JavaFXPluginExtension()
+        }
+        ConfigureUtil.configure(closure, overrides.windows)
+    }
+
+    def macosx(Closure closure) {
+        if (!overrides.containsKey('macosx')) {
+             overrides.macosx = new JavaFXPluginExtension()
+        }
+        ConfigureUtil.configure(closure, overrides.macosx)
+    }
+
+    def linux(Closure closure) {
+        if (!overrides.containsKey('linux')) {
+             overrides.linux = new JavaFXPluginExtension()
+        }
+        ConfigureUtil.configure(closure, overrides.linux)
+    }
+
+    JavaFXPluginExtension getCurrentOverride() {
+        def currentOS = OperatingSystem.current();
+        if (currentOS.isWindows()) {
+            return overrides['windows']
+        }
+        if (currentOS.isLinux()) {
+            return overrides['linux']
+        }
+        if (currentOS.isMacOsX()) {
+            return overrides['macosx']
+        }
+
+        return null;
+    }
+
+    JavaFXPluginExtension getOverride(String os) {
+      return overrides.get(os)
+    }
+
     protected void addIcon(String kind, String href) {
         IconInfo ii = new IconInfo(href)
         ii.kind = kind

samples/Ensemble2/build.gradle

         volume = shortcut
         setup = 'icon-32.png'
     }
+
+    windows {
+        appID = 'b533f663-1efd-489f-b910-4c7ec20c7fd0'
+    }
+
+    macosx {
+        category = 'public.app-category.developer-tools'
+    }
 }