Meikel  Brandmeyer avatar Meikel Brandmeyer committed 9346d7c

Move things into subprojects

Prepare things for a driver jar. Makes things much easier!

Comments (0)

Files changed (24)

-apply {
-    plugin 'java'
-    plugin 'groovy'
-    plugin 'maven'
-}
+project(':clojuresque') {
+    apply {
+        plugin 'groovy'
+        plugin 'maven'
+    }
 
-group = 'clojuresque'
-version = '1.4.0-SNAPSHOT'
+    group = 'clojuresque'
+    version = '1.4.0-SNAPSHOT'
 
-dependencies {
-    compile gradleApi()
-    groovy localGroovy()
-}
+    dependencies {
+        compile gradleApi()
+        groovy localGroovy()
+    }
 
-uploadArchives.doLast {
-    if (!project.version.endsWith("-SNAPSHOT")) {
-        String pomName = project.buildDirName + "/" + project.pomDirName + "/" +
-            project.name + "-" + project.version + ".xml"
+    uploadArchives.doLast {
+        if (!project.version.endsWith("-SNAPSHOT")) {
+            String pomName = project.buildDirName + "/" + project.pomDirName + "/" +
+                project.name + "-" + project.version + ".xml"
 
-        project.pom().writeTo(pomName)
+            project.pom().writeTo(pomName)
 
-        project.exec {
-            commandLine(
-                '/usr/bin/scp',
-                project.file(project.tasks.jar.archivePath).path,
-                project.file(pomName).path,
-                'clojars@clojars.org:'
-            )
+            project.exec {
+                commandLine(
+                    '/usr/bin/scp',
+                    project.file(project.tasks.jar.archivePath).path,
+                    project.file(pomName).path,
+                    'clojars@clojars.org:'
+                )
+            }
         }
     }
 }

clojuresque/src/main/groovy/clojuresque/ClojureBasePlugin.groovy

+/*-
+ * Copyright 2009,2010 © 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.Plugin
+import org.gradle.api.Project
+import org.gradle.api.artifacts.dsl.RepositoryHandler
+import org.gradle.api.internal.project.ProjectInternal
+import org.gradle.api.plugins.JavaPlugin
+import org.gradle.api.plugins.MavenPlugin
+import org.gradle.api.tasks.Upload
+
+public class ClojureBasePlugin implements Plugin<Project> {
+    public void apply(Project project) {
+        project.apply plugin: JavaPlugin.class
+        project.apply plugin: MavenPlugin.class
+
+        project.convention.plugins.clojure = new ClojurePluginConvention()
+
+        RepositoryHandler repos = project.repositories
+        repos.convention.plugins.clojure =
+            new ClojureRepositoryConvention(repos)
+
+        configureConfigurations(project)
+        configureSourceSets(project)
+        configureCompilation(project)
+        configureClojarsUpload(project)
+    }
+
+    private void configureConfigurations(Project project) {
+        project.configurations {
+            clojuresque {
+                transitive = false
+                visible = false
+                description = "Deprecated: Please use the development configuration"
+            }
+            development {
+                transitive = false
+                visible = false
+                description = "Development only dependencies"
+                extendsFrom clojuresque
+            }
+        }
+    }
+
+    private void configureSourceSets(Project project) {
+        ProjectInternal projectInternal = (ProjectInternal)project
+
+        project.sourceSets.each { sourceSet ->
+            ClojureSourceSet clojureSourceSet =
+                new ClojureSourceSet(sourceSet.name, projectInternal.fileResolver)
+
+            sourceSet.convention.plugins.clojure = clojureSourceSet
+            sourceSet.clojure.srcDirs = [ String.format("src/%s/clojure", sourceSet.name) ]
+            sourceSet.resources.filter.exclude("**/*.clj")
+            sourceSet.allSource.add(clojureSourceSet.clojure)
+        }
+    }
+
+    private void configureCompilation(Project project) {
+        project.sourceSets.each { set ->
+            String compileTaskName = set.getCompileTaskName("clojure")
+            ClojureCompileTask task = project.tasks.add(name: compileTaskName,
+                    type: ClojureCompileTask.class) {
+                destinationDir = set.classesDir
+                source set.clojure
+                clojureRoots = set.clojure
+                compileClasspath = set.compileClasspath
+                dependsOn set.compileClasspath, project.configurations.development
+                description =
+                    String.format("Compile the %s Clojure source.",
+                            set.name)
+            }
+            project.tasks[set.classesTaskName].dependsOn task
+            set.compileClasspath = project.files(
+                set.compileClasspath,
+                project.configurations.development
+            )
+        }
+    }
+
+    private void configureClojarsUpload(Project project) {
+        project.tasks.whenTaskAdded { upload ->
+            if (!(upload instanceof Upload))
+                return
+            upload.convention.plugins.clojure =
+                new ClojureUploadConvention(upload)
+        }
+    }
+}

