[jboss-svn-commits] JBL Code SVN: r13125 - in labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven: plugins/jdocbook and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jul 5 19:01:56 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-07-05 19:01:56 -0400 (Thu, 05 Jul 2007)
New Revision: 13125

Added:
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/CompositeMavenProjectProperties.java
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesException.java
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesHelper.java
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceDelegate.java
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceException.java
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceHelper.java
Modified:
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/AbstractDocBookMojo.java
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/ResourceMojo.java
Log:
use Resources for project local images and css

Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/AbstractDocBookMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/AbstractDocBookMojo.java	2007-07-05 22:39:53 UTC (rev 13124)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/AbstractDocBookMojo.java	2007-07-05 23:01:56 UTC (rev 13125)
@@ -22,6 +22,7 @@
 import java.util.Set;
 
 import org.apache.maven.doxia.siterenderer.Renderer;
+import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -44,7 +45,7 @@
  * @author Steve Ebersole
  */
 public abstract class AbstractDocBookMojo extends AbstractMojo {
-	public static final String PLUGIN_NAME = "jboss-docbook";
+	public static final String PLUGIN_NAME = "jdocbook";
 
 	/**
 	 * INTERNAL : The project being built
@@ -119,25 +120,25 @@
 	protected File sourceDirectory;
 
 	/**
-	 * The directory containing local images
+	 * A {@link Resource} describing project-local images.
 	 *
-	 * @parameter expression="${basedir}/src/main/images"
+	 * @parameter
 	 */
-	protected File imagesDirectory;
+	protected Resource imageResource;
 
 	/**
-	 * The directory containing local css
+	 * A {@link Resource} describing project-local css.
 	 *
-	 * @parameter expression="${basedir}/src/main/css"
+	 * @parameter
 	 */
-	protected File cssDirectory;
+	protected Resource cssResource;
 
-	/**
-	 * The directory containing local fonts
-	 *
-	 * @parameter expression="${basedir}/src/main/fonts"
-	 */
-	protected File fontsDirectory;
+//	/**
+//	 * The directory containing local fonts
+//	 *
+//	 * @parameter expression="${basedir}/src/main/fonts"
+//	 */
+//	protected File fontsDirectory;
 
 	/**
 	 * The directory where the output will be written.
@@ -147,10 +148,8 @@
 	protected File targetDirectory;
 
 	/**
-	 * The directory where "docbook resource" staging occurs.  Mainly this is
-	 * used for (1) image/css staging for html-based output; (2) base directory
-	 * for value of <tt>img.src.path</tt> DocBook XSLT parameter for fop-based 
-	 * formattings.
+	 * The directory where we can perform some staging staging occurs.  Mainly
+	 * this is used for (1) image/css staging; (2) font staging.
 	 *
 	 * @parameter expression="${basedir}/target/staging"
 	 * @required

Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/ResourceMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/ResourceMojo.java	2007-07-05 22:39:53 UTC (rev 13124)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/ResourceMojo.java	2007-07-05 23:01:56 UTC (rev 13125)
@@ -25,10 +25,10 @@
 import org.codehaus.plexus.archiver.ArchiverException;
 import org.codehaus.plexus.archiver.UnArchiver;
 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
-import org.codehaus.plexus.util.FileUtils;
-import org.jboss.maven.plugins.jdocbook.gen.util.Formatting;
 import org.jboss.maven.plugins.jdocbook.gen.RenderingException;
 import org.jboss.maven.plugins.jdocbook.gen.XSLTException;
+import org.jboss.maven.plugins.jdocbook.gen.util.Formatting;
+import org.jboss.maven.shared.resource.ResourceDelegate;
 
 /**
  * This mojo's responsibility within the plugin/packaging is to process resources
@@ -46,50 +46,32 @@
 public class ResourceMojo extends AbstractDocBookMojo {
 
 	protected void process(Formatting[] formattings) throws RenderingException, XSLTException {
+		// allow project local style artifacts to override imported ones...
+		processDependencySupportArtifacts( collectDocBookStyleDependentArtifacts() );
 		processProjectResources();
-		processDependencySupportArtifacts( collectDocBookSupportDependentArtifacts() );
 	}
 
 	// project local resources ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 	private void processProjectResources() throws RenderingException {
-		copySource( imagesDirectory, new File( stagingDirectory, "images" ) );
-		copySource( cssDirectory, new File( stagingDirectory, "css" ) );
-		copySource( fontsDirectory, new File( stagingDirectory, "fonts" ) );
-	}
-
-	private void copySource(File sourceDirectory, File targetDirectory)
-			throws RenderingException {
-		getLog().info( "attempting to copy directory : " + sourceDirectory.getAbsolutePath() );
-		if ( !sourceDirectory.exists() ) {
-			return;
+		if ( imageResource != null ) {
+			new ResourceDelegate( project, new File( stagingDirectory, "images" ), getLog() ).process( imageResource );
 		}
-		String[] list = sourceDirectory.list();
-		if ( list == null || list.length == 0 ) {
-			return;
+		if ( cssResource != null ) {
+			new ResourceDelegate( project, new File( stagingDirectory, "css" ), getLog() ).process( cssResource );
 		}
-
-		if ( !targetDirectory.exists() ) {
-			targetDirectory.mkdirs();
-		}
-
-		try {
-			FileUtils.copyDirectoryStructure( sourceDirectory, targetDirectory );
-		}
-		catch ( IOException e ) {
-			throw new RenderingException( "unable to copy source directory [" + sourceDirectory.getAbsolutePath() + "]", e );
-		}
+//		copySource( fontsDirectory, new File( stagingDirectory, "fonts" ) );
 	}
 
 
 	// dependency support resources ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-	private List collectDocBookSupportDependentArtifacts() {
+	private List collectDocBookStyleDependentArtifacts() {
 		final ArrayList rtn = new ArrayList();
 		processArtifacts(
 				new ArtifactProcessor() {
 					public void process(Artifact artifact) {
-						if ( "docbook-support".equals( artifact.getType() ) ) {
+						if ( "jdocbook-style".equals( artifact.getType() ) ) {
 							rtn.add( artifact );
 						}
 					}

Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/CompositeMavenProjectProperties.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/CompositeMavenProjectProperties.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/CompositeMavenProjectProperties.java	2007-07-05 23:01:56 UTC (rev 13125)
@@ -0,0 +1,73 @@
+/*
+ * 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.properties;
+
+import java.util.AbstractMap;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.Set;
+import java.io.File;
+
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
+
+/**
+ * Presents an consolidated, aggregated view of project properties.
+ * <p/>
+ * Aggregation occurs across {@link System#getProperties()},
+ * {@link org.apache.maven.project.MavenProject#getProperties()} and
+ * via bean-propetties-style reflection on {@link org.apache.maven.project.MavenProject}.
+ *
+ * @author Steve Ebersole
+ */
+public class CompositeMavenProjectProperties extends AbstractMap {
+	private final MavenProject project;
+	private final Map values;
+
+	public CompositeMavenProjectProperties(MavenProject project) {
+		this.project = project;
+		values = new HashMap( System.getProperties() );
+		values.putAll( project.getProperties() );
+		Iterator itr = project.getBuild().getFilters().iterator();
+		while ( itr.hasNext() ) {
+			String filtersfile = ( String ) itr.next();
+			values.putAll(
+				PropertiesHelper.loadPropertyFile( new File( filtersfile ) )
+			);
+		}
+	}
+
+	public synchronized Object get(Object key) {
+		// try the local value map first...
+		Object value = values.get( key );
+
+		// then try reflection on the project bean properties...
+		if ( value == null ) {
+			try {
+				value = ReflectionValueExtractor.evaluate( String.valueOf( key ), project );
+			}
+			catch( Throwable ignore ) {
+				// intentionally empty...
+			}
+		}
+		return value;
+	}
+
+	public Set entrySet() {
+		throw new UnsupportedOperationException( "iterating MavenProject properties is not supported" );
+	}
+}

Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesException.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesException.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesException.java	2007-07-05 23:01:56 UTC (rev 13125)
@@ -0,0 +1,31 @@
+/*
+ * 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.properties;
+
+/**
+ * Some problem processing {@link java.util.Properties}.
+ *
+ * @author Steve Ebersole
+ */
+public class PropertiesException extends RuntimeException {
+	public PropertiesException(String message) {
+		super( message );
+	}
+
+	public PropertiesException(String message, Throwable cause) {
+		super( message, cause );
+	}
+}

Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesHelper.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesHelper.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesHelper.java	2007-07-05 23:01:56 UTC (rev 13125)
@@ -0,0 +1,139 @@
+/*
+ * 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.properties;
+
+import java.util.Properties;
+import java.util.Enumeration;
+import java.io.File;
+import java.io.IOException;
+import java.io.FileInputStream;
+
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * Utilities for dealing with @{link Properties} objects.
+ * <p/>
+ * Taken from maven-war-plugin, which apparently took it from
+ * maven-resources-plugin... ;)
+ *
+ * @author Steve Ebersole
+ */
+public class PropertiesHelper {
+
+	/**
+	 * Disallow external instantiation of PropertiesHelper.
+	 */
+	private PropertiesHelper() {
+	}
+
+	/**
+	 * Reads a property file, resolving all internal variables.
+	 *
+	 * @param propfile The property file to load
+	 *
+	 * @return the loaded and fully resolved Properties object
+	 */
+	public static Properties loadPropertyFile(File propfile) {
+		if ( !propfile.exists() ) {
+			throw new PropertiesException( "unable to locate spercified prop file [" + propfile.toString() + "]" );
+		}
+
+		Properties props = new Properties();
+		if ( propfile.exists() ) {
+			try {
+				FileInputStream inStream = new FileInputStream( propfile );
+				try {
+					props.load( inStream );
+				}
+				finally {
+					IOUtil.close( inStream );
+				}
+			}
+			catch( IOException ioe ) {
+				throw new PropertiesException( "unable to load properties file [" + propfile + "]" );
+			}
+		}
+
+		for ( Enumeration n = props.propertyNames(); n.hasMoreElements(); ) {
+			String k = ( String ) n.nextElement();
+			props.setProperty( k, PropertiesHelper.getInterpolatedPropertyValue( k, props ) );
+		}
+
+		return props;
+	}
+
+
+	/**
+	 * Retrieves a property value, replacing values like ${token}
+	 * using the Properties to look them up.
+	 * <p/>
+	 * It will leave unresolved properties alone, trying for System
+	 * properties, and implements reparsing (in the case that
+	 * the value of a property contains a key), and will
+	 * not loop endlessly on a pair like
+	 * test = ${test}.
+	 *
+	 * @param key The key for which to find the corresponding value
+	 * @param props The properties from which to find the value.
+	 * @return The (possible interpolated) property value
+	 */
+	public static String getInterpolatedPropertyValue(String key, Properties props) {
+		// This can also be done using InterpolationFilterReader,
+		// but it requires reparsing the file over and over until
+		// it doesn't change.
+
+		String v = props.getProperty( key );
+		String ret = "";
+		int idx, idx2;
+
+		while ( ( idx = v.indexOf( "${" ) ) >= 0 ) {
+			// append prefix to result
+			ret += v.substring( 0, idx );
+
+			// strip prefix from original
+			v = v.substring( idx + 2 );
+
+			// if no matching } then bail
+			if ( ( idx2 = v.indexOf( '}' ) ) < 0 ) {
+				break;
+			}
+
+			// strip out the key and resolve it
+			// resolve the key/value for the ${statement}
+			String nk = v.substring( 0, idx2 );
+			v = v.substring( idx2 + 1 );
+			String nv = props.getProperty( nk );
+
+			// try global environment..
+			if ( nv == null ) {
+				nv = System.getProperty( nk );
+			}
+
+			// if the key cannot be resolved,
+			// leave it alone ( and don't parse again )
+			// else prefix the original string with the
+			// resolved property ( so it can be parsed further )
+			// taking recursion into account.
+			if ( nv == null || nv.equals( key ) ) {
+				ret += "${" + nk + "}";
+			}
+			else {
+				v = nv + v;
+			}
+		}
+		return ret + v;
+	}
+}

Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceDelegate.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceDelegate.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceDelegate.java	2007-07-05 23:01:56 UTC (rev 13125)
@@ -0,0 +1,247 @@
+/*
+ * 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.resource;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.jboss.maven.shared.properties.CompositeMavenProjectProperties;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.InterpolationFilterReader;
+
+/**
+ * A delegate for handling {@link Resource} resolution.
+ *
+ * @author Steve Ebersole
+ */
+public class ResourceDelegate {
+	public static final String[] DEFAULT_DEFAULT_INCLUDES = new String[] { "**/**" };
+
+	private final File baseTargetDirectory;
+	private final String[] defaultIncludes;
+	private final String[] defaultExcludes;
+	private final Log log;
+
+	private final Map filterProperties;
+
+	/**
+	 * Constructs a Delegate instance for handling Resource resolution.
+	 *
+	 * @param project The project currently being built.
+	 * @param baseTargetDirectory The base target directory to which we should copy resources.
+	 * @param log The log instance to use for logging.
+	 */
+	public ResourceDelegate(MavenProject project, File baseTargetDirectory, Log log) {
+		this( project, baseTargetDirectory, DEFAULT_DEFAULT_INCLUDES, null, log );
+	}
+
+	/**
+	 * Constructs a Delegate instance for handling Resource resolution.
+	 *
+	 * @param project The project currently being built.
+	 * @param baseTargetDirectory The base target directory to which we should copy resources.
+	 * @param defaultIncludes default patterns for resource copying inclusion.
+	 * @param defaultExcludes default patterns for resource copying exclusion.
+	 * @param log The log instance to use for logging.
+	 */
+	public ResourceDelegate(
+			MavenProject project,
+			File baseTargetDirectory,
+			String[] defaultIncludes,
+			String[] defaultExcludes,
+			Log log) {
+		this.baseTargetDirectory = baseTargetDirectory;
+		this.defaultIncludes = defaultIncludes;
+		this.defaultExcludes = defaultExcludes;
+		this.log = log;
+		this.filterProperties = new CompositeMavenProjectProperties( project );
+	}
+
+	public void process(Resource[] resources) throws ResourceException {
+		for ( int i = 0; i < resources.length; i++ ) {
+			process( resources[i] );
+		}
+	}
+
+	public void process(Resource resource) throws ResourceException {
+		getLog().debug( "starting resource processing for : " + resource.getDirectory() );
+		String[] fileNames = collectFileNames( resource );
+		if ( fileNames == null ) {
+			getLog().debug( "no matching files found" );
+			return;
+		}
+
+		File destination = resource.getTargetPath() == null
+				? baseTargetDirectory
+				: new File( baseTargetDirectory, resource.getTargetPath() );
+		if ( !destination.exists() ) {
+			destination.mkdirs();
+		}
+
+		for ( int i = 0; i < fileNames.length; i++ ) {
+			if ( resource.isFiltering() ) {
+				copyFilteredFile(
+						new File( resource.getDirectory(), fileNames[i] ),
+						new File( destination, fileNames[i] ),
+						null,
+						getFilterWrappers(),
+						filterProperties
+				);
+			}
+			else {
+				copyFileIfModified(
+						new File( resource.getDirectory(), fileNames[i] ),
+						new File( destination, fileNames[i] )
+				);
+			}
+		}
+	}
+
+	/**
+	 * Given a resource, determine the matching file names which should be
+	 * processed.
+	 *
+	 * @param resource The resource model.
+	 * @return The collected matching file names.
+	 */
+	private String[] collectFileNames(Resource resource) {
+		DirectoryScanner scanner = new DirectoryScanner();
+		scanner.setBasedir( resource.getDirectory() );
+		scanner.setIncludes( determineIncludes( resource ) );
+		scanner.setExcludes( determineExcludes( resource ) );
+		scanner.addDefaultExcludes();
+		scanner.scan();
+		return scanner.getIncludedFiles();
+	}
+
+	private String[] determineIncludes(Resource resource) {
+		return toStringArray( resource.getIncludes(), defaultIncludes );
+	}
+
+	private String[] determineExcludes(Resource resource) {
+		return toStringArray( resource.getExcludes(), defaultExcludes );
+	}
+
+
+	private interface FilterWrapper {
+		Reader getReader(Reader fileReader, Map filterProperties);
+	}
+
+	private FilterWrapper[] getFilterWrappers() {
+		return new FilterWrapper[] {
+				// support ${token}
+				new FilterWrapper() {
+					public Reader getReader(Reader fileReader, Map filterProperties) {
+						return new InterpolationFilterReader(
+								fileReader, filterProperties, "${", "}"
+						);
+					}
+				},
+				// support @token@
+				new FilterWrapper() {
+					public Reader getReader(Reader fileReader, Map filterProperties) {
+						return new InterpolationFilterReader(
+								fileReader, filterProperties, "@", "@"
+						);
+					}
+				}
+		};
+	}
+
+	private static void copyFilteredFile(
+			File from,
+			File to,
+			String encoding,
+			FilterWrapper[] wrappers,
+			Map filterProperties) throws ResourceException {
+		// buffer so it isn't reading a byte at a time!
+		Reader fileReader = null;
+		Writer fileWriter = null;
+		try {
+			// fix for MWAR-36, ensures that the parent dir are created first
+			to.getParentFile().mkdirs();
+
+			if ( encoding == null || encoding.length() < 1 ) {
+				fileReader = new BufferedReader( new FileReader( from ) );
+				fileWriter = new FileWriter( to );
+			}
+			else {
+				FileInputStream instream = new FileInputStream( from );
+				FileOutputStream outstream = new FileOutputStream( to );
+				fileReader = new BufferedReader(
+						new InputStreamReader( instream, encoding )
+				);
+				fileWriter = new OutputStreamWriter( outstream, encoding );
+			}
+
+			Reader reader = fileReader;
+			for ( int i = 0; i < wrappers.length; i++ ) {
+				FilterWrapper wrapper = wrappers[i];
+				reader = wrapper.getReader( reader, filterProperties );
+			}
+
+			IOUtil.copy( reader, fileWriter );
+		}
+		catch( IOException e ) {
+			throw new ResourceException( e.getMessage(), e );
+		}
+		finally {
+			IOUtil.close( fileReader );
+			IOUtil.close( fileWriter );
+		}
+	}
+
+	private static void copyFileIfModified(File source, File destination) throws ResourceException {
+		if ( destination.lastModified() < source.lastModified() ) {
+			try {
+				FileUtils.copyFile( source.getCanonicalFile(), destination );
+				destination.setLastModified( source.lastModified() );
+			}
+			catch ( IOException e ) {
+				throw new ResourceException( e.getMessage(), e );
+			}
+		}
+	}
+
+	private Log getLog() {
+		return log;
+	}
+
+	private static String[] toStringArray(List list, String[] defaultArray) {
+		if ( list == null || list.isEmpty() ) {
+			return defaultArray;
+		}
+		else {
+			return ( String[] ) list.toArray( new String[ list.size() ] );
+		}
+	}
+}

Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceException.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceException.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceException.java	2007-07-05 23:01:56 UTC (rev 13125)
@@ -0,0 +1,31 @@
+/*
+ * 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.resource;
+
+/**
+ * Some problem processing resource definitions.
+ *
+ * @author Steve Ebersole
+ */
+public class ResourceException extends RuntimeException {
+	public ResourceException(String message) {
+		super( message );
+	}
+
+	public ResourceException(String message, Throwable cause) {
+		super( message, cause );
+	}
+}

Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceHelper.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceHelper.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceHelper.java	2007-07-05 23:01:56 UTC (rev 13125)
@@ -0,0 +1,32 @@
+/*
+ * 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.resource;
+
+import org.apache.maven.model.Resource;
+
+/**
+ * Utilities for dealing with @{link Resource} objects.
+ *
+ * @author Steve Ebersole
+ */
+public class ResourceHelper {
+	/**
+	 * Disallow external instantiation of ResourceHelper.
+	 */
+	private ResourceHelper() {
+	}
+
+}




More information about the jboss-svn-commits mailing list