dion 02/05/14 21:36:54
Modified: src/java/org/apache/maven/j2ee WarValidator.java
Log:
Added a status listener automatically to the validation.
At the end of validation, if there has been an error, a BuildException is thrown.
Revision Changes Path
1.7 +64 -12
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WarValidator.java 15 May 2002 00:05:54 -0000 1.6
+++ WarValidator.java 15 May 2002 04:36:53 -0000 1.7
@@ -60,10 +60,14 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipException;
+import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
-import org.apache.maven.executor.ProjectExecutor;
+import org.apache.tools.ant.BuildException;
+import org.apache.maven.executor.AbstractExecutor;
import org.dom4j.Document;
import org.dom4j.DocumentException;
@@ -77,18 +81,21 @@
* </ol>
* @author dIon Gillard
*/
-public class WarValidator extends ProjectExecutor
+public class WarValidator extends AbstractExecutor
{
/** name of the war file to be validated */
private String warFileName = null;
/** broadcaster to help with events */
private ValidationBroadcaster broadcaster = new ValidationBroadcaster();
+ /** status listener to keep track of errors etc */
+ private ValidationStatusListener status = new ValidationStatusListener();
//--- Constructors ---------------------------------------------------------
/** Creates a new instance of WarValidator */
public WarValidator()
{
+ addValidationListener(getStatus());
}
//--- Methods --------------------------------------------------------------
@@ -100,16 +107,38 @@
this.broadcaster = broadcaster;
}
+ /** Provides access to the status listener that is automatically attached
+ * to the validation
+ * @return Value of property status.
+ */
+ public ValidationStatusListener getStatus()
+ {
+ return status;
+ }
+
+ /** Changes the status listener that is associated with this validator
+ * @param status New value of property status.
+ */
+ private void setStatus(ValidationStatusListener status)
+ {
+ this.status = status;
+ }
+
/**
* Perform the validation.
*/
- public void doExecute()
+ public void execute() throws Exception
{
if (getWarFileName() == null)
{
throw new NullPointerException("war file name should not be null");
}
validate();
+ if (getStatus().isError())
+ {
+ throw new BuildException("Errors occurred during validation. "+
+ "Messages should have been provided");
+ }
}
/**
@@ -175,16 +204,16 @@
InputStream webXmlStream = jarFile.getInputStream(webXmlEntry);
SAXReader xmlReader = new SAXReader(false);
Document webXmlDoc = xmlReader.read(webXmlStream);
- List servletNodes = webXmlDoc.selectNodes("//servlet");
- Node node = null;
- for (Iterator nodes = servletNodes.iterator(); nodes.hasNext();)
+ // collect list of servlets
+ Map servlets = getServlets(webXmlDoc);
+ // check that there are servlets
+ if (servlets.size() != 0)
{
- node = (Node) nodes.next();
- String servletName =
node.selectSingleNode("./servlet-name").getText();
- String servletClass =
node.selectSingleNode("./servlet-class").getText();
- System.out.println("Servlet Name: " + servletName +
- ", class: " + servletClass);
- // check class (jarFile, servletClass)
+ // expand jar file WEB-INF/lib/*.jar to temp files
+
+ // create a URL classloader from temp files + WEB-INF/classes
+ // check each servlet by loadClass
+ // make sure class.classLoader == url classloader
}
}
catch (DocumentException de)
@@ -209,6 +238,28 @@
}
/**
+ * Get the servlets from web.xml.
+ *
+ * @param webXml a web.xml as a dom4j document
+ * @return a map containing servlet name -> servlet class for all servlets
+ * in the web.xml provided
+ */
+ private Map getServlets(Document webXml)
+ {
+ List servletNodes = webXml.selectNodes("//servlet");
+ Node node = null;
+ Map servlets = new HashMap();
+ for (Iterator nodes = servletNodes.iterator(); nodes.hasNext();)
+ {
+ node = (Node) nodes.next();
+ String servletName = node.selectSingleNode("./servlet-name").getText();
+ String servletClass =
node.selectSingleNode("./servlet-class").getText();
+ servlets.put(servletName, servletClass);
+ }
+ return servlets;
+ }
+
+ /**
* add a listener to the list to be notified
* @param listener a {@link ValidationListener}
*/
@@ -271,4 +322,5 @@
}
return buffer.toString();
}
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>