[jboss-svn-commits] JBL Code SVN: r13209 - in labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-style-plugin/src/main/java/org/jboss/maven: plugins/docbook/support and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Jul 7 09:30:23 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-07-07 09:30:22 -0400 (Sat, 07 Jul 2007)
New Revision: 13209

Added:
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-style-plugin/src/main/java/org/jboss/maven/shared/
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-style-plugin/src/main/java/org/jboss/maven/shared/file/
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-style-plugin/src/main/java/org/jboss/maven/shared/file/DirectoryCopier.java
Modified:
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-style-plugin/src/main/java/org/jboss/maven/plugins/docbook/support/ResourceMojo.java
Log:
filter-out scm directories on copy

Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-style-plugin/src/main/java/org/jboss/maven/plugins/docbook/support/ResourceMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-style-plugin/src/main/java/org/jboss/maven/plugins/docbook/support/ResourceMojo.java	2007-07-07 12:15:59 UTC (rev 13208)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-style-plugin/src/main/java/org/jboss/maven/plugins/docbook/support/ResourceMojo.java	2007-07-07 13:30:22 UTC (rev 13209)
@@ -21,7 +21,7 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.plexus.util.FileUtils;
+import org.jboss.maven.shared.file.DirectoryCopier;
 
 /**
  * Defines resources-like processing for the jdocbook-style packaging.  Handles
@@ -78,26 +78,13 @@
 		copySource( cssSourceDirectory, new File( outputDirectory, "css" ) );
 	}
 
-	private void copySource(File sourceDirectory, File targetDirectory)
-			throws MojoExecutionException {
+	private void copySource(File sourceDirectory, File targetDirectory) throws MojoExecutionException {
 		getLog().info( "attempting to copy directory : " + sourceDirectory.getAbsolutePath() );
-		if ( !sourceDirectory.exists() ) {
-			return;
-		}
-		String[] list = sourceDirectory.list();
-		if ( list == null || list.length == 0 ) {
-			return;
-		}
-
-		if ( !targetDirectory.exists() ) {
-			targetDirectory.mkdirs();
-		}
-
 		try {
-			FileUtils.copyDirectoryStructure( sourceDirectory, targetDirectory );
+			new DirectoryCopier( sourceDirectory ).copyTo( targetDirectory );
 		}
 		catch ( IOException e ) {
-			throw new MojoExecutionException( "unable to copy source directory [" + sourceDirectory.getAbsolutePath() + "]", e );
+			throw new MojoExecutionException( "Unable to copy directory [" + sourceDirectory + "]", e );
 		}
 	}
 }
\ No newline at end of file

Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-style-plugin/src/main/java/org/jboss/maven/shared/file/DirectoryCopier.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-style-plugin/src/main/java/org/jboss/maven/shared/file/DirectoryCopier.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-style-plugin/src/main/java/org/jboss/maven/shared/file/DirectoryCopier.java	2007-07-07 13:30:22 UTC (rev 13209)
@@ -0,0 +1,80 @@
+/*
+ * 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.file;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * Copies a directory with its structure intact.  Optionally allows defining
+ * includes and/or excludes.  Internally uses a {@link DirectoryScanner}, mainly
+ * to ensure we filter out "standard excludes" (like scm dirs) but also to apply
+ * any optionl includes and/or excludes.
+ *
+ * @author Steve Ebersole
+ */
+public class DirectoryCopier {
+	private final File sourceDirectory;
+
+	public DirectoryCopier(File sourceDirectory) {
+		this.sourceDirectory = sourceDirectory;
+	}
+
+	public void copyTo(File targetDirectory) throws IOException {
+		copyTo( targetDirectory, null, null );
+	}
+
+	private void copyTo(File targetDirectory, String[] includes, String[] excludes) throws IOException {
+		if ( !sourceDirectory.exists() ) {
+			return;
+		}
+		String[] list = sourceDirectory.list();
+		if ( list == null || list.length == 0 ) {
+			return;
+		}
+
+		if ( !targetDirectory.exists() ) {
+			targetDirectory.mkdirs();
+		}
+
+		DirectoryScanner scanner = new DirectoryScanner();
+		scanner.setBasedir( sourceDirectory );
+		scanner.setIncludes( includes );
+		scanner.setExcludes( excludes );
+		scanner.addDefaultExcludes();
+		scanner.scan();
+		String[] includedFiles = scanner.getIncludedFiles();
+
+
+		for ( int i = 0; i < includedFiles.length; i++ ) {
+			copyFileIfModified(
+					new File( sourceDirectory, includedFiles[i] ),
+					new File( targetDirectory, includedFiles[i] )
+			);
+		}
+	}
+
+	public static void copyFileIfModified(File source, File destination) throws IOException {
+		if ( destination.lastModified() < source.lastModified() ) {
+			FileUtils.copyFile( source.getCanonicalFile(), destination );
+			destination.setLastModified( source.lastModified() );
+		}
+	}
+
+}




More information about the jboss-svn-commits mailing list