Import Maven Artifacts to Ceylon Repos
Friday, November 22, 2013 |In trying to come up to speed on Ceylon, I’ve run into some issues with module import dependencies. I’m pretty sure they’re all pilot error, but it was suggested that I import the jars into the Ceylon repository and specify the dependencies between the modules. This would, effectively, be functionally the same as the <dependencies>
element in the Maven POM. In classic geek, over-engineer-the-solution fashion, I cobbled together this shell script. It could be more elegant, but it seems to work, and it was much simpler than a Java implementation using the Maven APIs. :)
Here’s the script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
FILE=deps
BASE=http://search.maven.org/remotecontent?filepath=
function download() {
curl --remote-name -s $1
}
function getRepoDir() {
GROUP=$1
ARTIFACT=$2
VERSION=$3
REPODIR=`getDir $GROUP/$ARTIFACT`
echo $HOME/.ceylon/repo/$REPODIR/$VERSION
}
function getUrl() {
G=$1
A=$2
V=$3
GPATH=`echo $G | sed -e 's/\./\//g'`
echo "${BASE}$GPATH/$A/$V/$A-$V"
}
function getDir() {
echo $1 | sed -e 's/\./\//g'
}
function downloadFiles() {
GROUP=$1
ARTIFACT=$2
VERSION=$3
URL=`getUrl $GROUP $ARTIFACT $VERSION`
download $URL.pom
download $URL.jar
}
function importJar() {
GROUP=$1
ARTIFACT=$2
VERSION=$3
ceylon import-jar --out $HOME/.ceylon/repo $GROUP.$ARTIFACT/$VERSION $ARTIFACT-$VERSION.jar
}
function getDeps() {
mvn dependency:tree -f *.pom | grep "\- " | grep -v ":test" | grep "\[INFO\] +- " | cut -c 11- > $FILE
}
function processDeps() {
REPODIR=$1
for DEP in `cat $FILE` ; do
DGROUP=`echo $DEP | cut -f 1 -d ":"`
DARTIFACT=`echo $DEP | cut -f 2 -d ":"`
DVERSION=`echo $DEP | cut -f 4 -d ":"`
echo "$DGROUP.$DARTIFACT=$DVERSION" >> $REPODIR/module.properties
DEPREPODIR=`getRepoDir $DGROUP $DARTIFACT $DVERSION`
processArtifact $DGROUP $DARTIFACT $DVERSION
done
}
function processArtifact() {
GROUP=$1
ARTIFACT=$2
VERSION=$3
REPODIR=`getRepoDir $GROUP $ARTIFACT $VERSION`
if [ ! -e $REPODIR ] ; then
echo "Processing $GROUP:$ARTIFACT:$VERSION"
#read -p "Press enter to continue: "
mkdir -p "$ARTIFACT"
cd "$ARTIFACT"
downloadFiles $GROUP $ARTIFACT $VERSION
importJar $GROUP $ARTIFACT $VERSION
getDeps
processDeps $REPODIR
rm -rf "./$ARTIFACT"
else
echo "A module for $GROUP:$ARTIFACT:$VERSION has been found. Skipping."
fi
}
if [ $# -lt 3 ] ; then
echo "Usage: mvnimport.sh <groupId> <artifactId> <version>"
exit -1
fi
processArtifact $1 $2 $3
To import a Maven artifact, all you have to do is specify the group ID, artifact, and version:
1
2
3
$ mvnimport.sh com.google.guava guava 14.0.1
Processing com.google.guava:guava:14.0.1
Processing com.google.code.findbugs:jsr305:1.3.9
It will import the artifact, record its immediate dependencies, then recursively process each dependency. If a module for the given coordinates has been found, the script currently skips it.
As I said, this seems to work, but if there are bugs are ways to improve it, I’m all ears. :)