Skip to content

Commit

Permalink
Merge pull request #238 from apache/feature/RAT-369
Browse files Browse the repository at this point in the history
RAT-369: Add checkstyle and spotbugs to build and generate a report
  • Loading branch information
ottlinger committed May 6, 2024
2 parents 8fcb1cf + c807a4d commit 5c091cd
Show file tree
Hide file tree
Showing 26 changed files with 270 additions and 39 deletions.
44 changes: 44 additions & 0 deletions apache-rat-core/spotbugs_ignore.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<FindBugsFilter>
<Match>
<!--
Convenience constructors that allow setting a charset are not available in Java8 for PrintStream.
-->
<Class name="org.apache.rat.Report"/>
<Bug pattern="DM_DEFAULT_ENCODING"/>
</Match>
<Match>
<!--
Convenience constructors that allow setting a charset are not available in Java8 for FileWriter.
-->
<Class name="org.apache.rat.annotation.AbstractLicenseAppender"/>
<Bug pattern="DM_DEFAULT_ENCODING"/>
</Match>
<Match>
<!--
Convenience constructors that allow setting a charset are not available in Java8 for FileReader.
-->
<Class name="org.apache.rat.document.impl.FileDocument"/>
<Bug pattern="DM_DEFAULT_ENCODING"/>
</Match>
<Match>
<Class name="org.apache.rat.document.impl.MonolithicFileDocument"/>
<Bug pattern="DM_DEFAULT_ENCODING"/>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.rat;

