Commits

Meikel Brandmeyer committed 3643e13

Rename the project to clojuresque. Much nicer than clj-gradle.

Comments (0)

Files changed (11)

-# clj-gradle – a Clojure plugin for Gradle
+# clojuresque – a Clojure plugin for Gradle
 
 ## What is Gradle?
 
 (if followed) automasie 95% of the build completely. Still the conventions
 are freely configurable to be adapted to different project structures.
 
-## What is clj-gradle?
+## What is clojuresque?
 
-[clj-gradle][cg] is now a plugin for [Gradle][], which adds [Clojure][clj]
+[clojuresque][cg] is now a plugin for [Gradle][], which adds [Clojure][clj]
 support. It allows compilation with automatic namespace recognition. The
 plugin is based on the Java plugin and hooks into the standard configurations
 and archives.
 ## Getting started
 
 Create a sandbox directory. Add a subdirectory `lib` and put the `clojure.jar`
-as well as the `clj-gradle.jar` there. Create some test namespace in
+as well as the `clojuresque.jar` there. Create some test namespace in
 `src/main/clojure/test/example.clj`:
 
     (ns test.example
             flatDir name: 'lib', dirs: 'lib'
         }
         dependencies {
-            classpath name: 'clj-gradle'
+            classpath name: 'clojuresque'
         }
     }
     
     
     configurations {
         compileOnly {
-            setVisible(false)
-            setTransitive(false)
+            visible = false
+            transitive = false
         }
         compile.extendsFrom(compileOnly)
     }
     
     dependencies {
-        compileOnly name: 'clj-gradle'
+        compileOnly name: 'clojuresque'
         compile name: 'clojure'
     }
 
 logic itself.
 
 Next we define the repositories and dependencies for the project being
-build. Since we need the `ClojureCompile` class from the `clj-gradle.jar`
+build. Since we need the `ClojureCompile` class from the `clojuresque.jar`
 in the classpath for compilation we introduce a special `compileOnly`
 configuration. It's private the finally deployed archives of the project
 won't depend on it at runtime. Additionally we add a dependency on the
 
 -- 
 Meikel Brandmeyer <mb@kotka.de>
-Frankfurt am Main, October 2009
+Frankfurt am Main, November 2009
 
 [Gradle]: http://www.gradle.org
 [Groovy]: http://groovy.codehaus.org
 [clj]:    http://clojure.org
-[cg]:     http://bitbucket.org/kotarak/clj-gradle
+[cg]:     http://bitbucket.org/kotarak/clojuresque

src/main/groovy/clojuresque/ClojureCompileTask.groovy

