├── samples ├── src │ ├── projects │ │ ├── basic-app │ │ │ ├── README.md │ │ │ ├── src │ │ │ │ └── main │ │ │ │ │ └── clojure │ │ │ │ │ └── org │ │ │ │ │ └── graclj │ │ │ │ │ └── samples │ │ │ │ │ └── app.clj │ │ │ └── build.gradle │ │ └── basic-library │ │ │ ├── README.md │ │ │ ├── src │ │ │ ├── main │ │ │ │ └── clojure │ │ │ │ │ └── org │ │ │ │ │ └── graclj │ │ │ │ │ └── samples │ │ │ │ │ └── library.clj │ │ │ └── test │ │ │ │ └── clojure │ │ │ │ └── org │ │ │ │ └── graclj │ │ │ │ └── samples │ │ │ │ ├── library_test2.clj │ │ │ │ └── library_test1.clj │ │ │ └── build.gradle │ └── test │ │ └── groovy │ │ └── org │ │ └── graclj │ │ └── samples │ │ ├── BasicAppTest.groovy │ │ └── BasicLibraryTest.groovy └── build.gradle ├── modules ├── graclj-plugin │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── org │ │ │ │ │ └── graclj │ │ │ │ │ │ └── version.properties │ │ │ │ └── META-INF │ │ │ │ │ └── gradle-plugins │ │ │ │ │ ├── org.graclj.clojure-lang.properties │ │ │ │ │ ├── org.graclj.clojure-test-suite.properties │ │ │ │ │ └── org.graclj.clojure-component.properties │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── graclj │ │ │ │ ├── language │ │ │ │ └── clj │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── tasks │ │ │ │ │ ├── package-info.java │ │ │ │ │ └── ClojureCompile.java │ │ │ │ │ ├── plugins │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── ClojureLanguagePlugin.java │ │ │ │ │ └── ClojureLanguageRules.java │ │ │ │ │ └── ClojureSourceSet.java │ │ │ │ ├── test │ │ │ │ └── clj │ │ │ │ │ └── plugins │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── ClojureTestSuitePlugin.java │ │ │ │ │ └── ClojureTestSuiteRules.java │ │ │ │ ├── internal │ │ │ │ ├── package-info.java │ │ │ │ ├── plugins │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── GracljInternalRules.java │ │ │ │ │ └── GracljInternalPlugin.java │ │ │ │ └── GracljInternal.java │ │ │ │ ├── platform │ │ │ │ └── clj │ │ │ │ │ ├── ClojureLibrarySpec.java │ │ │ │ │ ├── ClojureGeneralComponentSpec.java │ │ │ │ │ ├── ClojureApplicationSpec.java │ │ │ │ │ └── plugins │ │ │ │ │ ├── ClojureComponentPlugin.java │ │ │ │ │ └── ClojureComponentRules.java │ │ │ │ └── testing │ │ │ │ └── clj │ │ │ │ └── ClojureTestSuiteSpec.java │ │ └── test │ │ │ └── groovy │ │ │ └── org │ │ │ └── graclj │ │ │ ├── test │ │ │ └── clj │ │ │ │ └── plugins │ │ │ │ └── ClojureTestSuitePluginTest.groovy │ │ │ ├── language │ │ │ └── clj │ │ │ │ └── plugins │ │ │ │ └── ClojureLanguagePluginTest.groovy │ │ │ └── platform │ │ │ └── clj │ │ │ └── plugins │ │ │ └── ClojureComponentPluginTest.groovy │ └── build.gradle └── graclj-tools │ ├── src │ └── main │ │ └── clojure │ │ └── org │ │ └── graclj │ │ └── tools │ │ ├── compiler │ │ └── clojure.clj │ │ └── test │ │ └── clojure_test.clj │ └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .travis.yml ├── .gitignore ├── .editorconfig ├── notes-for-gradle.md ├── travis.sh ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /samples/src/projects/basic-app/README.md: -------------------------------------------------------------------------------- 1 | # Basic App Example 2 | 3 | ... 4 | -------------------------------------------------------------------------------- /samples/src/projects/basic-library/README.md: -------------------------------------------------------------------------------- 1 | # Basic Library Example 2 | 3 | ... 4 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/resources/org/graclj/version.properties: -------------------------------------------------------------------------------- 1 | version=@gracljVersion@ 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'modules:graclj-tools' 2 | include 'modules:graclj-plugin' 3 | include 'samples' 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ajoberstar/graclj/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/language/clj/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Clojure language support 3 | */ 4 | package org.graclj.language.clj; 5 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/resources/META-INF/gradle-plugins/org.graclj.clojure-lang.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.graclj.language.clj.plugins.ClojureLanguagePlugin 2 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/resources/META-INF/gradle-plugins/org.graclj.clojure-test-suite.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.graclj.test.clj.plugins.ClojureTestSuitePlugin 2 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/language/clj/tasks/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tasks supporting the Clojure language. 3 | */ 4 | package org.graclj.language.clj.tasks; 5 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/resources/META-INF/gradle-plugins/org.graclj.clojure-component.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.graclj.platform.clj.plugins.ClojureComponentPlugin 2 | -------------------------------------------------------------------------------- /samples/src/projects/basic-app/src/main/clojure/org/graclj/samples/app.clj: -------------------------------------------------------------------------------- 1 | (ns org.graclj.samples.app 2 | (:gen-class)) 3 | 4 | (defn -main [& args] 5 | (println (reverse args))) 6 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/test/clj/plugins/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Plugins supporting Clojure testing frameworks. 3 | */ 4 | package org.graclj.test.clj.plugins; 5 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/language/clj/plugins/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Plugins supporting the CLojure language. 3 | */ 4 | package org.graclj.language.clj.plugins; 5 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * CLasses needed to make Grclj work, but should not be used by external users. 3 | */ 4 | package org.graclj.internal; 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | install: "" 4 | script: ./travis.sh 5 | jdk: 6 | - oraclejdk8 7 | cache: 8 | directories: 9 | - $HOME/.gradle/caches 10 | - $HOME/.gradle/wrapper 11 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/internal/plugins/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Plugins internal to Graclj's implementation that should not be applied by external users. 3 | */ 4 | package org.graclj.internal.plugins; 5 | -------------------------------------------------------------------------------- /samples/src/projects/basic-library/src/main/clojure/org/graclj/samples/library.clj: -------------------------------------------------------------------------------- 1 | (ns org.graclj.samples.library 2 | (:require [clojure.string :as str])) 3 | 4 | (defn palindrome [string] 5 | (str string (str/reverse string))) 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build 4 | # Eclipse 5 | .settings 6 | .project 7 | .classpath 8 | bin 9 | # Idea 10 | *.iml 11 | *.iws 12 | *.ipr 13 | .idea 14 | # Sublime 15 | *.sublime-* 16 | # SonarQube 17 | .sonar 18 | .sonar_lock 19 | # Temp Files 20 | *~ 21 | *.swp 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Sep 27 16:31:03 CDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-bin.zip 7 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/language/clj/ClojureSourceSet.java: -------------------------------------------------------------------------------- 1 | package org.graclj.language.clj; 2 | 3 | import org.gradle.language.base.LanguageSourceSet; 4 | import org.gradle.model.Managed; 5 | 6 | @Managed 7 | public interface ClojureSourceSet extends LanguageSourceSet { 8 | } 9 | -------------------------------------------------------------------------------- /samples/src/projects/basic-library/src/test/clojure/org/graclj/samples/library_test2.clj: -------------------------------------------------------------------------------- 1 | (ns org.graclj.samples.library-test2 2 | (:require [org.graclj.samples.library :refer :all] 3 | [clojure.test :refer [deftest is]])) 4 | 5 | (deftest palindrome-works 6 | (is (= "carrac" (palindrome "car")))) 7 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/platform/clj/ClojureLibrarySpec.java: -------------------------------------------------------------------------------- 1 | package org.graclj.platform.clj; 2 | 3 | import org.gradle.jvm.JvmLibrarySpec; 4 | import org.gradle.model.Managed; 5 | 6 | @Managed 7 | public interface ClojureLibrarySpec extends JvmLibrarySpec, ClojureGeneralComponentSpec { 8 | } 9 | -------------------------------------------------------------------------------- /samples/src/projects/basic-library/src/test/clojure/org/graclj/samples/library_test1.clj: -------------------------------------------------------------------------------- 1 | (ns org.graclj.samples.library-test1 2 | (:require [org.graclj.samples.library :refer :all] 3 | [clojure.test :refer [deftest is]])) 4 | 5 | (deftest palindrome-works 6 | (is (= "testtset" (palindrome "test")))) 7 | 8 | (deftest this-fails 9 | (is (= "blah" (palindrome "blah")))) 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # defaults 7 | [*] 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | charset = utf-8 11 | indent_style = space 12 | indent_size = 4 13 | 14 | # Clojure dialect settings 15 | [*.{clj,cljc,cljs}] 16 | indent_style = space 17 | indent_size = 2 18 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/testing/clj/ClojureTestSuiteSpec.java: -------------------------------------------------------------------------------- 1 | package org.graclj.testing.clj; 2 | 3 | import org.graclj.platform.clj.ClojureGeneralComponentSpec; 4 | import org.gradle.jvm.test.JvmTestSuiteSpec; 5 | import org.gradle.model.Managed; 6 | 7 | @Managed 8 | public interface ClojureTestSuiteSpec extends JvmTestSuiteSpec, ClojureGeneralComponentSpec { 9 | } 10 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/platform/clj/ClojureGeneralComponentSpec.java: -------------------------------------------------------------------------------- 1 | package org.graclj.platform.clj; 2 | 3 | import org.gradle.jvm.JvmComponentSpec; 4 | import org.gradle.platform.base.GeneralComponentSpec; 5 | 6 | public interface ClojureGeneralComponentSpec extends GeneralComponentSpec, JvmComponentSpec { 7 | boolean isAot(); 8 | void setAot(boolean aot); 9 | } 10 | -------------------------------------------------------------------------------- /modules/graclj-tools/src/main/clojure/org/graclj/tools/compiler/clojure.clj: -------------------------------------------------------------------------------- 1 | (ns org.graclj.tools.compiler.clojure 2 | (:require [clojure.java.io :as io] 3 | [clojure.tools.namespace.find :refer [find-namespaces]]) 4 | (:gen-class)) 5 | 6 | (defn -main [source-path compile-path & args] 7 | (binding [*compile-path* compile-path] 8 | (let [source-dir (io/file source-path) 9 | namespaces (find-namespaces [source-dir])] 10 | (doseq [namespace namespaces] 11 | (compile namespace))))) 12 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/platform/clj/ClojureApplicationSpec.java: -------------------------------------------------------------------------------- 1 | package org.graclj.platform.clj; 2 | 3 | import org.gradle.jvm.JvmLibrarySpec; 4 | import org.gradle.model.Managed; 5 | 6 | // TODO Yes, I know I shouldn't call this Application and extend Library 7 | @Managed 8 | public interface ClojureApplicationSpec extends JvmLibrarySpec, ClojureGeneralComponentSpec { 9 | String getMain(); 10 | void setMain(String main); 11 | 12 | boolean isUberjar(); 13 | void setUberjar(boolean uberjar); 14 | } 15 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/internal/plugins/GracljInternalRules.java: -------------------------------------------------------------------------------- 1 | package org.graclj.internal.plugins; 2 | 3 | import org.graclj.internal.GracljInternal; 4 | import org.gradle.api.plugins.ExtensionContainer; 5 | import org.gradle.model.Model; 6 | import org.gradle.model.RuleSource; 7 | 8 | public class GracljInternalRules extends RuleSource { 9 | @Model 10 | public GracljInternal gracljInternalDependencies(ExtensionContainer extensions) { 11 | return extensions.getByType(GracljInternal.class); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/internal/plugins/GracljInternalPlugin.java: -------------------------------------------------------------------------------- 1 | package org.graclj.internal.plugins; 2 | 3 | import org.graclj.internal.GracljInternal; 4 | import org.gradle.api.Plugin; 5 | import org.gradle.api.Project; 6 | 7 | public class GracljInternalPlugin implements Plugin { 8 | @Override 9 | public void apply(Project project) { 10 | project.getExtensions().create("gracljInternal", GracljInternal.class, project.getConfigurations(), project.getDependencies()); 11 | project.getPluginManager().apply(GracljInternalRules.class); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/platform/clj/plugins/ClojureComponentPlugin.java: -------------------------------------------------------------------------------- 1 | package org.graclj.platform.clj.plugins; 2 | 3 | import org.graclj.internal.plugins.GracljInternalPlugin; 4 | import org.gradle.api.Plugin; 5 | import org.gradle.api.Project; 6 | import org.gradle.jvm.plugins.JvmComponentPlugin; 7 | 8 | public class ClojureComponentPlugin implements Plugin { 9 | @Override 10 | public void apply(Project project) { 11 | project.getPluginManager().apply(GracljInternalPlugin.class); 12 | project.getPluginManager().apply(JvmComponentPlugin.class); 13 | project.getPluginManager().apply(ClojureComponentRules.class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/language/clj/plugins/ClojureLanguagePlugin.java: -------------------------------------------------------------------------------- 1 | package org.graclj.language.clj.plugins; 2 | 3 | import org.graclj.internal.plugins.GracljInternalPlugin; 4 | import org.gradle.api.Plugin; 5 | import org.gradle.api.Project; 6 | import org.gradle.language.jvm.plugins.JvmResourcesPlugin; 7 | 8 | public class ClojureLanguagePlugin implements Plugin { 9 | @Override 10 | public void apply(Project project) { 11 | project.getPluginManager().apply(GracljInternalPlugin.class); 12 | project.getPluginManager().apply(JvmResourcesPlugin.class); 13 | project.getPluginManager().apply(ClojureLanguageRules.class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /notes-for-gradle.md: -------------------------------------------------------------------------------- 1 | # Gradle Notes 2 | 3 | Notes intended as feedback to Gradle devs about experience with new model plugins. 4 | 5 | ## Missing Pieces 6 | 7 | ### Needed 8 | 9 | - Dependency on Gradle API from jvm-component/java-lang 10 | - Public views (like the internal ones) so I can extend JarBinarySpec, etc. 11 | - Public way to inherit (or use in @Managed type, preferably) DependentSourceSet 12 | - Public way to inherit (or use in @Managed type, preferably) DependentSourceSet 13 | - Public way to resolve dependencies (maybe as a `Classpath`) 14 | 15 | 16 | ## Maybe 17 | 18 | - Public way to create (or use in @Managed type, preferably) Classpath 19 | 20 | 21 | ## Complications 22 | 23 | - JvmTestSuite plugins assume JUnit or TestNG 24 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/test/clj/plugins/ClojureTestSuitePlugin.java: -------------------------------------------------------------------------------- 1 | package org.graclj.test.clj.plugins; 2 | 3 | import org.gradle.api.Plugin; 4 | import org.gradle.api.Project; 5 | import org.gradle.jvm.plugins.JUnitTestSuitePlugin; 6 | import org.gradle.jvm.plugins.JvmComponentPlugin; 7 | import org.gradle.testing.base.plugins.TestingModelBasePlugin; 8 | 9 | public class ClojureTestSuitePlugin implements Plugin { 10 | @Override 11 | public void apply(Project project) { 12 | project.getPluginManager().apply(TestingModelBasePlugin.class); 13 | project.getPluginManager().apply(JvmComponentPlugin.class); 14 | project.getPluginManager().apply(JUnitTestSuitePlugin.class); 15 | project.getPluginManager().apply(ClojureTestSuiteRules.class); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /samples/src/test/groovy/org/graclj/samples/BasicAppTest.groovy: -------------------------------------------------------------------------------- 1 | package org.graclj.samples 2 | 3 | import org.gradle.testkit.runner.GradleRunner 4 | import spock.lang.Specification 5 | 6 | import java.nio.file.Paths 7 | 8 | class BasicAppTest extends Specification { 9 | GradleRunner runner 10 | 11 | def setup() { 12 | runner = GradleRunner.create() 13 | .withProjectDir(Paths.get(System.properties['test.projects.root'], 'basic-app').toFile()) 14 | .withGradleVersion(System.properties['test.gradle.version']) 15 | } 16 | 17 | def 'can execute main class'() { 18 | when: 19 | def result = runner 20 | .withArguments('clean', 'components', 'run', '--stacktrace') 21 | .build() 22 | then: 23 | result.output =~ /\(third second first\)/ 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /travis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | 4 | export TERM=dumb 5 | 6 | if [ "${TRAVIS_BRANCH}" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then 7 | echo 'Running Gradle check with SonarQube analysis' 8 | ./gradlew clean check sonarqube \ 9 | -Dsonar.host.url=https://sonarqube.ajoberstar.com \ 10 | -Dsonar.login=$SONARQUBE_TOKEN 11 | elif [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "${GITHUB_TOKEN:-}" ]; then 12 | echo 'Running Gradle check with SonarQube preview for pull requests' 13 | ./gradlew clean check sonarqube \ 14 | -Dsonar.host.url=https://sonarqube.ajoberstar.com \ 15 | -Dsonar.login=$SONARQUBE_TOKEN \ 16 | -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \ 17 | -Dsonar.github.repository=$TRAVIS_REPO_SLUG \ 18 | -Dsonar.github.oauth=$GITHUB_TOKEN \ 19 | -Dsonar.analysis.mode=issues 20 | else 21 | echo 'Running Gradle check without SonarQube analysis' 22 | ./gradlew clean check 23 | fi 24 | -------------------------------------------------------------------------------- /samples/src/test/groovy/org/graclj/samples/BasicLibraryTest.groovy: -------------------------------------------------------------------------------- 1 | package org.graclj.samples 2 | 3 | import org.gradle.testkit.runner.GradleRunner 4 | import spock.lang.Specification 5 | 6 | import java.nio.file.Paths 7 | 8 | class BasicLibraryTest extends Specification { 9 | GradleRunner runner 10 | 11 | def setup() { 12 | runner = GradleRunner.create() 13 | .withProjectDir(Paths.get(System.properties['test.projects.root'], 'basic-library').toFile()) 14 | .withGradleVersion(System.properties['test.gradle.version']) 15 | } 16 | 17 | def 'can publish to clojars'() { 18 | expect: 19 | runner 20 | .withArguments('clean', 'components', 'publishMainPublicationToClojars', '--stacktrace') 21 | .build() 22 | } 23 | 24 | def 'can execute tests'() { 25 | when: 26 | def result = runner 27 | .withArguments('clean', 'components', 'testMainJarBinaryTest', '--stacktrace') 28 | .buildAndFail() 29 | then: 30 | result.output =~ /3 tests completed, 1 failed/ 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /modules/graclj-tools/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'maven-publish' 4 | id 'com.jfrog.bintray' version '1.6' 5 | } 6 | 7 | sourceSets.main { 8 | resources.srcDir 'src/main/clojure' 9 | } 10 | sourceSets.test { 11 | resources.srcDir 'src/test/clojure' 12 | } 13 | 14 | dependencies { 15 | compile 'org.clojure:clojure:1.8.0' 16 | compile 'org.clojure:tools.namespace:0.2.11' 17 | 18 | compile 'junit:junit:4.12' 19 | } 20 | 21 | task sourcesJar(type: Jar) { 22 | classifier = 'sources' 23 | from sourceSets.main.allSource 24 | } 25 | 26 | publishing { 27 | publications { 28 | main(MavenPublication) { 29 | from components.java 30 | artifact sourcesJar 31 | } 32 | } 33 | } 34 | 35 | ext.cljClasses = new File(buildDir, 'classes-clj') 36 | 37 | task compileClj(type: JavaExec) { 38 | classpath file('src/main/clojure') 39 | classpath configurations.compile 40 | classpath cljClasses 41 | main 'clojure.main' 42 | args '--main', 'org.graclj.tools.compiler.clojure', 'src/main/clojure', cljClasses 43 | doFirst { 44 | cljClasses.mkdirs() 45 | } 46 | } 47 | 48 | jar { 49 | from cljClasses 50 | dependsOn compileClj 51 | } 52 | -------------------------------------------------------------------------------- /samples/src/projects/basic-app/build.gradle: -------------------------------------------------------------------------------- 1 | import org.gradle.jvm.test.JUnitTestSuiteSpec 2 | 3 | buildscript { 4 | repositories { mavenLocal() } 5 | dependencies { classpath 'org.graclj:graclj-plugin:@gracljVersion@' } 6 | } 7 | 8 | apply plugin: 'org.graclj.clojure-lang' 9 | apply plugin: 'org.graclj.clojure-component' 10 | apply plugin: 'org.graclj.clojure-test-suite' 11 | 12 | repositories { 13 | mavenLocal() 14 | jcenter() 15 | } 16 | 17 | import org.graclj.platform.clj.* 18 | 19 | model { 20 | components { 21 | main(ClojureApplicationSpec) { 22 | main = 'org.graclj.samples.app' 23 | dependencies { 24 | module 'org.clojure:clojure:1.8.0' 25 | } 26 | } 27 | } 28 | testSuites { 29 | test(JUnitTestSuiteSpec) { 30 | jUnitVersion '4.12' 31 | testing $.components.main 32 | } 33 | } 34 | } 35 | 36 | // I'm assuming there's a better way to do this 37 | class MyRules extends RuleSource { 38 | @Mutate 39 | void createRunTask(ModelMap tasks, @Path('binaries.mainJar') JarBinarySpec binary) { 40 | tasks.create('run', Exec) { 41 | dependsOn binary.tasks.jar 42 | commandLine 'java', '-jar', binary.jarFile, 'first', 'second', 'third' 43 | } 44 | } 45 | } 46 | 47 | apply plugin: MyRules 48 | -------------------------------------------------------------------------------- /samples/src/projects/basic-library/build.gradle: -------------------------------------------------------------------------------- 1 | import org.gradle.jvm.test.JUnitTestSuiteSpec 2 | 3 | buildscript { 4 | repositories { mavenLocal() } 5 | dependencies { classpath 'org.graclj:graclj-plugin:@gracljVersion@' } 6 | } 7 | 8 | apply plugin: 'org.graclj.clojure-lang' 9 | apply plugin: 'org.graclj.clojure-component' 10 | apply plugin: 'org.graclj.clojure-test-suite' 11 | apply plugin: 'maven-publish' 12 | 13 | repositories { 14 | mavenLocal() 15 | jcenter() 16 | } 17 | 18 | import org.graclj.platform.clj.* 19 | 20 | model { 21 | components { 22 | main(ClojureLibrarySpec) { 23 | dependencies { 24 | module 'org.clojure:clojure:1.8.0' 25 | } 26 | } 27 | } 28 | testSuites { 29 | test(JUnitTestSuiteSpec) { 30 | jUnitVersion '4.12' 31 | testing $.components.main 32 | } 33 | } 34 | } 35 | 36 | publishing { 37 | publications { 38 | main(MavenPublication) { 39 | groupId = 'org.graclj.samples' 40 | version = '0.1.0-SNAPSHOT' 41 | artifact(tasks.createMainJar) 42 | } 43 | } 44 | repositories { 45 | mavenLocal() 46 | maven { 47 | name = 'clojars' 48 | url = 'https://clojars.org/repo' 49 | credentials { 50 | username = clojars_username 51 | password = clojars_password 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /samples/build.gradle: -------------------------------------------------------------------------------- 1 | import java.nio.file.Files 2 | import org.apache.tools.ant.filters.ReplaceTokens 3 | 4 | plugins { 5 | id 'groovy' 6 | } 7 | 8 | dependencies { 9 | testCompile 'org.spockframework:spock-core:1.0-groovy-2.4' 10 | testCompile gradleTestKit() 11 | } 12 | 13 | ext.samplesDir = file("${buildDir}/samples") 14 | 15 | task prepSamples(type: Copy) { 16 | from 'src/projects' 17 | into samplesDir 18 | filter(ReplaceTokens, tokens: [gracljVersion: project.version.toString()]) 19 | } 20 | 21 | task prepProperties { 22 | dependsOn prepSamples 23 | ext.contents = """ 24 | clojars_username=${System.env['CLOJARS_USERNAME']} 25 | clojars_password=${System.env['CLOJARS_PASSWORD']} 26 | """.bytes 27 | doLast { 28 | Files.list(samplesDir.toPath()) 29 | .filter { Files.isDirectory(it) } 30 | .map { sampleDir -> sampleDir.resolve('gradle.properties') } 31 | .forEach { propsFile -> Files.write(propsFile, contents)} 32 | } 33 | } 34 | 35 | test.enabled = false 36 | 37 | ext.supportedGradleVersions = ['2.12-rc-1'] 38 | 39 | supportedGradleVersions.each { supportedGradleVersion -> 40 | ext.taskName = "test${supportedGradleVersion}" 41 | check.dependsOn taskName 42 | tasks.create(taskName, Test) { 43 | dependsOn prepProperties 44 | dependsOn ':modules:graclj-plugin:publishMainPublicationToMavenLocal' 45 | dependsOn ':modules:graclj-tools:publishMainPublicationToMavenLocal' 46 | 47 | systemProperty 'test.projects.root', samplesDir 48 | systemProperty 'test.gradle.version', supportedGradleVersion 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /modules/graclj-plugin/build.gradle: -------------------------------------------------------------------------------- 1 | import orrg.ajoberstar.gradle.hack.GradleDist 2 | import org.apache.tools.ant.filters.ReplaceTokens 3 | 4 | plugins { 5 | id 'groovy' 6 | id 'maven-publish' 7 | id 'com.jfrog.bintray' version '1.6' 8 | } 9 | 10 | configurations.all { 11 | exclude group: 'org.codehaus.groovy' 12 | } 13 | 14 | ext.primaryGradleVersion = '2.12-rc-1' 15 | 16 | dependencies { 17 | compile GradleDist.create(project, primaryGradleVersion).asFileTree 18 | compile gradleApi() 19 | compile localGroovy() 20 | 21 | testCompile 'org.spockframework:spock-core:1.0-groovy-2.4' 22 | testCompile gradleTestKit() 23 | } 24 | 25 | processResources { 26 | filter(ReplaceTokens, tokens: [gracljVersion: project.version.toString()]) 27 | } 28 | 29 | task sourcesJar(type: Jar) { 30 | classifier = 'sources' 31 | from sourceSets.main.allSource 32 | } 33 | 34 | task javadocJar(type: Jar) { 35 | classifier = 'javadoc' 36 | from tasks.javadoc.outputs.files 37 | } 38 | 39 | publishing { 40 | publications { 41 | main(MavenPublication) { 42 | from components.java 43 | artifact sourcesJar 44 | artifact javadocJar 45 | } 46 | } 47 | repositories { 48 | maven { 49 | name = 'test' 50 | url = "${buildDir}/repo" 51 | } 52 | } 53 | } 54 | 55 | test { 56 | dependsOn 'publishMainPublicationToTestRepository' 57 | dependsOn ':modules:graclj-tools:publishMainPublicationToMavenLocal' 58 | systemProperty 'test.plugin.repo', "${buildDir}/repo" 59 | systemProperty 'test.gradle.version', primaryGradleVersion 60 | } 61 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/language/clj/tasks/ClojureCompile.java: -------------------------------------------------------------------------------- 1 | package org.graclj.language.clj.tasks; 2 | 3 | import org.gradle.api.file.FileCollection; 4 | import org.gradle.api.tasks.SourceTask; 5 | import org.gradle.api.tasks.TaskAction; 6 | 7 | import java.io.File; 8 | 9 | public class ClojureCompile extends SourceTask { 10 | private FileCollection compiler = getProject().files(); 11 | private FileCollection classpath = getProject().files(); 12 | private File destinationDir = null; 13 | 14 | @TaskAction 15 | public void compile() { 16 | getProject().copy(spec -> { 17 | spec.from(getSource()); 18 | spec.into(getTemporaryDir()); 19 | }); 20 | getDestinationDir().mkdirs(); 21 | getProject().javaexec(spec -> { 22 | spec.classpath(getCompiler()); 23 | spec.classpath(getClasspath()); 24 | spec.classpath(getTemporaryDir()); 25 | spec.classpath(getDestinationDir()); 26 | 27 | spec.setMain("org.graclj.tools.compiler.clojure"); 28 | 29 | // Location of source 30 | spec.args(getTemporaryDir().getAbsolutePath()); 31 | 32 | // Location to write class files to 33 | spec.args(getDestinationDir().getAbsolutePath()); 34 | }); 35 | } 36 | 37 | public FileCollection getCompiler() { 38 | return compiler; 39 | } 40 | 41 | public void setCompiler(FileCollection compiler) { 42 | this.compiler = compiler; 43 | } 44 | 45 | public FileCollection getClasspath() { 46 | return classpath; 47 | } 48 | 49 | public void setClasspath(FileCollection classpath) { 50 | this.classpath = classpath; 51 | } 52 | 53 | public File getDestinationDir() { 54 | return destinationDir; 55 | } 56 | 57 | public void setDestinationDir(File destinationDir) { 58 | this.destinationDir = destinationDir; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/internal/GracljInternal.java: -------------------------------------------------------------------------------- 1 | package org.graclj.internal; 2 | 3 | import org.gradle.api.artifacts.ConfigurationContainer; 4 | import org.gradle.api.artifacts.Dependency; 5 | import org.gradle.api.artifacts.dsl.DependencyHandler; 6 | import org.gradle.api.file.FileCollection; 7 | import org.gradle.platform.base.DependencySpecContainer; 8 | import org.gradle.platform.base.ModuleDependencySpec; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.UncheckedIOException; 13 | import java.util.Arrays; 14 | import java.util.Properties; 15 | import java.util.stream.Stream; 16 | 17 | public class GracljInternal { 18 | private final ConfigurationContainer configurations; 19 | private final DependencyHandler dependencies; 20 | private final String gracljVersion; 21 | 22 | public GracljInternal(ConfigurationContainer configurations, DependencyHandler dependencies) { 23 | this.configurations = configurations; 24 | this.dependencies = dependencies; 25 | 26 | Properties props = new Properties(); 27 | try (InputStream stream = this.getClass().getResourceAsStream("/org/graclj/version.properties")) { 28 | props.load(stream); 29 | } catch (IOException e) { 30 | throw new UncheckedIOException(e); 31 | } 32 | gracljVersion = props.get("version").toString(); 33 | } 34 | 35 | public String getGracljVersion() { 36 | return gracljVersion; 37 | } 38 | 39 | public FileCollection resolve(DependencySpecContainer specs) { 40 | Stream notations = specs.getDependencies().stream() 41 | .filter(spec -> spec instanceof ModuleDependencySpec) 42 | .map(spec -> (ModuleDependencySpec) spec) 43 | .map(spec -> spec.getGroup() + ":" + spec.getName() + ":" + spec.getVersion()); 44 | return resolve(notations); 45 | } 46 | 47 | public FileCollection resolve(Object... notations) { 48 | return resolve(Arrays.stream(notations)); 49 | } 50 | 51 | public FileCollection resolve(Stream notations) { 52 | // TODO: Should this resolve eagerly? 53 | Dependency[] deps = notations.map(dependencies::create) 54 | .toArray(size -> new Dependency[size]); 55 | return configurations.detachedConfiguration(deps); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/test/clj/plugins/ClojureTestSuiteRules.java: -------------------------------------------------------------------------------- 1 | package org.graclj.test.clj.plugins; 2 | 3 | import org.graclj.internal.GracljInternal; 4 | import org.graclj.testing.clj.ClojureTestSuiteSpec; 5 | import org.gradle.api.Task; 6 | import org.gradle.api.tasks.Copy; 7 | import org.gradle.api.tasks.testing.Test; 8 | import org.gradle.jvm.internal.JvmAssembly; 9 | import org.gradle.jvm.internal.WithJvmAssembly; 10 | import org.gradle.jvm.test.JUnitTestSuiteBinarySpec; 11 | import org.gradle.model.ModelMap; 12 | import org.gradle.model.RuleSource; 13 | import org.gradle.platform.base.BinaryTasks; 14 | import org.gradle.platform.base.ComponentType; 15 | import org.gradle.platform.base.TypeBuilder; 16 | 17 | import java.io.File; 18 | import java.util.stream.Collectors; 19 | import java.util.stream.Stream; 20 | 21 | public class ClojureTestSuiteRules extends RuleSource { 22 | @ComponentType 23 | public void registerTestSuite(TypeBuilder builder) { 24 | // using managed type 25 | } 26 | 27 | @BinaryTasks 28 | public void copyGracljTools(ModelMap tasks, JUnitTestSuiteBinarySpec binary, GracljInternal internal) { 29 | Test testTask = binary.getTasks().getRun(); 30 | 31 | // Need to provide explicit list of directories to scan for test namespaces in. Not sure it should be in this rule. 32 | JvmAssembly assembly = ((WithJvmAssembly) binary).getAssembly(); 33 | Stream classDirs = assembly.getClassDirectories().stream(); 34 | Stream resourceDirs = assembly.getResourceDirectories().stream(); 35 | String testDirs = Stream.concat(classDirs, resourceDirs) 36 | .map(File::getAbsolutePath) 37 | .collect(Collectors.joining(File.pathSeparator)); 38 | testTask.systemProperty("clojure.test.dirs", testDirs); 39 | 40 | tasks.create(binary.getName() + "GracljTools", Copy.class, task -> { 41 | testTask.dependsOn(task); 42 | File tools = internal.resolve("org.graclj:graclj-tools:" + internal.getGracljVersion() + "@jar").getSingleFile(); 43 | task.from(task.getProject().zipTree(tools)); 44 | task.into(binary.getClassesDir()); 45 | }); 46 | testTask.setClasspath(testTask.getClasspath().plus(internal.resolve("org.graclj:graclj-tools:" + internal.getGracljVersion()))); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # graclj 2 | 3 | [![Build Status](https://travis-ci.org/graclj/graclj.svg?branch=master)](https://travis-ci.org/graclj/graclj) 4 | [![Quality Gate](https://sonarqube.ajoberstar.com/api/badges/gate?key=org.graclj:graclj)](https://sonarqube.ajoberstar.com/dashboard/index/org.graclj:graclj) 5 | [![Join the chat at https://gitter.im/graclj/graclj](https://badges.gitter.im/graclj/graclj.svg)](https://gitter.im/graclj/graclj?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 6 | 7 | **NOTE: Use [gradle-clojure](https://github.com/gradle-clojure/gradle-clojure) instead. This is no longer maintained.** 8 | 9 | Clojure plugin for Gradle's Software Model 10 | 11 | Just want to see how to use it? Try [learning-graclj](https://github.com/graclj/learning-graclj/tree/learning-0.1.0) 12 | 13 | **DISCLAIMERS:** 14 | 15 | 1. Graclj should not be considered stable until 1.0.0. Until then, minor versions (e.g. 0.1.0 to 0.2.0) will contain breaking changes. 16 | 2. Currently Graclj only works on nightly versions of Gradle. See the [releases](https://github.com/graclj/graclj/releases) to find the appropriate Gradle version. 17 | 18 | ## Goals 19 | 20 | - Provide a Gradle plugin for Clojure that feels native to Gradle and provides the features the Clojure community has 21 | come to expect from [Leiningen](http://leiningen.org/) and [Boot](http://boot-clj.com/). 22 | - Implement using the new [model space](https://docs.gradle.org/nightly/userguide/new_model.html) in Gradle. 23 | - Determine if/how any work here can be ported or shared with Clojuresque. In the initial stages, this will not be 24 | attempted in order to preserve the flexibility of Graclj. 25 | 26 | ## Background 27 | 28 | Gradle has had very low adoption in the Clojure community: 2% as of the [2014 State of Clojure](https://cognitect.wufoo.com/reports/state-of-clojure-2014-results/) and [2015 State of Clojure](https://www.surveymonkey.com/results/SM-QKBJ2C5J/). 29 | Clojure support is currently provided by [Clojuresque](https://bitbucket.org/clojuresque/), however it's development has stagnated recently. 30 | 31 | Additionally, Gradle continues to evolve with the "foundation of Gradle 3.0" being built on the model space. Which promotes 32 | Gradle's long-standing goal of modelling the build space, while trying to make the interactions between configuration 33 | from various plugins and build scripts more understandable. 34 | 35 | See [the original thread](https://groups.google.com/forum/#!topic/clojuresque/1j24yiOGa30) on the Clojuresque mailing list for 36 | more detail. 37 | 38 | ## Current Features 39 | 40 | ### Clojure 41 | 42 | - Packaging into JARs 43 | - AOT compilation 44 | - clojure.test execution 45 | - Publishing to any repo supported by Gradle (including Clojars) 46 | 47 | ### Clojurescript 48 | 49 | *Coming soon...* 50 | 51 | ## Roadmap 52 | 53 | - [0.2.0](https://github.com/graclj/graclj/milestones/0.2.0) will enhance Clojure support with things like uberjar and REPL support 54 | - [0.3.0](https://github.com/graclj/graclj/milestones/0.3.0) will target ClojureScript builds with the same goal. This is not intended to reconcile the relationship between the two. 55 | - ... 56 | - [1.0.0](https://github.com/graclj/graclj/milestones/1.0.0) ... many more great things ... 57 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/test/groovy/org/graclj/test/clj/plugins/ClojureTestSuitePluginTest.groovy: -------------------------------------------------------------------------------- 1 | package org.graclj.test.clj.plugins 2 | 3 | import org.gradle.testkit.runner.GradleRunner 4 | import org.gradle.testkit.runner.TaskOutcome 5 | import org.junit.Rule 6 | import org.junit.rules.TemporaryFolder 7 | import spock.lang.Specification 8 | 9 | import java.nio.file.Paths 10 | 11 | class ClojureTestSuitePluginTest extends Specification { 12 | private static final URI PLUGIN_REPO = Paths.get(System.properties['test.plugin.repo']).toUri() 13 | 14 | @Rule TemporaryFolder projectDir = new TemporaryFolder() 15 | 16 | GradleRunner runner 17 | 18 | def setup() { 19 | runner = GradleRunner.create() 20 | .withProjectDir(projectDir.root) 21 | .withGradleVersion(System.properties['test.gradle.version']) 22 | 23 | projectDir.newFile('build.gradle') << """ 24 | buildscript { 25 | repositories { 26 | maven { 27 | url = '${PLUGIN_REPO}' 28 | } 29 | } 30 | dependencies { 31 | classpath 'org.graclj:graclj-plugin:+' 32 | } 33 | } 34 | 35 | apply plugin: 'org.graclj.clojure-lang' 36 | apply plugin: 'org.graclj.clojure-test-suite' 37 | 38 | repositories { 39 | jcenter() 40 | mavenLocal() 41 | } 42 | 43 | model { 44 | components { 45 | main(JvmLibrarySpec) { 46 | dependencies { 47 | module 'org.clojure:clojure:1.8.0' 48 | } 49 | } 50 | } 51 | testSuites { 52 | test(JUnitTestSuiteSpec) { 53 | jUnitVersion '4.12' 54 | testing \$.components.main 55 | } 56 | } 57 | } 58 | """ 59 | projectDir.newFolder('src', 'main', 'clojure', 'sample') 60 | projectDir.newFile('src/main/clojure/sample/code.clj') << """ 61 | (ns sample.code 62 | (:require [clojure.string :as str])) 63 | 64 | (defn my-sample [x] (str/reverse x)) 65 | """ 66 | 67 | projectDir.newFolder('src', 'test', 'clojure', 'sample') 68 | projectDir.newFile('src/test/clojure/sample/test.clj') << """ 69 | (ns sample.test 70 | (:require [clojure.test :refer :all] 71 | [sample.code :refer :all])) 72 | 73 | (deftest my-sample-works 74 | (is (= "rac" (my-sample "car")))) 75 | 76 | (deftest my-sample-fails 77 | (is (= "car" (my-sample "car")))) 78 | """ 79 | } 80 | 81 | def 'executing all tests works'() { 82 | when: 'the test task is executed for all tests' 83 | def result = runner 84 | .withArguments('clean', 'components', 'testMainJarBinaryTest', '--stacktrace') 85 | .buildAndFail() 86 | then: 'then one test passes and one succeeds' 87 | result.tasks(TaskOutcome.FAILED)*.path == [':testMainJarBinaryTest'] 88 | result.output =~ /2 tests completed, 1 failed/ 89 | } 90 | 91 | def 'executing some tests works'() { 92 | when: 'the test task is executed for one test' 93 | def result = runner 94 | .withArguments('clean', 'components', 'testMainJarBinaryTest', '--tests', '*.my-sample-works', '--stacktrace') 95 | .build() 96 | then: 'then one test passes' 97 | result.task(':testMainJarBinaryTest').outcome == TaskOutcome.SUCCESS 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/platform/clj/plugins/ClojureComponentRules.java: -------------------------------------------------------------------------------- 1 | package org.graclj.platform.clj.plugins; 2 | 3 | import org.graclj.internal.GracljInternal; 4 | import org.graclj.platform.clj.ClojureApplicationSpec; 5 | import org.graclj.platform.clj.ClojureLibrarySpec; 6 | import org.gradle.api.Task; 7 | import org.gradle.api.file.FileTree; 8 | import org.gradle.jvm.JarBinarySpec; 9 | import org.gradle.jvm.internal.WithJvmAssembly; 10 | import org.gradle.jvm.tasks.Jar; 11 | import org.gradle.model.Defaults; 12 | import org.gradle.model.Each; 13 | import org.gradle.model.Finalize; 14 | import org.gradle.model.ModelMap; 15 | import org.gradle.model.RuleSource; 16 | import org.gradle.platform.base.BinaryTasks; 17 | import org.gradle.platform.base.ComponentType; 18 | import org.gradle.platform.base.TypeBuilder; 19 | 20 | import java.io.File; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | public class ClojureComponentRules extends RuleSource { 25 | @ComponentType 26 | public void registerLibrary(TypeBuilder builder) { 27 | // using managed type 28 | } 29 | 30 | @ComponentType 31 | public void registarApplication(TypeBuilder builder) { 32 | // using managed type 33 | } 34 | 35 | @Defaults 36 | public void applicationDefaults(@Each ClojureApplicationSpec component) { 37 | component.setUberjar(true); 38 | component.setAot(true); 39 | } 40 | 41 | @BinaryTasks 42 | public void uberjarPrep(ModelMap tasks, JarBinarySpec binary, GracljInternal internal) { 43 | if (binary.getLibrary() instanceof ClojureApplicationSpec) { 44 | boolean uberjar = ((ClojureApplicationSpec) binary.getLibrary()).isUberjar(); 45 | if (uberjar) { 46 | String taskName = binary.getTasks().taskName("extractDependencies"); 47 | File destinationDir = binary.getResourcesDir(); 48 | tasks.create(taskName, task -> { 49 | task.setDescription("Extract binary's dependencies for use in an uberjar."); 50 | 51 | task.doLast(t -> { 52 | internal.resolve(binary.getLibrary().getDependencies()).forEach(file -> { 53 | if (file.getName().endsWith(".jar")) { 54 | FileTree tree = task.getProject().zipTree(file); 55 | task.getProject().copy(spec -> { 56 | spec.from(tree); 57 | spec.into(destinationDir); 58 | spec.exclude("project.clj", "META-INF/MANIFEST.MF", "META-INF/NOTICE*", "META-INF/LICENSE*", "META-INF/DEPENDENCIES"); 59 | }); 60 | } 61 | }); 62 | }); 63 | 64 | ((WithJvmAssembly) binary).getAssembly().builtBy(task); 65 | }); 66 | } 67 | } 68 | } 69 | 70 | // TODO this is gross... 71 | @Finalize 72 | public void setMainClass(@Each JarBinarySpec binary) { 73 | if (binary.getLibrary() instanceof ClojureApplicationSpec) { 74 | Map attrs = new HashMap<>(); 75 | 76 | String main = ((ClojureApplicationSpec) binary.getLibrary()).getMain(); 77 | attrs.put("Main-Class", main); 78 | 79 | binary.getTasks().whenObjectAdded(task -> { 80 | if (task instanceof Jar) { 81 | ((Jar) task).getManifest().attributes(attrs); 82 | } 83 | }); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/main/java/org/graclj/language/clj/plugins/ClojureLanguageRules.java: -------------------------------------------------------------------------------- 1 | package org.graclj.language.clj.plugins; 2 | 3 | import org.graclj.internal.GracljInternal; 4 | import org.graclj.language.clj.ClojureSourceSet; 5 | import org.graclj.language.clj.tasks.ClojureCompile; 6 | import org.graclj.platform.clj.ClojureGeneralComponentSpec; 7 | import org.gradle.api.Task; 8 | import org.gradle.jvm.JarBinarySpec; 9 | import org.gradle.jvm.JvmBinarySpec; 10 | import org.gradle.jvm.JvmLibrarySpec; 11 | import org.gradle.jvm.internal.WithJvmAssembly; 12 | import org.gradle.jvm.test.JvmTestSuiteSpec; 13 | import org.gradle.language.jvm.tasks.ProcessResources; 14 | import org.gradle.model.Defaults; 15 | import org.gradle.model.Each; 16 | import org.gradle.model.ModelMap; 17 | import org.gradle.model.RuleSource; 18 | import org.gradle.platform.base.BinaryTasks; 19 | import org.gradle.platform.base.ComponentType; 20 | import org.gradle.platform.base.TypeBuilder; 21 | 22 | public class ClojureLanguageRules extends RuleSource { 23 | @ComponentType 24 | public void registerLanguage(TypeBuilder builder) { 25 | // using managed type 26 | } 27 | 28 | // TODO generalize to JvmComponentSpec when handles getSources 29 | @Defaults 30 | public void addLibrarySourceSets(@Each JvmLibrarySpec component) { 31 | component.getSources().create("clojure", ClojureSourceSet.class); 32 | } 33 | 34 | // TODO generalize to JvmComponentSpec when handles getSources 35 | @Defaults 36 | public void addTestSuiteSourceSets(@Each JvmTestSuiteSpec component) { 37 | component.getSources().create("clojure", ClojureSourceSet.class); 38 | } 39 | 40 | @BinaryTasks 41 | public void createSourceProcessTasks(ModelMap tasks, JvmBinarySpec binary) { 42 | binary.getInputs().withType(ClojureSourceSet.class, sourceSet -> { 43 | String taskName = binary.getTasks().taskName("process", sourceSet.getName()); 44 | tasks.create(taskName, ProcessResources.class, task -> { 45 | task.setDescription(String.format("Compiles %s", sourceSet)); 46 | task.dependsOn(sourceSet); 47 | task.from(sourceSet.getSource()); 48 | task.setDestinationDir(binary.getResourcesDir()); 49 | ((WithJvmAssembly) binary).getAssembly().builtBy(task); 50 | }); 51 | }); 52 | } 53 | 54 | @BinaryTasks 55 | public void createAotCompileTasks(ModelMap tasks, JarBinarySpec binary, GracljInternal internal) { 56 | if (binary.getLibrary() instanceof ClojureGeneralComponentSpec) { 57 | boolean aot = ((ClojureGeneralComponentSpec) binary.getLibrary()).isAot(); 58 | if (aot) { 59 | binary.getInputs().withType(ClojureSourceSet.class, sourceSet -> { 60 | String taskName = binary.getTasks().taskName("compile", sourceSet.getName()); 61 | tasks.create(taskName, ClojureCompile.class, task -> { 62 | task.setDescription(String.format("Compiles %s", sourceSet)); 63 | task.dependsOn(sourceSet); 64 | task.setSource(sourceSet.getSource()); 65 | task.setCompiler(internal.resolve("org.graclj:graclj-tools:" + internal.getGracljVersion())); 66 | task.setClasspath(internal.resolve(binary.getLibrary().getDependencies())); 67 | task.setDestinationDir(binary.getClassesDir()); 68 | ((WithJvmAssembly) binary).getAssembly().builtBy(task); 69 | }); 70 | }); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/test/groovy/org/graclj/language/clj/plugins/ClojureLanguagePluginTest.groovy: -------------------------------------------------------------------------------- 1 | package org.graclj.language.clj.plugins 2 | 3 | import org.gradle.testkit.runner.GradleRunner 4 | import org.junit.Rule 5 | import org.junit.rules.TemporaryFolder 6 | import spock.lang.Specification 7 | 8 | import java.nio.file.Paths 9 | 10 | class ClojureLanguagePluginTest extends Specification { 11 | private static final URI PLUGIN_REPO = Paths.get(System.properties['test.plugin.repo']).toUri() 12 | 13 | @Rule TemporaryFolder projectDir = new TemporaryFolder() 14 | 15 | GradleRunner runner 16 | 17 | def setup() { 18 | runner = GradleRunner.create() 19 | .withProjectDir(projectDir.root) 20 | .withGradleVersion(System.properties['test.gradle.version']) 21 | } 22 | 23 | def 'basic clojure config works'() { 24 | given: 'a build file with basic clojure configuration' 25 | projectDir.newFile('build.gradle') << """ 26 | buildscript { 27 | repositories { 28 | maven { 29 | url = '${PLUGIN_REPO}' 30 | } 31 | } 32 | dependencies { 33 | classpath 'org.graclj:graclj-plugin:+' 34 | } 35 | } 36 | 37 | apply plugin: 'org.graclj.clojure-lang' 38 | apply plugin: 'jvm-component' 39 | apply plugin: 'maven-publish' 40 | 41 | repositories { 42 | jcenter() 43 | mavenLocal() 44 | } 45 | 46 | model { 47 | components { 48 | main(JvmLibrarySpec) { 49 | dependencies { 50 | module 'org.clojure:clojure:1.8.0' 51 | } 52 | } 53 | } 54 | } 55 | 56 | publishing { 57 | publications { 58 | main(MavenPublication) { 59 | groupId = 'org.graclj.sample' 60 | version = '0.1.0' 61 | artifact(tasks.createMainJar) 62 | } 63 | } 64 | repositories { 65 | maven { 66 | name = 'project' 67 | url = file('build/repo') 68 | } 69 | } 70 | } 71 | 72 | import java.nio.file.Files 73 | import java.util.stream.Collectors 74 | 75 | task verifyPublish { 76 | doLast { 77 | def repoDir = file('build/repo').toPath() 78 | def files = Files.walk(repoDir) 79 | .filter { path -> path.getFileName().toString().endsWith('.jar') } 80 | .collect(Collectors.toSet()) 81 | def expected = [ 82 | repoDir.resolve("org/graclj/sample/\${project.name}/0.1.0/\${project.name}-0.1.0.jar"), 83 | ] as Set 84 | 85 | assert files == expected 86 | } 87 | } 88 | 89 | import org.graclj.internal.GracljInternal 90 | 91 | class MyRules extends RuleSource { 92 | @Mutate 93 | void createTask(ModelMap tasks, @Path('binaries.mainJar') JarBinarySpec jar, GracljInternal internal) { 94 | tasks.create('clojureWorks', JavaExec) { 95 | classpath jar.getJarFile() 96 | classpath internal.resolve(jar.getLibrary().getDependencies()) 97 | 98 | main = 'clojure.main' 99 | args '--main', 'sample.yay', 'does', 'it', 'work' 100 | } 101 | } 102 | } 103 | 104 | apply plugin: MyRules 105 | """ 106 | projectDir.newFolder('src', 'main', 'clojure', 'sample') 107 | projectDir.newFile('src/main/clojure/sample/yay.clj') << """ 108 | (ns sample.yay 109 | (:require [clojure.string :as str]) 110 | (:gen-class)) 111 | 112 | (defn my-sample [x] (str/reverse x)) 113 | 114 | (defn -main [& args] 115 | (println (map my-sample args))) 116 | """ 117 | 118 | 119 | when: 'the build task is executed' 120 | def result = runner 121 | .withArguments('clean', 'components', 'build', 'clojureWorks', 'publishMainPublicationToProjectRepository', 'verifyPublish', '--stacktrace') 122 | .build() 123 | then: 'the expected tasks were executed' 124 | result.tasks*.path == [ 125 | ':clean', 126 | ':components', 127 | ':processMainJarClojure', 128 | ':createMainJar', 129 | ':mainApiJar', 130 | ':mainJar', 131 | ':assemble', 132 | ':check', 133 | ':build', 134 | ':clojureWorks', 135 | ':generatePomFileForMainPublication', 136 | ':publishMainPublicationToProjectRepository', 137 | ':verifyPublish' 138 | ] 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >&- 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >&- 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /modules/graclj-tools/src/main/clojure/org/graclj/tools/test/clojure_test.clj: -------------------------------------------------------------------------------- 1 | (ns org.graclj.tools.test.clojure-test 2 | (:require [clojure.test :as test] 3 | [clojure.java.io :as io] 4 | [clojure.tools.namespace.find :refer [find-namespaces]]) 5 | (:import (java.lang.annotation Annotation) 6 | (org.junit.runner Description) 7 | (org.junit.runner.notification Failure) 8 | (java.io File))) 9 | 10 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 11 | ;; JUnit helpers 12 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 13 | 14 | (defn describe-suite [name] 15 | (Description/createSuiteDescription name (into-array Annotation []))) 16 | 17 | (defn describe-test [test-var] 18 | (let [suite (-> test-var meta :ns str) 19 | test (-> test-var meta :name str)] 20 | (Description/createTestDescription suite test (into-array Annotation [])))) 21 | 22 | (defrecord Test [description var]) 23 | 24 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 25 | ;; Report for scanning for test vars. 26 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 27 | (def ^:dynamic *tests* nil) 28 | 29 | (defmulti scan-report :type) 30 | 31 | (defmethod scan-report :begin-test-var [m] 32 | (let [test-var (-> m :var meta :old-var) 33 | description (describe-test test-var) 34 | test (->Test description test-var)] 35 | (swap! *tests* conj test))) 36 | 37 | (defmethod scan-report :default [m] 38 | nil) 39 | 40 | (defn suppress-test-var [real-test-var] 41 | (fn [v] 42 | (let [old-meta (meta v) 43 | new-meta (assoc old-meta :test (fn [& _] nil) :old-var v) 44 | suppressed (with-meta @v new-meta)] 45 | (real-test-var suppressed)))) 46 | 47 | (defn scan-tests [namespaces] 48 | (let [real-test-var test/test-var] 49 | (binding [*tests* (atom []) 50 | test/report scan-report 51 | test/test-var (suppress-test-var real-test-var)] 52 | (apply test/run-tests namespaces) 53 | @*tests*))) 54 | 55 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 56 | ;; Report for notifying JUnit. 57 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 58 | 59 | ;; Bound to a org.junit.runner.notification.RunNotifier 60 | (def ^:dynamic *notifier* nil) 61 | 62 | (def ^:dynamic *current-test* nil) 63 | 64 | (defn fail-message [{:keys [message expected actual]}] 65 | (with-out-str 66 | (if message 67 | (println message) 68 | (println)) 69 | (println "expected: " (pr-str expected)) 70 | (if-not (instance? Throwable actual) 71 | (println "actual: " (prn-str actual))))) 72 | 73 | (defn fail-ex [{:keys [actual] :as m}] 74 | (if (instance? Throwable actual) 75 | (RuntimeException. (fail-message m) actual) 76 | (RuntimeException. (fail-message m)))) 77 | 78 | (defmulti notifier-report :type) 79 | 80 | (defmethod notifier-report :begin-test-var [m] 81 | (let [desc (describe-test (:var m))] 82 | (reset! *current-test* desc) 83 | (.fireTestStarted *notifier* desc))) 84 | 85 | (defmethod notifier-report :end-test-var [m] 86 | (let [desc (describe-test (:var m))] 87 | (reset! *current-test* nil) 88 | (.fireTestFinished *notifier* desc))) 89 | 90 | (defmethod notifier-report :fail [m] 91 | (let [desc @*current-test*] 92 | (.fireTestFailure *notifier* (Failure. desc (fail-ex m))))) 93 | 94 | (defmethod notifier-report :error [m] 95 | (let [desc @*current-test*] 96 | (.fireTestFailure *notifier* (Failure. desc (fail-ex m))))) 97 | 98 | (defmethod notifier-report :default [_] nil) 99 | 100 | (defmacro with-notifier [notifier & body] 101 | `(binding [*notifier* ~notifier 102 | *current-test* (atom nil) 103 | test/report notifier-report] 104 | (do ~@body))) 105 | 106 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 107 | ;; JUnit runner. 108 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 109 | (gen-class 110 | :name org.graclj.tools.test.ClojureTestRunner 111 | :implements [org.junit.runner.manipulation.Filterable] 112 | :extends org.junit.runner.Runner 113 | :constructors {[Class] []} 114 | :init init 115 | :state state) 116 | 117 | (defn -init [clazz] 118 | (let [test-dirs (map #(File. ^String %) 119 | (.split (System/getProperty "clojure.test.dirs") 120 | (File/pathSeparator))) 121 | namespaces (find-namespaces test-dirs)] 122 | (doseq [namespace namespaces] 123 | (require namespace)) 124 | [[] (atom {:parent clazz :tests (scan-tests namespaces)})])) 125 | 126 | (defn -getDescription [this] 127 | (let [suite (describe-suite (-> this .state deref :parent str))] 128 | (doseq [test (-> this .state deref :tests)] 129 | (.addChild suite (:description test))) 130 | suite)) 131 | 132 | (defn -run [this notifier] 133 | (let [test-vars (map :var (-> this .state deref :tests))] 134 | (with-notifier notifier 135 | (test/test-vars test-vars)))) 136 | 137 | (defn -filter [this desc-filter] 138 | (letfn [(run? [test] (->> test :description (.shouldRun desc-filter))) 139 | (trim [tests] (filter run? tests))] 140 | (swap! (.state this) update :tests trim))) 141 | 142 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 143 | ;; Generate suite stub. 144 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 145 | (gen-class 146 | :name ^{org.junit.runner.RunWith org.graclj.tools.test.ClojureTestRunner} clojure.test) 147 | -------------------------------------------------------------------------------- /modules/graclj-plugin/src/test/groovy/org/graclj/platform/clj/plugins/ClojureComponentPluginTest.groovy: -------------------------------------------------------------------------------- 1 | package org.graclj.platform.clj.plugins 2 | 3 | import org.gradle.testkit.runner.GradleRunner 4 | import org.junit.Rule 5 | import org.junit.rules.TemporaryFolder 6 | import spock.lang.Specification 7 | 8 | import java.nio.file.Paths 9 | 10 | class ClojureComponentPluginTest extends Specification { 11 | private static final URI PLUGIN_REPO = Paths.get(System.properties['test.plugin.repo']).toUri() 12 | 13 | @Rule TemporaryFolder projectDir = new TemporaryFolder() 14 | 15 | GradleRunner runner 16 | 17 | def setup() { 18 | runner = GradleRunner.create() 19 | .withProjectDir(projectDir.root) 20 | .withGradleVersion(System.properties['test.gradle.version']) 21 | } 22 | 23 | def 'basic clojure config works'() { 24 | given: 'a build file with basic clojure configuration' 25 | projectDir.newFile('build.gradle') << """ 26 | buildscript { 27 | repositories { 28 | maven { 29 | url = '${PLUGIN_REPO}' 30 | } 31 | } 32 | dependencies { 33 | classpath 'org.graclj:graclj-plugin:+' 34 | } 35 | } 36 | 37 | apply plugin: 'org.graclj.clojure-lang' 38 | apply plugin: 'org.graclj.clojure-component' 39 | apply plugin: 'maven-publish' 40 | 41 | repositories { 42 | jcenter() 43 | mavenLocal() 44 | } 45 | 46 | import org.graclj.platform.clj.* 47 | 48 | model { 49 | components { 50 | main(ClojureLibrarySpec) { 51 | dependencies { 52 | module 'org.clojure:clojure:1.8.0' 53 | } 54 | } 55 | } 56 | } 57 | 58 | publishing { 59 | publications { 60 | main(MavenPublication) { 61 | groupId = 'org.graclj.sample' 62 | version = '0.1.0' 63 | artifact(tasks.createMainJar) 64 | } 65 | } 66 | repositories { 67 | maven { 68 | name = 'project' 69 | url = file('build/repo') 70 | } 71 | } 72 | } 73 | 74 | import java.nio.file.Files 75 | import java.util.stream.Collectors 76 | 77 | task verifyPublish { 78 | doLast { 79 | def repoDir = file('build/repo').toPath() 80 | def files = Files.walk(repoDir) 81 | .filter { path -> path.getFileName().toString().endsWith('.jar') } 82 | .collect(Collectors.toSet()) 83 | def expected = [ 84 | repoDir.resolve("org/graclj/sample/\${project.name}/0.1.0/\${project.name}-0.1.0.jar"), 85 | ] as Set 86 | 87 | assert files == expected 88 | } 89 | } 90 | 91 | import org.graclj.internal.GracljInternal 92 | 93 | class MyRules extends RuleSource { 94 | @Mutate 95 | void createTask(ModelMap tasks, @Path('binaries.mainJar') JarBinarySpec jar, GracljInternal internal) { 96 | tasks.create('clojureWorks', JavaExec) { 97 | classpath jar.getJarFile() 98 | classpath internal.resolve(jar.getLibrary().getDependencies()) 99 | 100 | main = 'clojure.main' 101 | args '--main', 'sample.yay', 'does', 'it', 'work' 102 | } 103 | } 104 | } 105 | 106 | apply plugin: MyRules 107 | """ 108 | projectDir.newFolder('src', 'main', 'clojure', 'sample') 109 | projectDir.newFile('src/main/clojure/sample/yay.clj') << """ 110 | (ns sample.yay 111 | (:require [clojure.string :as str]) 112 | (:gen-class)) 113 | 114 | (defn my-sample [x] (str/reverse x)) 115 | 116 | (defn -main [& args] 117 | (println (map my-sample args))) 118 | """ 119 | 120 | 121 | when: 'the build task is executed' 122 | def result = runner 123 | .withArguments('clean', 'components', 'build', 'clojureWorks', 'publishMainPublicationToProjectRepository', 'verifyPublish', '--stacktrace') 124 | .build() 125 | then: 'the expected tasks were executed' 126 | result.tasks*.path == [ 127 | ':clean', 128 | ':components', 129 | ':processMainJarClojure', 130 | ':createMainJar', 131 | ':mainApiJar', 132 | ':mainJar', 133 | ':assemble', 134 | ':check', 135 | ':build', 136 | ':clojureWorks', 137 | ':generatePomFileForMainPublication', 138 | ':publishMainPublicationToProjectRepository', 139 | ':verifyPublish' 140 | ] 141 | } 142 | 143 | def 'uberjar clojure config works'() { 144 | given: 'a build file with basic clojure configuration' 145 | projectDir.newFile('build.gradle') << """ 146 | buildscript { 147 | repositories { 148 | maven { 149 | url = '${PLUGIN_REPO}' 150 | } 151 | } 152 | dependencies { 153 | classpath 'org.graclj:graclj-plugin:+' 154 | } 155 | } 156 | 157 | apply plugin: 'org.graclj.clojure-lang' 158 | apply plugin: 'org.graclj.clojure-component' 159 | apply plugin: 'maven-publish' 160 | 161 | repositories { 162 | jcenter() 163 | mavenLocal() 164 | } 165 | 166 | import org.graclj.platform.clj.* 167 | 168 | model { 169 | components { 170 | main(ClojureApplicationSpec) { 171 | main = 'sample.yay' 172 | dependencies { 173 | module 'org.clojure:clojure:1.8.0' 174 | } 175 | } 176 | } 177 | } 178 | 179 | publishing { 180 | publications { 181 | main(MavenPublication) { 182 | groupId = 'org.graclj.sample' 183 | version = '0.1.0' 184 | artifact(tasks.createMainJar) 185 | } 186 | } 187 | repositories { 188 | maven { 189 | name = 'project' 190 | url = file('build/repo') 191 | } 192 | } 193 | } 194 | 195 | import java.nio.file.Files 196 | import java.util.stream.Collectors 197 | 198 | task verifyPublish { 199 | doLast { 200 | def repoDir = file('build/repo').toPath() 201 | def files = Files.walk(repoDir) 202 | .filter { path -> path.getFileName().toString().endsWith('.jar') } 203 | .collect(Collectors.toSet()) 204 | def expected = [ 205 | repoDir.resolve("org/graclj/sample/\${project.name}/0.1.0/\${project.name}-0.1.0.jar"), 206 | ] as Set 207 | 208 | assert files == expected 209 | } 210 | } 211 | 212 | import org.graclj.internal.GracljInternal 213 | 214 | class MyRules extends RuleSource { 215 | @Mutate 216 | void createTask(ModelMap tasks, @Path('binaries.mainJar') JarBinarySpec jar, GracljInternal internal) { 217 | tasks.create('clojureWorks', Exec) { 218 | commandLine 'java', '-jar', jar.getJarFile(), 'does', 'it', 'work' 219 | } 220 | } 221 | } 222 | 223 | apply plugin: MyRules 224 | """ 225 | projectDir.newFolder('src', 'main', 'clojure', 'sample') 226 | projectDir.newFile('src/main/clojure/sample/yay.clj') << """ 227 | (ns sample.yay 228 | (:require [clojure.string :as str]) 229 | (:gen-class)) 230 | 231 | (defn my-sample [x] (str/reverse x)) 232 | 233 | (defn -main [& args] 234 | (println (map my-sample args))) 235 | """ 236 | 237 | 238 | when: 'the build task is executed' 239 | def result = runner 240 | .withArguments('clean', 'components', 'build', 'clojureWorks', 'publishMainPublicationToProjectRepository', 'verifyPublish', '--stacktrace') 241 | .build() 242 | then: 'the expected tasks were executed' 243 | result.tasks*.path == [ 244 | ':clean', 245 | ':components', 246 | ':compileMainJarClojure', 247 | ':extractDependenciesMainJar', 248 | ':processMainJarClojure', 249 | ':createMainJar', 250 | ':mainApiJar', 251 | ':mainJar', 252 | ':assemble', 253 | ':check', 254 | ':build', 255 | ':clojureWorks', 256 | ':generatePomFileForMainPublication', 257 | ':publishMainPublicationToProjectRepository', 258 | ':verifyPublish' 259 | ] 260 | } 261 | } 262 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Eclipse Public License - v 1.0 2 | 3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 4 | 5 | 1. DEFINITIONS 6 | 7 | "Contribution" means: 8 | 9 | a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and 10 | b) in the case of each subsequent Contributor: 11 | i) changes to the Program, and 12 | ii) additions to the Program; 13 | where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. 14 | "Contributor" means any person or entity that distributes the Program. 15 | 16 | "Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. 17 | 18 | "Program" means the Contributions distributed in accordance with this Agreement. 19 | 20 | "Recipient" means anyone who receives the Program under this Agreement, including all Contributors. 21 | 22 | 2. GRANT OF RIGHTS 23 | 24 | a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. 25 | b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. 26 | c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. 27 | d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. 28 | 3. REQUIREMENTS 29 | 30 | A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: 31 | 32 | a) it complies with the terms and conditions of this Agreement; and 33 | b) its license agreement: 34 | i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; 35 | ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; 36 | iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and 37 | iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. 38 | When the Program is made available in source code form: 39 | 40 | a) it must be made available under this Agreement; and 41 | b) a copy of this Agreement must be included with each copy of the Program. 42 | Contributors may not remove or alter any copyright notices contained within the Program. 43 | 44 | Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. 45 | 46 | 4. COMMERCIAL DISTRIBUTION 47 | 48 | Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. 49 | 50 | For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. 51 | 52 | 5. NO WARRANTY 53 | 54 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. 55 | 56 | 6. DISCLAIMER OF LIABILITY 57 | 58 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 59 | 60 | 7. GENERAL 61 | 62 | If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. 63 | 64 | If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. 65 | 66 | All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. 67 | 68 | Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. 69 | 70 | This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. 71 | --------------------------------------------------------------------------------