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

Enable spotless for code formatting #180

Merged
merged 3 commits into from
May 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 29 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<url>https://www.mojohaus.org/build-helper-maven-plugin/</url>

<name>Build Helper Maven Plugin</name>
<description>This plugin contains various small independent goals to assist with Maven build lifecycle</description>
<url>https://www.mojohaus.org/build-helper-maven-plugin/</url>
<inceptionYear>2005</inceptionYear>
<licenses>
<license>
Expand Down Expand Up @@ -59,8 +59,8 @@
<scm>
<connection>scm:git:https://github.com/mojohaus/build-helper-maven-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/mojohaus/build-helper-maven-plugin.git</developerConnection>
<url>https://github.com/mojohaus/build-helper-maven-plugin/tree/master</url>
<tag>HEAD</tag>
<url>https://github.com/mojohaus/build-helper-maven-plugin/tree/master</url>
</scm>

<issueManagement>
Expand All @@ -76,6 +76,7 @@
<properties>
<mavenVersion>3.2.5</mavenVersion>
<mojo.java.target>8</mojo.java.target>
<recommendedJavaBuildVersion>11</recommendedJavaBuildVersion>
<!-- remove with parent upgrade -->
<maven-release-plugin.version>3.0.0</maven-release-plugin.version>
<scmpublish.content>${project.build.directory}/staging/build-helper-maven-plugin</scmpublish.content>
Expand Down Expand Up @@ -114,9 +115,9 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>file-management</artifactId>
<version>3.1.0</version>
<groupId>org.apache.maven.shared</groupId>
<artifactId>file-management</artifactId>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -137,30 +138,10 @@
</dependency>
</dependencies>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<!-- version inherited -->
<configuration>
<configLocation>config/maven_checks.xml</configLocation>
<headerLocation>header.txt</headerLocation>
</configuration>
</plugin>
</plugins>
</reporting>

<profiles>

<profile>
<id>run-its</id>
<activation>
<property>
<name>skipTests</name>
<value>!true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -188,6 +169,29 @@
</build>
</profile>

