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

Bump parent-pom to 74 and apply formatting #79

Merged
merged 2 commits into from
May 18, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 10 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand All @@ -18,14 +17,13 @@
specific language governing permissions and 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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>mojo-parent</artifactId>
<version>70</version>
<version>74</version>
<relativePath />
</parent>

Expand All @@ -34,10 +32,8 @@
<packaging>maven-plugin</packaging>

<name>Tidy Maven Plugin</name>
<description>
Tidy Plugin for Maven. The Tidy plugin provides goals for tidying up
your source code.
</description>
<description>Tidy Plugin for Maven. The Tidy plugin provides goals for tidying up
your source code.</description>
<url>https://www.mojohaus.org/tidy-maven-plugin/</url>
<inceptionYear>2011</inceptionYear>
<licenses>
Expand Down Expand Up @@ -68,19 +64,18 @@
</developers>

<prerequisites>
<maven>${mavenVersion}</maven>
<maven>${maven.version}</maven>
</prerequisites>

<scm>
<connection>scm:git:https://github.com/mojohaus/tidy-maven-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/mojohaus/tidy-maven-plugin.git</developerConnection>
<url>https://github.com/mojohaus/tidy-maven-plugin/tree/master</url>
<tag>HEAD</tag>
<url>https://github.com/mojohaus/tidy-maven-plugin/tree/master</url>
</scm>

<properties>
<mavenVersion>3.5.4</mavenVersion>
<junit.version>5.9.1</junit.version>
<maven.version>3.5.4</maven.version>
<project.build.outputTimestamp>2022-09-30T06:33:55Z</project.build.outputTimestamp>
</properties>

Expand All @@ -98,13 +93,13 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${mavenVersion}</version>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -134,26 +129,17 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.version}</version>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>run-its</id>
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/org/codehaus/mojo/tidy/CheckMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@
* Checks that the <code>pom.xml</code> is tidy. Fails the build if <code>mvn tidy:pom</code> would
* create a different <code>pom.xml</code> than the current one.
*/
@Mojo( name = "check", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true )
public class CheckMojo
extends TidyMojo
{
@Mojo(name = "check", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true)
public class CheckMojo extends TidyMojo {
@Override
protected void executeForPom( String pom )
throws MojoExecutionException, MojoFailureException
{
String tidyPom = tidy( pom );
if ( !pom.equals( tidyPom ) )
{
protected void executeForPom(String pom) throws MojoExecutionException, MojoFailureException {
String tidyPom = tidy(pom);
if (!pom.equals(tidyPom)) {
throw new MojoFailureException(
"The POM violates the code style. Please format it by running `mvn tidy:pom`." );
"The POM violates the code style. Please format it by running `mvn tidy:pom`.");
}
}
}
27 changes: 10 additions & 17 deletions src/main/java/org/codehaus/mojo/tidy/PomMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,26 @@
* under the License.
*/

import java.io.IOException;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;

import java.io.IOException;

import static org.codehaus.plexus.util.FileUtils.fileWrite;

/**
* Tidy up the <code>pom.xml</code> into the canonical order.
*/
@Mojo( name = "pom" )
public class PomMojo
extends TidyMojo
{
@Mojo(name = "pom")
public class PomMojo extends TidyMojo {
@Override
protected void executeForPom( String pom )
throws MojoExecutionException, MojoFailureException
{
try
{
String tidyPom = tidy( pom );
fileWrite( getPomFile(), tidyPom );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Failed to write the tidy POM.", e );
protected void executeForPom(String pom) throws MojoExecutionException, MojoFailureException {
try {
String tidyPom = tidy(pom);
fileWrite(getPomFile(), tidyPom);
} catch (IOException e) {
throw new MojoExecutionException("Failed to write the tidy POM.", e);
}
}
}
61 changes: 22 additions & 39 deletions src/main/java/org/codehaus/mojo/tidy/TidyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,37 @@
* under the License.
*/

import static org.codehaus.plexus.util.FileUtils.fileRead;
import javax.xml.stream.XMLStreamException;

import java.io.File;
import java.io.IOException;

import javax.xml.stream.XMLStreamException;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.tidy.task.PomTidy;

import static org.codehaus.plexus.util.FileUtils.fileRead;

/**
* An abstract base class for Mojos of the Tidy plugin. Handles common
* configuration issues and provides the POM as String.
*/
public abstract class TidyMojo
extends AbstractMojo
{
public abstract class TidyMojo extends AbstractMojo {
private static final PomTidy POM_TIDY = new PomTidy();

/**
* The Maven Project.
*/
@Parameter( defaultValue = "${project}", required = true, readonly = true )
@Parameter(defaultValue = "${project}", required = true, readonly = true)
protected MavenProject project;

/**
* Set this to 'true' to skip execution.
*/
@Parameter( property = "tidy.skip", defaultValue = "false" )
@Parameter(property = "tidy.skip", defaultValue = "false")
protected boolean skip;

/**
Expand All @@ -63,59 +61,44 @@ public abstract class TidyMojo
* @throws MojoFailureException if an expected problem (such as a compilation failure) occurs.
* Throwing this exception causes a "BUILD FAILURE" message to be displayed.
*/
protected abstract void executeForPom( String pom )
throws MojoExecutionException, MojoFailureException;
protected abstract void executeForPom(String pom) throws MojoExecutionException, MojoFailureException;

@Override
public void execute()
throws MojoExecutionException, MojoFailureException
{
if ( skip )
{
getLog().info( "Tidy is skipped." );
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().info("Tidy is skipped.");
return;
}
String pom = getProjectPom();
executeForPom( pom );
executeForPom(pom);
}

/**
* Returns the project's POM.
*/
private String getProjectPom()
throws MojoExecutionException
{
try
{
return fileRead( getPomFile() );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Failed to read the POM.", e );
private String getProjectPom() throws MojoExecutionException {
try {
return fileRead(getPomFile());
} catch (IOException e) {
throw new MojoExecutionException("Failed to read the POM.", e);
}
}

/**
* Returns the file of the POM.
*/
protected File getPomFile()
{
protected File getPomFile() {
return project.getFile();
}

/**
* Tidy the given POM.
*/
protected String tidy( String pom )
throws MojoExecutionException
{
try
{
return POM_TIDY.tidy( pom );
}
catch ( XMLStreamException e )
{
throw new MojoExecutionException( e.getMessage(), e );
protected String tidy(String pom) throws MojoExecutionException {
try {
return POM_TIDY.tidy(pom);
} catch (XMLStreamException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
Loading