Skip to content

Commit

Permalink
Remove package detectors and use the new ones from codingstyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 8, 2025
1 parent 7c3afb7 commit 2023196
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 498 deletions.
9 changes: 8 additions & 1 deletion 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>5.8.0</version>
<version>5.9.0</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -292,6 +292,13 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine} -Dorg.apache.logging.log4j.level=OFF</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down
99 changes: 0 additions & 99 deletions src/main/java/edu/hm/hafner/analysis/AbstractPackageDetector.java

This file was deleted.

34 changes: 0 additions & 34 deletions src/main/java/edu/hm/hafner/analysis/CSharpNamespaceDetector.java

This file was deleted.

35 changes: 0 additions & 35 deletions src/main/java/edu/hm/hafner/analysis/JavaPackageDetector.java

This file was deleted.

35 changes: 0 additions & 35 deletions src/main/java/edu/hm/hafner/analysis/KotlinPackageDetector.java

This file was deleted.

60 changes: 0 additions & 60 deletions src/main/java/edu/hm/hafner/analysis/PackageDetectors.java

This file was deleted.

35 changes: 17 additions & 18 deletions src/main/java/edu/hm/hafner/analysis/PackageNameResolver.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
package edu.hm.hafner.analysis;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import edu.hm.hafner.util.PackageDetectorFactory;
import edu.hm.hafner.util.PackageDetectorRunner;
import edu.hm.hafner.util.VisibleForTesting;

import static edu.hm.hafner.analysis.PackageDetectors.*;
import static java.util.function.Function.*;

/**
* Resolves packages or namespace names for a set of issues.
*
* @author Ullrich Hafner
*/
public class PackageNameResolver {
private final PackageDetectors packageDetectors;
private final PackageDetectorRunner runner;

/**
* Creates a new {@link PackageNameResolver}.
*/
public PackageNameResolver() {
this(new FileSystem());
this(PackageDetectorFactory.createPackageDetectors());
}

@VisibleForTesting
PackageNameResolver(final FileSystem fileSystem) {
List<AbstractPackageDetector> detectors = new ArrayList<>(Arrays.asList(
new JavaPackageDetector(fileSystem),
new CSharpNamespaceDetector(fileSystem),
new KotlinPackageDetector(fileSystem)
));
packageDetectors = new PackageDetectors(detectors);
PackageNameResolver(final PackageDetectorRunner runner) {
this.runner = runner;
}

/**
Expand All @@ -58,9 +51,11 @@ public void run(final Report report, final Charset charset) {
return;
}

Map<String, String> packagesOfFiles = filesWithoutPackageName.stream()
.collect(Collectors.toMap(identity(),
fileName -> packageDetectors.detectPackageName(fileName, charset)));
Map<String, String> packagesOfFiles = new HashMap<>();
filesWithoutPackageName.stream()
.map(f -> extractPackageName(f, charset))
.flatMap(Optional::stream)
.forEach(e -> packagesOfFiles.put(e.getKey(), e.getValue()));

try (var builder = new IssueBuilder()) {
report.stream().forEach(issue -> {
Expand All @@ -71,4 +66,8 @@ public void run(final Report report, final Charset charset) {
}
report.logInfo("-> resolved package names of %d affected files", filesWithoutPackageName.size());
}

private Optional<Map.Entry<String, String>> extractPackageName(final String fileName, final Charset charset) {
return runner.detectPackageName(fileName, charset).map(r -> Map.entry(fileName, r));
}
}
Loading

0 comments on commit 2023196

Please sign in to comment.