Skip to content

Commit c819ca0

Browse files
author
Gary Gregory
committed
Checkstyle and fix test sources.
- Move Checkstyle configuration from root folder to src/conf. - Remove unused imports. - Remove trailing whitespace. - Adjust line lengths. - No tabs. - Use final.
1 parent e90866f commit c819ca0

28 files changed

Lines changed: 290 additions & 293 deletions

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,10 @@ file comparators, endian transformation classes, and much more.
372372
<artifactId>maven-checkstyle-plugin</artifactId>
373373
<version>${checkstyle.plugin.version}</version>
374374
<configuration>
375-
<configLocation>${basedir}/checkstyle.xml</configLocation>
375+
<configLocation>${basedir}/src/conf/checkstyle.xml</configLocation>
376+
<suppressionsLocation>${basedir}/src/conf/checkstyle-suppressions.xml</suppressionsLocation>
376377
<enableRulesSummary>false</enableRulesSummary>
378+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
377379
</configuration>
378380
<dependencies>
379381
<dependency>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE suppressions PUBLIC
3+
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
4+
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
5+
<!--
6+
Licensed to the Apache Software Foundation (ASF) under one or more
7+
contributor license agreements. See the NOTICE file distributed with
8+
this work for additional information regarding copyright ownership.
9+
The ASF licenses this file to You under the Apache License, Version 2.0
10+
(the "License"); you may not use this file except in compliance with
11+
the License. You may obtain a copy of the License at
12+
13+
http://www.apache.org/licenses/LICENSE-2.0
14+
15+
Unless required by applicable law or agreed to in writing, software
16+
distributed under the License is distributed on an "AS IS" BASIS,
17+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
See the License for the specific language governing permissions and
19+
limitations under the License.
20+
-->
21+
22+
<suppressions>
23+
<!-- Suppress test Javadoc checks-->
24+
<suppress checks="JavadocMethod" files="src[/\\]test[/\\]java[/\\]" />
25+
<suppress checks="JavadocPackage" files="src[/\\]test[/\\]java[/\\]" />
26+
<!-- Suppress generated-test-sources checks-->
27+
<suppress checks=".*" files="target[/\\]generated-test-sources[/\\]" />
28+
</suppressions>

checkstyle.xml renamed to src/conf/checkstyle.xml

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,31 @@ limitations under the License.
1818
<!DOCTYPE module PUBLIC
1919
"-//Checkstyle//DTD Checkstyle Configuration 1.2//EN"
2020
"https://checkstyle.org/dtds/configuration_1_2.dtd">
21-
<!-- commons lang customization of default Checkstyle behavior -->
2221
<module name="Checker">
23-
<property name="localeLanguage" value="en"/>
22+
<property name="localeLanguage" value="en" />
2423
<module name="JavadocPackage">
2524
<!-- setting allowLegacy means it will check for package.html instead of just package-info.java -->
26-
<property name="allowLegacy" value="true"/>
25+
<property name="allowLegacy" value="true" />
2726
</module>
2827
<module name="FileTabCharacter">
29-
<property name="fileExtensions" value="java,xml"/>
28+
<property name="fileExtensions" value="java,xml" />
3029
</module>
3130
<module name="LineLength">
32-
<property name="max" value="160"/>
31+
<property name="max" value="160" />
3332
</module>
3433
<module name="TreeWalker">
35-
<module name="AvoidStarImport"/>
36-
<module name="RedundantImport"/>
37-
<module name="UnusedImports"/>
38-
<module name="NeedBraces"/>
39-
<module name="LeftCurly"/>
40-
<module name="JavadocMethod">
41-
</module>
42-
<!-- No Trailing whitespace -->
43-
<module name="Regexp">
44-
<property name="format" value="[ \t]+$"/>
45-
<property name="illegalPattern" value="true"/>
46-
<property name="message" value="Trailing whitespace"/>
47-
</module>
48-
</module>
34+
<module name="AvoidStarImport" />
35+
<module name="RedundantImport" />
36+
<module name="UnusedImports" />
37+
<module name="NeedBraces" />
38+
<module name="LeftCurly" />
39+
<module name="JavadocMethod" />
40+
<module name="FinalLocalVariable" />
41+
<!-- No Trailing whitespace -->
42+
<module name="Regexp">
43+
<property name="format" value="[ \t]+$" />
44+
<property name="illegalPattern" value="true" />
45+
<property name="message" value="Trailing whitespace" />
46+
</module>
47+
</module>
4948
</module>

