geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r821961 [22/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/cli/Commandline.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/cli/Commandline.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/Commandline.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/Commandline.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,782 @@
+package org.apache.geronimo.system.plugin.plexus.util.cli;
+
+/*
+ * 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.
+ */
+
+/***************************************************************************************************
+ * CruiseControl, a Continuous Integration Toolkit Copyright (c) 2001-2003, ThoughtWorks, Inc. 651 W
+ * Washington Ave. Suite 500 Chicago, IL 60661 USA All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted
+ * provided that the following conditions are met: + Redistributions of source code must retain the
+ * above copyright notice, this list of conditions and the following disclaimer. + 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. +
+ * Neither the name of ThoughtWorks, Inc., CruiseControl, nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 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 REGENTS OR 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.
+ **************************************************************************************************/
+
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ */
+
+import org.apache.geronimo.system.plugin.plexus.util.Os;
+import org.apache.geronimo.system.plugin.plexus.util.StringUtils;
+import org.apache.geronimo.system.plugin.plexus.util.cli.shell.BourneShell;
+import org.apache.geronimo.system.plugin.plexus.util.cli.shell.CmdShell;
+import org.apache.geronimo.system.plugin.plexus.util.cli.shell.CommandShell;
+import org.apache.geronimo.system.plugin.plexus.util.cli.shell.Shell;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Vector;
+
+/**
+ * <p/>
+ * Commandline objects help handling command lines specifying processes to
+ * execute.
+ * </p>
+ * <p/>
+ * The class can be used to define a command line as nested elements or as a
+ * helper to define a command line by an application.
+ * </p>
+ * <p/>
+ * <code>
+ * &lt;someelement&gt;<br>
+ * &nbsp;&nbsp;&lt;acommandline executable="/executable/to/run"&gt;<br>
+ * &nbsp;&nbsp;&nbsp;&nbsp;&lt;argument value="argument 1" /&gt;<br>
+ * &nbsp;&nbsp;&nbsp;&nbsp;&lt;argument line="argument_1 argument_2 argument_3" /&gt;<br>
+ * &nbsp;&nbsp;&nbsp;&nbsp;&lt;argument value="argument 4" /&gt;<br>
+ * &nbsp;&nbsp;&lt;/acommandline&gt;<br>
+ * &lt;/someelement&gt;<br>
+ * </code>
+ * </p>
+ * <p/>
+ * The element <code>someelement</code> must provide a method
+ * <code>createAcommandline</code> which returns an instance of this class.
+ * </p>
+ *
+ * @author thomas.haas@softwired-inc.com
+ * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
+ */
+public class Commandline
+    implements Cloneable
+{
+    /**
+     * @deprecated Use {@link org.apache.geronimo.system.plugin.plexus.util.Os} class instead.
+     */
+    protected static final String OS_NAME = "os.name";
+
+    /**
+     * @deprecated Use {@link org.apache.geronimo.system.plugin.plexus.util.Os} class instead.
+     */
+    protected static final String WINDOWS = "Windows";
+
+    protected Vector arguments = new Vector();
+
+    //protected Vector envVars = new Vector();
+    // synchronized added to preserve synchronize of Vector class
+    protected Map envVars = Collections.synchronizedMap( new LinkedHashMap() );
+
+    private long pid = -1;
+
+    private Shell shell;
+
+    /**
+     * @deprecated Use {@link Commandline#setExecutable(String)} instead.
+     */
+    protected String executable;
+
+    /**
+     * @deprecated Use {@link Commandline#setWorkingDirectory(File)} or
+     * {@link Commandline#setWorkingDirectory(String)} instead.
+     */
+    private File workingDir;
+
+    /**
+     * Create a new command line object.
+     * Shell is autodetected from operating system
+     *
+     * @param toProcess
+     */
+    public Commandline( String toProcess, Shell shell )
+    {
+        this.shell = shell;
+
+        String[] tmp = new String[0];
+        try
+        {
+            tmp = CommandLineUtils.translateCommandline( toProcess );
+        }
+        catch ( Exception e )
+        {
+            System.err.println( "Error translating Commandline." );
+        }
+        if ( ( tmp != null ) && ( tmp.length > 0 ) )
+        {
+            setExecutable( tmp[0] );
+            for ( int i = 1; i < tmp.length; i++ )
+            {
+                createArgument().setValue( tmp[i] );
+            }
+        }
+    }
+
+    /**
+     * Create a new command line object.
+     * Shell is autodetected from operating system
+     */
+    public Commandline( Shell shell )
+    {
+        this.shell = shell;
+    }
+
+    /**
+     * Create a new command line object.
+     * Shell is autodetected from operating system
+     *
+     * @param toProcess
+     */
+    public Commandline( String toProcess )
+    {
+        setDefaultShell();
+        String[] tmp = new String[0];
+        try
+        {
+            tmp = CommandLineUtils.translateCommandline( toProcess );
+        }
+        catch ( Exception e )
+        {
+            System.err.println( "Error translating Commandline." );
+        }
+        if ( ( tmp != null ) && ( tmp.length > 0 ) )
+        {
+            setExecutable( tmp[0] );
+            for ( int i = 1; i < tmp.length; i++ )
+            {
+                createArgument().setValue( tmp[i] );
+            }
+        }
+    }
+
+    /**
+     * Create a new command line object.
+     * Shell is autodetected from operating system
+     */
+    public Commandline()
+    {
+        setDefaultShell();
+    }
+
+    public long getPid()
+    {
+        if ( pid == -1 )
+        {
+            pid = Long.parseLong( String.valueOf( System.currentTimeMillis() ) );
+        }
+
+        return pid;
+    }
+
+    public void setPid( long pid )
+    {
+        this.pid = pid;
+    }
+
+    /**
+     * Class to keep track of the position of an Argument.
+     */
+    // <p>This class is there to support the srcfile and targetfile
+    // elements of &lt;execon&gt; and &lt;transform&gt; - don't know
+    // whether there might be additional use cases.</p> --SB
+    public class Marker
+    {
+
+        private int position;
+
+        private int realPos = -1;
+
+        Marker( int position )
+        {
+            this.position = position;
+        }
+
+        /**
+         * Return the number of arguments that preceeded this marker.
+         * <p/>
+         * <p>The name of the executable - if set - is counted as the
+         * very first argument.</p>
+         */
+        public int getPosition()
+        {
+            if ( realPos == -1 )
+            {
+                realPos = ( getExecutable() == null ? 0 : 1 );
+                for ( int i = 0; i < position; i++ )
+                {
+                    Arg arg = (Arg) arguments.elementAt( i );
+                    realPos += arg.getParts().length;
+                }
+            }
+            return realPos;
+        }
+    }
+
+    /**
+     * <p>Sets the shell or command-line interpretor for the detected operating system,
+     * and the shell arguments.</p>
+     */
+    private void setDefaultShell()
+    {
+        //If this is windows set the shell to command.com or cmd.exe with correct arguments.
+        if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
+        {
+            if ( Os.isFamily( Os.FAMILY_WIN9X ) )
+            {
+                setShell( new CommandShell() );
+            }
+            else
+            {
+                setShell( new CmdShell() );
+            }
+        }
+        else
+        {
+            setShell( new BourneShell() );
+        }
+    }
+
+    /**
+     * Creates an argument object.
+     * <p/>
+     * <p>Each commandline object has at most one instance of the
+     * argument class.  This method calls
+     * <code>this.createArgument(false)</code>.</p>
+     *
+     * @return the argument object.
+     * @see #createArgument(boolean)
+     * @deprecated Use {@link Commandline#createArg()} instead
+     */
+    public Argument createArgument()
+    {
+        return this.createArgument( false );
+    }
+
+    /**
+     * Creates an argument object and adds it to our list of args.
+     * <p/>
+     * <p>Each commandline object has at most one instance of the
+     * argument class.</p>
+     *
+     * @param insertAtStart if true, the argument is inserted at the
+     *                      beginning of the list of args, otherwise it is appended.
+     * @deprecated Use {@link Commandline#createArg(boolean)} instead
+     */
+    public Argument createArgument( boolean insertAtStart )
+    {
+        Argument argument = new Argument();
+        if ( insertAtStart )
+        {
+            arguments.insertElementAt( argument, 0 );
+        }
+        else
+        {
+            arguments.addElement( argument );
+        }
+        return argument;
+    }
+
+    /**
+     * Creates an argument object.
+     * <p/>
+     * <p>Each commandline object has at most one instance of the
+     * argument class.  This method calls
+     * <code>this.createArgument(false)</code>.</p>
+     *
+     * @return the argument object.
+     * @see #createArgument(boolean)
+     */
+    public Arg createArg()
+    {
+        return this.createArg( false );
+    }
+
+    /**
+     * Creates an argument object and adds it to our list of args.
+     * <p/>
+     * <p>Each commandline object has at most one instance of the
+     * argument class.</p>
+     *
+     * @param insertAtStart if true, the argument is inserted at the
+     *                      beginning of the list of args, otherwise it is appended.
+     */
+    public Arg createArg( boolean insertAtStart )
+    {
+        Arg argument = new Argument();
+        if ( insertAtStart )
+        {
+            arguments.insertElementAt( argument, 0 );
+        }
+        else
+        {
+            arguments.addElement( argument );
+        }
+        return argument;
+    }
+
+    /**
+     * Adds an argument object to our list of args.
+     *
+     * @return the argument object.
+     * @see #addArg(Arg,boolean)
+     */
+    public void addArg( Arg argument )
+    {
+        this.addArg( argument, false );
+    }
+
+    /**
+     * Adds an argument object to our list of args.
+     *
+     * @param insertAtStart if true, the argument is inserted at the
+     *                      beginning of the list of args, otherwise it is appended.
+     */
+    public void addArg( Arg argument, boolean insertAtStart )
+    {
+        if ( insertAtStart )
+        {
+            arguments.insertElementAt( argument, 0 );
+        }
+        else
+        {
+            arguments.addElement( argument );
+        }
+    }
+
+    /**
+     * Sets the executable to run.
+     */
+    public void setExecutable( String executable )
+    {
+        shell.setExecutable( executable );
+        this.executable = executable;
+    }
+
+    public String getExecutable()
+    {
+        String exec = shell.getExecutable();
+
+        if ( exec == null )
+        {
+            exec = executable;
+        }
+
+        return exec;
+    }
+
+    public void addArguments( String[] line )
+    {
+        for ( int i = 0; i < line.length; i++ )
+        {
+            createArgument().setValue( line[i] );
+        }
+    }
+
+    /**
+     * Add an environment variable
+     */
+    public void addEnvironment( String name, String value )
+    {
+        //envVars.add( name + "=" + value );
+        envVars.put( name, value );
+    }
+
+    /**
+     * Add system environment variables
+     */
+    public void addSystemEnvironment()
+        throws Exception
+    {
+        Properties systemEnvVars = CommandLineUtils.getSystemEnvVars();
+
+        for ( Iterator i = systemEnvVars.keySet().iterator(); i.hasNext(); )
+        {
+            String key = (String) i.next();
+            if ( !envVars.containsKey( key ) )
+            {
+                addEnvironment( key, systemEnvVars.getProperty( key ) );
+            }
+        }
+    }
+
+    /**
+     * Return the list of environment variables
+     */
+    public String[] getEnvironmentVariables()
+        throws CommandLineException
+    {
+        try
+        {
+            addSystemEnvironment();
+        }
+        catch ( Exception e )
+        {
+            throw new CommandLineException( "Error setting up environmental variables", e );
+        }
+        String[] environmentVars = new String[envVars.size()];
+        int i = 0;
+        for ( Iterator iterator = envVars.keySet().iterator(); iterator.hasNext(); )
+        {
+            String name = (String) iterator.next();
+            String value = (String) envVars.get( name );
+            environmentVars[i] = name + "=" + value;
+            i++;
+        }
+        return environmentVars;
+    }
+
+    /**
+     * Returns the executable and all defined arguments.
+     */
+    public String[] getCommandline()
+    {
+        final String[] args = getArguments();
+        String executable = getExecutable();
+
+        if ( executable == null )
+        {
+            return args;
+        }
+        final String[] result = new String[args.length + 1];
+        result[0] = executable;
+        System.arraycopy( args, 0, result, 1, args.length );
+        return result;
+    }
+
+    /**
+     * Returns the shell, executable and all defined arguments.
+     */
+    public String[] getShellCommandline()
+    {
+        // TODO: Provided only for backward compat. with <= 1.4
+        verifyShellState();
+
+        return (String[]) getShell().getShellCommandLine( getArguments() ).toArray( new String[0] );
+    }
+
+    /**
+     * Returns all arguments defined by <code>addLine</code>,
+     * <code>addValue</code> or the argument object.
+     */
+    public String[] getArguments()
+    {
+        Vector result = new Vector( arguments.size() * 2 );
+        for ( int i = 0; i < arguments.size(); i++ )
+        {
+            Argument arg = (Argument) arguments.elementAt( i );
+            String[] s = arg.getParts();
+            if ( s != null )
+            {
+                for ( int j = 0; j < s.length; j++ )
+                {
+                    result.addElement( s[j] );
+                }
+            }
+        }
+
+        String[] res = new String[result.size()];
+        result.copyInto( res );
+        return res;
+    }
+
+    public String toString()
+    {
+        return StringUtils.join( getShellCommandline(), " " );
+    }
+
+    public int size()
+    {
+        return getCommandline().length;
+    }
+
+    public Object clone()
+    {
+        Commandline c = new Commandline( (Shell) shell.clone() );
+        c.executable = executable;
+        c.workingDir = workingDir;
+        c.addArguments( getArguments() );
+        return c;
+    }
+
+    /**
+     * Clear out the whole command line.
+     */
+    public void clear()
+    {
+        executable = null;
+        workingDir = null;
+        shell.setExecutable( null );
+        shell.clearArguments();
+        arguments.removeAllElements();
+    }
+
+    /**
+     * Clear out the arguments but leave the executable in place for another operation.
+     */
+    public void clearArgs()
+    {
+        arguments.removeAllElements();
+    }
+
+    /**
+     * Return a marker.
+     * <p/>
+     * <p>This marker can be used to locate a position on the
+     * commandline - to insert something for example - when all
+     * parameters have been set.</p>
+     */
+    public Marker createMarker()
+    {
+        return new Marker( arguments.size() );
+    }
+
+    /**
+     * Sets execution directory.
+     */
+    public void setWorkingDirectory( String path )
+    {
+        shell.setWorkingDirectory( path );
+        workingDir = new File( path );
+    }
+
+    /**
+     * Sets execution directory.
+     */
+    public void setWorkingDirectory( File workingDirectory )
+    {
+        shell.setWorkingDirectory( workingDirectory );
+        workingDir = workingDirectory;
+    }
+
+    public File getWorkingDirectory()
+    {
+        File workDir = shell.getWorkingDirectory();
+
+        if ( workDir == null )
+        {
+            workDir = workingDir;
+        }
+
+        return workDir;
+    }
+
+    /**
+     * Executes the command.
+     */
+    public Process execute()
+        throws CommandLineException
+    {
+        // TODO: Provided only for backward compat. with <= 1.4
+        verifyShellState();
+
+        Process process;
+
+        //addEnvironment( "MAVEN_TEST_ENVAR", "MAVEN_TEST_ENVAR_VALUE" );
+
+        String[] environment = getEnvironmentVariables();
+
+        File workingDir = shell.getWorkingDirectory();
+
+        try
+        {
+            if ( workingDir == null )
+            {
+                process = Runtime.getRuntime().exec( getShellCommandline(), environment );
+            }
+            else
+            {
+                if ( !workingDir.exists() )
+                {
+                    throw new CommandLineException( "Working directory \"" + workingDir.getPath()
+                        + "\" does not exist!" );
+                }
+                else if ( !workingDir.isDirectory() )
+                {
+                    throw new CommandLineException( "Path \"" + workingDir.getPath()
+                        + "\" does not specify a directory." );
+                }
+
+                process = Runtime.getRuntime().exec( getShellCommandline(), environment, workingDir );
+            }
+        }
+        catch ( IOException ex )
+        {
+            throw new CommandLineException( "Error while executing process.", ex );
+        }
+
+        return process;
+    }
+
+    /**
+     * @deprecated Remove once backward compat with plexus-utils <= 1.4 is no longer a consideration
+     */
+    private void verifyShellState()
+    {
+        if ( shell.getWorkingDirectory() == null )
+        {
+            shell.setWorkingDirectory( workingDir );
+        }
+
+        if ( shell.getExecutable() == null )
+        {
+            shell.setExecutable( executable );
+        }
+    }
+
+    public Properties getSystemEnvVars()
+        throws Exception
+    {
+        return CommandLineUtils.getSystemEnvVars();
+    }
+
+    /**
+     * Allows to set the shell to be used in this command line.
+     *
+     * @param shell
+     * @since 1.2
+     */
+    public void setShell( Shell shell )
+    {
+        this.shell = shell;
+    }
+
+    /**
+     * Get the shell to be used in this command line.
+     *
+     * @since 1.2
+     */
+    public Shell getShell()
+    {
+        return shell;
+    }
+
+    /**
+     * @deprecated Use {@link CommandLineUtils#translateCommandline(String)} instead.
+     */
+    public static String[] translateCommandline( String toProcess )
+        throws Exception
+    {
+        return CommandLineUtils.translateCommandline( toProcess );
+    }
+
+    /**
+     * @deprecated Use {@link CommandLineUtils#quote(String)} instead.
+     */
+    public static String quoteArgument( String argument )
+        throws CommandLineException
+    {
+        return CommandLineUtils.quote( argument );
+    }
+
+    /**
+     * @deprecated Use {@link CommandLineUtils#toString(String[])} instead.
+     */
+    public static String toString( String[] line )
+    {
+        return CommandLineUtils.toString( line );
+    }
+
+    public static class Argument
+        implements Arg
+    {
+        private String[] parts;
+
+        /* (non-Javadoc)
+         * @see org.apache.geronimo.system.plugin.plexus.util.cli.Argumnt#setValue(java.lang.String)
+         */
+        public void setValue( String value )
+        {
+            if ( value != null )
+            {
+                parts = new String[] { value };
+            }
+        }
+
+        /* (non-Javadoc)
+         * @see org.apache.geronimo.system.plugin.plexus.util.cli.Argumnt#setLine(java.lang.String)
+         */
+        public void setLine( String line )
+        {
+            if ( line == null )
+            {
+                return;
+            }
+            try
+            {
+                parts = CommandLineUtils.translateCommandline( line );
+            }
+            catch ( Exception e )
+            {
+                System.err.println( "Error translating Commandline." );
+            }
+        }
+
+        /* (non-Javadoc)
+         * @see org.apache.geronimo.system.plugin.plexus.util.cli.Argumnt#setFile(java.io.File)
+         */
+        public void setFile( File value )
+        {
+            parts = new String[] { value.getAbsolutePath() };
+        }
+
+        /* (non-Javadoc)
+         * @see org.apache.geronimo.system.plugin.plexus.util.cli.Argumnt#getParts()
+         */
+        public String[] getParts()
+        {
+            return parts;
+        }
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/Commandline.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/cli/DefaultConsumer.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/cli/DefaultConsumer.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/DefaultConsumer.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/DefaultConsumer.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,30 @@
+package org.apache.geronimo.system.plugin.plexus.util.cli;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id: DefaultConsumer.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class DefaultConsumer
+    implements StreamConsumer
+{
+    public void consumeLine( String line )
+    {
+        System.out.println( line );
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/DefaultConsumer.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/cli/EnhancedStringTokenizer.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/cli/EnhancedStringTokenizer.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/EnhancedStringTokenizer.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/EnhancedStringTokenizer.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,138 @@
+package org.apache.geronimo.system.plugin.plexus.util.cli;
+
+/*
+ * 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.StringTokenizer;
+
+/**
+ * The java.util.StringTokenizer is horribly broken.
+ * Given the string  1,,,3,,4      (, delim)
+ * It will return 1,3,4
+ * Which is clearly wrong - 1,EMPTY,EMPTY,3,EMPTY,4 is what it should return
+ * @version $Id: EnhancedStringTokenizer.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public final class EnhancedStringTokenizer
+{
+    private StringTokenizer cst = null;
+
+    String cdelim;
+
+    final boolean cdelimSingleChar;
+
+    final char cdelimChar;
+
+    boolean creturnDelims;
+
+    String lastToken = null;
+
+    boolean delimLast = true;
+
+    public EnhancedStringTokenizer( String str )
+    {
+        this( str, " \t\n\r\f", false );
+    }
+
+    public EnhancedStringTokenizer( String str, String delim )
+    {
+        this( str, delim, false );
+    }
+
+    public EnhancedStringTokenizer( String str, String delim, boolean returnDelims )
+    {
+        cst = new StringTokenizer( str, delim, true );
+        cdelim = delim;
+        creturnDelims = returnDelims;
+        cdelimSingleChar = ( delim.length() == 1 );
+        cdelimChar = delim.charAt( 0 );
+    }
+
+    public boolean hasMoreTokens()
+    {
+        return cst.hasMoreTokens();
+    }
+
+    private String internalNextToken()
+    {
+        if ( lastToken != null )
+        {
+            String last = lastToken;
+            lastToken = null;
+            return last;
+        }
+
+        String token = cst.nextToken();
+        if ( isDelim( token ) )
+        {
+            if ( delimLast )
+            {
+                lastToken = token;
+                return "";
+            }
+            else
+            {
+                delimLast = true;
+                return token;
+            }
+        }
+        else
+        {
+            delimLast = false;
+            return token;
+        }
+    }
+
+    public String nextToken()
+    {
+        String token = internalNextToken();
+        if ( creturnDelims )
+        {
+            return token;
+        }
+        if ( isDelim( token ) )
+        {
+            return hasMoreTokens() ? internalNextToken() : "";
+        }
+        else
+        {
+            return token;
+        }
+    }
+
+    private boolean isDelim( String str )
+    {
+        if ( str.length() == 1 )
+        {
+            char ch = str.charAt( 0 );
+            if ( cdelimSingleChar )
+            {
+                if ( cdelimChar == ch )
+                {
+                    return true;
+                }
+            }
+            else
+            {
+                if ( cdelim.indexOf( ch ) >= 0 )
+                {
+                    return true;
+                }
+            }
+        }
+        return false;
+
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/EnhancedStringTokenizer.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/cli/StreamConsumer.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/cli/StreamConsumer.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/StreamConsumer.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/StreamConsumer.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,71 @@
+package org.apache.geronimo.system.plugin.plexus.util.cli;
+
+/*
+ * 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.
+ */
+
+/********************************************************************************
+ * CruiseControl, a Continuous Integration Toolkit
+ * Copyright (c) 2003, ThoughtWorks, Inc.
+ * 651 W Washington Ave. Suite 500
+ * Chicago, IL 60661 USA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *     + Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *
+ *     + 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.
+ *
+ *     + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
+ *       names of its contributors may be used to endorse or promote
+ *       products derived from this software without specific prior
+ *       written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS 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 REGENTS OR
+ * 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.
+ ********************************************************************************/
+
+/**
+ * Works in concert with the StreamPumper class to
+ * allow implementations to gain access to the lines being
+ * "Pumped".
+ *
+ * @author <a href="mailto:fvancea@maxiq.com">Florin Vancea</a>
+ * @author <a href="mailto:pj@thoughtworks.com">Paul Julius</a>
+ * @version $Id: StreamConsumer.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public interface StreamConsumer
+{
+    /**
+     * Called when the StreamPumper pumps a line from the Stream.
+     */
+    public void consumeLine( String line );
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/StreamConsumer.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/cli/StreamFeeder.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/cli/StreamFeeder.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/StreamFeeder.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/StreamFeeder.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,143 @@
+package org.apache.geronimo.system.plugin.plexus.util.cli;
+
+/*
+ * 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.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Read from an InputStream and write the output to an OutputStream.
+ *
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @version $Id: StreamFeeder.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class StreamFeeder
+    extends Thread
+{
+    private InputStream input;
+
+    private OutputStream output;
+
+    private boolean done;
+
+    /**
+     * Create a new StreamFeeder
+     *
+     * @param input  Stream to read from
+     * @param output Stream to write to
+     */
+    public StreamFeeder( InputStream input, OutputStream output )
+    {
+        this.input = input;
+
+        this.output = output;
+    }
+
+    // ----------------------------------------------------------------------
+    // Runnable implementation
+    // ----------------------------------------------------------------------
+
+    public void run()
+    {
+        try
+        {
+            feed();
+        }
+        catch ( Throwable ex )
+        {
+            // Catched everything so the streams will be closed and flagged as done.
+        }
+        finally
+        {
+            close();
+
+            done = true;
+
+            synchronized ( this )
+            {
+                this.notifyAll();
+            }
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    public void close()
+    {
+        if ( input != null )
+        {
+            synchronized ( input )
+            {
+                try
+                {
+                    input.close();
+                }
+                catch ( IOException ex )
+                {
+                    // ignore
+                }
+
+                input = null;
+            }
+        }
+
+        if ( output != null )
+        {
+            synchronized ( output )
+            {
+                try
+                {
+                    output.close();
+                }
+                catch ( IOException ex )
+                {
+                    // ignore
+                }
+
+                output = null;
+            }
+        }
+    }
+
+    public boolean isDone()
+    {
+        return done;
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    private void feed()
+        throws IOException
+    {
+        int data = input.read();
+
+        while ( !done && data != -1 )
+        {
+            synchronized ( output )
+            {
+                output.write( data );
+
+                data = input.read();
+            }
+        }
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/StreamFeeder.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/cli/StreamPumper.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/cli/StreamPumper.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/StreamPumper.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/StreamPumper.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,190 @@
+package org.apache.geronimo.system.plugin.plexus.util.cli;
+
+/*
+ * 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.
+ */
+
+/********************************************************************************
+ * CruiseControl, a Continuous Integration Toolkit
+ * Copyright (c) 2001-2003, ThoughtWorks, Inc.
+ * 651 W Washington Ave. Suite 500
+ * Chicago, IL 60661 USA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *     + Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *
+ *     + 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.
+ *
+ *     + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
+ *       names of its contributors may be used to endorse or promote
+ *       products derived from this software without specific prior
+ *       written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS 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 REGENTS OR
+ * 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.
+ ********************************************************************************/
+
+/* ====================================================================
+ * 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.
+ * ====================================================================
+ */
+
+import org.apache.geronimo.system.plugin.plexus.util.IOUtil;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+
+/**
+ * Class to pump the error stream during Process's runtime. Copied from the Ant
+ * built-in task.
+ *
+ * @author <a href="mailto:fvancea@maxiq.com">Florin Vancea </a>
+ * @author <a href="mailto:pj@thoughtworks.com">Paul Julius </a>
+ * @since June 11, 2001
+ * @version $Id: StreamPumper.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class StreamPumper
+    extends Thread
+{
+    private BufferedReader in;
+
+    private StreamConsumer consumer = null;
+
+    private PrintWriter out = null;
+
+    private static final int SIZE = 1024;
+
+    boolean done;
+
+    public StreamPumper( InputStream in )
+    {
+        this.in = new BufferedReader( new InputStreamReader( in ), SIZE );
+    }
+
+    public StreamPumper( InputStream in, StreamConsumer consumer )
+    {
+        this( in );
+
+        this.consumer = consumer;
+    }
+
+    public StreamPumper( InputStream in, PrintWriter writer )
+    {
+        this( in );
+
+        out = writer;
+    }
+
+    public StreamPumper( InputStream in, PrintWriter writer, StreamConsumer consumer )
+    {
+        this( in );
+        this.out = writer;
+        this.consumer = consumer;
+    }
+
+    public void run()
+    {
+        try
+        {
+            String s = in.readLine();
+
+            while ( s != null )
+            {
+                consumeLine( s );
+
+                if ( out != null )
+                {
+                    out.println( s );
+
+                    out.flush();
+                }
+
+                s = in.readLine();
+            }
+        }
+        catch ( Throwable e )
+        {
+            // Catched everything so the streams will be closed and flagged as done.
+        }
+        finally
+        {
+            IOUtil.close( in );
+
+            done = true;
+
+            synchronized ( this )
+            {
+                this.notifyAll();
+            }
+        }
+    }
+
+    public void flush()
+    {
+        if ( out != null )
+        {
+            out.flush();
+        }
+    }
+
+    public void close()
+    {
+        IOUtil.close( out );
+    }
+
+    public boolean isDone()
+    {
+        return done;
+    }
+
+    private void consumeLine( String line )
+    {
+        if ( consumer != null )
+        {
+            consumer.consumeLine( line );
+        }
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/StreamPumper.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/cli/WriterStreamConsumer.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/cli/WriterStreamConsumer.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/WriterStreamConsumer.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/WriterStreamConsumer.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,42 @@
+package org.apache.geronimo.system.plugin.plexus.util.cli;
+
+/*
+ * 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.PrintWriter;
+import java.io.Writer;
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id: WriterStreamConsumer.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class WriterStreamConsumer
+    implements StreamConsumer
+{
+    private PrintWriter writer;
+
+    public WriterStreamConsumer( Writer writer )
+    {
+        this.writer = new PrintWriter( writer );
+    }
+
+    public void consumeLine( String line )
+    {
+        writer.println( line );
+
+        writer.flush();
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/WriterStreamConsumer.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/cli/shell/BourneShell.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/cli/shell/BourneShell.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/BourneShell.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/BourneShell.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,170 @@
+package org.apache.geronimo.system.plugin.plexus.util.cli.shell;
+
+/*
+ * 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 org.apache.geronimo.system.plugin.plexus.util.Os;
+import org.apache.geronimo.system.plugin.plexus.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Jason van Zyl
+ * @version $Id: BourneShell.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class BourneShell
+    extends Shell
+{
+    private static final char[] BASH_QUOTING_TRIGGER_CHARS = {
+        ' ',
+        '$',
+        ';',
+        '&',
+        '|',
+        '<',
+        '>',
+        '*',
+        '?',
+        '(',
+        ')',
+        '[',
+        ']',
+        '{',
+        '}',
+        '`' };
+
+    public BourneShell()
+    {
+        this( false );
+    }
+
+    public BourneShell( boolean isLoginShell )
+    {
+        setShellCommand( "/bin/sh" );
+        setArgumentQuoteDelimiter( '\'' );
+        setExecutableQuoteDelimiter( '\"' );
+        setSingleQuotedArgumentEscaped( true );
+        setSingleQuotedExecutableEscaped( false );
+        setQuotedExecutableEnabled( true );
+
+        if ( isLoginShell )
+        {
+            addShellArg( "-l" );
+        }
+    }
+
+    /** {@inheritDoc} */
+    public String getExecutable()
+    {
+        if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
+        {
+            return super.getExecutable();
+        }
+
+        return unifyQuotes( super.getExecutable());
+    }
+
+    public List getShellArgsList()
+    {
+        List shellArgs = new ArrayList();
+        List existingShellArgs = super.getShellArgsList();
+
+        if ( ( existingShellArgs != null ) && !existingShellArgs.isEmpty() )
+        {
+            shellArgs.addAll( existingShellArgs );
+        }
+
+        shellArgs.add( "-c" );
+
+        return shellArgs;
+    }
+
+    public String[] getShellArgs()
+    {
+        String[] shellArgs = super.getShellArgs();
+        if ( shellArgs == null )
+        {
+            shellArgs = new String[0];
+        }
+
+        if ( ( shellArgs.length > 0 ) && !shellArgs[shellArgs.length - 1].equals( "-c" ) )
+        {
+            String[] newArgs = new String[shellArgs.length + 1];
+
+            System.arraycopy( shellArgs, 0, newArgs, 0, shellArgs.length );
+            newArgs[shellArgs.length] = "-c";
+
+            shellArgs = newArgs;
+        }
+
+        return shellArgs;
+    }
+
+    protected String getExecutionPreamble()
+    {
+        if ( getWorkingDirectoryAsString() == null )
+        {
+            return null;
+        }
+
+        String dir = getWorkingDirectoryAsString();
+        StringBuffer sb = new StringBuffer();
+        sb.append( "cd " );
+
+        sb.append( unifyQuotes( dir ) );
+        sb.append( " && " );
+
+        return sb.toString();
+    }
+
+    protected char[] getQuotingTriggerChars()
+    {
+        return BASH_QUOTING_TRIGGER_CHARS;
+    }
+
+    /**
+     * <p>Unify quotes in a path for the Bourne Shell.</p>
+     *
+     * <pre>
+     * BourneShell.unifyQuotes(null)                       = null
+     * BourneShell.unifyQuotes("")                         = (empty)
+     * BourneShell.unifyQuotes("/test/quotedpath'abc")     = /test/quotedpath\'abc
+     * BourneShell.unifyQuotes("/test/quoted path'abc")    = "/test/quoted path'abc"
+     * BourneShell.unifyQuotes("/test/quotedpath\"abc")    = "/test/quotedpath\"abc"
+     * BourneShell.unifyQuotes("/test/quoted path\"abc")   = "/test/quoted path\"abc"
+     * BourneShell.unifyQuotes("/test/quotedpath\"'abc")   = "/test/quotedpath\"'abc"
+     * BourneShell.unifyQuotes("/test/quoted path\"'abc")  = "/test/quoted path\"'abc"
+     * </pre>
+     *
+     * @param path not null path.
+     * @return the path unified correctly for the Bourne shell.
+     */
+    protected static String unifyQuotes( String path )
+    {
+        if ( path == null )
+        {
+            return null;
+        }
+
+        if ( path.indexOf( " " ) == -1 && path.indexOf( "'" ) != -1 && path.indexOf( "\"" ) == -1 )
+        {
+            return StringUtils.escape( path );
+        }
+
+        return StringUtils.quoteAndEscape( path, '\"', BASH_QUOTING_TRIGGER_CHARS );
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/BourneShell.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/cli/shell/CmdShell.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/cli/shell/CmdShell.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/CmdShell.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/CmdShell.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,89 @@
+package org.apache.geronimo.system.plugin.plexus.util.cli.shell;
+
+/*
+ * 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.Arrays;
+import java.util.List;
+
+/**
+ * <p>
+ * Implementation to call the CMD Shell present on Windows NT, 2000 and XP
+ * </p>
+ *
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @since 1.2
+ * @version $Id: CmdShell.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class CmdShell
+    extends Shell
+{
+    public CmdShell()
+    {
+        setShellCommand( "cmd.exe" );
+        setQuotedExecutableEnabled( true );
+        setShellArgs( new String[]{"/X", "/C"} );
+    }
+
+    /**
+     * <p>
+     * Specific implementation that quotes all the command line.
+     * </p>
+     * <p>
+     * Workaround for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6468220
+     * </p>
+     * <p>
+     * From cmd.exe /? output:
+     * </p>
+     *
+     * <pre>
+     *      If /C or /K is specified, then the remainder of the command line after
+     *      the switch is processed as a command line, where the following logic is
+     *      used to process quote (&quot;) characters:
+     *
+     *      1.  If all of the following conditions are met, then quote characters
+     *      on the command line are preserved:
+     *
+     *      - no /S switch
+     *      - exactly two quote characters
+     *      - no special characters between the two quote characters,
+     *      where special is one of: &amp;&lt;&gt;()@&circ;|
+     *      - there are one or more whitespace characters between the
+     *      the two quote characters
+     *      - the string between the two quote characters is the name
+     *      of an executable file.
+     *
+     *      2.  Otherwise, old behavior is to see if the first character is
+     *      a quote character and if so, strip the leading character and
+     *      remove the last quote character on the command line, preserving
+     *      any text after the last quote character.
+     * </pre>
+     *
+     *<p>
+     * Always quoting the entire command line, regardless of these conditions
+     * appears to make Windows processes invoke successfully.
+     * </p>
+     */
+    public List getCommandLine( String executable, String[] arguments )
+    {
+        StringBuffer sb = new StringBuffer();
+        sb.append( "\"" );
+        sb.append( super.getCommandLine( executable, arguments ).get( 0 ) );
+        sb.append( "\"" );
+
+        return Arrays.asList( new String[] { sb.toString() } );
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/CmdShell.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/cli/shell/CommandShell.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/cli/shell/CommandShell.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/CommandShell.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/CommandShell.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,37 @@
+package org.apache.geronimo.system.plugin.plexus.util.cli.shell;
+
+/*
+ * 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.
+ */
+
+/**
+ * <p>
+ * Implementation to call the Command.com Shell present on Windows 95, 98 and Me
+ * </p>
+ *
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @since 1.2
+ * @version $Id: CommandShell.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class CommandShell
+    extends Shell
+{
+    public CommandShell()
+    {
+        setShellCommand( "command.com" );
+        setShellArgs( new String[]{"/C"} );
+    }
+
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/CommandShell.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/cli/shell/Shell.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/cli/shell/Shell.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/Shell.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/Shell.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,399 @@
+package org.apache.geronimo.system.plugin.plexus.util.cli.shell;
+
+/*
+ * 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 org.apache.geronimo.system.plugin.plexus.util.StringUtils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * <p>
+ * Class that abstracts the Shell functionality,
+ * with subclases for shells that behave particularly, like
+ * <ul>
+ * <li><code>command.com</code></li>
+ * <li><code>cmd.exe</code></li>
+ * </ul>
+ * </p>
+ *
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @since 1.2
+ * @version $Id: Shell.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class Shell
+    implements Cloneable
+{
+    private static final char[] DEFAULT_QUOTING_TRIGGER_CHARS = { ' ' };
+
+    private String shellCommand;
+
+    private List shellArgs = new ArrayList();
+
+    private boolean quotedArgumentsEnabled = true;
+
+    private String executable;
+
+    private String workingDir;
+
+    private boolean quotedExecutableEnabled = true;
+
+    private boolean doubleQuotedArgumentEscaped = false;
+
+    private boolean singleQuotedArgumentEscaped = false;
+
+    private boolean doubleQuotedExecutableEscaped = false;
+
+    private boolean singleQuotedExecutableEscaped = false;
+
+    private char argQuoteDelimiter = '\"';
+
+    private char exeQuoteDelimiter = '\"';
+
+    /**
+     * Set the command to execute the shell (eg. COMMAND.COM, /bin/bash,...)
+     *
+     * @param shellCommand
+     */
+    public void setShellCommand( String shellCommand )
+    {
+        this.shellCommand = shellCommand;
+    }
+
+    /**
+     * Get the command to execute the shell
+     *
+     * @return
+     */
+    public String getShellCommand()
+    {
+        return shellCommand;
+    }
+
+    /**
+     * Set the shell arguments when calling a command line (not the executable arguments)
+     * (eg. /X /C for CMD.EXE)
+     *
+     * @param shellArgs
+     */
+    public void setShellArgs( String[] shellArgs )
+    {
+        this.shellArgs.clear();
+        this.shellArgs.addAll( Arrays.asList( shellArgs ) );
+    }
+
+    /**
+     * Get the shell arguments
+     *
+     * @return
+     */
+    public String[] getShellArgs()
+    {
+        if ( ( shellArgs == null ) || shellArgs.isEmpty() )
+        {
+            return null;
+        }
+        else
+        {
+            return (String[]) shellArgs.toArray( new String[shellArgs.size()] );
+        }
+    }
+
+    /**
+     * Get the command line for the provided executable and arguments in this shell
+     *
+     * @param executable executable that the shell has to call
+     * @param arguments  arguments for the executable, not the shell
+     * @return List with one String object with executable and arguments quoted as needed
+     */
+    public List getCommandLine( String executable, String[] arguments )
+    {
+        return getRawCommandLine( executable, arguments );
+    }
+
+    protected List getRawCommandLine( String executable, String[] arguments )
+    {
+        List commandLine = new ArrayList();
+        StringBuffer sb = new StringBuffer();
+
+        if ( executable != null )
+        {
+            String preamble = getExecutionPreamble();
+            if ( preamble != null )
+            {
+                sb.append( preamble );
+            }
+
+            if ( isQuotedExecutableEnabled() )
+            {
+                char[] escapeChars = getEscapeChars( isSingleQuotedExecutableEscaped(), isDoubleQuotedExecutableEscaped() );
+
+                sb.append( StringUtils.quoteAndEscape( getExecutable(), getExecutableQuoteDelimiter(), escapeChars, getQuotingTriggerChars(), '\\', false ) );
+            }
+            else
+            {
+                sb.append( getExecutable() );
+            }
+        }
+        for ( int i = 0; i < arguments.length; i++ )
+        {
+            if ( sb.length() > 0 )
+            {
+                sb.append( " " );
+            }
+
+            if ( isQuotedArgumentsEnabled() )
+            {
+                char[] escapeChars = getEscapeChars( isSingleQuotedExecutableEscaped(), isDoubleQuotedExecutableEscaped() );
+
+                sb.append( StringUtils.quoteAndEscape( arguments[i], getArgumentQuoteDelimiter(), escapeChars, getQuotingTriggerChars(), '\\', false ) );
+            }
+            else
+            {
+                sb.append( arguments[i] );
+            }
+        }
+
+        commandLine.add( sb.toString() );
+
+        return commandLine;
+    }
+
+    protected char[] getQuotingTriggerChars()
+    {
+        return DEFAULT_QUOTING_TRIGGER_CHARS;
+    }
+
+    protected String getExecutionPreamble()
+    {
+        return null;
+    }
+
+    protected char[] getEscapeChars( boolean includeSingleQuote, boolean includeDoubleQuote )
+    {
+        StringBuffer buf = new StringBuffer( 2 );
+        if ( includeSingleQuote )
+        {
+            buf.append( '\'' );
+        }
+
+        if ( includeDoubleQuote )
+        {
+            buf.append( '\"' );
+        }
+
+        char[] result = new char[buf.length()];
+        buf.getChars( 0, buf.length(), result, 0 );
+
+        return result;
+    }
+
+    protected boolean isDoubleQuotedArgumentEscaped()
+    {
+        return doubleQuotedArgumentEscaped;
+    }
+
+    protected boolean isSingleQuotedArgumentEscaped()
+    {
+        return singleQuotedArgumentEscaped;
+    }
+
+    protected boolean isDoubleQuotedExecutableEscaped()
+    {
+        return doubleQuotedExecutableEscaped;
+    }
+
+    protected boolean isSingleQuotedExecutableEscaped()
+    {
+        return singleQuotedExecutableEscaped;
+    }
+
+    protected void setArgumentQuoteDelimiter( char argQuoteDelimiter )
+    {
+        this.argQuoteDelimiter = argQuoteDelimiter;
+    }
+
+    protected char getArgumentQuoteDelimiter()
+    {
+        return argQuoteDelimiter;
+    }
+
+    protected void setExecutableQuoteDelimiter( char exeQuoteDelimiter )
+    {
+        this.exeQuoteDelimiter = exeQuoteDelimiter;
+    }
+
+    protected char getExecutableQuoteDelimiter()
+    {
+        return exeQuoteDelimiter;
+    }
+
+    /**
+     * Get the full command line to execute, including shell command, shell arguments,
+     * executable and executable arguments
+     *
+     * @param arguments  arguments for the executable, not the shell
+     * @return List of String objects, whose array version is suitable to be used as argument
+     *         of Runtime.getRuntime().exec()
+     */
+    public List getShellCommandLine( String[] arguments )
+    {
+
+        List commandLine = new ArrayList();
+
+        if ( getShellCommand() != null )
+        {
+            commandLine.add( getShellCommand() );
+        }
+
+        if ( getShellArgs() != null )
+        {
+            commandLine.addAll( getShellArgsList() );
+        }
+
+        commandLine.addAll( getCommandLine( getExecutable(), arguments ) );
+
+        return commandLine;
+
+    }
+
+    public List getShellArgsList()
+    {
+        return shellArgs;
+    }
+
+    public void addShellArg( String arg )
+    {
+        shellArgs.add( arg );
+    }
+
+    public void setQuotedArgumentsEnabled( boolean quotedArgumentsEnabled )
+    {
+        this.quotedArgumentsEnabled = quotedArgumentsEnabled;
+    }
+
+    public boolean isQuotedArgumentsEnabled()
+    {
+        return quotedArgumentsEnabled;
+    }
+
+    public void setQuotedExecutableEnabled( boolean quotedExecutableEnabled )
+    {
+        this.quotedExecutableEnabled = quotedExecutableEnabled;
+    }
+
+    public boolean isQuotedExecutableEnabled()
+    {
+        return quotedExecutableEnabled;
+    }
+
+    /**
+     * Sets the executable to run.
+     */
+    public void setExecutable( String executable )
+    {
+        if ( ( executable == null ) || ( executable.length() == 0 ) )
+        {
+            return;
+        }
+        this.executable = executable.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar );
+    }
+
+    public String getExecutable()
+    {
+        return executable;
+    }
+
+    /**
+     * Sets execution directory.
+     */
+    public void setWorkingDirectory( String path )
+    {
+        if ( path != null )
+        {
+            workingDir = path;
+        }
+    }
+
+    /**
+     * Sets execution directory.
+     */
+    public void setWorkingDirectory( File workingDir )
+    {
+        if ( workingDir != null )
+        {
+            this.workingDir = workingDir.getAbsolutePath();
+        }
+    }
+
+    public File getWorkingDirectory()
+    {
+        return workingDir == null ? null : new File( workingDir );
+    }
+
+    public String getWorkingDirectoryAsString()
+    {
+        return workingDir;
+    }
+
+    public void clearArguments()
+    {
+        shellArgs.clear();
+    }
+
+    public Object clone()
+    {
+        Shell shell = new Shell();
+        shell.setExecutable( getExecutable() );
+        shell.setWorkingDirectory( getWorkingDirectory() );
+        shell.setShellArgs( getShellArgs() );
+        return shell;
+    }
+
+    public String getOriginalExecutable()
+    {
+        return executable;
+    }
+
+    public List getOriginalCommandLine( String executable, String[] arguments )
+    {
+        return getRawCommandLine( executable, arguments );
+    }
+
+    protected void setDoubleQuotedArgumentEscaped( boolean doubleQuotedArgumentEscaped )
+    {
+        this.doubleQuotedArgumentEscaped = doubleQuotedArgumentEscaped;
+    }
+
+    protected void setDoubleQuotedExecutableEscaped( boolean doubleQuotedExecutableEscaped )
+    {
+        this.doubleQuotedExecutableEscaped = doubleQuotedExecutableEscaped;
+    }
+
+    protected void setSingleQuotedArgumentEscaped( boolean singleQuotedArgumentEscaped )
+    {
+        this.singleQuotedArgumentEscaped = singleQuotedArgumentEscaped;
+    }
+
+    protected void setSingleQuotedExecutableEscaped( boolean singleQuotedExecutableEscaped )
+    {
+        this.singleQuotedExecutableEscaped = singleQuotedExecutableEscaped;
+    }
+
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/cli/shell/Shell.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/dag/CycleDetectedException.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/dag/CycleDetectedException.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/dag/CycleDetectedException.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/dag/CycleDetectedException.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,64 @@
+package org.apache.geronimo.system.plugin.plexus.util.dag;
+
+/*
+ * 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.Iterator;
+import java.util.List;
+
+public class CycleDetectedException
+        extends Exception
+{
+    private List cycle;
+
+    public CycleDetectedException( final String message, final List cycle )
+    {
+        super( message );
+
+        this.cycle = cycle;
+
+    }
+
+
+    public List getCycle()
+    {
+        return cycle;
+    }
+
+    /**
+     * @return
+     */
+    public String cycleToString()
+    {
+        final StringBuffer buffer = new StringBuffer();
+
+        for ( Iterator iterator = cycle.iterator(); iterator.hasNext(); )
+        {
+            buffer.append( iterator.next() );
+
+            if ( iterator.hasNext() )
+            {
+                buffer.append( " --> " );
+            }
+        }
+        return buffer.toString();
+    }
+
+    public String getMessage()
+    {
+        return super.getMessage() + " " + cycleToString();
+    }
+}

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

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

Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/dag/CycleDetectedException.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/dag/CycleDetector.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/dag/CycleDetector.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/dag/CycleDetector.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/dag/CycleDetector.java Mon Oct  5 18:54:50 2009
@@ -0,0 +1,182 @@
+package org.apache.geronimo.system.plugin.plexus.util.dag;
+
+/*
+ * 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.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
+ * @version $Id: CycleDetector.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class CycleDetector
+{
+
+    private final static Integer NOT_VISTITED = new Integer( 0 );
+
+    private final static Integer VISITING = new Integer( 1 );
+
+    private final static Integer VISITED = new Integer( 2 );
+
+
+    public static List hasCycle( final DAG graph )
+    {
+        final List verticies = graph.getVerticies();
+
+        final Map vertexStateMap = new HashMap();
+
+        List retValue = null;
+
+        for ( final Iterator iter = verticies.iterator(); iter.hasNext(); )
+        {
+            final Vertex vertex = ( Vertex ) iter.next();
+
+            if ( isNotVisited( vertex, vertexStateMap ) )
+            {
+                retValue = introducesCycle( vertex, vertexStateMap );
+
+                if ( retValue != null )
+                {
+                    break;
+                }
+            }
+        }
+
+        return retValue;
+
+    }
+
+
+    /**
+     * This method will be called when an egde leading to given vertex was added
+     * and we want to check if introduction of this edge has not resulted
+     * in apparition of cycle in the graph
+     *
+     * @param vertex
+     * @param vertexStateMap
+     * @return
+     */
+    public static List introducesCycle( final Vertex vertex, final Map vertexStateMap )
+    {
+        final LinkedList cycleStack = new LinkedList();
+
+        final boolean hasCycle = dfsVisit( vertex, cycleStack, vertexStateMap );
+
+        if ( hasCycle )
+        {
+            // we have a situation like: [b, a, c, d, b, f, g, h].
+            // Label of Vertex which introduced  the cycle is at the first position in the list
+            // We have to find second occurence of this label and use its position in the list
+            // for getting the sublist of vertex labels of cycle paricipants
+            //
+            // So in our case we are seraching for [b, a, c, d, b]
+            final String label = ( String ) cycleStack.getFirst();
+
+            final int pos = cycleStack.lastIndexOf( label );
+
+            final List cycle = cycleStack.subList( 0, pos + 1 );
+
+            Collections.reverse( cycle );
+
+            return cycle;
+        }
+
+        return null;
+    }
+
+
+    public static List introducesCycle( final Vertex vertex )
+    {
+
+        final Map vertexStateMap = new HashMap();
+
+        return introducesCycle( vertex, vertexStateMap );
+
+    }
+
+    /**
+     * @param vertex
+     * @param vertexStateMap
+     * @return
+     */
+    private static boolean isNotVisited( final Vertex vertex, final Map vertexStateMap )
+    {
+        if ( !vertexStateMap.containsKey( vertex ) )
+        {
+            return true;
+        }
+
+        final Integer state = ( Integer ) vertexStateMap.get( vertex );
+
+        return NOT_VISTITED.equals( state );
+    }
+
+    /**
+     * @param vertex
+     * @param vertexStateMap
+     * @return
+     */
+    private static boolean isVisiting( final Vertex vertex, final Map vertexStateMap )
+    {
+        final Integer state = ( Integer ) vertexStateMap.get( vertex );
+
+        return VISITING.equals( state );
+    }
+
+    private static boolean dfsVisit( final Vertex vertex, final LinkedList cycle, final Map vertexStateMap )
+    {
+        cycle.addFirst( vertex.getLabel() );
+
+        vertexStateMap.put( vertex, VISITING );
+
+        final List verticies = vertex.getChildren();
+
+        for ( final Iterator iter = verticies.iterator(); iter.hasNext(); )
+        {
+            final Vertex v = ( Vertex ) iter.next();
+
+            if ( isNotVisited( v, vertexStateMap ) )
+            {
+                final boolean hasCycle = dfsVisit( v, cycle, vertexStateMap );
+
+                if ( hasCycle )
+                {
+                    return true;
+                }
+            }
+            else if ( isVisiting( v, vertexStateMap ) )
+            {
+                cycle.addFirst( v.getLabel() );
+
+                return true;
+            }
+        }
+        vertexStateMap.put( vertex, VISITED );
+
+        cycle.removeFirst();
+
+        return false;
+
+    }
+
+
+
+}
\ No newline at end of file

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

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

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



Mime
View raw message