-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmake-pom.sh
executable file
·77 lines (65 loc) · 2.6 KB
/
make-pom.sh
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
#!/bin/bash
if [ "$1" == "" ]; then
echo "Error: You did not specify the path of the directory to process"
echo "Syntax: $0 /path/to/project/lib/containing/jar/files"
exit 1;
fi
cd "$1"
for file in `find -name "*.jar" | sed "s/^\.\///g"`; do
VERSION=`unzip -p - $file META-INF/maven/*/*/pom.properties 2>/dev/null | grep "^version" | cut -d '=' -f 2 | sed -e 's/[[:space:]]*$//'`
ART=`unzip -p - $file META-INF/maven/*/*/pom.properties 2>/dev/null | grep "^artifactId" | cut -d '=' -f 2 | sed -e 's/[[:space:]]*$//'`
GROUP=`unzip -p - $file META-INF/maven/*/*/pom.properties 2>/dev/null | grep "^groupId" | cut -d '=' -f 2 | sed -e 's/[[:space:]]*$//'`
echo "<!-- $file -->" >> pom.xml
if [ "$VERSION" != "" ]; then
echo "$file found dep info in jar"
echo "<dependency>" >> pom.xml
echo " <groupId>$GROUP</groupId>" >> pom.xml
echo " <artifactId>$ART</artifactId>" >> pom.xml
echo " <version>$VERSION</version>" >> pom.xml
echo "</dependency>" >> pom.xml
echo "" >> pom.xml
else
SHA1=`sha1sum $file`
#LOOKUPINFO=`lookup-jar.py $file $SHA1`
# call python script to lookup jar by SHA1 checksum on search.maven.org
LOOKUPINFO=$(python - $file $SHA1 << END
import json
import urllib2
import sys
import os
jar = sys.argv[1]
sha = sys.argv[2]
searchurl = 'http://search.maven.org/solrsearch/select?q=1:%22'+sha+'%22&rows=20&wt=json'
page = urllib2.urlopen(searchurl)
data = json.loads("".join(page.readlines()))
if data["response"] and data["response"]["numFound"] == 1:
print "<!-- Found info on search.maven.org for "+jar+" -->\r\n"
jarinfo = data["response"]["docs"][0]
print '<dependency>\r\n'
print ' <groupId>'+jarinfo["g"]+'</groupId>\r\n'
print ' <artifactId>'+jarinfo["a"]+'</artifactId>\r\n'
print ' <version>'+jarinfo["v"]+'</version>\r\n'
print '</dependency>\r\n'
print '\r\n'
END
)
if [ "$LOOKUPINFO" != "" ]; then
echo $file found dep info at search.maven.org
echo $LOOKUPINFO >> pom.xml
else
# did not find on search.maven.org so add info from MANIFEST.MF
echo "$file ***** dep info not found *****"
MFHEAD=`unzip -p - $file META-INF/MANIFEST.MF | head -n 15`
VERSION=`unzip -p - $file META-INF/MANIFEST.MF | head -n 15 | grep "Implementation-Version" | cut -d ':' -f 2 | sed -e 's/[[:space:]]*//' | tr -d "\r"`
echo "<!-- TODO find the dep info for jar $file" >> pom.xml
echo "$MFHEAD" >> pom.xml
echo "-->" >> pom.xml
echo "<dependency>" >> pom.xml
echo " <groupId>$file</groupId>" >> pom.xml
echo " <artifactId>$file</artifactId>" >> pom.xml
echo " <version>$VERSION</version>" >> pom.xml
echo "</dependency>" >> pom.xml
echo "" >> pom.xml
fi
fi
done