Skip to content

Commit

Permalink
feat: Update enforcer-api to 3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Feb 25, 2023
1 parent 17eccca commit 1520eab
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 65 deletions.
27 changes: 18 additions & 9 deletions pomchecker-enforcer-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -49,21 +50,17 @@
<dependency>
<groupId>org.apache.maven.enforcer</groupId>
<artifactId>enforcer-api</artifactId>
<version>3.1.0</version>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.kordamp.maven</groupId>
<artifactId>pomchecker-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -86,6 +83,18 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
<version>0.9.0.M1</version>
<executions>
<execution>
<goals>
<goal>main-index</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
*/
package org.kordamp.maven.enforcer.checker;

import org.apache.maven.enforcer.rule.api.EnforcerRule;
import org.apache.maven.enforcer.rule.api.AbstractEnforcerRule;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.kordamp.maven.checker.BomChecker;
import org.kordamp.maven.checker.MavenLoggerAdapter;
import org.kordamp.maven.checker.PomCheckException;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Named;

/**
* Checks if a POM file is a minimal BOM file.
Expand All @@ -42,7 +39,8 @@
* @author Andres Almiray
* @since 1.0.0
*/
public class CheckBom implements EnforcerRule {
@Named("checkBom")
public class CheckBom extends AbstractEnforcerRule {
private boolean failOnError;

public boolean isFailOnError() {
Expand All @@ -54,32 +52,16 @@ public CheckBom setFailOnError(boolean failOnError) {
return this;
}

@Inject
private MavenProject project;

@Override
public void execute(@Nonnull EnforcerRuleHelper helper) throws EnforcerRuleException {
public void execute() throws EnforcerRuleException {
try {
MavenProject project = (MavenProject) helper.evaluate("${project}");
BomChecker.check(new MavenLoggerAdapter(helper.getLog()), project, new BomChecker.Configuration()
BomChecker.check(new MavenEnforcerLoggerAdapter(getLog()), project, new BomChecker.Configuration()
.withFailOnError(failOnError));
} catch (ExpressionEvaluationException e) {
throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
} catch (PomCheckException e) {
throw new EnforcerRuleException(e.getMessage());
}
}

@Override
public boolean isCacheable() {
return false;
}

@Override
public boolean isResultValid(@Nonnull EnforcerRule enforcerRule) {
return false;
}

@Nullable
@Override
public String getCacheId() {
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@
*/
package org.kordamp.maven.enforcer.checker;

import org.apache.maven.enforcer.rule.api.EnforcerRule;
import org.apache.maven.enforcer.rule.api.AbstractEnforcerRule;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.kordamp.maven.checker.MavenCentralChecker;
import org.kordamp.maven.checker.MavenLoggerAdapter;
import org.kordamp.maven.checker.PomCheckException;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Named;

/**
* Checks if a POM complies with the rules for uploading to Maven Central.
*
* @author Andres Almiray
* @since 1.0.0
*/
public class CheckMavenCentral implements EnforcerRule {
@Named("checkMavenCentral")
public class CheckMavenCentral extends AbstractEnforcerRule {
private boolean release = true;
private boolean strict = true;
private boolean failOnError = true;
Expand Down Expand Up @@ -77,35 +75,19 @@ public CheckMavenCentral setFailOnWarning(boolean failOnWarning) {
return this;
}

@Inject
private MavenProject project;

@Override
public void execute(@Nonnull EnforcerRuleHelper helper) throws EnforcerRuleException {
public void execute() throws EnforcerRuleException {
try {
MavenProject project = (MavenProject) helper.evaluate("${project}");
MavenCentralChecker.check(new MavenLoggerAdapter(helper.getLog()), project, new MavenCentralChecker.Configuration()
MavenCentralChecker.check(new MavenEnforcerLoggerAdapter(getLog()), project, new MavenCentralChecker.Configuration()
.withRelease(release)
.withStrict(strict)
.withFailOnError(failOnError)
.withFailOnWarning(failOnWarning));
} catch (ExpressionEvaluationException e) {
throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
} catch (PomCheckException e) {
throw new EnforcerRuleException(e.getMessage());
}
}

@Override
public boolean isCacheable() {
return false;
}

@Override
public boolean isResultValid(@Nonnull EnforcerRule enforcerRule) {
return false;
}

@Nullable
@Override
public String getCacheId() {
return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2023 Andres Almiray.
*
* Licensed 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
*
* https://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.
*/
package org.kordamp.maven.enforcer.checker;

import org.apache.maven.enforcer.rule.api.EnforcerLogger;
import org.kordamp.maven.checker.Logger;
import org.slf4j.helpers.MessageFormatter;

/**
* @author Andres Almiray
* @since 1.9.0
*/
public class MavenEnforcerLoggerAdapter implements Logger {
private final EnforcerLogger delegate;

public MavenEnforcerLoggerAdapter(EnforcerLogger delegate) {
this.delegate = delegate;
}

@Override
public void debug(String message) {
delegate.debug(message);
}

@Override
public void info(String message) {
delegate.info(message);
}

@Override
public void warn(String message) {
delegate.warn(message);
}

@Override
public void error(String message) {
delegate.error(message);
}

@Override
public void debug(String message, Object... args) {
delegate.debug(MessageFormatter.arrayFormat(message, args).getMessage());
}

@Override
public void info(String message, Object... args) {
delegate.info(MessageFormatter.arrayFormat(message, args).getMessage());
}

@Override
public void warn(String message, Object... args) {
delegate.warn(MessageFormatter.arrayFormat(message, args).getMessage());
}

@Override
public void error(String message, Object... args) {
delegate.error(MessageFormatter.arrayFormat(message, args).getMessage());
}

@Override
public void debug(String message, Throwable throwable) {
delegate.debug(message + " " + throwable);
}

@Override
public void info(String message, Throwable throwable) {
delegate.info(message + " " + throwable);
}

@Override
public void warn(String message, Throwable throwable) {
delegate.warn(message + " " + throwable);
}

@Override
public void error(String message, Throwable throwable) {
delegate.error(message + " " + throwable);
}
}

0 comments on commit 1520eab

Please sign in to comment.