Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAT-369: Add checkstyle and spotbugs to build and generate a report #238

Merged
merged 23 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b404d02
RAT-369: Add spotbugs to build and generate a report
ottlinger Apr 16, 2024
b23aac3
RAT-369: Fail the build if there are any bugs
ottlinger Apr 16, 2024
7fee5e2
RAT-369: Fix reliance on default encoding in some JDK8-compliant sett…
ottlinger Apr 21, 2024
191b119
RAT-369: Issue errors but do not fail the build in order to work incr…
ottlinger Apr 21, 2024
a916951
RAT-369: Ignore false positive
ottlinger Apr 21, 2024
d929953
RAT-369: Fix spotbugs warning
ottlinger Apr 21, 2024
39cb8b1
RAT-369: Tweak config and add exclusion files in submodules
ottlinger Apr 21, 2024
706732f
RAT-369: Add tweak info about subpackage syntax
ottlinger Apr 21, 2024
ab5a127
RAT-369: Fix whitespaces
ottlinger Apr 25, 2024
bea9d2c
Merge remote-tracking branch 'origin/master' into feature/RAT-369
ottlinger Apr 26, 2024
64b1c21
RAT-369: Add exclusion file to fix the build in new tools submodule
ottlinger Apr 26, 2024
10f925a
RAT-369: Add exclusion for charsets that cannot be set with Java8
ottlinger Apr 26, 2024
99cc9a0
RAT-369: Add exclusions and fix TYPO in enum
ottlinger Apr 26, 2024
a0e9fa0
RAT-369: Fix rename in module as well
ottlinger Apr 26, 2024
d25876f
Merge remote-tracking branch 'origin/master' into feature/RAT-369
ottlinger Apr 28, 2024
eaa2071
RAT-369: Remove examples from exclusion files in submodules
ottlinger May 1, 2024
2136362
RAT-369: Revert star-import
ottlinger May 4, 2024
85cb1a0
RAT-369: Fix import
ottlinger May 4, 2024
0a62cb2
RAT-369: Add checkstyle to build and maven site
ottlinger May 4, 2024
7081bdd
RAT-369: Add changelog
ottlinger May 4, 2024
959db49
INFRA-25758: try to cleanUp the workspace via another method
ottlinger May 1, 2024
b7524f3
Fix changelog
ottlinger May 4, 2024
c807a4d
RAT-369: Improve docs about why we do not fail the build and have emp…
ottlinger May 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
ottlinger marked this conversation as resolved.
Show resolved Hide resolved
}
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;
}
ottlinger marked this conversation as resolved.
Show resolved Hide resolved
}

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