+/*-
+ * Copyright 2009 © Meikel Brandmeyer.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+package clojuresque
+
+import org.gradle.api.Action
+import org.gradle.api.file.FileCollection
+import org.gradle.api.file.FileTree
+import org.gradle.api.tasks.SourceTask
+
+import org.apache.tools.ant.Project
+import org.apache.tools.ant.taskdefs.Java
+import org.apache.tools.ant.types.Environment
+import org.apache.tools.ant.types.Path
+
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import java.io.File
+import java.util.Set
+
+public class ClojureCompileTask extends SourceTask {
+    private static Logger logger = LoggerFactory.getLogger(ClojureCompileTask)
+
+    private ClojureSourceSet sourceSet
+    private File destinationDir
+    private FileCollection classpath
+
+    public ClojureCompileTask() {
+        super()
+        initialise()
+    }
+
+    public ClojureCompileTask(org.gradle.api.Project project, String string) {
+        super()
+        initialise()
+    }
+
+    private void initialise() {
+        def action = [ execute: { ClojureCompileTask task ->
+            boolean warnOnReflection = task.sourceSet.warnOnReflection
+            Set<File> sourceDirs = task.sourceSet.srcDirs
+            File destDir = task.destinationDir
+            FileTree source = task.source
+            FileCollection cp = task.classpath
+
+            Map args = [
+                classname:    'clojuresque.ClojureCompile',
+                failOnError:  true,
+                fork:         true,
+                classpathref: 'compile.classpath'
+            ]
+
+            ant.path(id: 'compile.classpath') {
+                sourceDirs.each {
+                    logger.debug("Add {} (source dir) to Ant classpath!", it)
+                    pathelement(location: it)
+                }
+
+                logger.debug("Add {} (dest dir) to Ant classpath!",
+                    destDir.path)
+                pathelement(location: destDir.path)
+
+                cp.each {
+                    logger.debug("Add {} to Ant classpath!", it)
+                    pathelement(location: it)
+                }
+            }
+
+            destDir.mkdirs()
+
+            ant.java(args) {
+                sysproperty(key: "clojure.compile.path", value: destDir)
+                sysproperty(key: "clojure.compile.warn-on-reflection",
+                    value: warnOnReflection)
+                source.each {
+                    arg(value: it)
+                }
+            }
+        } ] as Action
+
+        this.doLast(action)
+    }
+
+    public ClojureSourceSet getSourceSet() {
+        return sourceSet
+    }
+
+    public void setSourceSet(ClojureSourceSet set) {
+        sourceSet = set
+    }
+
+    public File getDestinationDir() {
+        return destinationDir
+    }
+
+    public void setDestinationDir(File dir) {
+        destinationDir = dir
+    }
+
+    public FileCollection getClasspath() {
+        return classpath
+    }
+
+    public void setClasspath(FileCollection path) {
+        classpath = path
+    }
+
+    public void addCommandLineArgument(Java java, File f) {
+        java.createArg().setFile(f)
+    }
+
+    public void addCommandLineArgument(Java java, String s) {
+        java.createArg().setValue(s)
+    }
+
+    public void addProperty(Java java, String k, File f) {
+        Environment.Variable v = new Environment.Variable()
+        v.setKey(k)
+        v.setFile(f)
+        java.addSysproperty(v)
+    }
+
+    public void addProperty(Java java, String k, String s) {
+        Environment.Variable v = new Environment.Variable()
+        v.setKey(k)
+        v.setValue(s)
+        java.addSysproperty(v)
+    }
+}

src/main/groovy/clojuresque/ClojurePlugin.groovy

+/*-
+ * Copyright 2009 © Meikel Brandmeyer.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+package clojuresque
+
+import org.gradle.api.Action
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.artifacts.Configuration
+import org.gradle.api.internal.ConventionMapping
+import org.gradle.api.internal.IConventionAware
+import org.gradle.api.internal.project.ProjectInternal
+import org.gradle.api.internal.tasks.DefaultSourceSet
+import org.gradle.api.tasks.SourceSet
+import org.gradle.api.plugins.Convention
+import org.gradle.api.plugins.JavaPlugin
+import org.gradle.api.plugins.JavaPluginConvention
+import org.gradle.api.plugins.ProjectPluginsContainer
+import org.gradle.api.tasks.ConventionValue
+
+public class ClojurePlugin implements Plugin {
+    public void use(Project project, ProjectPluginsContainer handler) {
+        JavaPlugin javaPlugin = handler.usePlugin(JavaPlugin.class, project)
+        configureCompileDefaults(project)
+        configureSourceSetDefaults(project, javaPlugin)
+    }
+
+    private JavaPluginConvention javaConvention(Convention convention) {
+        return convetion.getPlugin(JavaPluginConvention.class)
+    }
+
+    private SourceSet mainSourceSet(Convention convention) {
+        return javaConvention(convention)
+            .sourceSets[SourceSet.MAIN_SOURCE_SET_NAME]
+    }
+
+    private ClojureSourceSet mainClojureSourceSet(Convention convention) {
+        return mainSourceSet(convention)
+            .convention.getPlugin(ClojureSourceSet.class)
+    }
+
+    private configureCompileDefaults(Project project) {
+        def dsValue = [ getValue: { Convention convention,
+                IConventionAware object ->
+            return mainClojureSourceSet(convention).clojure
+        } ] as ConventionValue
+
+        def action = [ execute: { ClojureCompileTask task ->
+            task.conventionMapping.map("defaultSource", dsValue)
+        } ] as Action
+
+        project.tasks.withType(ClojureCompileTask.class).allTasks(action)
+    }
+
+    private configureSourceSet(DefaultSourceSet sourceSet,
+            Project project, JavaPlugin javaPlugin) {
+        ProjectInternal projectInternal = (ProjectInternal)project
+        String srcDir = String.format("src/%s/clojure", sourceSet.name)
+
+        DefaultClojureSourceSet clojureSourceSet =
+            new DefaultClojureSourceSet(sourceSet.displayName,
+                projectInternal.fileResolver)
+        sourceSet.convention.plugins["clojure"] = clojureSourceSet
+        clojureSourceSet.clojure.srcDir(srcDir)
+        sourceSet.resources.filter.exclude("**/*.clj")
+        sourceSet.allSource.add(clojureSourceSet.clojure)
+
+        String compileTaskName = sourceSet.getCompileTaskName("clojure")
+        ClojureCompileTask task = project.tasks.add(compileTaskName,
+                ClojureCompileTask.class)
+        task.sourceSet = clojureSourceSet
+        task.description = String.format("Compile the %s Clojure source.",
+                sourceSet.name)
+
+        ConventionMapping convMap = task.conventionMapping
+
+        def dsValue = [ getValue: { Convention c, IConventionAware o ->
+            return clojureSourceSet.clojure
+        } ] as ConventionValue
+        convMap.map("defaultSource", dsValue)
+
+        def cpValue = [ getValue: { Convention c, IConventionAware o ->
+            return sourceSet.compileClasspath
+        } ] as ConventionValue
+        convMap.map("classpath", cpValue)
+
+        def ddValue = [ getValue: { Convention c, IConventionAware o ->
+            return sourceSet.classesDir
+        } ] as ConventionValue
+        convMap.map("destinationDir", ddValue)
+
+        project.tasks[sourceSet.classesTaskName].dependsOn(compileTaskName)
+    }
+
+    private void configureSourceSetDefaults(Project project,
+            JavaPlugin javaPlugin) {
+        def action = [ execute: { SourceSet sourceSet ->
+            configureSourceSet(sourceSet, project, javaPlugin)
+        } ] as Action
+
+        project.convention.getPlugin(JavaPluginConvention.class)
+            .sourceSets.allObjects(action)
+    }
+}
+

