Author: jdcasey
Date: Wed Jul 19 12:11:40 2006
New Revision: 423571

URL: http://svn.apache.org/viewvc?rev=423571&view=rev
Log:
Adding mappers, and a new constructor for the FileSetManager to allow it to use 
a plexus logger.

Added:
    
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/
    
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java
   (with props)
    
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java
   (with props)
    
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java
   (with props)
    
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java
   (with props)
    
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java
   (with props)
    
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java
   (with props)
    
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java
   (with props)
    
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java
   (with props)
Modified:
    maven/shared/trunk/file-management/pom.xml
    
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
    maven/shared/trunk/file-management/src/main/mdo/fileset.mdo

Modified: maven/shared/trunk/file-management/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/file-management/pom.xml?rev=423571&r1=423570&r2=423571&view=diff
==============================================================================
--- maven/shared/trunk/file-management/pom.xml (original)
+++ maven/shared/trunk/file-management/pom.xml Wed Jul 19 12:11:40 2006
@@ -57,5 +57,20 @@
       <version>3.8.1</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-shared-io</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-container-default</artifactId>
+      <version>1.0-alpha-9</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0</version>
+    </dependency>
   </dependencies>
 </project>

Added: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java?rev=423571&view=auto
==============================================================================
--- 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java
 (added)
+++ 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java
 Wed Jul 19 12:11:40 2006
@@ -0,0 +1,55 @@
+/*
+ * Copyright  2000,2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.maven.shared.model.fileset.mappers;
+
+/**
+ * Interface to be used by SourceFileScanner.
+ *
+ * <p>Used to find the name of the target file(s) corresponding to a
+ * source file.</p>
+ *
+ * <p>The rule by which the file names are transformed is specified
+ * via the setFrom and setTo methods. The exact meaning of these is
+ * implementation dependent.</p>
+ *
+ */
+public interface FileNameMapper {
+
+    /**
+     * Sets the from part of the transformation rule.
+     */
+    void setFrom(String from);
+
+    /**
+     * Sets the to part of the transformation rule.
+     */
+    void setTo(String to);
+
+    /**
+     * Returns the target filename for the
+     * given source file.
+     *
+     * <p>if the given rule doesn't apply to the source file,
+     * implementation must return null. SourceFileScanner will then
+     * omit the source file in question.</p>
+     *
+     * @param sourceFileName the name of the source file relative to
+     *                       some given basedirectory.
+     */
+    String mapFileName(String sourceFileName);
+}

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java?rev=423571&view=auto
==============================================================================
--- 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java
 (added)
+++ 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java
 Wed Jul 19 12:11:40 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright  2000,2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.maven.shared.model.fileset.mappers;
+
+/**
+ * Implementation of FileNameMapper that always returns the source
+ * file name without any leading directory information.
+ *
+ * <p>This is the default FileNameMapper for the copy and move
+ * tasks if the flatten attribute has been set.</p>
+ *
+ */
+public class FlatFileNameMapper implements FileNameMapper {
+
+    /**
+     * Ignored.
+     */
+    public void setFrom(String from) {
+    }
+
+    /**
+     * Ignored.
+     */
+    public void setTo(String to) {
+    }
+
+    /**
+     * Returns an one-element array containing the source file name
+     * without any leading directory information.
+     */
+    public String mapFileName(String sourceFileName) {
+        return new String( new java.io.File(sourceFileName).getName() );
+    }
+}

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java?rev=423571&view=auto
==============================================================================
--- 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java
 (added)
+++ 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java
 Wed Jul 19 12:11:40 2006
