Skip to content

Commit de1324e

Browse files
authored
Apply spotless and checkstyle (#5390)
1 parent 2bdbc8c commit de1324e

File tree

458 files changed

+8766
-5973
lines changed

Some content is hidden

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

458 files changed

+8766
-5973
lines changed

.github/workflows/ci-docker-wormhole.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ jobs:
1616
-v "$HOME:$HOME" \
1717
-v "$PWD:$PWD" \
1818
-w "$PWD" \
19+
-e AUTO_APPLY_GIT_HOOKS=false \
1920
openjdk:8-jdk-alpine \
2021
./gradlew --no-daemon --continue --scan testcontainers:test --tests '*GenericContainerRuleTest'

build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
buildscript {
22
repositories {
33
mavenCentral()
4+
maven { url 'https://jitpack.io' }
45
}
56

67
dependencies {
78
// https://github.com/melix/japicmp-gradle-plugin/issues/36
89
classpath 'com.google.guava:guava:30.1.1-jre'
10+
classpath 'com.github.kiview:captain-hook:76a1c11a16'
911
}
1012
}
1113

@@ -17,6 +19,12 @@ plugins {
1719
}
1820

1921
apply from: "$rootDir/gradle/ci-support.gradle"
22+
apply plugin: 'com.github.tjni.captainhook'
23+
24+
captainHook {
25+
autoApplyGitHooks = Boolean.valueOf(System.getenv("AUTO_APPLY_GIT_HOOKS"))
26+
preCommit = './gradlew spotlessApply'
27+
}
2028

2129
subprojects {
2230
apply plugin: 'java-library'
@@ -110,8 +118,8 @@ subprojects {
110118
}
111119

112120
spotless {
113-
enforceCheck false
114121
java {
122+
toggleOffOn()
115123
removeUnusedImports()
116124
trimTrailingWhitespace()
117125
endWithNewline()
@@ -134,6 +142,5 @@ subprojects {
134142
checkstyle {
135143
toolVersion = "9.3"
136144
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
137-
ignoreFailures = true
138145
}
139146
}

config/checkstyle/checkstyle.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
LITERAL_FOR,
1212
LITERAL_IF,
1313
LITERAL_WHILE,
14-
LITERAL_CASE,
15-
LITERAL_DEFAULT,
14+
"
15+
/>
16+
</module>
17+
<module name="NeedBraces">
18+
<property name="tokens"
19+
value="
1620
LAMBDA,
1721
"
1822
/>

core/src/jarFileTest/java/org/testcontainers/AbstractJarFileTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import java.nio.file.FileSystems;
66
import java.nio.file.Path;
77
import java.nio.file.Paths;
8-
9-
import static java.util.Collections.emptyMap;
8+
import java.util.Collections;
109

1110
public abstract class AbstractJarFileTest {
1211

@@ -16,7 +15,7 @@ public abstract class AbstractJarFileTest {
1615
try {
1716
Path jarFilePath = Paths.get(System.getProperty("jarFile"));
1817
URI jarFileUri = new URI("jar", jarFilePath.toUri().toString(), null);
19-
FileSystem fileSystem = FileSystems.newFileSystem(jarFileUri, emptyMap());
18+
FileSystem fileSystem = FileSystems.newFileSystem(jarFileUri, Collections.emptyMap());
2019
root = fileSystem.getPath("/");
2120
} catch (Exception e) {
2221
throw new RuntimeException(e);

core/src/jarFileTest/java/org/testcontainers/JarFileShadingTest.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,26 @@ public class JarFileShadingTest extends AbstractJarFileTest {
1313

1414
@Test
1515
public void testPackages() throws Exception {
16-
assertThatFileList(root).containsOnly(
17-
"org",
18-
"META-INF"
19-
);
20-
21-
assertThatFileList(root.resolve("org")).containsOnly(
22-
"testcontainers"
23-
);
16+
assertThatFileList(root).containsOnly("org", "META-INF");
17+
18+
assertThatFileList(root.resolve("org")).containsOnly("testcontainers");
2419
}
2520

2621
@Test
2722
public void testMetaInf() throws Exception {
28-
assertThatFileList(root.resolve("META-INF")).containsOnly(
29-
"MANIFEST.MF",
30-
"services"
31-
);
23+
assertThatFileList(root.resolve("META-INF")).containsOnly("MANIFEST.MF", "services");
3224
}
3325

3426
@Test
3527
public void testMetaInfServices() throws Exception {
3628
assertThatFileList(root.resolve("META-INF").resolve("services"))
37-
.allMatch(it -> it.startsWith("org.testcontainers."));
29+
.allMatch(it -> it.startsWith("org.testcontainers."));
3830
}
3931

4032
private ListAssert<String> assertThatFileList(Path path) throws IOException {
4133
return (ListAssert) assertThat(Files.list(path))
42-
.extracting(Path::getFileName)
43-
.extracting(Path::toString)
44-
.extracting(it -> it.endsWith("/") ? it.substring(0, it.length() - 1) : it);
34+
.extracting(Path::getFileName)
35+
.extracting(Path::toString)
36+
.extracting(it -> it.endsWith("/") ? it.substring(0, it.length() - 1) : it);
4537
}
4638
}

core/src/jarFileTest/java/org/testcontainers/PublicBinaryAPITest.java

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
public class PublicBinaryAPITest extends AbstractJarFileTest {
3838

3939
private static String SHADED_PACKAGE = "org.testcontainers.shaded.";
40+
4041
private static String SHADED_PACKAGE_PATH = SHADED_PACKAGE.replaceAll("\\.", "/");
4142

4243
static {
@@ -49,36 +50,38 @@ public class PublicBinaryAPITest extends AbstractJarFileTest {
4950
public static List<Object[]> data() throws Exception {
5051
List<Object[]> result = new ArrayList<>();
5152

52-
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
53-
54-
@Override
55-
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
56-
String fileName = path.toString();
53+
Files.walkFileTree(
54+
root,
55+
new SimpleFileVisitor<Path>() {
56+
@Override
57+
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
58+
String fileName = path.toString();
5759

58-
if (!fileName.endsWith(".class")) {
59-
return super.visitFile(path, attrs);
60-
}
60+
if (!fileName.endsWith(".class")) {
61+
return super.visitFile(path, attrs);
62+
}
6163

62-
if (!fileName.startsWith("/org/testcontainers/") ) {
63-
return super.visitFile(path, attrs);
64-
}
64+
if (!fileName.startsWith("/org/testcontainers/")) {
65+
return super.visitFile(path, attrs);
66+
}
6567

66-
if (fileName.startsWith("/" + SHADED_PACKAGE_PATH)) {
67-
return super.visitFile(path, attrs);
68-
}
68+
if (fileName.startsWith("/" + SHADED_PACKAGE_PATH)) {
69+
return super.visitFile(path, attrs);
70+
}
6971

70-
try(InputStream inputStream = Files.newInputStream(path)) {
71-
ClassReader reader = new ClassReader(inputStream);
72-
ClassNode node = new ClassNode();
73-
reader.accept(node, ClassReader.SKIP_CODE);
74-
if ((node.access & Opcodes.ACC_PUBLIC) != 0) {
75-
result.add(new Object[]{ fileName, node });
72+
try (InputStream inputStream = Files.newInputStream(path)) {
73+
ClassReader reader = new ClassReader(inputStream);
74+
ClassNode node = new ClassNode();
75+
reader.accept(node, ClassReader.SKIP_CODE);
76+
if ((node.access & Opcodes.ACC_PUBLIC) != 0) {
77+
result.add(new Object[] { fileName, node });
78+
}
7679
}
77-
}
7880

79-
return super.visitFile(path, attrs);
81+
return super.visitFile(path, attrs);
82+
}
8083
}
81-
});
84+
);
8285
return result;
8386
}
8487

@@ -100,39 +103,36 @@ public void setUp() {
100103

101104
@Test
102105
public void testSuperClass() {
103-
assertThat(classNode.superName)
104-
.doesNotStartWith(SHADED_PACKAGE_PATH);
106+
assertThat(classNode.superName).doesNotStartWith(SHADED_PACKAGE_PATH);
105107
}
106108

107109
@Test
108110
public void testInterfaces() {
109-
assertThat(classNode.interfaces)
110-
.allSatisfy(it -> assertThat(it).doesNotStartWith(SHADED_PACKAGE_PATH));
111+
assertThat(classNode.interfaces).allSatisfy(it -> assertThat(it).doesNotStartWith(SHADED_PACKAGE_PATH));
111112
}
112113

113114
@Test
114115
public void testMethodReturnTypes() {
115116
assertThat(classNode.methods)
116-
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
117-
.allSatisfy(it -> assertThat(Type.getReturnType(it.desc).getClassName()).doesNotStartWith(SHADED_PACKAGE));
117+
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
118+
.allSatisfy(it -> assertThat(Type.getReturnType(it.desc).getClassName()).doesNotStartWith(SHADED_PACKAGE));
118119
}
119120

120121
@Test
121122
public void testMethodArguments() {
122123
assertThat(classNode.methods)
123-
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
124-
.allSatisfy(method -> assertThat(Arrays.asList(Type.getArgumentTypes(method.desc)))
125-
.extracting(Type::getClassName)
126-
.allSatisfy(it -> assertThat(it).doesNotStartWith(SHADED_PACKAGE))
127-
);
124+
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
125+
.allSatisfy(method -> {
126+
assertThat(Arrays.asList(Type.getArgumentTypes(method.desc)))
127+
.extracting(Type::getClassName)
128+
.allSatisfy(it -> assertThat(it).doesNotStartWith(SHADED_PACKAGE));
129+
});
128130
}
129131

130132
@Test
131133
public void testFields() {
132134
assertThat(classNode.fields)
133-
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
134-
.allSatisfy(it -> assertThat(Type.getType(it.desc).getClassName())
135-
.doesNotStartWith(SHADED_PACKAGE)
136-
);
135+
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
136+
.allSatisfy(it -> assertThat(Type.getType(it.desc).getClassName()).doesNotStartWith(SHADED_PACKAGE));
137137
}
138138
}

0 commit comments

Comments
 (0)