Skip to content

Commit 6e1d370

Browse files
Claudenwottlinger
andauthored
RAT-563: Rename IReportable and IReportableListWalker (#686)
* rename IReportable and IReportableListWalker * added tests * added license header * RAT-563: Add serial annotation --------- Co-authored-by: P. Ottlinger <pottlinger@apache.org>
1 parent 8f1322a commit 6e1d370

14 files changed

Lines changed: 197 additions & 58 deletions

File tree

apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.File;
2222
import java.io.IOException;
2323
import java.io.PrintWriter;
24+
import java.io.Serial;
2425
import java.io.Serializable;
2526
import java.nio.charset.StandardCharsets;
2627
import java.util.Arrays;
@@ -48,7 +49,7 @@
4849
import org.apache.rat.document.FileDocument;
4950
import org.apache.rat.help.Licenses;
5051
import org.apache.rat.license.LicenseSetFactory;
51-
import org.apache.rat.report.IReportable;
52+
import org.apache.rat.report.Reportable;
5253
import org.apache.rat.report.claim.ClaimStatistic;
5354
import org.apache.rat.utils.DefaultLog;
5455
import org.apache.rat.utils.Log.Level;
@@ -190,7 +191,7 @@ public static ReportConfiguration createConfiguration(final ArgumentContext argu
190191
}
191192
}
192193
for (String s : commandLine.getArgs()) {
193-
IReportable reportable = getReportable(new File(s), configuration);
194+
Reportable reportable = getReportable(new File(s), configuration);
194195
if (reportable != null) {
195196
configuration.addSource(reportable);
196197
}
@@ -208,14 +209,14 @@ public static Options buildOptions() {
208209
}
209210

210211
/**
211-
* Creates an IReportable object from the directory name and ReportConfiguration
212+
* Creates a Reportable object from the directory name and ReportConfiguration
212213
* object.
213214
*
214215
* @param base the directory that contains the files to report on.
215216
* @param config the ReportConfiguration.
216-
* @return the IReportable instance containing the files.
217+
* @return the Reportable instance containing the files.
217218
*/
218-
public static IReportable getReportable(final File base, final ReportConfiguration config) {
219+
public static Reportable getReportable(final File base, final ReportConfiguration config) {
219220
File absBase = base.getAbsoluteFile();
220221
DocumentName documentName = DocumentName.builder(absBase).build();
221222
if (!absBase.exists()) {
@@ -242,6 +243,7 @@ public static IReportable getReportable(final File base, final ReportConfigurati
242243
*/
243244
private static final class OptionComparator implements Comparator<Option>, Serializable {
244245
/** The serial version UID. */
246+
@Serial
245247
private static final long serialVersionUID = 5305467873966684014L;
246248

247249
private String getKey(final Option opt) {

apache-rat-core/src/main/java/org/apache/rat/OptionCollectionParser.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.File;
2222
import java.io.IOException;
2323
import java.io.PrintWriter;
24+
import java.io.Serial;
2425
import java.io.Serializable;
2526
import java.nio.charset.StandardCharsets;
2627
import java.util.Comparator;
@@ -34,7 +35,7 @@
3435
import org.apache.rat.commandline.Arg;
3536
import org.apache.rat.commandline.ArgumentContext;
3637
import org.apache.rat.help.Licenses;
37-
import org.apache.rat.report.IReportable;
38+
import org.apache.rat.report.Reportable;
3839
import org.apache.rat.ui.UIOptionCollection;
3940
import org.apache.rat.utils.DefaultLog;
4041

@@ -126,7 +127,7 @@ private ReportConfiguration populateConfiguration(final ArgumentContext argument
126127
final CommandLine commandLine = argumentContext.getCommandLine();
127128
if (!configuration.hasSource()) {
128129
for (String s : commandLine.getArgs()) {
129-
IReportable reportable = OptionCollection.getReportable(new File(s), configuration);
130+
Reportable reportable = OptionCollection.getReportable(new File(s), configuration);
130131
if (reportable != null) {
131132
configuration.addSource(reportable);
132133
}
@@ -140,6 +141,7 @@ private ReportConfiguration populateConfiguration(final ArgumentContext argument
140141
*/
141142
private static final class OptionComparator implements Comparator<Option>, Serializable {
142143
/** The serial version UID. */
144+
@Serial
143145
private static final long serialVersionUID = 5305467873966684014L;
144146

145147
private String getKey(final Option opt) {

apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454
import org.apache.rat.license.ILicenseFamily;
5555
import org.apache.rat.license.LicenseSetFactory;
5656
import org.apache.rat.license.LicenseSetFactory.LicenseFilter;
57-
import org.apache.rat.report.IReportable;
57+
import org.apache.rat.report.Reportable;
5858
import org.apache.rat.utils.DefaultLog;
5959
import org.apache.rat.utils.Log.Level;
6060
import org.apache.rat.utils.ReportingSet;
6161
import org.apache.rat.walker.FileListWalker;
62-
import org.apache.rat.walker.IReportableListWalker;
62+
import org.apache.rat.walker.ReportableListWalker;
6363

6464
/**
6565
* A configuration object is used by the front end to invoke the
@@ -131,7 +131,7 @@ public String desc() {
131131
/**
132132
* A list of reportables to process;
133133
*/
134-
private final List<IReportable> reportables;
134+
private final List<Reportable> reportables;
135135

136136
/**
137137
* A predicate to test if a path should be included in the processing.
@@ -210,7 +210,7 @@ private void notNull(final Object o, final String msg) {
210210
* Adds a Reportable as a source of files to scan.
211211
* @param reportable the reportable to process.
212212
*/
213-
public void addSource(final IReportable reportable) {
213+
public void addSource(final Reportable reportable) {
214214
notNull(reportable, "Reportable may not be null.");
215215
reportables.add(reportable);
216216
}
@@ -227,9 +227,9 @@ public boolean hasSource() {
227227
* Gets a builder initialized with any files specified as sources.
228228
* @return a configured builder.
229229
*/
230-
public IReportableListWalker.Builder getSources() {
230+
public ReportableListWalker.Builder getSources() {
231231
DocumentName name = DocumentName.builder(new File(".")).build();
232-
IReportableListWalker.Builder builder = IReportableListWalker.builder(name);
232+
ReportableListWalker.Builder builder = ReportableListWalker.builder(name);
233233
sources.forEach(file -> builder.addReportable(new FileListWalker(new FileDocument(file, DocumentNameMatcher.MATCHES_ALL))));
234234
reportables.forEach(builder::addReportable);
235235
return builder;
@@ -427,7 +427,7 @@ public void addIncludedPatterns(final Iterable<String> patterns) {
427427
}
428428

429429
/**
430-
* Get the DocumentNameMatcher that excludes files found in the directory tree..
430+
* Get the DocumentNameMatcher that excludes files found in the directory tree.
431431
* @param baseDir the DocumentName for the base directory.
432432
* @return the DocumentNameMatcher for the base directory.
433433
*/

apache-rat-core/src/main/java/org/apache/rat/config/exclusion/ExclusionProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
/**
3838
* Processes the include and exclude patterns and applies the result against a base directory
39-
* to return an IReportable that contains all the reportable objects.
39+
* to return a Reportable that contains all the reportable objects.
4040
*/
4141
public class ExclusionProcessor {
4242
/** Strings that identify the files/directories to exclude */

apache-rat-core/src/main/java/org/apache/rat/report/IReportable.java renamed to apache-rat-core/src/main/java/org/apache/rat/report/Reportable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.apache.rat.api.RatException;
2222
import org.apache.rat.document.DocumentName;
2323

24-
public interface IReportable {
24+
public interface Reportable {
2525
/**
2626
* Adds the reportable to the RatReport.
2727
* @param report the report to add the results to.
@@ -33,5 +33,5 @@ public interface IReportable {
3333
* Returns the DocumentName for the reportable.
3434
* @return the DocumentName for the reportable.
3535
*/
36-
DocumentName getName();
36+
DocumentName name();
3737
}

apache-rat-core/src/main/java/org/apache/rat/walker/FileListWalker.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
import org.apache.rat.document.DocumentName;
3030
import org.apache.rat.document.DocumentNameMatcher;
3131
import org.apache.rat.document.FileDocument;
32-
import org.apache.rat.report.IReportable;
3332
import org.apache.rat.report.RatReport;
33+
import org.apache.rat.report.Reportable;
3434
import org.apache.rat.utils.DefaultLog;
3535

3636
/**
37-
* Implementation of IReportable that traverses over a resource collection
37+
* Implementation of Reportable that traverses over a resource collection
3838
* internally.
3939
*/
40-
public class FileListWalker implements IReportable {
40+
public class FileListWalker implements Reportable {
4141
/** The source document name. */
4242
private final FileDocument source;
4343
/** The root document name. */
@@ -72,7 +72,7 @@ private FileDocument createDocument(final String unixFileName) {
7272
@Override
7373
public void run(final RatReport report) throws RatException {
7474
DefaultLog.getInstance().debug(String.format("Reading file name: %s due to option %s", source, Arg.SOURCE.option()));
75-
DocumentName sourceName = getName();
75+
DocumentName sourceName = name();
7676
try (Reader reader = source.reader()) {
7777
for (String docName : IOUtils.readLines(reader)) {
7878
try {
@@ -93,7 +93,7 @@ public void run(final RatReport report) throws RatException {
9393
}
9494

9595
@Override
96-
public DocumentName getName() {
96+
public DocumentName name() {
9797
return source.getName();
9898
}
9999
}

apache-rat-core/src/main/java/org/apache/rat/walker/IReportableListWalker.java renamed to apache-rat-core/src/main/java/org/apache/rat/walker/ReportableListWalker.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424

2525
import org.apache.rat.api.RatException;
2626
import org.apache.rat.document.DocumentName;
27-
import org.apache.rat.report.IReportable;
2827
import org.apache.rat.report.RatReport;
28+
import org.apache.rat.report.Reportable;
2929
import org.apache.rat.utils.DefaultLog;
3030

3131
/**
32-
* A Reportable that walks a list of IReportables and executes the run on each.
32+
* A Reportable that walks a list of Reportables and executes the run on each.
3333
*/
34-
public final class IReportableListWalker implements IReportable {
34+
public final class ReportableListWalker implements Reportable {
3535
/** The document name for this walker. */
3636
private final DocumentName documentName;
3737
/** The list of reportables for this walker. */
38-
private final List<IReportable> reportables;
38+
private final List<Reportable> reportables;
3939

4040
/**
4141
* Create a builder for the list walker.
@@ -50,24 +50,24 @@ public static Builder builder(final DocumentName name) {
5050
* Construct the builder.
5151
* @param builder for the reportable.
5252
*/
53-
private IReportableListWalker(final Builder builder) {
53+
private ReportableListWalker(final Builder builder) {
5454
this.documentName = builder.documentName;
5555
this.reportables = builder.reportables;
5656
}
5757

5858
@Override
5959
public void run(final RatReport report) {
60-
for (IReportable reportable : reportables) {
60+
for (Reportable reportable : reportables) {
6161
try {
6262
reportable.run(report);
6363
} catch (RatException e) {
64-
DefaultLog.getInstance().error("Error processing " + reportable.getName(), e);
64+
DefaultLog.getInstance().error("Error processing " + reportable.name(), e);
6565
}
6666
}
6767
}
6868

6969
@Override
70-
public DocumentName getName() {
70+
public DocumentName name() {
7171
return documentName;
7272
}
7373

@@ -77,8 +77,8 @@ public DocumentName getName() {
7777
public static final class Builder {
7878
/** The document name for the walker. */
7979
private final DocumentName documentName;
80-
/** The list of IReportable objects to execute. */
81-
private List<IReportable> reportables = new ArrayList<>();
80+
/** The list of Reportable objects to execute. */
81+
private List<Reportable> reportables = new ArrayList<>();
8282

8383
/**
8484
* Constructs the builder.
@@ -94,7 +94,7 @@ private Builder(final DocumentName name) {
9494
* @param reportable the reportable to run.
9595
* @return this.
9696
*/
97-
public Builder addReportable(final IReportable reportable) {
97+
public Builder addReportable(final Reportable reportable) {
9898
this.reportables.add(reportable);
9999
return this;
100100
}
@@ -104,11 +104,11 @@ public Builder addReportable(final IReportable reportable) {
104104
* @return the reportable.
105105
* @throws RatException on error.
106106
*/
107-
public IReportable build() throws RatException {
107+
public ReportableListWalker build() throws RatException {
108108
if (reportables == null) {
109109
throw new RatException("Builder may only be used once");
110110
}
111-
IReportable result = new IReportableListWalker(this);
111+
ReportableListWalker result = new ReportableListWalker(this);
112112
this.reportables = null;
113113
return result;
114114
}

apache-rat-core/src/main/java/org/apache/rat/walker/Walker.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121

2222
import org.apache.rat.api.Document;
2323
import org.apache.rat.document.DocumentName;
24-
import org.apache.rat.report.IReportable;
24+
import org.apache.rat.report.Reportable;
2525

2626
/**
2727
* Abstract walker.
2828
*/
29-
public abstract class Walker implements IReportable {
29+
public abstract class Walker implements Reportable {
3030

31-
/** The document this walker is walking */
31+
/** The document this walker is walking. */
3232
private final Document document;
3333

3434
/**
35-
* Creates the walker
35+
* Creates the walker.
3636
* @param document The document the walker is walking.
3737
*/
3838
protected Walker(final Document document) {
@@ -48,7 +48,7 @@ protected Document getDocument() {
4848
}
4949

5050
@Override
51-
public DocumentName getName() {
51+
public DocumentName name() {
5252
return document.getName();
5353
}
5454
}

apache-rat-core/src/test/java/org/apache/rat/OptionCollectionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import org.apache.rat.commandline.ArgumentContext;
3939
import org.apache.rat.document.DocumentName;
4040
import org.apache.rat.license.LicenseSetFactory;
41-
import org.apache.rat.report.IReportable;
41+
import org.apache.rat.report.Reportable;
4242
import org.apache.rat.test.AbstractConfigurationOptionsProvider;
4343
import org.apache.rat.test.utils.OptionFormatter;
4444
import org.apache.rat.testhelpers.TestingLog;
@@ -233,9 +233,9 @@ public void getReportableTest(String fName) throws IOException {
233233
DocumentName.FSInfo fsInfo = new DocumentName.FSInfo(testPath.getFileSystem());
234234
String expected = fsInfo.normalize(base.getAbsolutePath());
235235
ReportConfiguration config = OptionCollection.parseCommands(testPath.toFile(), new String[]{fName}, o -> fail("Help called"), false);
236-
IReportable reportable = OptionCollection.getReportable(base, config);
236+
Reportable reportable = OptionCollection.getReportable(base, config);
237237
assertThat(reportable).as(() -> format("'%s' returned null", fName)).isNotNull();
238-
assertThat(reportable.getName().getName()).isEqualTo(expected);
238+
assertThat(reportable.name().getName()).isEqualTo(expected);
239239
}
240240

241241
@Test
@@ -250,7 +250,7 @@ void getReportable() throws IOException {
250250
reportConfiguration.addExcludedPatterns(List.of(dir2.getName()));
251251
assertThat(OptionCollection.getReportable(dir2, reportConfiguration)).isNull();
252252

253-
IReportable reportable = OptionCollection.getReportable(dir1, new ReportConfiguration());
253+
Reportable reportable = OptionCollection.getReportable(dir1, new ReportConfiguration());
254254
assertThat(reportable).isInstanceOf(DirectoryWalker.class);
255255

256256
File file1 = new File(dir1, "file1");

apache-rat-core/src/test/java/org/apache/rat/ReportConfigurationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import org.apache.rat.license.ILicense;
5252
import org.apache.rat.license.ILicenseFamily;
5353
import org.apache.rat.license.LicenseSetFactory.LicenseFilter;
54-
import org.apache.rat.report.IReportable;
54+
import org.apache.rat.report.Reportable;
5555
import org.apache.rat.testhelpers.TestingLog;
5656
import org.apache.rat.testhelpers.TestingLicense;
5757
import org.apache.rat.testhelpers.TestingMatcher;
@@ -468,10 +468,10 @@ public void outputTest() throws IOException {
468468
@Test
469469
public void reportableTest() {
470470
assertThat(underTest.hasSource()).isFalse();
471-
IReportable reportable = mock(IReportable.class);
471+
Reportable reportable = mock(Reportable.class);
472472
underTest.addSource(reportable);
473473
assertThat(underTest.hasSource()).isTrue();
474-
assertThatThrownBy(() -> underTest.addSource((IReportable)null)).isExactlyInstanceOf(ConfigurationException.class)
474+
assertThatThrownBy(() -> underTest.addSource((Reportable)null)).isExactlyInstanceOf(ConfigurationException.class)
475475
.hasMessageContaining("Reportable may not be null.");
476476
}
477477

@@ -524,7 +524,7 @@ public void testValidate() {
524524

525525
sb.setLength(0);
526526
msg = "You must specify at least one license";
527-
underTest.addSource(mock(IReportable.class));
527+
underTest.addSource(mock(Reportable.class));
528528

529529
assertThatThrownBy(() -> underTest.validate(sb::append)).isExactlyInstanceOf(ConfigurationException.class)
530530
.hasMessageContaining(msg);

0 commit comments

Comments
 (0)