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

Cleanup dependencies #1088

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
97 changes: 16 additions & 81 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>edu.hm.hafner</groupId>
<artifactId>codingstyle-pom</artifactId>
<version>4.13.0</version>
<version>4.14.0</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -53,7 +53,7 @@

<properties>
<scmTag>HEAD</scmTag>
<revision>12.5.0</revision>
<revision>12.4.2</revision>
<changelist>-SNAPSHOT</changelist>

<module.name>edu.hm.hafner.analysis.model</module.name>
Expand All @@ -78,6 +78,16 @@

</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>12.5</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Project Dependencies -->
<dependency>
Expand Down Expand Up @@ -136,12 +146,6 @@
<artifactId>xercesImpl</artifactId>
<version>2.12.2</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.7</version>
</dependency>

<!-- FindBugs Parser Dependencies -->
<dependency>
<groupId>com.github.spotbugs</groupId>
Expand Down Expand Up @@ -173,23 +177,8 @@
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<artifactId>bcel</artifactId>
<groupId>org.apache.bcel</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.bcel</groupId>
<artifactId>bcel</artifactId>
<version>6.10.0</version>
<exclusions>
<exclusion>
<artifactId>commons-lang3</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>error_prone_annotations</artifactId>
<groupId>com.google.errorprone</groupId>
</exclusion>
</exclusions>
</dependency>
Expand Down Expand Up @@ -225,16 +214,11 @@
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>jcommander</artifactId>
<groupId>com.beust</groupId>
<artifactId>jul-to-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.82</version>
</dependency>

