Commits

Meikel Brandmeyer committed 399190c

Remove old 0.8 code and start all over

Comments (0)

Files changed (8)

 group = 'clojuresque'
 version = '1.4.0-SNAPSHOT'
 
-configurations {
-    clojarsDeployerJars {
-        visible = false
-        description = 'Private configuration to hold ssh wagon dependencies'
-    }
-}
-
 repositories {
     mavenCentral()
 }
 
 dependencies {
-    groovy 'org.clojure:clojure:1.0.0'
-
     groovy gradleApi()
     groovy localGroovy()
 }

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.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 aotCompile = task.project.aotCompile
-            boolean warnOnReflection = task.project.warnOnReflection
-            Set<File> sourceDirs = task.sourceSet.srcDirs
-            File destDir = task.destinationDir
-            FileTree source = task.source
-            FileCollection cp = task.classpath
-            FileCollection devDeps = task.project.configurations['development']
-
-            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)
-                }
-
-                devDeps.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)
-                sysproperty(key: "clojuresque.compile", value: aotCompile)
-                arg value: "compile"
-                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,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.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.Copy
-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.MavenPlugin
-import org.gradle.api.tasks.ConventionValue
-import org.gradle.api.tasks.StopExecutionException
-import org.gradle.api.tasks.bundling.Jar
-
-public class ClojurePlugin implements Plugin<Project> {
-    public static final String UEBERJAR_TASK_NAME = 'uberjar'
-    public static final String DEPS_TASK_NAME = 'deps'
-
-    public void apply(Project project) {
-        project.plugins.apply(JavaPlugin.class)
-        project.plugins.apply(MavenPlugin.class)
-
-        project.convention.plugins["clojure"] =
-            new ClojurePluginConvention(project)
-
-        project.repositories.convention.plugins["clojure"] =
-            new ClojureRepositoryConvention(project.repositories)
-
-        configureCompileDefaults(project)
-        configureSourceSetDefaults(project)
-        configureConfigurations(project)
-        configureArchives(project)
-        configureUeberjar(project)
-        configureDepsTask(project)
-    }
-
-    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) {
-        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) {
-        def action = [ execute: { SourceSet sourceSet ->
-            configureSourceSet(sourceSet, project)
-        } ] as Action
-
-        project.convention.getPlugin(JavaPluginConvention.class)
-            .sourceSets.allObjects(action)
-    }
-
-    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
-            }
-        }
-        project.dependencies {
-            development 'clojuresque:clojuresque:1.4.0-SNAPSHOT'
-        }
-    }
-
-    private void configureArchives(Project project) {
-        def action = [ execute: { Jar task ->
-            if (!task.project.aotCompile) {
-                task.from task.project.sourceSets[SourceSet.MAIN_SOURCE_SET_NAME].clojure
-            }
-        } ] as Action
-
-        project.tasks[JavaPlugin.JAR_TASK_NAME].doFirst(action)
-    }
-
-    private void configureUeberjar(Project project) {
-        Jar jar = project.tasks[JavaPlugin.JAR_TASK_NAME]
-        Jar ueberjar = project.tasks.add(UEBERJAR_TASK_NAME, Jar.class)
-
-        ueberjar.configure {
-            description =
-                'Constructs a jar with all runtime dependencies included'
-            dependsOn(jar)
-            baseName = jar.baseName + "-standalone"
-            enabled = false
-            doFirst {
-                if (!jar.enabled)
-                    throw new StopExecutionException("SKIPPED: jar not enabled")
-                project.configurations.runtime.resolve().each {
-                    ueberjar.from zipTree(it)
-                }
-                ueberjar.from zipTree(jar.archivePath)
-            }
-        }
-    }
-
-    private void configureDepsTask(Project project) {
-        Copy deps = project.tasks.add(DEPS_TASK_NAME, Copy)
-
-        deps.configure {
-            description =
-                'Copy runtime dependencies into the build/lib directory'
-            into 'lib'
-            from project.configurations.testRuntime
-        }
-    }
-}

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
-
-import org.gradle.api.Project
-import org.gradle.api.artifacts.dsl.RepositoryHandler
-import org.gradle.api.tasks.Upload
-
-class ClojurePluginConvention {
-    Project project
-    boolean warnOnReflection
-    boolean aotCompile
-
-    private boolean didConfigureDeployerJars = false
-
-    public ClojurePluginConvention(Project project) {
-        this.project = project
-        this.warnOnReflection = false
-        this.aotCompile = false
-    }
-
-    public void configureClojarsDeploy() {
-        configureClojarsDeploy(project.uploadArchives)
-    }
-
-    public void configureClojarsDeploy(Upload task) {
-        File dummyRepo = new File(project.buildDir, 'deploy')
-
-        project.configure(task) {
-            repositories.mavenDeployer {
-                name = 'dummyClojarsLocalDeployer'
-                description  = 'Dummy deployer to trick gradle into pom generation'
-                repository(url: 'file://' + dummyRepo.path)
-            }
-        }
-
-        task.doLast {
-            /* Clojars. :( This was changed in the source by Alex based
-             * on a note I sent him. This was before christmas 2009. Now,
-             * end of January 2010 it's still the old version live. */
-            project.fileTree(dir: dummyRepo, includes: ['**/*.pom']).each {
-                String name = it.path
-                String basename = name.substring(0, name.length() - 4)
-                String newname = basename + '.xml'
-
-                project.ant.move(file: it, tofile: project.file(newname))
-            }
-
-            Map args = [
-                executable:  '/usr/bin/scp',
-                failOnError: true
-            ]
-
-            project.ant.exec(args) {
-                project.fileTree(dummyRepo).each { arg value: it }
-                arg value: 'clojars@clojars.org:'
-            }
-        }
-    }
-
-    public boolean getWarnOnReflection() {
-        return this.warnOnReflection
-    }
-
-    public void setWarnOnReflection(boolean flag) {
-        this.warnOnReflection = flag
-    }
-
-    public boolean getAotCompile() {
-        return this.aotCompile
-    }
-
-    public void setAotCompile(boolean flag) {
-        this.aotCompile = flag
-    }
-}

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 {
-    RepositoryHandler repos
-
-    public ClojureRepositoryConvention(RepositoryHandler repos) {
-        this.repos = repos
-    }
-
-    public void clojureSnapshotsRepo() {
-        repos.mavenRepo name: 'clojureHudson', urls: 'http://build.clojure.org/snapshots'
-    }
-
-    public void clojarsRepo() {
-        repos.mavenRepo name: 'clojars', urls: 'http://clojars.org/repo'
-    }
-
-    public void gradleHomeRepo() {
-        String home = System.getenv('GRADLE_HOME')
-        if (home != null) {
-            repos.flatDir name: 'gradleHome', dirs: new File(home + '/lib/plugins')
-        }
-    }
-}

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 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()
-}

