Skip to content

Commit

Permalink
objectionary#2937 fix qulice warnings in eo-maven-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed Mar 25, 2024
1 parent c38c0ca commit 5e624cb
Show file tree
Hide file tree
Showing 24 changed files with 148 additions and 119 deletions.
5 changes: 5 additions & 0 deletions eo-maven-plugin/pom.xml
Expand Up @@ -212,6 +212,11 @@ SOFTWARE.
<!-- This dependency must precede jcabi-maven-slf4j in order
to enable configurable Log4j logging during testing -->
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>ch.qos.reload4j</groupId>
<artifactId>reload4j</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/Moja.java
Expand Up @@ -85,6 +85,7 @@ public Moja<T> with(final String attr, final Object value) {
* @param mojo Another mojo
* @return Itself
*/
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
public Moja<T> copy(final Object mojo) {
final Collection<String> mine = new ListOf<>(
new Mapped<>(
Expand Down Expand Up @@ -157,6 +158,7 @@ private static Collection<Field> fields(final Class<?> cls) {
* can't be set to the Mojo, we can't just remove Logger.warn. On the other hand, we will
* see warnings all the time during unit testing, which can be an insignificant problem.
*/
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
private void initField(
final Class<?> clazz,
final AbstractMojo mojo,
Expand Down
Expand Up @@ -59,7 +59,7 @@ public enum OptimizationFolder {
*
* @return The attribute name.
*/
String key() {
String getKey() {
return this.key;
}
}
Expand Up @@ -123,9 +123,9 @@ public Scalar<Integer> value(
private Path make(final XML xml, final Path file) throws IOException {
final String name = new XMLDocument(file).xpath("/program/@name").get(0);
final Place place = new Place(name);
final Path dir = this.paths.get(OptimizationFolder.TARGET.key());
final Path dir = this.paths.get(OptimizationFolder.TARGET.getKey());
final Path target = place.make(
dir.resolve(this.dirs.get(OptimizationFolder.TARGET.key())), TranspileMojo.EXT
dir.resolve(this.dirs.get(OptimizationFolder.TARGET.getKey())), TranspileMojo.EXT
);
new HmBase(dir).save(
xml.toString(),
Expand Down Expand Up @@ -153,8 +153,8 @@ private Optimization optimization(final ForeignTojo tojo, final Optimization com
res = new OptCached(
common,
this.paths.get(
OptimizationFolder.CACHE.key()
).resolve(this.dirs.get(OptimizationFolder.CACHE.key())).resolve(tojo.hash()),
OptimizationFolder.CACHE.getKey()
).resolve(this.dirs.get(OptimizationFolder.CACHE.getKey())).resolve(tojo.hash()),
this.source.apply(tojo)
);
} else {
Expand Down
Expand Up @@ -70,9 +70,10 @@ public final class OptimizeMojo extends SafeMojo {
* The map with directories of OptimizeMojo.
* @checkstyle DiamondOperatorCheck (10 lines)
*/
@SuppressWarnings("PMD.UseDiamondOperator")
private static final Map<String, String> DIRECTORIES = new MapOf<String, String>(
new MapEntry<>(OptimizationFolder.TARGET.key(), OptimizeMojo.DIR),
new MapEntry<>(OptimizationFolder.CACHE.key(), OptimizeMojo.OPTIMIZED)
new MapEntry<>(OptimizationFolder.TARGET.getKey(), OptimizeMojo.DIR),
new MapEntry<>(OptimizationFolder.CACHE.getKey(), OptimizeMojo.OPTIMIZED)
);

/**
Expand All @@ -96,8 +97,8 @@ public void exec() {
this.optimization(),
new OptimizationTask(
new MapOf<String, Path>(
new MapEntry<>(OptimizationFolder.TARGET.key(), this.targetDir.toPath()),
new MapEntry<>(OptimizationFolder.CACHE.key(), this.cache)
new MapEntry<>(OptimizationFolder.TARGET.getKey(), this.targetDir.toPath()),
new MapEntry<>(OptimizationFolder.CACHE.getKey(), this.cache)
),
OptimizeMojo.DIRECTORIES,
ForeignTojo::withOptimized,
Expand Down
Expand Up @@ -98,6 +98,7 @@ public final class ProbeMojo extends SafeMojo {
);

@Override
@SuppressWarnings("PMD.CognitiveComplexity")
public void exec() throws IOException {
if (this.hash == null) {
this.hash = new ChCached(
Expand Down
50 changes: 26 additions & 24 deletions eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java
Expand Up @@ -259,6 +259,7 @@ abstract class SafeMojo extends AbstractMojo {
* @checkstyle CyclomaticComplexityCheck (70 lines)
*/
@Override
@SuppressWarnings("PMD.CognitiveComplexity")
public final void execute() throws MojoFailureException {
StaticLoggerBinder.getSingleton().setMavenLog(this.getLog());
if (this.skip) {
Expand Down Expand Up @@ -383,35 +384,36 @@ private static void closeTojos(final Closeable res) throws MojoFailureException
*/
private void exitError(final String msg, final Throwable exp)
throws MojoFailureException {
if (!this.unrollExitError) {
return;
}
final MojoFailureException out = new MojoFailureException(msg, exp);
if (this.unrollExitError) {
final List<String> causes = SafeMojo.causes(exp);
for (int pos = 0; pos < causes.size(); ++pos) {
final String cause = causes.get(pos);
if (cause == null) {
causes.remove(pos);
break;
}
final List<String> causes = SafeMojo.causes(exp);
for (int pos = 0; pos < causes.size(); ++pos) {
final String cause = causes.get(pos);
if (cause == null) {
causes.remove(pos);
break;
}
}
int idx = 0;
while (true) {
if (idx >= causes.size()) {
break;
}
int idx = 0;
while (true) {
if (idx >= causes.size()) {
final String cause = causes.get(idx);
for (int later = idx + 1; later < causes.size(); ++later) {
final String another = causes.get(later);
if (another != null && cause.contains(another)) {
causes.remove(idx);
idx -= 1;
break;
}
final String cause = causes.get(idx);
for (int later = idx + 1; later < causes.size(); ++later) {
final String another = causes.get(later);
if (another != null && cause.contains(another)) {
causes.remove(idx);
idx -= 1;
break;
}
}
idx += 1;
}
for (final String cause : new LinkedHashSet<>(causes)) {
Logger.error(this, cause);
}
idx += 1;
}
for (final String cause : new LinkedHashSet<>(causes)) {
Logger.error(this, cause);
}
throw out;
}
Expand Down
9 changes: 5 additions & 4 deletions eo-maven-plugin/src/main/java/org/eolang/maven/ShakeMojo.java
Expand Up @@ -67,9 +67,10 @@ public final class ShakeMojo extends SafeMojo {
* The map with directories of ShakeMojo.
* @checkstyle DiamondOperatorCheck (10 lines)
*/
@SuppressWarnings("PMD.UseDiamondOperator")
private static final Map<String, String> DIRECTORIES = new MapOf<String, String>(
new MapEntry<>(OptimizationFolder.TARGET.key(), ShakeMojo.DIR),
new MapEntry<>(OptimizationFolder.CACHE.key(), ShakeMojo.SHAKEN)
new MapEntry<>(OptimizationFolder.TARGET.getKey(), ShakeMojo.DIR),
new MapEntry<>(OptimizationFolder.CACHE.getKey(), ShakeMojo.SHAKEN)
);

/**
Expand All @@ -93,8 +94,8 @@ void exec() {
this.optimization(),
new OptimizationTask(
new MapOf<String, Path>(
new MapEntry<>(OptimizationFolder.TARGET.key(), this.targetDir.toPath()),
new MapEntry<>(OptimizationFolder.CACHE.key(), this.cache)
new MapEntry<>(OptimizationFolder.TARGET.getKey(), this.targetDir.toPath()),
new MapEntry<>(OptimizationFolder.CACHE.getKey(), this.cache)
),
ShakeMojo.DIRECTORIES,
ForeignTojo::withShaken,
Expand Down
Expand Up @@ -161,7 +161,7 @@ private static class Metas extends IterableEnvelope<Directive> {
meta -> {
final String[] pair = meta.split(" ", 2);
final String head = pair[0].substring(1);
if (head.equals(UnphiMojo.Metas.PACKAGE)) {
if (UnphiMojo.Metas.PACKAGE.equals(head)) {
throw new IllegalStateException(
"+package meta is prohibited for attaching to unphied XMIR"
);
Expand Down
Expand Up @@ -75,6 +75,7 @@ public final class UnplaceMojo extends SafeMojo {
private Set<String> keepBinaries = new SetOf<>();

@Override
@SuppressWarnings("PMD.AvoidAccessToStaticMembersViaThis")
public void exec() throws IOException {
if (this.placedTojos.isEmpty()) {
Logger.info(
Expand Down Expand Up @@ -105,6 +106,7 @@ private void unplaceJars() {
* Place what's necessary.
* @throws IOException If fails
*/
@SuppressWarnings("PMD.AvoidAccessToStaticMembersViaThis")
private void unplaceClasses() throws IOException {
final Collection<PlacedTojo> classes = this.placedTojos.classes();
int deleted = 0;
Expand Down Expand Up @@ -141,6 +143,7 @@ private void unplaceClasses() throws IOException {
* @return Number of files deleted
* @throws IOException If fails
*/
@SuppressWarnings("PMD.CognitiveComplexity")
private int killThem(final Iterable<PlacedTojo> all) throws IOException {
int unplaced = 0;
for (final PlacedTojo tojo : all) {
Expand Down Expand Up @@ -195,6 +198,7 @@ private int killThem(final Iterable<PlacedTojo> all) throws IOException {
* @return Number of files deleted
* @throws IOException If fails
*/
@SuppressWarnings("PMD.AvoidAccessToStaticMembersViaThis")
private int keepThem(final Iterable<? extends PlacedTojo> tojos) throws IOException {
int deleted = 0;
int remained = 0;
Expand Down
Expand Up @@ -75,12 +75,12 @@ void exec() {
this.optimization(),
new OptimizationTask(
new MapOf<String, Path>(
new MapEntry<>(OptimizationFolder.TARGET.key(), this.targetDir.toPath()),
new MapEntry<>(OptimizationFolder.CACHE.key(), this.cache)
new MapEntry<>(OptimizationFolder.TARGET.getKey(), this.targetDir.toPath()),
new MapEntry<>(OptimizationFolder.CACHE.getKey(), this.cache)
),
new MapOf<String, String>(
new MapEntry<>(OptimizationFolder.TARGET.key(), "6-verify"),
new MapEntry<>(OptimizationFolder.CACHE.key(), "verified")
new MapEntry<>(OptimizationFolder.TARGET.getKey(), "6-verify"),
new MapEntry<>(OptimizationFolder.CACHE.getKey(), "verified")
),
ForeignTojo::withVerified,
ForeignTojo::shaken
Expand Down
Expand Up @@ -162,7 +162,7 @@ private int weight(final String tag) {
*/
private int numberOfConstants() {
return (int) Stream.of(this.template.split("\\."))
.filter(s -> !s.equals("*")).count();
.filter(s -> !"*".equals(s)).count();
}

/**
Expand All @@ -173,7 +173,7 @@ private int numberOfConstants() {
private String regex() {
final List<String> keys = new LinkedList<>();
for (final String key : this.template.split("\\.")) {
if (key.equals("*")) {
if ("*".equals(key)) {
keys.add("\\w+");
} else {
keys.add(key);
Expand Down

0 comments on commit 5e624cb

Please sign in to comment.