Skip to content

Commit 5078316

Browse files
committed
Remove me.raynes.conch dependency
We copied the functions that we need from https://github.com/Raynes/conch. Credits to Anthony Grimes for such a great library. Fixes code54#17
1 parent bae6ea9 commit 5078316

6 files changed

Lines changed: 87 additions & 42 deletions

File tree

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,14 @@ add these repos to your `settings.xml` or your project `pom.xml`. Example:
5353
<id>sonatype-releases</id>
5454
<url>http://oss.sonatype.org/content/repositories/releases</url>
5555
</pluginRepository>
56-
<pluginRepository>
57-
<id>clojars.org</id>
58-
<url>http://clojars.org/repo</url>
59-
</pluginRepository>
6056

6157
<!-- If you want to try SNAPSHOT versions, you need Sonatype's snapshots repo: -->
6258
<pluginRepository>
6359
<id>sonatype-snapshots</id>
6460
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
6561
</pluginRepository>
6662
</pluginRepositories>
67-
63+
6864
```
6965

7066

@@ -179,4 +175,3 @@ addition. He did the heavy-lifting to integrate Clojure with Maven and Plexus.
179175
## License
180176
Licensed under the [Eclipse Public License](http://www.eclipse.org/legal/epl-v10.html).
181177
Copyright 2012 Fernando Dobladez & Code54 S.A. (http://code54.com)
182-

pom.xml

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<artifactId>buildversion-plugin</artifactId>
1414
<version>1.1-SNAPSHOT</version>
1515
<packaging>maven-plugin</packaging>
16-
1716
<name>buildversion-plugin</name>
17+
1818
<description>
1919
This is a maven plugin that extracts current build information from git
2020
projects, including: the latest commit hash, timestamp, most recent tag,
@@ -43,7 +43,6 @@
4343
<maven.version>3.5.4</maven.version>
4444
</properties>
4545

46-
4746
<profiles>
4847
<profile>
4948
<id>release-sign-artifacts</id>
@@ -74,7 +73,6 @@
7473
</profile>
7574
</profiles>
7675

77-
7876
<build>
7977
<sourceDirectory>src/main/clojure</sourceDirectory>
8078
<resources>
@@ -153,16 +151,6 @@
153151
<goal>test</goal>
154152
</goals>
155153
</execution>
156-
157-
<!-- <execution> -->
158-
<!-- <id>default-compile</id> -->
159-
<!-- <phase>compile</phase> -->
160-
161-
<!-- <goals> -->
162-
<!-- <goal>compile</goal> -->
163-
<!-- </goals> -->
164-
<!-- </execution> -->
165-
166154
</executions>
167155
<configuration>
168156
<initScript>
@@ -176,7 +164,6 @@
176164
"buildversion.maven-bash-source-dir"
177165
(clojure.string/replace "${project.build.testSourceDirectory}"
178166
#"/java$" "/bash") )
179-
180167
</initScript>
181168
</configuration>
182169
</plugin>
@@ -190,14 +177,12 @@
190177
<autoVersionSubmodules>true</autoVersionSubmodules>
191178
<localCheckout>true</localCheckout>
192179
<pushChanges>false</pushChanges>
193-
194180
</configuration>
195181
</plugin>
196182
</plugins>
197183

198184
</build>
199185

200-
201186
<dependencies>
202187
<dependency>
203188
<groupId>org.clojure</groupId>
@@ -223,6 +208,7 @@
223208
<artifactId>clojure-maven-mojo-annotations</artifactId>
224209
<version>${clojureMaven.version}</version>
225210
</dependency>
211+
226212
<dependency>
227213
<groupId>org.cloudhoist</groupId>
228214
<artifactId>clojure-maven-plexus-component-factory</artifactId>
@@ -235,23 +221,13 @@
235221
<artifactId>maven-plugin-api</artifactId>
236222
<version>${maven.version}</version>
237223
</dependency>
238-
239-
<dependency>
240-
<groupId>me.raynes</groupId>
241-
<artifactId>conch</artifactId>
242-
<version>0.8.0</version>
243-
</dependency>
244224
</dependencies>
245225

246226
<repositories>
247227
<repository>
248228
<id>sonatype-releases</id>
249229
<url>https://oss.sonatype.org/content/repositories/releases</url>
250230
</repository>
251-
<repository>
252-
<id>clojars.org</id>
253-
<url>https://clojars.org/repo</url>
254-
</repository>
255231
</repositories>
256232

257233
<pluginRepositories>

project.clj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
"0.3.3"]
66
[org.cloudhoist/clojure-maven-mojo "0.3.3"]
77
[org.apache.maven/maven-plugin-api "3.5.4"]
8-
[org.clojure/tools.trace "0.7.10"]
9-
[me.raynes/conch "0.8.0"]]
8+
[org.clojure/tools.trace "0.7.10"]]
109
:source-paths ["src/main/clojure"]
1110
:jar-dir "target"
1211
:profiles {:dev {:dependencies [[radagast "1.1.0"]]}}
1312
:repositories {"sonatype-releases"
14-
"http://oss.sonatype.org/content/repositories/releases"}
13+
"https://oss.sonatype.org/content/repositories/releases"}
1514
:resource-paths ["src/main/resource"]
1615
:target-dir "target"
1716
:min-lein-version "2.0.0"

src/main/clojure/buildversion_plugin/git.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[clojure.java.io :only [reader]]
66
[clojure.string :only [trim-newline replace-first split join]] )
77
(:require
8-
[me.raynes.conch.low-level :as sh] ))
8+
[buildversion-plugin.shell :as sh] ))
99

1010

1111
(def ^:dynamic *debug-fn* #(println %))
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
(ns buildversion-plugin.shell
2+
"A simple but flexible library for shelling out from Clojure.
3+
This code was copied from https://github.com/Raynes/conch"
4+
(:require [clojure.java.io :as io])
5+
(:import (java.util.concurrent TimeUnit TimeoutException)))
6+
7+
(defn proc
8+
"Spin off another process. Returns the process's input stream,
9+
output stream, and err stream as a map of :in, :out, and :err keys
10+
If passed the optional :dir and/or :env keyword options, the dir
11+
and enviroment will be set to what you specify. If you pass
12+
:verbose and it is true, commands will be printed. If it is set to
13+
:very, environment variables passed, dir, and the command will be
14+
printed. If passed the :clear-env keyword option, then the process
15+
will not inherit its environment from its parent process."
16+
[& args]
17+
(let [[cmd args] (split-with (complement keyword?) args)
18+
args (apply hash-map args)
19+
builder (ProcessBuilder. (into-array String cmd))
20+
env (.environment builder)]
21+
(when (:clear-env args)
22+
(.clear env))
23+
(doseq [[k v] (:env args)]
24+
(.put env k v))
25+
(when-let [dir (:dir args)]
26+
(.directory builder (io/file dir)))
27+
(when (:verbose args) (apply println cmd))
28+
(when (= :very (:verbose args))
29+
(when-let [env (:env args)] (prn env))
30+
(when-let [dir (:dir args)] (prn dir)))
31+
(when (:redirect-err args)
32+
(.redirectErrorStream builder true))
33+
(let [process (.start builder)]
34+
{:out (.getInputStream process)
35+
:in (.getOutputStream process)
36+
:err (.getErrorStream process)
37+
:process process})))
38+
39+
(defn destroy
40+
"Destroy a process."
41+
[process]
42+
(.destroy (:process process)))
43+
44+
;; .waitFor returns the exit code. This makes this function useful for
45+
;; both getting an exit code and stopping the thread until a process
46+
;; terminates.
47+
(defn exit-code
48+
"Waits for the process to terminate (blocking the thread) and returns
49+
the exit code. If timeout is passed, it is assumed to be milliseconds
50+
to wait for the process to exit. If it does not exit in time, it is
51+
killed (with or without fire)."
52+
([process] (.waitFor (:process process)))
53+
([process timeout]
54+
(try
55+
(.get (future (.waitFor (:process process))) timeout TimeUnit/MILLISECONDS)
56+
(catch Exception e
57+
(if (or (instance? TimeoutException e)
58+
(instance? TimeoutException (.getCause e)))
59+
(do (destroy process)
60+
:timeout)
61+
(throw e))))))
62+
63+
(defn stream-to
64+
"Stream :out or :err from a process to an ouput stream.
65+
Options passed are fed to clojure.java.io/copy. They are :encoding to
66+
set the encoding and :buffer-size to set the size of the buffer.
67+
:encoding defaults to UTF-8 and :buffer-size to 1024."
68+
[process from to & args]
69+
(apply io/copy (process from) to args))
70+
71+
(defn stream-to-string
72+
"Streams the output of the process to a string and returns it."
73+
[process from & args]
74+
(with-open [writer (java.io.StringWriter.)]
75+
(apply stream-to process from writer args)
76+
(str writer)))

src/test/clojure/buildversion_plugin/test/git.clj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[clojure.string :only [trim-newline blank?] ]
44
; clojure.tools.trace
55
clojure.test)
6-
(:require [me.raynes.conch.low-level :as sh]
6+
(:require [buildversion-plugin.shell :as sh]
77
:reload [buildversion-plugin.git :as git]))
88

99
;; These system properties are set in the pom.xml by mvn's zi:test's "initScript".
@@ -27,17 +27,17 @@
2727

2828
(if (.isDirectory (file (str sample-project-dir "/.git")))
2929
(println "Example GIT project dir found... re-using it")
30-
30+
3131
(let [script (sh/proc (str maven-bash-source-dir "/create-sample-git-project.sh") sample-project-dir)
3232
exit-OK (zero? (sh/exit-code script)) ]
33-
33+
3434
(println "Building example GIT project for testing...")
3535
(println (script :out))
3636

3737
(if-not exit-OK (println (script :err)))
3838
(is exit-OK)))
3939

40-
40+
4141
(run-tests-fn))
4242

4343
(use-fixtures :once sample-git-project-fixture)
@@ -139,7 +139,7 @@
139139

140140
["aa44944 (HEAD, tag: v9.9.9, origin/master, master) ..."] "v9.9.9" 0
141141
["c3bc9ff (tag: v1.11.0) TMS: Add..." ] "v1.11.0" 0
142-
["c3bc9fx (tag: v1.10.0-dev) Blah blah..." ] "v1.10.0-dev" 0
142+
["c3bc9fx (tag: v1.10.0-dev) Blah blah..." ] "v1.10.0-dev" 0
143143

144144
["aabbccd Dummy commit"
145145
"bbccddee Dummy commmit2"
@@ -171,4 +171,3 @@
171171
(println actual-versions)
172172
(is (re-find #"000" (:build-tstamp actual-versions))
173173
"Always expecting 000 milliseconds. Git precision is up to seconds")))
174-

0 commit comments

Comments
 (0)