Commits

shemnon committed 24116ec

Allow the plugin to use a source set other than main

  • Participants
  • Parent commits ff9d1b6

Comments (0)

Files changed (2)

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

     }
 
     private Project project
+    
+    @Lazy private SourceSet sourceSet = project.javafx.getSourceSet('sourceSet', project)
+    
     @Lazy private String[] profiles = ([] + project.getProperties().profiles?.split(',') + getOSProfileName()).flatten().findAll {
             project.javafx.getProfile(it) != null
         }
         configureDebugTask(project)
 
         def mains = []
-        project.convention.getPlugin(JavaPluginConvention).sourceSets[SourceSet.MAIN_SOURCE_SET_NAME].allJava.visit {
+        sourceSet.allJava.visit {
             if (it.relativePath.lastName == 'Main.java') {
                 mains.add(it.relativePath.replaceLastName('Main').pathString.replace('/', '.'))
             }
         task.description =  "Converts CSS to Binary CSS."
         task.group =  'Build'
 
-        task.conventionMapping.distsDir = {convention, aware -> convention.getPlugin(JavaPluginConvention).sourceSets.main.output.resourcesDir}
+        task.conventionMapping.distsDir = {convention, aware -> sourceSet.output.resourcesDir}
 
         task.conventionMapping.inputFiles = {convention, aware ->
-            convention.getPlugin(JavaPluginConvention).sourceSets.main.resources
+            sourceSet.resources
         }
 
         project.tasks.getByName("classes").dependsOn(task)
             project.tasks.getByName("jar").archivePath
         }
         task.conventionMapping.classpath = {convention, aware ->
-            FileCollection compileClasspath = project.convention.getPlugin(JavaPluginConvention).sourceSets[SourceSet.MAIN_SOURCE_SET_NAME].compileClasspath;
+            FileCollection compileClasspath = sourceSet.compileClasspath;
             Configuration providedCompile = project.configurations[PROVIDED_COMPILE_CONFIGURATION_NAME];
             return compileClasspath - providedCompile;
         }
         task.conventionMapping.outdir = {convention, aware -> project.libsDir}
 
         task.conventionMapping.inputFiles = {convention, aware ->
-            FileCollection runtimeClasspath = project.convention.getPlugin(JavaPluginConvention).sourceSets[SourceSet.MAIN_SOURCE_SET_NAME].runtimeClasspath;
+            FileCollection runtimeClasspath = sourceSet.runtimeClasspath;
             Configuration providedRuntime = project.configurations[PROVIDED_RUNTIME_CONFIGURATION_NAME];
             project.files(runtimeClasspath - providedRuntime, project.configurations.archives.artifacts.files.collect{it})
         }
         def task = project.tasks.replace("jfxCopyLibs")
 
         task.doLast {
-            FileCollection runtimeClasspath = project.convention.getPlugin(JavaPluginConvention).sourceSets[SourceSet.MAIN_SOURCE_SET_NAME].runtimeClasspath;
+            FileCollection runtimeClasspath = sourceSet.runtimeClasspath;
             Configuration providedRuntime = project.configurations[PROVIDED_RUNTIME_CONFIGURATION_NAME];
             project.files(runtimeClasspath - providedRuntime, project.configurations.archives.artifacts.files.collect{it}).
                     findAll {File f -> f.exists() && !f.directory}.
         task.description = 'Runs the application.'
         task.group = 'Execution'
 
-        configureRunParams(project, task)
+        configureRunParams(task)
     }
 
-    protected void configureRunParams(Project project, JavaExec task) {
-        task.classpath = project.sourceSets.main.runtimeClasspath
+    protected void configureRunParams(JavaExec task) {
+        task.classpath = sourceSet.runtimeClasspath
         task.conventionMapping.main = basicExtensionMapping.curry('mainClass')
         task.doFirst {
             task.jvmArgs basicExtensionMapping('jvmArgs')
         task.description = 'Runs the applicaiton and sets up debugging on port 5005.'
         task.group = 'Execution'
 
-        configureRunParams(project, task)
+        configureRunParams(task)
         task.debug = true
     }
 

File 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.api.Project
+import org.gradle.api.tasks.SourceSet
 import org.gradle.util.ConfigureUtil
 import org.gradle.api.file.FileCollection
 
     // preliminaries
     FileCollection jfxrtJar
     FileCollection antJavaFXJar
+    
+    // where do we get our source>
+    def sourceSet = 'main'
 
     // build steps
     SigningKeyInfo debugKey
         ii.kind = kind
         getIconInfos().add(ii)
     }
+    
+    protected getSourceSet(String propertyName, Project project) {
+        return resolveSourceSet(this[propertyName], project)
+    }
+    
+    protected resolveSourceSet(SourceSet sourceSet, Project project) {
+        return sourceSet
+    }
+    
+    protected resolveSourceSet(String sourceSet, Project project) {
+        return project.sourceSets[sourceSet]
+    }
 }
 
 class SigningKeyInfo {