-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Surefire and other plugins support the `argLine` property for passing parameters to child jvms in the form of a single string. Pitest currently supports passing a list of properties using the jvmArgs param. This requires duplicating values already specified in the argLine. The list format also causes problems when the arguments contain delimiters, for which some unsatisfactory workarounds have been applied. This change adds a new argLine property to pitest, which is read from the standard maven property by default. It can be set explicitly for Ant and the command line. The existing jvmArgs parameter is retained, and can be used to set additional arguments for pitest.
- Loading branch information
Henry Coles
committed
Jul 14, 2022
1 parent
34153e5
commit 04b672c
Showing
16 changed files
with
327 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
pitest-entry/src/main/java/org/pitest/process/ArgLineParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.pitest.process; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Deque; | ||
import java.util.List; | ||
import java.util.StringTokenizer; | ||
|
||
import static org.pitest.process.ArgLineParser.State.START; | ||
|
||
/** | ||
* Simple state machine to split arglines into sections. Arglines may | ||
* contain single or double quotes, which might be escaped. | ||
*/ | ||
public class ArgLineParser { | ||
|
||
private static final String ESCAPE_CHAR = "\\"; | ||
private static final String SINGLE_QUOTE = "\'"; | ||
public static final String DOUBLE_QUOTE = "\""; | ||
|
||
public static List<String> split(String in) { | ||
return process(stripWhiteSpace(in)); | ||
} | ||
|
||
private static List<String> process(String in) { | ||
if (in.isEmpty()) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
final StringTokenizer tokenizer = new StringTokenizer(in, "\"\' \\", true); | ||
List<String> tokens = new ArrayList<>(); | ||
|
||
Deque<State> state = new ArrayDeque<>(); | ||
state.push(START); | ||
StringBuilder current = new StringBuilder(); | ||
while (tokenizer.hasMoreTokens()) { | ||
String token = tokenizer.nextToken(); | ||
switch (state.peek()) { | ||
case START: | ||
if (token.equals(SINGLE_QUOTE)) { | ||
state.push(State.IN_QUOTE); | ||
} else if (token.equals(DOUBLE_QUOTE)) { | ||
state.push(State.IN_DOUBLE_QUOTE); | ||
} else if (token.equals(" ")) { | ||
if (current.length() != 0) { | ||
tokens.add(current.toString()); | ||
current = new StringBuilder(); | ||
} | ||
} else { | ||
current.append(token); | ||
if (token.equals(ESCAPE_CHAR)) { | ||
state.push(State.IN_ESCAPE); | ||
} | ||
} | ||
break; | ||
case IN_QUOTE: | ||
if (token.equals(SINGLE_QUOTE)) { | ||
state.pop(); | ||
} else { | ||
current.append(token); | ||
if (token.equals(ESCAPE_CHAR)) { | ||
state.push(State.IN_ESCAPE); | ||
} | ||
} | ||
break; | ||
case IN_DOUBLE_QUOTE: | ||
if (token.equals(DOUBLE_QUOTE)) { | ||
state.pop(); | ||
} else { | ||
current.append(token); | ||
if (token.equals(ESCAPE_CHAR)) { | ||
state.push(State.IN_ESCAPE); | ||
} | ||
} | ||
break; | ||
case IN_ESCAPE: | ||
current.append(token); | ||
if (!token.equals(ESCAPE_CHAR)) { | ||
state.pop(); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
if (current.length() != 0) { | ||
tokens.add(current.toString()); | ||
} | ||
|
||
if (state.size() != 1) { | ||
throw new RuntimeException("Unclosed quote in " + in); | ||
} | ||
|
||
return tokens; | ||
} | ||
|
||
private static String stripWhiteSpace(String in) { | ||
if (in == null) { | ||
return ""; | ||
} | ||
return in.replaceAll("\\s", " ").trim(); | ||
} | ||
|
||
enum State { | ||
START, IN_ESCAPE, IN_QUOTE, IN_DOUBLE_QUOTE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.