clojuresque/src/main/groovy/clojuresque/ClojureCompileTask.groovy

+/*-
+ * Copyright 2009,2010 © 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.tasks.StopExecutionException
+import org.gradle.api.tasks.TaskAction
+
+import java.io.InputStream
+
+public class ClojureCompileTask extends ClojureSourceTask {
+    public InputStream compileOrRequire() {
+        String cmd = String.format(
+            this.class.getResourceAsStream("ClojureCompileDriver.clj").text,
+            source.collect {
+                String.format("(java.io.File. \"%s\")",
+                    it.path.replace("\\", "\\\\"))
+            }.join(" "),
+            project.aotCompile ? "compile" : "require"
+        )
+
+        return clojureInput(cmd)
+    }
+
+    @TaskAction
+    public void compile() {
+        if (destinationDir == null) {
+            throw new StopExecutionException("destinationDir not set!")
+        }
+        destinationDir.mkdirs()
+
+        project.javaexec {
+            this.jvmClosure()
+            systemProperties "clojure.compile.path": this.destinationDir.path
+            classpath = project.files(
+                this.clojureRoots.srcDirs,
+                this.destinationDir,
+                project.configurations.development,
+                this.compileClasspath
+            )
+            main = "clojure.main"
+            args = [ "-" ]
+            standardInput = this.compileOrRequire()
+        }
+
+        if (!project.aotCompile) {
+            project.copy {
+                from this.source
+                into this.destinationDir
+            }
+        }
+    }
+}

clojuresque/src/main/groovy/clojuresque/ClojurePlugin.groovy

+/*-
+ * Copyright 2009,2010 © 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.Plugin
+import org.gradle.api.Project
+import org.gradle.api.tasks.Copy
+import org.gradle.api.tasks.bundling.Jar
+
+public class ClojurePlugin implements Plugin<Project> {
+    public void apply(Project project) {
+        project.apply plugin: ClojureBasePlugin.class
+
+        configureUberjar(project)
+        configureDepsTask(project)
+    }
+
+    private void configureUberjar(Project project) {
+        project.tasks.withType(Jar.class).each { jar ->
+            project.tasks.add(name: "uber" + jar.name, type: Jar.class) {
+                description =
+                    'Constructs a jar with all runtime dependencies included'
+                dependsOn jar.source, project.configurations.runtime
+                baseName = jar.baseName + "-standalone"
+                enabled = false
+                doFirst {
+                    project.configurations.runtime.each {
+                        from project.zipTree(it)
+                        exclude 'META-INF/MANIFEST.MF'
+                    }
+                    from jar.source
+                }
+            }
+        }
+    }
+
+    private void configureDepsTask(Project project) {
+        Copy deps = project.tasks.add("deps", Copy.class)
+
+        deps.configure {
+            description =
+                'Copy runtime dependencies into the build/lib directory'
+            into 'lib'
+            from project.configurations.testRuntime
+            from project.configurations.development
+        }
+    }
+}

clojuresque/src/main/groovy/clojuresque/ClojurePluginConvention.groovy

+/*-
+ * Copyright 2009,2010 © 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
+
+class ClojurePluginConvention {
+    def boolean warnOnReflection = false
+    def boolean aotCompile = false
+}

clojuresque/src/main/groovy/clojuresque/ClojureRepositoryConvention.groovy

+/*-
+ * Copyright 2009,2010 © 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.Project
+import org.gradle.api.artifacts.dsl.RepositoryHandler
+
+class ClojureRepositoryConvention {
+    private RepositoryHandler repos
+
+    public ClojureRepositoryConvention(RepositoryHandler repos) {
+        this.repos = repos
+    }
+
+    public void clojureSnapshotsRepo() {
+        repos.mavenRepo name: 'clojureSnapshots',
+            urls: 'http://build.clojure.org/snapshots'
+    }
+
+    public void clojureReleasesRepo() {
+        repos.mavenRepo name: 'clojureReleases',
+            urls: 'http://build.clojure.org/releases'
+    }
+
+    public void clojarsRepo() {
+        repos.mavenRepo name: 'clojars', urls: 'http://clojars.org/repo'
+    }
+}

clojuresque/src/main/groovy/clojuresque/ClojureSourceSet.groovy

+/*-
+ * Copyright 2009,2010 © 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 groovy.lang.Closure
+
+import org.gradle.api.file.FileTree
+import org.gradle.api.file.SourceDirectorySet
+import org.gradle.api.internal.file.UnionFileTree
+import org.gradle.api.internal.file.DefaultSourceDirectorySet
+import org.gradle.api.internal.file.FileResolver
+import org.gradle.api.tasks.util.PatternFilterable
+import org.gradle.api.tasks.util.PatternSet
+import org.gradle.util.ConfigureUtil
+
+class ClojureSourceSet {
+    private final SourceDirectorySet clojure
+    private final UnionFileTree allClojure
+    private final PatternFilterable clojurePatterns = new PatternSet()
+
+    public ClojureSourceSet(String displayName, FileResolver fileResolver) {
+        clojure = new DefaultSourceDirectorySet(String.format("%s Clojure source", displayName), fileResolver)
+        clojure.filter.include("**/*.clj")
+        clojurePatterns.include("**/*.clj")
+        allClojure = new UnionFileTree(String.format("%s Clojure source", displayName), clojure.matching(clojurePatterns))
+    }
+
+    public SourceDirectorySet getClojure() {
+        return clojure
+    }
+
+    public ClojureSourceSet clojure(Closure configureClosure) {
+        ConfigureUtil.configure(configureClosure, this.clojure)
+        return this
+    }
+
+    public PatternFilterable getClojureSourcePatterns() {
+        return clojurePatterns
+    }
+
+    public FileTree getAllClojure() {
+        return allClojure
+    }
+
+    public void clojureIncludeNamespace(String pattern) {
+        clojure.include(
+            pattern.replaceAll("-", "_").replaceAll("\\.", "/") + ".clj"
+        )
+    }
+
+    public void clojureExcludeNamespace(String pattern) {
+        clojure.exclude(
+            pattern.replaceAll("-", "_").replaceAll("\\.", "/") + ".clj"
+        )
+    }
+}

