Skip to content

Commit 9dbaf7b

Browse files
committed
Remove curl dependency (fixes #29); Use release_url to run expandcp.kts from url-cache to avoid curling another file into ~/bin (fixes #26); prepare for sdkman release
1 parent edf9dbb commit 9dbaf7b

File tree

10 files changed

+130
-55
lines changed

10 files changed

+130
-55
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ install:
4141
- export PATH=$KSCRIPT_HOME::$PATH
4242

4343
- which kscript
44-
- which expandcp.kts
44+
- which resdeps.kts
4545
- which assert.sh
4646

4747
## does it run outside of test-suite?
4848
- kscript --help
4949
- java -version
5050
- mvn --version
51-
- expandcp.kts log4j:log4j:1.2.14
51+
- resdeps.kts log4j:log4j:1.2.14
5252
- kscript 'println("kotlin rocks")'
53-
# - expandcp.kts org.docopt:docopt:0.6.0-SNAPSHOT log4j:log4j:1.2.14
53+
# - resdeps.kts org.docopt:docopt:0.6.0-SNAPSHOT log4j:log4j:1.2.14
5454
# - kscript ${KSCRIPT_HOME}/test/resources/multi_line_deps.kts
5555

5656
script: ./test/test_suite.sh

NEWS.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11

22

3+
## v1.5
4+
5+
* removed `curl` dependency
6+
* more streamlined dependency lookup
7+
8+
39
## v1.4
410

511
Major new features
@@ -43,8 +49,8 @@ Other changes
4349
* versioning and auto-update
4450
* basic command-line help
4551
* Added support for `KOTLIN_OPTS` (see [#8](https://github.com/holgerbrandl/kscript/issues/8))
46-
* Added CLI help to `expandcp.kts`
47-
* Added option to clear dependency lookup cache: `expandcp.kts --clear-cache`
52+
* Added CLI help to `resdeps.kts`
53+
* Added option to clear dependency lookup cache: `resdeps.kts --clear-cache`
4854

4955
## v1.0
5056

examples/more_examples.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ kscript -st '"huhu" + it'
5757

5858

5959
## REPL test: Filter-Join fasta files by ID
60-
kotlinc -classpath $(expandcp.kts de.mpicbg.scicomp:kutils:0.2)
60+
kotlinc -classpath $(resdeps.kts de.mpicbg.scicomp:kutils:0.2)
6161
<<"EOF"
6262
import de.mpicbg.scicomp.kscript.*
6363

kscript

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,22 @@ trim() { while read -r line; do echo "$line"; done; }
1111

1212
assertInPath kotlinc
1313
assertInPath mvn
14-
assertInPath curl
14+
15+
16+
## cheap curl replacement to avoid dependency on curl
17+
## https://superuser.com/questions/238987/how-does-unix-search-for-executable-files
18+
kurl(){
19+
kscript 'import java.io.*
20+
21+
try {
22+
BufferedReader(InputStreamReader(java.net.URL(args[0]).openStream())).useLines { it.forEach { println(it) } }
23+
}catch(e: Throwable){
24+
System.err.println("[ERROR] Could not read from '" + e.message + "'")
25+
kotlin.system.exitProcess(1)
26+
}
27+
' "$@"
28+
}
29+
# kurl https://git.io/v9R73
1530

1631
## prefer JAVA_HOME over PATH for javac and jar (to stay in sync with kotlinc; see #6)
1732
if [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
@@ -37,7 +52,7 @@ if [ $# == 0 ] || [ "$1" == "-v" ] || [ "$1" == "--version" ] || [ "$1" == "-h"
3752
echo "Website : https://github.com/holgerbrandl/kscript" >&2
3853

3954
## determine the latest version
40-
latestVersion=$(curl -Ls https://git.io/v9R73 | grep '^KSCRIPT_VERSION' | cut -f2 -d'=' | tr -d '.')
55+
latestVersion=$(kurl https://git.io/v9R73 | grep '^KSCRIPT_VERSION' | cut -f2 -d'=' | tr -d '.')
4156
installedVersion=$(echo $KSCRIPT_VERSION | tr -d '.')
4257

4358
## http://stackoverflow.com/questions/15224581/floating-point-comparison-with-variable-in-bash
@@ -64,24 +79,21 @@ if [ "$1" == "--clear-cache" ]; then
6479
exit 0
6580
fi
6681

67-
68-
69-
## auto-install expandcp.kts into same dir as kscript for automatic dependency resolution if not yet in PATH
70-
if ! which expandcp.kts &> /dev/null; then
71-
installDir=$(dirname $(which kscript))
72-
curl -Lso ${installDir}/expandcp.kts https://git.io/v9R7n
73-
chmod u+x ${installDir}/expandcp.kts
82+
## look up resdeps from repo unless we're having a full local test clone of it
83+
if [[ -z "$(which resdeps.kts)" ]]; then
84+
resolve_script_deps(){ kscript "https://raw.githubusercontent.com/holgerbrandl/kscript/v${KSCRIPT_VERSION}/resdeps.kts" "$@"; }
85+
else
86+
resolve_script_deps(){ resdeps.kts "$@"; }
7487
fi
88+
#resolve_script_deps log4j:log4j:1.2.14
7589

7690

77-
## optionally self-update kscript ot the newest version
78-
if [ "$1" == "--self-update" ]; then
91+
## optionally self-update kscript ot the newest version (if not local copy is not being maintained by sdkman)
92+
if [[ "$1" == "--self-update" ]] && [[ -z "$(which kotlin | grep .sdkman)" ]]; then
7993
echo "Installing latest version of kscript..."
80-
curl -Lso $(which kscript) https://git.io/v9R73 && chmod u+x $(which kscript)
81-
curl -Lso $(which expandcp.kts) https://git.io/v9R7n && chmod u+x $(which expandcp.kts)
94+
kurl https://git.io/v9R73 > $(which kscript) && chmod u+x $(which kscript)
8295

8396
echo "You're now running kscript "$(kscript --help 2>&1| grep Version | cut -f2- | tr -d ':')
84-
8597
exit 0
8698
fi
8799

@@ -119,7 +131,9 @@ if [[ "$scriptFile" == "http://"* ]] || [[ "$scriptFile" == "https://"* ]]; then
119131

120132
if [ ! -f "$urlCache" ]; then
121133
# echo "fetching kscript from url $scriptFile into ${tmpScript}..."
122-
curl -L ${scriptFile} 2>/dev/null > ${urlCache}
134+
# curl -L ${scriptFile} 2>/dev/null > ${urlCache}
135+
kurl ${scriptFile} > ${urlCache}
136+
if [ $? -eq 1 ]; then rm ${urlCache}; exit 1; fi
123137
fi
124138

125139
scriptFile=${urlCache}
@@ -184,16 +198,16 @@ fi
184198
dependencies=$(grep "^//DEPS" ${scriptFile} | cut -f2- -d' ' | trim | tr ',;\n' ' ')
185199

186200

187-
## First try dependency cache directly to avoid jvm launch for expandcp.kts
201+
## First try dependency cache directly to avoid jvm launch for resdeps.kts
188202
# fix me more consistent use of ${TMPDIR}
189203
dependency_cache="${KSCRIPT_CACHE_DIR}/dependency_cache.txt"
190204
if [ -n "$dependencies" ] && [ -f "$dependency_cache" ]; then
191205
classpath=$(grep -F $(echo ${dependencies} | tr ' ' ';')" " ${dependency_cache} | cut -d' ' -f2)
192206
fi
193207

194-
## If there are dependencies but cache-lookup failed we run expandcp.kts
208+
## If there are dependencies but cache-lookup failed we run resdeps.kts
195209
if [ -n "$dependencies" ] && [ -z "$classpath" ];then
196-
classpath=$(expandcp.kts ${dependencies})
210+
classpath=$(resolve_script_deps ${dependencies})
197211
if [ $? -eq 1 ]; then exit 1; fi
198212
fi
199213

@@ -204,7 +218,7 @@ kotlin_opts=$(grep -F "//KOTLIN_OPTS" ${scriptFile} | head -n1 | cut -f2- -d' ')
204218
## Optionally enter interactive mode
205219
if [ "$is_interactive" = true ]; then
206220
echo "To create a shell with script dependencies run:"
207-
echo "kotlinc ${kotlin_opts} -classpath '$(expandcp.kts ${dependencies})'"
221+
echo "kotlinc ${kotlin_opts} -classpath '$(resdeps.kts ${dependencies})'"
208222
exit 0
209223
fi
210224

misc/kscript_dev_notes.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,65 @@
22

33
1. Increment version in `kscript`
44
2. Make sure that support api version is up to date and available from jcenter
5-
3. push and create github release tag
5+
3. Push and create github release tag
6+
```bash
7+
export KSCRIPT_HOME="/Users/brandl/projects/kotlin/kscript";
8+
export PATH=${KSCRIPT_HOME}:${PATH}
9+
export PATH=~/go/bin/:$PATH
10+
11+
kscript_version=$(grep 'export KSCRIPT_VERSION' ${KSCRIPT_HOME}/kscript | cut -f2 -d'=')
12+
echo "new version is $kscript_version"
13+
## see https://github.com/aktau/github-release
14+
15+
## create and upload deployment file for sdkman
16+
KSCRIPT_ARCHIVE=~/Dropbox/archive/kscript_versions/
17+
18+
mkdir -p $KSCRIPT_ARCHIVE/kscript-${kscript_version}/bin
19+
cp ${KSCRIPT_HOME}/kscript ${KSCRIPT_ARCHIVE}/kscript-${kscript_version}/bin
20+
21+
cd ${KSCRIPT_ARCHIVE}
22+
zip -r ${KSCRIPT_ARCHIVE}/kscript-${kscript_version}.zip kscript-${kscript_version}
23+
open ${KSCRIPT_ARCHIVE}
24+
25+
26+
## create tag on github
27+
#github-release --help
28+
29+
export GITHUB_TOKEN=${GH_TOKEN}
30+
#echo $GITHUB_TOKEN
31+
32+
33+
# make your tag and upload
34+
cd ${KSCRIPT_HOME}
35+
36+
#git tag v${kscript_version} && git push --tags
37+
(git diff --exit-code && git tag v${kscript_version}) || echo "could not tag current branch"
38+
git push --tags
39+
40+
# check the current tags and existing releases of the repo
41+
github-release info -u holgerbrandl -r kscript
42+
43+
# create a formal release
44+
github-release release \\
45+
--user holgerbrandl \\
46+
--repo kscript \\
47+
--tag "v${kscript_version}" \\
48+
--name "v${kscript_version}" \\
49+
--description "NEWS.md](https://github.com/holgerbrandl/kscript/blob/master/NEWS.md)"
50+
# \\
51+
# --pre-release
52+
53+
54+
## upload sdk-man binary set
55+
github-release upload \\
56+
--user aktau \\
57+
--repo gofinance \\
58+
--tag v0.1.0 \\
59+
--name "gofinance-osx-amd64" \\
60+
--file bin/darwin/amd64/gofinance
61+
```
62+
63+
664
4. Update release branch
765

866
```bash
@@ -14,7 +72,7 @@ cd kscript_releases
1472
#git rm --cached -r .
1573

1674
git checkout releases
17-
cp ~/projects/kotlin/kscript/expandcp.kts ~/projects/kotlin/kscript/kscript .
75+
cp ~/projects/kotlin/kscript/resdeps.kts ~/projects/kotlin/kscript/kscript .
1876
git add -A
1977
git status
2078
git commit -m "v1.4 release"

notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ https://unix.stackexchange.com/questions/153896/bash-process-substitution-and-st
119119
Related Projects
120120
----------------
121121

122-
* [coursier](https://github.com/alexarchambault/coursier) - Pure Scala Artifact Fetching. Potential more powerful replacement for `expandcp.kts`
122+
* [coursier](https://github.com/alexarchambault/coursier) - Pure Scala Artifact Fetching. Potential more powerful replacement for `resdeps.kts`
123123
* [kotlin-script](https://github.com/andrewoma/kotlin-script) - Support for using Kotlin as a scripting language
124124

125125

pom.xml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<version>1.0-SNAPSHOT</version>
88

99
<properties>
10-
<kotlin.version>1.0.7</kotlin.version>
10+
<kotlin.version>1.1.2-3</kotlin.version>
1111
<!-- updating here would render kscript incompatible with older versions of kotlins. do it carefully-->
1212
<!--<kotlin.version>1.1.1</kotlin.version>-->
1313
</properties>
@@ -22,11 +22,11 @@
2222
<dependency>
2323
<groupId>de.mpicbg.scicomp</groupId>
2424
<artifactId>kutils</artifactId>
25-
<version>0.4</version>
25+
<version>0.7</version>
2626
</dependency>
2727
<dependency>
2828
<groupId>org.jetbrains.kotlin</groupId>
29-
<artifactId>kotlin-stdlib</artifactId>
29+
<artifactId>kotlin-stdlib-jre8</artifactId>
3030
<version>${kotlin.version}</version>
3131
</dependency>
3232
<dependency>
@@ -35,11 +35,6 @@
3535
<version>${kotlin.version}</version>
3636
<scope>test</scope>
3737
</dependency>
38-
<dependency>
39-
<groupId>org.jetbrains.kotlin</groupId>
40-
<artifactId>kotlin-js-library</artifactId>
41-
<version>${kotlin.version}</version>
42-
</dependency>
4338

4439
</dependencies>
4540

@@ -57,12 +52,6 @@
5752
<goal>compile</goal>
5853
<goal>js</goal>
5954
</goals>
60-
<configuration>
61-
<sourceDirs>
62-
<source>examples</source>
63-
<source></source>
64-
</sourceDirs>
65-
</configuration>
6655
</execution>
6756
<execution>
6857
<id>test-compile</id>
@@ -77,5 +66,11 @@
7766
</plugins>
7867
</build>
7968

69+
<repositories>
70+
<repository>
71+
<id>jcenter</id>
72+
<url>http://jcenter.bintray.com/</url>
73+
</repository>
74+
</repositories>
8075

8176
</project>

expandcp.kts renamed to resdeps.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import kotlin.system.exitProcess
88
//val args = arrayOf("org.docopt:docopt:0.6.0-SNAPSHOT", "log4j:log4j:1.2.14")
99

1010
if (args.isNotEmpty() && listOf("--help", "-help", "-h").contains(args[0])) {
11-
System.err.println("""expandcp.kts resolves a space separated list of gradle-style resource locators into a
12-
classpath suitable for use with 'java -cp' or 'kotlin -cp'. expandcp.kts will use maven to resolve dependencies.
11+
System.err.println("""resdeps.kts resolves a space separated list of gradle-style resource locators into a
12+
classpath suitable for use with 'java -cp' or 'kotlin -cp'. resdeps.kts will use maven to resolve dependencies.
1313
1414
For details see https://github.com/holgerbrandl/kscript
1515
1616
## Example
1717
18-
expandcp.kts org.apache.commons:commons-csv:1.3 log4j:log4j:1.2.14
18+
resdeps.kts org.apache.commons:commons-csv:1.3 log4j:log4j:1.2.14
1919
2020
## Features
2121
2222
* Support for transitive Maven dependencies
23-
* Caching of dependency requests (cached requests take just around 30ms). Use `expandcp.kts --clear-cache` to
23+
* Caching of dependency requests (cached requests take just around 30ms). Use `resdeps.kts --clear-cache` to
2424
clear this cache in case the dependency tree has changed
2525
2626
## Copyright
@@ -114,7 +114,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
114114

115115

116116
fun runMaven(pom: String, goal: String): Iterable<String> {
117-
val temp = File.createTempFile("__expandcp__temp__", "_pom.xml")
117+
val temp = File.createTempFile("__resdeps__temp__", "_pom.xml")
118118
temp.writeText(pom)
119119
val exec = Runtime.getRuntime().exec("mvn -f ${temp.absolutePath} ${goal}")
120120
return BufferedReader(InputStreamReader(exec.inputStream)).
@@ -128,7 +128,7 @@ val mavenResult = runMaven(pom, "dependency:build-classpath")
128128

129129
// The following artifacts could not be resolved: log4ja:log4ja:jar:9.8.87, log4j:log4j:jar:9.8.105: Could not
130130

131-
// Check for errors (e.g. when using non-existing deps expandcp.kts log4j:log4j:1.2.14 org.docopt:docopt:22.3-MISSING)
131+
// Check for errors (e.g. when using non-existing deps resdeps.kts log4j:log4j:1.2.14 org.docopt:docopt:22.3-MISSING)
132132
mavenResult.filter { it.startsWith("[ERROR]") }.find { it.contains("Could not resolve dependencie") }?.let {
133133
System.err.println("Failed to lookup dependencies. Maven reported the following error:")
134134
System.err.println(it)

test/TestsReadme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ cd ${KSCRIPT_HOME}
3434
#sdk use kotlin 1.1-RC
3535
kscript --clear-cache
3636

37-
./test/test_suite.sh
37+
${KSCRIPT_HOME}/test/test_suite.sh
3838

3939
# run again with kotlin 1.0.X
4040
sdk use kotlin 1.0.6
4141
./test/test_suite.sh
4242

4343
```
4444

45+
export PATH=`echo ${PATH} | awk -v RS=: -v ORS=: '/kscript/ {next} {print}'`
46+
4547

4648
For more examples see https://github.com/lehmannro/assert.sh/blob/master/tests.sh
4749

test/test_suite.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,22 @@ assert_end environment_tests
7777

7878
# export KSCRIPT_HOME="/Users/brandl/projects/kotlin/kscript"; export PATH=${KSCRIPT_HOME}:${PATH}
7979

80-
assert "expandcp.kts log4j:log4j:1.2.14" "${HOME}/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar"
80+
assert "resdeps.kts log4j:log4j:1.2.14" "${HOME}/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar"
8181

8282
## impossible version
83-
assert_raises "expandcp.kts log4j:log4j:9.8.76" 1
83+
assert_raises "resdeps.kts log4j:log4j:9.8.76" 1
8484

8585
## wrong format should exit with 1
86-
assert_raises "expandcp.kts log4j:1.0" 1
86+
assert_raises "resdeps.kts log4j:1.0" 1
8787

8888
## wrong format should give meaningful error message
89-
assert "expandcp.kts log4j:1.0 2>&1" "invalid dependency locator: log4j:1.0\nExpected format is groupId:artifactId:version[:classifier]"
89+
assert "resdeps.kts log4j:1.0 2>&1" "invalid dependency locator: log4j:1.0\nExpected format is groupId:artifactId:version[:classifier]"
9090

9191
## other version of wrong format should die with useful error.
92-
assert "expandcp.kts log4j:::1.0 2>&1" "Failed to lookup dependencies. Check dependency locators or file a bug on https://github.com/holgerbrandl/kscript"
92+
assert "resdeps.kts log4j:::1.0 2>&1" "Failed to lookup dependencies. Check dependency locators or file a bug on https://github.com/holgerbrandl/kscript"
9393

9494
## one good dependency, one wrong
95-
assert_raises "expandcp.kts org.docopt:docopt:0.9.0-SNAPSHOT log4j:log4j:1.2.14" 1
95+
assert_raises "resdeps.kts org.docopt:docopt:0.9.0-SNAPSHOT log4j:log4j:1.2.14" 1
9696

9797
assert_end dependency_lookup
9898

0 commit comments

Comments
 (0)