You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/05/02 11:17:32 UTC
svn commit: r165612 - /maven/components/trunk/maven-core-it
/maven/components/trunk/maven-core-it/it0006
/maven/components/trunk/maven-core-it/it0006/src
/maven/components/trunk/maven-core-it/it0006/src/test
/maven/components/trunk/maven-core-it/it0006/src/test/verifier
/maven/components/trunk/maven-plugins
/maven/components/trunk/maven-plugins/maven-verifier-plugin
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/mdo
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/plugin
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/plugin/verifier
/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources
Author: brett
Date: Mon May 2 02:17:30 2005
New Revision: 165612
URL: http://svn.apache.org/viewcvs?rev=165612&view=rev
Log:
PR: MNG-348
Submitted by: Vincent Massol
Reviewed by: Brett Porter (applied with some changes)
Add a verifier plugin, for doing integration tests
Added:
maven/components/trunk/maven-core-it/it0006/
maven/components/trunk/maven-core-it/it0006/expected-results.txt (with props)
maven/components/trunk/maven-core-it/it0006/goals.txt (with props)
maven/components/trunk/maven-core-it/it0006/pom.xml (with props)
maven/components/trunk/maven-core-it/it0006/src/
maven/components/trunk/maven-core-it/it0006/src/test/
maven/components/trunk/maven-core-it/it0006/src/test/verifier/
maven/components/trunk/maven-core-it/it0006/src/test/verifier/verifications.xml (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/
maven/components/trunk/maven-plugins/maven-verifier-plugin/pom.xml (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/ConsoleVerificationResultPrinter.java (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResult.java (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResultPrinter.java (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerifierMojo.java (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/mdo/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/mdo/verifications.mdo
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/plugin/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/plugin/verifier/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/plugin/verifier/VerifierMojoTest.java (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileDoesNotExist.xml (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExists.xml (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsInvalidContent.xml (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsValidContent.xml (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFile.xml (with props)
maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFileThatExists.xml (with props)
Modified:
maven/components/trunk/maven-core-it/README.txt
maven/components/trunk/maven-core-it/integration-tests.txt
maven/components/trunk/maven-plugins/pom.xml
Modified: maven/components/trunk/maven-core-it/README.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/README.txt?rev=165612&r1=165611&r2=165612&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/README.txt (original)
+++ maven/components/trunk/maven-core-it/README.txt Mon May 2 02:17:30 2005
@@ -19,6 +19,8 @@
it0005: The simplest of pom installation. We have a snapshot pom and we install
it in local repository.
+it0006: Integration test for the verifier plugin.
+
it0007: We specify a parent in the POM and make sure that it is downloaded as
part of the process.
Modified: maven/components/trunk/maven-core-it/integration-tests.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/integration-tests.txt?rev=165612&r1=165611&r2=165612&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/integration-tests.txt (original)
+++ maven/components/trunk/maven-core-it/integration-tests.txt Mon May 2 02:17:30 2005
@@ -4,6 +4,7 @@
it0003
it0004
it0005
+it0006
it0007
it0008
it0009
@@ -15,4 +16,4 @@
it0016
it0017
it0018
-#it0019
+it0019
Added: maven/components/trunk/maven-core-it/it0006/expected-results.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0006/expected-results.txt?rev=165612&view=auto
==============================================================================
(empty)
Propchange: maven/components/trunk/maven-core-it/it0006/expected-results.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0006/expected-results.txt
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core-it/it0006/goals.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0006/goals.txt?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0006/goals.txt (added)
+++ maven/components/trunk/maven-core-it/it0006/goals.txt Mon May 2 02:17:30 2005
@@ -0,0 +1 @@
+integration-test
Propchange: maven/components/trunk/maven-core-it/it0006/goals.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0006/goals.txt
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core-it/it0006/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0006/pom.xml?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0006/pom.xml (added)
+++ maven/components/trunk/maven-core-it/it0006/pom.xml Mon May 2 02:17:30 2005
@@ -0,0 +1,29 @@
+<model>
+ <parent>
+ <artifactId>maven-verifier-plugin</artifactId>
+ <groupId>org.apache.maven.plugins</groupId>
+ <version>1.0-alpha-2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>maven-verifier-plugin-test</artifactId>
+ <name>Maven Verifier Plugin Test</name>
+ <version>1.0-alpha-2-SNAPSHOT</version>
+ <dependencies/>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-verifier-plugin</artifactId>
+ <!-- Problem here: if I specify a version, it won't build if the verifier plugin is not
+ in the remote repo. If I don't specify a version, it fails...
+ Now, even if I have built the verifier plugin locally m2 insist for downloading it
+ from the remote repo. Why is that? -->
+ <version>1.0-alpha-2-SNAPSHOT</version>
+ <goals>
+ <goal>
+ <id>verify</id>
+ </goal>
+ </goals>
+ </plugin>
+ </plugins>
+ </build>
+</model>
Propchange: maven/components/trunk/maven-core-it/it0006/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0006/pom.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core-it/it0006/src/test/verifier/verifications.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0006/src/test/verifier/verifications.xml?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0006/src/test/verifier/verifications.xml (added)
+++ maven/components/trunk/maven-core-it/it0006/src/test/verifier/verifications.xml Mon May 2 02:17:30 2005
@@ -0,0 +1,15 @@
+<verifications>
+ <files>
+ <file>
+ <location>src/test/verifier/verifications.xml</location>
+ </file>
+ <file>
+ <location>src/test/verifier/invalidfile</location>
+ <exists>false</exists>
+ </file>
+ <file>
+ <location>pom.xml</location>
+ <contains>Maven.*Plugin Test</contains>
+ </file>
+ </files>
+</verifications>
\ No newline at end of file
Propchange: maven/components/trunk/maven-core-it/it0006/src/test/verifier/verifications.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core-it/it0006/src/test/verifier/verifications.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/pom.xml?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/pom.xml (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/pom.xml Mon May 2 02:17:30 2005
@@ -0,0 +1,60 @@
+<model>
+ <parent>
+ <artifactId>maven-plugin-parent</artifactId>
+ <groupId>org.apache.maven.plugins</groupId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>maven-verifier-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <name>Maven Verifier Plugin</name>
+ <version>1.0-alpha-2-SNAPSHOT</version>
+ <developers>
+ <developer>
+ <id>vmassol</id>
+ <name>Vincent Massol</name>
+ <email>vmassol@apache.org</email>
+ <organization>Apache Software Foundation</organization>
+ <roles>
+ <role>Creator</role>
+ <role>Java Developer</role>
+ </roles>
+ </developer>
+ </developers>
+ <dependencies>
+ <dependency>
+ <groupId>plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.0-alpha-2</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-modello-plugin</artifactId>
+ <version>1.0-alpha-2-SNAPSHOT</version>
+ <configuration>
+ <model>src/main/mdo/verifications.mdo</model>
+ <version>1.0.0</version>
+ </configuration>
+ <goals>
+ <goal>
+ <id>xpp3-reader</id>
+ </goal>
+ <goal>
+ <id>xpp3-writer</id>
+ </goal>
+ <goal>
+ <id>java</id>
+ </goal>
+ </goals>
+ </plugin>
+ </plugins>
+ </build>
+</model>
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/pom.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/ConsoleVerificationResultPrinter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/ConsoleVerificationResultPrinter.java?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/ConsoleVerificationResultPrinter.java (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/ConsoleVerificationResultPrinter.java Mon May 2 02:17:30 2005
@@ -0,0 +1,74 @@
+package org.apache.maven.plugin.verifier;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.monitor.logging.Log;
+
+import java.util.Iterator;
+
+public class ConsoleVerificationResultPrinter
+ implements VerificationResultPrinter
+{
+ private Log log;
+
+ public ConsoleVerificationResultPrinter( Log log )
+ {
+ this.log = log;
+ }
+
+ public void print( VerificationResult results )
+ {
+ printExistenceFailures( results );
+ printNonExistenceFailures( results );
+ printContentFailures( results );
+ }
+
+ private void printExistenceFailures( VerificationResult results )
+ {
+ for ( Iterator i = results.getExistenceFailures().iterator(); i.hasNext(); )
+ {
+ org.apache.maven.plugin.verifier.model.File file = (org.apache.maven.plugin.verifier.model.File) i.next();
+
+ printMessage( "File not found [" + file.getLocation() + "]" );
+ }
+ }
+
+ private void printNonExistenceFailures( VerificationResult results )
+ {
+ for ( Iterator i = results.getNonExistenceFailures().iterator(); i.hasNext(); )
+ {
+ org.apache.maven.plugin.verifier.model.File file = (org.apache.maven.plugin.verifier.model.File) i.next();
+
+ printMessage( "File should not exist [" + file.getLocation() + "]" );
+ }
+ }
+
+ private void printContentFailures( VerificationResult results )
+ {
+ for ( Iterator i = results.getContentFailures().iterator(); i.hasNext(); )
+ {
+ org.apache.maven.plugin.verifier.model.File file = (org.apache.maven.plugin.verifier.model.File) i.next();
+
+ printMessage( "File [" + file.getLocation() + "] does not match regexp [" + file.getContains() + "]" );
+ }
+ }
+
+ private void printMessage( String message )
+ {
+ this.log.error( "[Verifier] " + message );
+ }
+}
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/ConsoleVerificationResultPrinter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/ConsoleVerificationResultPrinter.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResult.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResult.java?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResult.java (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResult.java Mon May 2 02:17:30 2005
@@ -0,0 +1,67 @@
+package org.apache.maven.plugin.verifier;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.plugin.verifier.model.File;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class VerificationResult
+{
+ private List existenceFailures = new ArrayList();
+
+ private List nonExistenceFailures = new ArrayList();
+
+ private List contentFailures = new ArrayList();
+
+ public void addExistenceFailure( File file )
+ {
+ existenceFailures.add( file );
+ }
+
+ public void addNonExistenceFailure( File file )
+ {
+ nonExistenceFailures.add( file );
+ }
+
+ public void addContentFailure( File file )
+ {
+ contentFailures.add( file );
+ }
+
+ public List getExistenceFailures()
+ {
+ return existenceFailures;
+ }
+
+ public List getNonExistenceFailures()
+ {
+ return nonExistenceFailures;
+ }
+
+ public List getContentFailures()
+ {
+ return contentFailures;
+ }
+
+ public boolean hasFailures()
+ {
+ return !getExistenceFailures().isEmpty() || !getNonExistenceFailures().isEmpty() ||
+ !getContentFailures().isEmpty();
+ }
+}
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResult.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResult.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResultPrinter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResultPrinter.java?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResultPrinter.java (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResultPrinter.java Mon May 2 02:17:30 2005
@@ -0,0 +1,22 @@
+package org.apache.maven.plugin.verifier;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public interface VerificationResultPrinter
+{
+ void print( VerificationResult result );
+}
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResultPrinter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerificationResultPrinter.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerifierMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerifierMojo.java?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerifierMojo.java (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerifierMojo.java Mon May 2 02:17:30 2005
@@ -0,0 +1,222 @@
+package org.apache.maven.plugin.verifier;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.verifier.model.Verifications;
+import org.apache.maven.plugin.verifier.model.io.xpp3.VerificationsXpp3Reader;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Verifies existence or non-existence of files/directories an optionally checks file content against a regexp.
+ *
+ * @goal verify
+ * @phase integration-test
+ *
+ * @author <a href="vmassol@apache.org">Vincent Massol</a>
+ * @version $Id$
+ */
+public class VerifierMojo
+ extends AbstractMojo
+{
+ /**
+ * @parameter expression="${basedir}"
+ * @required
+ */
+ private String basedir;
+
+ /**
+ * @parameter expression="${basedir}/src/test/verifier/verifications.xml"
+ * @required
+ */
+ private File verificationFile;
+
+ /**
+ * @required
+ */
+ private boolean failOnError = true;
+
+ private VerificationResultPrinter resultPrinter = new ConsoleVerificationResultPrinter( getLog() );
+
+ public void execute()
+ throws MojoExecutionException
+ {
+ VerificationResult results = verify();
+ this.resultPrinter.print( results );
+
+ // Fail the build if there are errors
+ if ( this.failOnError && results.hasFailures() )
+ {
+ throw new MojoExecutionException( "There are test failures" );
+ }
+ }
+
+ /**
+ * @param file the file path of the file to check (can be relative or absolute). If relative
+ * the project's basedir will be prefixed.
+ * @return the absolute file path of the file to check
+ */
+ protected File getAbsoluteFileToCheck( File file )
+ {
+ File result = file;
+ if ( !file.isAbsolute() )
+ {
+ result = new File( new File( this.basedir ), file.getPath() );
+ }
+ return result;
+ }
+
+ private VerificationResult verify()
+ throws MojoExecutionException
+ {
+ VerificationResult results = new VerificationResult();
+
+ Reader reader = null;
+ try
+ {
+ reader = new FileReader( this.verificationFile );
+
+ VerificationsXpp3Reader xppReader = new VerificationsXpp3Reader();
+ Verifications verifications = xppReader.read( reader );
+
+ for ( Iterator i = verifications.getFiles().iterator(); i.hasNext(); )
+ {
+ org.apache.maven.plugin.verifier.model.File file = (org.apache.maven.plugin.verifier.model.File) i.next();
+
+ // Transform the file to check into an absolute path prefixing the basedir if
+ // the location is relative
+ if ( file.getLocation() != null )
+ {
+ file.setLocation( getAbsoluteFileToCheck( new File( file.getLocation() ) ).getPath() );
+ verifyFile( file, results );
+ }
+ else
+ {
+ throw new MojoExecutionException( "Missing <location> element" );
+ }
+ }
+ }
+ catch ( org.codehaus.plexus.util.xml.pull.XmlPullParserException 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.plugin.verifier.model.File fileCheck, VerificationResult results )
+ throws IOException
+ {
+ boolean result;
+
+ result = verifyFileExistence( fileCheck, results );
+ if ( result && fileCheck.getContains() != null )
+ {
+ result = result && verifyFileContent( fileCheck, results );
+ }
+
+ return result;
+ }
+
+ private boolean verifyFileContent( org.apache.maven.plugin.verifier.model.File fileCheck,
+ VerificationResult results )
+ throws IOException
+ {
+ boolean result = false;
+
+ Pattern pattern = Pattern.compile( fileCheck.getContains() );
+
+ // Note: Very inefficient way as we load the whole file in memory. If you have a better
+ // idea, please submit it!
+ Matcher matcher = pattern.matcher( FileUtils.fileRead( new File( fileCheck.getLocation() ) ) );
+
+ if ( matcher.find() )
+ {
+ result = true;
+ }
+ else
+ {
+ results.addContentFailure( fileCheck );
+ }
+
+ return result;
+ }
+
+ private boolean verifyFileExistence( org.apache.maven.plugin.verifier.model.File fileCheck,
+ VerificationResult results )
+ {
+ boolean result = false;
+
+ File physicalFile = new File( fileCheck.getLocation() );
+ if ( fileCheck.isExists() )
+ {
+ result = physicalFile.exists();
+ if ( !result )
+ {
+ results.addExistenceFailure( fileCheck );
+ }
+ }
+ else
+ {
+ result = !physicalFile.exists();
+ if ( !result )
+ {
+ results.addNonExistenceFailure( fileCheck );
+ }
+ }
+
+ return result;
+ }
+
+ public void setBaseDir( String basedir )
+ {
+ this.basedir = basedir;
+ }
+
+ public void setVerificationFile( File file )
+ {
+ this.verificationFile = file;
+ }
+
+ public void setVerificationResultPrinter( VerificationResultPrinter printer )
+ {
+ this.resultPrinter = printer;
+ }
+
+ public void setFailOnError( boolean failOnError )
+ {
+ this.failOnError = failOnError;
+ }
+}
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerifierMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/java/org/apache/maven/plugin/verifier/VerifierMojo.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/mdo/verifications.mdo
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/mdo/verifications.mdo?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/mdo/verifications.mdo (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/main/mdo/verifications.mdo Mon May 2 02:17:30 2005
@@ -0,0 +1,65 @@
+<model>
+ <id>verifications</id>
+ <name>Verifications</name>
+ <description><![CDATA[
+ Project-specific configuration file for the Verifier plugin. It contains
+ definition of expected files and directories to be checked for after an
+ integration test has run. It can also check for file content against
+ regexps.]]></description>
+ <defaults>
+ <default>
+ <key>package</key>
+ <value>org.apache.maven.plugin.verifier.model</value>
+ </default>
+ </defaults>
+ <classes>
+ <class rootElement="true" xml.tagName="verifications">
+ <name>Verifications</name>
+ <version>1.0.0</version>
+ <description>Root element of the project verification file.</description>
+ <fields>
+ <field>
+ <name>files</name>
+ <version>1.0.0</version>
+ <description><![CDATA[
+ List of files and directories to check for.
+ ]]></description>
+ <association>
+ <type>File</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <name>File</name>
+ <version>1.0.0</version>
+ <fields>
+ <field>
+ <name>location</name>
+ <version>1.0.0</version>
+ <required>true</required>
+ <description><![CDATA[Location of the file or directory to check.]]></description>
+ <type>String</type>
+ </field>
+ <field>
+ <name>contains</name>
+ <version>1.0.0</version>
+ <description><![CDATA[Check the content against this regexp.]]></description>
+ <required>false</required>
+ <type>String</type>
+ </field>
+ <field>
+ <name>exists</name>
+ <version>1.0.0</version>
+ <description><![CDATA[
+ If true checks for file or directory existence, otherwise checks that the
+ file or directory doesn't exist.
+ ]]></description>
+ <defaultValue>true</defaultValue>
+ <type>boolean</type>
+ </field>
+ </fields>
+ </class>
+ </classes>
+</model>
\ No newline at end of file
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/plugin/verifier/VerifierMojoTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/plugin/verifier/VerifierMojoTest.java?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/plugin/verifier/VerifierMojoTest.java (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/plugin/verifier/VerifierMojoTest.java Mon May 2 02:17:30 2005
@@ -0,0 +1,198 @@
+package org.apache.maven.plugin.verifier;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import junit.framework.TestCase;
+
+import java.io.File;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+public class VerifierMojoTest
+ extends TestCase
+{
+ public void testPrefixWithBaseDir()
+ {
+ VerifierMojo mojo = new VerifierMojo();
+ mojo.setBaseDir( "c:/some/path" );
+
+ File result = mojo.getAbsoluteFileToCheck( new File( "target/dummy.txt" ) );
+
+ File expectedResult = new File( "c:/some/path/target/dummy.txt" );
+ assertEquals( expectedResult.getPath(), result.getPath() );
+ }
+
+ public void testDoNotPrefixWhenAbsolutePath()
+ {
+ VerifierMojo mojo = new VerifierMojo();
+ mojo.setBaseDir( "c:/some/path" );
+
+ File result = mojo.getAbsoluteFileToCheck( new File( "c:/project/target/dummy.txt" ) );
+
+ File expectedResult = new File( "c:/project/target/dummy.txt" );
+ assertEquals( expectedResult.getPath(), result.getPath() );
+ }
+
+ public void testCheckFileThatDoesNotExist()
+ throws Exception
+ {
+ VerifierMojo mojo = new VerifierMojo();
+ File file = new File( getClass().getResource( "/FileDoesNotExist.xml" ).getFile() );
+ mojo.setBaseDir( "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() );
+ }
+ } );
+
+ try
+ {
+ mojo.execute();
+ fail( "Should have thrown an exception" );
+ }
+ catch ( MojoExecutionException expected )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testCheckFileThatExists()
+ throws Exception
+ {
+ VerifierMojo mojo = new VerifierMojo();
+ File file = new File( getClass().getResource( "/FileExists.xml" ).getFile() );
+ mojo.setBaseDir( file.getParent() );
+ 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.execute();
+ }
+
+ public void testCheckForInexistentFile()
+ throws Exception
+ {
+ VerifierMojo mojo = new VerifierMojo();
+ File file = new File( getClass().getResource( "/InexistentFile.xml" ).getFile() );
+ mojo.setBaseDir( "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.execute();
+ }
+
+ public void testCheckForInexistentFileThatExists()
+ throws Exception
+ {
+ VerifierMojo mojo = new VerifierMojo();
+ File file = new File( getClass().getResource( "/InexistentFileThatExists.xml" ).getFile() );
+ mojo.setBaseDir( file.getParent() );
+ mojo.setVerificationFile( file );
+ mojo.setFailOnError( true );
+ mojo.setVerificationResultPrinter( new VerificationResultPrinter()
+ {
+ public void print( VerificationResult result )
+ {
+ assertEquals( 0, result.getExistenceFailures().size() );
+ assertEquals( 1, result.getNonExistenceFailures().size() );
+ assertEquals( 0, result.getContentFailures().size() );
+ }
+ } );
+
+ try
+ {
+ mojo.execute();
+ fail( "Should have thrown an exception" );
+ }
+ catch ( MojoExecutionException expected )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testCheckFileForContent()
+ throws Exception
+ {
+ VerifierMojo mojo = new VerifierMojo();
+ File file = new File( getClass().getResource( "/FileExistsValidContent.xml" ).getFile() );
+ mojo.setBaseDir( file.getParent() );
+ 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.execute();
+ }
+
+ public void testCheckFileForInvalidContent()
+ throws Exception
+ {
+ VerifierMojo mojo = new VerifierMojo();
+ File file = new File( getClass().getResource( "/FileExistsInvalidContent.xml" ).getFile() );
+ mojo.setBaseDir( file.getParent() );
+ 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() );
+ }
+ } );
+
+ try
+ {
+ mojo.execute();
+ fail( "Should have thrown an exception" );
+ }
+ catch ( MojoExecutionException expected )
+ {
+ assertTrue( true );
+ }
+ }
+
+}
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/plugin/verifier/VerifierMojoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/java/org/apache/maven/plugin/verifier/VerifierMojoTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileDoesNotExist.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileDoesNotExist.xml?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileDoesNotExist.xml (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileDoesNotExist.xml Mon May 2 02:17:30 2005
@@ -0,0 +1,7 @@
+<verifications>
+ <files>
+ <file>
+ <location>src/test/resources/Dummy.xml</location>
+ </file>
+ </files>
+</verifications>
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileDoesNotExist.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileDoesNotExist.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExists.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExists.xml?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExists.xml (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExists.xml Mon May 2 02:17:30 2005
@@ -0,0 +1,7 @@
+<verifications>
+ <files>
+ <file>
+ <location>FileExists.xml</location>
+ </file>
+ </files>
+</verifications>
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExists.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExists.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsInvalidContent.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsInvalidContent.xml?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsInvalidContent.xml (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsInvalidContent.xml Mon May 2 02:17:30 2005
@@ -0,0 +1,8 @@
+<verifications>
+ <files>
+ <file>
+ <location>FileExistsValidContent.xml</location>
+ <contains><![CDATA[something]]></contains>
+ </file>
+ </files>
+</verifications>
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsInvalidContent.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsInvalidContent.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsValidContent.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsValidContent.xml?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsValidContent.xml (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsValidContent.xml Mon May 2 02:17:30 2005
@@ -0,0 +1,8 @@
+<verifications>
+ <files>
+ <file>
+ <location>FileExistsValidContent.xml</location>
+ <contains><![CDATA[location>FileExists]]></contains>
+ </file>
+ </files>
+</verifications>
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsValidContent.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/FileExistsValidContent.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFile.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFile.xml?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFile.xml (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFile.xml Mon May 2 02:17:30 2005
@@ -0,0 +1,8 @@
+<verifications>
+ <files>
+ <file>
+ <location>src/test/resources/Dummy.xml</location>
+ <exists>false</exists>
+ </file>
+ </files>
+</verifications>
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFile.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFile.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFileThatExists.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFileThatExists.xml?rev=165612&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFileThatExists.xml (added)
+++ maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFileThatExists.xml Mon May 2 02:17:30 2005
@@ -0,0 +1,8 @@
+<verifications>
+ <files>
+ <file>
+ <location>InexistentFileThatExists.xml</location>
+ <exists>false</exists>
+ </file>
+ </files>
+</verifications>
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFileThatExists.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-plugins/maven-verifier-plugin/src/test/resources/InexistentFileThatExists.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/components/trunk/maven-plugins/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/pom.xml?rev=165612&r1=165611&r2=165612&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/pom.xml (original)
+++ maven/components/trunk/maven-plugins/pom.xml Mon May 2 02:17:30 2005
@@ -67,9 +67,7 @@
</repository>
</distributionManagement>
<modules>
-<!--
<module>maven-assembly-plugin</module>
--->
<module>maven-clean-plugin</module>
<module>maven-compiler-plugin</module>
<module>maven-deploy-plugin</module>
@@ -82,6 +80,7 @@
<module>maven-site-plugin</module>
<module>maven-surefire-plugin</module>
<module>maven-war-plugin</module>
+ <module>maven-verifier-plugin</module>
</modules>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins</connection>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org