Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4b4545ce731293477745e0790412acb76f6dd635 (plain) (blame)
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/bin/bash -ex

# These cause a lot of logging in Jenkins which we don't need nor want.
unset JAVA_TOOL_OPTIONS
unset _JAVA_OPTIONS

# Behavior and file names depend on the OS.
if [[ $OSTYPE == darwin* ]]; then
  os=mac
  jdk_suffix="_osx-x64_bin.tar.gz"
  eclipse_suffix="-macosx-cocoa-x86_64.tar.gz"
  jre_suffix="macosx-x86_64"
  jdk_relative_bin_folder="Contents/Home/bin"
  jdk_relative_lib_folder="Contents/Home/lib"
  jdk_relative_vm_arg="Contents/MacOS/libjli.dylib"
  jre_relative_vm_arg="lib/libjli.dylib"
  strip_debug="--strip-debug"
  eclipse_root="Eclipse.app/Contents/Eclipse"
  eclipse_executable="Eclipse.app/Contents/Macos/eclipse"
  unpack200_executable="unpack200"
  if [[ "$JDK_URLS_MACOS" != "" && $# == 0 ]]; then
    urls=$JDK_URLS_MACOS
  fi
elif [[ $OSTYPE == cygwin ||  $OSTYPE = msys ]]; then
  os=win
  jdk_suffix="_windows-x64_bin.zip"
  eclipse_suffix="-win32-x86_64.zip"
  jre_suffix="win32-x86_64"
  jdk_relative_bin_folder="bin"
  jdk_relative_lib_folder="lib"
  jdk_relative_vm_arg="bin"
  jre_relative_vm_arg="bin"
  strip_debug="--strip-debug"
  eclipse_root="eclipse"
  eclipse_executable="eclipse/eclipsec.exe"
  unpack200_executable="unpack200.exe"
  if [[ "$JDK_URLS_WINDOWS" != "" && $# == 0 ]]; then
    urls=$JDK_URLS_WINDOWS
  fi
else
  os=linux

  arch=$(uname -m)
  if [[ "$arch" == aarch64 ]]; then
    jdk_suffix="_linux-aarch64_bin.tar.gz"
    eclipse_suffix="-linux-gtk-aarch64.tar.gz"
    jre_suffix="linux-aarch64"
  else
    jdk_suffix="_linux-x64_bin.tar.gz"
    eclipse_suffix="-linux-gtk-x86_64.tar.gz"
    jre_suffix="linux-x86_64"
  fi

  jdk_relative_bin_folder="bin"
  jdk_relative_lib_folder="lib"
  jdk_relative_vm_arg="bin"
  jre_relative_vm_arg="bin"
  strip_debug="--strip-debug"
  eclipse_root="eclipse"
  eclipse_executable="eclipse/eclipse"
  unpack200_executable="unpack200"

  if [[ "$arch" == aarch64 ]]; then
    if [[ "$JDK_URLS_LINUX_AARCH64" != "" && $# == 0 ]]; then
      urls=$JDK_URLS_LINUX_AARCH64
    fi
  else
    if [[ "$JDK_URLS_LINUX" != "" && $# == 0 ]]; then
      urls=$JDK_URLS_LINUX
    fi
  fi
fi

echo "Processing for os=$os"

# Use a default if the environment has not set the URL.
#
if [[ "$urls" == "" ]]; then
  if [[ $# != 0 ]]; then
    # We deliberately want to split on space because a URL should not have spaces.
    urls=$@
  else
    # Default to Java 15 Open JDK.
    urls="https://download.java.net/java/GA/jdk15.0.1/51f4f36ad4ef43e39d0dfdbaf6549e32/9/GPL/openjdk-15.0.1$jdk_suffix"
  fi
fi

# Loop over all URLs.
for url in $urls; do

echo "Processing '$url'"

# Download the os-specific JDK.
#
file=${url##*/}
if [ ! -f $file ]; then
  echo "Downloading $url"
  curl -O -L -J $url
fi

# Download an os-specific version of Eclipse.
#
eclipse_url="https://download.eclipse.org/eclipse/downloads/drops4/R-4.17-202009021800/eclipse-SDK-4.17$eclipse_suffix"
eclipse_file=${eclipse_url##*/}

if [ ! -f $eclipse_file ]; then
  echo "Downloading $eclipse_url"
  curl -O -L -J $eclipse_url
fi

# Extract the JDK; the folder name is expected to start with jdk-.
#
rm -rf jdk-*
jdk="jdk-*"
if [ ! -d $jdk ]; then
  echo "Unpackaging $file"
  #rm -rf $jdk
  if [[ $os == win ]]; then
    unzip -q $file
  else
    tar -xf $file
  fi
fi

# A sanity test that the JDK has been unpacked.
#
jdk=$(echo jdk-*)
echo "JDK Folder: $jdk"
echo "JDK Version:"
$jdk/$jdk_relative_bin_folder/java -version

# Extract Eclipse; the folder name is expected to be eclipse or Eclipse.app.
#
if [ ! -d $eclipse_root ]; then
  echo "Unpackaging $eclipse_file"
  #rm -rf $eclipse_root
  if [[ $os == win ]]; then
    unzip -q $eclipse_file
  else
    tar -xf $eclipse_file
  fi
fi

# Remove the incubator modules.
#
all_modules=$($jdk/$jdk_relative_bin_folder/java --list-modules | sed "s/@.*//g" | grep -v "jdk.incubator" | tr '\n' ',' | sed 's/,$//')
simrel_modules="java.base,java.compiler,java.datatransfer,java.desktop,java.instrument,java.logging,java.management,java.naming,java.prefs,java.rmi,java.scripting,java.security.jgss,java.security.sasl,java.sql,java.sql.rowset,java.xml,jdk.crypto.ec,jdk.jdi,jdk.management,jdk.unsupported,jdk.xml.dom"
installer_modules="java.base,java.desktop,java.logging,java.management,java.naming,java.prefs,java.security.jgss,java.sql,java.xml,jdk.xml.dom,jdk.unsupported"


# Create an Ant build file for getting system properties, including ones calculated by Equinox.
#
cat - > build.xml << END
<?xml version="1.0"?>
<project name="SystemProperty" default="build">
  <target name="build">
    <echoproperties/>
  </target>
</project>
END

# Needed for cygwin.
if [[ $OSTYPE == cygwin ]]; then
  for i in $(find eclipse -name "*.exe" -o -name "*.dll"); do
   chmod +x $i
  done
fi

# On Mac this needs to be absolute.
jdk_vm_arg="$jdk/$jdk_relative_vm_arg"
[[ $os == mac ]] && jdk_vm_arg="$PWD/$jdk_vm_arg"

# And then on Mac the launch messes up the user.dir so it can't find the build.xml.
# Also the PWD might contain spaces so we need "" when we use this variable, but then on Linux, an empty string argument is passed and that is used like a class name.
# So always have an argument that might be useless.
user_dir="-Dunused=unused"
[[ $os == mac ]] && user_dir="-Duser.dir=$PWD"

# Capture all the system properties.
$eclipse_executable -application org.eclipse.ant.core.antRunner -nosplash -emacs -vm "$jdk_vm_arg" -vmargs "$user_dir" > all.properties

# Determine the Java version from the system properties.
java_version=$(grep "^java.version=" all.properties | sed 's/^.*=//;s/\r//')
echo "Java Version '$java_version'"

# Compute the name prefix depending on the vendor and VM.
if grep "^java.vendor.version=" all.properties | grep -q "AdoptOpenJDK"; then
  vendor_url="https://adoptopenjdk.net/"
  if grep "OpenJ9" all.properties; then
    vendor_label="AdoptOpenJDK J9"
    vendor_prefix="adoptopenjdk.j9"
  else
    vendor_label="AdoptOpenJDK Hotspot"
    vendor_prefix="adoptopenjdk.hotspot"
  fi
else
  vendor_url="https://jdk.java.net/"
  vendor_label="OpenJDK Hotspot"
  vendor_prefix="openjdk.hotspot"
fi

echo "Vendor prefix: $vendor_prefix-$java_version-$jre_suffix"

# These are the tuples for which we want to generate JREs.
jres=(

"$vendor_prefix.jre.base"
  "JRE Base"
  "Provides the minimal modules needed to launch Equinox without reflection warnings."
  java.base,java.xml,jdk.unsupported,jdk.jdwp.agent
  "--compress=2"
  filter

"$vendor_prefix.jre.base.stripped"
  "JRE Base Stripped"
  "Provides the minimal modules needed to launch Equinox without reflection warnings, stripped of debug information."
  java.base,java.xml,jdk.unsupported
  "--compress=2 $strip_debug"
  false

"$vendor_prefix.jre.full"
  "JRE Complete"
  "Provides the complete set of modules of the JDK, excluding incubators."
  $all_modules
  "--compress=2"
  true

"$vendor_prefix.jre.full.stripped"
  "JRE Complete Stripped"
  "Provides the complete set of modules of the JDK, excluding incubators, stripped of debug information."
  $all_modules
  "--compress=2 $strip_debug"
  false

"$vendor_prefix.jre.minimal"
  "JRE Minimal"
  "Provides the minimal modules needed to satisfy all of the bundles of the simultaneous release."
  $simrel_modules,jdk.jdwp.agent
  "--compress=2"
  filter

"$vendor_prefix.jre.minimal.stripped"
  "JRE Minimal Stripped"
  "Provides the minimal modules needed to satisfy all of the bundles of the simultaneous release, stripped of debug information."
  $simrel_modules
  "--compress=2 $strip_debug"
  false

)

# Iterate over the tuples.
for ((i=0; i<${#jres[@]}; i+=6)); do

  jre_name=${jres[i]}
  jre_label="$vendor_label ${jres[i+1]}"
  jre_description="${jres[i+2]}"
  jre_folder="org.eclipse.justj.$jre_name-$java_version-$jre_suffix"
  rm -rf $jre_folder
  modules=${jres[i+3]}
  jlink_args=${jres[i+4]}
  include_source=${jres[i+5]}

  # Generate the JRE using jlink from the JDK.
  echo "Generating: $jre_folder"
  $jdk/$jdk_relative_bin_folder/jlink --add-modules=$modules $jlink_args --output $jre_folder
  if [[ -f $jdk/$jdk_relative_bin_folder/$unpack200_executable ]]; then
    cp $jdk/$jdk_relative_bin_folder/$unpack200_executable $jre_folder/bin
  fi

  # Include src.zip if needed
  if [[ "$include_source" = true ]]; then
    echo "Copying src.zip from ${jdk}/${jdk_relative_lib_folder}/src.zip into ${jre_folder}/lib"
    cp $jdk/$jdk_relative_lib_folder/src.zip $jre_folder/lib
  elif [[ "$include_source" == filter ]]; then
    echo "Copying filtered src.zip from ${jdk}/${jdk_relative_lib_folder}/src.zip into ${jre_folder}/lib"
    rm -rf jre-src
    mkdir -p jre-src
    unzip -q ${jdk}/${jdk_relative_lib_folder}/src.zip ${modules//,/\/** }/** -d jre-src
    cd jre-src
    zip -r -9 -q ../src.zip *
    cd -
    mv src.zip $jre_folder/lib
    rm -rf jre-src
  fi

  # Build the -vm arg value.
  jre_vm_arg="$jre_folder/$jre_relative_vm_arg"

  # On Mac it must be absolute.
  if [[ $os == mac ]]; then
    jre_vm_arg="$PWD/$jre_vm_arg"
    # On the older 11 JDK, it was in a different folder.
    if [[ ! -f $jre_vm_arg ]]; then
      jre_relative_vm_arg=lib/jli/libjli.dylib
      jre_vm_arg="$jre_folder/$jre_relative_vm_arg"
      jre_vm_arg="$PWD/$jre_vm_arg"
    fi
  fi

  # Capture the interesting system properties.
  $eclipse_executable -application org.eclipse.ant.core.antRunner -nosplash -emacs -vm "$jre_vm_arg"\
      -vmargs "$user_dir" \
      -Dorg.eclipse.justj.vm.arg="$jre_relative_vm_arg" \
      -Dorg.eclipse.justj.name=$jre_name \
      -Dorg.eclipse.justj.label="$jre_label" \
      -Dorg.eclipse.justj.description="$jre_description" \
      -Dorg.eclipse.justj.modules=$modules \
      -Dorg.eclipse.justj.jlink.args="$jlink_args" \
      -Dorg.eclipse.justj.url.vendor="$vendor_url" \
      -Dorg.eclipse.justj.url.source="$url" |
    grep -E "^org.eclipse.just|^java.class.version|^java.runtime|^java.specification|^java.vendor|^java.version|^java.vm|^org.osgi.framework.system.capabilities|^org.osgi.framework.system.packages|^org.osgi.framework.version|^osgi.arch|^osgi.ws|^osgi.os" |
    sort > $jre_folder/org.eclipse.justj.properties

  # Package up the results without the folder name.
  cd $jre_folder
  tar -cf ../$jre_folder.tar *
  tar -czf ../$jre_folder.tar.gz *
  cd -
done

done

Back to the top