You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2022/07/14 23:12:25 UTC
[royale-compiler] 06/06: royaleunit-ant-tasks: added commandArgs attribute to element (closes #168)
This is an automated email from the ASF dual-hosted git repository.
joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit 4c5c9049188f0dee62aee4dc73f9c9e6f1e4582b
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Jul 14 15:13:00 2022 -0700
royaleunit-ant-tasks: added commandArgs attribute to <royaleunit/> element (closes #168)
---
.../commands/player/CustomPlayerCommand.java | 23 ++++++++--
.../commands/player/PlayerCommandFactory.java | 3 +-
.../royale/test/ant/tasks/RoyaleUnitTask.java | 49 +++++++++++++++++++---
.../org/apache/royale/test/ant/tasks/TestRun.java | 1 +
.../ant/tasks/configuration/TaskConfiguration.java | 5 +++
.../tasks/configuration/TestRunConfiguration.java | 16 +++++++
6 files changed, 88 insertions(+), 9 deletions(-)
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/CustomPlayerCommand.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/CustomPlayerCommand.java
index 830af6ecb..ebf6e80dd 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/CustomPlayerCommand.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/CustomPlayerCommand.java
@@ -28,6 +28,7 @@ public class CustomPlayerCommand implements PlayerCommand
{
private DefaultPlayerCommand proxiedCommand;
private File executable;
+ private String[] executableArgs;
public PlayerCommand getProxiedCommand()
{
@@ -48,6 +49,16 @@ public class CustomPlayerCommand implements PlayerCommand
{
this.executable = executable;
}
+
+ public String[] getExecutableArgs()
+ {
+ return executableArgs;
+ }
+
+ public void setExecutableArgs(String[] executableArgs)
+ {
+ this.executableArgs = executableArgs;
+ }
public void setProject(Project project)
{
@@ -79,15 +90,21 @@ public class CustomPlayerCommand implements PlayerCommand
proxiedCommand.getCommandLine().setExecutable(executable.getAbsolutePath());
proxiedCommand.getCommandLine().clearArgs();
+ int customArgsCount = executableArgs != null ? executableArgs.length : 0;
+ String[] args = new String[customArgsCount + 1];
+ if (executableArgs != null)
+ {
+ System.arraycopy(executableArgs, 0, args, 0, executableArgs.length);
+ }
if(getUrl() != null)
{
- proxiedCommand.getCommandLine().addArguments(new String[]{getUrl()});
+ args[args.length - 1] = getUrl();
}
else
{
- proxiedCommand.getCommandLine().addArguments(new String[]{getFileToExecute().getAbsolutePath()});
+ args[args.length - 1] = getFileToExecute().getAbsolutePath();
}
-
+ proxiedCommand.getCommandLine().addArguments(args);
}
public Process launch() throws IOException
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java
index 696126276..8c3264f2f 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java
@@ -35,7 +35,7 @@ public class PlayerCommandFactory
* @param localTrusted
* @return Desired player command with platform defaults possibly wrapped in a custom command
*/
- public static PlayerCommand createPlayer(OperatingSystem os, String player, File customCommand, boolean localTrusted)
+ public static PlayerCommand createPlayer(OperatingSystem os, String player, File customCommand, String[] customCommandArgs, boolean localTrusted)
{
PlayerCommand newInstance = null;
@@ -73,6 +73,7 @@ public class PlayerCommandFactory
CustomPlayerCommand customInstance = new CustomPlayerCommand();
customInstance.setProxiedCommand(defaultInstance);
customInstance.setExecutable(customCommand);
+ customInstance.setExecutableArgs(customCommandArgs);
newInstance = customInstance;
}
else
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/RoyaleUnitTask.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/RoyaleUnitTask.java
index d01e03a5d..9f4f73f61 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/RoyaleUnitTask.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/RoyaleUnitTask.java
@@ -16,16 +16,25 @@
*/
package org.apache.royale.test.ant.tasks;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.royale.test.ant.tasks.configuration.TaskConfiguration;
+import org.apache.royale.test.ant.tasks.types.LoadConfig;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DynamicAttribute;
import org.apache.tools.ant.DynamicElement;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
-import org.apache.royale.test.ant.tasks.configuration.TaskConfiguration;
-import org.apache.royale.test.ant.tasks.types.LoadConfig;
-public class RoyaleUnitTask extends Task implements DynamicElement
+public class RoyaleUnitTask extends Task implements DynamicElement, DynamicAttribute
{
+ private static final Pattern COMMAND_ARGS_PATTERN = Pattern.compile(
+ "([\\-+]([^\\s]+\\+?=)(('([^'])*')|(\"([^\"])*\")|([^\\s\"',]+))(,(('([^'])*')|(\"([^\"])*\")|([^\\s\"']+)))*)|('([^'])*')|(\"([^\"])*\")|([^\\s\"']+)");
+
private TaskConfiguration configuration;
public RoyaleUnitTask()
@@ -142,6 +151,11 @@ public class RoyaleUnitTask extends Task implements DynamicElement
configuration.setCommand(executableFilePath);
}
+ public void setCommandArgs(String[] customArgs)
+ {
+ configuration.setCommandArgs(customArgs);
+ }
+
public void setHeadless(boolean headless)
{
configuration.setHeadless(headless);
@@ -204,11 +218,36 @@ public class RoyaleUnitTask extends Task implements DynamicElement
LoadConfig loadconfig = new LoadConfig();
configuration.setLoadConfig(loadconfig);
return loadconfig;
- }
+ }
else
{
- throw new BuildException( "The <royaleUnit> type doesn't support the " + arg0 + "nested element");
+ throw new BuildException( "The <royaleUnit> type doesn't support the " + arg0 + " nested element");
}
}
+ private String[] parseCommandArgs(String combined)
+ {
+ List<String> result = new ArrayList<String>();
+ Matcher matcher = COMMAND_ARGS_PATTERN.matcher(combined);
+ while (matcher.find())
+ {
+ String option = matcher.group();
+ result.add(option);
+ }
+ return result.toArray(new String[0]);
+ }
+
+ public void setDynamicAttribute(String arg0, String arg1)
+ throws BuildException {
+ if("commandargs".equals(arg0))
+ {
+ String[] commandArgs = parseCommandArgs(arg1);
+ configuration.setCommandArgs(commandArgs);
+ }
+ else
+ {
+ throw new BuildException( "The <royaleUnit> type doesn't support the " + arg0 + " attribute");
+ }
+ }
+
}
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java
index 531474b4d..d46e03beb 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java
@@ -104,6 +104,7 @@ public class TestRun
configuration.getOs(),
configuration.getPlayer(),
configuration.getCommand(),
+ configuration.getCommandArgs(),
configuration.isLocalTrusted());
command.setProject(project);
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java
index 790ea140a..69edba135 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java
@@ -93,6 +93,11 @@ public class TaskConfiguration
testRunConfiguration.setCommand(project.resolveFile(commandPath));
}
}
+
+ public void setCommandArgs(String[] commandArgs)
+ {
+ testRunConfiguration.setCommandArgs(commandArgs);
+ }
public void setDisplay(int display)
{
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TestRunConfiguration.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TestRunConfiguration.java
index c5951c589..b60f8e59d 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TestRunConfiguration.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TestRunConfiguration.java
@@ -17,6 +17,7 @@
package org.apache.royale.test.ant.tasks.configuration;
import java.io.File;
+import java.util.Arrays;
import org.apache.tools.ant.BuildException;
import org.apache.royale.test.ant.LoggingUtil;
@@ -29,6 +30,7 @@ public class TestRunConfiguration implements StepConfiguration
private String player;
private File command = null;
+ private String[] commandArgs = null;
private int display = 99;
private boolean failOnTestFailure = false;
private String failureProperty = "royaleunit.failed";
@@ -54,6 +56,16 @@ public class TestRunConfiguration implements StepConfiguration
this.command = command;
}
+ public String[] getCommandArgs()
+ {
+ return commandArgs;
+ }
+
+ public void setCommandArgs(String[] commandArgs)
+ {
+ this.commandArgs = commandArgs;
+ }
+
public boolean isCustomCommand()
{
return command != null;
@@ -268,6 +280,10 @@ public class TestRunConfiguration implements StepConfiguration
if(isCustomCommand())
{
LoggingUtil.log("\tcommand: [" + command + "]");
+ if (commandArgs != null)
+ {
+ LoggingUtil.log("\tcommandArgs: [" + Arrays.toString(commandArgs) + "]");
+ }
}
LoggingUtil.log("\tport: [" + port + "]");