Skip to content

Commit

Permalink
Execute checkstyle during build and apply recommended code format
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Sep 30, 2022
1 parent 3122013 commit b3ccff6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 27 deletions.
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@
</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
2 changes: 1 addition & 1 deletion src/main/java/org/codehaus/mojo/tidy/CheckMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* 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)
@Mojo( name = "check", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true )
public class CheckMojo
extends TidyMojo
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/codehaus/mojo/tidy/TidyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public abstract class TidyMojo
/**
* The Maven Project.
*/
@Parameter(defaultValue = "${project}", required = true, readonly = true)
@Parameter( defaultValue = "${project}", required = true, readonly = true )
protected MavenProject project;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -59,7 +60,8 @@ class EnsureOrderAndIndent
new SectionSorter( "build/extensions/extension", new NodeGroup( "groupId", "artifactId", "version" ) ),
new SectionSorter( "/project/parent", new NodeGroup( "groupId", "artifactId", "version", "relativePath" ) ),
new SectionSorter( "plugin", new NodeGroup( "groupId", "artifactId", "version" ) ),
new SectionSorter( "/project/distributionManagement/relocation", new NodeGroup( "groupId", "artifactId", "version" ) ) );
new SectionSorter( "/project/distributionManagement/relocation",
new NodeGroup( "groupId", "artifactId", "version" ) ) );

@Override
public String tidyPom( String pom, Format format )
Expand Down Expand Up @@ -237,7 +239,8 @@ private String formatSection( XMLEventReader reader, String pom, Format format,
}
addTextIfNotEmpty( output, indent, getPrecedingText( pom, starts[i], ends ), format );
addTextIfNotEmpty( output, indent, pom.substring( starts[i], ends[i] ), format );
firstGroupStarted = groupStarted = true;
firstGroupStarted = true;
groupStarted = true;
}
++i;
}
Expand Down
50 changes: 27 additions & 23 deletions src/test/java/org/codehaus/mojo/tidy/task/PomTidyFixesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,32 @@
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class PomTidyFixesTest {

protected static final String PATH = "fixes/order-and-indent-start-element-of-scope/";

@Parameters(name = "{0}")
public static Iterable<String> tests() {
return asList(
"property-ending-with-plugin.pom.xml",
"property-ending-with-dependency.pom.xml"
);
}

@Parameter(0)
public String name;

@Test
public void shouldThrowNoError()
throws Exception {
final String pom = IOUtil.toString(getClass().getResourceAsStream(PATH + name));
String tidyPom = new PomTidy().tidy(pom);
assertEquals(pom, tidyPom, "nothing to tidy here");
}
@RunWith( Parameterized.class )
public class PomTidyFixesTest
{

protected static final String PATH = "fixes/order-and-indent-start-element-of-scope/";

@Parameters( name = "{0}" )
public static Iterable<String> tests()
{
return asList(
"property-ending-with-plugin.pom.xml",
"property-ending-with-dependency.pom.xml"
);
}

@SuppressWarnings( "checkstyle:VisibilityModifier" )
@Parameter( 0 )
public String name;

@Test
public void shouldThrowNoError()
throws Exception
{
final String pom = IOUtil.toString( getClass().getResourceAsStream( PATH + name ) );
String tidyPom = new PomTidy().tidy( pom );
assertEquals( pom, tidyPom, "nothing to tidy here" );
}

}
1 change: 1 addition & 0 deletions src/test/java/org/codehaus/mojo/tidy/task/PomTidyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static Iterable<String> tests()
"pom-with-reporting", "project-single-line" );
}

@SuppressWarnings( "checkstyle:VisibilityModifier" )
@Parameter( 0 )
public String name;

Expand Down

0 comments on commit b3ccff6

Please sign in to comment.