src/main/groovy/clojuresque/ClojureSourceSet.groovy

+/*-
+ * Copyright 2009 © Meikel Brandmeyer.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+package clojuresque
+
+import org.gradle.api.file.SourceDirectorySet
+import org.gradle.api.file.FileTree
+
+import groovy.lang.Closure
+
+import java.io.File
+import java.util.Set
+
+public interface ClojureSourceSet {
+    public SourceDirectorySet getClojure()
+    public ClojureSourceSet clojure(Closure closure)
+    public FileTree getAllClojure()
+    public Set<File> getSrcDirs()
+    public boolean getWarnOnReflection()
+    public void setWarnOnReflection(boolean flag)
+}

src/main/groovy/clojuresque/DefaultClojureSourceSet.groovy

+/*-
+ * Copyright 2009 © Meikel Brandmeyer.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+package clojuresque
+
+import org.gradle.api.file.FileTree
+import org.gradle.api.tasks.SourceSet
+import org.gradle.api.tasks.util.PatternSet
+import org.gradle.api.internal.file.DefaultSourceDirectorySet
+import org.gradle.api.internal.file.FileResolver
+import org.gradle.api.internal.file.UnionFileTree
+import org.gradle.util.ConfigureUtil
+
+import groovy.lang.Closure
+
+import java.io.File
+import java.util.Set
+
+public class DefaultClojureSourceSet implements ClojureSourceSet {
+    private DefaultSourceDirectorySet clojure
+    private PatternSet clojurePatterns
+    private UnionFileTree allClojure
+    private boolean warnOnReflection
+
+    public DefaultClojureSourceSet(String displayName,
+            FileResolver fileResolver) {
+        String desc = String.format("%s Clojure source", displayName)
+
+        clojure = new DefaultSourceDirectorySet(desc, fileResolver)
+        clojure.filter.include("**/*.clj")
+
+        clojurePatterns = new PatternSet()
+        clojurePatterns.include("**/*.clj")
+
+        allClojure = new UnionFileTree(desc, clojure.matching(clojurePatterns))
+
+        warnOnReflection = false
+    }
+
+    public DefaultSourceDirectorySet getClojure() {
+        return clojure
+    }
+
+    public ClojureSourceSet clojure(Closure closure) {
+        ConfigureUtil.configure(closure, getClojure())
+        return this
+    }
+
+    public FileTree getAllClojure() {
+        return allClojure
+    }
+
+    public Set<File> getSrcDirs() {
+        return clojure.srcDirs
+    }
+
+    public boolean getWarnOnReflection() {
+        return warnOnReflection
+    }
+
+    public void setWarnOnReflection(boolean flag) {
+        warnOnReflection = flag
+    }
+}

