Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / shell / maven-javadoc-generate.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> maven-javadoc-generate.sh"
12 # Generates javadoc in a Maven project.
13
14 # Ensure we fail the job if any steps fail.
15 # DO NOT enable -u because $MAVEN_PARAMS and $MAVEN_OPTIONS could be unbound.
16 set -e -o pipefail
17 set +u
18
19 JAVADOC_DIR="$WORKSPACE/archives/javadoc"
20 mkdir -p "$WORKSPACE/archives"
21
22 export MAVEN_OPTS
23
24 # use absolute path as workaround for javadoc:aggregate
25 # silent failure on relative path, for example "-f ."
26 maven_dir_abs=$(readlink -f "$MAVEN_DIR")
27
28 # Disable SC2086 because we want to allow word splitting for $MAVEN_* parameters.
29 # shellcheck disable=SC2086
30 # Use -x via subshell to show maven invocation details in the log
31 (set -x
32     $MVN clean install javadoc:aggregate \
33         -f "$maven_dir_abs" \
34         -e -Pq -Dmaven.javadoc.skip=false \
35         -DskipTests=true \
36         -Dcheckstyle.skip=true \
37         -Dfindbugs.skip=true \
38         --global-settings "$GLOBAL_SETTINGS_FILE" \
39         --settings "$SETTINGS_FILE" \
40         $MAVEN_OPTIONS $MAVEN_PARAMS
41 )
42
43 mv "$WORKSPACE/$MAVEN_DIR/target/site/apidocs" "$JAVADOC_DIR"
44
45 # TODO: Nexus unpack plugin throws a "504 gateway timeout" for jobs archiving
46 # large number of small files. Remove the workaround when we move away from
47 # using Nexus as the log server.
48 if [[ "$JOB_NAME" =~ "javadoc-verify" ]]; then
49     # Tarball the javadoc dir and rm the directory to avoid re-upload into logs
50     tarball="$WORKSPACE/archives/javadoc.tar.xz"
51     echo "INFO: archiving $JAVADOC_DIR as $tarball"
52     pushd "$JAVADOC_DIR"
53     tar cvJf "$tarball" .
54     popd
55     rm -rf "$JAVADOC_DIR"
56 fi