<profile>
<id>java11+</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>${checkstyle.spotless.config}</configLocation>
<violationIgnore>MagicNumber</violationIgnore>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<!-- This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
<profile>
<id>only-eclipse</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,33 @@
/**
* Abstract Mojo for adding Resources
*/
public abstract class AbstractAddResourceMojo
extends AbstractMojo
{
public abstract class AbstractAddResourceMojo extends AbstractMojo {
/**
* Additional resource directories.
*/
@Parameter( required = true )
@Parameter(required = true)
private Resource[] resources;

/**
* The maven project
*/
@Parameter( readonly = true, defaultValue = "${project}" )
@Parameter(readonly = true, defaultValue = "${project}")
private MavenProject project;

/**
* Main plugin execution
*/
public void execute()
{
for ( Resource resource : resources )
{
public void execute() {
for (Resource resource : resources) {
// Check for relative paths in the resource configuration.
// http://maven.apache.org/plugin-developers/common-bugs.html#Resolving_Relative_Paths
File resourceDir = new File( resource.getDirectory() );
if ( !resourceDir.isAbsolute() )
{
resourceDir = new File( project.getBasedir(), resource.getDirectory() );
resource.setDirectory( resourceDir.getAbsolutePath() );
File resourceDir = new File(resource.getDirectory());
if (!resourceDir.isAbsolute()) {
resourceDir = new File(project.getBasedir(), resource.getDirectory());
resource.setDirectory(resourceDir.getAbsolutePath());
}

addResource( resource );
addResource(resource);
}
}

Expand All @@ -74,15 +69,14 @@ public void execute()
*
* @param resource the resource to add
*/
public abstract void addResource( Resource resource );
public abstract void addResource(Resource resource);

/**
* Get the current project instance.
*
* @return the project
*/
public MavenProject getProject()
{
public MavenProject getProject() {
return this.project;
}
}
Original file line number Diff line number Diff line change
@@ -1,59 +1,54 @@
package org.codehaus.mojo.buildhelper;

/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

public abstract class AbstractDefinePropertyMojo
extends AbstractMojo
{
/**
* The maven project
*/
@Parameter( readonly = true, defaultValue = "${project}" )
protected MavenProject project;

protected void defineProperty( String name, String value )
{
if ( getLog().isDebugEnabled() )
{
getLog().debug( "define property " + name + " = \"" + value + "\"" );
}

project.getProperties().put( name, value );
}

/**
* Get the current project instance.
*
* @return the project
*/
public MavenProject getProject()
{
return this.project;
}
}
package org.codehaus.mojo.buildhelper;

/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

public abstract class AbstractDefinePropertyMojo extends AbstractMojo {
/**
* The maven project
*/
@Parameter(readonly = true, defaultValue = "${project}")
protected MavenProject project;

protected void defineProperty(String name, String value) {
if (getLog().isDebugEnabled()) {
getLog().debug("define property " + name + " = \"" + value + "\"");
}

project.getProperties().put(name, value);
}

/**
* Get the current project instance.
*
* @return the project
*/
public MavenProject getProject() {
return this.project;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.codehaus.mojo.buildhelper;

import java.util.Locale;

/*
* The MIT License
*
Expand All @@ -26,6 +24,7 @@
* SOFTWARE.
*/

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
Expand All @@ -34,64 +33,47 @@
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.StringUtils;

public abstract class AbstractRegexPropertyMojo
extends AbstractDefinePropertyMojo
{
public abstract class AbstractRegexPropertyMojo extends AbstractDefinePropertyMojo {

protected void execute( RegexPropertySetting config )
throws MojoExecutionException, MojoFailureException
{
try
{
protected void execute(RegexPropertySetting config) throws MojoExecutionException, MojoFailureException {
try {
config.validate();
}
catch ( IllegalArgumentException e )
{
throw new MojoExecutionException( e.getMessage(), e );
} catch (IllegalArgumentException e) {
throw new MojoExecutionException(e.getMessage(), e);
}

Pattern pattern;
try
{
pattern = Pattern.compile( config.getRegex() );
try {
pattern = Pattern.compile(config.getRegex());
} catch (PatternSyntaxException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
catch ( PatternSyntaxException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
Matcher matcher = pattern.matcher( config.getValue() );
Matcher matcher = pattern.matcher(config.getValue());

if ( matcher.find() )
{
if (matcher.find()) {
// if the string replacement is empty, we define the value replacement to empty.
config.setValue( ( StringUtils.isNotEmpty( config.getReplacement() )
? matcher.replaceAll( config.getReplacement() ) : matcher.replaceAll( "" ) ) );
}
else
{
if ( config.isFailIfNoMatch() )
{
throw new MojoFailureException( "No match to regex '" + config.getRegex() + "' found in '"
+ config.getValue() + "'." );
}
else
{
getLog().info( "No match to regex '" + config.getRegex() + "' found in '" + config.getValue() + "'. "
+ "The initial value '" + config.getValue() + "' is left as-is..." );
config.setValue(
(StringUtils.isNotEmpty(config.getReplacement())
? matcher.replaceAll(config.getReplacement())
: matcher.replaceAll("")));
} else {
if (config.isFailIfNoMatch()) {
throw new MojoFailureException(
"No match to regex '" + config.getRegex() + "' found in '" + config.getValue() + "'.");
} else {
getLog().info("No match to regex '" + config.getRegex() + "' found in '" + config.getValue() + "'. "
+ "The initial value '" + config.getValue() + "' is left as-is...");
}
}

if ( config.isToLowerCase() )
{
config.setValue( config.getValue().toLowerCase( Locale.getDefault() ) );
if (config.isToLowerCase()) {
config.setValue(config.getValue().toLowerCase(Locale.getDefault()));
}

if ( config.isToUpperCase() )
{
config.setValue( config.getValue().toUpperCase( Locale.getDefault() ) );
if (config.isToUpperCase()) {
config.setValue(config.getValue().toUpperCase(Locale.getDefault()));
}

defineProperty( config.getName(), config.getValue() );

defineProperty(config.getName(), config.getValue());
}
}