clojuresque/src/main/groovy/clojuresque/ClojureSourceTask.groovy

+/*-
+ * Copyright 2009,2010 © 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.FileCollection
+import org.gradle.api.file.SourceDirectorySet
+import org.gradle.api.tasks.OutputDirectory
+import org.gradle.api.tasks.SourceTask
+import org.gradle.api.tasks.SourceSet
+import org.gradle.api.tasks.StopExecutionException
+import org.gradle.api.tasks.TaskAction
+
+import groovy.lang.Closure
+
+import java.io.File
+import java.io.ByteArrayInputStream
+import java.util.ArrayList;
+import java.util.List;
+
+public class ClojureSourceTask extends SourceTask {
+    def Closure jvmClosure = {}
+    def FileCollection compileClasspath
+    def File destinationDir
+    def SourceDirectorySet clojureRoots
+
+    public ByteArrayInputStream clojureInput(String cmd) {
+        return new ByteArrayInputStream(cmd.bytes)
+    }
+
+    @OutputDirectory
+    public File getDestinationDir() {
+        return this.destinationDir
+    }
+
+    public ClojureCompileTask jvm(Closure closure) {
+        this.jvmClosure = closure
+        return this
+    }
+
+    /* Duplicate the functionality of ClojureSourceSet. */
+    public ClojureCompileTask includeNamespace(String pattern) {
+        include(pattern.replaceAll("-", "_").replaceAll("\\.", "/") + ".clj")
+        return this
+    }
+
+    public ClojureCompileTask excludeNamespace(String pattern) {
+        exclude(pattern.replaceAll("-", "_").replaceAll("\\.", "/") + ".clj")
+        return this
+    }
+}