src/main/groovy/clojuresque/DefaultClojureSourceSet.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.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
-
-private class ClojureSourceDirectorySet extends DefaultSourceDirectorySet {
-    public ClojureSourceDirectorySet(String desc, FileResolver fileResolver) {
-        super(desc, fileResolver)
-    }
-
-    public void includeNamespace(String pattern) {
-        include(pattern.replaceAll("-", "_").replaceAll("\\.", "/")+".clj")
-    }
-
-    public void excludeNamespace(String pattern) {
-        exclude(pattern.replaceAll("-", "_").replaceAll("\\.", "/")+".clj")
-    }
-}
-
-public class DefaultClojureSourceSet implements ClojureSourceSet {
-    private ClojureSourceDirectorySet clojure
-    private PatternSet clojurePatterns
-    private UnionFileTree allClojure
-
-    public DefaultClojureSourceSet(String displayName,
-            FileResolver fileResolver) {
-        String desc = String.format("%s Clojure source", displayName)
-
-        clojure = new ClojureSourceDirectorySet(desc, fileResolver)
-        clojure.filter.include("**/*.clj")
-
-        clojurePatterns = new PatternSet()
-        clojurePatterns.include("**/*.clj")
-
-        allClojure = new UnionFileTree(desc, clojure.matching(clojurePatterns))
-    }
-
-    public ClojureSourceDirectorySet 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
-    }
-}

src/main/java/clojuresque/ClojureCompile.java

-/*-
- * 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 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 String DO_COMPILE_PROP = "clojuresque.compile";
-    private static final Var compile = RT.var("clojure.core", "compile");
-    private static final Var require = RT.var("clojure.core", "require");
-    private static final Var apply = RT.var("clojure.core", "apply");
-
-    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();
-    }
-
-    private static ISeq findNamespaces(ISeq files) throws Exception {
-        IPersistentSet seen = RT.set();
-
-        while (files != null) {
-            String file = (String)files.first();
-            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 = (IPersistentSet)seen.cons(ns);
-                }
-            } finally {
-                rdr.close();
-            }
-
-            files = files.next();
-        }
-        return RT.seq(seen);
-    }
-
-    public static void compileFiles(ISeq namespaces) throws Exception {
-        String compilePath = System.getProperty(COMPILE_PATH_PROP);
-        boolean warnOnReflection =
-            System.getProperty(WARN_ON_REFLECTION_PROP).equals("true");
-        boolean doCompile = System.getProperty(DO_COMPILE_PROP).equals("true");
-
-        IPersistentMap threadBindings = RT.map(
-                COMPILE_PATH, compilePath,
-                WARN_ON_REFLECTION, warnOnReflection
-                );
-
-        Var.pushThreadBindings(threadBindings);
-        try {
-            while (namespaces != null) {
-                if (doCompile)
-                    compile.invoke(namespaces.first());
-                else
-                    require.invoke(namespaces.first());
-                namespaces = namespaces.next();
-            }
-        } finally {
-            Var.popThreadBindings();
-        }
-    }
-
-    public static void runTests(ISeq namespaces) throws Exception {
-        require.invoke(Symbol.intern("clojure.test"));
-        Var runtests = RT.var("clojure.test", "run-tests");
-
-        if (RT.seq(namespaces) != null) {
-            apply.invoke(require, namespaces);
-            apply.invoke(runtests, namespaces);
-        }
-    }
-
-    public static void main(String[] args) throws Exception {
-        ISeq argsSeq = RT.seq(args);
-
-        String command = (String)argsSeq.first();
-        ISeq namespaces = findNamespaces(argsSeq.next());
-        if (command.equals("compile")) {
-            compileFiles(namespaces);
-        } else if (command.equals("test")) {
-            runTests(namespaces);
-        }
-    }
-}