shemnon avatar shemnon committed 800809b

Change from a plugin convention to a Gradle Extension

Comments (0)

Files changed (3)

plugin/src/main/groovy/com/bitbucket/shemnon/javafxplugin/JavaFXPlugin.groovy

     @Override
     void apply(Project project) {
         project.getPlugins().apply(JavaPlugin)
+        project.extensions.create('javafx', JavaFXPluginExtension)
+
         configureConfigurations(project.configurations)
 
         def jfxrtJarFile = project.files(findJFXJar())
-        project.convention.plugins.javafx = new JavaFXPluginConvention(project, {
-                jfxrtJar = jfxrtJarFile
-                antJavaFXJar = project.files(findAntJavaFXJar())
-                mainClass = "${project.group}${(project.group&&project.name)?'.':''}${project.name}${(project.group||project.name)?'.':''}Main"
-                appName = project.name //FIXME capatalize
-                packaging = 'all'
-                debugKey {
-                    alias = 'javafxdebugkey'
-                    keyPass = 'JavaFX'
-                    keyStore = new File(project.projectDir, 'debug.keyStore')
-                    storePass = 'JavaFX'
-                }
-                signingMode = 'debug'
-            })
+        project.javafx {
+            jfxrtJar = jfxrtJarFile
+            antJavaFXJar = project.files(findAntJavaFXJar())
+            mainClass = "${project.group}${(project.group&&project.name)?'.':''}${project.name}${(project.group||project.name)?'.':''}Main"
+            appName = project.name //FIXME capatalize
+            packaging = 'all'
+            debugKey {
+                alias = 'javafxdebugkey'
+                keyPass = 'JavaFX'
+                keyStore = new File(project.projectDir, 'debug.keyStore')
+                storePass = 'JavaFX'
+            }
+            signingMode = 'debug'
+        }
 
 
         project.dependencies {
                 description: "Jars up the classes and adds JavaFX specific packaging.",
                 group: 'Build')
 
-        task.conventionMapping.mainClass = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).mainClass }
+        task.conventionMapping.mainClass = {convention, aware -> project.javafx.mainClass }
 
         task.conventionMapping.outputDirectory = {convention, aware ->
             "$project.libsDir" as File}
                 description: "Generates the JAvaFX Debug Key.",
                 group: 'Build')
 
-        task.conventionMapping.alias     = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).debugKey.alias }
-        task.conventionMapping.keyPass   = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).debugKey.keyPass }
-        task.conventionMapping.keyStore  = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).debugKey.keyStore }
-        task.conventionMapping.storePass = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).debugKey.storePass }
-        task.conventionMapping.storeType = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).debugKey.storeType }
+        task.conventionMapping.alias     = {convention, aware -> project.javafx.debugKey.alias }
+        task.conventionMapping.keyPass   = {convention, aware -> project.javafx.debugKey.keyPass }
+        task.conventionMapping.keyStore  = {convention, aware -> project.javafx.debugKey.keyStore }
+        task.conventionMapping.storePass = {convention, aware -> project.javafx.debugKey.storePass }
+        task.conventionMapping.storeType = {convention, aware -> project.javafx.debugKey.storeType }
         task.conventionMapping.dname     = {convention, aware -> 'CN=JavaFX Gradle Plugin Default Debug Key, O=JavaFX Debug' }
         task.conventionMapping.validity  = {convention, aware -> ((365.25) * 25 as int) /* 25 years */ }
     }
 
         ['alias', 'keyPass', 'storePass', 'storeType'].each { prop ->
             task.conventionMapping[prop]  = {convention, aware ->
-                def jfxc = convention.getPlugin(JavaFXPluginConvention);
+                def jfxc = project.javafx;
                 def props = project.properties
                 def mode = props['javafx.signingMode']  ?: jfxc.signingMode
                 return props?."javafx.${mode}Key.$prop" ?: jfxc?."${mode}Key"?."$prop"
             }
         }
         task.conventionMapping.keyStore  = {convention, aware ->
-            def jfxc = convention.getPlugin(JavaFXPluginConvention);
+            def jfxc = project.javafx;
             def props = project.properties
             def mode = props['javafx.signingMode']  ?: jfxc.signingMode
             String keyFile = props?."javafx.${mode}Key.keyStore"
                 description: "Processes the JavaFX jars and generates webstart and native packages.",
                 group: 'Build')
 
-        task.conventionMapping.packaging = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).packaging }
+        task.conventionMapping.packaging = {convention, aware -> project.javafx.packaging }
 
         task.conventionMapping.antJavaFXJar = {convention, aware ->
-            convention.getPlugin(JavaFXPluginConvention).antJavaFXJar }
+            project.javafx.antJavaFXJar }
 
-        task.conventionMapping.appID = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).appID }
-        task.conventionMapping.appName = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).appName }
-        task.conventionMapping.mainClass = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).mainClass }
+        task.conventionMapping.appID = {convention, aware -> project.javafx.appID }
+        task.conventionMapping.appName = {convention, aware -> project.javafx.appName }
+        task.conventionMapping.mainClass = {convention, aware -> project.javafx.mainClass }
 
 
         task.conventionMapping.inputFiles = {convention, aware ->
             project.fileTree("$project.libsDir/../signed").include("*.jar")
         }
 