<dependency>
<groupId>net.sourceforge.pmd</groupId>
Expand Down Expand Up @@ -405,57 +389,8 @@
<configuration>
<skip>true</skip>
<failBuildOnProblemsFound>false</failBuildOnProblemsFound>
<analysisConfiguration>
<revapi.differences id="manually-vetted">
<differences combine.children="append">
<item>
<ignore>true</ignore>
<regex>true</regex>
<classQualifiedName>shaded.*</classQualifiedName>
<code>.*</code>
</item>
<item>
<ignore>true</ignore>
<package>javax.xml.transform</package>
<code>java.class.externalClassExposedInAPI</code>
</item>
</differences>
<filter.classes>
<item>
<exclude>edu.hm.hafner.analysis.parser.checkstyle.TopicRule</exclude>
</item>
</filter.classes>
</revapi.differences>
</analysisConfiguration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>org.ow2.asm:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.objectweb.asm</pattern>
<shadedPattern>shaded.org.objectweb.asm</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void collectProjects(final Map<String, String> mapping, final List<String> proje
*/
private String parseBuildXml(final String buildXml) {
try (InputStream file = getFactory().open(buildXml)) {
SecureDigester digester = new SecureDigester(ModuleDetector.class);
var digester = new SecureDigester(ModuleDetector.class);

digester.push(new StringBuilder());
String xPath = "project";
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/edu/hm/hafner/analysis/DuplicationGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.util.Generated;
import edu.umd.cs.findbugs.annotations.CheckForNull;

/**
Expand Down Expand Up @@ -53,7 +55,7 @@ public void setCodeFragment(@CheckForNull final String codeFragment) {
* Adds the specified duplication (represented by an {@link Issue} instance) to this group of duplications.
*
* @param issue
* the issues that references the position of the duplicated code fragment
* the issues that reference the position of the duplicated code fragment
*/
public void add(final Issue issue) {
occurrences.add(issue);
Expand All @@ -73,21 +75,21 @@ public List<Issue> getDuplications() {
}

@Override
public boolean equals(@CheckForNull final Object o) {
@Generated
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

DuplicationGroup that = (DuplicationGroup) o;

return codeFragment.equals(that.codeFragment);
var that = (DuplicationGroup) o;
return Objects.equals(codeFragment, that.codeFragment);
}

@Override
@Generated
public int hashCode() {
return codeFragment.hashCode();
return Objects.hashCode(codeFragment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class FileReaderFactory extends ReaderFactory {
* @param charset
* the charset to use when reading the file (or {@code null} if the charset should be detected)
*/
public FileReaderFactory(final Path file, final @CheckForNull Charset charset) {
public FileReaderFactory(final Path file, @CheckForNull final Charset charset) {
super(StandardCharsets.UTF_8);

this.file = file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.nio.charset.MalformedInputException;
import java.nio.file.InvalidPathException;
import java.nio.file.NoSuchFileException;
import java.util.Locale;
import java.util.Set;

import org.apache.commons.io.FilenameUtils;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class FingerprintGenerator {
* the character set to use when reading the source files
*/
public void run(final FullTextFingerprint algorithm, final Report report, final Charset charset) {
FilteredLog log = new FilteredLog("Can't create fingerprints for some files:");
var log = new FilteredLog("Can't create fingerprints for some files:");
int sum = 0;
for (Issue issue : report) {
if (!issue.hasFingerprint()) {
Expand Down Expand Up @@ -88,8 +89,8 @@ private int computeFingerprint(final Issue issue, final FullTextFingerprint algo

@VisibleForTesting
static String createDefaultFingerprint(final Issue issue) {
HashCodeBuilder builder = new HashCodeBuilder();
return String.format("FALLBACK-%x",
var builder = new HashCodeBuilder();
return String.format(Locale.ENGLISH, "FALLBACK-%x",
builder.append(issue.getBaseName())
.append(issue.getType())
.append(issue.getCategory())
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/analysis/FullTextFingerprint.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public String compute(final String fileName, final int line, final Charset chars

@VisibleForTesting
String getFallbackFingerprint(final String fileName) {
return String.format("%x", fileName.hashCode());
return String.format(Locale.ENGLISH, "%x", fileName.hashCode());
}

@VisibleForTesting
Expand Down Expand Up @@ -108,7 +108,7 @@ String extractContext(final int affectedLine, final Iterator<String> lines) {

int start = computeStartLine(affectedLine);

StringBuilder context = new StringBuilder(LINE_RANGE_BUFFER_SIZE);
var context = new StringBuilder(LINE_RANGE_BUFFER_SIZE);
int line = 1;
for (; lines.hasNext() && line < start - LINES_LOOK_AHEAD; line++) {
lines.next(); // skip the first lines
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/edu/hm/hafner/analysis/Issue.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Predicate;
Expand Down Expand Up @@ -975,6 +976,8 @@ public int hashCode() {

@Override
public String toString() {
return String.format("%s%s(%d,%d): %s: %s: %s", isPartOfModifiedCode() ? "*" : StringUtils.EMPTY, getBaseName(), lineStart, columnStart, type, category, message);
return String.format(Locale.ENGLISH, "%s%s(%d,%d): %s: %s: %s",
isPartOfModifiedCode() ? "*" : StringUtils.EMPTY, getBaseName(),
lineStart, columnStart, type, category, message);
}
}
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/analysis/LookaheadParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected LookaheadParser(final String pattern) {

@Override
public Report parse(final ReaderFactory readerFactory) throws ParsingException, ParsingCanceledException {
Report report = new Report();
var report = new Report();
try (Stream<String> lines = readerFactory.readStream()) {
try (LookaheadStream lookahead = new LookaheadStream(lines, readerFactory.getFileName())) {
parse(report, lookahead);
Expand Down Expand Up @@ -148,7 +148,7 @@ else if (line.contains(LEAVING_DIRECTORY)) {
builder.setDirectory(leaveDirectory());
}
else if (line.contains(CMAKE_PREFIX)) {
extractDirectory(line, CMAKE_PATH, log).map(builder::setDirectory);
extractDirectory(line, CMAKE_PATH, log).ifPresent(builder::setDirectory);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private String parsePom(final String pom) {
@SuppressWarnings("OverlyBroadCatchBlock")
private String parsePomAttribute(final String pom, final String tagName) {
try (InputStream file = getFactory().open(pom)) {
SecureDigester digester = new SecureDigester(ModuleDetector.class);
var digester = new SecureDigester(ModuleDetector.class);
digester.push(new StringBuilder());
digester.addCallMethod("project/" + tagName, "append", 0);

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/edu/hm/hafner/analysis/OsgiModuleDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public void collectProjects(final Map<String, String> mapping, final List<String
*/
private String parseManifest(final String manifestFile) {
try (InputStream file = getFactory().open(manifestFile)) {
Manifest manifest = new Manifest(file);
Attributes attributes = manifest.getMainAttributes();
Properties properties = readProperties(StringUtils.substringBefore(manifestFile, OSGI_BUNDLE));
var manifest = new Manifest(file);
var attributes = manifest.getMainAttributes();
var properties = readProperties(StringUtils.substringBefore(manifestFile, OSGI_BUNDLE));
String name = getLocalizedValue(attributes, properties, BUNDLE_NAME);
if (StringUtils.isNotBlank(name)) {
return name;
Expand All @@ -69,7 +69,7 @@ private String parseManifest(final String manifestFile) {
}

private Properties readProperties(final String path) {
Properties properties = new Properties();
var properties = new Properties();
readProperties(path, properties, PLUGIN_PROPERTIES);
readProperties(path, properties, BUNDLE_PROPERTIES);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/analysis/ReaderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public ReaderFactory(final Charset charset, final Function<String, String> lineM
@SuppressFBWarnings("OS_OPEN_STREAM")
public Stream<String> readStream() {
try {
BufferedReader reader = new BufferedReader(create());
var reader = new BufferedReader(create());
Stream<String> stringStream = reader.lines().onClose(closeReader(reader));
if (hasLineMapper()) {
return stringStream.map(lineMapper);
Expand Down Expand Up @@ -142,7 +142,7 @@ public String readString() {
*/
public Document readDocument() {
try (Reader reader = create()) {
SecureXmlParserFactory parserFactory = new SecureXmlParserFactory();
var parserFactory = new SecureXmlParserFactory();
return parserFactory.readDocument(reader, getCharset());
}
catch (IOException | SecureXmlParserFactory.ParsingException exception) {
Expand Down
Loading
Loading