[jboss-svn-commits] JBL Code SVN: r13248 - in labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src: main/java/org/jboss/maven/plugins/test/ext and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jul 8 21:12:55 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-07-08 21:12:55 -0400 (Sun, 08 Jul 2007)
New Revision: 13248
Added:
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/AttributeValueExtracter.java
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/DocumentLoader.java
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/ElementValueExtracter.java
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/Extracter.java
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/ExtracterSupport.java
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/NestedElementValueExtracter.java
Modified:
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/EnvironmentBuilder.java
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java
labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/site/apt/examples/basic.apt
Log:
working version
Modified: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/EnvironmentBuilder.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/EnvironmentBuilder.java 2007-07-08 22:24:09 UTC (rev 13247)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/EnvironmentBuilder.java 2007-07-09 01:12:55 UTC (rev 13248)
@@ -15,14 +15,17 @@
*/
package org.jboss.maven.plugins.test.ext;
-import java.util.Iterator;
import java.util.ArrayList;
+import java.util.Iterator;
-import org.dom4j.Element;
-import org.dom4j.Attribute;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Resource;
+import org.dom4j.Element;
+import org.jboss.maven.shared.xml.dom4j.AttributeValueExtracter;
+import org.jboss.maven.shared.xml.dom4j.Extracter;
+import org.jboss.maven.shared.xml.dom4j.ElementValueExtracter;
+import org.jboss.maven.shared.xml.dom4j.NestedElementValueExtracter;
/**
* Builds {@link Environment} instances by parsing its XML definition.
@@ -33,6 +36,22 @@
public static final String ENVIRONMENT = "environment";
+ private static Extracter ENV_NAME_EXTRACTER = new AttributeValueExtracter( "name", true, null );
+
+ private static Extracter BASIC_ELEMENT_VALUE_EXTRACTER = new ElementValueExtracter();
+
+ private static Extracter GROUPID_EXTRACTER = new NestedElementValueExtracter( "groupId", true, null );
+ private static Extracter ARTIFACTID_EXTRACTER = new NestedElementValueExtracter( "artifactId", true, null );
+ private static Extracter VERSION_EXTRACTER = new NestedElementValueExtracter( "version", true, null );
+ private static Extracter TYPE_EXTRACTER = new NestedElementValueExtracter( "type", false, "jar" );
+ private static Extracter CLASSIFIER_EXTRACTER = new NestedElementValueExtracter( "classifier", false, null );
+ private static Extracter SYSPATH_EXTRACTER = new NestedElementValueExtracter( "systemPath", false, null );
+ private static Extracter OPTIONAL_EXTRACTER = new NestedElementValueExtracter( "optional", false, "false" );
+
+ private static Extracter DIRECTORY_EXTRACTER = new NestedElementValueExtracter( "directory", true, null );
+ private static Extracter TARGETPATH_EXTRACTER = new NestedElementValueExtracter( "targetPath", false, null );
+ private static Extracter FILTERING_EXTRACTER = new NestedElementValueExtracter( "filtering", false, null );
+
/**
* Constructs a new EnvironmentBuilder instance.
*/
@@ -40,7 +59,7 @@
}
public String extractEnvironmentName(Element environmentElement) {
- return getTrimmedValue( environmentElement.attribute( "name" ) );
+ return ENV_NAME_EXTRACTER.extract( environmentElement );
}
public Environment buildEnvironment(Element environmentElement) {
@@ -48,7 +67,7 @@
}
private Environment extractEnvironmentInfo(Element environmentElement) {
- Environment env = new Environment( environmentElement.attributeValue( "name" ) );
+ Environment env = new Environment( extractEnvironmentName( environmentElement ) );
// deps...
Element dependenciesElement = environmentElement.element( "dependencies" );
@@ -76,15 +95,15 @@
private Dependency extractDependencyInfo(Element dependencyElement) {
Dependency dependency = new Dependency();
dependency.setModelEncoding( dependencyElement.getDocument().getXMLEncoding() );
- dependency.setGroupId( getTrimmedValue( dependencyElement.attribute( "groupId" ) ) );
- dependency.setArtifactId( getTrimmedValue( dependencyElement.attribute( "artifactId" ) ) );
- dependency.setVersion( getTrimmedValue( dependencyElement.attribute( "version" ) ) );
- dependency.setType( getTrimmedValue( dependencyElement.attribute( "type" ) ) );
- dependency.setClassifier( getTrimmedValue( dependencyElement.attribute( "classifier" ) ) );
+ dependency.setGroupId( GROUPID_EXTRACTER.extract( dependencyElement ) );
+ dependency.setArtifactId( ARTIFACTID_EXTRACTER.extract( dependencyElement ) );
+ dependency.setVersion( VERSION_EXTRACTER.extract( dependencyElement ) );
+ dependency.setType( TYPE_EXTRACTER.extract( dependencyElement ) );
+ dependency.setClassifier( CLASSIFIER_EXTRACTER.extract( dependencyElement ) );
+ dependency.setSystemPath( SYSPATH_EXTRACTER.extract( dependencyElement ) );
+ dependency.setOptional( Boolean.valueOf( OPTIONAL_EXTRACTER.extract( dependencyElement ) ).booleanValue() );
// ignore scope in environment, but instead set it here to test for correctness
dependency.setScope( "test" );
- dependency.setSystemPath( getTrimmedValue( dependencyElement.attribute( "systemPath" ) ) );
- dependency.setOptional( getBooleanValue( dependencyElement.attribute( "optional" ) ) );
ArrayList exclusions = new ArrayList();
Element exclusionsElement = dependencyElement.element( "exclusions" );
@@ -103,17 +122,17 @@
private Object extractExclusionInfo(Element exclusionElement) {
Exclusion exclusion = new Exclusion();
exclusion.setModelEncoding( exclusionElement.getDocument().getXMLEncoding() );
- exclusion.setGroupId( getTrimmedValue( exclusionElement.attribute( "groupId" ) ) );
- exclusion.setArtifactId( getTrimmedValue( exclusionElement.attribute( "artifactId" ) ) );
+ exclusion.setGroupId( GROUPID_EXTRACTER.extract( exclusionElement ) );
+ exclusion.setArtifactId( ARTIFACTID_EXTRACTER.extract( exclusionElement ) );
return exclusion;
}
private Resource extractResourceInfo(Element resourceElement) {
Resource resource = new Resource();
resource.setModelEncoding( resourceElement.getDocument().getXMLEncoding() );
- resource.setTargetPath( getTrimmedValue( resourceElement.attribute( "targetPath" ) ) );
- resource.setFiltering( getBooleanValue( resourceElement.attribute( "filtering" ) ) );
- resource.setDirectory( getTrimmedValue( resourceElement.attribute( "directory" ) ) );
+ resource.setDirectory( DIRECTORY_EXTRACTER.extract( resourceElement ) );
+ resource.setTargetPath( TARGETPATH_EXTRACTER.extract( resourceElement ) );
+ resource.setFiltering( Boolean.valueOf( FILTERING_EXTRACTER.extract( resourceElement ) ).booleanValue() );
ArrayList includes = new ArrayList();
Element includesElement = resourceElement.element( "includes" );
@@ -121,7 +140,7 @@
Iterator itr = includesElement.elementIterator( "include" );
while ( itr.hasNext() ) {
final Element includeElement = ( Element ) itr.next();
- includes.add( getTrimmedText( includeElement.getText() ) );
+ includes.add( BASIC_ELEMENT_VALUE_EXTRACTER.extract( includeElement ) );
}
}
resource.setIncludes( includes );
@@ -132,7 +151,7 @@
Iterator itr = excludesElement.elementIterator( "exclude" );
while ( itr.hasNext() ) {
final Element excludeElement = ( Element ) itr.next();
- excludes.add( getTrimmedText( excludeElement.getText() ) );
+ excludes.add( BASIC_ELEMENT_VALUE_EXTRACTER.extract( excludeElement ) );
}
}
resource.setExcludes( excludes );
@@ -140,26 +159,4 @@
return resource;
}
- public String getTrimmedValue(Attribute attribute) {
- if ( attribute == null ) {
- return null;
- }
- String text = attribute.getStringValue();
- return getTrimmedText( text );
- }
-
- public String getTrimmedText(String text) {
- if ( text == null ) {
- return null;
- }
- return text.trim();
- }
-
- public boolean getBooleanValue(Attribute attribute) {
- String text = getTrimmedValue( attribute );
- if ( text == null ) {
- return false;
- }
- return Boolean.valueOf( text ).booleanValue();
- }
}
Modified: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java 2007-07-08 22:24:09 UTC (rev 13247)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/plugins/test/ext/ExtenderMojo.java 2007-07-09 01:12:55 UTC (rev 13248)
@@ -42,16 +42,12 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.dom4j.Document;
-import org.dom4j.DocumentException;
import org.dom4j.Element;
-import org.dom4j.io.SAXReader;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXParseException;
+import org.jboss.maven.shared.xml.dom4j.DocumentLoader;
/**
* Extends the test environment by expanding the test classpath based on some
@@ -63,11 +59,12 @@
* plugins resources (extend.dtd)
*
* @goal extend
- * @phase
+ * @phase generate-resources
*
* @author Steve Ebersole
*/
public class ExtenderMojo extends AbstractMojo implements LogEnabled {
+
/**
* INTERNAL : The Maven project
*
@@ -153,6 +150,7 @@
// Mojo#execute impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void execute() throws MojoExecutionException, MojoFailureException {
+ getLog().info( "starting test environment extension mojo" );
Environment environment = parseEnvironment();
extendTestClasspath( environment );
}
@@ -168,6 +166,7 @@
final Element environmentElement = ( Element ) itr.next();
if ( extenderEnv.equals( environmentBuilder.extractEnvironmentName( environmentElement ) ) ) {
// EARLY EXIT!!!!!
+ getLog().info( "found environment definition [" + extenderEnv + "]" );
return environmentBuilder.buildEnvironment( environmentElement );
}
}
@@ -175,59 +174,15 @@
return null;
}
- protected Document loadExtenderConfigDocument()
- throws MojoExecutionException {
+ protected Document loadExtenderConfigDocument() throws MojoExecutionException {
File extenderConfigFile = new File( extenderConfig );
if ( !extenderConfigFile.exists() ) {
getLog().warn( "Could not locate specified extender config file [" + extenderConfig + "]" );
}
-
- try {
- List errors = new ArrayList();
- SAXReader saxReader = new SAXReader();
- saxReader.setErrorHandler( new ErrorLogger( extenderConfig, errors, getLog() ) );
- saxReader.setMergeAdjacentText( true );
- saxReader.setValidation( true );
-
- Document doc = saxReader.read( extenderConfigFile );
- if ( errors.size() != 0 ) {
- throw new MojoExecutionException( "errors reading extender-config file [" + extenderConfig + "]", ( Throwable ) errors.get( 0 ) );
- }
- return doc;
- }
- catch ( DocumentException e) {
- throw new MojoExecutionException( "errors reading extender-config file [" + extenderConfig + "]", e );
- }
+ return new DocumentLoader( getLog() ).loadDocument( extenderConfigFile );
}
-
- public static class ErrorLogger implements ErrorHandler {
- private final String file;
- private final List errors;
- private final Log log;
-
- public ErrorLogger(String file, List errors, Log log) {
- this.file = file;
- this.errors = errors;
- this.log = log;
- }
-
- public void error(SAXParseException error) {
- log.error( "Error parsing XML: " + file + '(' + error.getLineNumber() + ") " + error.getMessage() );
- errors.add(error);
- }
-
- public void fatalError(SAXParseException error) {
- error(error);
- }
-
- public void warning(SAXParseException warn) {
- log.warn( "Warning parsing XML: " + file + '(' + warn.getLineNumber() + ") " + warn.getMessage() );
- }
- }
-
-
// extend classpath ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
protected void extendTestClasspath(Environment environment)
@@ -236,8 +191,8 @@
attachResources( environment.getResources() );
}
- protected void attachDependencies(List dependencies)
- throws MojoExecutionException {
+ protected void attachDependencies(List dependencies) throws MojoExecutionException {
+ getLog().info( "extending via dependencies" );
Set artifacts = new HashSet();
Iterator itr = dependencies.iterator();
while ( itr.hasNext() ) {
Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/AttributeValueExtracter.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/AttributeValueExtracter.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/AttributeValueExtracter.java 2007-07-09 01:12:55 UTC (rev 13248)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.shared.xml.dom4j;
+
+import org.dom4j.Element;
+import org.dom4j.Attribute;
+
+/**
+ * Extracts the value of an attribute
+ *
+ * @author Steve Ebersole
+ */
+public class AttributeValueExtracter extends ExtracterSupport {
+ private final String attributeName;
+
+ public AttributeValueExtracter(String attributeName, boolean required, String defaultValue) {
+ super( required, defaultValue );
+ this.attributeName = attributeName;
+ }
+
+ protected String extractValue(Element element) {
+ Attribute attribute = element.attribute( attributeName );
+ return attribute == null ? null : attribute.getValue();
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/DocumentLoader.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/DocumentLoader.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/DocumentLoader.java 2007-07-09 01:12:55 UTC (rev 13248)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.shared.xml.dom4j;
+
+import java.io.File;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.io.SAXReader;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXParseException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * A helper for loading dom4j {@link Document documents}.
+ *
+ * @author Steve Ebersole
+ */
+public class DocumentLoader {
+ private final Log log;
+
+ public DocumentLoader(Log log) {
+ this.log = log;
+ }
+
+ public Document loadDocument(File file) throws MojoExecutionException {
+ String location = file.getAbsolutePath();
+ try {
+ List errors = new ArrayList();
+ SAXReader saxReader = new SAXReader();
+ saxReader.setErrorHandler( new ErrorLogger( location, errors, log ) );
+ saxReader.setMergeAdjacentText( true );
+
+ Document doc = saxReader.read( file );
+ if ( errors.size() != 0 ) {
+ throw new MojoExecutionException( "errors loading file [" + location + "]", ( Throwable ) errors.get( 0 ) );
+ }
+ return doc;
+ }
+ catch ( DocumentException e) {
+ throw new MojoExecutionException( "errors loading file [" + location + "]", e );
+ }
+ }
+
+ public static class ErrorLogger implements ErrorHandler {
+ private final String file;
+ private final List errors;
+ private final Log log;
+
+ public ErrorLogger(String file, List errors, Log log) {
+ this.file = file;
+ this.errors = errors;
+ this.log = log;
+ }
+
+ public void error(SAXParseException error) {
+ log.error( "Error parsing XML: " + file + '(' + error.getLineNumber() + ") " + error.getMessage() );
+ errors.add(error);
+ }
+
+ public void fatalError(SAXParseException error) {
+ error(error);
+ }
+
+ public void warning(SAXParseException warn) {
+ log.warn( "Warning parsing XML: " + file + '(' + warn.getLineNumber() + ") " + warn.getMessage() );
+ }
+
+ }
+
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/ElementValueExtracter.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/ElementValueExtracter.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/ElementValueExtracter.java 2007-07-09 01:12:55 UTC (rev 13248)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.shared.xml.dom4j;
+
+import org.dom4j.Element;
+
+/**
+ * Extracts the text value from an element.
+ *
+ * @author Steve Ebersole
+ */
+public class ElementValueExtracter extends ExtracterSupport {
+ public ElementValueExtracter() {
+ this( true, null );
+ }
+
+ protected ElementValueExtracter(boolean required, String defaultValue) {
+ super( required, defaultValue );
+ }
+
+ protected String extractValue(Element element) {
+ return element.getTextTrim();
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/Extracter.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/Extracter.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/Extracter.java 2007-07-09 01:12:55 UTC (rev 13248)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.shared.xml.dom4j;
+
+import org.dom4j.Element;
+
+/**
+ * Defines a strategy contract for extracting values from dom4j
+ * {@link Element elements}.
+ *
+ * @author Steve Ebersole
+ */
+public interface Extracter {
+ /**
+ * Extract appropriate value from the given element.
+ *
+ * @param element Element from which to extract the value.
+ * @return The extracted value.
+ */
+ public String extract(Element element);
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/ExtracterSupport.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/ExtracterSupport.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/ExtracterSupport.java 2007-07-09 01:12:55 UTC (rev 13248)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.shared.xml.dom4j;
+
+import org.dom4j.Element;
+
+/**
+ * Simple support class for Extracter implementations.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class ExtracterSupport implements Extracter {
+ private final boolean required;
+ private final String defaultValue;
+
+ protected ExtracterSupport(boolean required, String defaultValue) {
+ this.required = required;
+ this.defaultValue = defaultValue;
+ }
+
+ public final String extract(Element element) {
+ String value = null;
+ if ( element != null ) {
+ value = extractValue( element );
+ }
+ if ( value == null ) {
+ if ( required ) {
+ requiredMissing();
+ }
+ return defaultValue;
+ }
+ else {
+ return value;
+ }
+ }
+
+ /**
+ * Extract the value according to the underlying implementations
+ * contract. The given element is guarenteed to not be null.
+ *
+ * @param element The non-null element.
+ * @return The extracted value.
+ */
+ protected abstract String extractValue(Element element);
+
+ /**
+ * Indicates that the implementation requires this value,
+ * but that null was encountered.
+ */
+ protected void requiredMissing() {
+ throw new IllegalStateException( "Required setting missing" );
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/NestedElementValueExtracter.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/NestedElementValueExtracter.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/main/java/org/jboss/maven/shared/xml/dom4j/NestedElementValueExtracter.java 2007-07-09 01:12:55 UTC (rev 13248)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.shared.xml.dom4j;
+
+import org.dom4j.Element;
+
+/**
+ * Extracts the text value from a named element of an element.
+ *
+ * @author Steve Ebersole
+ */
+public class NestedElementValueExtracter extends ExtracterSupport {
+ private final String elementName;
+
+ public NestedElementValueExtracter(String elementName, boolean required, String defaultValue) {
+ super( required, defaultValue );
+ this.elementName = elementName;
+ }
+
+ public String extractValue(Element element) {
+ Element subElement = element.element( elementName );
+ return subElement == null
+ ? null
+ : subElement.getTextTrim();
+ }
+}
Modified: labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/site/apt/examples/basic.apt
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/site/apt/examples/basic.apt 2007-07-08 22:24:09 UTC (rev 13247)
+++ labs/jbossbuild/maven-plugins/trunk/maven-test-ext-plugin/src/site/apt/examples/basic.apt 2007-07-09 01:12:55 UTC (rev 13248)
@@ -30,8 +30,8 @@
* Define environment(s)
Environments are defined in XML format. Here is an example to define
- some dependencies and resources specific to a database from venerable
- acme.com:
+ some dependencies and resources specific to a database from good 'ol
+ Acme Corporation:
+-----+
<environments>
More information about the jboss-svn-commits
mailing list