aboutsummaryrefslogtreecommitdiffstats
path: root/bootstrap.sh
blob: 43c62033f6d5bd4d8f174e00edeb19d85912ccd7 (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
#!/bin/bash -e
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

usage() {
    echo "Usage: $0 [full | java | default]" >&2
}

if [ $# -eq 0 ]; then
    # Build minimal set of java modules required to run cmake
    MODE=default
elif [ "$1" = "full" ]; then
    # Build all java modules required by C++ testing
    MODE=full
elif [ "$1" = "java" ]; then
    # Build only plugins
    MODE=java
elif [ "$1" = "default" ]; then
    MODE=default
elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
    usage
    exit 0
else
    echo "Unknown argument: $1" >&2
    usage
    exit 1
fi

get_env_var_with_optional_default() {
   local var_name=$1
   local default_val=$2
   eval "existing_value=\${$var_name}"
    if [[ -n $existing_value ]]; then
        echo "$existing_value"
    elif [[ -n $default_val ]]; then
        echo "$default_val"
    fi
}

readonly MAVEN_CMD=$(get_env_var_with_optional_default VESPA_MAVEN_COMMAND "$(pwd)/mvnw")
readonly MAVEN_EXTRA_OPTS=$(get_env_var_with_optional_default VESPA_MAVEN_EXTRA_OPTS)
readonly MAVEN_TARGET=$(get_env_var_with_optional_default VESPA_MAVEN_TARGET "install")
echo "Using maven command: ${MAVEN_CMD}"
echo "Using maven extra opts: ${MAVEN_EXTRA_OPTS}"
echo "Using maven target: ${MAVEN_TARGET}"

mvn_install() {
    ${MAVEN_CMD} --batch-mode --no-snapshot-updates -Dmaven.wagon.http.retryHandler.count=5 clean ${MAVEN_TARGET} ${MAVEN_EXTRA_OPTS} "$@"
}

force_move() {
    local src_dir=$1
    local file=$2

    rm -rf "./${file:?}"
    cp -r "$src_dir/${file:?}" .
    rm -rf "$src_dir/${file:?}"
}

# Generate vtag map
top=$(dirname $0)
$top/dist/getversionmap.sh $top > $top/dist/vtag.map

# NOTES ON BUILDING JAVA MODULES
#
# mvn is unable to resolve references to a plugin, if the same mvn
# program builds the plugin in the same reactor build.
#
# Therefore, we need to manually build all plugins first.
#
# The 'java' mode only builds the plugins.
# The 'default' mode also builds some modules needed by C++ code.
# The 'full' mode also builds modules needed by C++ tests.

# Set up maven wrapper.
echo "Setting up maven wrapper in $(pwd)"
mvn wrapper:wrapper -Dmaven=3.8.8 -f maven-plugins/pom.xml ${MAVEN_EXTRA_OPTS}
force_move maven-plugins .mvn
force_move maven-plugins mvnw
rm -f maven-plugins/mvnw.cmd
${MAVEN_CMD} -v

# must install parent poms first:
echo "Downloading all dependencies. This may take a few minutes with an empty Maven cache."
(
  cd dependency-versions
  mvn_install
)
(
  cd container-dependency-versions
  mvn_install
)
(
  cd parent
  mvn_install
)
mvn_install -N

# and build plugins first:
echo "Building Vespa Maven plugins."
mvn_install -f maven-plugins/pom.xml

# now everything else should just work with normal maven dependency resolution:

case "$MODE" in
    java)
        ;;
    full)
	echo "Building full set of dependencies."
        mvn_install -am -T1C -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -pl jrt,linguistics,messagebus
        ;;
    default)
	echo "Building default set of dependencies."
        ;;
esac