Skip to content

Commit

Permalink
Show dependents on the jar page
Browse files Browse the repository at this point in the history
This will show other Clojars project versions that depend on the jar
project version being viewed.

See #814
  • Loading branch information
tobias committed Oct 26, 2021
1 parent 5144fc8 commit 6bd6579
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
8 changes: 8 additions & 0 deletions dev-resources/test-0.0.2/test.pom
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>fake</groupId>
<artifactId>fake</artifactId>
<version>0.0.2</version>
</dependency>
</dependencies>
</project>
11 changes: 11 additions & 0 deletions resources/queries/queryfile.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/clojars/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
31 changes: 22 additions & 9 deletions src/clojars/web/jar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,26 @@
[: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
(map
#(set/rename-keys % {:dep_group_name :group_name
:dep_jar_name :jar_name
:dep_version :version
:dep_scope :scope}))
(filter #(= (:scope %) "compile")))
(db/find-dependencies db group_name jar_name version))))

(defn dependents [db {:keys [group_name jar_name version]}]
(dependency-section
db "Dependents" "dependents"
(into []
(comp
(map #(set/rename-keys % {:dep_scope :scope}))
(filter #(= (:scope %) "compile")))
(db/find-dependents db group_name jar_name version))))

(defn homepage [{:keys [homepage]}]
(when homepage
Expand Down Expand Up @@ -295,6 +306,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)]
Expand Down
8 changes: 8 additions & 0 deletions test/clojars/integration/jars_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 6bd6579

Please sign in to comment.