2222import org .apache .tools .ant .Project ;
2323import org .apache .tools .ant .types .Commandline ;
2424import org .apache .tools .ant .types .CommandlineJava ;
25+ import org .apache .tools .ant .types .EnumeratedAttribute ;
2526import org .apache .tools .ant .types .Environment ;
2627import org .apache .tools .ant .types .Path ;
2728import org .apache .tools .ant .types .PropertySet ;
@@ -42,6 +43,7 @@ public class ForkDefinition {
4243
4344 private String dir ;
4445 private long timeout = -1 ;
46+ private Mode mode = new Mode ("once" );
4547
4648 ForkDefinition () {
4749 this .commandLineJava = new CommandlineJava ();
@@ -63,14 +65,37 @@ long getTimeout() {
6365 return this .timeout ;
6466 }
6567
68+ /**
69+ * Possible values are "once" and "perTest". If set to "once" (the default),
70+ * only a single Java VM will be forked for all tests, with "perTest" each test
71+ * will be run in a fresh Java VM.
72+ * @param mode the mode to use.
73+ * @since Ant 1.10.13
74+ */
75+ public void setMode (final Mode mode ) {
76+ this .mode = mode ;
77+ }
78+
79+ public Mode getMode () {
80+ return mode ;
81+ }
82+
6683 public void setIncludeJUnitPlatformLibraries (final boolean include ) {
6784 this .includeJUnitPlatformLibraries = include ;
6885 }
6986
87+ public boolean isIncludeJUnitPlatformLibraries () {
88+ return includeJUnitPlatformLibraries ;
89+ }
90+
7091 public void setIncludeAntRuntimeLibraries (final boolean include ) {
7192 this .includeAntRuntimeLibraries = include ;
7293 }
7394
95+ public boolean isIncludeAntRuntimeLibraries () {
96+ return includeAntRuntimeLibraries ;
97+ }
98+
7499 public Commandline .Argument createJvmArg () {
75100 return this .commandLineJava .createVmArgument ();
76101 }
@@ -140,4 +165,39 @@ CommandlineJava generateCommandLine(final JUnitLauncherTask task) {
140165 return cmdLine ;
141166 }
142167
168+ /**
169+ * Forking option. There are two available: "once" and "perTest".
170+ * @since Ant 1.10.13
171+ */
172+ public static final class Mode extends EnumeratedAttribute {
173+
174+ /**
175+ * fork once only
176+ */
177+ public static final String ONCE = "once" ;
178+ /**
179+ * fork once per test class
180+ */
181+ public static final String PER_TEST = "perTest" ;
182+
183+ /** No arg constructor. */
184+ public Mode () {
185+ super ();
186+ }
187+
188+ /**
189+ * Constructor using a value.
190+ * @param value the value to use - once or perTest.
191+ */
192+ public Mode (final String value ) {
193+ super ();
194+ setValue (value );
195+ }
196+
197+ /** {@inheritDoc}. */
198+ @ Override
199+ public String [] getValues () {
200+ return new String [] {ONCE , PER_TEST };
201+ }
202+ }
143203}
0 commit comments