Skip to content

Commit 95583bf

Browse files
seancorfieldpuredanger
authored andcommitted
TBUILD-41 :src-pom :none
1 parent 20de303 commit 95583bf

File tree

8 files changed

+108
-5
lines changed

8 files changed

+108
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ test-out
1111
.clj-kondo/.cache
1212
.vscode
1313
.lsp
14+
.calva/mcp-server/port
15+
.portal/vs-code.edn

src/main/clojure/clojure/tools/build/api.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@
385385
Options:
386386
:basis - required, used to pull deps, repos
387387
:src-pom - source pom.xml to synchronize from, default = \"./pom.xml\"
388+
may be :none to ignore any existing pom.xml file
388389
:class-dir - root dir for writing pom files, created if needed
389390
:target - file path to write pom if no :class-dir specified
390391
:lib - required, project lib symbol
@@ -396,7 +397,7 @@
396397
:resource-dirs - coll of resource dirs
397398
:repos - map of repo name to repo config, replaces repos from deps.edn
398399
:pom-data - vector of hiccup-style extra pom top elements to include when
399-
no :src-pom is provided:
400+
:src-pom is :none or the source pom.xml does not exist:
400401
[[:licenses
401402
[:license
402403
[:name \"Eclipse Public License 1.0\"]
@@ -409,7 +410,7 @@
409410
[params]
410411
(assert-required "write-pom" params [:basis :lib :version])
411412
(assert-specs "write-pom" params
412-
:src-pom ::specs/path
413+
:src-pom (s/or :none #{:none} :path ::specs/path)
413414
:class-dir ::specs/path
414415
:target ::specs/path
415416
:lib ::specs/lib
@@ -556,4 +557,3 @@
556557
:jar-file ::specs/path
557558
:class-dir ::specs/path)
558559
((requiring-resolve 'clojure.tools.build.tasks.install/install) params))
559-

src/main/clojure/clojure/tools/build/tasks/write_pom.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@
238238
(let [{:keys [basis class-dir target src-pom lib version scm src-dirs resource-dirs repos pom-data]} params
239239
{:keys [libs]} basis
240240
root-deps (libs->deps libs)
241-
src-pom-file (api/resolve-path (or src-pom "pom.xml"))
241+
src-pom-file (when-not (= :none src-pom)
242+
(api/resolve-path (or src-pom "pom.xml")))
242243
repos (or repos (remove #(= "https://repo1.maven.org/maven2/" (-> % val :url)) (:mvn/repos basis)))
243-
pom (if (.exists src-pom-file)
244+
pom (if (and src-pom-file (.exists src-pom-file))
244245
(do
245246
(when pom-data
246247
(println "Warning in write-pom: pom-data supplied but not used because pom template exists at" (or src-pom "pom.xml")))

src/test/clojure/clojure/tools/build/tasks/test_pom.clj

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,74 @@
120120
(is (.exists prop-out))
121121
(is (submap? {"groupId" "test", "artifactId" "p2", "version" "1.2.3"} props)))))
122122

123+
(deftest test-ignore-existing-pom
124+
;; verify existing scm info is preserved if src-pom is supplied:
125+
(with-test-dir "test-data/p4"
126+
(api/set-project-root! (.getAbsolutePath *test-dir*))
127+
(api/delete {:path "target"})
128+
(api/write-pom {:lib 'test/p4
129+
:version "1.2.3"
130+
:class-dir "target/classes"
131+
:src-dirs ["src"]
132+
:src-pom "pom.xml"
133+
:resource-dirs ["resources"]
134+
:basis (api/create-basis nil)})
135+
(let [pom-dir (jio/file (project-path "target/classes/META-INF/maven/test/p4"))
136+
pom-out (jio/file pom-dir "pom.xml")
137+
pom (read-xml pom-out)
138+
prop-out (jio/file pom-dir "pom.properties")
139+
props (read-props prop-out)]
140+
;; check xml out
141+
(is (.exists pom-out))
142+
(are [path val] (= val (xml-path-val pom path))
143+
[::pom/packaging] ["jar"]
144+
[::pom/groupId] ["test"]
145+
[::pom/artifactId] ["p4"]
146+
[::pom/version] ["1.2.3"]
147+
[::pom/name] ["p4"]
148+
[::pom/build ::pom/sourceDirectory] ["src"]
149+
[::pom/build ::pom/resources ::pom/resource ::pom/directory] ["resources"]
150+
[::pom/scm ::pom/tag] ["HEAD"]
151+
[::pom/scm ::pom/url] ["git@github.com:clojure/tools.build.git"])
152+
(is (= 2 (count (xml-path-val pom [::pom/dependencies]))))
153+
(is (= 1 (count (xml-path-val pom [::pom/repositories]))))
154+
;; check properties out
155+
(is (.exists prop-out))
156+
(is (submap? {"groupId" "test", "artifactId" "p4", "version" "1.2.3"} props))))
157+
;; verify no scm info is present if src-pom is :none:
158+
(with-test-dir "test-data/p4"
159+
(api/set-project-root! (.getAbsolutePath *test-dir*))
160+
(api/delete {:path "target"})
161+
(api/write-pom {:lib 'test/p4
162+
:version "1.2.3"
163+
:class-dir "target/classes"
164+
:src-dirs ["src"]
165+
:src-pom :none
166+
:resource-dirs ["resources"]
167+
:basis (api/create-basis nil)})
168+
(let [pom-dir (jio/file (project-path "target/classes/META-INF/maven/test/p4"))
169+
pom-out (jio/file pom-dir "pom.xml")
170+
pom (read-xml pom-out)
171+
prop-out (jio/file pom-dir "pom.properties")
172+
props (read-props prop-out)]
173+
;; check xml out
174+
(is (.exists pom-out))
175+
(are [path val] (= val (xml-path-val pom path))
176+
[::pom/packaging] ["jar"]
177+
[::pom/groupId] ["test"]
178+
[::pom/artifactId] ["p4"]
179+
[::pom/version] ["1.2.3"]
180+
[::pom/name] ["p4"]
181+
[::pom/build ::pom/sourceDirectory] ["src"]
182+
[::pom/build ::pom/resources ::pom/resource ::pom/directory] ["resources"]
183+
[::pom/scm ::pom/tag] nil
184+
[::pom/scm ::pom/url] nil)
185+
(is (= 2 (count (xml-path-val pom [::pom/dependencies]))))
186+
(is (= 1 (count (xml-path-val pom [::pom/repositories]))))
187+
;; check properties out
188+
(is (.exists prop-out))
189+
(is (submap? {"groupId" "test", "artifactId" "p4", "version" "1.2.3"} props)))))
190+
123191
;; check that optional deps are marked optional
124192
(deftest test-optional
125193
(with-test-dir "test-data/p3"

test-data/p4/deps.edn

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{:paths [:clj-paths :resource-paths]
2+
3+
:deps
4+
{org.clojure/clojure {:mvn/version "1.10.1"}
5+
org.clojure/core.cache {:mvn/version "1.0.207"}}
6+
7+
:aliases
8+
{:clj-paths ["src"]
9+
:resource-paths ["resources"]}}

test-data/p4/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<packaging>jar</packaging>
5+
<groupId>foo</groupId>
6+
<artifactId>bar</artifactId>
7+
<version>0.0.1</version>
8+
<name>name</name>
9+
<dependencies>
10+
</dependencies>
11+
<repositories>
12+
</repositories>
13+
<scm>
14+
<connection>scm:git:git@github.com:clojure/tools.build.git</connection>
15+
<developerConnection>scm:git:git@github.com:clojure/tools.build.git</developerConnection>
16+
<url>git@github.com:clojure/tools.build.git</url>
17+
<tag>HEAD</tag>
18+
</scm>
19+
</project>

test-data/p4/resources/data.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{:version "$version"}

test-data/p4/src/foo/bar.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(ns foo.bar)
2+
3+
(defn hello [] (println "hello"))

0 commit comments

Comments
 (0)