Codebase list java-classpath-clojure / upstream/latest
New upstream version 0.2.3 Apollon Oikonomopoulos 6 years ago
8 changed file(s) with 559 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 target
0 # java.classpath Change Log
1
2
3 ## 0.2.x series
4
5 Latest development version is 0.2.4-SNAPSHOT, current Git `master` branch
6
7 ### Release [0.2.3] on 2015-Nov-06
8
9 * Fix [CLASSPATH-7]: ignore classloaders which do not implement URLClasspath
10
11 ### Release [0.2.2] on 2014-Jan-10
12
13 * Enhancement [CLASSPATH-5]: extensible protocol to other classloaders
14
15 ### Release [0.2.1] on 2013-Jan-18
16
17 * Fix [CLASSPATH-4]: Use io/as-file instead of treating URL as file path
18
19 * Fix [CLASSPATH-3]: Eliminate reflection
20
21 ### Release [0.2.0] on 2011-Sep-15
22
23 * Fix [CLASSPATH-1] & [CLASSPATH-2]: return classpath from all parent classloaders
24
25
26
27 ## 0.1.x series
28
29 ### Release [0.1.2] on 2011-Sep-06
30
31 * Use both java.class.path and Clojure's ClassLoader
32
33 ### Release [0.1.1] on 2011-Apr-28
34
35 * Eliminate relection
36
37 ### Release [0.1.0] on 2011-Apr-22
38
39 * Migrated from `clojure.contrib.classpath` and `clojure.contrib.jar`
40 in legacy [clojure-contrib](https://github.com/clojure/clojure-contrib)
41
42
43
44 [CLASSPATH-7]: http://dev.clojure.org/jira/browse/CLASSPATH-7
45 [CLASSPATH-6]: http://dev.clojure.org/jira/browse/CLASSPATH-6
46 [CLASSPATH-5]: http://dev.clojure.org/jira/browse/CLASSPATH-5
47 [CLASSPATH-4]: http://dev.clojure.org/jira/browse/CLASSPATH-4
48 [CLASSPATH-3]: http://dev.clojure.org/jira/browse/CLASSPATH-3
49 [CLASSPATH-2]: http://dev.clojure.org/jira/browse/CLASSPATH-2
50 [CLASSPATH-1]: http://dev.clojure.org/jira/browse/CLASSPATH-1
51
52 [0.2.3]: https://github.com/clojure/java.classpath/tree/java.classpath-0.2.3
53 [0.2.2]: https://github.com/clojure/java.classpath/tree/java.classpath-0.2.2
54 [0.2.1]: https://github.com/clojure/java.classpath/tree/java.classpath-0.2.1
55 [0.2.0]: https://github.com/clojure/java.classpath/tree/java.classpath-0.2.0
56 [0.1.2]: https://github.com/clojure/java.classpath/tree/java.classpath-0.1.2
57 [0.1.1]: https://github.com/clojure/java.classpath/tree/java.classpath-0.1.1
58 [0.1.0]: https://github.com/clojure/java.classpath/tree/java.classpath-0.1.0
59
0 This is a [Clojure contrib] project.
1
2 Under the Clojure contrib [guidelines], this project cannot accept
3 pull requests. All patches must be submitted via [JIRA].
4
5 See [Contributing] and the [FAQ] on the Clojure development [wiki] for
6 more information on how to contribute.
7
8 [Clojure contrib]: http://dev.clojure.org/display/doc/Clojure+Contrib
9 [Contributing]: http://dev.clojure.org/display/community/Contributing
10 [FAQ]: http://dev.clojure.org/display/community/Contributing+FAQ
11 [JIRA]: http://dev.clojure.org/jira/browse/CLASSPATH
12 [guidelines]: http://dev.clojure.org/display/community/Guidelines+for+Clojure+Contrib+committers
13 [wiki]: http://dev.clojure.org/
0 # java.classpath
1
2 Examine the Java classpath from Clojure programs.
3
4
5 ## Releases and Dependency Information
6
7 Latest stable release is 0.2.3
8
9 [Leiningen] dependency information:
10
11 [org.clojure/java.classpath "0.2.3"]
12
13 [Maven] dependency information:
14
15 <dependency>
16 <groupId>org.clojure</groupId>
17 <artifactId>java.classpath</artifactId>
18 <version>0.2.3</version>
19 </dependency>
20
21 [Gradle] dependency information:
22
23 compile "org.clojure:java.classpath:0.2.3"
24
25 [Leiningen]: http://leiningen.org/
26 [Maven]: http://maven.apache.org/
27 [Gradle]: http://www.gradle.org/
28
29 Other versions:
30
31 * [All Released Versions](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22java.classpath%22)
32
33 * [Development SNAPSHOTs](https://oss.sonatype.org/index.html#nexus-search;gav~org.clojure~java.classpath~~~)
34
35 * [How to get Development SNAPSHOTs](http://dev.clojure.org/display/doc/Maven+Settings+and+Repositories)
36
37 Releases are published to the [Maven Central Repository](http://search.maven.org/)
38
39 Development SNAPSHOTs are published to the [Sonatype Open-Source Repository](https://oss.sonatype.org/)
40
41
42 ## Usage
43
44 See the [API Documentation](http://clojure.github.com/java.classpath/)
45
46 Examples:
47
48 ```clojure
49 (require '[clojure.java.classpath :as cp])
50
51 (cp/classpath)
52 ;; (#<File /foo/test> #<File /foo/src> ...)
53 ```
54
55 The `classpath` function returns a sequence of java.io.File objects
56 representing all JAR files and directories on the classpath. It
57 defaults to using the classpath of Clojure's base
58 [ClassLoader](http://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html).
59
60 `classpath` also takes a ClassLoader as an optional argument.
61
62 Alternatively, the `system-classpath` function returns a sequence of
63 java.io.File objects parsed from the `java.class.path` Java system
64 property.
65
66 If you are using an environment which provides its own ClassLoader
67 implementation, such as a Java application server, you can extend the
68 protocol `URLClasspath` to support it. Refer to the source for
69 details.
70
71
72 ## Developer Information
73
74 * [Change log](CHANGES.md)
75
76 * [GitHub project](https://github.com/clojure/java.classpath)
77
78 * [How to contribute](http://dev.clojure.org/display/community/Contributing)
79
80 * [Bug Tracker](http://dev.clojure.org/jira/browse/CLASSPATH)
81
82 * [Continuous Integration](http://build.clojure.org/job/java.classpath/)
83
84 * [Compatibility Test Matrix](http://build.clojure.org/job/java.classpath-test-matrix/)
85
86
87
88 ## Copyright and License
89
90 Copyright (c) 2013 Rich Hickey, Stuart Sierra, and contributors. All
91 rights reserved. The use and distribution terms for this software are
92 covered by the Eclipse Public License 1.0
93 (http://opensource.org/licenses/eclipse-1.0.php) which can be found in
94 the file epl.html at the root of this distribution. By using this
95 software in any fashion, you are agreeing to be bound by the terms of
96 this license. You must not remove this notice, or any other, from this
97 software.
0 <?xml version="1.0" encoding="ISO-8859-1" ?>
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
6 <title>Eclipse Public License - Version 1.0</title>
7 <style type="text/css">
8 body {
9 size: 8.5in 11.0in;
10 margin: 0.25in 0.5in 0.25in 0.5in;
11 tab-interval: 0.5in;
12 }
13 p {
14 margin-left: auto;
15 margin-top: 0.5em;
16 margin-bottom: 0.5em;
17 }
18 p.list {
19 margin-left: 0.5in;
20 margin-top: 0.05em;
21 margin-bottom: 0.05em;
22 }
23 </style>
24
25 </head>
26
27 <body lang="EN-US">
28
29 <h2>Eclipse Public License - v 1.0</h2>
30
31 <p>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
32 PUBLIC LICENSE (&quot;AGREEMENT&quot;). ANY USE, REPRODUCTION OR
33 DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
34 AGREEMENT.</p>
35
36 <p><b>1. DEFINITIONS</b></p>
37
38 <p>&quot;Contribution&quot; means:</p>
39
40 <p class="list">a) in the case of the initial Contributor, the initial
41 code and documentation distributed under this Agreement, and</p>
42 <p class="list">b) in the case of each subsequent Contributor:</p>
43 <p class="list">i) changes to the Program, and</p>
44 <p class="list">ii) additions to the Program;</p>
45 <p class="list">where such changes and/or additions to the Program
46 originate from and are distributed by that particular Contributor. A
47 Contribution 'originates' from a Contributor if it was added to the
48 Program by such Contributor itself or anyone acting on such
49 Contributor's behalf. Contributions do not include additions to the
50 Program which: (i) are separate modules of software distributed in
51 conjunction with the Program under their own license agreement, and (ii)
52 are not derivative works of the Program.</p>
53
54 <p>&quot;Contributor&quot; means any person or entity that distributes
55 the Program.</p>
56
57 <p>&quot;Licensed Patents&quot; mean patent claims licensable by a
58 Contributor which are necessarily infringed by the use or sale of its
59 Contribution alone or when combined with the Program.</p>
60
61 <p>&quot;Program&quot; means the Contributions distributed in accordance
62 with this Agreement.</p>
63
64 <p>&quot;Recipient&quot; means anyone who receives the Program under
65 this Agreement, including all Contributors.</p>
66
67 <p><b>2. GRANT OF RIGHTS</b></p>
68
69 <p class="list">a) Subject to the terms of this Agreement, each
70 Contributor hereby grants Recipient a non-exclusive, worldwide,
71 royalty-free copyright license to reproduce, prepare derivative works
72 of, publicly display, publicly perform, distribute and sublicense the
73 Contribution of such Contributor, if any, and such derivative works, in
74 source code and object code form.</p>
75
76 <p class="list">b) Subject to the terms of this Agreement, each
77 Contributor hereby grants Recipient a non-exclusive, worldwide,
78 royalty-free patent license under Licensed Patents to make, use, sell,
79 offer to sell, import and otherwise transfer the Contribution of such
80 Contributor, if any, in source code and object code form. This patent
81 license shall apply to the combination of the Contribution and the
82 Program if, at the time the Contribution is added by the Contributor,
83 such addition of the Contribution causes such combination to be covered
84 by the Licensed Patents. The patent license shall not apply to any other
85 combinations which include the Contribution. No hardware per se is
86 licensed hereunder.</p>
87
88 <p class="list">c) Recipient understands that although each Contributor
89 grants the licenses to its Contributions set forth herein, no assurances
90 are provided by any Contributor that the Program does not infringe the
91 patent or other intellectual property rights of any other entity. Each
92 Contributor disclaims any liability to Recipient for claims brought by
93 any other entity based on infringement of intellectual property rights
94 or otherwise. As a condition to exercising the rights and licenses
95 granted hereunder, each Recipient hereby assumes sole responsibility to
96 secure any other intellectual property rights needed, if any. For
97 example, if a third party patent license is required to allow Recipient
98 to distribute the Program, it is Recipient's responsibility to acquire
99 that license before distributing the Program.</p>
100
101 <p class="list">d) Each Contributor represents that to its knowledge it
102 has sufficient copyright rights in its Contribution, if any, to grant
103 the copyright license set forth in this Agreement.</p>
104
105 <p><b>3. REQUIREMENTS</b></p>
106
107 <p>A Contributor may choose to distribute the Program in object code
108 form under its own license agreement, provided that:</p>
109
110 <p class="list">a) it complies with the terms and conditions of this
111 Agreement; and</p>
112
113 <p class="list">b) its license agreement:</p>
114
115 <p class="list">i) effectively disclaims on behalf of all Contributors
116 all warranties and conditions, express and implied, including warranties
117 or conditions of title and non-infringement, and implied warranties or
118 conditions of merchantability and fitness for a particular purpose;</p>
119
120 <p class="list">ii) effectively excludes on behalf of all Contributors
121 all liability for damages, including direct, indirect, special,
122 incidental and consequential damages, such as lost profits;</p>
123
124 <p class="list">iii) states that any provisions which differ from this
125 Agreement are offered by that Contributor alone and not by any other
126 party; and</p>
127
128 <p class="list">iv) states that source code for the Program is available
129 from such Contributor, and informs licensees how to obtain it in a
130 reasonable manner on or through a medium customarily used for software
131 exchange.</p>
132
133 <p>When the Program is made available in source code form:</p>
134
135 <p class="list">a) it must be made available under this Agreement; and</p>
136
137 <p class="list">b) a copy of this Agreement must be included with each
138 copy of the Program.</p>
139
140 <p>Contributors may not remove or alter any copyright notices contained
141 within the Program.</p>
142
143 <p>Each Contributor must identify itself as the originator of its
144 Contribution, if any, in a manner that reasonably allows subsequent
145 Recipients to identify the originator of the Contribution.</p>
146
147 <p><b>4. COMMERCIAL DISTRIBUTION</b></p>
148
149 <p>Commercial distributors of software may accept certain
150 responsibilities with respect to end users, business partners and the
151 like. While this license is intended to facilitate the commercial use of
152 the Program, the Contributor who includes the Program in a commercial
153 product offering should do so in a manner which does not create
154 potential liability for other Contributors. Therefore, if a Contributor
155 includes the Program in a commercial product offering, such Contributor
156 (&quot;Commercial Contributor&quot;) hereby agrees to defend and
157 indemnify every other Contributor (&quot;Indemnified Contributor&quot;)
158 against any losses, damages and costs (collectively &quot;Losses&quot;)
159 arising from claims, lawsuits and other legal actions brought by a third
160 party against the Indemnified Contributor to the extent caused by the
161 acts or omissions of such Commercial Contributor in connection with its
162 distribution of the Program in a commercial product offering. The
163 obligations in this section do not apply to any claims or Losses
164 relating to any actual or alleged intellectual property infringement. In
165 order to qualify, an Indemnified Contributor must: a) promptly notify
166 the Commercial Contributor in writing of such claim, and b) allow the
167 Commercial Contributor to control, and cooperate with the Commercial
168 Contributor in, the defense and any related settlement negotiations. The
169 Indemnified Contributor may participate in any such claim at its own
170 expense.</p>
171
172 <p>For example, a Contributor might include the Program in a commercial
173 product offering, Product X. That Contributor is then a Commercial
174 Contributor. If that Commercial Contributor then makes performance
175 claims, or offers warranties related to Product X, those performance
176 claims and warranties are such Commercial Contributor's responsibility
177 alone. Under this section, the Commercial Contributor would have to
178 defend claims against the other Contributors related to those
179 performance claims and warranties, and if a court requires any other
180 Contributor to pay any damages as a result, the Commercial Contributor
181 must pay those damages.</p>
182
183 <p><b>5. NO WARRANTY</b></p>
184
185 <p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
186 PROVIDED ON AN &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS
187 OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
188 ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
189 OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
190 responsible for determining the appropriateness of using and
191 distributing the Program and assumes all risks associated with its
192 exercise of rights under this Agreement , including but not limited to
193 the risks and costs of program errors, compliance with applicable laws,
194 damage to or loss of data, programs or equipment, and unavailability or
195 interruption of operations.</p>
196
197 <p><b>6. DISCLAIMER OF LIABILITY</b></p>
198
199 <p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
200 NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
201 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
202 WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
203 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
204 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
205 DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
206 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p>
207
208 <p><b>7. GENERAL</b></p>
209
210 <p>If any provision of this Agreement is invalid or unenforceable under
211 applicable law, it shall not affect the validity or enforceability of
212 the remainder of the terms of this Agreement, and without further action
213 by the parties hereto, such provision shall be reformed to the minimum
214 extent necessary to make such provision valid and enforceable.</p>
215
216 <p>If Recipient institutes patent litigation against any entity
217 (including a cross-claim or counterclaim in a lawsuit) alleging that the
218 Program itself (excluding combinations of the Program with other
219 software or hardware) infringes such Recipient's patent(s), then such
220 Recipient's rights granted under Section 2(b) shall terminate as of the
221 date such litigation is filed.</p>
222
223 <p>All Recipient's rights under this Agreement shall terminate if it
224 fails to comply with any of the material terms or conditions of this
225 Agreement and does not cure such failure in a reasonable period of time
226 after becoming aware of such noncompliance. If all Recipient's rights
227 under this Agreement terminate, Recipient agrees to cease use and
228 distribution of the Program as soon as reasonably practicable. However,
229 Recipient's obligations under this Agreement and any licenses granted by
230 Recipient relating to the Program shall continue and survive.</p>
231
232 <p>Everyone is permitted to copy and distribute copies of this
233 Agreement, but in order to avoid inconsistency the Agreement is
234 copyrighted and may only be modified in the following manner. The
235 Agreement Steward reserves the right to publish new versions (including
236 revisions) of this Agreement from time to time. No one other than the
237 Agreement Steward has the right to modify this Agreement. The Eclipse
238 Foundation is the initial Agreement Steward. The Eclipse Foundation may
239 assign the responsibility to serve as the Agreement Steward to a
240 suitable separate entity. Each new version of the Agreement will be
241 given a distinguishing version number. The Program (including
242 Contributions) may always be distributed subject to the version of the
243 Agreement under which it was received. In addition, after a new version
244 of the Agreement is published, Contributor may elect to distribute the
245 Program (including its Contributions) under the new version. Except as
246 expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
247 rights or licenses to the intellectual property of any Contributor under
248 this Agreement, whether expressly, by implication, estoppel or
249 otherwise. All rights in the Program not expressly granted under this
250 Agreement are reserved.</p>
251
252 <p>This Agreement is governed by the laws of the State of New York and
253 the intellectual property laws of the United States of America. No party
254 to this Agreement will bring a legal action under this Agreement more
255 than one year after the cause of action arose. Each party waives its
256 rights to a jury trial in any resulting litigation.</p>
257
258 </body>
259
260 </html>
0 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1 <modelVersion>4.0.0</modelVersion>
2 <artifactId>java.classpath</artifactId>
3 <version>0.2.3</version>
4 <name>${project.artifactId}</name>
5
6 <parent>
7 <groupId>org.clojure</groupId>
8 <artifactId>pom.contrib</artifactId>
9 <version>0.1.2</version>
10 </parent>
11
12 <developers>
13 <developer>
14 <name>Stuart Sierra</name>
15 </developer>
16 </developers>
17
18 <scm>
19 <connection>scm:git:git@github.com:clojure/java.classpath.git</connection>
20 <developerConnection>scm:git:git@github.com:clojure/java.classpath.git</developerConnection>
21 <url>git@github.com:clojure/java.classpath.git</url>
22 <tag>java.classpath-0.2.3</tag>
23 </scm>
24 </project>
0 ;;; classpath.clj: utilities for working with the Java class path
1
2 ;; by Stuart Sierra, http://stuartsierra.com/
3 ;; April 19, 2009
4
5 ;; Copyright (c) Rich Hickey, Stuart Sierra, and contributors.
6 ;; All rights reserved. The use
7 ;; and distribution terms for this software are covered by the Eclipse
8 ;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
9 ;; which can be found in the file epl-v10.html at the root of this
10 ;; distribution. By using this software in any fashion, you are
11 ;; agreeing to be bound by the terms of this license. You must not
12 ;; remove this notice, or any other, from this software.
13
14
15 (ns
16 ^{:author "Stuart Sierra"
17 :doc "Utilities for dealing with the JVM's classpath"}
18 clojure.java.classpath
19 (:require [clojure.java.io :as io])
20 (:import (java.io File)
21 (java.util.jar JarFile JarEntry)
22 (java.net URL URLClassLoader)))
23
24 (defprotocol URLClasspath
25 (urls [loader]
26 "Returns a sequence of java.net.URL objects representing locations
27 which this classloader will search for classes and resources."))
28
29 (extend-type java.net.URLClassLoader
30 URLClasspath
31 (urls [loader] (seq (.getURLs loader))))
32
33 (defn get-urls
34 "Returns a sequence of java.net.URL objects used by this
35 classloader, or nil if the classloader does not sastify the
36 URLClasspath protocol."
37 [loader]
38 (when (satisfies? URLClasspath loader)
39 (urls loader)))
40
41 (defn jar-file?
42 "Returns true if file is a normal file with a .jar or .JAR extension."
43 [f]
44 (let [file (io/file f)]
45 (and (.isFile file)
46 (or (.endsWith (.getName file) ".jar")
47 (.endsWith (.getName file) ".JAR")))))
48
49 (defn filenames-in-jar
50 "Returns a sequence of Strings naming the non-directory entries in
51 the JAR file."
52 [^JarFile jar-file]
53 (map #(.getName ^JarEntry %)
54 (filter #(not (.isDirectory ^JarEntry %))
55 (enumeration-seq (.entries jar-file)))))
56
57 (defn system-classpath
58 "Returns a sequence of File paths from the 'java.class.path' system
59 property."
60 []
61 (map #(File. ^String %)
62 (.split (System/getProperty "java.class.path")
63 (System/getProperty "path.separator"))))
64
65 (defn loader-classpath
66 "Returns a sequence of File paths from a classloader."
67 [loader]
68 (map io/as-file (get-urls loader)))
69
70 (defn classpath
71 "Returns a sequence of File objects of the elements on the classpath."
72 ([classloader]
73 (distinct
74 (mapcat
75 loader-classpath
76 (take-while
77 identity
78 (iterate #(.getParent ^ClassLoader %) classloader)))))
79 ([] (classpath (clojure.lang.RT/baseLoader))))
80
81 (defn classpath-directories
82 "Returns a sequence of File objects for the directories on classpath."
83 []
84 (filter #(.isDirectory ^File %) (classpath)))
85
86 (defn classpath-jarfiles
87 "Returns a sequence of JarFile objects for the JAR files on classpath."
88 []
89 (map #(JarFile. ^File %) (filter jar-file? (classpath))))
0 (ns clojure.java.classpath-test
1 (:require
2 [clojure.java.classpath :as classpath]
3 [clojure.test :as test]))
4
5 (test/deftest classpath-test
6 (test/is (every? #(instance? java.io.File %) (classpath/classpath))
7 "returns File objects")
8 (test/is (seq (classpath/classpath))
9 "returns a non empty sequence"))