Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 175 lines (134 sloc) 4.982 kb
4972c0e7 » dragos
2012-02-22 Added bash script to update the Scala version in an existing Eclipse …
1 #!/bin/bash
2
3 # This script updates the compiler and library OSGI bundles in an existing Eclipse
4 # installation. Use at your own risk! It saves a lot of time if all you need is a custom
5 # compiler, but it should be binary compatible (the other bundles, such as the Sbt builder
6 # and the Scala plugin itself, are not rebuilt against the new version and may lead to
7 # MissingMethodErrors)
8
9 eclipse_dir="/Applications/Programming/eclipse-indigo/"
10 base_dir=""
11
12 function usage()
13 {
14 cat <<EOF
15 `basename $0` [opt] command <basedir>
16
17 Update the compiler and library bundles in an existing Eclipse installation. <basedir>
18 should have a subdirectory lib/ containing scala-library.jar and/or scala-compiler.jar
19 (for instance, the build/pack directory in a Scala checkout)
20
21 Options:
22 --eclipse-dir <path> Path to the Eclipse installation that you want to modify
23
24
25 Commands:
26 update-lib <basedir> Update the scala library with the given jar file. <basedir> should
27 have lib/scala-library.jar.
28
29 update-comp <basedir> Update the scala compiler with the given jar file. <basedir> should
30 have lib/scala-compiler.jar.
31
32 update <basedir> Update both the library and compiler from <basedir>/lib/scala-[library|compiler].jar
33
34 help Print this help screen
35
36 EOF
37 exit 1
38 }
39
40 function test_basedir() {
41 dummy=`stat $base_dir/lib/$1`
42 if [[ $? -ne 0 ]]; then
43 echo "Make sure the argument passed to 'update' contains lib/$1"
44 exit $?
45 fi
46 }
47
48 #
49 # Return the Scala version inside a given jar file, based on the MANIFEST.MF file
50 # For obvious reasons, it 0-pads the minor version component, i.e. 2.9.2.rdev-... becomes 2.09.2.-rdev...
51 #
52 function get_version() {
53 unzip -c "$1" META-INF/MANIFEST.MF | grep Bundle-Version | cut -d : -f 2 | awk -F"." '{printf("%0d.%02d.%0d.%s",$1,$2,$3,$4); }'
54 }
55
56 #
57 # Return the Scala version inside a given jar file, based on the compiler or library.properties file.
58 # It replaces the maven-style qualifier (2.10.0-M2) with a . (2.10.0.M2)
59 #
60 function get_properties_version() {
684a051b » dragos
2012-03-23 Fixed update-scala to use the new osgi.version.number string.
61 unzip -c "$1" "$2.properties" | grep "osgi.version.number" | cut -d = -f 2 # | sed 's/\([0-9]\)-M/\1.M/'
4972c0e7 » dragos
2012-02-22 Added bash script to update the Scala version in an existing Eclipse …
62 }
63
64 latest_file=""
65 newest_version=""
66
67 #
68 # This function popluates global variables $latest_file and $newest_version
69 # $1 - 'library' of 'compiler', used to build the bundle name under @eclipse_dir/plugins
70 #
71 function find_latest_version {
72 count=0
73 latest_file=""
74 newest_version=""
75
76
77 echo -e "\nLooking for jar files inside $eclipse_dir..\n"
78 for f in $eclipse_dir/plugins/org.scala-ide.scala.${1}*.jar; do
79 #statements
80 version=`get_version $f`
81 echo -e '\t' $version
82
83 if [[ $version > $newest_version ]]; then
84 latest_file=$f
85 newest_version=$version
86 fi
87
88 count=$(($count+1))
89 done
90
91 if [[ $count -gt 1 ]]; then
92 echo -e "Found more than one jar in your eclipse installation, using\n\t $latest_file with bundle version $newest_version."
93 fi
94
95 if [[ $count -eq 0 ]]; then
96 echo "Could not find any $1 in your eclipse dir. Backing off"
97 exit 1
98 fi
99 }
100
101 #
102 # $1 - scala-library.jar (file to use)
103 # $2 - 'library' or 'compiler' (file to look for)
104 #
105 function update_jar() {
106 find_latest_version $2
107 to_patch=$latest_file
108 backup=${to_patch}_saved
109
110 echo "Latest file: $latest_file"
111
112 cp $latest_file $backup
113 echo -e "\nCopied original file to `basename $backup`"
114
115 updated_version=`get_properties_version $base_dir/$1 $2`
116 echo -e "\nSetting new version: $updated_version"
117
118 echo -e "Bundle-Version: $updated_version\n" > /tmp/manf
119
120 jar uvmf /tmp/manf $latest_file -C $base_dir $1
121 rm /tmp/manf
5ebb0ce6 » dragos
2012-03-02 Remove cached jars when swapping the Scala compiler in an existing Ec…
122
123 cached_lib=`find $eclipse_dir -iname scala-$2.jar`
124 cached_dir=`dirname $cached_lib`
125 echo -e "Removing cached version in $cached_dir"
126 rm -rf $cached_dir
4972c0e7 » dragos
2012-02-22 Added bash script to update the Scala version in an existing Eclipse …
127 }
128
129
130 while [ $# -gt 0 ]; do
131
132 case $1 in
133 "" | "help")
134 usage
135 ;;
136
137 "--eclipse-dir")
138 eclipse_dir=$2
139 echo -e "Eclipse installation dir is $eclipse_dir\n"
140 shift 2
141 ;;
142
143 "update-comp")
144 base_dir=$2
145 test_basedir "scala-compiler.jar"
146 update_jar "lib/scala-compiler.jar" "compiler"
147 shift 2
148 ;;
149
150 "update-lib")
151 base_dir=$2
152 test_basedir "scala-library.jar"
153 update_jar "lib/scala-library.jar" "library"
154 shift 2
155 ;;
156
157 "update")
158 base_dir=$2
159 test_basedir "scala-library.jar"
160 test_basedir "scala-compiler.jar"
161
162 update_jar "lib/scala-library.jar" "library"
163
164 echo "..Now updating compiler.."
165
166 update_jar "lib/scala-compiler.jar" "compiler"
167
168 shift 2
169 ;;
170
171 *)
172 usage
173 ;;
174 esac
175 done
Something went wrong with that request. Please try again.