Commits

shemnon committed 6787d20

switch to profiles closure instead of explicit os overrides.

Comments (0)

Files changed (3)

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

 import org.bitbucket.shemnon.javafxplugin.tasks.GenKeyTask
 import org.gradle.api.DefaultTask
 import org.gradle.api.artifacts.ResolvedArtifact
+import org.gradle.internal.os.OperatingSystem
 
 
 class JavaFXPlugin implements Plugin<Project> {
     public static final String PROVIDED_COMPILE_CONFIGURATION_NAME = "providedCompile";
     public static final String PROVIDED_RUNTIME_CONFIGURATION_NAME = "providedRuntime";
 
+    static String getOSProfileName() {
+        def currentOS = OperatingSystem.current();
+        if (currentOS.isWindows()) {
+            return 'windows'
+        }
+        if (currentOS.isLinux()) {
+            return 'linux'
+        }
+        if (currentOS.isMacOsX()) {
+            return 'macosx'
+        }
+
+        return null;
+    }
+
     private Project project
+    @Lazy private String[] profiles = ([] + project.getProperties().profiles?.split(',') + getOSProfileName()).flatten().findAll {
+            project.javafx.getProfile(it) != null
+        }
 
     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]
+        for (profile in profiles) {
+            JavaFXPluginExtension override = ext.getProfile(profile)
+            def val = override[prop]
+            if (val != null) {
+                return val;
+            }
+        }
+        return ext[prop]
     }
 
 

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
 
 
     public static final String NO_RUNTIME = '<NO RUNTIME>'
 
-    protected Map<String, JavaFXPluginExtension> overrides = [:]
+    protected Map<String, JavaFXPluginExtension> profileMap = [:]
 
     // preliminaries
     FileCollection jfxrtJar
         }
     }
 
-    def windows(Closure closure) {
-        if (!overrides.containsKey('windows')) {
-             overrides.windows = new JavaFXPluginExtension()
-        }
-        ConfigureUtil.configure(closure, overrides.windows)
+    def profiles(Closure closure) {
+        ConfigureUtil.configure(closure, new MethodToMap(map: profileMap))
     }
 
-    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)
+    JavaFXPluginExtension getProfile(String profile) {
+      return profileMap.get(profile)
     }
 
     protected void addIcon(String kind, String href) {
     }
 
 }
+
+class MethodToMap {
+
+    Map map
+
+    Object methodMissing(String name, args) {
+        if (args.length == 1 && args[0] instanceof Closure) {
+            map[name] = [:]
+            ConfigureUtil.configure(args[0], map[name])
+        } else {
+            throw new MissingMethodException(name, JavaFXPluginExtension.class, args, false);
+        }
+    }
+}

samples/FullyExpressed/build.gradle

 
 javafx {
 
+    profiles {
     // not every possible platform override, but ones that have a known impact
-    windows {
-        id = 'c533f663-1efd-489f-b910-4c7ec20c7fd0'
-        category = 'JavaFX Demos'
-        javaRuntime = 'C:/Program Files (x86)/Java/jdk1.7.0_21'
-    }
-
-    macosx {
-        id = 'net.java.openjdk.openjfx.Ensemble2'
-        category = 'public.app-category.developer-tools'
-        javaRuntime = '/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/'
-    }
-
-    linux {
-        // linux doesn't care about id, it goes un-used at the moment
-        category = 'Development'
-        javaRuntime = '/usr/lib/jvm/java-7-oracle'
+        windows {
+            id = 'c533f663-1efd-489f-b910-4c7ec20c7fd0'
+            category = 'JavaFX Demos'
+            javaRuntime = 'C:/Program Files (x86)/Java/jdk1.7.0_21'
+        }
+
+        macosx {
+            id = 'net.java.openjdk.openjfx.Ensemble2'
+            category = 'public.app-category.developer-tools'
+            javaRuntime = '/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/'
+        }
+
+        linux {
+            // linux doesn't care about id, it goes un-used at the moment
+            category = 'Development'
+            javaRuntime = '/usr/lib/jvm/java-7-oracle'
+        }
     }
 
     debugKey {