Skip to content

Commit

Permalink
Enable spotless and checkstyle - code reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Jul 27, 2023
1 parent 3c13b09 commit f70cd08
Show file tree
Hide file tree
Showing 13 changed files with 853 additions and 1,095 deletions.
65 changes: 30 additions & 35 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,32 +17,29 @@
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>76</version>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>properties-maven-plugin</artifactId>
<version>1.2.0-SNAPSHOT</version>

<name>Properties Maven Plugin</name>
<description>
The Properties Maven Plugin is here to make life a little easier when dealing
with properties. It provides goals to read and write properties from files.
</description>

<inceptionYear>2009</inceptionYear>

<packaging>maven-plugin</packaging>

<name>Properties Maven Plugin</name>
<description>The Properties Maven Plugin is here to make life a little easier when dealing
with properties. It provides goals to read and write properties from files.</description>

<url>https://www.mojohaus.org/properties-maven-plugin</url>

<inceptionYear>2009</inceptionYear>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
Expand All @@ -52,29 +48,6 @@
</license>
</licenses>

<properties>
<mavenVersion>3.5.4</mavenVersion>
<recommendedJavaBuildVersion>11</recommendedJavaBuildVersion>
<scmpublish.content>target/staging/${project.artifactId}</scmpublish.content>
<project.build.outputTimestamp>2022-03-19T15:53:05Z</project.build.outputTimestamp>
</properties>


<scm>
<connection>scm:git:https://github.com/mojohaus/properties-maven-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/mojohaus/properties-maven-plugin.git</developerConnection>
<url>https://github.com/mojohaus/properties-maven-plugin/tree/master</url>
<tag>master</tag>
</scm>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/mojohaus/properties-maven-plugin/issues/</url>
</issueManagement>
<ciManagement>
<system>GitHub</system>
<url>https://github.com/mojohaus/properties-maven-plugin/actions/</url>
</ciManagement>

<developers>
<developer>
<id>arsenalist</id>
Expand All @@ -94,6 +67,28 @@
</developer>
</developers>

<scm>
<connection>scm:git:https://github.com/mojohaus/properties-maven-plugin.git</connection>
<developerConnection>scm:git:ssh://git@github.com/mojohaus/properties-maven-plugin.git</developerConnection>
<tag>master</tag>
<url>https://github.com/mojohaus/properties-maven-plugin/tree/master</url>
</scm>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/mojohaus/properties-maven-plugin/issues/</url>
</issueManagement>
<ciManagement>
<system>GitHub</system>
<url>https://github.com/mojohaus/properties-maven-plugin/actions/</url>
</ciManagement>

<properties>
<mavenVersion>3.5.4</mavenVersion>
<recommendedJavaBuildVersion>11</recommendedJavaBuildVersion>
<scmpublish.content>target/staging/${project.artifactId}</scmpublish.content>
<project.build.outputTimestamp>2022-03-19T15:53:05Z</project.build.outputTimestamp>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,123 +19,99 @@
* under the License.
*/

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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.io.BufferedReader;

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

/**
* @author <a href="mailto:zarars@gmail.com">Zarar Siddiqi</a>
*/
public abstract class AbstractWritePropertiesMojo
extends AbstractMojo
{
public abstract class AbstractWritePropertiesMojo extends AbstractMojo {

@Parameter( defaultValue = "${project}", required = true, readonly = true )
@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;

@Parameter( required = true, property = "properties.outputFile" )
@Parameter(required = true, property = "properties.outputFile")
private File outputFile;

/**
* @param properties {@link Properties}
* @param file {@link File}
* @throws MojoExecutionException {@link MojoExecutionException}
*/
protected void writeProperties( Properties properties, File file )
throws MojoExecutionException
{
try
{
storeWithoutTimestamp( properties, file, "Properties" );
}
catch ( FileNotFoundException e )
{
getLog().error( "Could not create FileOutputStream: " + file );
throw new MojoExecutionException( e.getMessage(), e );
}
catch ( IOException e )
{
getLog().error( "Error writing properties: " + file );
throw new MojoExecutionException( e.getMessage(), e );
protected void writeProperties(Properties properties, File file) throws MojoExecutionException {
try {
storeWithoutTimestamp(properties, file, "Properties");
} catch (FileNotFoundException e) {
getLog().error("Could not create FileOutputStream: " + file);
throw new MojoExecutionException(e.getMessage(), e);
} catch (IOException e) {
getLog().error("Error writing properties: " + file);
throw new MojoExecutionException(e.getMessage(), e);
}
}

// https://github.com/apache/maven-archiver/blob/master/src/main/java/org/apache/maven/archiver/PomPropertiesUtil.java#L81
private void storeWithoutTimestamp( Properties properties, File outputFile, String comments )
throws IOException
{
try ( PrintWriter pw = new PrintWriter( outputFile, "ISO-8859-1" ); StringWriter sw = new StringWriter() )
{
properties.store( sw, comments );
private void storeWithoutTimestamp(Properties properties, File outputFile, String comments) throws IOException {
try (PrintWriter pw = new PrintWriter(outputFile, "ISO-8859-1");
StringWriter sw = new StringWriter()) {
properties.store(sw, comments);
comments = '#' + comments;

List<String> lines = new ArrayList<>();
try ( BufferedReader r = new BufferedReader( new StringReader( sw.toString() ) ) )
{
try (BufferedReader r = new BufferedReader(new StringReader(sw.toString()))) {
String line;
while ( ( line = r.readLine() ) != null )
{
if ( !line.startsWith( "#" ) || line.equals( comments ) )
{
lines.add( line );
while ((line = r.readLine()) != null) {
if (!line.startsWith("#") || line.equals(comments)) {
lines.add(line);
}
}
}

Collections.sort( lines );
for ( String l : lines )
{
pw.println( l );
Collections.sort(lines);
for (String l : lines) {
pw.println(l);
}
}
}

/**
* @throws MojoExecutionException {@link MojoExecutionException}
*/
protected void validateOutputFile()
throws MojoExecutionException
{
if ( outputFile.isDirectory() )
{
throw new MojoExecutionException( "outputFile must be a file and not a directory" );
protected void validateOutputFile() throws MojoExecutionException {
if (outputFile.isDirectory()) {
throw new MojoExecutionException("outputFile must be a file and not a directory");
}
// ensure path exists
if ( outputFile.getParentFile() != null )
{
if (outputFile.getParentFile() != null) {
outputFile.getParentFile().mkdirs();
}
}

/**
* @return {@link MavenProject}
*/
public MavenProject getProject()
{
public MavenProject getProject() {
return project;
}

/**
* @return {@link #outputFile}
*/
public File getOutputFile()
{
public File getOutputFile() {
return outputFile;
}

}

0 comments on commit f70cd08

Please sign in to comment.