Meikel Brandmeyer  committed 53d898a

Allow inclusion/exclusion based on namespace names

[#4 state:resolved tagged:committed]

  • Participants
  • Parent commits 23505c1

Comments (0)

Files changed (2)

 ## Caveats
-* Sitting between the chairs of [Clojure][clj]'s namespace based and the
-  other languages file based compilation, you have to include or exclude
-  namespaces based on filenames for now.
 * Automatic recognition of namespaces only works if the `ns` form is the
   first in the file. Comments may precede the form. The symbol is allowed
   to be fully qualified: `clojure.core/ns`.
 From now on you can skip the whole `buildscript` stuff and just use
 `usePlugin('clojure')` to load the plugin.
+## Filter
+In the filesets you can specify filters with `include` resp. `exclude`.
+This is fine for mostly file based languages. However clojure is strongly
+based on namespaces. Therefor the clojure part of the source sets support
+also `includeNamespace` and `excludeNamespace` which can be used to filter
+on the namespace name. Eg. to exclude examples from the final jar one
+could use
+    sourceSets.main.clojure {
+        excludeNamespace 'my.project.examples.**.*'
+    }
 ## Clojars Deployment
 **Note: Does work only on Unix/Mac OS via shell out to scp. Does not

File src/main/groovy/clojuresque/DefaultClojureSourceSet.groovy

 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 DefaultSourceDirectorySet clojure
+    private ClojureSourceDirectorySet clojure
     private PatternSet clojurePatterns
     private UnionFileTree allClojure
             FileResolver fileResolver) {
         String desc = String.format("%s Clojure source", displayName)
-        clojure = new DefaultSourceDirectorySet(desc, fileResolver)
+        clojure = new ClojureSourceDirectorySet(desc, fileResolver)
         clojurePatterns = new PatternSet()
         allClojure = new UnionFileTree(desc, clojure.matching(clojurePatterns))
-    public DefaultSourceDirectorySet getClojure() {
+    public ClojureSourceDirectorySet getClojure() {
         return clojure