geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r821961 [15/30] - in /geronimo/sandbox/djencks/osgi/framework: ./ buildsupport/ buildsupport/car-maven-plugin/ buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ buildsupport/geronimo-maven-plugin/src/main/jav...
Date Mon, 05 Oct 2009 18:54:56 GMT
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CollectionUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CollectionUtils.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CollectionUtils.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CollectionUtils.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,252 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/*
+ * Copyright The Codehaus 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:olamy@codehaus.org">olamy</a>
+ * @version $Id: CollectionUtils.java 8055 2009-01-16 12:45:08Z vsiveton $
+ */
+public class CollectionUtils
+{
+    // ----------------------------------------------------------------------
+    // Static methods that can probably be moved to a real util class.
+    // ----------------------------------------------------------------------
+
+    /**
+     * Take a dominant and recessive Map and merge the key:value
+     * pairs where the recessive Map may add key:value pairs to the dominant
+     * Map but may not override any existing key:value pairs.
+     *
+     * If we have two Maps, a dominant and recessive, and
+     * their respective keys are as follows:
+     *
+     *  dominantMapKeys = { a, b, c, d, e, f }
+     * recessiveMapKeys = { a, b, c, x, y, z }
+     *
+     * Then the result should be the following:
+     *
+     * resultantKeys = { a, b, c, d, e, f, x, y, z }
+     *
+     * @param dominantMap Dominant Map.
+     * @param recessiveMap Recessive Map.
+     * @return The result map with combined dominant and recessive values.
+     */
+    public static Map mergeMaps( Map dominantMap, Map recessiveMap )
+    {
+
+        if ( dominantMap == null && recessiveMap == null )
+        {
+            return null;
+        }
+
+        if ( dominantMap != null && recessiveMap == null )
+        {
+            return dominantMap;
+        }
+
+        if ( dominantMap == null && recessiveMap != null )
+        {
+            return recessiveMap;
+        }
+
+        Map result = new HashMap();
+
+        // Grab the keys from the dominant and recessive maps.
+        Set dominantMapKeys = dominantMap.keySet();
+        Set recessiveMapKeys = recessiveMap.keySet();
+
+        // Create the set of keys that will be contributed by the
+        // recessive Map by subtracting the intersection of keys
+        // from the recessive Map's keys.
+        Collection contributingRecessiveKeys =
+            CollectionUtils.subtract( recessiveMapKeys,
+                                      CollectionUtils.intersection( dominantMapKeys, recessiveMapKeys ) );
+
+        result.putAll( dominantMap );
+
+        // Now take the keys we just found and extract the values from
+        // the recessiveMap and put the key:value pairs into the dominantMap.
+        for ( Iterator i = contributingRecessiveKeys.iterator(); i.hasNext(); )
+        {
+            Object key = i.next();
+            result.put( key, recessiveMap.get( key ) );
+        }
+
+        return result;
+    }
+
+    /**
+     * Take a series of <code>Map</code>s and merge
+     * them where the ordering of the array from 0..n
+     * is the dominant order.
+     *
+     * @param maps An array of Maps to merge.
+     * @return Map The result Map produced after the merging process.
+     */
+    public static Map mergeMaps( Map[] maps )
+    {
+        Map result = null;
+
+        if ( maps.length == 0 )
+        {
+            result = null;
+        }
+        else if ( maps.length == 1 )
+        {
+            result = maps[0];
+        }
+        else
+        {
+            result = mergeMaps( maps[0], maps[1] );
+
+            for ( int i = 2; i < maps.length; i++ )
+            {
+                result = mergeMaps( result, maps[i] );
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * Returns a {@link Collection} containing the intersection
+     * of the given {@link Collection}s.
+     * <p>
+     * The cardinality of each element in the returned {@link Collection}
+     * will be equal to the minimum of the cardinality of that element
+     * in the two given {@link Collection}s.
+     *
+     * @see Collection#retainAll
+     */
+    public static Collection intersection( final Collection a, final Collection b )
+    {
+        ArrayList list = new ArrayList();
+        Map mapa = getCardinalityMap( a );
+        Map mapb = getCardinalityMap( b );
+        Set elts = new HashSet( a );
+        elts.addAll( b );
+        Iterator it = elts.iterator();
+        while ( it.hasNext() )
+        {
+            Object obj = it.next();
+            for ( int i = 0,m = Math.min( getFreq( obj, mapa ), getFreq( obj, mapb ) ); i < m; i++ )
+            {
+                list.add( obj );
+            }
+        }
+        return list;
+    }
+
+    /**
+     * Returns a {@link Collection} containing <tt><i>a</i> - <i>b</i></tt>.
+     * The cardinality of each element <i>e</i> in the returned {@link Collection}
+     * will be the cardinality of <i>e</i> in <i>a</i> minus the cardinality
+     * of <i>e</i> in <i>b</i>, or zero, whichever is greater.
+     *
+     * @see Collection#removeAll
+     */
+    public static Collection subtract( final Collection a, final Collection b )
+    {
+        ArrayList list = new ArrayList( a );
+        Iterator it = b.iterator();
+        while ( it.hasNext() )
+        {
+            list.remove( it.next() );
+        }
+        return list;
+    }
+
+    /**
+     * Returns a {@link Map} mapping each unique element in
+     * the given {@link Collection} to an {@link Integer}
+     * representing the number of occurances of that element
+     * in the {@link Collection}.
+     * An entry that maps to <tt>null</tt> indicates that the
+     * element does not appear in the given {@link Collection}.
+     */
+    public static Map getCardinalityMap( final Collection col )
+    {
+        HashMap count = new HashMap();
+        Iterator it = col.iterator();
+        while ( it.hasNext() )
+        {
+            Object obj = it.next();
+            Integer c = (Integer) ( count.get( obj ) );
+            if ( null == c )
+            {
+                count.put( obj, new Integer( 1 ) );
+            }
+            else
+            {
+                count.put( obj, new Integer( c.intValue() + 1 ) );
+            }
+        }
+        return count;
+    }
+
+    public static List iteratorToList( Iterator it )
+    {
+        if ( it == null )
+        {
+            throw new NullPointerException( "it cannot be null." );
+        }
+
+        List list = new ArrayList();
+
+        while ( it.hasNext() )
+        {
+            list.add( it.next() );
+        }
+
+        return list;
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    private static final int getFreq( final Object obj, final Map freqMap )
+    {
+        try
+        {
+            Object o = freqMap.get( obj );
+            if ( o != null )  // minimize NullPointerExceptions
+            {
+                return ( (Integer) o ).intValue();
+            }
+        }
+        catch ( NullPointerException e )
+        {
+            // ignored
+        }
+        catch ( NoSuchElementException e )
+        {
+            // ignored
+        }
+        return 0;
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CollectionUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CollectionUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/CollectionUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryScanner.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryScanner.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryScanner.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryScanner.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,726 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.codehaus.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "Ant" and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact codehaus@codehaus.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.codehaus.org/>.
+ */
+
+package org.apache.geronimo.system.plugin.plexus.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Vector;
+
+/**
+ * Class for scanning a directory for files/directories which match certain
+ * criteria.
+ * <p>
+ * These criteria consist of selectors and patterns which have been specified.
+ * With the selectors you can select which files you want to have included.
+ * Files which are not selected are excluded. With patterns you can include
+ * or exclude files based on their filename.
+ * <p>
+ * The idea is simple. A given directory is recursively scanned for all files
+ * and directories. Each file/directory is matched against a set of selectors,
+ * including special support for matching against filenames with include and
+ * and exclude patterns. Only files/directories which match at least one
+ * pattern of the include pattern list or other file selector, and don't match
+ * any pattern of the exclude pattern list or fail to match against a required
+ * selector will be placed in the list of files/directories found.
+ * <p>
+ * When no list of include patterns is supplied, "**" will be used, which
+ * means that everything will be matched. When no list of exclude patterns is
+ * supplied, an empty list is used, such that nothing will be excluded. When
+ * no selectors are supplied, none are applied.
+ * <p>
+ * The filename pattern matching is done as follows:
+ * The name to be matched is split up in path segments. A path segment is the
+ * name of a directory or file, which is bounded by
+ * <code>File.separator</code> ('/' under UNIX, '\' under Windows).
+ * For example, "abc/def/ghi/xyz.java" is split up in the segments "abc",
+ * "def","ghi" and "xyz.java".
+ * The same is done for the pattern against which should be matched.
+ * <p>
+ * The segments of the name and the pattern are then matched against each
+ * other. When '**' is used for a path segment in the pattern, it matches
+ * zero or more path segments of the name.
+ * <p>
+ * There is a special case regarding the use of <code>File.separator</code>s
+ * at the beginning of the pattern and the string to match:<br>
+ * When a pattern starts with a <code>File.separator</code>, the string
+ * to match must also start with a <code>File.separator</code>.
+ * When a pattern does not start with a <code>File.separator</code>, the
+ * string to match may not start with a <code>File.separator</code>.
+ * When one of these rules is not obeyed, the string will not
+ * match.
+ * <p>
+ * When a name path segment is matched against a pattern path segment, the
+ * following special characters can be used:<br>
+ * '*' matches zero or more characters<br>
+ * '?' matches one character.
+ * <p>
+ * Examples:
+ * <p>
+ * "**\*.class" matches all .class files/dirs in a directory tree.
+ * <p>
+ * "test\a??.java" matches all files/dirs which start with an 'a', then two
+ * more characters and then ".java", in a directory called test.
+ * <p>
+ * "**" matches everything in a directory tree.
+ * <p>
+ * "**\test\**\XYZ*" matches all files/dirs which start with "XYZ" and where
+ * there is a parent directory called test (e.g. "abc\test\def\ghi\XYZ123").
+ * <p>
+ * Case sensitivity may be turned off if necessary. By default, it is
+ * turned on.
+ * <p>
+ * Example of usage:
+ * <pre>
+ *   String[] includes = {"**\\*.class"};
+ *   String[] excludes = {"modules\\*\\**"};
+ *   ds.setIncludes(includes);
+ *   ds.setExcludes(excludes);
+ *   ds.setBasedir(new File("test"));
+ *   ds.setCaseSensitive(true);
+ *   ds.scan();
+ *
+ *   System.out.println("FILES:");
+ *   String[] files = ds.getIncludedFiles();
+ *   for (int i = 0; i < files.length; i++) {
+ *     System.out.println(files[i]);
+ *   }
+ * </pre>
+ * This will scan a directory called test for .class files, but excludes all
+ * files in all proper subdirectories of a directory called "modules"
+ *
+ * @author Arnout J. Kuiper
+ * <a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a>
+ * @author Magesh Umasankar
+ * @author <a href="mailto:bruce@callenish.com">Bruce Atherton</a>
+ * @author <a href="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</a>
+ */
+public class DirectoryScanner extends AbstractScanner
+{
+
+    /** The base directory to be scanned. */
+    protected File basedir;
+
+    /** The files which matched at least one include and no excludes
+     *  and were selected.
+     */
+    protected Vector filesIncluded;
+
+    /** The files which did not match any includes or selectors. */
+    protected Vector filesNotIncluded;
+
+    /**
+     * The files which matched at least one include and at least
+     * one exclude.
+     */
+    protected Vector filesExcluded;
+
+    /** The directories which matched at least one include and no excludes
+     *  and were selected.
+     */
+    protected Vector dirsIncluded;
+
+    /** The directories which were found and did not match any includes. */
+    protected Vector dirsNotIncluded;
+
+    /**
+     * The directories which matched at least one include and at least one
+     * exclude.
+     */
+    protected Vector dirsExcluded;
+
+    /** The files which matched at least one include and no excludes and
+     *  which a selector discarded.
+     */
+    protected Vector filesDeselected;
+
+    /** The directories which matched at least one include and no excludes
+     *  but which a selector discarded.
+     */
+    protected Vector dirsDeselected;
+
+    /** Whether or not our results were built by a slow scan. */
+    protected boolean haveSlowResults = false;
+
+    /**
+     * Whether or not symbolic links should be followed.
+     *
+     * @since Ant 1.5
+     */
+    private boolean followSymlinks = true;
+
+    /** Whether or not everything tested so far has been included. */
+    protected boolean everythingIncluded = true;
+
+    /**
+     * Sole constructor.
+     */
+    public DirectoryScanner()
+    {
+    }
+
+    /**
+     * Sets the base directory to be scanned. This is the directory which is
+     * scanned recursively. All '/' and '\' characters are replaced by
+     * <code>File.separatorChar</code>, so the separator used need not match
+     * <code>File.separatorChar</code>.
+     *
+     * @param basedir The base directory to scan.
+     *                Must not be <code>null</code>.
+     */
+    public void setBasedir( String basedir )
+    {
+        setBasedir( new File( basedir.replace( '/', File.separatorChar ).replace(
+            '\\', File.separatorChar ) ) );
+    }
+
+    /**
+     * Sets the base directory to be scanned. This is the directory which is
+     * scanned recursively.
+     *
+     * @param basedir The base directory for scanning.
+     *                Should not be <code>null</code>.
+     */
+    public void setBasedir( File basedir )
+    {
+        this.basedir = basedir;
+    }
+
+    /**
+     * Returns the base directory to be scanned.
+     * This is the directory which is scanned recursively.
+     *
+     * @return the base directory to be scanned
+     */
+    public File getBasedir()
+    {
+        return basedir;
+    }
+
+    /**
+     * Sets whether or not symbolic links should be followed.
+     *
+     * @param followSymlinks whether or not symbolic links should be followed
+     */
+    public void setFollowSymlinks( boolean followSymlinks )
+    {
+        this.followSymlinks = followSymlinks;
+    }
+
+    /**
+     * Returns whether or not the scanner has included all the files or
+     * directories it has come across so far.
+     *
+     * @return <code>true</code> if all files and directories which have
+     *         been found so far have been included.
+     */
+    public boolean isEverythingIncluded()
+    {
+        return everythingIncluded;
+    }
+
+    /**
+     * Scans the base directory for files which match at least one include
+     * pattern and don't match any exclude patterns. If there are selectors
+     * then the files must pass muster there, as well.
+     *
+     * @exception IllegalStateException if the base directory was set
+     *            incorrectly (i.e. if it is <code>null</code>, doesn't exist,
+     *            or isn't a directory).
+     */
+    public void scan() throws IllegalStateException
+    {
+        if ( basedir == null )
+        {
+            throw new IllegalStateException( "No basedir set" );
+        }
+        if ( !basedir.exists() )
+        {
+            throw new IllegalStateException( "basedir " + basedir
+                                             + " does not exist" );
+        }
+        if ( !basedir.isDirectory() )
+        {
+            throw new IllegalStateException( "basedir " + basedir
+                                             + " is not a directory" );
+        }
+
+        setupDefaultFilters();
+
+        filesIncluded = new Vector();
+        filesNotIncluded = new Vector();
+        filesExcluded = new Vector();
+        filesDeselected = new Vector();
+        dirsIncluded = new Vector();
+        dirsNotIncluded = new Vector();
+        dirsExcluded = new Vector();
+        dirsDeselected = new Vector();
+
+        if ( isIncluded( "" ) )
+        {
+            if ( !isExcluded( "" ) )
+            {
+                if ( isSelected( "", basedir ) )
+                {
+                    dirsIncluded.addElement( "" );
+                }
+                else
+                {
+                    dirsDeselected.addElement( "" );
+                }
+            }
+            else
+            {
+                dirsExcluded.addElement( "" );
+            }
+        }
+        else
+        {
+            dirsNotIncluded.addElement( "" );
+        }
+        scandir( basedir, "", true );
+    }
+
+    /**
+     * Top level invocation for a slow scan. A slow scan builds up a full
+     * list of excluded/included files/directories, whereas a fast scan
+     * will only have full results for included files, as it ignores
+     * directories which can't possibly hold any included files/directories.
+     * <p>
+     * Returns immediately if a slow scan has already been completed.
+     */
+    protected void slowScan()
+    {
+        if ( haveSlowResults )
+        {
+            return;
+        }
+
+        String[] excl = new String[dirsExcluded.size()];
+        dirsExcluded.copyInto( excl );
+
+        String[] notIncl = new String[dirsNotIncluded.size()];
+        dirsNotIncluded.copyInto( notIncl );
+
+        for ( int i = 0; i < excl.length; i++ )
+        {
+            if ( !couldHoldIncluded( excl[i] ) )
+            {
+                scandir( new File( basedir, excl[i] ),
+                         excl[i] + File.separator, false );
+            }
+        }
+
+        for ( int i = 0; i < notIncl.length; i++ )
+        {
+            if ( !couldHoldIncluded( notIncl[i] ) )
+            {
+                scandir( new File( basedir, notIncl[i] ),
+                         notIncl[i] + File.separator, false );
+            }
+        }
+
+        haveSlowResults = true;
+    }
+
+    /**
+     * Scans the given directory for files and directories. Found files and
+     * directories are placed in their respective collections, based on the
+     * matching of includes, excludes, and the selectors.  When a directory
+     * is found, it is scanned recursively.
+     *
+     * @param dir   The directory to scan. Must not be <code>null</code>.
+     * @param vpath The path relative to the base directory (needed to
+     *              prevent problems with an absolute path when using
+     *              dir). Must not be <code>null</code>.
+     * @param fast  Whether or not this call is part of a fast scan.
+     * @throws IOException
+     *
+     * @see #filesIncluded
+     * @see #filesNotIncluded
+     * @see #filesExcluded
+     * @see #dirsIncluded
+     * @see #dirsNotIncluded
+     * @see #dirsExcluded
+     * @see #slowScan
+     */
+    protected void scandir( File dir, String vpath, boolean fast )
+    {
+        String[] newfiles = dir.list();
+
+        if ( newfiles == null )
+        {
+            /*
+             * two reasons are mentioned in the API docs for File.list
+             * (1) dir is not a directory. This is impossible as
+             *     we wouldn't get here in this case.
+             * (2) an IO error occurred (why doesn't it throw an exception
+             *     then???)
+             */
+
+
+            /*
+             * [jdcasey] (2) is apparently happening to me, as this is killing one of my tests...
+             * this is affecting the assembly plugin, fwiw. I will initialize the newfiles array as
+             * zero-length for now.
+             *
+             * NOTE: I can't find the problematic code, as it appears to come from a native method
+             * in UnixFileSystem...
+             */
+            /*
+             * [bentmann] A null array will also be returned from list() on NTFS when dir refers to a soft link or
+             * junction point whose target is not existent.
+             */
+            newfiles = new String[0];
+
+            // throw new IOException( "IO error scanning directory " + dir.getAbsolutePath() );
+        }
+
+        if ( !followSymlinks )
+        {
+            Vector noLinks = new Vector();
+            for ( int i = 0; i < newfiles.length; i++ )
+            {
+                try
+                {
+                    if ( isSymbolicLink( dir, newfiles[i] ) )
+                    {
+                        String name = vpath + newfiles[i];
+                        File file = new File( dir, newfiles[i] );
+                        if ( file.isDirectory() )
+                        {
+                            dirsExcluded.addElement( name );
+                        }
+                        else
+                        {
+                            filesExcluded.addElement( name );
+                        }
+                    }
+                    else
+                    {
+                        noLinks.addElement( newfiles[i] );
+                    }
+                }
+                catch ( IOException ioe )
+                {
+                    String msg = "IOException caught while checking "
+                        + "for links, couldn't get cannonical path!";
+                    // will be caught and redirected to Ant's logging system
+                    System.err.println( msg );
+                    noLinks.addElement( newfiles[i] );
+                }
+            }
+            newfiles = new String[noLinks.size()];
+            noLinks.copyInto( newfiles );
+        }
+
+        for ( int i = 0; i < newfiles.length; i++ )
+        {
+            String name = vpath + newfiles[i];
+            File file = new File( dir, newfiles[i] );
+            if ( file.isDirectory() )
+            {
+                if ( isIncluded( name ) )
+                {
+                    if ( !isExcluded( name ) )
+                    {
+                        if ( isSelected( name, file ) )
+                        {
+                            dirsIncluded.addElement( name );
+                            if ( fast )
+                            {
+                                scandir( file, name + File.separator, fast );
+                            }
+                        }
+                        else
+                        {
+                            everythingIncluded = false;
+                            dirsDeselected.addElement( name );
+                            if ( fast && couldHoldIncluded( name ) )
+                            {
+                                scandir( file, name + File.separator, fast );
+                            }
+                        }
+
+                    }
+                    else
+                    {
+                        everythingIncluded = false;
+                        dirsExcluded.addElement( name );
+                        if ( fast && couldHoldIncluded( name ) )
+                        {
+                            scandir( file, name + File.separator, fast );
+                        }
+                    }
+                }
+                else
+                {
+                    everythingIncluded = false;
+                    dirsNotIncluded.addElement( name );
+                    if ( fast && couldHoldIncluded( name ) )
+                    {
+                        scandir( file, name + File.separator, fast );
+                    }
+                }
+                if ( !fast )
+                {
+                    scandir( file, name + File.separator, fast );
+                }
+            }
+            else if ( file.isFile() )
+            {
+                if ( isIncluded( name ) )
+                {
+                    if ( !isExcluded( name ) )
+                    {
+                        if ( isSelected( name, file ) )
+                        {
+                            filesIncluded.addElement( name );
+                        }
+                        else
+                        {
+                            everythingIncluded = false;
+                            filesDeselected.addElement( name );
+                        }
+                    }
+                    else
+                    {
+                        everythingIncluded = false;
+                        filesExcluded.addElement( name );
+                    }
+                }
+                else
+                {
+                    everythingIncluded = false;
+                    filesNotIncluded.addElement( name );
+                }
+            }
+        }
+    }
+
+    /**
+     * Tests whether a name should be selected.
+     *
+     * @param name the filename to check for selecting
+     * @param file the java.io.File object for this filename
+     * @return <code>false</code> when the selectors says that the file
+     *         should not be selected, <code>true</code> otherwise.
+     */
+    protected boolean isSelected( String name, File file )
+    {
+        return true;
+    }
+
+    /**
+     * Returns the names of the files which matched at least one of the
+     * include patterns and none of the exclude patterns.
+     * The names are relative to the base directory.
+     *
+     * @return the names of the files which matched at least one of the
+     *         include patterns and none of the exclude patterns.
+     */
+    public String[] getIncludedFiles()
+    {
+        String[] files = new String[filesIncluded.size()];
+        filesIncluded.copyInto( files );
+        return files;
+    }
+
+    /**
+     * Returns the names of the files which matched none of the include
+     * patterns. The names are relative to the base directory. This involves
+     * performing a slow scan if one has not already been completed.
+     *
+     * @return the names of the files which matched none of the include
+     *         patterns.
+     *
+     * @see #slowScan
+     */
+    public String[] getNotIncludedFiles()
+    {
+        slowScan();
+        String[] files = new String[filesNotIncluded.size()];
+        filesNotIncluded.copyInto( files );
+        return files;
+    }
+
+    /**
+     * Returns the names of the files which matched at least one of the
+     * include patterns and at least one of the exclude patterns.
+     * The names are relative to the base directory. This involves
+     * performing a slow scan if one has not already been completed.
+     *
+     * @return the names of the files which matched at least one of the
+     *         include patterns and at at least one of the exclude patterns.
+     *
+     * @see #slowScan
+     */
+    public String[] getExcludedFiles()
+    {
+        slowScan();
+        String[] files = new String[filesExcluded.size()];
+        filesExcluded.copyInto( files );
+        return files;
+    }
+
+    /**
+     * <p>Returns the names of the files which were selected out and
+     * therefore not ultimately included.</p>
+     *
+     * <p>The names are relative to the base directory. This involves
+     * performing a slow scan if one has not already been completed.</p>
+     *
+     * @return the names of the files which were deselected.
+     *
+     * @see #slowScan
+     */
+    public String[] getDeselectedFiles()
+    {
+        slowScan();
+        String[] files = new String[filesDeselected.size()];
+        filesDeselected.copyInto( files );
+        return files;
+    }
+
+    /**
+     * Returns the names of the directories which matched at least one of the
+     * include patterns and none of the exclude patterns.
+     * The names are relative to the base directory.
+     *
+     * @return the names of the directories which matched at least one of the
+     * include patterns and none of the exclude patterns.
+     */
+    public String[] getIncludedDirectories()
+    {
+        String[] directories = new String[dirsIncluded.size()];
+        dirsIncluded.copyInto( directories );
+        return directories;
+    }
+
+    /**
+     * Returns the names of the directories which matched none of the include
+     * patterns. The names are relative to the base directory. This involves
+     * performing a slow scan if one has not already been completed.
+     *
+     * @return the names of the directories which matched none of the include
+     * patterns.
+     *
+     * @see #slowScan
+     */
+    public String[] getNotIncludedDirectories()
+    {
+        slowScan();
+        String[] directories = new String[dirsNotIncluded.size()];
+        dirsNotIncluded.copyInto( directories );
+        return directories;
+    }
+
+    /**
+     * Returns the names of the directories which matched at least one of the
+     * include patterns and at least one of the exclude patterns.
+     * The names are relative to the base directory. This involves
+     * performing a slow scan if one has not already been completed.
+     *
+     * @return the names of the directories which matched at least one of the
+     * include patterns and at least one of the exclude patterns.
+     *
+     * @see #slowScan
+     */
+    public String[] getExcludedDirectories()
+    {
+        slowScan();
+        String[] directories = new String[dirsExcluded.size()];
+        dirsExcluded.copyInto( directories );
+        return directories;
+    }
+
+    /**
+     * <p>Returns the names of the directories which were selected out and
+     * therefore not ultimately included.</p>
+     *
+     * <p>The names are relative to the base directory. This involves
+     * performing a slow scan if one has not already been completed.</p>
+     *
+     * @return the names of the directories which were deselected.
+     *
+     * @see #slowScan
+     */
+    public String[] getDeselectedDirectories()
+    {
+        slowScan();
+        String[] directories = new String[dirsDeselected.size()];
+        dirsDeselected.copyInto( directories );
+        return directories;
+    }
+
+    /**
+     * Checks whether a given file is a symbolic link.
+     *
+     * <p>It doesn't really test for symbolic links but whether the
+     * canonical and absolute paths of the file are identical - this
+     * may lead to false positives on some platforms.</p>
+     *
+     * @param parent the parent directory of the file to test
+     * @param name the name of the file to test.
+     *
+     * @since Ant 1.5
+     */
+    public boolean isSymbolicLink( File parent, String name )
+        throws IOException
+    {
+        File resolvedParent = new File( parent.getCanonicalPath() );
+        File toTest = new File( resolvedParent, name );
+        return !toTest.getAbsolutePath().equals( toTest.getCanonicalPath() );
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryScanner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryScanner.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryScanner.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalkListener.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalkListener.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalkListener.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalkListener.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,48 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/*
+ * Copyright The Codehaus 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.
+ */
+
+import java.io.File;
+
+/**
+ * DirectoryWalkListener
+ * @version $Id: DirectoryWalkListener.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public interface DirectoryWalkListener
+{
+    /**
+     * The directory walking has begun.
+     *
+     * @param basedir the basedir that walk started in.
+     */
+    void directoryWalkStarting( File basedir );
+
+    /**
+     * The included entry that was encountered.
+     *
+     * @param percentage rough percentage of the walk completed. (inaccurate)
+     * @param file the file that was included.
+     */
+    void directoryWalkStep( int percentage, File file );
+
+    /**
+     * The directory walking has finished.
+     */
+    void directoryWalkFinished();
+
+    void debug( String message );
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalkListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalkListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalkListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalker.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalker.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalker.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalker.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,443 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/*
+ * Copyright The Codehaus 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.
+ */
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Stack;
+
+/**
+ * DirectoryWalker
+ * @version $Id: DirectoryWalker.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class DirectoryWalker
+{
+    /**
+     * DirStackEntry is an Item on the {@link DirectoryWalker#dirStack}
+     */
+    class DirStackEntry
+    {
+        /**
+         * Count of files in the directory.
+         */
+        public int count;
+
+        /**
+         * Current Directory.
+         */
+        public File dir;
+
+        /**
+         * Index (or offset) within the directory count.
+         */
+        public int index;
+
+        /**
+         * Offset for percentage calculations. Based on parent DirStackEntry.
+         */
+        public double percentageOffset;
+
+        /**
+         * Size of percentage space to work with.
+         */
+        public double percentageSize;
+
+        /**
+         * Create a DirStackEntry.
+         *
+         * @param d the directory to track
+         * @param length the length of entries in the directory.
+         */
+        public DirStackEntry( File d, int length )
+        {
+            dir = d;
+            count = length;
+        }
+
+        /**
+         * Calculate the next percentage offset.
+         * Used by the next DirStackEntry.
+         *
+         * @return the value for the next percentage offset.
+         */
+        public double getNextPercentageOffset()
+        {
+            return percentageOffset + ( index * ( percentageSize / count ) );
+        }
+
+        /**
+         * Calculate the next percentage size.
+         * Used by the next DirStackEntry.
+         *
+         * @return the value for the next percentage size.
+         */
+        public double getNextPercentageSize()
+        {
+            return ( percentageSize / count );
+        }
+
+        /**
+         * The percentage of the DirStackEntry right now.
+         * Based on count, index, percentageOffset, and percentageSize.
+         *
+         * @return the percentage right now.
+         */
+        public int getPercentage()
+        {
+            double percentageWithinDir = (double) index / (double) count;
+            return (int) Math.floor( percentageOffset + ( percentageWithinDir * percentageSize ) );
+        }
+
+        public String toString()
+        {
+            return "DirStackEntry[" + "dir=" + dir.getAbsolutePath() + ",count=" + count + ",index=" + index
+                + ",percentageOffset=" + percentageOffset + ",percentageSize=" + percentageSize + ",percentage()="
+                + getPercentage() + ",getNextPercentageOffset()=" + getNextPercentageOffset()
+                + ",getNextPercentageSize()=" + getNextPercentageSize() + "]";
+        }
+    }
+
+    private File baseDir;
+
+    private int baseDirOffset;
+
+    private Stack dirStack;
+
+    private List excludes;
+
+    private List includes;
+
+    private boolean isCaseSensitive = true;
+
+    private List listeners;
+
+    private boolean debugEnabled = false;
+
+    public DirectoryWalker()
+    {
+        this.includes = new ArrayList();
+        this.excludes = new ArrayList();
+        this.listeners = new ArrayList();
+    }
+
+    public void addDirectoryWalkListener( DirectoryWalkListener listener )
+    {
+        this.listeners.add( listener );
+    }
+
+    public void addExclude( String exclude )
+    {
+        this.excludes.add( fixPattern( exclude ) );
+    }
+
+    public void addInclude( String include )
+    {
+        this.includes.add( fixPattern( include ) );
+    }
+
+    /**
+     * Add's to the Exclude List the default list of SCM excludes.
+     */
+    public void addSCMExcludes()
+    {
+        String scmexcludes[] = DirectoryScanner.DEFAULTEXCLUDES;
+        for ( int i = 0; i < scmexcludes.length; i++ )
+        {
+            addExclude( scmexcludes[i] );
+        }
+    }
+
+    private void fireStep( File file )
+    {
+        DirStackEntry dsEntry = (DirStackEntry) dirStack.peek();
+        int percentage = dsEntry.getPercentage();
+        Iterator it = this.listeners.iterator();
+        while ( it.hasNext() )
+        {
+            DirectoryWalkListener listener = (DirectoryWalkListener) it.next();
+            listener.directoryWalkStep( percentage, file );
+        }
+    }
+
+    private void fireWalkFinished()
+    {
+        Iterator it = this.listeners.iterator();
+        while ( it.hasNext() )
+        {
+            DirectoryWalkListener listener = (DirectoryWalkListener) it.next();
+            listener.directoryWalkFinished();
+        }
+    }
+
+    private void fireWalkStarting()
+    {
+        Iterator it = this.listeners.iterator();
+        while ( it.hasNext() )
+        {
+            DirectoryWalkListener listener = (DirectoryWalkListener) it.next();
+            listener.directoryWalkStarting( this.baseDir );
+        }
+    }
+
+    private void fireDebugMessage( String message )
+    {
+        Iterator it = this.listeners.iterator();
+        while ( it.hasNext() )
+        {
+            DirectoryWalkListener listener = (DirectoryWalkListener) it.next();
+            listener.debug( message );
+        }
+    }
+
+    private String fixPattern( String pattern )
+    {
+        String cleanPattern = pattern;
+
+        if ( File.separatorChar != '/' )
+        {
+            cleanPattern = cleanPattern.replace( '/', File.separatorChar );
+        }
+
+        if ( File.separatorChar != '\\' )
+        {
+            cleanPattern = cleanPattern.replace( '\\', File.separatorChar );
+        }
+
+        return cleanPattern;
+    }
+
+    public void setDebugMode( boolean debugEnabled )
+    {
+        this.debugEnabled = debugEnabled;
+    }
+
+    /**
+     * @return Returns the baseDir.
+     */
+    public File getBaseDir()
+    {
+        return baseDir;
+    }
+
+    /**
+     * @return Returns the excludes.
+     */
+    public List getExcludes()
+    {
+        return excludes;
+    }
+
+    /**
+     * @return Returns the includes.
+     */
+    public List getIncludes()
+    {
+        return includes;
+    }
+
+    private boolean isExcluded( String name )
+    {
+        return isMatch( this.excludes, name );
+    }
+
+    private boolean isIncluded( String name )
+    {
+        return isMatch( this.includes, name );
+    }
+
+    private boolean isMatch( List patterns, String name )
+    {
+        Iterator it = patterns.iterator();
+        while ( it.hasNext() )
+        {
+            String pattern = (String) it.next();
+            if ( SelectorUtils.matchPath( pattern, name, isCaseSensitive ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    private String relativeToBaseDir( File file )
+    {
+        return file.getAbsolutePath().substring( baseDirOffset + 1 );
+    }
+
+    /**
+     * Removes a DirectoryWalkListener.
+     *
+     * @param listener the listener to remove.
+     */
+    public void removeDirectoryWalkListener( DirectoryWalkListener listener )
+    {
+        this.listeners.remove( listener );
+    }
+
+    /**
+     * Performs a Scan against the provided {@link #setBaseDir(File)}
+     */
+    public void scan()
+    {
+        if ( baseDir == null )
+        {
+            throw new IllegalStateException( "Scan Failure.  BaseDir not specified." );
+        }
+
+        if ( !baseDir.exists() )
+        {
+            throw new IllegalStateException( "Scan Failure.  BaseDir does not exist." );
+        }
+
+        if ( !baseDir.isDirectory() )
+        {
+            throw new IllegalStateException( "Scan Failure.  BaseDir is not a directory." );
+        }
+
+        if ( this.includes.isEmpty() )
+        {
+            // default to include all.
+            addInclude( "**" );
+        }
+
+        if ( debugEnabled )
+        {
+            Iterator it;
+            StringBuffer dbg = new StringBuffer();
+            dbg.append( "DirectoryWalker Scan" );
+            dbg.append( "\n  Base Dir: " ).append( this.baseDir.getAbsolutePath() );
+            dbg.append( "\n  Includes: " );
+            it = this.includes.iterator();
+            while ( it.hasNext() )
+            {
+                String include = (String) it.next();
+                dbg.append( "\n    - \"" ).append( include ).append( "\"" );
+            }
+            dbg.append( "\n  Excludes: " );
+            it = this.excludes.iterator();
+            while ( it.hasNext() )
+            {
+                String exclude = (String) it.next();
+                dbg.append( "\n    - \"" ).append( exclude ).append( "\"" );
+            }
+            fireDebugMessage( dbg.toString() );
+        }
+
+        fireWalkStarting();
+        dirStack = new Stack();
+        scanDir( this.baseDir );
+        fireWalkFinished();
+    }
+
+    private void scanDir( File dir )
+    {
+        File files[] = dir.listFiles();
+
+        if ( files == null )
+        {
+            return;
+        }
+
+        DirStackEntry curStackEntry = new DirStackEntry( dir, files.length );
+        if ( dirStack.isEmpty() )
+        {
+            curStackEntry.percentageOffset = 0;
+            curStackEntry.percentageSize = 100;
+        }
+        else
+        {
+            DirStackEntry previousStackEntry = (DirStackEntry) dirStack.peek();
+            curStackEntry.percentageOffset = previousStackEntry.getNextPercentageOffset();
+            curStackEntry.percentageSize = previousStackEntry.getNextPercentageSize();
+        }
+
+        dirStack.push( curStackEntry );
+
+        for ( int idx = 0; idx < files.length; idx++ )
+        {
+            curStackEntry.index = idx;
+            String name = relativeToBaseDir( files[idx] );
+
+            if ( isExcluded( name ) )
+            {
+                fireDebugMessage( name + " is excluded." );
+                continue;
+            }
+
+            if ( files[idx].isDirectory() )
+            {
+                scanDir( files[idx] );
+            }
+            else
+            {
+                if ( isIncluded( name ) )
+                {
+                    fireStep( files[idx] );
+                }
+            }
+        }
+
+        dirStack.pop();
+    }
+
+    /**
+     * @param baseDir The baseDir to set.
+     */
+    public void setBaseDir( File baseDir )
+    {
+        this.baseDir = baseDir;
+        this.baseDirOffset = baseDir.getAbsolutePath().length();
+    }
+
+    /**
+     * @param entries The excludes to set.
+     */
+    public void setExcludes( List entries )
+    {
+        this.excludes.clear();
+        if ( entries != null )
+        {
+            Iterator it = entries.iterator();
+            while ( it.hasNext() )
+            {
+                String pattern = (String) it.next();
+                this.excludes.add( fixPattern( pattern ) );
+            }
+        }
+    }
+
+    /**
+     * @param entries The includes to set.
+     */
+    public void setIncludes( List entries )
+    {
+        this.includes.clear();
+        if ( entries != null )
+        {
+            Iterator it = entries.iterator();
+            while ( it.hasNext() )
+            {
+                String pattern = (String) it.next();
+                this.includes.add( fixPattern( pattern ) );
+            }
+        }
+    }
+
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalker.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/DirectoryWalker.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ExceptionUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ExceptionUtils.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ExceptionUtils.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ExceptionUtils.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,666 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.codehaus.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact codehaus@codehaus.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.codehaus.org/>.
+ */
+package org.apache.geronimo.system.plugin.plexus.util;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ * <p><code>ExceptionUtils</code> provides utilities for manipulating
+ * <code>Throwable</code> objects.</p>
+ *
+ * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
+ * @author Dmitri Plotnikov
+ * @author Stephen Colebourne
+ * @since 1.0
+ * @version $Id: ExceptionUtils.java 5958 2007-02-28 10:29:55Z olamy $
+ */
+public class ExceptionUtils
+{
+    /**
+     * Used when printing stack frames to denote the start of a
+     * wrapped exception.  Package private for accessibility by test
+     * suite.
+     */
+    static final String WRAPPED_MARKER = " [wrapped] ";
+
+    /**
+     * The names of methods commonly used to access a wrapped
+     * exception.
+     */
+    protected static String[] CAUSE_METHOD_NAMES = {
+        "getCause",
+        "getNextException",
+        "getTargetException",
+        "getException",
+        "getSourceException",
+        "getRootCause",
+        "getCausedByException",
+        "getNested"
+    };
+
+    /**
+     * Constructs a new <code>ExceptionUtils</code>. Protected to
+     * discourage instantiation.
+     */
+    protected ExceptionUtils()
+    {
+    }
+
+    /**
+     * <p>Adds to the list of method names used in the search for <code>Throwable</code>
+     * objects.</p>
+     *
+     * @param methodName  the methodName to add to the list, null and empty strings are ignored
+     */
+    public static void addCauseMethodName( String methodName )
+    {
+        if ( methodName != null && methodName.length() > 0 )
+        {
+            List list = new ArrayList( Arrays.asList( CAUSE_METHOD_NAMES ) );
+            list.add( methodName );
+            CAUSE_METHOD_NAMES = (String[]) list.toArray( new String[list.size()] );
+        }
+    }
+
+    /**
+     * <p>Introspects the specified <code>Throwable</code> to obtain the cause.</p>
+     *
+     * <p>The method searches for methods with specific names that return a
+     * <code>Throwable</code> object. This will pick up most wrapping exceptions,
+     * including those from JDK 1.4, and
+     * The method names can be added to using {@link #addCauseMethodName(String)}.
+     * The default list searched for are:</p>
+     * <ul>
+     * <li><code>getCause()</code>
+     * <li><code>getNextException()</code>
+     * <li><code>getTargetException()</code>
+     * <li><code>getException()</code>
+     * <li><code>getSourceException()</code>
+     * <li><code>getRootCause()</code>
+     * <li><code>getCausedByException()</code>
+     * <li><code>getNested()</code>
+     * </ul>
+     *
+     * <p>In the absence of any such method, the object is inspected for a
+     * <code>detail</code> field assignable to a <code>Throwable</code>.</p>
+     *
+     * <p>If none of the above is found, returns <code>null</code>.</p>
+     *
+     * @param throwable The exception to introspect for a cause.
+     * @return The cause of the <code>Throwable</code>.
+     * @throws NullPointerException if the throwable is null
+     */
+    public static Throwable getCause( Throwable throwable )
+    {
+        return getCause( throwable, CAUSE_METHOD_NAMES );
+    }
+
+    /**
+     * <p>Introspects the specified <code>Throwable</code> to obtain the cause
+     * using a supplied array of method names.</p>
+     *
+     * @param throwable The exception to introspect for a cause.
+     * @return The cause of the <code>Throwable</code>.
+     * @throws NullPointerException if the method names array is null or contains null
+     * @throws NullPointerException if the throwable is null
+     */
+    public static Throwable getCause( Throwable throwable, String[] methodNames )
+    {
+        Throwable cause = getCauseUsingWellKnownTypes( throwable );
+        if ( cause == null )
+        {
+            for ( int i = 0; i < methodNames.length; i++ )
+            {
+                cause = getCauseUsingMethodName( throwable, methodNames[i] );
+                if ( cause != null )
+                {
+                    break;
+                }
+            }
+
+            if ( cause == null )
+            {
+                cause = getCauseUsingFieldName( throwable, "detail" );
+            }
+        }
+        return cause;
+    }
+
+    /**
+     * <p>Walks through the exception chain to the last element -- the
+     * "root" of the tree -- using {@link #getCause(Throwable)}, and
+     * returns that exception.</p>
+     *
+     * @param throwable  the throwable to get the root cause for
+     * @return The root cause of the <code>Throwable</code>.
+     */
+    public static Throwable getRootCause( Throwable throwable )
+    {
+        Throwable cause = getCause( throwable );
+        if ( cause != null )
+        {
+            throwable = cause;
+            while ( ( throwable = getCause( throwable ) ) != null )
+            {
+                cause = throwable;
+            }
+        }
+        return cause;
+    }
+
+    /**
+     * <p>Uses <code>instanceof</code> checks to examine the exception,
+     * looking for well known types which could contain chained or
+     * wrapped exceptions.</p>
+     *
+     * @param throwable  the exception to examine
+     * @return The wrapped exception, or <code>null</code> if not
+     * found.
+     */
+    private static Throwable getCauseUsingWellKnownTypes( Throwable throwable )
+    {
+        if ( throwable instanceof SQLException )
+        {
+            return ( (SQLException) throwable ).getNextException();
+        }
+        else if ( throwable instanceof InvocationTargetException )
+        {
+            return ( (InvocationTargetException) throwable ).getTargetException();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * <p>Find a throwable by method name.</p>
+     *
+     * @param throwable  the exception to examine
+     * @param methodName  the name of the method to find and invoke
+     * @return The wrapped exception, or <code>null</code> if not
+     * found.
+     */
+    private static Throwable getCauseUsingMethodName( Throwable throwable, String methodName )
+    {
+        Method method = null;
+        try
+        {
+            method = throwable.getClass().getMethod( methodName, null );
+        }
+        catch ( NoSuchMethodException ignored )
+        {
+        }
+        catch ( SecurityException ignored )
+        {
+        }
+
+        if ( method != null && Throwable.class.isAssignableFrom( method.getReturnType() ) )
+        {
+            try
+            {
+                return (Throwable) method.invoke( throwable, new Object[0] );
+            }
+            catch ( IllegalAccessException ignored )
+            {
+            }
+            catch ( IllegalArgumentException ignored )
+            {
+            }
+            catch ( InvocationTargetException ignored )
+            {
+            }
+        }
+        return null;
+    }
+
+    /**
+     * <p>Find a throwable by field name.</p>
+     *
+     * @param throwable  the exception to examine
+     * @param fieldName  the name of the attribute to examine
+     * @return The wrapped exception, or <code>null</code> if not
+     * found.
+     */
+    private static Throwable getCauseUsingFieldName( Throwable throwable, String fieldName )
+    {
+        Field field = null;
+        try
+        {
+            field = throwable.getClass().getField( fieldName );
+        }
+        catch ( NoSuchFieldException ignored )
+        {
+        }
+        catch ( SecurityException ignored )
+        {
+        }
+
+        if ( field != null && Throwable.class.isAssignableFrom( field.getType() ) )
+        {
+            try
+            {
+                return (Throwable) field.get( throwable );
+            }
+            catch ( IllegalAccessException ignored )
+            {
+            }
+            catch ( IllegalArgumentException ignored )
+            {
+            }
+        }
+        return null;
+    }
+
+    /**
+     * <p>Returns the number of <code>Throwable</code> objects in the
+     * exception chain.</p>
+     *
+     * @param throwable  the exception to inspect
+     * @return The throwable count.
+     */
+    public static int getThrowableCount( Throwable throwable )
+    {
+        // Count the number of throwables
+        int count = 0;
+        while ( throwable != null )
+        {
+            count++;
+            throwable = ExceptionUtils.getCause( throwable );
+        }
+        return count;
+    }
+
+    /**
+     * <p>Returns the list of <code>Throwable</code> objects in the
+     * exception chain.</p>
+     *
+     * @param throwable  the exception to inspect
+     * @return The list of <code>Throwable</code> objects.
+     */
+    public static Throwable[] getThrowables( Throwable throwable )
+    {
+        List list = new ArrayList();
+        while ( throwable != null )
+        {
+            list.add( throwable );
+            throwable = ExceptionUtils.getCause( throwable );
+        }
+        return (Throwable[]) list.toArray( new Throwable[list.size()] );
+    }
+
+    /**
+     * <p>Delegates to {@link #indexOfThrowable(Throwable, Class, int)},
+     * starting the search at the beginning of the exception chain.</p>
+     *
+     * @see #indexOfThrowable(Throwable, Class, int)
+     */
+    public static int indexOfThrowable( Throwable throwable, Class type )
+    {
+        return indexOfThrowable( throwable, type, 0 );
+    }
+
+    /**
+     * <p>Returns the (zero based) index, of the first
+     * <code>Throwable</code> that matches the specified type in the
+     * exception chain of <code>Throwable</code> objects with an index
+     * greater than or equal to the specified index, or
+     * <code>-1</code> if the type is not found.</p>
+     *
+     * @param throwable  the exception to inspect
+     * @param type  <code>Class</code> to look for
+     * @param fromIndex  the (zero based) index of the starting
+     *  position in the chain to be searched
+     * @return the first occurrence of the type in the chain, or
+     *  <code>-1</code> if the type is not found
+     * @throws IndexOutOfBoundsException If the <code>fromIndex</code>
+     *  argument is negative or not less than the count of
+     *  <code>Throwable</code>s in the chain.
+     */
+    public static int indexOfThrowable( Throwable throwable, Class type, int fromIndex )
+    {
+        if ( fromIndex < 0 )
+        {
+            throw new IndexOutOfBoundsException( "Throwable index out of range: " + fromIndex );
+        }
+        Throwable[] throwables = ExceptionUtils.getThrowables( throwable );
+        if ( fromIndex >= throwables.length )
+        {
+            throw new IndexOutOfBoundsException( "Throwable index out of range: " + fromIndex );
+        }
+        for ( int i = fromIndex; i < throwables.length; i++ )
+        {
+            if ( throwables[i].getClass().equals( type ) )
+            {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * Prints a compact stack trace for the root cause of a throwable.
+     * The compact stack trace starts with the root cause and prints
+     * stack frames up to the place where it was caught and wrapped.
+     * Then it prints the wrapped exception and continues with stack frames
+     * until the wrapper exception is caught and wrapped again, etc.
+     * <p>
+     * The method is equivalent to t.printStackTrace() for throwables
+     * that don't have nested causes.
+     */
+    public static void printRootCauseStackTrace( Throwable t, PrintStream stream )
+    {
+        String trace[] = getRootCauseStackTrace( t );
+        for ( int i = 0; i < trace.length; i++ )
+        {
+            stream.println( trace[i] );
+        }
+        stream.flush();
+    }
+
+    /**
+     * Equivalent to printRootCauseStackTrace(t, System.err)
+     */
+    public static void printRootCauseStackTrace( Throwable t )
+    {
+        printRootCauseStackTrace( t, System.err );
+    }
+
+    /**
+     * Same as printRootCauseStackTrace(t, stream), except it takes
+     * a PrintWriter as an argument.
+     */
+    public static void printRootCauseStackTrace( Throwable t, PrintWriter writer )
+    {
+        String trace[] = getRootCauseStackTrace( t );
+        for ( int i = 0; i < trace.length; i++ )
+        {
+            writer.println( trace[i] );
+        }
+        writer.flush();
+    }
+
+    /**
+     * Creates a compact stack trace for the root cause of the supplied
+     * throwable.
+     *
+     * See <code>printRootCauseStackTrace(Throwable t, PrintStream s)</code>
+     */
+    public static String[] getRootCauseStackTrace( Throwable t )
+    {
+        Throwable throwables[] = getThrowables( t );
+        int count = throwables.length;
+        ArrayList frames = new ArrayList();
+        List nextTrace = getStackFrameList( throwables[count - 1] );
+        for ( int i = count; --i >= 0; )
+        {
+            List trace = nextTrace;
+            if ( i != 0 )
+            {
+                nextTrace = getStackFrameList( throwables[i - 1] );
+                removeCommonFrames( trace, nextTrace );
+            }
+            if ( i == count - 1 )
+            {
+                frames.add( throwables[i].toString() );
+            }
+            else
+            {
+                frames.add( WRAPPED_MARKER + throwables[i].toString() );
+            }
+            for ( int j = 0; j < trace.size(); j++ )
+            {
+                frames.add( trace.get( j ) );
+            }
+        }
+        return (String[]) frames.toArray( new String[0] );
+    }
+
+    /**
+     * Given two stack traces, removes common frames from the cause trace.
+     *
+     * @param causeFrames   stack trace of a cause throwable
+     * @param wrapperFrames stack trace of a wrapper throwable
+     */
+    private static void removeCommonFrames( List causeFrames, List wrapperFrames )
+    {
+        int causeFrameIndex = causeFrames.size() - 1;
+        int wrapperFrameIndex = wrapperFrames.size() - 1;
+        while ( causeFrameIndex >= 0 && wrapperFrameIndex >= 0 )
+        {
+            // Remove the frame from the cause trace if it is the same
+            // as in the wrapper trace
+            String causeFrame = (String) causeFrames.get( causeFrameIndex );
+            String wrapperFrame = (String) wrapperFrames.get( wrapperFrameIndex );
+            if ( causeFrame.equals( wrapperFrame ) )
+            {
+                causeFrames.remove( causeFrameIndex );
+            }
+            causeFrameIndex--;
+            wrapperFrameIndex--;
+        }
+    }
+
+    /**
+     * A convenient way of extracting the stack trace from an
+     * exception.
+     *
+     * @param t The <code>Throwable</code>.
+     * @return The stack trace as generated by the exception's
+     * <code>printStackTrace(PrintWriter)</code> method.
+     */
+    public static String getStackTrace( Throwable t )
+    {
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter( sw, true );
+        t.printStackTrace( pw );
+        return sw.getBuffer().toString();
+    }
+
+    /**
+     * A way to get the entire nested stack-trace of an throwable.
+     *
+     * @param t The <code>Throwable</code>.
+     * @return The nested stack trace, with the root cause first.
+     */
+    public static String getFullStackTrace( Throwable t )
+    {
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter( sw, true );
+        Throwable[] ts = getThrowables( t );
+        for ( int i = 0; i < ts.length; i++ )
+        {
+            ts[i].printStackTrace( pw );
+            if ( isNestedThrowable( ts[i] ) )
+            {
+                break;
+            }
+        }
+        return sw.getBuffer().toString();
+    }
+
+    /**
+     * Whether an Throwable is considered nested or not.
+     *
+     * @param throwable The <code>Throwable</code>.
+     * @return boolean true/false
+     */
+    public static boolean isNestedThrowable( Throwable throwable )
+    {
+        if ( throwable == null )
+        {
+            return false;
+        }
+
+        if ( throwable instanceof SQLException )
+        {
+            return true;
+        }
+        else if ( throwable instanceof InvocationTargetException )
+        {
+            return true;
+        }
+
+        int sz = CAUSE_METHOD_NAMES.length;
+        for ( int i = 0; i < sz; i++ )
+        {
+            try
+            {
+                Method method = throwable.getClass().getMethod( CAUSE_METHOD_NAMES[i], null );
+                if ( method != null )
+                {
+                    return true;
+                }
+            }
+            catch ( NoSuchMethodException ignored )
+            {
+            }
+            catch ( SecurityException ignored )
+            {
+            }
+        }
+
+        try
+        {
+            Field field = throwable.getClass().getField( "detail" );
+            if ( field != null )
+            {
+                return true;
+            }
+        }
+        catch ( NoSuchFieldException ignored )
+        {
+        }
+        catch ( SecurityException ignored )
+        {
+        }
+
+        return false;
+    }
+
+    /**
+     * Captures the stack trace associated with the specified
+     * <code>Throwable</code> object, decomposing it into a list of
+     * stack frames.
+     *
+     * @param t The <code>Throwable</code>.
+     * @return  An array of strings describing each stack frame.
+     */
+    public static String[] getStackFrames( Throwable t )
+    {
+        return getStackFrames( getStackTrace( t ) );
+    }
+
+    /**
+     * Functionality shared between the
+     * <code>getStackFrames(Throwable)</code> methods of this and the
+     * classes.
+     */
+    static String[] getStackFrames( String stackTrace )
+    {
+        String linebreak = System.getProperty( "line.separator" );
+        StringTokenizer frames = new StringTokenizer( stackTrace, linebreak );
+        List list = new LinkedList();
+        while ( frames.hasMoreTokens() )
+        {
+            list.add( frames.nextToken() );
+        }
+        return (String[]) list.toArray( new String[]{
+        } );
+    }
+
+    /**
+     * Produces a List of stack frames - the message is not included.
+     * This works in most cases - it will only fail if the exception message
+     * contains a line that starts with:  "   at".
+     *
+     * @param t is any throwable
+     * @return List of stack frames
+     */
+    static List getStackFrameList( Throwable t )
+    {
+        String stackTrace = getStackTrace( t );
+        String linebreak = System.getProperty( "line.separator" );
+        StringTokenizer frames = new StringTokenizer( stackTrace, linebreak );
+        List list = new LinkedList();
+        boolean traceStarted = false;
+        while ( frames.hasMoreTokens() )
+        {
+            String token = frames.nextToken();
+            // Determine if the line starts with <whitespace>at
+            int at = token.indexOf( "at" );
+            if ( at != -1 && token.substring( 0, at ).trim().length() == 0 )
+            {
+                traceStarted = true;
+                list.add( token );
+            }
+            else if ( traceStarted )
+            {
+                break;
+            }
+        }
+        return list;
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ExceptionUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ExceptionUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ExceptionUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Expand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Expand.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Expand.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Expand.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,242 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.codehaus.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact codehaus@codehaus.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.codehaus.org/>.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * Unzip a file.
+ *
+ * @author costin@dnt.ro
+ * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
+ * @author <a href="mailto:umagesh@codehaus.org">Magesh Umasankar</a>
+ * @since Ant 1.1 @ant.task category="packaging" name="unzip" name="unjar"
+ *      name="unwar"
+ * @version $Id: Expand.java 6695 2007-07-28 12:03:30Z hboutemy $
+ */
+public class Expand
+{
+    private File dest;//req
+
+    private File source;// req
+
+    private boolean overwrite = true;
+
+    /**
+     * Do the work.
+     *
+     * @exception Exception Thrown in unrecoverable error.
+     */
+    public void execute()
+        throws Exception
+    {
+        expandFile( source, dest );
+    }
+
+    /*
+     * This method is to be overridden by extending unarchival tasks.
+     */
+    /**
+     * Description of the Method
+     */
+    protected void expandFile( File srcF, File dir )
+        throws Exception
+    {
+        ZipInputStream zis = null;
+        try
+        {
+            // code from WarExpand
+            zis = new ZipInputStream( new FileInputStream( srcF ) );
+            ZipEntry ze = null;
+
+            while ( ( ze = zis.getNextEntry() ) != null )
+            {
+                extractFile( srcF,
+                             dir, zis,
+                             ze.getName(),
+                             new Date( ze.getTime() ),
+                             ze.isDirectory() );
+            }
+
+            //log("expand complete", Project.MSG_VERBOSE);
+        }
+        catch ( IOException ioe )
+        {
+            throw new Exception("Error while expanding " + srcF.getPath(), ioe);
+        }
+        finally
+        {
+            if ( zis != null )
+            {
+                try
+                {
+                    zis.close();
+                }
+                catch ( IOException e )
+                {
+                }
+            }
+        }
+    }
+
+    /**
+     * Description of the Method
+     */
+    protected void extractFile( File srcF,
+                                File dir,
+                                InputStream compressedInputStream,
+                                String entryName,
+                                Date entryDate,
+                                boolean isDirectory )
+        throws Exception
+    {
+        File f = FileUtils.resolveFile( dir, entryName );
+        try
+        {
+            if ( !overwrite && f.exists()
+                &&
+                f.lastModified() >= entryDate.getTime() )
+            {
+                return;
+            }
+
+            // create intermediary directories - sometimes zip don't add them
+            File dirF = f.getParentFile();
+            dirF.mkdirs();
+
+            if ( isDirectory )
+            {
+                f.mkdirs();
+            }
+            else
+            {
+                byte[] buffer = new byte[1024];
+                int length = 0;
+                FileOutputStream fos = null;
+                try
+                {
+                    fos = new FileOutputStream( f );
+
+                    while ( ( length =
+                        compressedInputStream.read( buffer ) ) >= 0 )
+                    {
+                        fos.write( buffer, 0, length );
+                    }
+
+                    fos.close();
+                    fos = null;
+                }
+                finally
+                {
+                    if ( fos != null )
+                    {
+                        try
+                        {
+                            fos.close();
+                        }
+                        catch ( IOException e )
+                        {
+                        }
+                    }
+                }
+            }
+
+            f.setLastModified( entryDate.getTime() );
+        }
+        catch ( FileNotFoundException ex )
+        {
+            throw new Exception( "Can't extract file " + srcF.getPath(), ex );
+        }
+
+    }
+
+    /**
+     * Set the destination directory. File will be unzipped into the destination
+     * directory.
+     *
+     * @param d Path to the directory.
+     */
+    public void setDest( File d )
+    {
+        this.dest = d;
+    }
+
+    /**
+     * Set the path to zip-file.
+     *
+     * @param s Path to zip-file.
+     */
+    public void setSrc( File s )
+    {
+        this.source = s;
+    }
+
+    /**
+     * Should we overwrite files in dest, even if they are newer than the
+     * corresponding entries in the archive?
+     */
+    public void setOverwrite( boolean b )
+    {
+        overwrite = b;
+    }
+}

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Expand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Expand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Expand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message