Skip to content
Closed
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
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ under the License.

<properties>
<mavenVersion>3.0</mavenVersion>
<javaVersion>7</javaVersion>
<javaVersion>8</javaVersion>
</properties>

<dependencies>
Expand All @@ -77,19 +77,20 @@ under the License.
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there wasn't a version here before you probably don't want it now. I'd guess it's supplied by thedependencyManagement section of a parent or some such thing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I didn't find out any information about this.

<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
*/
public class VerificationResult
{
private List<File> existenceFailures = new ArrayList<File>();
private List<File> existenceFailures = new ArrayList<>();

private List<File> nonExistenceFailures = new ArrayList<File>();
private List<File> nonExistenceFailures = new ArrayList<>();

private List<File> contentFailures = new ArrayList<File>();
private List<File> contentFailures = new ArrayList<>();

/**
* @param file {@link File}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/**
*
*/
@FunctionalInterface
public interface VerificationResultPrinter
{
/**
Expand Down
33 changes: 9 additions & 24 deletions src/main/java/org/apache/maven/plugins/verifier/VerifierMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.apache.maven.plugins.verifier.model.Verifications;
import org.apache.maven.plugins.verifier.model.io.xpp3.VerificationsXpp3Reader;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

/**
* Verifies the existence or non-existence of files/directories and optionally checks file content against a regular
Expand All @@ -74,10 +74,9 @@ public class VerifierMojo
/**
* The file containing the verifications to perform.
*/
// CHECKSTYLE_OFF: LineLength
@Parameter( property = "verifier.verificationFile", defaultValue = "${basedir}/src/test/verifier/verifications.xml", required = true )
@Parameter( property = "verifier.verificationFile",
defaultValue = "${basedir}/src/test/verifier/verifications.xml", required = true )
private File verificationFile;
// CHECKSTYLE_ON: LineLength

/**
* Whether the build will fail on verification errors.
Expand Down Expand Up @@ -123,17 +122,11 @@ private VerificationResult verify()
{
VerificationResult results = new VerificationResult();

Reader reader = null;
try
try ( Reader reader = new FileReader( this.verificationFile ) )
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not changed in this PR, but this is likely a bug. There's no specified character set

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. There are no open issues about it, though, and according to this answer there is no possibility to set encoding for FileReader until Java 11. https://stackoverflow.com/questions/696626/java-filereader-encoding-issue
(another way still exists, though)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is why code shouldn't use FileReader. It's a bad API.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
reader = new FileReader( this.verificationFile );

VerificationsXpp3Reader xppReader = new VerificationsXpp3Reader();
Verifications verifications = xppReader.read( reader );

reader.close();
reader = null;

for ( org.apache.maven.plugins.verifier.model.File file : verifications.getFiles() )
{
// Transform the file to check into an absolute path prefixing the basedir if
Expand All @@ -149,23 +142,16 @@ private VerificationResult verify()
}
}
}
catch ( org.codehaus.plexus.util.xml.pull.XmlPullParserException e )
catch ( XmlPullParserException | IOException e )
{
throw new MojoExecutionException( "Error while verifying files", e );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error while verifying files", e );
}
finally
{
IOUtil.close( reader );
}

return results;
}

private boolean verifyFile( org.apache.maven.plugins.verifier.model.File fileCheck, VerificationResult results )
private boolean verifyFile( org.apache.maven.plugins.verifier.model.File fileCheck,
VerificationResult results )
throws IOException
{
boolean result;
Expand All @@ -179,8 +165,8 @@ private boolean verifyFile( org.apache.maven.plugins.verifier.model.File fileChe
return result;
}

// CHECKSTYLE_OFF: LineLength
private boolean verifyFileContent( org.apache.maven.plugins.verifier.model.File fileCheck, VerificationResult results )
private boolean verifyFileContent( org.apache.maven.plugins.verifier.model.File fileCheck,
VerificationResult results )
throws IOException
{
boolean result = false;
Expand All @@ -204,7 +190,6 @@ private boolean verifyFileContent( org.apache.maven.plugins.verifier.model.File

return result;
}
// CHECKSTYLE_ON: LineLength

private boolean verifyFileExistence( org.apache.maven.plugins.verifier.model.File fileCheck,
VerificationResult results )
Expand Down
4 changes: 2 additions & 2 deletions src/site/site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ specific language governing permissions and limitations
under the License.
-->

<project xmlns="http://maven.apache.org/DECORATION/1.0.0"
<project xmlns="http://maven.apache.org/DECORATION/1.8.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.0 http://maven.apache.org/xsd/decoration-1.8.0.xsd">
<body>
<menu name="Overview">
<item name="Introduction" href="index.html"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.verifier.VerificationResult;
import org.apache.maven.plugins.verifier.VerificationResultPrinter;
import org.apache.maven.plugins.verifier.VerifierMojo;

/*
* Licensed to the Apache Software Foundation (ASF) under one
Expand Down Expand Up @@ -36,7 +34,7 @@ public class VerifierMojoTest
private File getResourceFile( String name ) throws UnsupportedEncodingException
{
String file = getClass().getResource( name ).getFile();
String decode = URLDecoder.decode( file, "UTF-8" ); // necessary for JDK 1.5+, where spaces are escaped to %20
String decode = URLDecoder.decode( file, StandardCharsets.UTF_8.toString() );
return new File( decode );
}

Expand Down Expand Up @@ -70,15 +68,11 @@ public void testCheckFileThatDoesNotExist()
mojo.setBaseDir( new File( "c:/some/path" ) );
mojo.setVerificationFile( file );
mojo.setFailOnError( true );
mojo.setVerificationResultPrinter( new VerificationResultPrinter()
{
public void print( VerificationResult result )
{
assertEquals( 1, result.getExistenceFailures().size() );
assertEquals( 0, result.getNonExistenceFailures().size() );
assertEquals( 0, result.getContentFailures().size() );
}
} );
mojo.setVerificationResultPrinter(result -> {
assertEquals( 1, result.getExistenceFailures().size() );
assertEquals( 0, result.getNonExistenceFailures().size() );
assertEquals( 0, result.getContentFailures().size() );
});

try
{
Expand All @@ -99,15 +93,11 @@ public void testCheckFileThatExists()
mojo.setBaseDir( file.getParentFile() );
mojo.setVerificationFile( file );
mojo.setFailOnError( true );
mojo.setVerificationResultPrinter( new VerificationResultPrinter()
{
public void print( VerificationResult result )
{
assertEquals( 0, result.getExistenceFailures().size() );
assertEquals( 0, result.getNonExistenceFailures().size() );
assertEquals( 0, result.getContentFailures().size() );
}
} );
mojo.setVerificationResultPrinter(result -> {
assertEquals( 0, result.getExistenceFailures().size() );
assertEquals( 0, result.getNonExistenceFailures().size() );
assertEquals( 0, result.getContentFailures().size() );
});

mojo.execute();
}
Expand All @@ -119,15 +109,11 @@ public void testCheckForInexistentFile()
File file = getResourceFile( "/InexistentFile.xml" );
mojo.setBaseDir( new File( "c:/some/path" ) );
mojo.setVerificationFile( file );
mojo.setVerificationResultPrinter( new VerificationResultPrinter()
{
public void print( VerificationResult result )
{
assertEquals( 0, result.getExistenceFailures().size() );
assertEquals( 0, result.getNonExistenceFailures().size() );
assertEquals( 0, result.getContentFailures().size() );
}
} );
mojo.setVerificationResultPrinter(result -> {
assertEquals( 0, result.getExistenceFailures().size() );
assertEquals( 0, result.getNonExistenceFailures().size() );
assertEquals( 0, result.getContentFailures().size() );
});

mojo.execute();
}
Expand All @@ -140,15 +126,13 @@ public void testCheckForInexistentFileThatExists()
mojo.setBaseDir( file.getParentFile() );
mojo.setVerificationFile( file );
mojo.setFailOnError( true );
mojo.setVerificationResultPrinter( new VerificationResultPrinter()
{
public void print( VerificationResult result )
mojo.setVerificationResultPrinter( result ->
{
assertEquals( 0, result.getExistenceFailures().size() );
assertEquals( 1, result.getNonExistenceFailures().size() );
assertEquals( 0, result.getContentFailures().size() );
}
} );
);

try
{
Expand All @@ -168,15 +152,11 @@ public void testCheckFileForContent()
File file = getResourceFile( "/FileExistsValidContent.xml" );
mojo.setBaseDir( file.getParentFile() );
mojo.setVerificationFile( file );
mojo.setVerificationResultPrinter( new VerificationResultPrinter()
{
public void print( VerificationResult result )
{
assertEquals( 0, result.getExistenceFailures().size() );
assertEquals( 0, result.getNonExistenceFailures().size() );
assertEquals( 0, result.getContentFailures().size() );
}
} );
mojo.setVerificationResultPrinter(result -> {
assertEquals( 0, result.getExistenceFailures().size() );
assertEquals( 0, result.getNonExistenceFailures().size() );
assertEquals( 0, result.getContentFailures().size() );
});

mojo.execute();
}
Expand All @@ -189,15 +169,11 @@ public void testCheckFileForInvalidContent()
mojo.setBaseDir( file.getParentFile() );
mojo.setVerificationFile( file );
mojo.setFailOnError( true );
mojo.setVerificationResultPrinter( new VerificationResultPrinter()
{
public void print( VerificationResult result )
{
assertEquals( 0, result.getExistenceFailures().size() );
assertEquals( 0, result.getNonExistenceFailures().size() );
assertEquals( 1, result.getContentFailures().size() );
}
} );
mojo.setVerificationResultPrinter(result -> {
assertEquals( 0, result.getExistenceFailures().size() );
assertEquals( 0, result.getNonExistenceFailures().size() );
assertEquals( 1, result.getContentFailures().size() );
});

try
{
Expand Down