git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270462 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -16,6 +16,7 @@ import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.types.Commandline; | import org.apache.tools.ant.types.Commandline; | ||||
| import org.apache.tools.ant.types.CommandlineJava; | import org.apache.tools.ant.types.CommandlineJava; | ||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| import org.apache.tools.ant.types.SysProperties; | |||||
| /* | /* | ||||
| * @author thomas.haas@softwired-inc.com | * @author thomas.haas@softwired-inc.com | ||||
| @@ -25,7 +26,7 @@ public class ExecuteJava | |||||
| { | { | ||||
| private Commandline m_javaCommand; | private Commandline m_javaCommand; | ||||
| private Path m_classpath; | private Path m_classpath; | ||||
| private CommandlineJava.SysProperties m_sysProperties; | |||||
| private SysProperties m_sysProperties; | |||||
| public void setClasspath( final Path classpath ) | public void setClasspath( final Path classpath ) | ||||
| { | { | ||||
| @@ -37,7 +38,7 @@ public class ExecuteJava | |||||
| m_javaCommand = javaCommand; | m_javaCommand = javaCommand; | ||||
| } | } | ||||
| public void setSystemProperties( final CommandlineJava.SysProperties sysProperties ) | |||||
| public void setSystemProperties( final SysProperties sysProperties ) | |||||
| { | { | ||||
| m_sysProperties = sysProperties; | m_sysProperties = sysProperties; | ||||
| } | } | ||||
| @@ -28,6 +28,7 @@ import org.apache.tools.ant.types.CommandlineJava; | |||||
| import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| import org.apache.tools.ant.types.EnvironmentVariable; | import org.apache.tools.ant.types.EnvironmentVariable; | ||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| import org.apache.tools.ant.types.SysProperties; | |||||
| /** | /** | ||||
| * Ant task to run JUnit tests. <p> | * Ant task to run JUnit tests. <p> | ||||
| @@ -686,7 +687,7 @@ public class JUnitTask extends Task | |||||
| getLogger().warn( "dir attribute ignored if running in the same VM" ); | getLogger().warn( "dir attribute ignored if running in the same VM" ); | ||||
| } | } | ||||
| CommandlineJava.SysProperties sysProperties = commandline.getSystemProperties(); | |||||
| SysProperties sysProperties = commandline.getSystemProperties(); | |||||
| if( sysProperties != null ) | if( sysProperties != null ) | ||||
| { | { | ||||
| sysProperties.setSystem(); | sysProperties.setSystem(); | ||||
| @@ -7,13 +7,8 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.types; | package org.apache.tools.ant.types; | ||||
| import java.util.ArrayList; | |||||
| import java.util.Iterator; | |||||
| import java.util.Properties; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.framework.Os; | import org.apache.myrmidon.framework.Os; | ||||
| import org.apache.myrmidon.framework.exec.Environment; | |||||
| import org.apache.myrmidon.framework.exec.ExecException; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| /** | /** | ||||
| @@ -303,94 +298,4 @@ public class CommandlineJava implements Cloneable | |||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Specialized EnvironmentData class for System properties | |||||
| * | |||||
| * @author RT | |||||
| */ | |||||
| public static class SysProperties extends EnvironmentData implements Cloneable | |||||
| { | |||||
| Properties sys = null; | |||||
| public void setSystem() | |||||
| throws TaskException | |||||
| { | |||||
| try | |||||
| { | |||||
| Properties p = new Properties( sys = System.getProperties() ); | |||||
| for( Iterator e = m_variables.iterator(); e.hasNext(); ) | |||||
| { | |||||
| EnvironmentVariable v = (EnvironmentVariable)e.next(); | |||||
| p.put( v.getKey(), v.getValue() ); | |||||
| } | |||||
| System.setProperties( p ); | |||||
| } | |||||
| catch( SecurityException e ) | |||||
| { | |||||
| throw new TaskException( "Cannot modify system properties", e ); | |||||
| } | |||||
| } | |||||
| public String[] getJavaVariables() | |||||
| throws TaskException | |||||
| { | |||||
| String props[] = new String[ 0 ]; | |||||
| try | |||||
| { | |||||
| props = Environment.toNativeFormat( super.getVariables() ); | |||||
| } | |||||
| catch( final ExecException ee ) | |||||
| { | |||||
| throw new TaskException( ee.getMessage(), ee ); | |||||
| } | |||||
| if( props == null ) | |||||
| return null; | |||||
| for( int i = 0; i < props.length; i++ ) | |||||
| { | |||||
| props[ i ] = "-D" + props[ i ]; | |||||
| } | |||||
| return props; | |||||
| } | |||||
| public Object clone() | |||||
| { | |||||
| try | |||||
| { | |||||
| SysProperties c = (SysProperties)super.clone(); | |||||
| c.m_variables.addAll( (ArrayList)m_variables.clone() ); | |||||
| return c; | |||||
| } | |||||
| catch( CloneNotSupportedException e ) | |||||
| { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| public void restoreSystem() | |||||
| throws TaskException | |||||
| { | |||||
| if( sys == null ) | |||||
| throw new TaskException( "Unbalanced nesting of SysProperties" ); | |||||
| try | |||||
| { | |||||
| System.setProperties( sys ); | |||||
| sys = null; | |||||
| } | |||||
| catch( SecurityException e ) | |||||
| { | |||||
| throw new TaskException( "Cannot modify system properties", e ); | |||||
| } | |||||
| } | |||||
| public int size() | |||||
| { | |||||
| return m_variables.size(); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,119 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE.txt file. | |||||
| */ | |||||
| package org.apache.tools.ant.types; | |||||
| import java.util.ArrayList; | |||||
| import java.util.Iterator; | |||||
| import java.util.Properties; | |||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.framework.exec.ExecException; | |||||
| /** | |||||
| * Specialized EnvironmentData class for System properties | |||||
| */ | |||||
| public class SysProperties | |||||
| extends EnvironmentData | |||||
| implements Cloneable | |||||
| { | |||||
| private Properties m_system; | |||||
| public void setSystem() | |||||
| throws TaskException | |||||
| { | |||||
| try | |||||
| { | |||||
| Properties p = new Properties( m_system = System.getProperties() ); | |||||
| for( Iterator e = m_variables.iterator(); e.hasNext(); ) | |||||
| { | |||||
| EnvironmentVariable v = (EnvironmentVariable)e.next(); | |||||
| p.put( v.getKey(), v.getValue() ); | |||||
| } | |||||
| System.setProperties( p ); | |||||
| } | |||||
| catch( SecurityException e ) | |||||
| { | |||||
| throw new TaskException( "Cannot modify system properties", e ); | |||||
| } | |||||
| } | |||||
| public String[] getJavaVariables() | |||||
| throws TaskException | |||||
| { | |||||
| String props[] = new String[ 0 ]; | |||||
| try | |||||
| { | |||||
| props = toNativeFormat( super.getVariables() ); | |||||
| } | |||||
| catch( final ExecException ee ) | |||||
| { | |||||
| throw new TaskException( ee.getMessage(), ee ); | |||||
| } | |||||
| if( props == null ) | |||||
| return null; | |||||
| for( int i = 0; i < props.length; i++ ) | |||||
| { | |||||
| props[ i ] = "-D" + props[ i ]; | |||||
| } | |||||
| return props; | |||||
| } | |||||
| public Object clone() | |||||
| { | |||||
| try | |||||
| { | |||||
| SysProperties c = (SysProperties)super.clone(); | |||||
| c.m_variables.addAll( (ArrayList)m_variables.clone() ); | |||||
| return c; | |||||
| } | |||||
| catch( CloneNotSupportedException e ) | |||||
| { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| public void restoreSystem() | |||||
| throws TaskException | |||||
| { | |||||
| if( m_system == null ) | |||||
| throw new TaskException( "Unbalanced nesting of SysProperties" ); | |||||
| try | |||||
| { | |||||
| System.setProperties( m_system ); | |||||
| m_system = null; | |||||
| } | |||||
| catch( SecurityException e ) | |||||
| { | |||||
| throw new TaskException( "Cannot modify system properties", e ); | |||||
| } | |||||
| } | |||||
| public int size() | |||||
| { | |||||
| return m_variables.size(); | |||||
| } | |||||
| private String[] toNativeFormat( final Properties environment ) | |||||
| throws ExecException | |||||
| { | |||||
| final ArrayList newEnvironment = new ArrayList(); | |||||
| final Iterator keys = environment.keySet().iterator(); | |||||
| while( keys.hasNext() ) | |||||
| { | |||||
| final String key = (String)keys.next(); | |||||
| final String value = environment.getProperty( key ); | |||||
| newEnvironment.add( key + '=' + value ); | |||||
| } | |||||
| return (String[])newEnvironment.toArray( new String[ newEnvironment.size() ] ); | |||||
| } | |||||
| } | |||||
| @@ -16,6 +16,7 @@ import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.types.Commandline; | import org.apache.tools.ant.types.Commandline; | ||||
| import org.apache.tools.ant.types.CommandlineJava; | import org.apache.tools.ant.types.CommandlineJava; | ||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| import org.apache.tools.ant.types.SysProperties; | |||||
| /* | /* | ||||
| * @author thomas.haas@softwired-inc.com | * @author thomas.haas@softwired-inc.com | ||||
| @@ -25,7 +26,7 @@ public class ExecuteJava | |||||
| { | { | ||||
| private Commandline m_javaCommand; | private Commandline m_javaCommand; | ||||
| private Path m_classpath; | private Path m_classpath; | ||||
| private CommandlineJava.SysProperties m_sysProperties; | |||||
| private SysProperties m_sysProperties; | |||||
| public void setClasspath( final Path classpath ) | public void setClasspath( final Path classpath ) | ||||
| { | { | ||||
| @@ -37,7 +38,7 @@ public class ExecuteJava | |||||
| m_javaCommand = javaCommand; | m_javaCommand = javaCommand; | ||||
| } | } | ||||
| public void setSystemProperties( final CommandlineJava.SysProperties sysProperties ) | |||||
| public void setSystemProperties( final SysProperties sysProperties ) | |||||
| { | { | ||||
| m_sysProperties = sysProperties; | m_sysProperties = sysProperties; | ||||
| } | } | ||||
| @@ -28,6 +28,7 @@ import org.apache.tools.ant.types.CommandlineJava; | |||||
| import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| import org.apache.tools.ant.types.EnvironmentVariable; | import org.apache.tools.ant.types.EnvironmentVariable; | ||||
| import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
| import org.apache.tools.ant.types.SysProperties; | |||||
| /** | /** | ||||
| * Ant task to run JUnit tests. <p> | * Ant task to run JUnit tests. <p> | ||||
| @@ -686,7 +687,7 @@ public class JUnitTask extends Task | |||||
| getLogger().warn( "dir attribute ignored if running in the same VM" ); | getLogger().warn( "dir attribute ignored if running in the same VM" ); | ||||
| } | } | ||||
| CommandlineJava.SysProperties sysProperties = commandline.getSystemProperties(); | |||||
| SysProperties sysProperties = commandline.getSystemProperties(); | |||||
| if( sysProperties != null ) | if( sysProperties != null ) | ||||
| { | { | ||||
| sysProperties.setSystem(); | sysProperties.setSystem(); | ||||
| @@ -7,13 +7,8 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.types; | package org.apache.tools.ant.types; | ||||
| import java.util.ArrayList; | |||||
| import java.util.Iterator; | |||||
| import java.util.Properties; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.framework.Os; | import org.apache.myrmidon.framework.Os; | ||||
| import org.apache.myrmidon.framework.exec.Environment; | |||||
| import org.apache.myrmidon.framework.exec.ExecException; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| /** | /** | ||||
| @@ -303,94 +298,4 @@ public class CommandlineJava implements Cloneable | |||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Specialized EnvironmentData class for System properties | |||||
| * | |||||
| * @author RT | |||||
| */ | |||||
| public static class SysProperties extends EnvironmentData implements Cloneable | |||||
| { | |||||
| Properties sys = null; | |||||
| public void setSystem() | |||||
| throws TaskException | |||||
| { | |||||
| try | |||||
| { | |||||
| Properties p = new Properties( sys = System.getProperties() ); | |||||
| for( Iterator e = m_variables.iterator(); e.hasNext(); ) | |||||
| { | |||||
| EnvironmentVariable v = (EnvironmentVariable)e.next(); | |||||
| p.put( v.getKey(), v.getValue() ); | |||||
| } | |||||
| System.setProperties( p ); | |||||
| } | |||||
| catch( SecurityException e ) | |||||
| { | |||||
| throw new TaskException( "Cannot modify system properties", e ); | |||||
| } | |||||
| } | |||||
| public String[] getJavaVariables() | |||||
| throws TaskException | |||||
| { | |||||
| String props[] = new String[ 0 ]; | |||||
| try | |||||
| { | |||||
| props = Environment.toNativeFormat( super.getVariables() ); | |||||
| } | |||||
| catch( final ExecException ee ) | |||||
| { | |||||
| throw new TaskException( ee.getMessage(), ee ); | |||||
| } | |||||
| if( props == null ) | |||||
| return null; | |||||
| for( int i = 0; i < props.length; i++ ) | |||||
| { | |||||
| props[ i ] = "-D" + props[ i ]; | |||||
| } | |||||
| return props; | |||||
| } | |||||
| public Object clone() | |||||
| { | |||||
| try | |||||
| { | |||||
| SysProperties c = (SysProperties)super.clone(); | |||||
| c.m_variables.addAll( (ArrayList)m_variables.clone() ); | |||||
| return c; | |||||
| } | |||||
| catch( CloneNotSupportedException e ) | |||||
| { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| public void restoreSystem() | |||||
| throws TaskException | |||||
| { | |||||
| if( sys == null ) | |||||
| throw new TaskException( "Unbalanced nesting of SysProperties" ); | |||||
| try | |||||
| { | |||||
| System.setProperties( sys ); | |||||
| sys = null; | |||||
| } | |||||
| catch( SecurityException e ) | |||||
| { | |||||
| throw new TaskException( "Cannot modify system properties", e ); | |||||
| } | |||||
| } | |||||
| public int size() | |||||
| { | |||||
| return m_variables.size(); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,119 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE.txt file. | |||||
| */ | |||||
| package org.apache.tools.ant.types; | |||||
| import java.util.ArrayList; | |||||
| import java.util.Iterator; | |||||
| import java.util.Properties; | |||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.framework.exec.ExecException; | |||||
| /** | |||||
| * Specialized EnvironmentData class for System properties | |||||
| */ | |||||
| public class SysProperties | |||||
| extends EnvironmentData | |||||
| implements Cloneable | |||||
| { | |||||
| private Properties m_system; | |||||
| public void setSystem() | |||||
| throws TaskException | |||||
| { | |||||
| try | |||||
| { | |||||
| Properties p = new Properties( m_system = System.getProperties() ); | |||||
| for( Iterator e = m_variables.iterator(); e.hasNext(); ) | |||||
| { | |||||
| EnvironmentVariable v = (EnvironmentVariable)e.next(); | |||||
| p.put( v.getKey(), v.getValue() ); | |||||
| } | |||||
| System.setProperties( p ); | |||||
| } | |||||
| catch( SecurityException e ) | |||||
| { | |||||
| throw new TaskException( "Cannot modify system properties", e ); | |||||
| } | |||||
| } | |||||
| public String[] getJavaVariables() | |||||
| throws TaskException | |||||
| { | |||||
| String props[] = new String[ 0 ]; | |||||
| try | |||||
| { | |||||
| props = toNativeFormat( super.getVariables() ); | |||||
| } | |||||
| catch( final ExecException ee ) | |||||
| { | |||||
| throw new TaskException( ee.getMessage(), ee ); | |||||
| } | |||||
| if( props == null ) | |||||
| return null; | |||||
| for( int i = 0; i < props.length; i++ ) | |||||
| { | |||||
| props[ i ] = "-D" + props[ i ]; | |||||
| } | |||||
| return props; | |||||
| } | |||||
| public Object clone() | |||||
| { | |||||
| try | |||||
| { | |||||
| SysProperties c = (SysProperties)super.clone(); | |||||
| c.m_variables.addAll( (ArrayList)m_variables.clone() ); | |||||
| return c; | |||||
| } | |||||
| catch( CloneNotSupportedException e ) | |||||
| { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| public void restoreSystem() | |||||
| throws TaskException | |||||
| { | |||||
| if( m_system == null ) | |||||
| throw new TaskException( "Unbalanced nesting of SysProperties" ); | |||||
| try | |||||
| { | |||||
| System.setProperties( m_system ); | |||||
| m_system = null; | |||||
| } | |||||
| catch( SecurityException e ) | |||||
| { | |||||
| throw new TaskException( "Cannot modify system properties", e ); | |||||
| } | |||||
| } | |||||
| public int size() | |||||
| { | |||||
| return m_variables.size(); | |||||
| } | |||||
| private String[] toNativeFormat( final Properties environment ) | |||||
| throws ExecException | |||||
| { | |||||
| final ArrayList newEnvironment = new ArrayList(); | |||||
| final Iterator keys = environment.keySet().iterator(); | |||||
| while( keys.hasNext() ) | |||||
| { | |||||
| final String key = (String)keys.next(); | |||||
| final String value = environment.getProperty( key ); | |||||
| newEnvironment.add( key + '=' + value ); | |||||
| } | |||||
| return (String[])newEnvironment.toArray( new String[ newEnvironment.size() ] ); | |||||
| } | |||||
| } | |||||