-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·138 lines (117 loc) · 5.02 KB
/
build.sh
File metadata and controls
executable file
·138 lines (117 loc) · 5.02 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
# Copyright 2023 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Build the Java library from Protobuf source:
# https://github.com/googleapis/google-cloudevents
set -e # Must be set for script to fail
if [[ -z "${DATA_SOURCE_PATH}" ]]
then
echo "Use \$DATA_SOURCE_PATH to set the location of the google-cloudevents repo."
exit 1
fi
# Set Data Source Path ($DATA_SOURCE_PATH should be set to google-cloudevents repo)
PROTOBUF_SRC="${DATA_SOURCE_PATH}/proto"
THIRDPARTY="${DATA_SOURCE_PATH}/third_party/googleapis"
# Set Library Path
LIBRARY_SRC="google-cloudevent-types"
PROTOC_OUT="${LIBRARY_SRC}/src/main/java/"
TEST_GEN_OUT="${LIBRARY_SRC}/src/test/java/"
# Set protoc Path
PROTOC_PATH="${PROTOC_PATH:-protoc}"
# Clean up previously generated files
rm -rf $PROTOC_OUT
mkdir -p $PROTOC_OUT
rm -rf $TEST_GEN_OUT
mkdir -p $TEST_GEN_OUT
# Set sed options for Ubuntu vs MacOs
SED="sed -i"
# Ensure clean source for local builds
BUILD_LOCALLY="${BUILD_LOCALLY:-false}"
if [[ "$BUILD_LOCALLY" == "true" ]]; then
SED="sed -i .bak"
current=$(pwd)
cd "$DATA_SOURCE_PATH"
git restore --staged "$PROTOBUF_SRC" "$THIRDPARTY"
git restore "$PROTOBUF_SRC" "$THIRDPARTY"
git clean -f
cd "$current"
fi
# Assemble protoc plugin to generate tests
mvn clean package assembly:single -f protoc-gen-java-snowpea/
# Setup monitored resource proto with Java options
MonitoredResourceProto=$(find "$THIRDPARTY" -name "monitored_resource.proto")
{
echo -en "\noption java_multiple_files = true;"
echo -en "\noption java_outer_classname = \"MonitoredResourceProto\";"
echo -en "\noption java_package = \"com.google.api\";"
} >> "$MonitoredResourceProto"
echo
echo "########################################################"
for proto_src in $(find "${PROTOBUF_SRC}" -type f -name data.proto); do
echo
echo "# Generating proto bindings - ${proto_src}"
# Comment out preset Java options
$SED 's/option java/\/\/option java/' "$proto_src"
# Set Java option: multiple files
echo -en "\noption java_multiple_files = true;" >> "$proto_src"
# Set Java option: package name
awk '/^package/,/;/' "$proto_src" > PROTO_PACKAGE; # Ex. package google.events.cloud.pubsub.v1; => google.events.cloud.pubsub.v1
$SED 's/package /option java_package = \"com./' PROTO_PACKAGE
$SED 's/;/"/' PROTO_PACKAGE
echo -en "\n$(cat PROTO_PACKAGE);" >> "$proto_src"
$PROTOC_PATH \
-I="$PROTOBUF_SRC" \
-I="$THIRDPARTY" \
--java_out=$PROTOC_OUT \
"$proto_src"
done
echo
echo "########################################################"
for proto_src in $(find "${PROTOBUF_SRC}" -type f -name events.proto); do
echo
echo "# Generating validation tests - ${proto_src}"
# Note: --java-snowpea_opt is a list tests to skip due to imcompatibility
$PROTOC_PATH \
--plugin=protoc-gen-java-snowpea=protoc-gen-java-snowpea/startup-script.sh \
--java-snowpea_out $TEST_GEN_OUT \
--java-snowpea_opt "MessagePublishedData,LogEntryData#strict" \
-I "$PROTOBUF_SRC" \
-I "$THIRDPARTY" \
--experimental_allow_proto3_optional \
"$proto_src"
done
YEAR=$(date +'%Y')
LICENSE="/\*\n \* Copyright $YEAR Google LLC\n \*\n \* Licensed under the Apache License, Version 2.0 (the \"License\");\n \* you may not use this file except in compliance with the License.\n \* You may obtain a copy of the License at\n \*\n \* https://www.apache.org/licenses/LICENSE-2.0\n \*\n \* Unless required by applicable law or agreed to in writing, software\n \* distributed under the License is distributed on an \"AS IS\" BASIS,\n \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n \* See the License for the specific language governing permissions and\n \* limitations under the License.\n \*/"
FILE_HEAD="// Generated by the protocol buffer compiler."
echo
echo "########################################################"
for i in $(find "${PROTOC_OUT}" -type f -name "*.java"); do
echo "# Generating license header - ${i}"
$SED "s|$FILE_HEAD|$LICENSE\n$FILE_HEAD|" "$i"
done
echo
echo "########################################################"
echo "# Formatting generated code files..."
mvn com.spotify.fmt:fmt-maven-plugin:format -f google-cloudevent-types
echo
echo "########################################################"
echo "# Running library tests..."
mvn verify
# echo
# echo "########################################################"
# echo "# Running sample tests..."
# mvn install -DskipTests
# mvn verify -f samples/gcf
# mvn verify -f samples/springboot
# mvn verify -f samples/springboot-proto