Commits

shemnon committed 1813559

move cssToBin to use PackagerLib directly

Comments (0)

Files changed (3)

plugin/build.gradle

 apply plugin: 'maven'
 
 group = 'com.bitbucket.shemnon.javafxplugin'
-version = '0.0.1-SNAPSHOT'
+version = '0.1.0-SNAPSHOT'
 
 repositories {
     mavenCentral()

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

                 description: "Converts CSS to Binary CSS.",
                 group: 'Build')
 
-        task.conventionMapping.antJavaFXJar = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).antJavaFXJar }
-        task.conventionMapping.jfxrtJar = {convention, aware -> convention.getPlugin(JavaFXPluginConvention).jfxrtJar }
-
         task.conventionMapping.distsDir = {convention, aware -> convention.getPlugin(JavaPluginConvention).sourceSets.main.output.resourcesDir}
 
         task.conventionMapping.inputFiles = {convention, aware ->
-            project.fileTree(dir: convention.getPlugin(JavaPluginConvention).sourceSets.main.output.resourcesDir, include: '**/*.css')
+            convention.getPlugin(JavaPluginConvention).sourceSets.main.resources
         }
 
         project.tasks.getByName("classes").dependsOn(task)

plugin/src/main/groovy/com/bitbucket/shemnon/javafxplugin/tasks/JavaFXCSSToBinTask.groovy

  *   (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.tasks;
+package com.bitbucket.shemnon.javafxplugin.tasks
 
-
-import org.gradle.api.file.FileCollection
+import com.sun.javafx.tools.packager.CreateBSSParams
+import com.sun.javafx.tools.packager.PackagerLib
+import org.gradle.api.file.FileVisitDetails
+import org.gradle.api.file.FileVisitor
+import org.gradle.api.file.SourceDirectorySet
 import org.gradle.api.internal.ConventionTask
+import org.gradle.api.internal.file.collections.DirectoryFileTree
 import org.gradle.api.tasks.InputFiles
 import org.gradle.api.tasks.OutputDirectory
 import org.gradle.api.tasks.TaskAction
 
     @TaskAction
     processResources() {
-        ant.taskdef(name: 'csstobin',
-                classname: 'com.sun.javafx.tools.ant.CSSToBinTask',
-                classpath: (getAntJavaFXJar() + getJfxrtJar()).asPath)
-
-        ant.csstobin(
-                outDir: getDistsDir()
-        ) {
-            getInputFiles().addToAntBuilder(ant, "fileset", FileCollection.AntType.FileSet)
-        }
-    }
+        PackagerLib packager = new PackagerLib();
 
-    FileCollection antJavaFXJar
-    FileCollection jfxrtJar
+        CreateBSSParams bssParams = new CreateBSSParams();
+        getInputFiles().srcDirTrees.each { DirectoryFileTree dirTree ->
+            dirTree.visit new FileVisitor() {
+                @Override
+                void visitDir(FileVisitDetails fileVisitDetails) {
+                    // do nothing
+                }
 
+                @Override
+                void visitFile(FileVisitDetails fileVisitDetails) {
+                    File f = fileVisitDetails.getFile();
+                    if (f.getName().endsWith(".css")) {
+                        bssParams.addResource(dirTree.getDir(), f);
+                    }
+                }
+            }
+        }
+        bssParams.setOutdir(getDistsDir())
 
+        packager.generateBSS(bssParams)
+    }
 
     @InputFiles
-    FileCollection inputFiles
+    SourceDirectorySet inputFiles
 
     @OutputDirectory
     File distsDir