Skip to content

Commit fa3caea

Browse files
committed
format java with bazel
1 parent d1887af commit fa3caea

File tree

171 files changed

+4248
-4126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+4248
-4126
lines changed

buildSrc/src/main/java/BinaryDictionaryResourceNormalizer.java

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,71 +18,68 @@
1818

1919
/** Compresses a list of words and frequencies into a tree structured binary dictionary. */
2020
class BinaryDictionaryResourceNormalizer {
21-
private static final int DICT_FILE_CHUNK_SIZE = 1000 * 1000;
22-
private final File tempOutputFile;
23-
private final File outputFolder;
24-
private final File dict_id_array;
25-
private final String mPrefix;
21+
private static final int DICT_FILE_CHUNK_SIZE = 1000 * 1000;
22+
private final File tempOutputFile;
23+
private final File outputFolder;
24+
private final File dict_id_array;
25+
private final String mPrefix;
2626

27-
public BinaryDictionaryResourceNormalizer(
28-
File tempOutputFile, File outputFolder, File dict_id_array, String prefix) {
29-
this.tempOutputFile = tempOutputFile;
30-
this.outputFolder = outputFolder;
31-
this.dict_id_array = dict_id_array;
32-
mPrefix = prefix;
33-
}
34-
35-
public void writeDictionaryIdsResource() throws IOException {
36-
splitOutputFile(tempOutputFile, outputFolder);
37-
}
27+
public BinaryDictionaryResourceNormalizer(
28+
File tempOutputFile, File outputFolder, File dict_id_array, String prefix) {
29+
this.tempOutputFile = tempOutputFile;
30+
this.outputFolder = outputFolder;
31+
this.dict_id_array = dict_id_array;
32+
mPrefix = prefix;
33+
}
3834

39-
private int splitOutputFile(final File tempOutputFile, final File outputFolder)
40-
throws IOException {
41-
// output should be words_1.dict....words_n.dict
42-
InputStream inputStream = new FileInputStream(tempOutputFile);
43-
int file_postfix = 0;
44-
int current_output_file_size = 0;
45-
byte[] buffer = new byte[4 * 1024];
46-
OutputStream outputStream = null;
47-
int read = 0;
48-
XmlWriter xml = new XmlWriter(dict_id_array);
49-
xml.writeEntity("resources");
50-
xml.writeEntity("array").writeAttribute("name", mPrefix + "_words_dict_array");
35+
public void writeDictionaryIdsResource() throws IOException {
36+
splitOutputFile(tempOutputFile, outputFolder);
37+
}
5138

52-
while ((read = inputStream.read(buffer)) > 0) {
53-
if (outputStream != null && current_output_file_size >= DICT_FILE_CHUNK_SIZE) {
54-
outputStream.flush();
55-
outputStream.close();
56-
outputStream = null;
57-
}
39+
private int splitOutputFile(final File tempOutputFile, final File outputFolder)
40+
throws IOException {
41+
// output should be words_1.dict....words_n.dict
42+
InputStream inputStream = new FileInputStream(tempOutputFile);
43+
int file_postfix = 0;
44+
int current_output_file_size = 0;
45+
byte[] buffer = new byte[4 * 1024];
46+
OutputStream outputStream = null;
47+
int read = 0;
48+
XmlWriter xml = new XmlWriter(dict_id_array);
49+
xml.writeEntity("resources");
50+
xml.writeEntity("array").writeAttribute("name", mPrefix + "_words_dict_array");
5851

59-
if (outputStream == null) {
60-
file_postfix++;
61-
xml.writeEntity("item")
62-
.writeText("@raw/" + mPrefix + "_words_" + file_postfix)
63-
.endEntity();
64-
current_output_file_size = 0;
65-
File chunkFile =
66-
new File(outputFolder, mPrefix + "_words_" + file_postfix + ".dict");
67-
outputStream = new FileOutputStream(chunkFile);
68-
System.out.println("Writing to dict file " + chunkFile.getAbsolutePath());
69-
}
52+
while ((read = inputStream.read(buffer)) > 0) {
53+
if (outputStream != null && current_output_file_size >= DICT_FILE_CHUNK_SIZE) {
54+
outputStream.flush();
55+
outputStream.close();
56+
outputStream = null;
57+
}
7058

71-
outputStream.write(buffer, 0, read);
72-
current_output_file_size += read;
73-
}
59+
if (outputStream == null) {
60+
file_postfix++;
61+
xml.writeEntity("item").writeText("@raw/" + mPrefix + "_words_" + file_postfix).endEntity();
62+
current_output_file_size = 0;
63+
File chunkFile = new File(outputFolder, mPrefix + "_words_" + file_postfix + ".dict");
64+
outputStream = new FileOutputStream(chunkFile);
65+
System.out.println("Writing to dict file " + chunkFile.getAbsolutePath());
66+
}
7467

75-
xml.endEntity();
76-
xml.endEntity();
77-
xml.close();
68+
outputStream.write(buffer, 0, read);
69+
current_output_file_size += read;
70+
}
7871

79-
inputStream.close();
80-
if (outputStream != null) {
81-
outputStream.flush();
82-
outputStream.close();
83-
}
84-
System.out.println("Done. Wrote " + file_postfix + " files.");
72+
xml.endEntity();
73+
xml.endEntity();
74+
xml.close();
8575

86-
return file_postfix;
76+
inputStream.close();
77+
if (outputStream != null) {
78+
outputStream.flush();
79+
outputStream.close();
8780
}
81+
System.out.println("Done. Wrote " + file_postfix + " files.");
82+
83+
return file_postfix;
84+
}
8885
}

buildSrc/src/main/java/BuildLogger.java

Lines changed: 88 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -12,102 +12,104 @@
1212

1313
public class BuildLogger extends BuildAdapter {
1414

15-
private final File mOutputFile;
15+
private final File mOutputFile;
1616

17-
public BuildLogger(File outputFile) {
18-
mOutputFile = outputFile;
19-
if (mOutputFile.getParentFile().exists() || mOutputFile.getParentFile().mkdirs()) {
20-
try {
21-
try (OutputStreamWriter writer =
22-
new OutputStreamWriter(
23-
new FileOutputStream(mOutputFile, false), StandardCharsets.UTF_8)) {
24-
writer.append("Build log created at ")
25-
.append(Instant.now().toString())
26-
.append(System.lineSeparator());
27-
}
28-
} catch (IOException e) {
29-
throw new RuntimeException(e);
30-
}
31-
} else {
32-
throw new IllegalStateException(
33-
String.format(
34-
Locale.ROOT,
35-
"Can not create parent folder '%s' for logging!",
36-
mOutputFile.getParentFile().getAbsolutePath()));
17+
public BuildLogger(File outputFile) {
18+
mOutputFile = outputFile;
19+
if (mOutputFile.getParentFile().exists() || mOutputFile.getParentFile().mkdirs()) {
20+
try {
21+
try (OutputStreamWriter writer =
22+
new OutputStreamWriter(
23+
new FileOutputStream(mOutputFile, false), StandardCharsets.UTF_8)) {
24+
writer
25+
.append("Build log created at ")
26+
.append(Instant.now().toString())
27+
.append(System.lineSeparator());
3728
}
29+
} catch (IOException e) {
30+
throw new RuntimeException(e);
31+
}
32+
} else {
33+
throw new IllegalStateException(
34+
String.format(
35+
Locale.ROOT,
36+
"Can not create parent folder '%s' for logging!",
37+
mOutputFile.getParentFile().getAbsolutePath()));
3838
}
39+
}
3940

40-
private static String taskToString(TaskState state) {
41-
if (state.getSkipped()) return "SKIPPED";
42-
if (state.getNoSource()) return "NO-SOURCE";
43-
if (state.getUpToDate()) return "UP-TO-DATE";
44-
if (state.getFailure() != null) return "FAILED " + exceptionToString(state.getFailure());
45-
if (state.getExecuted()) return "EXECUTED";
46-
return "unknown";
47-
}
48-
49-
private static String exceptionToString(Throwable throwable) {
50-
StringBuilder builder = new StringBuilder(throwable.getMessage());
51-
while (throwable.getCause() != null) {
52-
throwable = throwable.getCause();
53-
builder.append(" ]> ").append(throwable.getMessage());
54-
}
41+
private static String taskToString(TaskState state) {
42+
if (state.getSkipped()) return "SKIPPED";
43+
if (state.getNoSource()) return "NO-SOURCE";
44+
if (state.getUpToDate()) return "UP-TO-DATE";
45+
if (state.getFailure() != null) return "FAILED " + exceptionToString(state.getFailure());
46+
if (state.getExecuted()) return "EXECUTED";
47+
return "unknown";
48+
}
5549

56-
return builder.toString();
50+
private static String exceptionToString(Throwable throwable) {
51+
StringBuilder builder = new StringBuilder(throwable.getMessage());
52+
while (throwable.getCause() != null) {
53+
throwable = throwable.getCause();
54+
builder.append(" ]> ").append(throwable.getMessage());
5755
}
5856

59-
@Override
60-
public void projectsEvaluated(Gradle gradle) {
61-
appendToFile(
62-
"Build started at "
63-
+ Instant.now().toString()
64-
+ System.lineSeparator()
65-
+ "Gradle "
66-
+ gradle.getGradleVersion()
67-
+ System.lineSeparator());
68-
}
57+
return builder.toString();
58+
}
6959

70-
@Override
71-
public void buildFinished(BuildResult buildResult) {
72-
StringBuilder log = new StringBuilder();
73-
log.append("Build finished at ")
74-
.append(Instant.now().toString())
75-
.append(System.lineSeparator());
76-
log.append("build action: ").append(buildResult.getAction()).append(System.lineSeparator());
77-
log.append("build result ")
78-
.append(
79-
buildResult.getFailure() != null
80-
? "FAILED with " + exceptionToString(buildResult.getFailure())
81-
: "SUCCESS")
82-
.append(System.lineSeparator());
83-
log.append("build tasks:").append(System.lineSeparator());
84-
final Gradle gradle = buildResult.getGradle();
85-
if (gradle != null) {
86-
gradle.getTaskGraph()
87-
.getAllTasks()
88-
.forEach(
89-
t ->
90-
log.append("* ")
91-
.append(t.getPath())
92-
.append(" state: ")
93-
.append(taskToString(t.getState()))
94-
.append(System.lineSeparator()));
95-
}
96-
appendToFile(log.toString());
60+
@Override
61+
public void projectsEvaluated(Gradle gradle) {
62+
appendToFile(
63+
"Build started at "
64+
+ Instant.now().toString()
65+
+ System.lineSeparator()
66+
+ "Gradle "
67+
+ gradle.getGradleVersion()
68+
+ System.lineSeparator());
69+
}
70+
71+
@Override
72+
public void buildFinished(BuildResult buildResult) {
73+
StringBuilder log = new StringBuilder();
74+
log.append("Build finished at ")
75+
.append(Instant.now().toString())
76+
.append(System.lineSeparator());
77+
log.append("build action: ").append(buildResult.getAction()).append(System.lineSeparator());
78+
log.append("build result ")
79+
.append(
80+
buildResult.getFailure() != null
81+
? "FAILED with " + exceptionToString(buildResult.getFailure())
82+
: "SUCCESS")
83+
.append(System.lineSeparator());
84+
log.append("build tasks:").append(System.lineSeparator());
85+
final Gradle gradle = buildResult.getGradle();
86+
if (gradle != null) {
87+
gradle
88+
.getTaskGraph()
89+
.getAllTasks()
90+
.forEach(
91+
t ->
92+
log.append("* ")
93+
.append(t.getPath())
94+
.append(" state: ")
95+
.append(taskToString(t.getState()))
96+
.append(System.lineSeparator()));
9797
}
98+
appendToFile(log.toString());
99+
}
98100

99-
private void appendToFile(String output) {
100-
// the file might be deleted if a "clean" task was executed.
101-
if (mOutputFile.exists()) {
102-
try {
103-
try (OutputStreamWriter writer =
104-
new OutputStreamWriter(
105-
new FileOutputStream(mOutputFile, true), StandardCharsets.UTF_8)) {
106-
writer.append(output);
107-
}
108-
} catch (IOException e) {
109-
throw new RuntimeException(e);
110-
}
101+
private void appendToFile(String output) {
102+
// the file might be deleted if a "clean" task was executed.
103+
if (mOutputFile.exists()) {
104+
try {
105+
try (OutputStreamWriter writer =
106+
new OutputStreamWriter(
107+
new FileOutputStream(mOutputFile, true), StandardCharsets.UTF_8)) {
108+
writer.append(output);
111109
}
110+
} catch (IOException e) {
111+
throw new RuntimeException(e);
112+
}
112113
}
114+
}
113115
}

0 commit comments

Comments
 (0)