dion 02/05/12 06:41:07
Modified: xdocs/ref/j2ee build-file.xml
src/java/org/apache/maven/j2ee ValidationListener.java
WarValidator.java ValidationEvent.java
src/templates/build build.xml Control-j2ee.vm build-j2ee.xml
Added: src/java/org/apache/maven/j2ee ValidationBroadcaster.java
ValidationFormatter.java
Log:
no message
Revision Changes Path
1.3 +18 -0 jakarta-turbine-maven/xdocs/ref/j2ee/build-file.xml
Index: build-file.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/xdocs/ref/j2ee/build-file.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- build-file.xml 9 May 2002 17:40:04 -0000 1.2
+++ build-file.xml 12 May 2002 13:41:06 -0000 1.3
@@ -67,6 +67,10 @@
<td>Creates a <code>WAR</code> file.</td>
</tr>
<tr>
+ <td><a href="#maven:validate-war">maven:validate-war</a></td>
+ <td>Validate a <code>WAR</code> file.</td>
+ </tr>
+ <tr>
<td><a href="#maven:ear">maven:ear</a></td>
<td>Creates an <code>EAR</code> file.</td>
</tr>
@@ -131,6 +135,20 @@
</td>
</tr>
</table>
+ </subsection>
+ <subsection name="maven:validate-war">
+ <p>
+ The <code>maven:validate-war</code>code> target validates the newly
+ produced war file.
+ </p>
+ <p>
+ Currently the validator only checks the folowing:
+ <ol>
+ <li>The war file exists</li>
+ <li>It is readable</li>
+ <li>It contains a WEB-INF/web.xml deployment descriptor</li>
+ </ol>
+ </p>
</subsection>
<subsection name="maven:ear">
<p>
1.2 +9 -2
jakarta-turbine-maven/src/java/org/apache/maven/j2ee/ValidationListener.java
Index: ValidationListener.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/j2ee/ValidationListener.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ValidationListener.java 11 May 2002 15:46:44 -0000 1.1
+++ ValidationListener.java 12 May 2002 13:41:06 -0000 1.2
@@ -60,7 +60,7 @@
* An interface implemented by those who want to receive validation events
* from a J2EE Validator (WAR, EAR etc).
*
- * @version $Id: ValidationListener.java,v 1.1 2002/05/11 15:46:44 dion Exp $
+ * @version $Id: ValidationListener.java,v 1.2 2002/05/12 13:41:06 dion Exp $
* @author dion
*/
public interface ValidationListener extends EventListener {
@@ -73,11 +73,18 @@
/**
* Called when a validation error occurs. That is, the subject being
- * validated has a serious problem
+ * validated has a serious (fatal) problem
* @param event a {@link ValidationEvent}
*/
void validationError(ValidationEvent event);
-
+
+ /**
+ * Called when a validation warning occurs. That is, the subject being
+ * validated has a problem which may not be fatal
+ * @param event a {@link ValidationEvent}
+ */
+ void validationWarning(ValidationEvent event);
+
/**
* Called when validation ends
* @param event a {@link ValidationEvent}
1.3 +87 -23
jakarta-turbine-maven/src/java/org/apache/maven/j2ee/WarValidator.java
Index: WarValidator.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/j2ee/WarValidator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WarValidator.java 11 May 2002 16:28:35 -0000 1.2
+++ WarValidator.java 12 May 2002 13:41:06 -0000 1.3
@@ -55,8 +55,12 @@
*/
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
import org.apache.maven.executor.ProjectExecutor;
@@ -72,8 +76,8 @@
/** name of the war file to be validated */
private String warFileName = null;
-
- private List listeners = new ArrayList();
+ /** broadcaster to help with events */
+ private ValidationBroadcaster broadcaster = new ValidationBroadcaster();
//--- Constructors ---------------------------------------------------------
/** Creates a new instance of WarValidator */
@@ -82,22 +86,14 @@
}
//--- Methods --------------------------------------------------------------
- /** Getter for property listeners.
- * @return Value of property listeners.
+ /** Setter for property broadcaster.
+ * @param broadcaster New value of property broadcaster.
*/
- private List getListeners()
+ private void setBroadcaster(ValidationBroadcaster broadcaster)
{
- return listeners;
+ this.broadcaster = broadcaster;
}
- /** Setter for property listeners.
- * @param listeners New value of property listeners.
- */
- private void setListeners(List listeners)
- {
- this.listeners = listeners;
- }
-
/**
* Perform the validation.
*/
@@ -107,17 +103,55 @@
{
throw new NullPointerException("war file name should not be null");
}
+ validate();
+ }
+
+ /**
+ * validate the provided war file
+ * @param warFile an existing file
+ */
+ public void validate()
+ {
+ File warFile = null;
+ try
+ {
+ getBroadcaster().fireStartedEvent( new ValidationEvent(this,
+ getWarFileName(), "started"));
- File warFile = new File(getWarFileName());
- if (!warFile.exists())
+ warFile = new File(getWarFileName());
+
+ if (!warFile.exists())
+ {
+ getBroadcaster().fireErrorEvent(new ValidationEvent(this, warFile,
+ "File does not exist"));
+ return;
+ }
+ if (!warFile.canRead())
+ {
+ getBroadcaster().fireErrorEvent(new ValidationEvent(this, warFile,
+ "File does not exist"));
+ return;
+ }
+
+ JarFile jarFile = new JarFile(warFile);
+ // validate structure - at the moment just web.xml
+ JarEntry webxmlEntry = jarFile.getJarEntry("WEB-INF/web.xml");
+ if (webxmlEntry == null)
+ {
+ getBroadcaster().fireWarningEvent(new ValidationEvent(this,
+ jarFile, "WEB-INF/web.xml entry not found"));
+ }
+
+ }
+ catch (IOException ioe)
{
- throw new IllegalArgumentException("War file: '" + warFile +
- "' does not exist");
+ getBroadcaster().fireErrorEvent(new ValidationEvent(this,
+ getWarFileName(), "Error opening war file"));
}
- if (!warFile.canRead())
+ finally
{
- throw new IllegalArgumentException("War file: '" + warFile +
- "' is not readable");
+ getBroadcaster().fireEndedEvent( new ValidationEvent(this,
+ getWarFileName(), "ended"));
}
}
@@ -127,7 +161,7 @@
*/
public void addValidationListener(ValidationListener listener)
{
- getListeners().add(listener);
+ getBroadcaster().addValidationListener(listener);
}
/**
@@ -136,7 +170,7 @@
*/
public void removeValidationListener(ValidationListener listener)
{
- getListeners().remove(listener);
+ getBroadcaster().removeValidationListener(listener);
}
/** Getter for property warFileName.
@@ -154,4 +188,34 @@
{
this.warFileName = warFileName;
}
+
+ /** Getter for property broadcaster.
+ * @return Value of property broadcaster.
+ */
+ private ValidationBroadcaster getBroadcaster()
+ {
+ return broadcaster;
+ }
+
+ /** add a formatter to pick up events and display the output.
+ * Used by ant when a nested formatter element is present.
+ * @param formatter a class to format validation events
+ */
+ public void addFormatter(ValidationFormatter formatter)
+ {
+ addValidationListener((ValidationListener)formatter);
+ }
+
+ /** provide a string representation of the validator
+ * @return "WarValidator(file)"
+ */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer("WarValidator");
+ if (getWarFileName() != null)
+ {
+ buffer.append("(").append(getWarFileName()).append(")");
+ }
+ return buffer.toString();
+ }
}
1.2 +11 -2
jakarta-turbine-maven/src/java/org/apache/maven/j2ee/ValidationEvent.java
Index: ValidationEvent.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/j2ee/ValidationEvent.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ValidationEvent.java 11 May 2002 15:46:44 -0000 1.1
+++ ValidationEvent.java 12 May 2002 13:41:06 -0000 1.2
@@ -59,7 +59,7 @@
/**
* A class that holds details about the validation
*
- * @version $Id: ValidationEvent.java,v 1.1 2002/05/11 15:46:44 dion Exp $
+ * @version $Id: ValidationEvent.java,v 1.2 2002/05/12 13:41:06 dion Exp $
* @author dion
*/
public class ValidationEvent extends EventObject {
@@ -74,9 +74,18 @@
* @param source the source of the event, some validator.
*/
public ValidationEvent(Object source) {
+ this(source, null, null);
+ }
+
+ /** Creates a new instance of ValidationEvent.
+ * @param source the source of the event, some validator.
+ */
+ public ValidationEvent(Object source, Object subject, String message) {
super(source);
+ setSubject(subject);
+ setMessage(message);
}
-
+
/** Getter for property message.
* @return Value of property message.
*/
1.1
jakarta-turbine-maven/src/java/org/apache/maven/j2ee/ValidationBroadcaster.java
Index: ValidationBroadcaster.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
*
* @version $Id: ValidationBroadcaster.java,v 1.1 2002/05/12 13:41:06 dion Exp $
* @author dion
*/
public class ValidationBroadcaster
{
/** {@link ValidationListeners} handled by this broadcaster */
private List listeners = new ArrayList();
/** Creates a new instance of ValidationBroadcaster */
public ValidationBroadcaster()
{
}
/**
* fire a {@link ValidationListener#validationStarted(ValidationEvent)
* started} event.
* @param event the event to broadcast
*/
public void fireStartedEvent(ValidationEvent event)
{
for(Iterator listeners = getListeners().iterator(); listeners.hasNext(); )
{
((ValidationListener)listeners.next()).validationStarted(event);
}
}
/**
* fire an {@link ValidationListener#validationEnded(ValidationEvent)
* ended} event.
* @param event the event to broadcast
*/
public void fireEndedEvent(ValidationEvent event)
{
for(Iterator listeners = getListeners().iterator(); listeners.hasNext(); )
{
((ValidationListener)listeners.next()).validationEnded(event);
}
}
/**
* fire an {@link ValidationListener#validationError(ValidationEvent)
* error} event.
* @param event the event to broadcast
*/
public void fireErrorEvent(ValidationEvent event)
{
for(Iterator listeners = getListeners().iterator(); listeners.hasNext(); )
{
((ValidationListener)listeners.next()).validationError(event);
}
}
/**
* fire a {@link ValidationListener#validationWarning(ValidationEvent)
* warning} event.
* @param event the event to broadcast
*/
public void fireWarningEvent(ValidationEvent event)
{
for(Iterator listeners = getListeners().iterator(); listeners.hasNext(); )
{
((ValidationListener)listeners.next()).validationWarning(event);
}
}
/** Getter for property listeners.
* @return Value of property listeners.
*/
private List getListeners()
{
return listeners;
}
/** Setter for property listeners.
* @param listeners New value of property listeners.
*/
private void setListeners(List listeners)
{
this.listeners = listeners;
}
/**
* add a listener to the list to be notified
* @param listener a {@link ValidationListener}
*/
public void addValidationListener(ValidationListener listener)
{
getListeners().add(listener);
}
/**
* remove a listener from the list to be notified
* @param listener a {@link ValidationListener}
*/
public void removeValidationListener(ValidationListener listener)
{
getListeners().remove(listener);
}
}
1.1
jakarta-turbine-maven/src/java/org/apache/maven/j2ee/ValidationFormatter.java
Index: ValidationFormatter.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
/**
* Base class for formatters of validation events - handles plain and xml
* formats.
* @version $Id: ValidationFormatter.java,v 1.1 2002/05/12 13:41:06 dion Exp $
* @author dion
*/
public class ValidationFormatter implements ValidationListener
{
/** Whether the formatter should write it's results to a file */
private boolean usefile;
/** name of the file (if usefile is true) to send output to */
private String file;
/** type of output: plain/xml */
private String type = ValidationFormatter.PLAIN;
/** Plain format output */
public static final String PLAIN = "plain";
/** xml format output */
public static final String XML = "xml";
/** output destination */
private PrintStream stream = null;
// --- Constructors --------------------------------------------------------
/** Creates a new instance of ValidationFormatter */
public ValidationFormatter()
{
stream = System.out;
}
// --- Methods -------------------------------------------------------------
/** Test whether the formatter is in plain mode.
* @return true if {@link #type} is set to {@link PLAIN}
*/
private boolean isPlain()
{
return ValidationFormatter.PLAIN.equals(getType());
}
/** print an event in xml format
* @param event the event to print
* @param eventName started/ended/error etc
*/
private void printEventAsXML(ValidationEvent event, String eventName)
{
getStream().println("\t<" + eventName + ">");
getStream().println("\t\t<source>");
getStream().println("\t\t\t"+event.getSource());
getStream().println("\t\t</source>");
getStream().println("\t\t<subject>");
getStream().println("\t\t\t"+event.getSubject());
getStream().println("\t\t</subject>");
getStream().println("\t\t<message>");
getStream().println("\t\t\t"+event.getMessage());
getStream().println("\t\t</message>");
getStream().println("\t</" + eventName + ">");
}
/** print an event in plain format
* @param event the event to print
*/
private void printEvent(ValidationEvent event)
{
getStream().println(event.getSubject() + ": " + event.getMessage());
}
/**
* Called when validation ends
* @param event a {@link ValidationEvent}
*/
public void validationEnded(ValidationEvent event)
{
if (isPlain())
{
printEvent(event);
}
else
{
printEventAsXML(event, "ended");
getStream().println("</validation-report>");
}
}
/** Called when a validation error occurs. That is, the subject being
* validated has a serious (fatal) problem
* @param event a {@link ValidationEvent}
*/
public void validationError(ValidationEvent event)
{
if (isPlain())
{
printEvent(event);
}
else
{
printEventAsXML(event, "error");
}
}
/**
* Called when validation starts
* @param event a {@link ValidationEvent}
*/
public void validationStarted(ValidationEvent event)
{
if (isPlain())
{
printEvent(event);
}
else
{
getStream().println("<?xml version=\"1.0\" ?>");
getStream().println("<validation-report>");
printEventAsXML(event, "started");
}
}
/** Called when a validation warning occurs. That is, the subject being
* validated has a problem which may not be fatal
* @param event a {@link ValidationEvent}
*/
public void validationWarning(ValidationEvent event)
{
if (isPlain())
{
printEvent(event);
}
else
{
printEventAsXML(event, "warning");
}
}
/** Getter for property file.
* @return Value of property file.
*/
public String getFile()
{
return file;
}
/** Setter for property file.
* @param file New value of property file.
*/
public void setFile(String file) throws FileNotFoundException
{
this.file = file;
FileOutputStream fos = new FileOutputStream(file);
stream = new PrintStream(fos);
}
/** Getter for property usefile.
* @return Value of property usefile.
*/
public boolean isUsefile()
{
return usefile;
}
/** Setter for property usefile.
* @param usefile New value of property usefile.
*/
public void setUsefile(boolean usefile)
{
this.usefile = usefile;
}
/** Getter for property stream.
* @return Value of property stream.
*/
public PrintStream getStream() {
return stream;
}
/** Setter for property stream.
* @param stream New value of property stream.
*/
public void setStream(PrintStream stream) {
this.stream = stream;
}
/** Getter for property type.
* @return Value of property type.
*/
public String getType() {
return type;
}
/** Setter for property type.
* @param type New value of property type.
*/
public void setType(String type) {
this.type = type;
}
}
1.38 +5 -0 jakarta-turbine-maven/src/templates/build/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/templates/build/build.xml,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- build.xml 10 May 2002 03:23:13 -0000 1.37
+++ build.xml 12 May 2002 13:41:07 -0000 1.38
@@ -154,6 +154,11 @@
</target>
<target
+ name="maven:validate-war">
+ <ant antfile="$mavenDirectory/build-j2ee.xml" target="validate-war"/>
+ </target>
+
+ <target
name="maven:ear">
<ant antfile="$mavenDirectory/build-j2ee.xml" target="ear"/>
</target>
1.4 +1 -0 jakarta-turbine-maven/src/templates/build/Control-j2ee.vm
Index: Control-j2ee.vm
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/templates/build/Control-j2ee.vm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Control-j2ee.vm 5 May 2002 11:47:39 -0000 1.3
+++ Control-j2ee.vm 12 May 2002 13:41:07 -0000 1.4
@@ -12,6 +12,7 @@
## Make the list of build-j2ee.xml delegators
## -------------------------------------------------------
$delegators.put("war","build-j2ee.xml")
+$delegators.put("validate-war","build-j2ee.xml")
$delegators.put("ear","build-j2ee.xml")
1.10 +16 -0 jakarta-turbine-maven/src/templates/build/build-j2ee.xml
Index: build-j2ee.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/templates/build/build-j2ee.xml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- build-j2ee.xml 7 May 2002 17:17:16 -0000 1.9
+++ build-j2ee.xml 12 May 2002 13:41:07 -0000 1.10
@@ -105,6 +105,22 @@
</war>
</target>
+ <target name="validate-war" depends="local-init">
+ <taskdef
+ name="warvalidator"
+ classname="org.apache.maven.j2ee.WarValidator">
+ <classpath refid="maven-classpath"/>
+ <classpath refid="maven.dependency.classpath"/>
+ </taskdef>
+
+ <warvalidator
+ warFileName="${maven.build.dir}/${maven.j2ee.war.name}.war"
+ projectDescriptor="project.xml">
+ <formatter type="plain" usefile="false"/>
+ </warvalidator>
+
+ </target>
+
<!--
EAR processing
-->
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>