src/main/groovy/de/kotka/gradle/ClojureCompileTask.groovy

-/*-
- * Copyright 2009 © Meikel Brandmeyer.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-package de.kotka.gradle
-
-import org.gradle.api.Action
-import org.gradle.api.file.FileCollection
-import org.gradle.api.file.FileTree
-import org.gradle.api.tasks.SourceTask
-
-import org.apache.tools.ant.Project
-import org.apache.tools.ant.taskdefs.Java
-import org.apache.tools.ant.types.Environment
-import org.apache.tools.ant.types.Path
-
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
-
-import java.io.File
-import java.util.Set
-
-public class ClojureCompileTask extends SourceTask {
-    private static Logger logger = LoggerFactory.getLogger(ClojureCompileTask)
-
-    private ClojureSourceSet sourceSet
-    private File destinationDir
-    private FileCollection classpath
-
-    public ClojureCompileTask() {
-        super()
-        initialise()
-    }
-
-    public ClojureCompileTask(org.gradle.api.Project project, String string) {
-        super()
-        initialise()
-    }
-
-    private void initialise() {
-        def action = [ execute: { ClojureCompileTask task ->
-            boolean warnOnReflection = task.sourceSet.warnOnReflection
-            Set<File> sourceDirs = task.sourceSet.srcDirs
-            File destDir = task.destinationDir
-            FileTree source = task.source
-            FileCollection cp = task.classpath
-
-            Map args = [
-                classname:    'de.kotka.gradle.ClojureCompile',
-                failOnError:  true,
-                fork:         true,
-                classpathref: 'compile.classpath'
-            ]
-
-            ant.path(id: 'compile.classpath') {
-                sourceDirs.each {
-                    logger.debug("Add {} (source dir) to Ant classpath!", it)
-                    pathelement(location: it)
-                }
-
-                logger.debug("Add {} (dest dir) to Ant classpath!",
-                    destDir.path)
-                pathelement(location: destDir.path)
-
-                cp.each {
-                    logger.debug("Add {} to Ant classpath!", it)
-                    pathelement(location: it)
-                }
-            }
-
-            destDir.mkdirs()
-
-            ant.java(args) {
-                sysproperty(key: "clojure.compile.path", value: destDir)
-                sysproperty(key: "clojure.compile.warn-on-reflection",
-                    value: warnOnReflection)
-                source.each {
-                    arg(value: it)
-                }
-            }
-        } ] as Action
-
-        this.doLast(action)
-    }
-
-    public ClojureSourceSet getSourceSet() {
-        return sourceSet
-    }
-
-    public void setSourceSet(ClojureSourceSet set) {
-        sourceSet = set
-    }
-
-    public File getDestinationDir() {
-        return destinationDir
-    }
-
-    public void setDestinationDir(File dir) {
-        destinationDir = dir
-    }
-
-    public FileCollection getClasspath() {
-        return classpath
-    }
-
-    public void setClasspath(FileCollection path) {
-        classpath = path
-    }
-
-    public void addCommandLineArgument(Java java, File f) {
-        java.createArg().setFile(f)
-    }
-
-    public void addCommandLineArgument(Java java, String s) {
-        java.createArg().setValue(s)
-    }
-
-    public void addProperty(Java java, String k, File f) {
-        Environment.Variable v = new Environment.Variable()
-        v.setKey(k)
-        v.setFile(f)
-        java.addSysproperty(v)
-    }
-
-    public void addProperty(Java java, String k, String s) {
-        Environment.Variable v = new Environment.Variable()
-        v.setKey(k)
-        v.setValue(s)
-        java.addSysproperty(v)
-    }
-}

src/main/groovy/de/kotka/gradle/ClojurePlugin.groovy

-/*-
- * Copyright 2009 © Meikel Brandmeyer.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-package de.kotka.gradle
-
-import org.gradle.api.Action
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.api.artifacts.Configuration
-import org.gradle.api.internal.ConventionMapping
-import org.gradle.api.internal.IConventionAware
-import org.gradle.api.internal.project.ProjectInternal
-import org.gradle.api.internal.tasks.DefaultSourceSet
-import org.gradle.api.tasks.SourceSet
-import org.gradle.api.plugins.Convention
-import org.gradle.api.plugins.JavaPlugin
-import org.gradle.api.plugins.JavaPluginConvention
-import org.gradle.api.plugins.ProjectPluginsContainer
-import org.gradle.api.tasks.ConventionValue
-
-public class ClojurePlugin implements Plugin {
-    public void use(Project project, ProjectPluginsContainer handler) {
-        JavaPlugin javaPlugin = handler.usePlugin(JavaPlugin.class, project)
-        configureCompileDefaults(project)
-        configureSourceSetDefaults(project, javaPlugin)
-    }
-
-    private JavaPluginConvention javaConvention(Convention convention) {
-        return convetion.getPlugin(JavaPluginConvention.class)
-    }
-
-    private SourceSet mainSourceSet(Convention convention) {
-        return javaConvention(convention)
-            .sourceSets[SourceSet.MAIN_SOURCE_SET_NAME]
-    }
-
-    private ClojureSourceSet mainClojureSourceSet(Convention convention) {
-        return mainSourceSet(convention)
-            .convention.getPlugin(ClojureSourceSet.class)
-    }
-
-    private configureCompileDefaults(Project project) {
-        def dsValue = [ getValue: { Convention convention,
-                IConventionAware object ->
-            return mainClojureSourceSet(convention).clojure
-        } ] as ConventionValue
-
-        def action = [ execute: { ClojureCompileTask task ->
-            task.conventionMapping.map("defaultSource", dsValue)
-        } ] as Action
-
-        project.tasks.withType(ClojureCompileTask.class).allTasks(action)
-    }
-
-    private configureSourceSet(DefaultSourceSet sourceSet,
-            Project project, JavaPlugin javaPlugin) {
-        ProjectInternal projectInternal = (ProjectInternal)project
-        String srcDir = String.format("src/%s/clojure", sourceSet.name)
-
-        DefaultClojureSourceSet clojureSourceSet =
-            new DefaultClojureSourceSet(sourceSet.displayName,
-                projectInternal.fileResolver)
-        sourceSet.convention.plugins["clojure"] = clojureSourceSet
-        clojureSourceSet.clojure.srcDir(srcDir)
-        sourceSet.resources.filter.exclude("**/*.clj")
-        sourceSet.allSource.add(clojureSourceSet.clojure)
-
-        String compileTaskName = sourceSet.getCompileTaskName("clojure")
-        ClojureCompileTask task = project.tasks.add(compileTaskName,
-                ClojureCompileTask.class)
-        task.sourceSet = clojureSourceSet
-        task.description = String.format("Compile the %s Clojure source.",
-                sourceSet.name)
-
-        ConventionMapping convMap = task.conventionMapping
-
-        def dsValue = [ getValue: { Convention c, IConventionAware o ->
-            return clojureSourceSet.clojure
-        } ] as ConventionValue
-        convMap.map("defaultSource", dsValue)
-
-        def cpValue = [ getValue: { Convention c, IConventionAware o ->
-            return sourceSet.compileClasspath
-        } ] as ConventionValue
-        convMap.map("classpath", cpValue)
-
-        def ddValue = [ getValue: { Convention c, IConventionAware o ->
-            return sourceSet.classesDir
-        } ] as ConventionValue
-        convMap.map("destinationDir", ddValue)
-
-        project.tasks[sourceSet.classesTaskName].dependsOn(compileTaskName)
-    }
-
-    private void configureSourceSetDefaults(Project project,
-            JavaPlugin javaPlugin) {
-        def action = [ execute: { SourceSet sourceSet ->
-            configureSourceSet(sourceSet, project, javaPlugin)
-        } ] as Action
-
-        project.convention.getPlugin(JavaPluginConvention.class)
-            .sourceSets.allObjects(action)
-    }
-}
-