@@ -0,0 +1,166 @@
+/*
+ * Copyright  2000,2002,2004-2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.maven.shared.model.fileset.mappers;
+
+/**
+ * Implementation of FileNameMapper that does simple wildcard pattern
+ * replacements.
+ *
+ * <p>This does simple translations like *.foo -> *.bar where the
+ * prefix to .foo will be left unchanged. It only handles a single *
+ * character, use regular expressions for more complicated
+ * situations.</p>
+ *
+ * <p>This is one of the more useful Mappers, it is used by javac for
+ * example.</p>
+ *
+ */
+public class GlobPatternMapper implements FileNameMapper {
+
+    /**
+     * Part of &quot;from&quot; pattern before the *.
+     */
+    protected String fromPrefix = null;
+
+    /**
+     * Part of &quot;from&quot; pattern after the *.
+     */
+    protected String fromPostfix = null;
+
+    /**
+     * Length of the prefix (&quot;from&quot; pattern).
+     */
+    protected int prefixLength;
+
+    /**
+     * Length of the postfix (&quot;from&quot; pattern).
+     */
+    protected int postfixLength;
+
+    /**
+     * Part of &quot;to&quot; pattern before the *.
+     */
+    protected String toPrefix = null;
+
+    /**
+     * Part of &quot;to&quot; pattern after the *.
+     */
+    protected String toPostfix = null;
+
+    private boolean handleDirSep = false;
+    private boolean caseSensitive = true;
+
+    /**
+     * Attribute specifing whether to ignore the difference
+     * between / and \ (the two common directory characters).
+     * @param handleDirSep a boolean, default is false.
+     * @since Ant 1.6.3
+     */
+    public void setHandleDirSep(boolean handleDirSep) {
+        this.handleDirSep = handleDirSep;
+    }
+
+    /**
+     * Attribute specifing whether to ignore the case difference
+     * in the names.
+     *
+     * @param caseSensitive a boolean, default is false.
+     * @since Ant 1.6.3
+     */
+    public void setCaseSensitive(boolean caseSensitive) {
+        this.caseSensitive = caseSensitive;
+    }
+
+    /**
+     * Sets the &quot;from&quot; pattern. Required.
+     * @param from a string
+     */
+    public void setFrom(String from) {
+        int index = from.lastIndexOf("*");
+        if (index == -1) {
+            fromPrefix = from;
+            fromPostfix = "";
+        } else {
+            fromPrefix = from.substring(0, index);
+            fromPostfix = from.substring(index + 1);
+        }
+        prefixLength = fromPrefix.length();
+        postfixLength = fromPostfix.length();
+    }
+
+    /**
+     * Sets the &quot;to&quot; pattern. Required.
+     * @param to a string
+     */
+    public void setTo(String to) {
+        int index = to.lastIndexOf("*");
+        if (index == -1) {
+            toPrefix = to;
+            toPostfix = "";
+        } else {
+            toPrefix = to.substring(0, index);
+            toPostfix = to.substring(index + 1);
+        }
+    }
+
+    /**
+     * Returns null if the source file name doesn't match the
+     * &quot;from&quot; pattern, an one-element array containing the
+     * translated file otherwise.
+     * @param sourceFileName the filename to map
+     * @return a list of converted filenames
+     */
+    public String mapFileName(String sourceFileName) {
+        if (fromPrefix == null
+            || !modifyName(sourceFileName).startsWith(modifyName(fromPrefix))
+            || !modifyName(sourceFileName).endsWith(modifyName(fromPostfix))) {
+            return null;
+        }
+        return new String (toPrefix
+                                 + extractVariablePart(sourceFileName)
+                                 + toPostfix);
+    }
+
+    /**
+     * Returns the part of the given string that matches the * in the
+     * &quot;from&quot; pattern.
+     * @param name the source file name
+     * @return the variable part of the name
+     */
+    protected String extractVariablePart(String name) {
+        return name.substring(prefixLength,
+                              name.length() - postfixLength);
+    }
+
+    /**
+     * modify string based on dir char mapping and case sensitivity
+     * @param name the name to convert
+     * @return the converted name
+     */
+    private String modifyName(String name) {
+        if (!caseSensitive) {
+            name = name.toLowerCase();
+        }
+        if (handleDirSep) {
+            if (name.indexOf('\\') != -1) {
+                name = name.replace('\\', '/');
+            }
+        }
+        return name;
+    }
+}

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java?rev=423571&view=auto
==============================================================================
--- 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java
 (added)
+++ 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java
 Wed Jul 19 12:11:40 2006
@@ -0,0 +1,47 @@
+/*
+ * Copyright  2000,2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.maven.shared.model.fileset.mappers;
+
+/**
+ * Implementation of FileNameMapper that always returns the source file name.
+ *
+ * <p>This is the default FileNameMapper for the copy and move
+ * tasks.</p>
+ *
+ */
+public class IdentityMapper implements FileNameMapper {
+
+    /**
+     * Ignored.
+     */
+    public void setFrom(String from) {
+    }
+
+    /**
+     * Ignored.
+     */
+    public void setTo(String to) {
+    }
+
+    /**
+     * Returns an one-element array containing the source file name.
+     */
+    public String mapFileName(String sourceFileName) {
+        return sourceFileName;
+    }
+}

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java?rev=423571&view=auto
==============================================================================
--- 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java
 (added)
