forked from scenerygraphics/sciview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulate_fiji.sh
executable file
·207 lines (173 loc) · 7.31 KB
/
populate_fiji.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/sh
#
# populate_fiji.sh
#
# This script generates a local Fiji.app with SciView installed.
# -- Functions --
left() { echo "${1%$2*}"; }
right() { echo "${1##*$2}"; }
mid() { right "$(left "$1" "$3")" "$2"; }
die() {
echo "ERROR: $@" 1>&2; exit 1;
}
# Copies the given Maven coordinate to the specified output directory.
install() {
(set -x; mvn dependency:copy -Dartifact="$1" -DoutputDirectory="$2" > /dev/null) ||
die "Install failed"
}
# Copies the given Maven coordinate to the specified output directory, keeping the groupId
installWithGroupId() {
(set -x; mvn dependency:copy -Dartifact="$1" -DoutputDirectory="$2" -Dmdep.prependGroupId=true > /dev/null) ||
die "Install failed"
}
# Deletes the natives JAR with the given artifactId and classifier.
deleteNative() {
(set -x; rm -f $FijiDirectory/jars/$1-[0-9]*-$2.jar $FijiDirectory/jars/*/$1-[0-9]*-$2.jar) ||
die "Delete failed"
}
# Deletes all natives JARs with the given artifactId.
deleteNatives() {
(set -x; rm -f $FijiDirectory/jars/$1-[0-9]*-natives-*.jar $FijiDirectory/jars/*/$1-[0-9]*-natives-*.jar) ||
die "Delete failed"
}
case "$(uname -s),$(uname -m)" in
Linux,x86_64) launcher=ImageJ-linux64 ;;
Linux,*) launcher=ImageJ-linux32 ;;
Darwin,*) launcher=Contents/MacOS/ImageJ-macosx ;;
MING*,*) launcher=ImageJ-win32.exe ;;
MSYS_NT*,*) launcher=ImageJ-win32.exe ;;
*) die "Unknown platform" ;;
esac
# -- Check if we have a path given, in that case we do not download a new Fiji, but use the path given --
if [ -z "$1" ]
then
echo "--> Installing into pristine Fiji installation"
echo "--> If you want to install into a pre-existing Fiji installation, run as"
echo " $0 path/to/Fiji.app"
# -- Determine correct ImageJ launcher executable --
# -- Roll out a fresh Fiji --
if [ ! -f fiji-nojre.zip ]
then
echo
echo "--> Downloading Fiji"
curl -L -O https://downloads.imagej.net/fiji/latest/fiji-nojre.zip ||
die "Could not download Fiji"
fi
echo "--> Unpacking Fiji"
rm -rf Fiji.app
unzip fiji-nojre.zip || die "Could not unpack Fiji"
echo
echo "--> Updating Fiji"
Fiji.app/$launcher --update update-force-pristine
FijiDirectory=Fiji.app
else
echo "--> Installing into Fiji installation at $1"
FijiDirectory=$1
fi
echo
echo "--> Copying dependencies into Fiji installation"
(set -x; mvn -Dscijava.app.directory=$FijiDirectory) ||
die "Failed to copy dependencies into Fiji directory"
echo "--> Removing slf4j bindings"
(set -x; rm -f $FijiDirectory/jars/slf4j-simple-*.jar) ||
die "Failed to remove slf4j bindings"
# -- Put back jar/gluegen-rt and jar/jogl-all --
echo
echo "--> Reinstalling gluegen-rt, jogl-all, jocl, jinput, and ffmpeg"
gluegenJar=$(echo $FijiDirectory/jars/gluegen-rt-main-*.jar)
gluegenVersion=$(mid "$gluegenJar" "-" ".jar")
install "org.jogamp.gluegen:gluegen-rt:$gluegenVersion" $FijiDirectory/jars
joglJar=$(echo $FijiDirectory/jars/jogl-all-main-*.jar)
joglVersion=$(mid "$joglJar" "-" ".jar")
install "org.jogamp.jogl:jogl-all:$joglVersion" $FijiDirectory/jars
joclGAV=$(mvn dependency:tree | grep jocl | awk -e '{print $NF}' | cut -d: -f1-4 | sed 's/:jar//g')
installWithGroupId "$joclGAV" $FijiDirectory/jars
jinputGAV=$(mvn dependency:tree | grep jinput | head -n1 | awk -e '{print $NF}' | cut -d: -f1-4 | sed 's/:jar//g' | sed 's/:compile//g')
install "$jinputGAV" $FijiDirectory/jars
installWithGroupId "$jinputGAV:jar:natives-all" $FijiDirectory/jars/win64
installWithGroupId "$jinputGAV:jar:natives-all" $FijiDirectory/jars/linux64
installWithGroupId "$jinputGAV:jar:natives-all" $FijiDirectory/jars/macosx
echo "--> Removing jinput natives from JAR root"
(set -x; rm -f $FijiDirectory/jars/jinput-*-natives-all.jar)
ffmpegGAV=$(mvn dependency:tree | grep 'ffmpeg:jar' | head -n1 | awk -e '{print $NF}' | cut -d: -f1-4 | sed 's/:jar//g' | sed 's/:compile//g')
installWithGroupId "$ffmpegGAV" $FijiDirectory/jars
installWithGroupId "$ffmpegGAV:jar:windows-x86_64" $FijiDirectory/jars/win64
installWithGroupId "$ffmpegGAV:jar:linux-x86_64" $FijiDirectory/jars/linux64
installWithGroupId "$ffmpegGAV:jar:macosx-x86_64" $FijiDirectory/jars/macosx
# -- Get the latest imagej-launcher -- [CHECK IF THIS CAN BE REMOVED]
wget "https://maven.scijava.org/service/local/repositories/releases/content/net/imagej/imagej-launcher/5.0.2/imagej-launcher-5.0.2-linux64.exe" -O $FijiDirectory/ImageJ-linux64 ||
die "Could not get linux64 launcher"
chmod +x $FijiDirectory/ImageJ-linux64
mkdir -p $FijiDirectory/Contents/MacOS/
wget "https://maven.scijava.org/service/local/repositories/releases/content/net/imagej/imagej-launcher/5.0.2/imagej-launcher-5.0.2-macosx.exe" -O $FijiDirectory/Contents/MacOS/ImageJ-macosx ||
die "Could not get macOS launcher"
chmod +x $FijiDirectory/Contents/MacOS/ImageJ-macosx
wget "https://maven.scijava.org/service/local/repositories/releases/content/net/imagej/imagej-launcher/5.0.2/imagej-launcher-5.0.2-win32.exe" -O $FijiDirectory/ImageJ-win32 ||
die "Could not get Win32 launcher"
chmod +x $FijiDirectory/ImageJ-win32
wget "https://maven.scijava.org/service/local/repositories/releases/content/net/imagej/imagej-launcher/5.0.2/imagej-launcher-5.0.2-win64.exe" -O $FijiDirectory/ImageJ-win64 ||
die "Could not get Win64 launcher"
chmod +x $FijiDirectory/ImageJ-win64
# -- Fix old miglayout
rm $FijiDirectory/jars/miglayout-3.7.4-swing.jar
install "com.miglayout:miglayout-swing:5.2" $FijiDirectory/jars
# -- Fix imagej-mesh versions with jitpack version clashing (temporary)
rm $FijiDirectory/jars/imagej-mesh-*
install "net.imagej:imagej-mesh:0.8.1" $FijiDirectory/jars
# -- Get the list of native libraries --
# [NB] dependency:list emits G:A:P:C:V but dependency:copy needs G:A:V:P:C.
echo
echo "--> Extracting list of native dependencies"
natives=$(mvn -B dependency:list |
grep natives |
sed -e 's/^\[INFO\] *\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):\([^:]*\):.*/\1:\2:\5:\3:\4/' |
grep -v -- '-\(android\|armv6\|solaris\)' |
sort)
for gavpc in $natives
do
gavp=$(left "$gavpc" ':')
gav=$(left "$gavp" ':')
ga=$(left "$gav" ':')
g=$(left "$ga" ':')
a=$(right "$ga" ':')
v=$(right "$gav" ':')
p=$(right "$gavp" ':')
c=$(right "$gavpc" ':')
echo
echo "[$a-$v-$c]"
case "$g" in
org.lwjgl|graphics.scenery)
deleteNatives "$a"
# [NB] Install all architectures manually; only one is a dependency.
install "$gavp:natives-windows" $FijiDirectory/jars/win64
install "$gavp:natives-macos" $FijiDirectory/jars/macosx
install "$gavp:natives-linux" $FijiDirectory/jars/linux64
;;
*)
deleteNative "$a" "$c"
case "$c" in
natives-win*-i586) continue ;;
natives-win*) platform=win64 ;;
natives-linux*-i586) continue ;;
natives-linux*) platform=linux64 ;;
natives-osx|natives-mac*) platform=macosx ;;
natives-all*) continue ;;
*) die "Unsupported platform: $c" ;;
esac
install "$gavpc" "$FijiDirectory/jars/$platform"
;;
esac
done
# -- Now that we populated fiji, let's double check that it works --
echo
echo "--> Testing installation with command: sc.iview.commands.help.About"
EXE="$FijiDirectory//$launcher"
OUT_TEST=$($EXE --headless --run sc.iview.commands.help.About)
echo $OUT_TEST
if [ -z "$OUT_TEST" ]
then
echo "Test failed"
exit 1
else
echo "Test passed"
fi