bodewig 2003/12/12 01:41:46 Modified: src/main/org/apache/tools/ant/taskdefs Java.java src/main/org/apache/tools/ant/taskdefs/optional/junit JUnitTask.java src/main/org/apache/tools/ant/types CommandlineJava.java Path.java PropertySet.java Log: Add a cloneVm attribute to CommandlineJava and <java> and <junit>. If set, the forked VM will be configured to match the currently running VM closely. This involves: * copying of all system properties. * copying of the bootclasspath - only if no bootclasspath has been specified explicitly or build.sysclasspath has been set to "only". This is accompanied by a magic system property build.clonevm that can be used to force the attribute to be set. It has to be a system property as CommandlineJava doesn't know about project instances. PR: 25327 Revision Changes Path 1.79 +13 -0 ant/src/main/org/apache/tools/ant/taskdefs/Java.java Index: Java.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Java.java,v retrieving revision 1.78 retrieving revision 1.79 diff -u -r1.78 -r1.79 --- Java.java 23 Sep 2003 06:31:46 -0000 1.78 +++ Java.java 12 Dec 2003 09:41:46 -0000 1.79 @@ -330,6 +330,19 @@ } /** + * If set, system properties will be copied to the cloned VM - as + * well as the bootclasspath unless you have explicitly specified + * a bootclaspath. + * + * <p>Doesn't have any effect unless fork is true.</p> + * + * @since Ant 1.7 + */ + public void setCloneVm(boolean cloneVm) { + cmdl.setCloneVm(cloneVm); + } + + /** * Adds a command-line argument. * * @return created argument 1.89 +14 -1 ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java Index: JUnitTask.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v retrieving revision 1.88 retrieving revision 1.89 diff -u -r1.88 -r1.89 --- JUnitTask.java 22 Oct 2003 14:38:50 -0000 1.88 +++ JUnitTask.java 12 Dec 2003 09:41:46 -0000 1.89 @@ -588,6 +588,19 @@ } /** + * If set, system properties will be copied to the cloned VM - as + * well as the bootclasspath unless you have explicitly specified + * a bootclaspath. + * + * <p>Doesn't have any effect unless fork is true.</p> + * + * @since Ant 1.7 + */ + public void setCloneVm(boolean cloneVm) { + commandline.setCloneVm(cloneVm); + } + + /** * Creates a new JUnitRunner and enables fork of a new Java VM. * * @throws Exception under ??? circumstances 1.48 +58 -2 ant/src/main/org/apache/tools/ant/types/CommandlineJava.java Index: CommandlineJava.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/CommandlineJava.java,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- CommandlineJava.java 21 Sep 2003 20:20:02 -0000 1.47 +++ CommandlineJava.java 12 Dec 2003 09:41:46 -0000 1.48 @@ -105,6 +105,12 @@ private boolean executeJar = false; /** + * Whether system properties and bootclasspath shall be cloned. + * @since Ant 1.7 + */ + private boolean cloneVm = false; + + /** * Specialized Environment class for System properties */ public static class SysProperties extends Environment implements Cloneable { @@ -294,6 +300,15 @@ vmVersion = value; } + /** + * If set, system properties will be copied to the cloned VM - as + * well as the bootclasspath unless you have explicitly specified + * a bootclaspath. + * @since Ant 1.7 + */ + public void setCloneVm(boolean cloneVm) { + this.cloneVm = cloneVm; + } /** * get the current assertions @@ -397,10 +412,26 @@ getActualVMCommand().addCommandToList(listIterator); // properties are part of the vm options... sysProperties.addDefinitionsToList(listIterator); + + if (isCloneVm()) { + SysProperties clonedSysProperties = new SysProperties(); + PropertySet ps = new PropertySet(); + PropertySet.BuiltinPropertySetName sys = + new PropertySet.BuiltinPropertySetName(); + sys.setValue("system"); + ps.appendBuiltin(sys); + clonedSysProperties.addSyspropertyset(ps); + clonedSysProperties.addDefinitionsToList(listIterator); + } + //boot classpath if (haveBootclasspath(true)) { listIterator.add("-Xbootclasspath:" + bootclasspath.toString()); + } else if (cloneBootclasspath()) { + listIterator.add("-Xbootclasspath:" + + Path.systemBootClasspath.toString()); } + //main classpath if (haveClasspath()) { listIterator.add("-classpath"); @@ -489,13 +520,19 @@ * @deprecated please dont use this -it effectively creates the entire command. */ public int size() { - int size = getActualVMCommand().size() + javaCommand.size() + sysProperties.size(); + int size = getActualVMCommand().size() + javaCommand.size() + + sysProperties.size(); + // cloned system properties + if (isCloneVm()) { + size += System.getProperties().size(); + } + // classpath is "-classpath <classpath>" -> 2 args if (haveClasspath()) { size += 2; } // bootclasspath is "-Xbootclasspath:<classpath>" -> 1 arg - if (haveBootclasspath(true)) { + if (haveBootclasspath(true) || cloneBootclasspath()) { size++; } // jar execution requires an additional -jar option @@ -648,4 +685,23 @@ return false; } + /** + * Should a bootclasspath argument be created to clone the current + * VM settings? + * + * @since Ant 1.7 + */ + private boolean cloneBootclasspath() { + return isCloneVm() && !vmVersion.startsWith("1.1") + && Path.systemBootClasspath.size() > 0; + } + + /** + * Has the cloneVm attribute or the magic property build.clonevm been set? + * + * @since 1.7 + */ + private boolean isCloneVm() { + return cloneVm || "true".equals(System.getProperty("build.clonevm")); + } } 1.58 +10 -1 ant/src/main/org/apache/tools/ant/types/Path.java Index: Path.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/Path.java,v retrieving revision 1.57 retrieving revision 1.58 diff -u -r1.57 -r1.58 --- Path.java 14 Aug 2003 16:25:52 -0000 1.57 +++ Path.java 12 Dec 2003 09:41:46 -0000 1.58 @@ -104,6 +104,15 @@ new Path(null, System.getProperty("java.class.path")); + /** + * The system bootclassspath as a Path object. + * + * @since Ant 1.7 + */ + public static Path systemBootClasspath = + new Path(null, System.getProperty("sun.boot.class.path")); + + /** * Helper class, holds the nested <code><pathelement></code> values. */ @@ -404,7 +413,7 @@ public static String[] translatePath(Project project, String source) { final Vector result = new Vector(); if (source == null) { - return new String[0]; + return new String[0]; } PathTokenizer tok = new PathTokenizer(source); 1.9 +6 -4 ant/src/main/org/apache/tools/ant/types/PropertySet.java Index: PropertySet.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/PropertySet.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- PropertySet.java 13 Aug 2003 15:14:31 -0000 1.8 +++ PropertySet.java 12 Dec 2003 09:41:46 -0000 1.9 @@ -194,13 +194,15 @@ public Properties getProperties() { Vector names = null; Project prj = getProject(); + Hashtable props = + prj == null ? System.getProperties() : prj.getProperties(); if (getDynamic() || cachedNames == null) { names = new Vector(); // :TODO: should be a Set! if (isReference()) { - getRef().addPropertyNames(names, prj.getProperties()); + getRef().addPropertyNames(names, props); } else { - addPropertyNames(names, prj.getProperties()); + addPropertyNames(names, props); } if (!getDynamic()) { @@ -218,7 +220,7 @@ Properties properties = new Properties(); for (Enumeration e = names.elements(); e.hasMoreElements();) { String name = (String) e.nextElement(); - String value = prj.getProperty(name); + String value = (String) props.get(name); if (mapper != null) { String[] newname = mapper.mapFileName(name); if (newname != null) { @@ -243,7 +245,7 @@ for (Enumeration e = ptyRefs.elements(); e.hasMoreElements();) { PropertyRef ref = (PropertyRef) e.nextElement(); if (ref.name != null) { - if (prj.getProperty(ref.name) != null) { + if (prj != null && prj.getProperty(ref.name) != null) { names.addElement(ref.name); } } else if (ref.prefix != null) {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]