src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public long skip(final long n) throws IOException {
383383
return n;
384384
}
385385
stateChangeLock.lock();
386-
long skipped;
386+
final long skipped;
387387
try {
388388
skipped = skipInternal(n);
389389
} finally {

src/test/java/org/apache/commons/io/FileCleaningTrackerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.junit.jupiter.api.Assertions.assertNull;
2222
import static org.junit.jupiter.api.Assertions.assertThrows;
2323
import static org.junit.jupiter.api.Assertions.assertTrue;
24-
import static org.junit.jupiter.api.Assertions.fail;
2524

2625
import java.io.BufferedOutputStream;
2726
import java.io.File;
@@ -33,7 +32,6 @@
3332
import java.util.ArrayList;
3433
import java.util.List;
3534

36-
import org.apache.commons.io.filefilter.PrefixFileFilter;
3735
import org.apache.commons.io.test.TestUtils;
3836
import org.junit.jupiter.api.AfterEach;
3937
import org.junit.jupiter.api.BeforeEach;
@@ -185,7 +183,7 @@ public void testFileCleanerExitWhenFinished_NoTrackAfter() {
185183

186184
final String path = testFile.getPath();
187185
final Object marker = new Object();
188-
186+
189187
assertThrows(IllegalStateException.class, () -> theInstance.track(path, marker));
190188
assertTrue(theInstance.exitWhenFinished);
191189
assertNull(theInstance.reaper);
@@ -306,12 +304,14 @@ private void waitUntilTrackCount() throws Exception {
306304
System.gc();
307305
TestUtils.sleep(500);
308306
int count = 0;
309-
while(theInstance.getTrackCount() != 0 && count++ < 5) {
307+
while (theInstance.getTrackCount() != 0 && count++ < 5) {
310308
List<String> list = new ArrayList<>();
311309
try {
312310
long i = 0;
313311
while (theInstance.getTrackCount() != 0) {
314-
list.add("A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String " + (i++));
312+
list.add(
313+
"A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String "
314+
+ (i++));
315315
}
316316
} catch (final Throwable ignored) {
317317
}

src/test/java/org/apache/commons/io/FileDeleteStrategyTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static org.junit.jupiter.api.Assertions.assertFalse;
2121
import static org.junit.jupiter.api.Assertions.assertThrows;
2222
import static org.junit.jupiter.api.Assertions.assertTrue;
23-
import static org.junit.jupiter.api.Assertions.fail;
2423

2524
import java.io.BufferedOutputStream;
2625
import java.io.File;

src/test/java/org/apache/commons/io/FileSystemUtilsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertNotNull;
2121
import static org.junit.jupiter.api.Assertions.assertThrows;
22-
import static org.junit.jupiter.api.Assertions.fail;
2322

2423
import java.io.BufferedReader;
2524
import java.io.ByteArrayInputStream;

src/test/java/org/apache/commons/io/FileUtilsDeleteDirectoryLinuxTest.java

Lines changed: 83 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -33,88 +33,87 @@
3333
@DisabledOnOs({OS.WINDOWS, OS.MAC})
3434
public class FileUtilsDeleteDirectoryLinuxTest extends FileUtilsDeleteDirectoryBaseTest {
3535

36-
/** Only runs on Linux. */
37-
private boolean chmod(final File file, final int mode, final boolean recurse) throws InterruptedException {
38-
final List<String> args = new ArrayList<>();
39-
args.add("chmod");
40-
41-
if (recurse) {
42-
args.add("-R");
43-
}
44-
45-
args.add(Integer.toString(mode));
46-
args.add(file.getAbsolutePath());
47-
48-
final Process proc;
49-
50-
try {
51-
proc = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
52-
} catch (final IOException e) {
53-
return false;
54-
}
55-
return proc.waitFor() == 0;
56-
}
57-
58-
@Override
59-
protected boolean setupSymlink(final File res, final File link) throws Exception {
60-
// create symlink
61-
final List<String> args = new ArrayList<>();
62-
args.add("ln");
63-
args.add("-s");
64-
65-
args.add(res.getAbsolutePath());
66-
args.add(link.getAbsolutePath());
67-
68-
final Process proc;
69-
70-
proc = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
71-
return proc.waitFor() == 0;
72-
}
73-
74-
@Test
75-
public void testThrowsOnCannotDeleteFile() throws Exception {
76-
final File nested = new File(top, "nested");
77-
assertTrue(nested.mkdirs());
78-
79-
final File file = new File(nested, "restricted");
80-
FileUtils.touch(file);
81-
82-
assumeTrue(chmod(nested, 500, false));
83-
84-
try {
85-
// deleteDirectory calls forceDelete
86-
FileUtils.deleteDirectory(nested);
87-
fail("expected IOException");
88-
} catch (final IOException e) {
89-
final IOExceptionList list = (IOExceptionList) e;
90-
assertEquals("Cannot delete file: " + file.getAbsolutePath(), list.getCause(0).getMessage());
91-
} finally {
92-
chmod(nested, 755, false);
93-
FileUtils.deleteDirectory(nested);
94-
}
95-
assertEquals(0, top.list().length);
96-
}
97-
98-
@Test
99-
public void testThrowsOnNullList() throws Exception {
100-
final File nested = new File(top, "nested");
101-
assertTrue(nested.mkdirs());
102-
103-
// test wont work if we can't restrict permissions on the
104-
// directory, so skip it.
105-
assumeTrue(chmod(nested, 0, false));
106-
107-
try {
108-
// cleanDirectory calls forceDelete
109-
FileUtils.deleteDirectory(nested);
110-
fail("expected IOException");
111-
} catch (final IOException e) {
112-
assertEquals("Unknown I/O error listing contents of directory: " + nested.getAbsolutePath(),
113-
e.getMessage());
114-
} finally {
115-
chmod(nested, 755, false);
116-
FileUtils.deleteDirectory(nested);
117-
}
118-
assertEquals(0, top.list().length);
119-
}
36+
/** Only runs on Linux. */
37+
private boolean chmod(final File file, final int mode, final boolean recurse) throws InterruptedException {
38+
final List<String> args = new ArrayList<>();
39+
args.add("chmod");
40+
41+
if (recurse) {
42+
args.add("-R");
43+
}
44+
45+
args.add(Integer.toString(mode));
46+
args.add(file.getAbsolutePath());
47+
48+
final Process proc;
49+
50+
try {
51+
proc = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
52+
} catch (final IOException e) {
53+
return false;
54+
}
55+
return proc.waitFor() == 0;
56+
}
57+
58+
@Override
59+
protected boolean setupSymlink(final File res, final File link) throws Exception {
60+
// create symlink
61+
final List<String> args = new ArrayList<>();
62+
args.add("ln");
63+
args.add("-s");
64+
65+
args.add(res.getAbsolutePath());
66+
args.add(link.getAbsolutePath());
67+
68+
final Process proc;
69+
70+
proc = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
71+
return proc.waitFor() == 0;
72+
}
73+
74+
@Test
75+
public void testThrowsOnCannotDeleteFile() throws Exception {
76+
final File nested = new File(top, "nested");
77+
assertTrue(nested.mkdirs());
78+
79+
final File file = new File(nested, "restricted");
80+
FileUtils.touch(file);
81+
82+
assumeTrue(chmod(nested, 500, false));
83+
84+
try {
85+
// deleteDirectory calls forceDelete
86+
FileUtils.deleteDirectory(nested);
87+
fail("expected IOException");
88+
} catch (final IOException e) {
89+
final IOExceptionList list = (IOExceptionList) e;
90+
assertEquals("Cannot delete file: " + file.getAbsolutePath(), list.getCause(0).getMessage());
91+
} finally {
92+
chmod(nested, 755, false);
93+
FileUtils.deleteDirectory(nested);
94+
}
95+
assertEquals(0, top.list().length);
96+
}
97+
98+
@Test
99+
public void testThrowsOnNullList() throws Exception {
100+
final File nested = new File(top, "nested");
101+
assertTrue(nested.mkdirs());
102+
103+
// test wont work if we can't restrict permissions on the
104+
// directory, so skip it.
105+
assumeTrue(chmod(nested, 0, false));
106+
107+
try {
108+
// cleanDirectory calls forceDelete
109+
FileUtils.deleteDirectory(nested);
110+
fail("expected IOException");
111+
} catch (final IOException e) {
112+
assertEquals("Unknown I/O error listing contents of directory: " + nested.getAbsolutePath(), e.getMessage());
113+
} finally {
114+
chmod(nested, 755, false);
115+
FileUtils.deleteDirectory(nested);
116+
}
117+
assertEquals(0, top.list().length);
118+
}
120119
}

0 commit comments

Comments
 (0)