/**
* An exception thrown when there is an issue with the Configuration.
* An exception thrown when there is an issue with the configuration.
*/
public class ImplementationException extends RuntimeException {

Expand Down
5 changes: 2 additions & 3 deletions apache-rat-core/src/main/java/org/apache/rat/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static ReportConfiguration createConfiguration(String baseDirectory, CommandLine
if (url == null) {
ioSupplier = () -> Files.newInputStream(Paths.get(style[0]));
} else {
ioSupplier = () -> url.openStream();
ioSupplier = url::openStream;
}
configuration.setStyleSheet(ioSupplier);
}
Expand Down Expand Up @@ -332,8 +332,7 @@ static FilenameFilter parseExclusions(List<String> excludes) {
}

static Options buildOptions() {
String licFilterValues = String.join(", ",
Arrays.stream(LicenseFilter.values()).map(LicenseFilter::name).collect(Collectors.toList()));
String licFilterValues = Arrays.stream(LicenseFilter.values()).map(LicenseFilter::name).collect(Collectors.joining(", "));

Options opts = new Options()
.addOption(Option.builder().longOpt(DRY_RUN)
Expand Down
3 changes: 2 additions & 1 deletion apache-rat-core/src/main/java/org/apache/rat/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
Expand Down Expand Up @@ -76,7 +77,7 @@ public Reporter(ReportConfiguration configuration) throws RatException {
try {
if (configuration.getReportable() != null) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Writer outputWriter = new OutputStreamWriter(outputStream);
Writer outputWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
try (IXmlWriter writer = new XmlWriter(outputWriter)) {
statistic = new ClaimStatistic();
RatReport report = XmlReportFactory.createStandardReport(writer, statistic, configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
Expand Down Expand Up @@ -287,7 +288,7 @@ private boolean attachLicense(Writer writer, File document,
BufferedReader br = null;
try {
fis = new FileInputStream(document);
br = new BufferedReader(new InputStreamReader(new BOMInputStream(fis)));
br = new BufferedReader(new InputStreamReader(new BOMInputStream(fis), StandardCharsets.UTF_8));

if (!expectsHashPling
&& !expectsAtEcho
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.rat.api;

import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -72,6 +73,6 @@ public String getSubType() {
* @return not null
*/
public Map<String, String> getParameters() {
return parameters;
return Collections.unmodifiableMap(parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public enum ComponentType {
MATCHER,
/** A Parameter for example the "id" parameter found in every component */
PARAMETER,
/** A parameter that is supplied by the environment. Currently systems using builders have to handle seting this. For example the list of matchers for the "MatcherRefBuilder" */
BULID_PARAMETER
/** A parameter that is supplied by the environment. Currently systems using builders have to handle setting this. For example the list of matchers for the "MatcherRefBuilder" */
BUILD_PARAMETER
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Description(ComponentType type, String name, String desc, boolean isColle
this.desc = desc;
this.isCollection = isCollection;
this.required = required;
if (type == ComponentType.BULID_PARAMETER) {
if (type == ComponentType.BUILD_PARAMETER) {
Method m;
try {
m = BuilderParams.class.getMethod(name);
Expand Down Expand Up @@ -275,7 +275,7 @@ public Method setter(Class<?> clazz) throws NoSuchMethodException, SecurityExcep
case PARAMETER:
return clazz.getMethod(methodName,
IHeaderMatcher.class.isAssignableFrom(childClass) ? IHeaderMatcher.Builder.class : childClass);
case BULID_PARAMETER:
case BUILD_PARAMETER:
return clazz.getMethod(methodName, childClass);
}
// should not happen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ private void callSetter(Description desc, IHeaderMatcher.Builder builder, Object
}

private void processBuilderParams(Description description, IHeaderMatcher.Builder builder) {
for (Description desc : description.childrenOfType(ComponentType.BULID_PARAMETER)) {
for (Description desc : description.childrenOfType(ComponentType.BUILD_PARAMETER)) {
Method m = builderParams.get(desc.getCommonName());
try {
callSetter(desc, builder, m.invoke(builderParams));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
ImplementationException.makeInstance(e);
throw ImplementationException.makeInstance(e);
}
}
}
Expand Down Expand Up @@ -270,7 +270,7 @@ private BiPredicate<Node, Description> matcherChildNodeProcessor(AbstractBuilder
return (child, childDescription) -> {
switch (childDescription.getType()) {
case LICENSE:
case BULID_PARAMETER:
case BUILD_PARAMETER:
throw new ConfigurationException(String.format(
"%s may not be used as an enclosed matcher. %s '%s' found in '%s'", childDescription.getType(),
childDescription.getType(), childDescription.getCommonName(), description.getCommonName()));
Expand Down Expand Up @@ -411,7 +411,7 @@ private BiPredicate<Node, Description> licenseChildNodeProcessor(ILicense.Builde
throw new ConfigurationException(String.format(
"%s may not be enclosed in another license. %s '%s' found in '%s'", childDescription.getType(),
childDescription.getType(), childDescription.getCommonName(), description.getCommonName()));
case BULID_PARAMETER:
case BUILD_PARAMETER:
break;
case MATCHER:
AbstractBuilder b = parseMatcher(child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void writeDescription(IXmlWriter writer, Description description, IHeaderMatcher
}
}
break;
case BULID_PARAMETER:
case BUILD_PARAMETER:
// ignore;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static class IHeaderMatcherProxy implements IHeaderMatcher {
private final String proxyId;
private IHeaderMatcher wrapped;

@ConfigComponent(type = ComponentType.BULID_PARAMETER, name = "matcherMap", desc = "Map of matcher names to matcher instances")
@ConfigComponent(type = ComponentType.BUILD_PARAMETER, name = "matcherMap", desc = "Map of matcher names to matcher instances")
private Map<String, IHeaderMatcher> matchers;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;

import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData;
Expand Down Expand Up @@ -60,7 +61,7 @@ public boolean isComposite() {
}

public Reader reader() throws IOException {
return new InputStreamReader(new ByteArrayInputStream(contents));
return new InputStreamReader(new ByteArrayInputStream(contents), StandardCharsets.UTF_8);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData;
Expand Down Expand Up @@ -61,7 +63,7 @@ public MetaData getMetaData() {
}

public InputStream inputStream() throws IOException {
return new FileInputStream(file);
return Files.newInputStream(file.toPath());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.Reader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import org.apache.rat.api.Document;

Expand Down Expand Up @@ -67,6 +68,6 @@ public Reader reader() throws IOException {
}

public InputStream inputStream() throws IOException {
return new FileInputStream(file);
return Files.newInputStream(file.toPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@ConfigComponent(type = ComponentType.LICENSE)
public class SimpleLicense implements ILicense {

@ConfigComponent(type = ComponentType.BULID_PARAMETER, desc = "The defined license families.", name = "licenseFamilies")
@ConfigComponent(type = ComponentType.BUILD_PARAMETER, desc = "The defined license families.", name = "licenseFamilies")
private ILicenseFamily family;

@ConfigComponent(type = ComponentType.PARAMETER, desc = "The matcher for this license.", required = true)
Expand Down
26 changes: 26 additions & 0 deletions apache-rat-plugin/spotbugs_ignore.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<FindBugsFilter>
<Match>
<!--
Convenience constructors that allow setting a charset are not available in Java8 for FileReader.
-->
<Class name="org.apache.rat.mp.util.ignore.GlobIgnoreMatcher"/>
<Bug pattern="DM_DEFAULT_ENCODING"/>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -115,7 +116,7 @@ public static boolean isComment(final String line) {
}

public List<String> getExclusionLines() {
return exclusionLines;
return Collections.unmodifiableList(exclusionLines);
}

@Override
Expand Down
26 changes: 26 additions & 0 deletions apache-rat-tasks/spotbugs_ignore.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<FindBugsFilter>
<Match>
<!--
Convenience constructors that allow setting a charset are not available in Java8 for PrintStream.
-->
<Class name="org.apache.rat.anttasks.Report"/>
<Bug pattern="DM_DEFAULT_ENCODING"/>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
*/
package org.apache.rat.anttasks;

import java.io.File;
import java.io.FilenameFilter;
import java.io.PrintWriter;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -319,10 +318,9 @@ public void log(Level level, String msg) {
case ERROR:
write(Project.MSG_ERR, msg);
break;
case OFF:
break;
default:
break;
case OFF:
default:
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;

import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData;
Expand Down Expand Up @@ -69,7 +70,7 @@ private ResourceDocument(Resource resource) {
@Override
public Reader reader() throws IOException {
final InputStream in = resource.getInputStream();
return new InputStreamReader(in);
return new InputStreamReader(in, StandardCharsets.UTF_8);
}

@Override
Expand Down
Loading

0 comments on commit 5c091cd

Please sign in to comment.