src/main/groovy/de/kotka/gradle/ClojureSourceSet.groovy

-/*-
- * Copyright 2009 © Meikel Brandmeyer.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-package de.kotka.gradle
-
-import org.gradle.api.file.SourceDirectorySet
-import org.gradle.api.file.FileTree
-
-import groovy.lang.Closure
-
-import java.io.File
-import java.util.Set
-
-public interface ClojureSourceSet {
-    public SourceDirectorySet getClojure()
-    public ClojureSourceSet clojure(Closure closure)
-    public FileTree getAllClojure()
-    public Set<File> getSrcDirs()
-    public boolean getWarnOnReflection()
-    public void setWarnOnReflection(boolean flag)
-}

src/main/groovy/de/kotka/gradle/DefaultClojureSourceSet.groovy

-/*-
- * Copyright 2009 © Meikel Brandmeyer.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-package de.kotka.gradle
-
-import org.gradle.api.file.FileTree
-import org.gradle.api.tasks.SourceSet
-import org.gradle.api.tasks.util.PatternSet
-import org.gradle.api.internal.file.DefaultSourceDirectorySet
-import org.gradle.api.internal.file.FileResolver
-import org.gradle.api.internal.file.UnionFileTree
-import org.gradle.util.ConfigureUtil
-
-import groovy.lang.Closure
-
-import java.io.File
-import java.util.Set
-
-public class DefaultClojureSourceSet implements ClojureSourceSet {
-    private DefaultSourceDirectorySet clojure
-    private PatternSet clojurePatterns
-    private UnionFileTree allClojure
-    private boolean warnOnReflection
-
-    public DefaultClojureSourceSet(String displayName,
-            FileResolver fileResolver) {
-        String desc = String.format("%s Clojure source", displayName)
-
-        clojure = new DefaultSourceDirectorySet(desc, fileResolver)
-        clojure.filter.include("**/*.clj")
-
-        clojurePatterns = new PatternSet()
-        clojurePatterns.include("**/*.clj")
-
-        allClojure = new UnionFileTree(desc, clojure.matching(clojurePatterns))
-
-        warnOnReflection = false
-    }
-
-    public DefaultSourceDirectorySet getClojure() {
-        return clojure
-    }
-
-    public ClojureSourceSet clojure(Closure closure) {
-        ConfigureUtil.configure(closure, getClojure())
-        return this
-    }
-
-    public FileTree getAllClojure() {
-        return allClojure
-    }
-
-    public Set<File> getSrcDirs() {
-        return clojure.srcDirs
-    }
-
-    public boolean getWarnOnReflection() {
-        return warnOnReflection
-    }
-
-    public void setWarnOnReflection(boolean flag) {
-        warnOnReflection = flag
-    }
-}

