Skip to content

Commit 43eb1e5

Browse files
shs96cdiemol
andauthored
Automatically format the code (#12023)
* Add a script to format the code in the project Currently, this only handles Java, but later revisions can be extended to cover other languages (and the build files) too. * Run the format script --------- Co-authored-by: Diego Molina <[email protected]>
1 parent 5c891ce commit 43eb1e5

File tree

1,056 files changed

+29039
-26928
lines changed

Some content is hidden

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

1,056 files changed

+29039
-26928
lines changed

Diff for: java/maven_deps.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def selenium_java_deps():
2424
"com.google.auto:auto-common:1.2.1",
2525
"com.google.auto.service:auto-service:1.0.1",
2626
"com.google.auto.service:auto-service-annotations:1.0.1",
27+
"com.google.googlejavaformat:google-java-format:jar:1.17.0",
2728
"com.graphql-java:graphql-java:20.2",
2829
"com.graphql-java:java-dataloader:3.2.0",
2930
"io.grpc:grpc-context:1.55.1",

Diff for: java/maven_install.json

+21
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@
136136
},
137137
"version": "2.11.0"
138138
},
139+
"com.google.googlejavaformat:google-java-format": {
140+
"shasums": {
141+
"jar": "631ba54c39f6c20df027dc1420736df2e5e43c581880efdd1e46ddb4ce050e3e",
142+
"sources": "75db73d4bc603e30ee28d2109dee973bf26dfc065499e18e086ddf90e1e90d6e"
143+
},
144+
"version": "1.17.0"
145+
},
139146
"com.google.guava:failureaccess": {
140147
"shasums": {
141148
"jar": "a171ee4c734dd2da837e4b16be9df4661afab72a41adaf31eb84dfdaf936ca26",
@@ -1143,6 +1150,9 @@
11431150
"com.google.auto:auto-common": [
11441151
"com.google.guava:guava"
11451152
],
1153+
"com.google.googlejavaformat:google-java-format": [
1154+
"com.google.guava:guava"
1155+
],
11461156
"com.google.guava:guava": [
11471157
"com.google.code.findbugs:jsr305",
11481158
"com.google.errorprone:error_prone_annotations",
@@ -1848,6 +1858,13 @@
18481858
"com.google.errorprone.annotations",
18491859
"com.google.errorprone.annotations.concurrent"
18501860
],
1861+
"com.google.googlejavaformat:google-java-format": [
1862+
"com.google.googlejavaformat",
1863+
"com.google.googlejavaformat.java",
1864+
"com.google.googlejavaformat.java.filer",
1865+
"com.google.googlejavaformat.java.java17",
1866+
"com.google.googlejavaformat.java.javadoc"
1867+
],
18511868
"com.google.guava:failureaccess": [
18521869
"com.google.common.util.concurrent.internal"
18531870
],
@@ -3637,6 +3654,8 @@
36373654
"com.google.code.gson:gson:jar:sources",
36383655
"com.google.errorprone:error_prone_annotations",
36393656
"com.google.errorprone:error_prone_annotations:jar:sources",
3657+
"com.google.googlejavaformat:google-java-format",
3658+
"com.google.googlejavaformat:google-java-format:jar:sources",
36403659
"com.google.guava:failureaccess",
36413660
"com.google.guava:failureaccess:jar:sources",
36423661
"com.google.guava:guava",
@@ -3954,6 +3973,8 @@
39543973
"com.google.code.gson:gson:jar:sources",
39553974
"com.google.errorprone:error_prone_annotations",
39563975
"com.google.errorprone:error_prone_annotations:jar:sources",
3976+
"com.google.googlejavaformat:google-java-format",
3977+
"com.google.googlejavaformat:google-java-format:jar:sources",
39573978
"com.google.guava:failureaccess",
39583979
"com.google.guava:failureaccess:jar:sources",
39593980
"com.google.guava:guava",

Diff for: java/src/dev/selenium/tools/javadoc/JavadocJarMaker.java

+70-51
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@
1717

1818
package dev.selenium.tools.javadoc;
1919

20-
import com.github.bazelbuild.rules_jvm_external.zip.StableZipEntry;
21-
import org.openqa.selenium.io.TemporaryFilesystem;
20+
import static java.nio.charset.StandardCharsets.UTF_8;
2221

23-
import javax.tools.DocumentationTool;
24-
import javax.tools.JavaFileObject;
25-
import javax.tools.StandardJavaFileManager;
26-
import javax.tools.StandardLocation;
27-
import javax.tools.ToolProvider;
22+
import com.github.bazelbuild.rules_jvm_external.zip.StableZipEntry;
2823
import java.io.File;
2924
import java.io.IOException;
3025
import java.io.InputStream;
@@ -46,8 +41,12 @@
4641
import java.util.zip.ZipEntry;
4742
import java.util.zip.ZipInputStream;
4843
import java.util.zip.ZipOutputStream;
49-
50-
import static java.nio.charset.StandardCharsets.UTF_8;
44+
import javax.tools.DocumentationTool;
45+
import javax.tools.JavaFileObject;
46+
import javax.tools.StandardJavaFileManager;
47+
import javax.tools.StandardLocation;
48+
import javax.tools.ToolProvider;
49+
import org.openqa.selenium.io.TemporaryFilesystem;
5150

5251
public class JavadocJarMaker {
5352

@@ -76,11 +75,13 @@ public static void main(String[] args) throws IOException {
7675
}
7776

7877
if (sourceJars.isEmpty()) {
79-
throw new IllegalArgumentException("At least one input just must be specified via the --in flag");
78+
throw new IllegalArgumentException(
79+
"At least one input just must be specified via the --in flag");
8080
}
8181

8282
if (out == null) {
83-
throw new IllegalArgumentException("The output jar location must be specified via the --out flag");
83+
throw new IllegalArgumentException(
84+
"The output jar location must be specified via the --out flag");
8485
}
8586

8687
TemporaryFilesystem tmpFS = TemporaryFilesystem.getDefaultTmpFS();
@@ -89,22 +90,26 @@ public static void main(String[] args) throws IOException {
8990
tempDirs.add(dir);
9091

9192
DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
92-
try (StandardJavaFileManager fileManager = tool.getStandardFileManager(null, Locale.getDefault(), UTF_8)) {
93+
try (StandardJavaFileManager fileManager =
94+
tool.getStandardFileManager(null, Locale.getDefault(), UTF_8)) {
9395
fileManager.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, List.of(dir));
94-
fileManager.setLocation(StandardLocation.CLASS_PATH, classpath.stream().map(Path::toFile).collect(Collectors.toSet()));
96+
fileManager.setLocation(
97+
StandardLocation.CLASS_PATH,
98+
classpath.stream().map(Path::toFile).collect(Collectors.toSet()));
9599

96100
Set<JavaFileObject> sources = new HashSet<>();
97101
Set<String> topLevelPackages = new HashSet<>();
98102

99103
File unpackTo = tmpFS.createTempDir("unpacked-sources", "");
100104
tempDirs.add(unpackTo);
101105
Set<String> fileNames = new HashSet<>();
102-
readSourceFiles(unpackTo.toPath(), fileManager, sourceJars, sources, topLevelPackages, fileNames);
106+
readSourceFiles(
107+
unpackTo.toPath(), fileManager, sourceJars, sources, topLevelPackages, fileNames);
103108

104109
// True if we're just exporting a set of modules
105110
if (sources.isEmpty()) {
106111
try (OutputStream os = Files.newOutputStream(out);
107-
ZipOutputStream zos = new ZipOutputStream(os)) {
112+
ZipOutputStream zos = new ZipOutputStream(os)) {
108113
// It's enough to just create the thing
109114
}
110115
return;
@@ -113,10 +118,21 @@ public static void main(String[] args) throws IOException {
113118
List<String> options = new ArrayList<>();
114119
if (!classpath.isEmpty()) {
115120
options.add("-cp");
116-
options.add(classpath.stream().map(String::valueOf).collect(Collectors.joining(File.pathSeparator)));
121+
options.add(
122+
classpath.stream()
123+
.map(String::valueOf)
124+
.collect(Collectors.joining(File.pathSeparator)));
117125
}
118-
options.addAll(List.of("-html5", "--frames", "-notimestamp", "-use", "-quiet", "-Xdoclint:-missing", "-encoding", "UTF8"));
119-
126+
options.addAll(
127+
List.of(
128+
"-html5",
129+
"--frames",
130+
"-notimestamp",
131+
"-use",
132+
"-quiet",
133+
"-Xdoclint:-missing",
134+
"-encoding",
135+
"UTF8"));
120136

121137
File outputTo = tmpFS.createTempDir("output-dir", "");
122138
tempDirs.add(outputTo);
@@ -127,7 +143,8 @@ public static void main(String[] args) throws IOException {
127143
sources.forEach(obj -> options.add(obj.getName()));
128144

129145
Writer writer = new StringWriter();
130-
DocumentationTool.DocumentationTask task = tool.getTask(writer, fileManager, null, null, options, sources);
146+
DocumentationTool.DocumentationTask task =
147+
tool.getTask(writer, fileManager, null, null, options, sources);
131148
Boolean result = task.call();
132149
if (result == null || !result) {
133150
System.err.println("javadoc " + String.join(" ", options));
@@ -136,46 +153,48 @@ public static void main(String[] args) throws IOException {
136153
}
137154

138155
try (OutputStream os = Files.newOutputStream(out);
139-
ZipOutputStream zos = new ZipOutputStream(os);
140-
Stream<Path> walk = Files.walk(outputToPath)) {
156+
ZipOutputStream zos = new ZipOutputStream(os);
157+
Stream<Path> walk = Files.walk(outputToPath)) {
141158
walk.sorted(Comparator.naturalOrder())
142-
.forEachOrdered(path -> {
143-
if (path.equals(outputToPath)) {
144-
return;
145-
}
146-
147-
try {
148-
if (Files.isDirectory(path)) {
149-
String name = outputToPath.relativize(path) + "/";
150-
ZipEntry entry = new StableZipEntry(name);
151-
zos.putNextEntry(entry);
152-
zos.closeEntry();
153-
} else {
154-
String name = outputToPath.relativize(path).toString();
155-
ZipEntry entry = new StableZipEntry(name);
156-
zos.putNextEntry(entry);
157-
try (InputStream is = Files.newInputStream(path)) {
158-
is.transferTo(zos);
159-
}
160-
zos.closeEntry();
161-
}
162-
} catch (IOException e) {
163-
throw new UncheckedIOException(e);
164-
}
165-
});
159+
.forEachOrdered(
160+
path -> {
161+
if (path.equals(outputToPath)) {
162+
return;
163+
}
164+
165+
try {
166+
if (Files.isDirectory(path)) {
167+
String name = outputToPath.relativize(path) + "/";
168+
ZipEntry entry = new StableZipEntry(name);
169+
zos.putNextEntry(entry);
170+
zos.closeEntry();
171+
} else {
172+
String name = outputToPath.relativize(path).toString();
173+
ZipEntry entry = new StableZipEntry(name);
174+
zos.putNextEntry(entry);
175+
try (InputStream is = Files.newInputStream(path)) {
176+
is.transferTo(zos);
177+
}
178+
zos.closeEntry();
179+
}
180+
} catch (IOException e) {
181+
throw new UncheckedIOException(e);
182+
}
183+
});
166184
}
167185
}
168186

169187
tempDirs.forEach(tmpFS::deleteTempDir);
170188
}
171189

172190
private static void readSourceFiles(
173-
Path unpackTo,
174-
StandardJavaFileManager fileManager,
175-
Set<Path> sourceJars,
176-
Set<JavaFileObject> sources,
177-
Set<String> topLevelPackages,
178-
Set<String> fileNames) throws IOException {
191+
Path unpackTo,
192+
StandardJavaFileManager fileManager,
193+
Set<Path> sourceJars,
194+
Set<JavaFileObject> sources,
195+
Set<String> topLevelPackages,
196+
Set<String> fileNames)
197+
throws IOException {
179198

180199
for (Path jar : sourceJars) {
181200
if (!Files.exists(jar)) {

Diff for: java/src/dev/selenium/tools/modules/ModuleGenerator.java

+14-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
package dev.selenium.tools.modules;
1919

20+
import static com.github.javaparser.ParseStart.COMPILATION_UNIT;
21+
import static net.bytebuddy.jar.asm.Opcodes.ACC_MANDATED;
22+
import static net.bytebuddy.jar.asm.Opcodes.ACC_MODULE;
23+
import static net.bytebuddy.jar.asm.Opcodes.ACC_OPEN;
24+
import static net.bytebuddy.jar.asm.Opcodes.ACC_TRANSITIVE;
25+
import static net.bytebuddy.jar.asm.Opcodes.ASM9;
26+
2027
import com.github.bazelbuild.rules_jvm_external.zip.StableZipEntry;
2128
import com.github.javaparser.JavaParser;
2229
import com.github.javaparser.ParseResult;
@@ -34,14 +41,6 @@
3441
import com.github.javaparser.ast.modules.ModuleRequiresDirective;
3542
import com.github.javaparser.ast.modules.ModuleUsesDirective;
3643
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
37-
import net.bytebuddy.jar.asm.ClassReader;
38-
import net.bytebuddy.jar.asm.ClassVisitor;
39-
import net.bytebuddy.jar.asm.ClassWriter;
40-
import net.bytebuddy.jar.asm.MethodVisitor;
41-
import net.bytebuddy.jar.asm.ModuleVisitor;
42-
import net.bytebuddy.jar.asm.Type;
43-
import org.openqa.selenium.io.TemporaryFilesystem;
44-
4544
import java.io.ByteArrayOutputStream;
4645
import java.io.File;
4746
import java.io.IOException;
@@ -80,13 +79,13 @@
8079
import java.util.stream.Stream;
8180
import java.util.zip.ZipEntry;
8281
import java.util.zip.ZipOutputStream;
83-
84-
import static com.github.javaparser.ParseStart.COMPILATION_UNIT;
85-
import static net.bytebuddy.jar.asm.Opcodes.ACC_MANDATED;
86-
import static net.bytebuddy.jar.asm.Opcodes.ACC_MODULE;
87-
import static net.bytebuddy.jar.asm.Opcodes.ACC_OPEN;
88-
import static net.bytebuddy.jar.asm.Opcodes.ACC_TRANSITIVE;
89-
import static net.bytebuddy.jar.asm.Opcodes.ASM9;
82+
import net.bytebuddy.jar.asm.ClassReader;
83+
import net.bytebuddy.jar.asm.ClassVisitor;
84+
import net.bytebuddy.jar.asm.ClassWriter;
85+
import net.bytebuddy.jar.asm.MethodVisitor;
86+
import net.bytebuddy.jar.asm.ModuleVisitor;
87+
import net.bytebuddy.jar.asm.Type;
88+
import org.openqa.selenium.io.TemporaryFilesystem;
9089

9190
public class ModuleGenerator {
9291

Diff for: java/src/org/openqa/selenium/AcceptedW3CCapabilityKeys.java

+17-16
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@
2323

2424
public class AcceptedW3CCapabilityKeys implements Predicate<String> {
2525

26-
private static final Predicate<String> ACCEPTED_W3C_PATTERNS = Stream.of(
27-
"^[\\w-]+:.*$",
28-
"^acceptInsecureCerts$",
29-
"^browserName$",
30-
"^browserVersion$",
31-
"^platformName$",
32-
"^pageLoadStrategy$",
33-
"^proxy$",
34-
"^setWindowRect$",
35-
"^strictFileInteractability$",
36-
"^timeouts$",
37-
"^unhandledPromptBehavior$",
38-
"^webSocketUrl$") // from webdriver-bidi
39-
.map(Pattern::compile)
40-
.map(Pattern::asPredicate)
41-
.reduce(identity -> false, Predicate::or);
26+
private static final Predicate<String> ACCEPTED_W3C_PATTERNS =
27+
Stream.of(
28+
"^[\\w-]+:.*$",
29+
"^acceptInsecureCerts$",
30+
"^browserName$",
31+
"^browserVersion$",
32+
"^platformName$",
33+
"^pageLoadStrategy$",
34+
"^proxy$",
35+
"^setWindowRect$",
36+
"^strictFileInteractability$",
37+
"^timeouts$",
38+
"^unhandledPromptBehavior$",
39+
"^webSocketUrl$") // from webdriver-bidi
40+
.map(Pattern::compile)
41+
.map(Pattern::asPredicate)
42+
.reduce(identity -> false, Predicate::or);
4243

4344
@Override
4445
public boolean test(String capabilityName) {

0 commit comments

Comments
 (0)