clojuresque/src/main/groovy/clojuresque/ClojureUploadConvention.groovy

+/*-
+ * Copyright 2009,2010 © 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.Project
+import org.gradle.api.tasks.Upload
+
+class ClojureUploadConvention {
+    private Upload upload
+
+    public ClojureUploadConvention(Upload upload) {
+        this.upload = upload
+    }
+
+    public void clojarsDeploy() {
+        upload.doLast {
+            String pomName = project.buildDirName + "/" +
+                project.pomDirName + "/" +
+                "pom-" + upload.configuration.name + ".xml"
+
+            project.pom().writeTo(pomName)
+            project.exec {
+                executable = '/usr/bin/scp'
+                args = project.files(upload.artifacts)*.path +
+                    [ project.file(pomName).path,
+                      'clojars@clojars.org:' ]
+            }
+        }
+    }
+}

clojuresque/src/main/resources/META-INF/gradle-plugins/clojure-min.properties

+implementation-class=clojuresque.ClojureBasePlugin

clojuresque/src/main/resources/META-INF/gradle-plugins/clojure.properties

+implementation-class=clojuresque.ClojurePlugin

clojuresque/src/main/resources/clojuresque/ClojureCompileDriver.clj

+(in-ns 'user)
+
+(let [find-namespace
+      (fn [file]
+        (let [of-interest '#{ns clojure.core/ns}
+              eof         (Object.)
+              input       (clojure.lang.LineNumberingPushbackReader.
+                            (java.io.FileReader. file))
+              in-seq      (take-while #(not (identical? %% eof))
+                                      (repeatedly #(read input false eof)))
+              candidate   (first
+                            (drop-while
+                              #(or (not (instance? clojure.lang.ISeq %%))
+                                   (not (contains? of-interest (first %%))))
+                              in-seq))]
+          (when candidate
+            (second candidate))))
+      namespaces
+      (set (map find-namespace [%1$s]))]
+  (doseq [nspace namespaces :when nspace]
+    (%2$s nspace)))
+rootProject.name = 'root'
+include 'clojuresque'

src/main/groovy/clojuresque/ClojureBasePlugin.groovy

-/*-
- * Copyright 2009,2010 © 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.Plugin
-import org.gradle.api.Project
-import org.gradle.api.artifacts.dsl.RepositoryHandler
-import org.gradle.api.internal.project.ProjectInternal
-import org.gradle.api.plugins.JavaPlugin
-import org.gradle.api.plugins.MavenPlugin
-import org.gradle.api.tasks.Upload
-
-public class ClojureBasePlugin implements Plugin<Project> {
-    public void apply(Project project) {
-        project.apply plugin: JavaPlugin.class
-        project.apply plugin: MavenPlugin.class
-
-        project.convention.plugins.clojure = new ClojurePluginConvention()
-
-        RepositoryHandler repos = project.repositories
-        repos.convention.plugins.clojure =
-            new ClojureRepositoryConvention(repos)
-
-        configureConfigurations(project)
-        configureSourceSets(project)
-        configureCompilation(project)
-        configureClojarsUpload(project)
-    }
-
-    private void configureConfigurations(Project project) {
-        project.configurations {
-            clojuresque {
-                transitive = false
-                visible = false
-                description = "Deprecated: Please use the development configuration"
-            }
-            development {
-                transitive = false
-                visible = false
-                description = "Development only dependencies"
-                extendsFrom clojuresque
-            }
-        }
-    }
-
-    private void configureSourceSets(Project project) {
-        ProjectInternal projectInternal = (ProjectInternal)project
-
-        project.sourceSets.each { sourceSet ->
-            ClojureSourceSet clojureSourceSet =
-                new ClojureSourceSet(sourceSet.name, projectInternal.fileResolver)
-
-            sourceSet.convention.plugins.clojure = clojureSourceSet
-            sourceSet.clojure.srcDirs = [ String.format("src/%s/clojure", sourceSet.name) ]
-            sourceSet.resources.filter.exclude("**/*.clj")
-            sourceSet.allSource.add(clojureSourceSet.clojure)
-        }
-    }
-
-    private void configureCompilation(Project project) {
-        project.sourceSets.each { set ->
-            String compileTaskName = set.getCompileTaskName("clojure")
-            ClojureCompileTask task = project.tasks.add(name: compileTaskName,
-                    type: ClojureCompileTask.class) {
-                destinationDir = set.classesDir
-                source set.clojure
-                clojureRoots = set.clojure
-                compileClasspath = set.compileClasspath
-                dependsOn set.compileClasspath, project.configurations.development
-                description =
-                    String.format("Compile the %s Clojure source.",
-                            set.name)
-            }
-            project.tasks[set.classesTaskName].dependsOn task
-            set.compileClasspath = project.files(
-                set.compileClasspath,
-                project.configurations.development
-            )
-        }
-    }
-
-    private void configureClojarsUpload(Project project) {
-        project.tasks.whenTaskAdded { upload ->
-            if (!(upload instanceof Upload))
-                return
-            upload.convention.plugins.clojure =
-                new ClojureUploadConvention(upload)
-        }
-    }
-}

