OSDN Git Service

first commit
[japandigitalstudio/build-jds.git] / build-script.sh
1 #!/bin/bash
2
3 set -u
4 set -e
5 set +o nounset
6
7 # Workaround for at least Debian Buster
8 # Require to build bonita-portal-js due to issue with PhantomJS launched by Karma
9 # See https://github.com/ariya/phantomjs/issues/14520
10 export OPENSSL_CONF=/etc/ssl
11
12 # Script configuration
13 # You can set the following environment variables
14 BONITA_BUILD_NO_CLEAN=${BONITA_BUILD_NO_CLEAN:-true}
15 BONITA_BUILD_QUIET=${BONITA_BUILD_QUIET:-false}
16 BONITA_BUILD_STUDIO_ONLY=${BONITA_BUILD_STUDIO_ONLY:-true}
17 BONITA_BUILD_STUDIO_SKIP=${BONITA_BUILD_STUDIO_SKIP:-false}
18
19 # Bonita version
20
21 BONITA_VERSION=7.13.0
22
23
24 ########################################################################################################################
25 # SCM AND BUILD FUNCTIONS
26 ########################################################################################################################
27
28 # $1: the message to be displayed as header
29 echoHeaders() {
30     echo
31     echo
32         echo "============================================================"
33         echo "$1"
34         echo "============================================================"
35 }
36
37 # params:
38 # - Git repository name
39 # - Tag name (optional)
40 # - Checkout folder name (optional)
41 checkout() {
42     # We need at least one parameter (the repository name) and no more than three (repository name, tag name and checkout folder name)
43     if [ "$#" -lt 1 ] || [ "$#" -gt 3 ]; then
44         echo "Incorrect number of parameters: $@"
45         exit 1
46     fi
47
48     repository_name="$1"
49
50     if [ "$#" -ge 2 ]; then
51         tag_name="$2"
52     else
53         # If we don't have a tag name assume that the tag is named with the Bonita version
54                 tag_name=$BONITA_VERSION
55     fi
56         echoHeaders "Processing ${repository_name} ${tag_name}"
57
58     if [ "$#" -eq 3 ]; then
59         checkout_folder_name="$3"
60     else
61         # If no checkout folder path is provided use the repository name as destination folder name
62         checkout_folder_name="$repository_name"
63     fi
64
65     # If we don't already clone the repository do it
66     if [ ! -d "$checkout_folder_name/.git" ]; then
67       git clone --depth 1 "https://github.com/bonitasoft/$repository_name.git" $checkout_folder_name
68     fi
69     # Ensure we fetch all the tags and that we are on the appropriate one
70     git -C $checkout_folder_name fetch --tags
71     git -C $checkout_folder_name reset --hard tags/$tag_name
72
73     # Move to the repository clone folder (required to run Maven/Gradle wrapper)
74     cd $checkout_folder_name
75 }
76
77 run_maven_with_standard_system_properties() {
78         build_command="$build_command -Dengine.version=$BONITA_VERSION -Dfilters.version=$BONITA_VERSION"
79     echo "[DEBUG] Running build command: $build_command"
80     eval "$build_command"
81     # Go back to script folder (checkout move current directory to project checkout folder.
82     cd ..
83 }
84
85 run_gradle_with_standard_system_properties() {
86     echo "[DEBUG] Running build command: $build_command"
87     eval "$build_command"
88     # Go back to script folder (checkout move current directory to project checkout folder.
89     cd ..
90 }
91
92 build_maven_wrapper() {
93     build_command="./mvnw"
94 }
95
96 build_gradle_wrapper() {
97     build_command="./gradlew"
98 }
99
100 build_quiet_if_requested() {
101     if [[ "${BONITA_BUILD_QUIET}" == "true" ]]; then
102         echo "Configure quiet build"
103         build_command="$build_command --quiet"
104     fi
105 }
106
107 build() {
108     build_command="$build_command build"
109 }
110
111 publishToMavenLocal() {
112     build_command="$build_command publishToMavenLocal"
113 }
114
115 clean() {
116     if [[ "${BONITA_BUILD_NO_CLEAN}" == "true" ]]; then
117         echo "Configure build to skip clean task"
118     else
119         build_command="$build_command clean"
120     fi
121 }
122
123 install() {
124     build_command="$build_command install"
125 }
126
127 verify() {
128     build_command="$build_command verify"
129 }
130
131 skiptest() {
132     build_command="$build_command -DskipTests"
133 }
134
135 gradle_test_skip() {
136     build_command="$build_command -x test"
137 }
138
139 profile() {
140     build_command="$build_command -P$1"
141 }
142
143 # params:
144 # - Git repository name
145 # - Profile name
146 build_maven_wrapper_verify_skiptest_with_profile()
147 {
148     checkout $1
149     build_maven_wrapper
150     build_quiet_if_requested
151     clean
152     verify
153     skiptest
154     profile $2
155     run_maven_with_standard_system_properties
156 }
157
158 # params:
159 # - Git repository name
160 build_maven_wrapper_install_skiptest()
161 {
162     checkout "$@"
163     unzip jdsicons.zip
164     unzip -o JDSmessages.zip
165     cp bonita-studio.pom.xml bonita-studio/pom.xml
166     cp bundles.plugins.pom.xml bonita-studio/bundles/plugins/pom.xml
167     cp console.libs.pom.xml bonita-studio/bundles/plugins/org.bonitasoft.studio.console.libs/pom.xml
168     cp bundles.features.studio-feature.feature.xml bonita-studio/bundles/features/studio-feature/feature.xml
169     cp console.libs.build.properties bonita-studio/bundles/plugins/org.bonitasoft.studio.console.libs/build.properties
170     rm bonita-studio/bundles/plugins/org.bonitasoft.studio.console.libs/META-INF/p2.inf
171     cp splash.bmp bonita-studio/bundles/plugins/org.bonitasoft.studio-product/splash_without_version.bmp
172     cp splash.bmp bonita-studio/bundles/plugins/org.bonitasoft.studio-product/src/org/bonitasoft/studiosplash_without_version.bmp
173     cp splash.bmp bonita-studio/bundles/plugins/org.bonitasoft.studio-product/splash.bmp
174     cp about.bmp bonita-studio/bundles/plugins/org.bonitasoft.studio-product/about.bmp
175     cp studio-product.pom.xml bonita-studio/bundles/plugins/org.bonitasoft.studio-product/pom.xml
176     cp bundles.plugins.studio-product.plugin.xml bonita-studio/bundles/plugins/org.bonitasoft.studio-product/plugin.xml
177     cp bundles.plugins.intro.plugin.xml bonita-studio/bundles/plugins/org.bonitasoft.studio.intro/plugin.xml
178     cp bundles.plugins.intro.plugin.properties bonita-studio/bundles/plugins/org.bonitasoft.studio.intro/plugin.properties
179     cp bundles.plugins.intro.content.introContent.xml bonita-studio/bundles/plugins/org.bonitasoft.studio.intro/content/introContent.xml
180     cp bundles.plugins.intro.content.welcome.html bonita-studio/bundles/plugins/org.bonitasoft.studio.intro/content/welcome.html
181     cp all-in-one.bonitastudio-features.product bonita-studio/all-in-one/bonitastudio-features.product
182     rm bonita-studio/bundles/plugins/org.bonitasoft.studio.application/src/org/bonitasoft/studio/application/coolbar/WelcomeCoolbarItem.java
183     cp bundles.plugins.application.src.org.bonitasoft.studio.application.actions.OpenIntroCommandHnadler.java bonita-studio/bundles/plugins/org.bonitasoft.studio.application/src/org/bonitasoft/studio/application/actions/OpenIntroCommandHandler.java
184     cp bundles.plugins.application.src.org.bonitasoft.studio.application.BonitaStudioWorkbenchAdvisor.java bonita-studio/bundles/plugins/org.bonitasoft.studio.application/src/org/bonitasoft/studio/application/BonitaStudioWorkbenchAdvisor.java
185     rm bonita-studio/bundles/plugins/org.bonitasoft.studio.engine/src/org/bonitasoft/studio/engine/coolbar/OpenPortalCoolbarItem.java
186     rm bonita-studio/bundles/plugins/org.bonitasoft.studio.engine/src/org/bonitasoft/studio/engine/coolbar/RunCoolbarItem.java
187     cp bundles.plugins.application.plugin.xml bonita-studio/bundles/plugins/org.bonitasoft.studio.application/plugin.xml
188     cp bundles.plugins.engine.plugin.xml bonita-studio/bundles/plugins/org.bonitasoft.studio.engine/plugin.xml
189     cp bundles.plugins.engine.src.org.bonitasoft.studio.engine.BOSEngineManager.java bonita-studio/bundles/plugins/org.bonitasoft.studio.engine/src/org/bonitasoft/studio/engine/BOSEngineManager.java    install
190     build_maven_wrapper
191     build_quiet_if_requested
192     clean
193     skiptest
194     run_maven_with_standard_system_properties
195 }
196
197 build_gradle_wrapper_test_skip_publishToMavenLocal() {
198     checkout "$@"
199     build_gradle_wrapper
200     build_quiet_if_requested
201     clean
202     gradle_test_skip
203     profile forceCurrentVersion=7.13.0
204     publishToMavenLocal
205     run_gradle_with_standard_system_properties
206 }
207
208 ########################################################################################################################
209 # PARAMETERS PARSING AND VALIDATIONS
210 ########################################################################################################################
211
212 OS_IS_LINUX=false
213 OS_IS_MAC=false
214 OS_IS_WINDOWS=false
215
216 detectOS() {
217     case "`uname`" in
218       CYGWIN*)  OS_IS_WINDOWS=true;;
219       MINGW*)   OS_IS_WINDOWS=true;;
220       Darwin*)  OS_IS_MAC=true;;
221       *)        OS_IS_LINUX=true;;
222     esac
223 }
224
225 logBuildInfo() {
226     echo "OS information"
227     if [[ "${OS_IS_LINUX}" == "true" ]]; then
228         echo "  > Run on Linux"
229         echo "$(cat /etc/lsb-release)" | xargs -L 1 -I % echo "      %"
230     elif [[ "${OS_IS_MAC}" == "true" ]]; then
231         echo "  > Run on MacOS"
232         echo "$(sw_vers)" | xargs -L 1 -I % echo "      %"
233     else
234         echo "  > Run on Windows"
235         echo "$(wmic os get Caption,OSArchitecture,Version //value)" | xargs -L 1 --no-run-if-empty -I % echo "      %" | grep -v -e '^[[:space:]]*$'
236     fi
237     echo "  > Generic information: $(uname -a)"
238
239     echo "Build environment"
240     echo "  > Use $(git --version)"
241     echo "  > Commit: $(git rev-parse FETCH_HEAD)"
242
243     echo "Build settings"
244     echo "  > BONITA_VERSION: ${BONITA_VERSION}"
245     echo "  > BONITA_BUILD_NO_CLEAN: ${BONITA_BUILD_NO_CLEAN}"
246     echo "  > BONITA_BUILD_QUIET: ${BONITA_BUILD_QUIET}"
247     echo "  > BONITA_BUILD_STUDIO_ONLY: ${BONITA_BUILD_STUDIO_ONLY}"
248     echo "  > BONITA_BUILD_STUDIO_SKIP: ${BONITA_BUILD_STUDIO_SKIP}"
249 }
250
251 checkPrerequisites() {
252     echo "Prerequisites"
253 #    if [[ "${OS_IS_LINUX}" == "true" ]]; then
254 #        if [[ "${BONITA_BUILD_STUDIO_SKIP}" == "false" ]]; then
255 #            # Test that x server is running. Required to generate Bonita Studio models
256 #            # Can be ignored if Studio is build without the "generate" Maven profile
257 #
258 #            if ! xset q &>/dev/null; then
259 #                echo "No X server at \$DISPLAY [$DISPLAY]" >&2
260 #                exit 1
261 #            fi
262 #            echo "  > X server running correctly"
263 #        fi
264 #    fi
265 #
266     # Test if Curl exists
267     if hash curl 2>/dev/null; then
268         CURL_VERSION="$(curl --version 2>&1  | awk -F " " 'NR==1 {print $2}')"
269         echo "  > Use curl version: $CURL_VERSION"
270     else
271         echo "curl not found. Exiting."
272         exit 1
273     fi
274
275     checkJavaVersion
276 }
277
278 checkJavaVersion() {
279     local JAVA_CMD=
280     echo "  > Java prerequisites"
281     echo "      Check if Java version is compatible with Bonita"
282
283     if [[ "x$JAVA" = "x" ]]; then
284         if [[ "x$JAVA_HOME" != "x" ]]; then
285             echo "      JAVA_HOME is set"
286             JAVA_CMD="$JAVA_HOME/bin/java"
287         else
288             echo "      JAVA_HOME is not set. Use java in path"
289             JAVA_CMD="java"
290         fi
291     else
292         JAVA_CMD=${JAVA}
293     fi
294     echo "      Java command path is $JAVA_CMD"
295
296     java_full_version_details=$("$JAVA_CMD" -version 2>&1)
297     echo "      JVM details"
298     echo "${java_full_version_details}" | xargs -L 1 -I % echo "        %"
299
300     java_full_version=$("$JAVA_CMD" -version 2>&1 | grep -i version | sed 's/.*version "\(.*\)".*$/\1/g')
301     echo "      Java full version: $java_full_version"
302     if [[ "x$java_full_version" = "x" ]]; then
303       echo "No Java command could be found. Please set JAVA_HOME variable to a JDK and/or add the java executable to your PATH"
304       exit 1
305     fi
306
307     java_version_1st_digit=$(echo "$java_full_version" | sed 's/\(.*\)\..*\..*$/\1/g')
308     java_version_expected=11
309     # pre Java 9 versions, get minor version
310     if [[ "$java_version_1st_digit" -eq "1" ]]; then
311       java_version=$(echo "$java_full_version" | sed 's/.*\.\(.*\)\..*$/\1/g')
312     else
313       java_version=${java_version_1st_digit}
314     fi
315     echo "      Java version: $java_version"
316
317     if [[ "$java_version" -ne "$java_version_expected" ]]; then
318       echo "Invalid Java version $java_version not $java_version_expected. Please set JAVA_HOME environment variable to a valid JDK version, and/or add the java executable to your PATH"
319       exit 1
320     fi
321     echo "      Java version is compatible with Bonita"
322 }
323
324
325 ########################################################################################################################
326 # TOOLING
327 ########################################################################################################################
328
329 detectWebPagesDependenciesVersions() {
330     echoHeaders "Detecting web-pages dependencies versions"
331     local webPagesGradleBuild=`curl -sS -X GET https://raw.githubusercontent.com/bonitasoft/bonita-web-pages/${BONITA_VERSION}/build.gradle`
332
333     WEB_PAGES_UID_VERSION=`echo "${webPagesGradleBuild}" | tr -s "[:blank:]" | tr -d "\n" | sed 's@.*UIDesigner {\(.*\)"}.*@\1@g' | sed 's@.*version "\(.*\)@\1@g'`
334     echo "WEB_PAGES_UID_VERSION: ${WEB_PAGES_UID_VERSION}"
335 }
336
337 detectStudioDependenciesVersions() {
338 #    echoHeaders "Detecting Studio dependencies versions"
339 #    local studioPom=`curl -sS -X GET https://raw.githubusercontent.com/bonitasoft/bonita-studio/${BONITA_VERSION}/pom.xml`
340
341 #    STUDIO_UID_VERSION=`echo "${studioPom}" | grep \<ui.designer.version\> | sed 's@.*>\(.*\)<.*@\1@g'`
342     STUDIO_UID_VERSION=1.13.20
343     echo "STUDIO_UID_VERSION: ${STUDIO_UID_VERSION}"
344 }
345
346
347
348 ########################################################################################################################
349 # MAIN
350 ########################################################################################################################
351 detectOS
352 logBuildInfo
353 checkPrerequisites
354 echo
355
356 # List of repositories on https://github.com/bonitasoft that you don't need to build
357 # Note that archived repositories are not listed here, as they are only required to build old Bonita versions
358 #
359 # angular-strap: automatically downloaded in the build of bonita-web project.
360 # babel-preset-bonita: automatically downloaded in the build of bonita-ui-designer project.
361 # bonita-codesign-windows: use to sign Windows binaries when building using Bonita Continuous Integration.
362 # bonita-connector-talend: deprecated.
363 # bonita-continuous-delivery-doc: Bonita Enterprise Edition Continuous Delivery module documentation.
364 # bonita-custom-page-seed: a project to start building a custom page. Deprecated in favor of UI Designer page + REST API extension.
365 # bonita-doc: Bonita documentation.
366 # bonita-developer-resources: guidelines for contributing to Bonita, contributor license agreement, code style...
367 # bonita-examples: Bonita usage code examples.
368 # bonita-ici-doc: Bonita Enterprise Edition AI module documentation.
369 # bonita-js-components: automatically downloaded in the build of projects that require it.
370 # bonita-migration: migration tool to update a server from a previous Bonita release.
371 # bonita-page-authorization-rules: documentation project to provide an example for page mapping authorization rule.
372 # bonita-connector-sap: deprecated. Use REST connector instead.
373 # bonita-vacation-management-example: an example for Bonita Enterprise Edition Continuous Delivery module.
374 # bonita-web-devtools: Bonitasoft internal development tools.
375 # bonita-widget-contrib: project to start building custom widgets outside UI Designer.
376 # create-react-app: required for Bonita Subscription Intelligent Continuous Improvement module.
377 # dojo: Bonitasoft R&D coding dojos.
378 # jscs-preset-bonita: Bonita JavaScript code guidelines.
379 # ngUpload: automatically downloaded in the build of bonita-ui-designer project.
380 # preact-chartjs-2: required for Bonita Subscription Intelligent Continuous Improvement module.
381 # preact-content-loader: required for Bonita Subscription Intelligent Continuous Improvement module.
382 # restlet-framework-java: /!\
383 # swt-repo: legacy repository required by Bonita Studio. Deprecated.
384 # training-presentation-tool: fork of reveal.js with custom look and feel.
385 # widget-builder: automatically downloaded in the build of bonita-ui-designer project.
386 # bonita-studio-watchdog: obsolete since 7.10 (included in bonita-studio).
387
388
389 if [[ "${BONITA_BUILD_STUDIO_ONLY}" == "false" ]]; then
390     build_gradle_wrapper_test_skip_publishToMavenLocal bonita-engine
391
392     build_maven_wrapper_install_skiptest bonita-web-extensions
393
394     build_maven_wrapper_install_skiptest bonita-web
395     build_maven_wrapper_install_skiptest bonita-portal-js
396
397     # bonita-web-pages uses a dedicated UID version
398     detectWebPagesDependenciesVersions
399     build_maven_wrapper_install_skiptest bonita-ui-designer ${WEB_PAGES_UID_VERSION}
400     build_gradle_wrapper_test_skip_publishToMavenLocal bonita-web-pages
401
402     build_maven_wrapper_install_skiptest bonita-application-directory
403     build_maven_wrapper_install_skiptest bonita-user-application
404     build_maven_wrapper_install_skiptest bonita-admin-application
405     build_maven_wrapper_install_skiptest bonita-super-admin-application
406
407     build_maven_wrapper_install_skiptest bonita-distrib
408 else
409     echoHeaders "Skipping all build prior the Studio part"
410     build_gradle_wrapper_test_skip_publishToMavenLocal bonita-engine
411 fi
412
413 if [[ "${BONITA_BUILD_STUDIO_SKIP}" == "false" ]]; then
414     build_maven_wrapper_install_skiptest bonita-data-repository
415     
416     # bonita-studio uses a dedicated UID version
417     detectStudioDependenciesVersions
418     build_maven_wrapper_install_skiptest bonita-ui-designer ${STUDIO_UID_VERSION}
419     
420     build_maven_wrapper_verify_skiptest_with_profile bonita-studio default,all-in-one,!jdk11-tests
421 else
422     echoHeaders "Skipping the Studio build"
423 fi