Skip to content

Commit

Permalink
Enable checkstyle during build
Browse files Browse the repository at this point in the history
- checkstyle verification will be done on each build
- reformat code according to rules
- reorder imports
  • Loading branch information
slawekjaranowski committed Aug 25, 2022
1 parent 6c6688b commit 9934505
Show file tree
Hide file tree
Showing 86 changed files with 1,827 additions and 1,533 deletions.
14 changes: 4 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,11 @@
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>2.0.0</version>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public boolean isProcessingParent()
/**
* Should the artifacts produced in the current reactor be excluded from processing.
*
* @return returns <code>true</code> if the artifacts produced in the current reactor should be excluded from processing.
* @return returns <code>true</code> if the artifacts produced in the current reactor
* should be excluded from processing.
* @since 1.0-alpha-3
*/
public boolean isExcludeReactor()
Expand All @@ -182,7 +183,7 @@ public boolean isExcludeReactor()

/**
* Should the dependency be updated itself or is it handled by properties.
*
*
* @param dependency Dependency
* @return true if the version starts with '${'
* @since 2.8
Expand Down Expand Up @@ -220,8 +221,8 @@ protected Artifact findArtifact( Dependency dependency )
* Try to find the dependency artifact that matches the given dependency.
*
* @param dependency Dependency
* @throws MojoExecutionException Mojo execution exception
* @return Artifact
* @throws MojoExecutionException Mojo execution exception
* @since 1.0-alpha-3
*/
protected Artifact toArtifact( Dependency dependency )
Expand Down Expand Up @@ -301,9 +302,11 @@ protected String toString( Dependency d )
*/
protected boolean isProducedByReactor( Dependency dependency )
{
for ( Object reactorProject : reactorProjects ) {
for ( Object reactorProject : reactorProjects )
{
MavenProject project = (MavenProject) reactorProject;
if ( compare(project, dependency) ) {
if ( compare( project, dependency ) )
{
return true;
}
}
Expand All @@ -315,7 +318,7 @@ protected boolean isProducedByReactor( Dependency dependency )
* Compare a project to a dependency. Returns true only if the groupId and artifactId are all equal.
*
* @param project the project
* @param dep the dependency
* @param dep the dependency
* @return true if project and dep refer to the same artifact
*/
private boolean compare( MavenProject project, Dependency dep )
Expand All @@ -332,7 +335,7 @@ private boolean compare( MavenProject project, Dependency dep )
* equal.
*
* @param artifact Artifact
* @param dep Dependency
* @param dep Dependency
* @return true if artifact and dep refer to the same artifact
*/
private boolean compare( Artifact artifact, Dependency dep )
Expand Down Expand Up @@ -381,7 +384,7 @@ protected boolean isIncluded( Artifact artifact )

/**
* Indicates whether any includes were specified via the 'includes' or 'includesList' options.
*
*
* @return true if includes were specified, false otherwise.
*/
protected boolean hasIncludes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public abstract class AbstractVersionsDisplayMojo
extends AbstractVersionsUpdaterMojo
{
String NL = System.getProperty( "line.separator" );
static final String NL = System.getProperty( "line.separator" );

private static final int DEFAULT_OUTPUT_LINE_WIDTH = 80;

Expand Down Expand Up @@ -70,7 +70,8 @@ public abstract class AbstractVersionsDisplayMojo
*
* @since 2.10.0
*/
@Parameter( property = "versions.outputLineWidth", defaultValue = AbstractVersionsDisplayMojo.DEFAULT_OUTPUT_LINE_WIDTH + "" )
@Parameter( property = "versions.outputLineWidth",
defaultValue = AbstractVersionsDisplayMojo.DEFAULT_OUTPUT_LINE_WIDTH + "" )
private int outputLineWidth;

private boolean outputFileError = false;
Expand Down Expand Up @@ -129,7 +130,7 @@ else if ( !outputFile.getParentFile().isDirectory() )
{
outputEncoding = System.getProperty( "file.encoding" );
getLog().warn( "File encoding has not been set, using platform encoding " + outputEncoding
+ ", i.e. build is platform dependent!" );
+ ", i.e. build is platform dependent!" );
}
}
}
Expand All @@ -152,8 +153,8 @@ protected void logLine( boolean error, String line )
try
{
Files.write( outputFile.toPath(),
( error ? "> " + line + NL : line + NL ).getBytes( outputEncoding ),
StandardOpenOption.APPEND, StandardOpenOption.CREATE );
( error ? "> " + line + NL : line + NL ).getBytes( outputEncoding ),
StandardOpenOption.APPEND, StandardOpenOption.CREATE );
}
catch ( IOException e )
{
Expand All @@ -166,7 +167,8 @@ protected void logLine( boolean error, String line )
/**
* @return Offset of the configured output line width compared to the default with of 80.
*/
protected int getOutputLineWidthOffset() {
protected int getOutputLineWidthOffset()
{
return this.outputLineWidth - DEFAULT_OUTPUT_LINE_WIDTH;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
* under the License.
*/

import java.io.File;
import java.util.List;
import java.util.Locale;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
Expand All @@ -44,10 +48,6 @@
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.plexus.i18n.I18N;

import java.io.File;
import java.util.List;
import java.util.Locale;

/**
* Base class for all versions reports.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ protected void safeBold()
}
}

@SuppressWarnings( "checkstyle:MethodName" )
protected void safeBold_()
{
try
Expand All @@ -235,6 +236,7 @@ protected void safeItalic()
}
}

@SuppressWarnings( "checkstyle:MethodName" )
protected void safeItalic_()
{
try
Expand Down Expand Up @@ -306,6 +308,7 @@ protected void renderDependencyDetailTable( Dependency dependency, ArtifactVersi
renderDependencyDetailTable( dependency, details, true, true, true );
}

@SuppressWarnings( "checkstyle:MethodLength" )
protected void renderDependencyDetailTable( Dependency dependency, ArtifactVersions details, boolean includeScope,
boolean includeClassifier, boolean includeType )
{
Expand Down Expand Up @@ -601,6 +604,7 @@ protected void renderPropertySummaryTableHeader()
sink.tableRow_();
}

@SuppressWarnings( "checkstyle:MethodLength" )
protected void renderPropertyDetailTable( Property property, PropertyVersions versions )
{
final SinkEventAttributes headerAttributes = new SinkEventAttributeSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
* under the License.
*/

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Writer;
import java.util.List;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
Expand All @@ -38,7 +47,6 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Settings;
import org.codehaus.mojo.versions.api.ArtifactVersions;
Expand All @@ -55,14 +63,6 @@
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.stax2.XMLInputFactory2;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Writer;
import java.util.List;

/**
* Abstract base class for Versions Mojos.
*
Expand Down Expand Up @@ -277,14 +277,14 @@ public void execute()
/**
* Finds the latest version of the specified artifact that matches the version range.
*
* @param artifact The artifact.
* @param versionRange The version range.
* @param allowingSnapshots <code>null</code> for no override, otherwise the local override to apply.
* @param artifact The artifact.
* @param versionRange The version range.
* @param allowingSnapshots <code>null</code> for no override, otherwise the local override to apply.
* @param usePluginRepositories Use plugin repositories
* @return The latest version of the specified artifact that matches the specified version range or
* <code>null</code> if no matching version could be found.
* <code>null</code> if no matching version could be found.
* @throws ArtifactMetadataRetrievalException If the artifact metadata could not be found.
* @throws MojoExecutionException if something goes wrong.
* @throws MojoExecutionException if something goes wrong.
* @since 1.0-alpha-1
*/
protected ArtifactVersion findLatestVersion( Artifact artifact, VersionRange versionRange,
Expand All @@ -308,7 +308,7 @@ protected ArtifactVersion findLatestVersion( Artifact artifact, VersionRange ver
* Gets the property value that is defined in the pom. This is an extension point to allow updating a file external
* to the reactor.
*
* @param pom The pom.
* @param pom The pom.
* @param property The property.
* @return The value as defined in the pom or <code>null</code> if not defined.
* @since 1.0-alpha-1
Expand All @@ -323,7 +323,7 @@ protected String getPropertyValue( StringBuilder pom, String property )
*
* @param outFile The file to process.
* @throws MojoExecutionException If things go wrong.
* @throws MojoFailureException If things go wrong.
* @throws MojoFailureException If things go wrong.
* @since 1.0-alpha-1
*/
protected void process( File outFile )
Expand Down Expand Up @@ -375,7 +375,7 @@ protected void process( File outFile )
* Creates a {@link org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader} from a StringBuilder.
*
* @param input The XML to read and modify.
* @param path Path pointing to the source of the XML
* @param path Path pointing to the source of the XML
* @return The {@link org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader}.
*/
protected final ModifiedPomXMLEventReader newModifiedPomXER( StringBuilder input, String path )
Expand All @@ -398,13 +398,13 @@ protected final ModifiedPomXMLEventReader newModifiedPomXER( StringBuilder input
* Writes a StringBuilder into a file.
*
* @param outFile The file to read.
* @param input The contents of the file.
* @param input The contents of the file.
* @throws IOException when things go wrong.
*/
protected final void writeFile( File outFile, StringBuilder input )
throws IOException
{
try (Writer writer = WriterFactory.newXmlWriter( outFile ) )
try ( Writer writer = WriterFactory.newXmlWriter( outFile ) )
{
IOUtil.copy( input.toString(), writer );
}
Expand All @@ -414,44 +414,44 @@ protected final void writeFile( File outFile, StringBuilder input )
* Updates the pom.
*
* @param pom The pom to update.
* @throws MojoExecutionException If things go wrong.
* @throws MojoFailureException If things go wrong.
* @throws MojoExecutionException If things go wrong.
* @throws MojoFailureException If things go wrong.
* @throws javax.xml.stream.XMLStreamException If things go wrong.
* @throws ArtifactMetadataRetrievalException if something goes wrong.
* @throws ArtifactMetadataRetrievalException if something goes wrong.
* @since 1.0-alpha-1
*/
protected abstract void update( ModifiedPomXMLEventReader pom )
throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException;

/**
* @deprecated
* This method no longer supported.
* use shouldApplyUpdate( Artifact artifact, String currentVersion, ArtifactVersion updateVersion, Boolean forceUpdate )
*
* Returns <code>true</code> if the update should be applied.
*
* @param artifact The artifact.
* @param artifact The artifact.
* @param currentVersion The current version of the artifact.
* @param updateVersion The proposed new version of the artifact.
* @param updateVersion The proposed new version of the artifact.
* @return <code>true</code> if the update should be applied.
* @since 1.0-alpha-1
* @deprecated This method no longer supported.
* use shouldApplyUpdate( Artifact artifact, String currentVersion, ArtifactVersion updateVersion, Boolean
* forceUpdate )
* <p>
* Returns <code>true</code> if the update should be applied.
*/
@Deprecated
protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, ArtifactVersion updateVersion )
{
return shouldApplyUpdate(artifact,currentVersion,updateVersion,false);
return shouldApplyUpdate( artifact, currentVersion, updateVersion, false );
}

/**
* Returns <code>true</code> if the update should be applied.
*
* @param artifact The artifact.
* @param artifact The artifact.
* @param currentVersion The current version of the artifact.
* @param updateVersion The proposed new version of the artifact.
* @param updateVersion The proposed new version of the artifact.
* @return <code>true</code> if the update should be applied to the pom.
* @since 2.9
*/
protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, ArtifactVersion updateVersion, boolean forceUpdate )
protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, ArtifactVersion updateVersion,
boolean forceUpdate )
{
getLog().debug( "Proposal is to update from " + currentVersion + " to " + updateVersion );

Expand Down Expand Up @@ -495,8 +495,8 @@ protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, A
* Based on the passed flags, determines which segment is unchangable. This can be used when determining an upper
* bound for the "latest" version.
*
* @param allowMajorUpdates Allow major updates
* @param allowMinorUpdates Allow minor updates
* @param allowMajorUpdates Allow major updates
* @param allowMinorUpdates Allow minor updates
* @param allowIncrementalUpdates Allow incremental updates
* @return Returns the segment that is unchangable. If any segment can change, returns -1.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/codehaus/mojo/versions/CommitMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* under the License.
*/

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

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand All @@ -27,9 +30,6 @@
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;

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

/**
* Removes the initial backup of the pom, thereby accepting the changes.
*
Expand Down
Loading

0 comments on commit 9934505

Please sign in to comment.