Meikel  Brandmeyer avatar Meikel Brandmeyer committed 53d898a

Allow inclusion/exclusion based on namespace names

[#4 state:resolved tagged:committed]

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

src/main/groovy/clojuresque/DefaultClojureSourceSet.groovy

 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 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)
         clojure.filter.include("**/*.clj")
 
         clojurePatterns = new PatternSet()
         allClojure = new UnionFileTree(desc, clojure.matching(clojurePatterns))
     }
 
-    public DefaultSourceDirectorySet getClojure() {
+    public ClojureSourceDirectorySet getClojure() {
         return clojure
     }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.