Skip to content

Commit

Permalink
Add tests from pedantic lib as well.
Browse files Browse the repository at this point in the history
Fix HTTP-using jar test.
  • Loading branch information
technomancy committed May 26, 2017
1 parent bcfeee5 commit 3385971
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 22 deletions.
170 changes: 170 additions & 0 deletions leiningen-core/test/leiningen/core/test/pedantic.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
(ns leiningen.core.test.pedantic
(:require [clojure.test :refer :all]
[clojure.java.io :as io]
[leiningen.core.pedantic :as pedantic]
[cemerick.pomegranate.aether :as aether]))

(def tmp-dir (io/file
(System/getProperty "java.io.tmpdir") "pedantic"))
(def tmp-local-repo-dir (io/file tmp-dir "local-repo"))
(defn delete-recursive
[dir]
(when (.isDirectory dir)
(doseq [file (.listFiles dir)]
(delete-recursive file)))
(.delete dir))

(defn clear-tmp
[f]
(delete-recursive (io/file tmp-dir)) (f))

(defn get-versions [name repo]
(let [name (symbol name)]
(map second (filter #(= name (first %)) (keys repo)))))

(defn make-pom-string [name version deps]
(str "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<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\">
<modelVersion>4.0.0</modelVersion>
<groupId>" name "</groupId>
<artifactId>" name "</artifactId>
<packaging>jar</packaging>
<version>" version "</version>
<name>" name "</name>"
(if-not (empty? deps)
(apply str
"<dependencies>"
(clojure.string/join "\n"
(for [[n v] deps]
(str "<dependency>
<groupId>" n "</groupId>
<artifactId>"n"</artifactId>
<version>"v"</version>
</dependency>")))
"</dependencies>"))
" </project>"))

(defn make-metadata [name versions]
(str "<metadata>
<groupId>" name "</groupId>
<artifactId>" name "</artifactId>
<versioning>
<versions>"
(clojure.string/join "\n"
(for [v versions]
(str "<version>"v"</version>")))
"</versions>
<lastUpdated>20120810193549</lastUpdated>
</versioning>
</metadata>"))

(defn add-repo [repo]
(fn [f]
(aether/register-wagon-factory!
"fake"
#(reify org.apache.maven.wagon.Wagon
(getRepository [_]
(proxy [org.apache.maven.wagon.repository.Repository] []))
(^void connect [_
^org.apache.maven.wagon.repository.Repository _
^org.apache.maven.wagon.authentication.AuthenticationInfo _
^org.apache.maven.wagon.proxy.ProxyInfoProvider _])
(disconnect [_])
(removeTransferListener [_ _])
(addTransferListener [_ _])
(setTimeout [_ _])
(setInteractive [_ _])
(get [_ name file]
(let [[n _ version] (clojure.string/split name #"/")]
(if (= name (str n "/" n "/maven-metadata.xml"))
(if-let [versions (get-versions n repo)]
(spit file (make-metadata n versions))
(spit file ""))
(if-let [deps (repo [(symbol n) version])]
(if (re-find #".pom$" name)
(spit file (make-pom-string n version deps))
(spit file ""))
(throw (org.apache.maven.wagon.ResourceDoesNotExistException. ""))))))))
(f)))

(def ranges (atom []))
(def overrides (atom []))

(defn reset-state [f]
(reset! ranges [])
(reset! overrides [])
(f))

(defn resolve-deps [coords]
(aether/resolve-dependencies
:coordinates coords
:repositories {"test-repo" {:url "fake://ss"
:checksum false}}
:local-repo tmp-local-repo-dir
:repository-session-fn
#(-> %
aether/repository-session
(#'pedantic/use-transformer ranges overrides))))

(defmulti translate type)

(defmethod translate :default [x] x)

(defmethod translate java.util.List
[l]
(remove nil? (map translate l)))

(defmethod translate java.util.Map
[m]
(into {} (map (fn [[k v]] [k (translate v)]) m)))

(defmethod translate org.eclipse.aether.graph.DependencyNode
[n]
(if-let [a (#'pedantic/node->artifact-map n)]
[(symbol (:artifactId a)) (:version a)]))

(def repo
'{[a "1"] []
[a "2"] []
[aa "2"] [[a "2"]]
[range "1"] [[a "[1,)"]]
[range "2"] [[a "[2,)"]]})

(use-fixtures :once (add-repo repo))
(use-fixtures :each clear-tmp)
(use-fixtures :each reset-state)


(deftest top-level-overrides-transative-later
(resolve-deps '[[a "1"]
[aa "2"]])
(is (= @ranges []))
(is (= (translate @overrides)
'[{:accepted {:node [a "1"]
:parents []}
:ignoreds [{:node [a "2"]
:parents [[aa "2"]]}]
:ranges []}])))

(deftest ranges-are-found
(resolve-deps '[[range "1"]])
(is (= (translate @ranges) '[{:node [a "1"]
:parents [[range "1"]]}
{:node [a "2"]
:parents [[range "1"]]}]))
(is (= @overrides
[])))

(deftest range-causes-other-transative-to-ignore-top-level
(resolve-deps '[[a "1"]
[aa "2"]
[range "2"]])
(is (= (translate @ranges) '[{:node [a "2"]
:parents [[range "2"]]}]))
(is (= (translate @overrides)
'[{:accepted {:node [a "2"]
:parents [[aa "2"]]}
:ignoreds [{:node [a "1"]
:parents []}]
:ranges [{:node [a "2"]
:parents [[range "2"]]}]}])))
44 changes: 23 additions & 21 deletions resources/leiningen/bootclasspath-deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
(let [hierarchy (cp/managed-dependency-hierarchy :dependencies
:managed-dependencies
(project/read))]
(-> (into {} (for [[a v] (artifacts h)]
(-> (into {} (for [[a v] (artifacts hierarchy)]
[a v]))
;; Unhelpful to warn on these:
(dissoc 'org.clojure/clojure)
Expand All @@ -22,46 +22,48 @@
{
bultitude "0.2.8"
clojure-complete "0.2.4"
com.cemerick/pomegranate "0.3.1"
com.cemerick/pomegranate "0.4.0-alpha1"
com.google.guava/guava "20.0"
com.hypirion/io "0.3.1"
commons-codec "1.9"
commons-io "2.5"
commons-lang "2.6"
commons-logging "1.2"
net.cgrand/parsley "0.9.3"
net.cgrand/regex "1.1.0"
net.cgrand/sjacket "0.1.1"
org.apache.httpcomponents/httpclient "4.5.2"
org.apache.commons/commons-lang3 "3.5"
org.apache.httpcomponents/httpclient "4.5.3"
org.apache.httpcomponents/httpcore "4.4.4"
org.apache.maven.resolver/maven-resolver-api "1.0.3"
org.apache.maven.resolver/maven-resolver-connector-basic "1.0.3"
org.apache.maven.resolver/maven-resolver-impl "1.0.3"
org.apache.maven.resolver/maven-resolver-spi "1.0.3"
org.apache.maven.resolver/maven-resolver-transport-file "1.0.3"
org.apache.maven.resolver/maven-resolver-transport-http "1.0.3"
org.apache.maven.resolver/maven-resolver-transport-wagon "1.0.3"
org.apache.maven.resolver/maven-resolver-util "1.0.3"
org.apache.maven.wagon/wagon-http "2.12"
org.apache.maven.wagon/wagon-http-shared "2.12"
org.apache.maven.wagon/wagon-provider-api "2.2"
org.apache.maven/maven-aether-provider "3.0.4"
org.apache.maven/maven-model "3.0.4"
org.apache.maven/maven-model-builder "3.0.4"
org.apache.maven/maven-repository-metadata "3.0.4"
org.apache.maven.wagon/wagon-provider-api "2.12"
org.apache.maven/maven-artifact "3.5.0"
org.apache.maven/maven-builder-support "3.5.0"
org.apache.maven/maven-model "3.5.0"
org.apache.maven/maven-model-builder "3.5.0"
org.apache.maven/maven-repository-metadata "3.5.0"
org.apache.maven/maven-resolver-provider "3.5.0"
org.clojure/data.xml "0.0.8"
org.clojure/tools.macro "0.1.5"
org.clojure/tools.nrepl "0.2.12"
org.codehaus.plexus/plexus-classworlds "2.4"
org.codehaus.plexus/plexus-component-annotations "1.5.5"
org.codehaus.plexus/plexus-interpolation "1.14"
org.codehaus.plexus/plexus-component-annotations "1.7.1"
org.codehaus.plexus/plexus-interpolation "1.24"
org.codehaus.plexus/plexus-utils "3.0.24"
org.flatland/classlojure "0.7.1"
org.jsoup/jsoup "1.7.2"
org.slf4j/jcl-over-slf4j "1.7.22"
org.slf4j/slf4j-api "1.7.22"
org.slf4j/slf4j-nop "1.7.22"
org.sonatype.aether/aether-api "1.13.1"
org.sonatype.aether/aether-connector-file "1.13.1"
org.sonatype.aether/aether-connector-wagon "1.13.1"
org.sonatype.aether/aether-impl "1.13.1"
org.sonatype.aether/aether-spi "1.13.1"
org.sonatype.aether/aether-util "1.13.1"
org.sonatype.sisu/sisu-guice "3.0.3"
org.sonatype.sisu/sisu-inject-bean "2.2.3"
org.sonatype.sisu/sisu-inject-plexus "2.2.3"
org.tcrawley/dynapath "0.2.5"
pedantic "0.2.0"
quoin "0.1.2"
robert/hooke "1.3.0"
scout "0.1.1"
Expand Down
2 changes: 1 addition & 1 deletion test/leiningen/test/jar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
(deftest javac-launched-with-whitelisted-settings
(let [user-profile {:local-repo "test_projects/jar/foo/bar"
:mirrors {"central" {:name "central"
:url "http://uk.maven.org/maven2"}}}
:url "https://maven-central.storage.googleapis.com"}}}
orig-project (-> (helper/read-test-project-with-user-profiles
"java-main"
{:user user-profile}))
Expand Down

0 comments on commit 3385971

Please sign in to comment.