+++ 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java
 Wed Jul 19 12:11:40 2006
@@ -0,0 +1,121 @@
+/*
+ * Copyright  2000-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.maven.shared.model.fileset.mappers;
+
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.apache.maven.shared.model.fileset.Mapper;
+import org.apache.maven.shared.model.fileset.mappers.FileNameMapper;
+
+/**
+ * Element to define a FileNameMapper.
+ */
+public class MapperUtil
+{
+
+    private Properties implementations;
+
+    protected String from = null;
+
+    protected String to = null;
+
+    protected String type = "identity";
+
+    protected String classname = null;
+
+    /**
+     * Construct a new <CODE>MapperUtil</CODE> element.
+     * 
+     * @param p
+     *            the owning Ant <CODE>Project</CODE>.
+     */
+    public MapperUtil( Mapper mapper )
+    {
+        initializeProperties();
+        this.type = mapper.getType();
+        this.from = mapper.getFrom();
+        this.to = mapper.getTo();
+        this.classname = mapper.getClassname();
+    }
+
+    /**
+     * Initializes a properties object to store the built-in classnames.
+     */
+    public void initializeProperties()
+    {
+        implementations = new Properties();
+        implementations.setProperty( "identity", 
"org.apache.maven.plugin.assembly.mappers.IdentityMapper" );
+        implementations.setProperty( "flatten", 
"org.apache.maven.plugin.assembly.mappers.FlatFileNameMapper" );
+        implementations.setProperty( "glob", 
"org.apache.maven.plugin.assembly.mappers.GlobPatternMapper" );
+        implementations.setProperty( "merge", 
"org.apache.maven.plugin.assembly.mappers.MergingMapper" );
+        implementations.setProperty( "regexp", 
"org.apache.maven.plugin.assembly.mappers.RegexpPatternMapper" );
+        implementations.setProperty( "package", 
"org.apache.maven.plugin.assembly.mappers.PackageNameMapper" );
+        implementations.setProperty( "unpackage", 
"org.apache.maven.plugin.assembly.mappers.UnPackageNameMapper" );
+    }
+
+    /**
+     * Returns a fully configured FileNameMapper implementation.
+     */
+    public FileNameMapper getImplementation()
+        throws Exception
+    {
+        if ( type == null && classname == null )
+        {
+            throw new Exception( "nested mapper or " + "one of the attributes 
type or classname is required" );
+        }
+
+        if ( type != null && classname != null )
+        {
+            throw new Exception( "must not specify both type and classname 
attribute" );
+        }
+        if ( type != null )
+        {
+            classname = implementations.getProperty( type );
+        }
+
+        try
+        {
+            FileNameMapper m = (FileNameMapper) Class.forName( classname 
).newInstance();
+
+            m.setFrom( from );
+            m.setTo( to );
+
+            return m;
+        }
+        catch ( ClassNotFoundException cnfe )
+        {
+            throw cnfe;
+        }
+        catch ( Throwable t )
+        {
+            throw new Exception( t );
+        }
+    }
+
+    public Enumeration getTypes()
+    {
+        return implementations.propertyNames();
+    }
+
+    public Properties getImplementations()
+    {
+        return this.implementations;
+    }
+
+}

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java?rev=423571&view=auto
==============================================================================
--- 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java
 (added)
+++ 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java
 Wed Jul 19 12:11:40 2006
@@ -0,0 +1,51 @@
+/*
+ * Copyright  2000,2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.maven.shared.model.fileset.mappers;
+
+/**
+ * Implementation of FileNameMapper that always returns the same
+ * target file name.
+ *
+ * <p>This is the default FileNameMapper for the archiving tasks and
+ * uptodate.</p>
+ *
+ */
+public class MergingMapper implements FileNameMapper {
+    protected String mergedFile = null;
+
+    /**
+     * Ignored.
+     */
+    public void setFrom(String from) {
+    }
+
+    /**
+     * Sets the name of the merged file.
+     */
+    public void setTo(String to) {
+        mergedFile = to;
+    }
+
+    /**
+     * Returns an one-element array containing the file name set via setTo.
+     */
+    public String mapFileName(String sourceFileName) {
+        return mergedFile;
+    }
+
+}

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java?rev=423571&view=auto
==============================================================================
--- 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java
 (added)
+++ 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java
 Wed Jul 19 12:11:40 2006
@@ -0,0 +1,45 @@
+/*
+ * Copyright  2001-2002,2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.maven.shared.model.fileset.mappers;
+
+import java.io.File;
+
+/**
+ * Maps directory name matches into a dotted package name. This is
+ * useful for matching JUnit test cases againt their XML formatter
+ * results.
+ * <pre>
+ * &lt;mapper classname="org.apache.tools.ant.util.PackageNameMapper"
+ *         from="*Test.java" to="${test.data.dir}/TEST-*Test.xml"/&gt;
+ * </pre>
+ *
+ */
+public class PackageNameMapper extends GlobPatternMapper {
+    /**
+     *  Returns the part of the given string that matches the * in the
+     *  &quot;from&quot; pattern replacing file separators with dots
+     *
+     [EMAIL PROTECTED]  name  Source filename
+     [EMAIL PROTECTED]       Replaced variable part
+     */
+    protected String extractVariablePart(String name) {
+        String var = name.substring(prefixLength,
+                name.length() - postfixLength);
+        return var.replace(File.separatorChar, '.');
+    }
+}
+

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java?rev=423571&view=auto
==============================================================================
--- 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java
 (added)
+++ 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java
 Wed Jul 19 12:11:40 2006
@@ -0,0 +1,47 @@
+/*
+ * Copyright  2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.maven.shared.model.fileset.mappers;
+
+import java.io.File;
+
+/**
+ * Maps dotted package name matches to a directory name.
+ * This is the inverse of the package mapper.
+ * This is useful for matching XML formatter results against their JUnit test
+ * cases.
+ * <pre>
+ * &lt;mapper classname="org.apache.tools.ant.util.UnPackageNameMapper"
+ *         from="${test.data.dir}/TEST-*Test.xml" to="*Test.java"&gt;
+ * </pre>
+ *
+ *
+ */
+public class UnPackageNameMapper extends GlobPatternMapper {
+    /**
+     *  Returns the part of the given string that matches the * in the
+     *  &quot;from&quot; pattern replacing dots with file separators
+     *
+     [EMAIL PROTECTED]  name  Source filename
+     [EMAIL PROTECTED]       Replaced variable part
+     */
+    protected String extractVariablePart(String name) {
+        String var = name.substring(prefixLength,
+                name.length() - postfixLength);
+        return var.replace('.', File.separatorChar);
+    }
+}
+

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java?rev=423571&r1=423570&r2=423571&view=diff
==============================================================================
--- 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
 (original)
+++ 
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
 Wed Jul 19 12:11:40 2006
@@ -27,7 +27,13 @@
 import java.util.Set;
 
 import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.shared.io.logging.DefaultMessageHolder;
+import org.apache.maven.shared.io.logging.MessageHolder;
+import org.apache.maven.shared.io.logging.MessageLevels;
+import org.apache.maven.shared.io.logging.MojoLogSink;
+import org.apache.maven.shared.io.logging.PlexusLoggerSink;
 import org.apache.maven.shared.model.fileset.FileSet;
+import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.util.DirectoryScanner;
 
 /**
@@ -44,7 +50,7 @@
     private static final String[] EMPTY_STRING_ARRAY = new String[0];
     
     private final boolean verbose;
-    private final Log log;
+    private MessageHolder messages;
 
     /**
      * Create a new manager instance with the supplied log instance and flag 
for whether to output
@@ -55,7 +61,15 @@
      */
     public FileSetManager( Log log, boolean verbose )
     {
-        this.log = log;
+        if ( verbose )
+        {
+            this.messages = new DefaultMessageHolder( 
MessageLevels.LEVEL_DEBUG, MessageLevels.LEVEL_INFO, new MojoLogSink( log ) );
+        }
+        else
+        {
+            this.messages = new DefaultMessageHolder( 
MessageLevels.LEVEL_INFO, MessageLevels.LEVEL_INFO, new MojoLogSink( log ) );
+        }
+        
         this.verbose = verbose;
     }
     
@@ -66,18 +80,49 @@
      */
     public FileSetManager( Log log )
     {
-        this.log = log;
+        this.messages = new DefaultMessageHolder( MessageLevels.LEVEL_INFO, 
MessageLevels.LEVEL_INFO, new MojoLogSink( log ) );
+        this.verbose = false;
+    }
+    
+    /**
+     * Create a new manager instance with the supplied log instance and flag 
for whether to output
+     * verbose messages.
+     * 
+     * @param log The mojo log instance
+     * @param verbose Whether to output verbose messages
+     */
+    public FileSetManager( Logger log, boolean verbose )
+    {
+        if ( verbose )
+        {
+            this.messages = new DefaultMessageHolder( 
MessageLevels.LEVEL_DEBUG, MessageLevels.LEVEL_INFO, new PlexusLoggerSink( log 
) );
+        }
+        else
+        {
+            this.messages = new DefaultMessageHolder( 
MessageLevels.LEVEL_INFO, MessageLevels.LEVEL_INFO, new PlexusLoggerSink( log ) 
);
+        }
+        
+        this.verbose = verbose;
+    }
+    
+    /**
+     * Create a new manager instance with the supplied log instance. Verbose 
flag is set to false.
+     * 
+     * @param log The mojo log instance
+     */
+    public FileSetManager( Logger log )
+    {
+        this.messages = new DefaultMessageHolder( MessageLevels.LEVEL_INFO, 
MessageLevels.LEVEL_INFO, new PlexusLoggerSink( log ) );
         this.verbose = false;
     }
     
     /**
-     * Create a new manager instance with an empty log. Verbose flag is set to 
false.
+     * Create a new manager instance with an empty messages. Verbose flag is 
set to false.
      * 
      * @param log The mojo log instance
      */
     public FileSetManager()
     {
-        this.log = null;
         this.verbose = false;
     }
     
@@ -166,9 +211,9 @@
     {
         Set deletablePaths = findDeletablePaths( fileSet );
         
-        if ( log != null && log.isDebugEnabled() )
+        if ( messages != null && messages.isDebugEnabled() )
         {
-            log.debug( "Found deletable paths: " + String.valueOf( 
deletablePaths ).replace( ',', '\n' ) );
+            messages.addDebugMessage( "Found deletable paths: " + 
String.valueOf( deletablePaths ).replace( ',', '\n' ) );
         }        
         
         for ( Iterator it = deletablePaths.iterator(); it.hasNext(); )
@@ -181,18 +226,18 @@
             {
                 if ( file.isDirectory() && ( fileSet.isFollowSymlinks() || 
!isSymlink( file ) ) )
                 {
-                    if ( verbose && log != null )
+                    if ( verbose && messages != null )
                     {
-                        log.info( "Deleting directory: " + file );
+                        messages.addInfoMessage( "Deleting directory: " + file 
);
                     }
                     
                     removeDir( file, fileSet.isFollowSymlinks() );
                 }
                 else
                 {
-                    if ( verbose && log != null )
+                    if ( verbose && messages != null )
                     {
-                        log.info( "Deleting file: " + file );
+                        messages.addInfoMessage( "Deleting file: " + file );
                     }
                     
                     if ( !delete( file ) )
@@ -209,9 +254,9 @@
         File parent = file.getParentFile();
         File canonicalFile = file.getCanonicalFile();
         
-        if ( log != null && log.isDebugEnabled() )
+        if ( messages != null && messages.isDebugEnabled() )
         {
-            log.debug( "Checking for symlink:\nParent file's canonical path: " 
+ parent.getCanonicalPath()
+            messages.addDebugMessage( "Checking for symlink:\nParent file's 
canonical path: " + parent.getCanonicalPath()
                 + "\nMy canonical path: " + canonicalFile.getPath() );
         }        
         return parent != null && ( !canonicalFile.getName().equals( 
file.getName() ) || !canonicalFile.getPath().startsWith( 
parent.getCanonicalPath() ) );
@@ -227,9 +272,9 @@
 
     private Set findDeletableDirectories( FileSet fileSet )
     {
-        if ( verbose && log != null )
+        if ( verbose && messages != null )
         {
-            log.info( "Scanning for deletable directories." );
+            messages.addInfoMessage( "Scanning for deletable directories." );
         }
         
         DirectoryScanner scanner = scan( fileSet );
@@ -248,19 +293,19 @@
         
         if ( !fileSet.isFollowSymlinks() )
         {
-            if ( verbose && log != null )
+            if ( verbose && messages != null )
             {
-                log.info( "Adding symbolic link dirs which were previously 
excluded to the list being deleted." );
+                messages.addInfoMessage( "Adding symbolic link dirs which were 
previously excluded to the list being deleted." );
             }
             
             // we need to see which entries were excluded because they're 
symlinks...
             scanner.setFollowSymlinks( true );
             scanner.scan();
             
-            if ( log != null && log.isDebugEnabled() )
+            if ( messages != null && messages.isDebugEnabled() )
             {
-                log.debug( "Originally marked for delete: " + includes );
-                log.debug( "Marked for preserve (with followSymlinks == 
false): " + excludes );
+                messages.addDebugMessage( "Originally marked for delete: " + 
includes );
+                messages.addDebugMessage( "Marked for preserve (with 
followSymlinks == false): " + excludes );
             }
             
             List notSymlinks = Arrays.asList( scanner.getIncludedDirectories() 
);
@@ -268,9 +313,9 @@
             linksForDeletion.addAll( excludes );
             linksForDeletion.retainAll( notSymlinks );
             
-            if ( log != null && log.isDebugEnabled() )
+            if ( messages != null && messages.isDebugEnabled() )
             {
-                log.debug( "Symlinks marked for deletion (originally 
mismarked): " + linksForDeletion );
+                messages.addDebugMessage( "Symlinks marked for deletion 
(originally mismarked): " + linksForDeletion );
             }
             
             excludes.removeAll( notSymlinks );
@@ -286,16 +331,16 @@
             
             while( parentPath != null )
             {
-                if ( log != null && log.isDebugEnabled() )
+                if ( messages != null && messages.isDebugEnabled() )
                 {
-                    log.debug( "Verifying path: " + parentPath + " is not 
present; contains file which is excluded." );
+                    messages.addDebugMessage( "Verifying path: " + parentPath 
+ " is not present; contains file which is excluded." );
                 }
                 
                 boolean removed = includes.remove( parentPath );
                 
-                if ( removed && log != null && log.isDebugEnabled() )
+                if ( removed && messages != null && messages.isDebugEnabled() )
                 {
-                    log.debug( "Path: " + parentPath + " was removed from 
delete list." );
+                    messages.addDebugMessage( "Path: " + parentPath + " was 
removed from delete list." );
                 }
                 
                 parentPath = new File( parentPath ).getParent();
@@ -309,9 +354,9 @@
 
     private Set findDeletableFiles( FileSet fileSet, Set deletableDirectories )
     {
-        if ( verbose && log != null )
+        if ( verbose && messages != null )
         {
-            log.info( "Re-scanning for deletable files." );
+            messages.addInfoMessage( "Re-scanning for deletable files." );
         }
         
         DirectoryScanner scanner = scan( fileSet );
@@ -331,19 +376,19 @@
         
         if ( !fileSet.isFollowSymlinks() )
         {
-            if ( verbose && log != null )
+            if ( verbose && messages != null )
             {
-                log.info( "Adding symbolic link files which were previously 
excluded to the list being deleted." );
+                messages.addInfoMessage( "Adding symbolic link files which 
were previously excluded to the list being deleted." );
             }
             
             // we need to see which entries were excluded because they're 
symlinks...
             scanner.setFollowSymlinks( true );
             scanner.scan();
             
-            if ( log != null && log.isDebugEnabled() )
+            if ( messages != null && messages.isDebugEnabled() )
             {
-                log.debug( "Originally marked for delete: " + includes );
-                log.debug( "Marked for preserve (with followSymlinks == 
false): " + excludes );
+                messages.addDebugMessage( "Originally marked for delete: " + 
includes );
+                messages.addDebugMessage( "Marked for preserve (with 
followSymlinks == false): " + excludes );
             }
             
             List notSymlinks = Arrays.asList( scanner.getExcludedFiles() );
@@ -351,9 +396,9 @@
             linksForDeletion.addAll( excludes );
             linksForDeletion.retainAll( notSymlinks );
             
-            if ( log != null && log.isDebugEnabled() )
+            if ( messages != null && messages.isDebugEnabled() )
             {
-                log.debug( "Symlinks marked for deletion (originally 
mismarked): " + linksForDeletion );
+                messages.addDebugMessage( "Symlinks marked for deletion 
(originally mismarked): " + linksForDeletion );
             }
             
             excludes.removeAll( notSymlinks );
@@ -369,16 +414,16 @@
             
             while( parentPath != null )
             {
-                if ( log != null && log.isDebugEnabled() )
+                if ( messages != null && messages.isDebugEnabled() )
                 {
-                    log.debug( "Verifying path: " + parentPath + " is not 
present; contains file which is excluded." );
+                    messages.addDebugMessage( "Verifying path: " + parentPath 
+ " is not present; contains file which is excluded." );
                 }
                 
                 boolean removed = includes.remove( parentPath );
                 
-                if ( removed && log != null && log.isDebugEnabled() )
+                if ( removed && messages != null && messages.isDebugEnabled() )
                 {
-                    log.debug( "Path: " + parentPath + " was removed from 
delete list." );
+                    messages.addDebugMessage( "Path: " + parentPath + " was 
removed from delete list." );
                 }
                 
                 parentPath = new File( parentPath ).getParent();

Modified: maven/shared/trunk/file-management/src/main/mdo/fileset.mdo
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/mdo/fileset.mdo?rev=423571&r1=423570&r2=423571&view=diff
==============================================================================
--- maven/shared/trunk/file-management/src/main/mdo/fileset.mdo (original)
+++ maven/shared/trunk/file-management/src/main/mdo/fileset.mdo Wed Jul 19 
12:11:40 2006
@@ -99,6 +99,17 @@
                ]]>
           </description>
         </field>
+        <field>
+          <name>mapper</name>
+          <version>1.0.0</version>
+          <association>
+            <type>Mapper</type>
+          </association>
+          <defaultValue>new Mapper()</defaultValue>
+          <description>
+            Specifies the mapper used.
+          </description>
+        </field>
       </fields>
       <codeSegments>
         <codeSegment>
@@ -147,6 +158,59 @@
           ]]></code>
         </codeSegment>
       </codeSegments>
+    </class>
+    <class>
+      <name>Mapper</name>
+      <version>1.0.0</version>
+      <fields>
+        <field>
+          <name>type</name>
+          <version>1.0.0</version>
+          <type>String</type>
+          <defaultValue>identity</defaultValue>
+          <description>
+            specifies one of the built-in mapper implementations. A custom 
mapper may be specified by using the classname property.
+            If classname is being used, then the type should not be used.
+            <![CDATA[ 
+            Valid values:
+            <ul>
+              <li><b>"flatten"</b> - The target file name is identical to the 
source file name, with all leading directory information stripped off. Both to 
and from will be ignored </li>
+              <li><b>"glob"</b> - Both to and from define patterns that may 
contain at most one *. For each source file that matches the from pattern, a 
target file name will be constructed from the to pattern by substituting the * 
in the to pattern with the text that matches the * in the from pattern. Source 
file names that don't match the from pattern will be ignored/li>
+              <li><b>"regexp"</b> - Both to and from define regular 
expressions. If the source file name matches the from pattern, the target file 
name will be constructed from the to pattern, using \0 to \9 as back-references 
for the full match (\0) or the matches of the subexpressions in parentheses. 
Source files not matching the from pattern will be ignored.</li>
+              <li><b>"merge"</b> - The target file name will always be the 
same, as defined by to. from will be ignored</li>
+              <li><b>"package"</b> - Sharing the same syntax as the glob 
mapper, the package mapper replaces directory separators found in the matched 
source pattern with dots in the target pattern placeholder. This mapper is 
particularly useful in combination with <uptodate> and <junit> output. </li>
+              <li><b>"unpackage"</b> - This mapper is the inverse of the 
package mapper. It replaces the dots in a package name with directory 
separators. This is useful for matching XML formatter results against their 
JUnit test test cases. The mapper shares the sample syntax as the glob mapper. 
</li>
+            </ul>
+            ]]>
+          </description>
+          <required>true</required>
+        </field>
+        <field>
+          <name>from</name>
+          <version>1.0.0</version>
+          <type>String</type>
+          <description>
+          the from attribute for the given implementation. Depends on the 
implementation
+          </description>
+        </field>
+        <field>
+          <name>to</name>
+          <version>1.0.0</version>
+          <type>String</type>
+          <description>
+          the to attribute for the given implementation. Depends on the 
implementation
+          </description>
+        </field>
+        <field>
+          <name>classname</name>
+          <version>1.0.0</version>
+          <type>String</type>
+          <description>
+          Specify your own implementation of the mapper. The class has to be 
in the classpath of the project. 
+          Do not specify the classname if the type is used.
+          </description>
+        </field>
+      </fields>
     </class>
     <class rootElement="true" xml.tagName="fileSet">
       <name>FileSet</name>


Reply via email to