src/main/groovy/clojuresque/ClojureCompileTask.groovy

-/*-
- * Copyright 2009,2010 © 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.tasks.StopExecutionException
-import org.gradle.api.tasks.TaskAction
-
-import java.io.InputStream
-
-public class ClojureCompileTask extends ClojureSourceTask {
-    public InputStream compileOrRequire() {
-        String cmd = String.format(
-            this.class.getResourceAsStream("ClojureCompileDriver.clj").text,
-            source.collect {
-                String.format("(java.io.File. \"%s\")",
-                    it.path.replace("\\", "\\\\"))
-            }.join(" "),
-            project.aotCompile ? "compile" : "require"
-        )
-
-        return clojureInput(cmd)
-    }
-
-    @TaskAction
-    public void compile() {
-        if (destinationDir == null) {
-            throw new StopExecutionException("destinationDir not set!")
-        }
-        destinationDir.mkdirs()
-
-        project.javaexec {
-            this.jvmClosure()
-            systemProperties "clojure.compile.path": this.destinationDir.path
-            classpath = project.files(
-                this.clojureRoots.srcDirs,
-                this.destinationDir,
-                project.configurations.development,
-                this.compileClasspath
-            )
-            main = "clojure.main"
-            args = [ "-" ]
-            standardInput = this.compileOrRequire()
-        }
-
-        if (!project.aotCompile) {
-            project.copy {
-                from this.source
-                into this.destinationDir
-            }
-        }
-    }
-}

src/main/groovy/clojuresque/ClojurePlugin.groovy

-/*-
- * Copyright 2009,2010 © 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.Plugin
-import org.gradle.api.Project
-import org.gradle.api.tasks.Copy
-import org.gradle.api.tasks.bundling.Jar
-
-public class ClojurePlugin implements Plugin<Project> {
-    public void apply(Project project) {
-        project.apply plugin: ClojureBasePlugin.class
-
-        configureUberjar(project)
-        configureDepsTask(project)
-    }
-
-    private void configureUberjar(Project project) {
-        project.tasks.withType(Jar.class).each { jar ->
-            project.tasks.add(name: "uber" + jar.name, type: Jar.class) {
-                description =
-                    'Constructs a jar with all runtime dependencies included'
-                dependsOn jar.source, project.configurations.runtime
-                baseName = jar.baseName + "-standalone"
-                enabled = false
-                doFirst {
-                    project.configurations.runtime.each {
-                        from project.zipTree(it)
-                        exclude 'META-INF/MANIFEST.MF'
-                    }
-                    from jar.source
-                }
-            }
-        }
-    }
-
-    private void configureDepsTask(Project project) {
-        Copy deps = project.tasks.add("deps", Copy.class)
-
-        deps.configure {
-            description =
-                'Copy runtime dependencies into the build/lib directory'
-            into 'lib'
-            from project.configurations.testRuntime
-            from project.configurations.development
-        }
-    }
-}

src/main/groovy/clojuresque/ClojurePluginConvention.groovy

-/*-
- * Copyright 2009,2010 © 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
-
-class ClojurePluginConvention {
-    def boolean warnOnReflection = false
-    def boolean aotCompile = false
-}

src/main/groovy/clojuresque/ClojureRepositoryConvention.groovy

-/*-
- * Copyright 2009,2010 © 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.Project
-import org.gradle.api.artifacts.dsl.RepositoryHandler
-
-class ClojureRepositoryConvention {
-    private RepositoryHandler repos
-
-    public ClojureRepositoryConvention(RepositoryHandler repos) {
-        this.repos = repos
-    }
-
-    public void clojureSnapshotsRepo() {
-        repos.mavenRepo name: 'clojureSnapshots',
-            urls: 'http://build.clojure.org/snapshots'
-    }
-
-    public void clojureReleasesRepo() {
-        repos.mavenRepo name: 'clojureReleases',
-            urls: 'http://build.clojure.org/releases'
-    }
-
-    public void clojarsRepo() {
-        repos.mavenRepo name: 'clojars', urls: 'http://clojars.org/repo'
-    }
-}

src/main/groovy/clojuresque/ClojureSourceSet.groovy

-/*-
- * Copyright 2009,2010 © 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 groovy.lang.Closure
-
-import org.gradle.api.file.FileTree
-import org.gradle.api.file.SourceDirectorySet
-import org.gradle.api.internal.file.UnionFileTree
-import org.gradle.api.internal.file.DefaultSourceDirectorySet
-import org.gradle.api.internal.file.FileResolver
-import org.gradle.api.tasks.util.PatternFilterable
-import org.gradle.api.tasks.util.PatternSet
-import org.gradle.util.ConfigureUtil
-
-class ClojureSourceSet {
-    private final SourceDirectorySet clojure
-    private final UnionFileTree allClojure
-    private final PatternFilterable clojurePatterns = new PatternSet()
-
-    public ClojureSourceSet(String displayName, FileResolver fileResolver) {
-        clojure = new DefaultSourceDirectorySet(String.format("%s Clojure source", displayName), fileResolver)
-        clojure.filter.include("**/*.clj")
-        clojurePatterns.include("**/*.clj")
-        allClojure = new UnionFileTree(String.format("%s Clojure source", displayName), clojure.matching(clojurePatterns))
-    }
-
-    public SourceDirectorySet getClojure() {
-        return clojure
-    }
-
-    public ClojureSourceSet clojure(Closure configureClosure) {
-        ConfigureUtil.configure(configureClosure, this.clojure)
-        return this
-    }
-
-    public PatternFilterable getClojureSourcePatterns() {
-        return clojurePatterns
-    }
-
-    public FileTree getAllClojure() {
-        return allClojure
-    }
-
-    public void clojureIncludeNamespace(String pattern) {
-        clojure.include(
-            pattern.replaceAll("-", "_").replaceAll("\\.", "/") + ".clj"
-        )
-    }
-
-    public void clojureExcludeNamespace(String pattern) {
-        clojure.exclude(
-            pattern.replaceAll("-", "_").replaceAll("\\.", "/") + ".clj"
-        )
-    }
-}