-        task.conventionMapping.distsDir = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).distsDir }
+        task.conventionMapping.distsDir = {convention, aware -> project.distsDir }
 
         task.dependsOn(project.tasks.getByName("jfxSignJar"))
         project.tasks.getByName("assemble").dependsOn(task)
             group: 'Execution')
 
         task.classpath = project.sourceSets.main.runtimeClasspath
-        task.conventionMapping.main = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).mainClass }
+        task.conventionMapping.main = {convention, aware -> project.javafx.mainClass }
     }
 
     private void configureDebugTask(Project project) {
             group: 'Execution')
 
         task.classpath = project.sourceSets.main.runtimeClasspath
-        task.conventionMapping.main = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).mainClass }
+        task.conventionMapping.main = {convention, aware -> project.javafx.mainClass }
         task.debug = true
     }
 

plugin/src/main/groovy/com/bitbucket/shemnon/javafxplugin/JavaFXPluginConvention.groovy

-/*
- * Copyright (c) 2012, Danno Ferrin
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions are met:
- *       * Redistributions of source code must retain the above copyright
- *         notice, this list of conditions and the following disclaimer.
- *       * Redistributions in binary form must reproduce the above copyright
- *         notice, this list of conditions and the following disclaimer in the
- *         documentation and/or other materials provided with the distribution.
- *       * Neither the name of Danno Ferrin nor the
- *         names of contributors may be used to endorse or promote products
- *         derived from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- *   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *   DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
- *   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- *   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- *   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.bitbucket.shemnon.javafxplugin
-
-import org.gradle.util.ConfigureUtil
-import org.gradle.api.file.FileCollection
-import org.gradle.api.plugins.BasePluginConvention
-import org.gradle.api.Project
-
-class JavaFXPluginConvention extends BasePluginConvention {
-
-    // preliminaries
-    FileCollection jfxrtJar
-    FileCollection antJavaFXJar
-
-    // build steps
-    SigningKeyInfo debugKey
-    SigningKeyInfo releaseKey
-
-    String signingMode
-
-    // app info
-    String appID
-    String appName
-    String mainClass
-
-    String packaging
-
-    // results
-    public JavaFXPluginConvention(Project newProject, Closure configure) {
-        super(newProject)
-        ConfigureUtil.configure(configure, this)
-    }
-
-    public debugKey(Closure closure) {
-        debugKey = new SigningKeyInfo(closure)
-    }
-
-    public releaseKey(Closure closure) {
-        releaseKey = new SigningKeyInfo(closure)
-    }
-
-    def javafx(Closure closure) {
-        closure.delegate = this
-        closure()
-    }
-
-}
-
-class SigningKeyInfo {
-    String alias
-    String keyPass
-    File keyStore
-    String storePass
-    String storeType
-
-
-    public SigningKeyInfo(Closure configure) {
-        ConfigureUtil.configure(configure, this)
-    }
-
-    //TODO logic methods
-    //   - determine if a key exists
-    //   - load stuff like validity and dname from existing key
-    //   - prompt for password if set to null on a read
-}

plugin/src/main/groovy/com/bitbucket/shemnon/javafxplugin/JavaFXPluginExtension.groovy

+/*
+ * Copyright (c) 2012, Danno Ferrin
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions are met:
+ *       * Redistributions of source code must retain the above copyright
+ *         notice, this list of conditions and the following disclaimer.
+ *       * Redistributions in binary form must reproduce the above copyright
+ *         notice, this list of conditions and the following disclaimer in the
+ *         documentation and/or other materials provided with the distribution.
+ *       * Neither the name of Danno Ferrin nor the
+ *         names of contributors may be used to endorse or promote products
+ *         derived from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ *   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *   DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ *   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ *   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ *   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.bitbucket.shemnon.javafxplugin
+
+import org.gradle.util.ConfigureUtil
+import org.gradle.api.file.FileCollection
+import org.gradle.api.plugins.BasePluginConvention
+import org.gradle.api.Project
+
+class JavaFXPluginExtension { //extends BasePluginConvention {
+
+    // preliminaries
+    FileCollection jfxrtJar
+    FileCollection antJavaFXJar
+
+    // build steps
+    SigningKeyInfo debugKey
+    SigningKeyInfo releaseKey
+
+    String signingMode
+
+    // app info
+    String appID
+    String appName
+    String mainClass
+
+    String packaging
+
+    public debugKey(Closure closure) {
+        debugKey = new SigningKeyInfo(closure)
+    }
+
+    public releaseKey(Closure closure) {
+        releaseKey = new SigningKeyInfo(closure)
+    }
+
+
+}
+
+class SigningKeyInfo {
+    String alias
+    String keyPass
+    File keyStore
+    String storePass
+    String storeType
+
+
+    public SigningKeyInfo(Closure configure) {
+        ConfigureUtil.configure(configure, this)
+    }
+
+    //TODO logic methods
+    //   - determine if a key exists
+    //   - load stuff like validity and dname from existing key
+    //   - prompt for password if set to null on a read
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.