-
Notifications
You must be signed in to change notification settings - Fork 1
/
bazelize.sh
executable file
·106 lines (88 loc) · 2.5 KB
/
bazelize.sh
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
#!/bin/bash
# customize the following declarations
# ------------------------------------------------------------------------------
export USE_BAZEL_VERSION=0.14.1
BAZEL_BIN=/home/unknown/dev/bazelisk/bin/bazelisk-linux-amd64
MAIN_CLASS=
# ------------------------------------------------------------------------------
MAVEN_PLUGIN=kupusoglu.orhan:bazelize-maven-plugin
SEPARATOR=$(printf "%0.s=" {1..80})
OPTION=$1
case $OPTION in
-h | --help )
printf "usage:\n"
printf "\t$0 <option>\n"
printf "options:\n"
printf "\tmigrate to bazel: -m | --migrate | -g | --generate\n"
printf "\tclean bazel: -c | --clean\n"
printf "\tbuild with bazel: -b | --build\n"
printf "\ttest with bazel: -t | --test\n"
printf "\trun with bazel: -r | --run\n"
printf "requires Bazelisk for Bazel v${USE_BAZEL_VERSION}:\n"
printf "\t$BAZEL_BIN\n"
exit 0
;;
-m | --migrate | -g | --generate )
MSG="migrate"
;;
-c | --clean )
MSG="clean"
;;
-b | --build )
MSG="build"
;;
-t | --test )
MSG="test"
;;
-r | --run )
MSG="run"
;;
* )
echo "ERROR - unknown option: $OPTION"
exit 1
esac
MSG="$MSG | bazel version: $USE_BAZEL_VERSION"
printf "$SEPARATOR\n"
printf "== ${MSG}\n"
printf "$SEPARATOR\n\n"
if [ ! -f $BAZEL_BIN ]
then
echo "ERROR - missing Bazelisk"
echo "path: $BAZEL_BIN"
exit 2
fi
case $OPTION in
-m | --migrate | -g | --generate )
mvn ${MAVEN_PLUGIN}:clean -Dexpunge
mvn ${MAVEN_PLUGIN}:module
mvn ${MAVEN_PLUGIN}:meta
mvn ${MAVEN_PLUGIN}:build
mvn ${MAVEN_PLUGIN}:workspace
mvn ${MAVEN_PLUGIN}:clean
mvn ${MAVEN_PLUGIN}:test
if [[ ! -z $MAIN_CLASS ]]
then
mvn ${MAVEN_PLUGIN}:binary -DmainClass=${MAIN_CLASS}
fi
;;
-c | --clean )
$BAZEL_BIN clean --expunge
rm -f bazelize.out bazelize.out.html
;;
-b | --build )
$BAZEL_BIN build ... --strict_java_deps=off --profile=bazelize.out
$BAZEL_BIN analyze-profile --html bazelize.out
;;
-t | --test )
$BAZEL_BIN test ... --strict_java_deps=off --test_output all
;;
-r | --run )
if [[ -z $MAIN_CLASS ]]
then
echo "ERROR: no main class is given"
else
MAIN_BAZEL=${MAIN_CLASS//./_}
$BAZEL_BIN run $MAIN_BAZEL
fi
;;
esac