src/main/groovy/clojuresque/ClojureSourceTask.groovy

-/*-
- * Copyright 2009,2010 © 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.FileCollection
-import org.gradle.api.file.SourceDirectorySet
-import org.gradle.api.tasks.OutputDirectory
-import org.gradle.api.tasks.SourceTask
-import org.gradle.api.tasks.SourceSet
-import org.gradle.api.tasks.StopExecutionException
-import org.gradle.api.tasks.TaskAction
-
-import groovy.lang.Closure
-
-import java.io.File
-import java.io.ByteArrayInputStream
-import java.util.ArrayList;
-import java.util.List;
-
-public class ClojureSourceTask extends SourceTask {
-    def Closure jvmClosure = {}
-    def FileCollection compileClasspath
-    def File destinationDir
-    def SourceDirectorySet clojureRoots
-
-    public ByteArrayInputStream clojureInput(String cmd) {
-        return new ByteArrayInputStream(cmd.bytes)
-    }
-
-    @OutputDirectory
-    public File getDestinationDir() {
-        return this.destinationDir
-    }
-
-    public ClojureCompileTask jvm(Closure closure) {
-        this.jvmClosure = closure
-        return this
-    }
-
-    /* Duplicate the functionality of ClojureSourceSet. */
-    public ClojureCompileTask includeNamespace(String pattern) {
-        include(pattern.replaceAll("-", "_").replaceAll("\\.", "/") + ".clj")
-        return this
-    }
-
-    public ClojureCompileTask excludeNamespace(String pattern) {
-        exclude(pattern.replaceAll("-", "_").replaceAll("\\.", "/") + ".clj")
-        return this
-    }
-}

