mikera
mikera

Reputation: 106351

Get Clojure namespaces in current .jar file

I'm looking for a way to get a list of all the current namespaces in the current project, i.e. excluding namespaces in imported jars, libraries etc.

Currently I have found bultitude which seems pretty close to what I need and can do:

(bultitude.core/namespaces-on-classpath)

However this returns all the namespaces on the classpath, including "clojure.core" etc. rather than just the ones in the current project.

Is there an easy and reliable way to solve this?

Upvotes: 1

Views: 392

Answers (2)

Rayne
Rayne

Reputation: 32625

Well, it depends.

The idea behind bultitude is to provide a list of namespaces on the classpath. Any .clj files on that classpath will be accounted for.

You can, however, look up only namespaces beginning with a certain prefix. Usually projects also begin with a certain prefix in their namespaces. Would that work? Example from the readme:

user=> (b/namespaces-on-classpath :prefix "bultitude")
(bultitude.core-test bultitude.core)

If that isn't good enough, you can try to give it a classpath that only your files are on, but that may not work so well.

user=> (b/namespaces-on-classpath :prefix "bultitude" :classpath "src:test")
(bultitude.core bultitude.core-test)

Upvotes: 1

number23_cn
number23_cn

Reputation: 4619

what about the tools.namespace lib? there are the api:

find-namespaces-in-dir
find-namespaces-in-jarfile
find-namespaces-on-classpath

Upvotes: 2

Related Questions