src/main/java/clojuresque/ClojureCompile.java

+/*-
+ * Copyright 2009 © Meikel Brandmeyer.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+package clojuresque;
+
+import clojure.lang.ISeq;
+import clojure.lang.IPersistentMap;
+import clojure.lang.IPersistentSet;
+
+import clojure.lang.RT;
+import clojure.lang.Var;
+import clojure.lang.Symbol;
+import clojure.lang.LispReader;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.BufferedReader;
+import java.io.PushbackReader;
+import java.io.IOException;
+
+public class ClojureCompile {
+    private static final String COMPILE_PATH_PROP = "clojure.compile.path";
+    private static final Var COMPILE_PATH =
+        RT.var("clojure.core", "*compile-path*");
+
+    private static final String WARN_ON_REFLECTION_PROP =
+        "clojure.compile.warn-on-reflection";
+    private static final Var WARN_ON_REFLECTION =
+        RT.var("clojure.core", "*warn-on-reflection*");
+
+    private static final IPersistentSet NS_FORMS =
+        RT.set(Symbol.intern("ns"), Symbol.intern("clojure.core", "ns"));
+
+    private static final Var compile = RT.var("clojure.core", "compile");
+
+    private static Object findNamespace(Object form) {
+        if (!(form instanceof ISeq))
+            return null;
+
+        ISeq s = (ISeq)form;
+
+        if (!(NS_FORMS.contains(s.first())))
+            return null;
+
+        return s.next().first();
+    }
+
+    public static void main(String[] files) throws Exception {
+        String compilePath = System.getProperty(COMPILE_PATH_PROP);
+        boolean warnOnReflection =
+            System.getProperty(WARN_ON_REFLECTION_PROP).equals("true");
+
+        IPersistentMap threadBindings = RT.map(
+                COMPILE_PATH, compilePath,
+                WARN_ON_REFLECTION, warnOnReflection
+                );
+        IPersistentSet seen = RT.set();
+
+        Var.pushThreadBindings(threadBindings);
+        try {
+            for (String file : files) {
+                PushbackReader rdr =
+                    new PushbackReader(
+                        new BufferedReader(
+                            new FileReader(
+                                new File(file))));
+
+                try {
+                    Object o = LispReader.read(rdr, false, null, false);
+                    Object ns = findNamespace(o);
+                    if (ns != null && !seen.contains(ns))
+                        compile.invoke(ns);
+                    seen = (IPersistentSet)seen.cons(ns);
+                } finally {
+                    rdr.close();
+                }
+            }
+        } catch(IOException e) {
+            e.printStackTrace();
+        } finally {
+            Var.popThreadBindings();
+        }
+    }
+}

src/main/java/de/kotka/gradle/ClojureCompile.java

-/*-
- * Copyright 2009 © Meikel Brandmeyer.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-package de.kotka.gradle;
-
-import clojure.lang.ISeq;
-import clojure.lang.IPersistentMap;
-import clojure.lang.IPersistentSet;
-
-import clojure.lang.RT;
-import clojure.lang.Var;
-import clojure.lang.Symbol;
-import clojure.lang.LispReader;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.BufferedReader;
-import java.io.PushbackReader;
-import java.io.IOException;
-
-public class ClojureCompile {
-    private static final String COMPILE_PATH_PROP = "clojure.compile.path";
-    private static final Var COMPILE_PATH =
-        RT.var("clojure.core", "*compile-path*");
-
-    private static final String WARN_ON_REFLECTION_PROP =
-        "clojure.compile.warn-on-reflection";
-    private static final Var WARN_ON_REFLECTION =
-        RT.var("clojure.core", "*warn-on-reflection*");
-
-    private static final IPersistentSet NS_FORMS =
-        RT.set(Symbol.intern("ns"), Symbol.intern("clojure.core", "ns"));
-
-    private static final Var compile = RT.var("clojure.core", "compile");
-
-    private static Object findNamespace(Object form) {
-        if (!(form instanceof ISeq))
-            return null;
-
-        ISeq s = (ISeq)form;
-
-        if (!(NS_FORMS.contains(s.first())))
-            return null;
-
-        return s.next().first();
-    }
-
-    public static void main(String[] files) throws Exception {
-        String compilePath = System.getProperty(COMPILE_PATH_PROP);
-        boolean warnOnReflection =
-            System.getProperty(WARN_ON_REFLECTION_PROP).equals("true");
-
-        IPersistentMap threadBindings = RT.map(
-                COMPILE_PATH, compilePath,
-                WARN_ON_REFLECTION, warnOnReflection
-                );
-        IPersistentSet seen = RT.set();
-
-        Var.pushThreadBindings(threadBindings);
-        try {
-            for (String file : files) {
-                PushbackReader rdr =
-                    new PushbackReader(
-                        new BufferedReader(
-                            new FileReader(
-                                new File(file))));
-
-                try {
-                    Object o = LispReader.read(rdr, false, null, false);
-                    Object ns = findNamespace(o);
-                    if (ns != null && !seen.contains(ns))
-                        compile.invoke(ns);
-                    seen = (IPersistentSet)seen.cons(ns);
-                } finally {
-                    rdr.close();
-                }
-            }
-        } catch(IOException e) {
-            e.printStackTrace();
-        } finally {
-            Var.popThreadBindings();
-        }
-    }
-}