Skip to content

Commit c216b66

Browse files
committed
More changes to correctly generate source links
1 parent 6b304d1 commit c216b66

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

params/clojure-contrib/params.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{:name "clojure-contrib",
66
:file-prefix file-prefix,
77
:root root,
8-
:web-src-dir "http://github.com/clojure/clojure-contrib/blob/",
8+
:web-src-dir "https://github.com/clojure/clojure-contrib/blob/",
99

1010
:web-home "http://clojure.github.com/clojure-contrib/",
1111
:output-path (str file-prefix "/autodoc/"),
@@ -34,7 +34,7 @@
3434
:version "v1.1"
3535
:status "stable"
3636
:params {:built-clojure-jar "/home/tom/src/clj/clojure/clojure-slim.jar"
37-
:load-classpath [(str root "/classes")]}}
37+
:load-classpath [(str root "/src") (str root "/classes")]}}
3838
]
3939

4040
:load-except-list
@@ -48,6 +48,7 @@
4848
#"/javadoc"
4949
#"/jmx/Bean"
5050
#"/test/clojure/clojure/contrib/"
51+
#"/src/main/clojure/clojure/contrib/test_base64"
5152
#"/target/classes/"
5253
#"/target/test-classes/"
5354
],

src/autodoc/branches.clj

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[clojure.java.shell :only [with-sh-dir sh]]
44
[clojure.pprint :only [cl-format pprint]]
55
[clojure.contrib.str-utils :only (re-split)]
6-
[autodoc.params :only (params)]
6+
[autodoc.params :only (params expand-classpath)]
77
[autodoc.build-html :only (branch-subdir)]
88
[autodoc.doc-files :only (xform-tree)])
99

@@ -28,14 +28,6 @@
2828
(system (str "git checkout " branch))
2929
(system (str "git merge origin/" branch))))
3030

31-
(defn expand-wildcards
32-
"Find all the files under root that match re. Not truly wildcard expansion, but..."
33-
[root re]
34-
(if (instance? java.util.regex.Pattern re)
35-
(for [f (file-seq (File. root)) :when (re-find re (.getAbsolutePath f))]
36-
(.getAbsolutePath f))
37-
(list re)))
38-
3931
(defn path-str [path-seq]
4032
(apply str (interpose (System/getProperty "path.separator")
4133
(map #(.getAbsolutePath (file %)) path-seq))))
@@ -63,7 +55,7 @@
6355
"src"
6456
(.getPath (File. (params :root) (params :source-path)))
6557
"."])
66-
(mapcat (partial expand-wildcards (params :root)) (params :load-classpath))
58+
(expand-classpath branch-name (params :root) (params :load-classpath))
6759
(expand-jar-path (params :load-jar-dirs)))
6860
tmp-file (File/createTempFile "collect-" ".clj")]
6961
(exec-clojure class-path

src/autodoc/build_html.clj

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
(:require [clojure.string :as str]
66
[clojure.contrib.str-utils :as cc-str])
77
(:use [net.cgrand.enlive-html :exclude (deftemplate)]
8-
[clojure.java.io :only (file writer)]
8+
[clojure.java.io :only (as-file file writer)]
99
[clojure.java.shell :only (sh)]
1010
[clojure.pprint :only (pprint cl-format)]
1111
[clojure.contrib.json :only (pprint-json)]
1212
[autodoc.collect-info :only (contrib-info)]
13-
[autodoc.params :only (params)]))
13+
[autodoc.params :only (params expand-classpath)]))
1414

1515
(def *layout-file* "layout.html")
1616
(def *master-toc-file* "master-toc.html")
@@ -297,17 +297,36 @@ actually changed). This reduces the amount of random doc file changes that happe
297297
(memoize
298298
(fn [] (.getAbsolutePath (file ".")))))
299299

300+
(def expand-src-file
301+
(memoize
302+
(fn [f branch]
303+
(let [fl (as-file f)]
304+
(if (.isAbsolute fl)
305+
f
306+
(if-let [result (first
307+
(filter #(.exists %)
308+
(map #(File. % f)
309+
(expand-classpath
310+
branch
311+
(params :root)
312+
(params :load-classpath)))))]
313+
(.getAbsolutePath result)
314+
(do
315+
(cl-format *err* "No absolute path for file metadata ~a~%" f)
316+
nil)))))))
317+
300318
(defn var-base-file
301319
"strip off the prepended path to the source directory from the filename"
302-
[f]
303-
(cond
304-
(.startsWith f (params :root)) (.substring f (inc (src-prefix-length)))
305-
(.startsWith f (memoized-working-directory)) (.substring f (inc (.length (memoized-working-directory))))
306-
true (.getPath (file (params :source-path) f))))
320+
[f branch]
321+
(let [f (or (expand-src-file f branch) f)]
322+
(cond
323+
(.startsWith f (params :root)) (.substring f (inc (src-prefix-length)))
324+
(.startsWith f (memoized-working-directory)) (.substring f (inc (.length (memoized-working-directory))))
325+
true (.getPath (file (params :source-path) f)))))
307326

308327
(defn var-src-link [v branch]
309328
(when (and (:file v) (:line v))
310-
(when-let [web-file (web-src-file (var-base-file (:file v)) branch)]
329+
(when-let [web-file (web-src-file (var-base-file (:file v) branch) branch)]
311330
(cl-format nil "~a#L~d" web-file (:line v)))))
312331

313332
;;; TODO: factor out var from namespace and sub-namespace into a separate template.
@@ -465,7 +484,7 @@ vars in ns-info that begin with that letter"
465484
:wiki-url (str (params :web-home) "/" (var-url ns v))
466485
:source-url (var-src-link v branch)
467486
:raw-source-url (when (:file v)
468-
(web-raw-src-file (var-base-file (:file v)) branch))))
487+
(web-raw-src-file (var-base-file (:file v) branch) branch))))
469488

470489
(defn structured-index
471490
"Create a structured index of all the reference information about contrib"

src/autodoc/params.clj

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(ns autodoc.params)
1+
(ns autodoc.params
2+
(import [java.io File]))
23

34
;;;
45
;;; Description and default values for settable parameters. These are overridden in the
@@ -102,3 +103,22 @@
102103
[args]
103104
(let [[params args] (consume extract-arg args)]
104105
[(into {} (for [[p v] params] [p (convert-arg p v)])) (into [] args)]))
106+
107+
(defn expand-wildcards
108+
"Find all the files under root that match re. Not truly wildcard expansion, but..."
109+
[root re]
110+
(if (instance? java.util.regex.Pattern re)
111+
(for [f (file-seq (File. root)) :when (re-find re (.getAbsolutePath f))]
112+
(.getAbsolutePath f))
113+
(list re)))
114+
115+
;;; Expand any regexp patterns in the classpath to the set of
116+
;;; available files. This function is memoized so the filesystem work will
117+
;;; only be done of the first call. The classpath is expanded relative to
118+
;;; the argument root, branch is included to force the memoization to a
119+
;;; single branch
120+
121+
(def expand-classpath
122+
(memoize
123+
(fn [branch root cp]
124+
(mapcat (partial expand-wildcards root) cp))))

0 commit comments

Comments
 (0)