diff --git a/dev-resources/test-0.0.2/test.pom b/dev-resources/test-0.0.2/test.pom index f6777564..05308bcf 100644 --- a/dev-resources/test-0.0.2/test.pom +++ b/dev-resources/test-0.0.2/test.pom @@ -12,4 +12,12 @@ UTF-8 + + + + fake + fake + 0.0.2 + + diff --git a/resources/queries/queryfile.sql b/resources/queries/queryfile.sql index 1eeab963..3a952c1b 100644 --- a/resources/queries/queryfile.sql +++ b/resources/queries/queryfile.sql @@ -295,6 +295,17 @@ WHERE ( version = :version ); +--name: find-dependents +SELECT * +FROM deps +WHERE ( + dep_group_name = :groupname + AND + dep_jar_name = :jarname + AND + dep_version = :version +); + --name: all-projects SELECT DISTINCT group_name, jar_name FROM jars diff --git a/src/clojars/db.clj b/src/clojars/db.clj index f2fd1283..d8e2bc45 100644 --- a/src/clojars/db.clj +++ b/src/clojars/db.clj @@ -278,6 +278,13 @@ :version version} {:connection db})) +(defn find-dependents + [db groupname jarname version] + (sql/find-dependents {:groupname groupname + :jarname jarname + :version version} + {:connection db})) + (defn all-projects [db offset-num limit-num] (sql/all-projects {:num limit-num :offset offset-num} diff --git a/src/clojars/web/jar.clj b/src/clojars/web/jar.clj index 05f9fc11..9ad65946 100644 --- a/src/clojars/web/jar.clj +++ b/src/clojars/web/jar.clj @@ -210,15 +210,23 @@ [:li (dependency-link db dep)])]))) (defn dependencies [db {:keys [group_name jar_name version]}] - (dependency-section db "Dependencies" "dependencies" - (remove #(not= (:scope %) "compile") - (map - #(set/rename-keys % {:dep_group_name :group_name - :dep_jar_name :jar_name - :dep_version :version - :dep_scope :scope}) - (db/find-dependencies db - group_name jar_name version))))) + (dependency-section + db "Dependencies" "dependencies" + (into [] + (comp + (filter #(= (:dep_scope %) "compile")) + (map + #(set/rename-keys % {:dep_group_name :group_name + :dep_jar_name :jar_name + :dep_version :version}))) + (db/find-dependencies db group_name jar_name version)))) + +(defn dependents [db {:keys [group_name jar_name version]}] + (dependency-section + db "Dependents (on Clojars)" "dependents" + (filter + #(= (:dep_scope %) "compile") + (db/find-dependents db group_name jar_name version)))) (defn homepage [{:keys [homepage]}] (when homepage @@ -295,6 +303,8 @@ [:li (versions jar recent-versions count)] (when-let [dependencies (dependencies db jar)] [:li dependencies]) + (when-let [dependents (dependents db jar)] + [:li dependents]) (when-let [homepage (homepage jar)] [:li.homepage homepage]) (when-let [licenses (licenses jar)] diff --git a/test/clojars/integration/jars_test.clj b/test/clojars/integration/jars_test.clj index ee3be3cc..a574934c 100644 --- a/test/clojars/integration/jars_test.clj +++ b/test/clojars/integration/jars_test.clj @@ -87,6 +87,14 @@ (within [:ul#dependencies] (has (text? "org.clojure/clojure 1.3.0-beta1"))))) +(deftest canonical-jars-can-view-dependents + (inject-artifacts-into-repo! help/*db* "someuser" "fake.jar" "fake-0.0.2/fake.pom") + (inject-artifacts-into-repo! help/*db* "someuser" "test.jar" "test-0.0.2/test.pom") + (-> (session (help/app)) + (visit "/fake") + (within [:ul#dependents] + (has (text? "org.clojars.dantheman/test 0.0.2"))))) + (deftest shadow-jars-have-a-message (inject-artifacts-into-repo! help/*db* "someuser" "fake.jar" (help/rewrite-pom (io/file (io/resource "fake-0.0.1/fake.pom")) diff --git a/test/clojars/test_helper.clj b/test/clojars/test_helper.clj index 5bd38ac0..38214426 100644 --- a/test/clojars/test_helper.clj +++ b/test/clojars/test_helper.clj @@ -210,5 +210,4 @@ [params m] `(let [db# (:db (config/config)) audit# (first (db/find-audit db# ~params))] - (prn (db/find-audit db# ~params)) (is (~'match? ~m audit#))))