Migrate shellcheck hook to pre-commit
[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 # Disable SC2086 because we want to allow word splitting for $MAVEN_* parameters.
25 # shellcheck disable=SC2086
26 # Use -x via subshell to show maven invocation details in the log
27 (set -x
28   $MVN clean install javadoc:aggregate \
29     -e -Pq -Dmaven.javadoc.skip=false \
30     -DskipTests=true \
31     -Dcheckstyle.skip=true \
32     -Dfindbugs.skip=true \
33     --global-settings "$GLOBAL_SETTINGS_FILE" \
34     --settings "$SETTINGS_FILE" \
35     -f "$MAVEN_DIR" \
36     $MAVEN_OPTIONS $MAVEN_PARAMS \
37 )
38
39 mv "$WORKSPACE/$MAVEN_DIR/target/site/apidocs" "$JAVADOC_DIR"
40
41 # TODO: Nexus unpack plugin throws a "504 gateway timeout" for jobs archiving
42 # large number of small files. Remove the workaround when we move away from
43 # using Nexus as the log server.
44 if [[ "$JOB_NAME" =~ "javadoc-verify" ]]; then
45     # Tarball the javadoc dir and rm the directory to avoid re-upload into logs
46     tarball="$WORKSPACE/archives/javadoc.tar.xz"
47     echo "INFO: archiving $JAVADOC_DIR as $tarball"
48     pushd "$JAVADOC_DIR"
49     tar cvJf "$tarball" .
50     popd
51     rm -rf "$JAVADOC_DIR"
52 fi