src/main/groovy/clojuresque/ClojureUploadConvention.groovy

-/*-
- * Copyright 2009,2010 © 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.Project
-import org.gradle.api.tasks.Upload
-
-class ClojureUploadConvention {
-    private Upload upload
-
-    public ClojureUploadConvention(Upload upload) {
-        this.upload = upload
-    }
-
-    public void clojarsDeploy() {
-        upload.doLast {
-            String pomName = project.buildDirName + "/" +
-                project.pomDirName + "/" +
-                "pom-" + upload.configuration.name + ".xml"
-
-            project.pom().writeTo(pomName)
-            project.exec {
-                executable = '/usr/bin/scp'
-                args = project.files(upload.artifacts)*.path +
-                    [ project.file(pomName).path,
-                      'clojars@clojars.org:' ]
-            }
-        }
-    }
-}

src/main/resources/META-INF/gradle-plugins/clojure-min.properties

-implementation-class=clojuresque.ClojureBasePlugin

src/main/resources/META-INF/gradle-plugins/clojure.properties

-implementation-class=clojuresque.ClojurePlugin

src/main/resources/clojuresque/ClojureCompileDriver.clj

-(in-ns 'user)
-
-(let [find-namespace
-      (fn [file]
-        (let [of-interest '#{ns clojure.core/ns}
-              eof         (Object.)
-              input       (clojure.lang.LineNumberingPushbackReader.
-                            (java.io.FileReader. file))
-              in-seq      (take-while #(not (identical? %% eof))
-                                      (repeatedly #(read input false eof)))
-              candidate   (first
-                            (drop-while
-                              #(or (not (instance? clojure.lang.ISeq %%))
-                                   (not (contains? of-interest (first %%))))
-                              in-seq))]
-          (when candidate
-            (second candidate))))
-      namespaces
-      (set (map find-namespace [%1$s]))]
-  (doseq [nspace namespaces :when nspace]
-    (%2$s nspace)))
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.