dion 02/05/21 23:35:03
Modified: src/java/org/apache/maven/j2ee WarValidator.java
Log:
- refactor out commonly used code
- make class validation available to subclasses
Revision Changes Path
1.22 +54 -48
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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- WarValidator.java 21 May 2002 00:35:10 -0000 1.21
+++ WarValidator.java 22 May 2002 06:35:03 -0000 1.22
@@ -83,7 +83,7 @@
* ></code> element must exist in the war file</li>
* </ol>
* @author dIon Gillard
- * @version $Id: WarValidator.java,v 1.21 2002/05/21 00:35:10 dion Exp $
+ * @version $Id: WarValidator.java,v 1.22 2002/05/22 06:35:03 dion Exp $
*/
public class WarValidator extends AbstractExecutor
{
@@ -158,6 +158,7 @@
try
{
startValidation();
+ validateFile();
if (!getStatus().isError())
{
validateWarContents();
@@ -165,8 +166,7 @@
}
finally
{
- getBroadcaster().fireEndedEvent(new ValidationEvent(this,
- getWarFileName(), "war validation ended"));
+ endValidation();
}
}
@@ -177,7 +177,6 @@
{
getBroadcaster().fireStartedEvent(new ValidationEvent(this,
getWarFileName(), "war validation started"));
- validateFile();
}
/** Hook point for subclasses to add validations
@@ -203,14 +202,12 @@
if (!warFile.exists())
{
- getBroadcaster().fireErrorEvent(new ValidationEvent(this,
- getWarFileName(), "File does not exist"));
+ error("File does not exist");
return;
}
if (!warFile.canRead())
{
- getBroadcaster().fireErrorEvent(new ValidationEvent(this,
- getWarFileName(), "File can't be read"));
+ error("File can't be read");
return;
}
}
@@ -225,8 +222,7 @@
war = new WarFile(getWarFileName());
if (war.getWebXmlEntry() == null)
{
- getBroadcaster().fireWarningEvent(new ValidationEvent(this,
- getWarFileName(), "web.xml entry not found"));
+ warning("web.xml entry not found");
return;
}
validateServlets(war);
@@ -238,9 +234,8 @@
catch (IOException ioe)
{
ioe.printStackTrace();
- getBroadcaster().fireErrorEvent(new ValidationEvent(this,
- getWarFileName(), "Error opening war file for web.xml - " +
- "possibly missing manifest"));
+ error("Error opening war file for web.xml - possibly missing " +
+ "manifest");
}
}
@@ -265,9 +260,8 @@
{
entry = (Map.Entry) entries.next();
className = (String) entry.getValue();
- getBroadcaster().fireInformationEvent(new ValidationEvent(this,
- getWarFileName(), "validating servlet name: " +
- entry.getKey() + " class: " + className));
+ info("validating servlet name: " + entry.getKey() + " class: "
+ + className);
// check each servlet by loading the class
validateClass(className, classLoader);
}
@@ -292,15 +286,12 @@
{
entry = (Map.Entry) entries.next();
String jspFile = (String) entry.getValue();
- getBroadcaster().fireInformationEvent(new ValidationEvent(this,
- getWarFileName(), "validating servlet name: " +
- entry.getKey() + " jsp file: " + jspFile));
+ info("validating servlet name: " + entry.getKey() +
+ " jsp file: " + jspFile);
if (!war.hasFile(jspFile))
{
- getBroadcaster().fireErrorEvent(new ValidationEvent(this,
- getWarFileName(), "JSP File: '" + jspFile +
- "' not found"));
+ error("JSP File: '" + jspFile + "' not found");
}
}
}
@@ -311,7 +302,7 @@
* @param className the name of a class to attempt loading
* @param loader a {@link ClassLoader class loader}
*/
- private void validateClass(String className, ClassLoader loader)
+ protected void validateClass(String className, ClassLoader loader)
{
try
{
@@ -319,21 +310,18 @@
if (clazz.getClassLoader() != loader)
{
// loaded from classpath - a no no.
- getBroadcaster().fireErrorEvent(new ValidationEvent(this,
- getWarFileName(), "class (" + className + ") loaded from " +
- "system classpath rather than war file"));
+ error("class (" + className + ") loaded from system classpath "
+ + "rather than war file");
}
}
catch (ClassNotFoundException e)
{
- getBroadcaster().fireErrorEvent(new ValidationEvent(this,
- getWarFileName(), "class (" + className + ") not found "));
+ error("class (" + className + ") not found ");
}
catch (NoClassDefFoundError error)
{
- getBroadcaster().fireErrorEvent(new ValidationEvent(this,
- getWarFileName(), "class (" + className + ") was found, but a "
- + "referenced class was missing: " + error.getMessage()));
+ error("class (" + className + ") was found, but a referenced class "
+ + "was missing: " + error.getMessage());
}
}
@@ -357,13 +345,10 @@
entry = (Map.Entry) entries.next();
String uri = (String) entry.getKey();
String location = (String)entry.getValue();
- getBroadcaster().fireInformationEvent(new ValidationEvent(this,
- getWarFileName(), "validating taglib uri: " + uri));
+ info("validating taglib uri: " + uri);
if (!war.hasFile(location))
{
- getBroadcaster().fireErrorEvent(new ValidationEvent(this,
- getWarFileName(), "Taglib location: '" + location +
- "' not found"));
+ error("Taglib location: '" + location + "' not found");
}
}
}
@@ -388,14 +373,10 @@
entry = (Map.Entry) entries.next();
String errorQualifier = (String) entry.getKey();
String location = (String) entry.getValue();
- getBroadcaster().fireInformationEvent(new ValidationEvent(this,
- getWarFileName(), "validating error page for: " +
- errorQualifier));
+ info("validating error page for: " + errorQualifier);
if (!war.hasFile(location))
{
- getBroadcaster().fireErrorEvent(new ValidationEvent(this,
- getWarFileName(), "Error page location: '" + location +
- "' not found"));
+ error("Error page location: '" + location + "' not found");
}
}
}
@@ -413,15 +394,13 @@
{
if (!war.hasFile(config.getLoginPage()))
{
- getBroadcaster().fireErrorEvent(new ValidationEvent(this,
- getWarFileName(), "<form-config-login> login-page location:"
- + " '" + config.getLoginPage() + "' not found"));
+ info("<form-config-login> login-page location: '"
+ + config.getLoginPage() + "' not found");
}
if (!war.hasFile(config.getErrorPage()))
{
- getBroadcaster().fireErrorEvent(new ValidationEvent(this,
- getWarFileName(), "<form-config-login> error-page location:"
- + " '" + config.getErrorPage() + "' not found"));
+ error("<form-config-login> error-page location: '" +
+ config.getErrorPage() + "' not found");
}
}
}
@@ -506,4 +485,31 @@
this.failOnError = failOnError;
}
+ /** Helper method to fire an information message using the broadcaster
+ * @param message to be fired
+ */
+ protected void info(String message)
+ {
+ getBroadcaster().fireInformationEvent(new ValidationEvent(this,
+ getWarFileName(), message));
+ }
+
+ /** Helper method to fire an error message using the broadcaster
+ * @param message to be fired
+ */
+ protected void error(String message)
+ {
+ getBroadcaster().fireErrorEvent(new ValidationEvent(this,
+ getWarFileName(), message));
+ }
+
+ /** Helper method to fire a warning message using the broadcaster
+ * @param message to be fired
+ */
+ protected void warning(String message)
+ {
+ getBroadcaster().fireWarningEvent(new ValidationEvent(this,
+ getWarFileName(), message));
+ }
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>