-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move feed generation into main codebase [#456]
This integrates code from an old POC rewrite of clojars that only existed on the server, and was used to generate `/repo/feed.clj.gz`.
- Loading branch information
Showing
7 changed files
with
201 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
(ns clojars.tools.generate-feed | ||
(:require [clojure.java.io :as io] | ||
[clojars.maven :as maven] | ||
[clojure.set :as set]) | ||
(:import java.util.zip.GZIPOutputStream | ||
(java.io FileOutputStream PrintWriter))) | ||
|
||
(defn pom-seq [repo] | ||
(for [f (file-seq repo) | ||
:when (and (not (re-matches #".*/\..*" (str f))) | ||
(.endsWith (.getName f) ".pom")) | ||
:let [pom (try | ||
(-> (maven/pom-to-map f) | ||
(update :scm maven/scm-to-map) | ||
maven/without-nil-values) | ||
(catch Exception e (.printStackTrace e)))] | ||
:when pom] | ||
pom)) | ||
|
||
(defn full-feed [repo] | ||
(let [grouped-jars (->> (pom-seq repo) | ||
(map (comp #(select-keys % [:group-id :artifact-id :version | ||
:description :scm :url | ||
:homepage]) | ||
#(set/rename-keys % {:group :group-id | ||
:name :artifact-id}))) | ||
(group-by (juxt :group-id :artifact-id)) | ||
(vals))] | ||
(for [jars grouped-jars] | ||
(let [jars (sort-by :version #(maven/compare-versions %2 %1) jars)] | ||
(-> (first jars) | ||
(dissoc :version) | ||
(assoc :versions (vec (distinct (map :version jars))))))))) | ||
|
||
(defn write-feed! [feed f] | ||
(with-open [w (-> (FileOutputStream. f) | ||
(GZIPOutputStream.) | ||
(PrintWriter.))] | ||
(binding [*out* w] | ||
(doseq [form feed] | ||
(prn form))))) | ||
|
||
(defn -main [repo dest] | ||
(write-feed! (full-feed (io/file repo)) (str dest "/feed.clj.gz"))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(ns clojars.test.unit.tools.generate-feed | ||
(:require [clojars.tools.generate-feed :refer :all] | ||
[clojars.config :refer [config]] | ||
[clojure.test :refer :all] | ||
[clojars.test.test-helper :as help] | ||
[clojure.java.io :as io])) | ||
|
||
(use-fixtures :each help/default-fixture) | ||
|
||
(defn setup-repo [] | ||
(doseq [name ["fake" "test"] | ||
version ["0.0.1" "0.0.2" "0.0.3-SNAPSHOT"] | ||
:let [dest-file (io/file (:repo config) | ||
(format "%s/%s/%s/%s-%s.pom" name name version name version))]] | ||
(.mkdirs (.getParentFile dest-file)) | ||
(io/copy (io/reader (io/resource (format "%s-%s/%s.pom" name version name))) | ||
dest-file))) | ||
|
||
(deftest feed-generation-should-work | ||
(setup-repo) | ||
(let [expected [{:description "FAKE" | ||
:group-id "fake" | ||
:artifact-id "fake" | ||
:versions ["0.0.3-SNAPSHOT" "0.0.2" "0.0.1"]} | ||
{:description "TEST" | ||
:scm {:connection "scm:git:git://github.com/fake/test.git" | ||
:developer-connection "scm:git:ssh://[email protected]/fake/test.git" | ||
:tag "70470ff6ae74505bdbfe5955fca6797f613c113c" | ||
:url "https://github.com/fake/test"} | ||
:group-id "fake" | ||
:artifact-id "test" | ||
:url "http://example.com" | ||
:homepage "http://example.com" | ||
:versions ["0.0.3-SNAPSHOT" "0.0.2" "0.0.1"]}]] | ||
(is (= expected (full-feed (io/file (:repo config))))))) |