blob: fa4c106b3b0d53ebce7024d4259f7590ef45af46 [file] [log] [blame]
Inseob Kim5f8f32c2018-08-24 11:10:44 +09001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "sysprop_java_gen"
18
19#include "JavaGen.h"
20
21#include <android-base/file.h>
22#include <android-base/logging.h>
23#include <android-base/stringprintf.h>
24#include <android-base/strings.h>
25#include <cerrno>
Inseob Kim4584b8f2019-06-17 15:52:48 +090026#include <filesystem>
Inseob Kim5f8f32c2018-08-24 11:10:44 +090027#include <regex>
28#include <string>
29
30#include "CodeWriter.h"
31#include "Common.h"
32#include "sysprop.pb.h"
33
Inseob Kim053b83d2019-06-26 13:41:51 +090034using android::base::Result;
35
Inseob Kim5f8f32c2018-08-24 11:10:44 +090036namespace {
37
38constexpr const char* kIndent = " ";
39
40constexpr const char* kJavaFileImports =
Inseob Kim38569c72019-07-30 18:36:28 +090041 R"(import android.os.SystemProperties;
Inseob Kim3f452c02020-03-31 13:41:19 +090042import android.util.Log;
Inseob Kim1ca03f32019-06-08 16:31:59 +090043
Inseob Kim51313222020-01-15 14:37:49 +090044import java.lang.StringBuilder;
Inseob Kim5f8f32c2018-08-24 11:10:44 +090045import java.util.ArrayList;
46import java.util.function.Function;
47import java.util.List;
Todd Kennedye37e10d2019-07-17 12:56:11 -070048import java.util.Locale;
Inseob Kim5f8f32c2018-08-24 11:10:44 +090049import java.util.Optional;
50import java.util.StringJoiner;
Inseob Kim9c5147d2019-03-06 11:36:36 +090051import java.util.stream.Collectors;
Inseob Kim5f8f32c2018-08-24 11:10:44 +090052
53)";
54
55constexpr const char* kJavaParsersAndFormatters =
Inseob Kim51313222020-01-15 14:37:49 +090056 R"s(private static Boolean tryParseBoolean(String str) {
Todd Kennedye37e10d2019-07-17 12:56:11 -070057 switch (str.toLowerCase(Locale.US)) {
Inseob Kim5f8f32c2018-08-24 11:10:44 +090058 case "1":
Inseob Kim5f8f32c2018-08-24 11:10:44 +090059 case "true":
60 return Boolean.TRUE;
61 case "0":
Inseob Kim5f8f32c2018-08-24 11:10:44 +090062 case "false":
63 return Boolean.FALSE;
64 default:
65 return null;
66 }
67}
68
69private static Integer tryParseInteger(String str) {
70 try {
71 return Integer.valueOf(str);
72 } catch (NumberFormatException e) {
73 return null;
74 }
75}
76
Inseob Kim22133ec2020-10-28 22:08:07 +090077private static Integer tryParseUInt(String str) {
78 try {
79 return Integer.parseUnsignedInt(str);
80 } catch (NumberFormatException e) {
81 return null;
82 }
83}
84
Inseob Kim5f8f32c2018-08-24 11:10:44 +090085private static Long tryParseLong(String str) {
86 try {
87 return Long.valueOf(str);
88 } catch (NumberFormatException e) {
89 return null;
90 }
91}
92
Inseob Kim22133ec2020-10-28 22:08:07 +090093private static Long tryParseULong(String str) {
94 try {
95 return Long.parseUnsignedLong(str);
96 } catch (NumberFormatException e) {
97 return null;
98 }
99}
100
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900101private static Double tryParseDouble(String str) {
102 try {
103 return Double.valueOf(str);
104 } catch (NumberFormatException e) {
105 return null;
106 }
107}
108
109private static String tryParseString(String str) {
Inseob Kime76e2722018-12-13 00:18:25 +0900110 return "".equals(str) ? null : str;
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900111}
112
113private static <T extends Enum<T>> T tryParseEnum(Class<T> enumType, String str) {
114 try {
Todd Kennedye37e10d2019-07-17 12:56:11 -0700115 return Enum.valueOf(enumType, str.toUpperCase(Locale.US));
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900116 } catch (IllegalArgumentException e) {
117 return null;
118 }
119}
120
121private static <T> List<T> tryParseList(Function<String, T> elementParser, String str) {
Inseob Kime76e2722018-12-13 00:18:25 +0900122 if ("".equals(str)) return new ArrayList<>();
Inseob Kim4c474eb2018-11-27 12:17:21 +0900123
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900124 List<T> ret = new ArrayList<>();
125
Inseob Kim51313222020-01-15 14:37:49 +0900126 int p = 0;
127 for (;;) {
128 StringBuilder sb = new StringBuilder();
129 while (p < str.length() && str.charAt(p) != ',') {
130 if (str.charAt(p) == '\\') ++p;
131 if (p == str.length()) break;
132 sb.append(str.charAt(p++));
133 }
134 ret.add(elementParser.apply(sb.toString()));
135 if (p == str.length()) break;
136 ++p;
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900137 }
138
139 return ret;
140}
141
142private static <T extends Enum<T>> List<T> tryParseEnumList(Class<T> enumType, String str) {
Inseob Kime76e2722018-12-13 00:18:25 +0900143 if ("".equals(str)) return new ArrayList<>();
Inseob Kim4c474eb2018-11-27 12:17:21 +0900144
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900145 List<T> ret = new ArrayList<>();
146
147 for (String element : str.split(",")) {
Inseob Kim4c474eb2018-11-27 12:17:21 +0900148 ret.add(tryParseEnum(enumType, element));
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900149 }
150
151 return ret;
152}
153
Inseob Kim51313222020-01-15 14:37:49 +0900154private static String escape(String str) {
155 return str.replaceAll("([\\\\,])", "\\\\$1");
156}
157
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900158private static <T> String formatList(List<T> list) {
159 StringJoiner joiner = new StringJoiner(",");
160
161 for (T element : list) {
Inseob Kim51313222020-01-15 14:37:49 +0900162 joiner.add(element == null ? "" : escape(element.toString()));
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900163 }
164
165 return joiner.toString();
166}
Inseob Kimf346e502019-01-04 10:32:39 +0900167
Inseob Kim22133ec2020-10-28 22:08:07 +0900168private static String formatUIntList(List<Integer> list) {
169 StringJoiner joiner = new StringJoiner(",");
170
171 for (Integer element : list) {
172 joiner.add(element == null ? "" : escape(Integer.toUnsignedString(element)));
173 }
174
175 return joiner.toString();
176}
177
178private static String formatULongList(List<Long> list) {
179 StringJoiner joiner = new StringJoiner(",");
180
181 for (Long element : list) {
182 joiner.add(element == null ? "" : escape(Long.toUnsignedString(element)));
183 }
184
185 return joiner.toString();
186}
187
Inseob Kimf346e502019-01-04 10:32:39 +0900188private static <T extends Enum<T>> String formatEnumList(List<T> list, Function<T, String> elementFormatter) {
189 StringJoiner joiner = new StringJoiner(",");
190
191 for (T element : list) {
192 joiner.add(element == null ? "" : elementFormatter.apply(element));
193 }
194
195 return joiner.toString();
196}
Inseob Kim51313222020-01-15 14:37:49 +0900197)s";
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900198
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900199const std::regex kRegexDot{"\\."};
200const std::regex kRegexUnderscore{"_"};
201
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900202std::string GetJavaTypeName(const sysprop::Property& prop);
203std::string GetJavaEnumTypeName(const sysprop::Property& prop);
204std::string GetJavaPackageName(const sysprop::Properties& props);
205std::string GetJavaClassName(const sysprop::Properties& props);
Inseob Kimf346e502019-01-04 10:32:39 +0900206std::string GetParsingExpression(const sysprop::Property& prop);
207std::string GetFormattingExpression(const sysprop::Property& prop);
Inseob Kim38569c72019-07-30 18:36:28 +0900208std::string GenerateJavaClass(const sysprop::Properties& props,
209 sysprop::Scope scope);
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900210
211std::string GetJavaEnumTypeName(const sysprop::Property& prop) {
Inseob Kim14e51872018-10-25 14:27:33 +0900212 return ApiNameToIdentifier(prop.api_name()) + "_values";
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900213}
214
215std::string GetJavaTypeName(const sysprop::Property& prop) {
216 switch (prop.type()) {
217 case sysprop::Boolean:
218 return "Boolean";
219 case sysprop::Integer:
Inseob Kim22133ec2020-10-28 22:08:07 +0900220 case sysprop::UInt:
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900221 return "Integer";
222 case sysprop::Long:
Inseob Kim22133ec2020-10-28 22:08:07 +0900223 case sysprop::ULong:
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900224 return "Long";
225 case sysprop::Double:
226 return "Double";
227 case sysprop::String:
228 return "String";
229 case sysprop::Enum:
230 return GetJavaEnumTypeName(prop);
231 case sysprop::BooleanList:
232 return "List<Boolean>";
233 case sysprop::IntegerList:
Inseob Kim22133ec2020-10-28 22:08:07 +0900234 case sysprop::UIntList:
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900235 return "List<Integer>";
236 case sysprop::LongList:
Inseob Kim22133ec2020-10-28 22:08:07 +0900237 case sysprop::ULongList:
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900238 return "List<Long>";
239 case sysprop::DoubleList:
240 return "List<Double>";
241 case sysprop::StringList:
242 return "List<String>";
243 case sysprop::EnumList:
244 return "List<" + GetJavaEnumTypeName(prop) + ">";
245 default:
246 __builtin_unreachable();
247 }
248}
249
250std::string GetParsingExpression(const sysprop::Property& prop) {
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900251 switch (prop.type()) {
252 case sysprop::Boolean:
Inseob Kim3f452c02020-03-31 13:41:19 +0900253 return "Optional.ofNullable(tryParseBoolean(value))";
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900254 case sysprop::Integer:
Inseob Kim3f452c02020-03-31 13:41:19 +0900255 return "Optional.ofNullable(tryParseInteger(value))";
Inseob Kim22133ec2020-10-28 22:08:07 +0900256 case sysprop::UInt:
257 return "Optional.ofNullable(tryParseUInt(value))";
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900258 case sysprop::Long:
Inseob Kim3f452c02020-03-31 13:41:19 +0900259 return "Optional.ofNullable(tryParseLong(value))";
Inseob Kim22133ec2020-10-28 22:08:07 +0900260 case sysprop::ULong:
261 return "Optional.ofNullable(tryParseULong(value))";
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900262 case sysprop::Double:
Inseob Kim3f452c02020-03-31 13:41:19 +0900263 return "Optional.ofNullable(tryParseDouble(value))";
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900264 case sysprop::String:
Inseob Kim3f452c02020-03-31 13:41:19 +0900265 return "Optional.ofNullable(tryParseString(value))";
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900266 case sysprop::Enum:
Inseob Kim3f452c02020-03-31 13:41:19 +0900267 return "Optional.ofNullable(tryParseEnum(" + GetJavaEnumTypeName(prop) +
268 ".class, value))";
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900269 case sysprop::EnumList:
Inseob Kim0773b942018-10-04 19:29:27 +0900270 return "tryParseEnumList(" + GetJavaEnumTypeName(prop) +
271 ".class, "
272 "value)";
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900273 default:
274 break;
275 }
276
277 // The remaining cases are lists for types other than Enum which share the
278 // same parsing function "tryParseList"
279 std::string element_parser;
280
281 switch (prop.type()) {
282 case sysprop::BooleanList:
283 element_parser = "v -> tryParseBoolean(v)";
284 break;
285 case sysprop::IntegerList:
286 element_parser = "v -> tryParseInteger(v)";
287 break;
288 case sysprop::LongList:
289 element_parser = "v -> tryParseLong(v)";
290 break;
291 case sysprop::DoubleList:
292 element_parser = "v -> tryParseDouble(v)";
293 break;
294 case sysprop::StringList:
295 element_parser = "v -> tryParseString(v)";
296 break;
Inseob Kim22133ec2020-10-28 22:08:07 +0900297 case sysprop::UIntList:
298 element_parser = "v -> tryParseUInt(v)";
299 break;
300 case sysprop::ULongList:
301 element_parser = "v -> tryParseULong(v)";
302 break;
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900303 default:
304 __builtin_unreachable();
305 }
306
Inseob Kim0773b942018-10-04 19:29:27 +0900307 return "tryParseList(" + element_parser + ", value)";
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900308}
309
Inseob Kimf346e502019-01-04 10:32:39 +0900310std::string GetFormattingExpression(const sysprop::Property& prop) {
Inseob Kim9c5147d2019-03-06 11:36:36 +0900311 if (prop.integer_as_bool()) {
312 if (prop.type() == sysprop::Boolean) {
313 // Boolean -> Integer String
314 return "(value ? \"1\" : \"0\")";
315 } else {
316 // List<Boolean> -> String directly
317 return "value.stream().map("
318 "x -> x == null ? \"\" : (x ? \"1\" : \"0\"))"
319 ".collect(Collectors.joining(\",\"))";
320 }
Inseob Kimf346e502019-01-04 10:32:39 +0900321 }
Inseob Kim22133ec2020-10-28 22:08:07 +0900322
323 switch (prop.type()) {
324 case sysprop::Enum:
325 return "value.getPropValue()";
326 case sysprop::EnumList:
327 return "formatEnumList(value, " + GetJavaEnumTypeName(prop) +
328 "::getPropValue)";
329 case sysprop::UInt:
330 return "Integer.toUnsignedString(value)";
331 case sysprop::ULong:
332 return "Long.toUnsignedString(value)";
333 case sysprop::UIntList:
334 return "formatUIntList(value)";
335 case sysprop::ULongList:
336 return "formatULongList(value)";
337 default:
338 break;
339 }
340
341 return IsListProp(prop) ? "formatList(value)" : "value.toString()";
Inseob Kimf346e502019-01-04 10:32:39 +0900342}
343
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900344std::string GetJavaPackageName(const sysprop::Properties& props) {
345 const std::string& module = props.module();
346 return module.substr(0, module.rfind('.'));
347}
348
349std::string GetJavaClassName(const sysprop::Properties& props) {
350 const std::string& module = props.module();
351 return module.substr(module.rfind('.') + 1);
352}
353
Inseob Kim38569c72019-07-30 18:36:28 +0900354std::string GenerateJavaClass(const sysprop::Properties& props,
355 sysprop::Scope scope) {
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900356 std::string package_name = GetJavaPackageName(props);
357 std::string class_name = GetJavaClassName(props);
358
359 CodeWriter writer(kIndent);
360 writer.Write("%s", kGeneratedFileFooterComments);
361 writer.Write("package %s;\n\n", package_name.c_str());
362 writer.Write("%s", kJavaFileImports);
363 writer.Write("public final class %s {\n", class_name.c_str());
364 writer.Indent();
365 writer.Write("private %s () {}\n\n", class_name.c_str());
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900366 writer.Write("%s", kJavaParsersAndFormatters);
367
368 for (int i = 0; i < props.prop_size(); ++i) {
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900369 const sysprop::Property& prop = props.prop(i);
370
Inseob Kim38569c72019-07-30 18:36:28 +0900371 // skip if scope is internal and we are generating public class
372 if (prop.scope() > scope) continue;
373
374 writer.Write("\n");
375
Inseob Kim14e51872018-10-25 14:27:33 +0900376 std::string prop_id = ApiNameToIdentifier(prop.api_name()).c_str();
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900377 std::string prop_type = GetJavaTypeName(prop);
378
379 if (prop.type() == sysprop::Enum || prop.type() == sysprop::EnumList) {
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900380 writer.Write("public static enum %s {\n",
381 GetJavaEnumTypeName(prop).c_str());
382 writer.Indent();
Inseob Kim472fb632020-03-21 03:29:39 +0900383 std::vector<std::string> values = ParseEnumValues(prop.enum_values());
Christopher Di Bella9e63ade2021-03-02 22:56:16 +0000384 for (std::size_t i = 0; i < values.size(); ++i) {
Inseob Kimf346e502019-01-04 10:32:39 +0900385 const std::string& name = values[i];
386 writer.Write("%s(\"%s\")", ToUpper(name).c_str(), name.c_str());
387 if (i + 1 < values.size()) {
388 writer.Write(",\n");
389 } else {
390 writer.Write(";\n");
391 }
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900392 }
Inseob Kimf346e502019-01-04 10:32:39 +0900393 writer.Write(
394 "private final String propValue;\n"
395 "private %s(String propValue) {\n",
396 GetJavaEnumTypeName(prop).c_str());
397 writer.Indent();
398 writer.Write("this.propValue = propValue;\n");
399 writer.Dedent();
400 writer.Write(
401 "}\n"
402 "public String getPropValue() {\n");
403 writer.Indent();
404 writer.Write("return propValue;\n");
405 writer.Dedent();
406 writer.Write("}\n");
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900407 writer.Dedent();
408 writer.Write("}\n\n");
409 }
410
Inseob Kim5e64f892019-06-17 15:09:48 +0900411 if (prop.deprecated()) {
412 writer.Write("@Deprecated\n");
413 }
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900414
Inseob Kime76e2722018-12-13 00:18:25 +0900415 if (IsListProp(prop)) {
416 writer.Write("public static %s %s() {\n", prop_type.c_str(),
417 prop_id.c_str());
Inseob Kime76e2722018-12-13 00:18:25 +0900418 } else {
419 writer.Write("public static Optional<%s> %s() {\n", prop_type.c_str(),
420 prop_id.c_str());
Inseob Kim3f452c02020-03-31 13:41:19 +0900421 }
422 writer.Indent();
423 writer.Write("String value = SystemProperties.get(\"%s\");\n",
424 prop.prop_name().c_str());
425 if (!prop.legacy_prop_name().empty()) {
426 // SystemProperties.get() returns "" (empty string) when the property
427 // doesn't exist
428 writer.Write("if (\"\".equals(value)) {\n");
Inseob Kime76e2722018-12-13 00:18:25 +0900429 writer.Indent();
Inseob Kim3f452c02020-03-31 13:41:19 +0900430 writer.Write(
Inseob Kim4c6640d2021-03-11 15:58:18 +0900431 "Log.v(\"%s\", \"prop %s doesn't exist; fallback to legacy prop "
Inseob Kim3f452c02020-03-31 13:41:19 +0900432 "%s\");\n",
433 class_name.c_str(), prop.prop_name().c_str(),
434 prop.legacy_prop_name().c_str());
435 writer.Write("value = SystemProperties.get(\"%s\");\n",
436 prop.legacy_prop_name().c_str());
Inseob Kime76e2722018-12-13 00:18:25 +0900437 writer.Dedent();
438 writer.Write("}\n");
439 }
Inseob Kim3f452c02020-03-31 13:41:19 +0900440 writer.Write("return %s;\n", GetParsingExpression(prop).c_str());
441 writer.Dedent();
442 writer.Write("}\n");
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900443
Inseob Kim4ab20d32019-12-03 13:44:55 +0900444 if (prop.access() != sysprop::Readonly) {
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900445 writer.Write("\n");
Inseob Kim5e64f892019-06-17 15:09:48 +0900446 if (prop.deprecated()) {
447 writer.Write("@Deprecated\n");
448 }
Inseob Kim0773b942018-10-04 19:29:27 +0900449 writer.Write("public static void %s(%s value) {\n", prop_id.c_str(),
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900450 prop_type.c_str());
451 writer.Indent();
Inseob Kimbd987ed2018-11-01 11:07:15 +0900452 writer.Write("SystemProperties.set(\"%s\", value == null ? \"\" : %s);\n",
Inseob Kim14e51872018-10-25 14:27:33 +0900453 prop.prop_name().c_str(),
Inseob Kimf346e502019-01-04 10:32:39 +0900454 GetFormattingExpression(prop).c_str());
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900455 writer.Dedent();
Inseob Kim14e51872018-10-25 14:27:33 +0900456 writer.Write("}\n");
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900457 }
458 }
459
460 writer.Dedent();
461 writer.Write("}\n");
462
Inseob Kim053b83d2019-06-26 13:41:51 +0900463 return writer.Code();
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900464}
465
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900466} // namespace
467
Inseob Kim053b83d2019-06-26 13:41:51 +0900468Result<void> GenerateJavaLibrary(const std::string& input_file_path,
Inseob Kim38569c72019-07-30 18:36:28 +0900469 sysprop::Scope scope,
Inseob Kim053b83d2019-06-26 13:41:51 +0900470 const std::string& java_output_dir) {
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900471 sysprop::Properties props;
472
Bernie Innocenti7ac8da42020-02-06 23:30:12 +0900473 if (auto res = ParseProps(input_file_path); res.ok()) {
Inseob Kim053b83d2019-06-26 13:41:51 +0900474 props = std::move(*res);
475 } else {
476 return res.error();
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900477 }
478
Inseob Kim38569c72019-07-30 18:36:28 +0900479 std::string java_result = GenerateJavaClass(props, scope);
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900480 std::string package_name = GetJavaPackageName(props);
481 std::string java_package_dir =
482 java_output_dir + "/" + std::regex_replace(package_name, kRegexDot, "/");
483
Inseob Kim4584b8f2019-06-17 15:52:48 +0900484 std::error_code ec;
485 std::filesystem::create_directories(java_package_dir, ec);
486 if (ec) {
Inseob Kim053b83d2019-06-26 13:41:51 +0900487 return Errorf("Creating directory to {} failed: {}", java_package_dir,
488 ec.message());
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900489 }
490
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900491 std::string class_name = GetJavaClassName(props);
492 std::string java_output_file = java_package_dir + "/" + class_name + ".java";
493 if (!android::base::WriteStringToFile(java_result, java_output_file)) {
Inseob Kim053b83d2019-06-26 13:41:51 +0900494 return ErrnoErrorf("Writing generated java class to {} failed",
495 java_output_file);
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900496 }
497
Inseob Kim053b83d2019-06-26 13:41:51 +0900498 return {};
Inseob Kim5f8f32c2018-08-24 11:10:44 +0900499}