Skip to content

Commit 11c4cfe

Browse files
authored
Merge pull request #85 from robotframework/feat/python_runner
Feat/python runner
2 parents 703ba09 + e36cc34 commit 11c4cfe

16 files changed

Lines changed: 138 additions & 87 deletions

.github/workflows/maven.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
java: [ 8, 11 ]
1212
name: Test with Java ${{ matrix.java }}
1313
steps:
14-
- uses: actions/checkout@v2.0.0
14+
- uses: actions/checkout@v2
1515
- name: Set up JDK ${{ matrix.java }}
16-
uses: actions/setup-java@v1.3.0
16+
uses: actions/setup-java@v1
1717
with:
1818
java-version: ${{ matrix.java }}
1919
- name: Build with Maven
@@ -24,13 +24,13 @@ jobs:
2424
runs-on: ubuntu-latest
2525
name: Release package
2626
steps:
27-
- uses: actions/checkout@v2.0.0
27+
- uses: actions/checkout@v2
2828
- name: Set up JDK
29-
uses: actions/setup-java@v1.3.0
29+
uses: actions/setup-java@v1
3030
with:
3131
java-version: 8
3232
- name: Release Maven package
33-
uses: samuelmeuli/action-maven-publish@82d218a8bc9cacee5493e3604d651ab3ca74b506 #v1.0.0
33+
uses: samuelmeuli/action-maven-publish@201a45a3f311b2ee888f252ba9f4194257545709 #v1.4.0
3434
with:
3535
gpg_private_key: ${{ secrets.gpg_private_key }}
3636
gpg_passphrase: ${{ secrets.gpg_passphrase }}

pom.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>org.robotframework</groupId>
88
<artifactId>robotframework-maven-plugin</artifactId>
99
<packaging>maven-plugin</packaging>
10-
<version>1.7.3-SNAPSHOT</version>
10+
<version>1.8.0-SNAPSHOT</version>
1111
<name>Robot Framework Maven Plugin</name>
1212
<description>
1313
Maven plugin for the Robot Framework.
@@ -123,7 +123,7 @@
123123
<plugin>
124124
<groupId>org.apache.maven.plugins</groupId>
125125
<artifactId>maven-javadoc-plugin</artifactId>
126-
<version>3.1.1</version>
126+
<version>3.2.0</version>
127127
<executions>
128128
<execution>
129129
<id>attach-javadocs</id>
@@ -203,7 +203,7 @@
203203
<dependency>
204204
<groupId>com.google.guava</groupId>
205205
<artifactId>guava</artifactId>
206-
<version>29.0-jre</version>
206+
<version>30.1-jre</version>
207207
</dependency>
208208
<dependency>
209209
<groupId>org.apache.maven</groupId>
@@ -226,7 +226,7 @@
226226
<dependency>
227227
<groupId>junit</groupId>
228228
<artifactId>junit</artifactId>
229-
<version>4.13.1</version>
229+
<version>4.13.2</version>
230230
<scope>test</scope>
231231
<exclusions>
232232
<exclusion>
@@ -252,7 +252,7 @@
252252
<dependency>
253253
<groupId>org.mockito</groupId>
254254
<artifactId>mockito-core</artifactId>
255-
<version>2.28.2</version>
255+
<version>3.7.7</version>
256256
<scope>test</scope>
257257
<exclusions>
258258
<exclusion>
@@ -264,13 +264,13 @@
264264
<dependency>
265265
<groupId>org.powermock</groupId>
266266
<artifactId>powermock-module-junit4</artifactId>
267-
<version>2.0.7</version>
267+
<version>2.0.9</version>
268268
<scope>test</scope>
269269
</dependency>
270270
<dependency>
271271
<groupId>org.powermock</groupId>
272272
<artifactId>powermock-api-mockito2</artifactId>
273-
<version>2.0.7</version>
273+
<version>2.0.9</version>
274274
<scope>test</scope>
275275
</dependency>
276276

@@ -333,7 +333,7 @@
333333
<plugin>
334334
<groupId>org.apache.maven.plugins</groupId>
335335
<artifactId>maven-resources-plugin</artifactId>
336-
<version>3.1.0</version>
336+
<version>3.2.0</version>
337337
</plugin>
338338
<plugin>
339339
<inherited>true</inherited>
@@ -348,14 +348,14 @@
348348
<plugin>
349349
<groupId>org.apache.maven.plugins</groupId>
350350
<artifactId>maven-surefire-plugin</artifactId>
351-
<version>3.0.0-M4</version>
351+
<version>3.0.0-M5</version>
352352
</plugin>
353353
<plugin>
354354
<!-- integration tests can be skipped using -DskipITs, or -Darguments="-DskipITs"
355355
in a release build, note that you need -D twice in the latter case -->
356356
<groupId>org.apache.maven.plugins</groupId>
357357
<artifactId>maven-failsafe-plugin</artifactId>
358-
<version>3.0.0-M4</version>
358+
<version>3.0.0-M5</version>
359359
<configuration>
360360
<environmentVariables>
361361
<MAVEN_LIBRARY_VERSION>${project.version}</MAVEN_LIBRARY_VERSION>
@@ -401,7 +401,7 @@
401401
<plugin>
402402
<groupId>org.apache.maven.plugins</groupId>
403403
<artifactId>maven-site-plugin</artifactId>
404-
<version>3.8.2</version>
404+
<version>3.9.1</version>
405405
</plugin>
406406
<plugin>
407407
<groupId>com.github.github</groupId>

src/main/java/org/robotframework/mavenplugin/AbstractMojoWithLoadedClasspath.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,40 @@ public abstract class AbstractMojoWithLoadedClasspath
4747
*/
4848
private String localRepository;
4949

50+
/**
51+
* <p>Test are executed in a new process if this configuration is used.</p>
52+
* <p>The classpath for the new process will include by default all the test
53+
* scope dependencies from the pom.</p>
54+
*
55+
* <ul>
56+
* <li>Environment variables can be added with <strong>environmentVariables</strong> map. CLASSPATH environment
57+
* variable is added (prepended) to the default dependencies.</li>
58+
* <li><strong>excludeDependencies</strong> can be used to exclude the test scope dependencies from the classpath of the new process.</li>
59+
* <li><strong>jvmArgs</strong> can be used to specify JVM options</li>
60+
* <li><strong>runnerClass</strong> can be used to specify runner class</li>
61+
* <li><strong>runWithPython</strong> can be used to specify running with Python Robot Framework</li>
62+
* </ul>
63+
*
64+
* Example:
65+
* <pre><![CDATA[<externalRunner>
66+
* <environmentVariables>
67+
* <foo>bar</foo>
68+
* <CLASSPATH>this-should-be-seen-by-external-process.jar</CLASSPATH>
69+
* </environmentVariables>
70+
* <jvmArgs>
71+
* <jvmArg>-XX:PermSize=128m</jvmArg>
72+
* <jvmArg>-XX:MaxPermSize=256m</jvmArg>
73+
* <jvmArg>-Xmx512m</jvmArg>
74+
* </jvmArgs>
75+
* <excludeDependencies>true</excludeDependencies>
76+
* <runnerClass>org.robotframework.RobotFramework</runnerClass>
77+
* <runWithPython>false</runWithPython>
78+
* </externalRunner>]]></pre>
79+
*
80+
* @parameter
81+
*/
82+
protected ExternalRunnerConfiguration externalRunner;
83+
5084
public void execute()
5185
throws MojoExecutionException, MojoFailureException {
5286
loadClassPath();

src/main/java/org/robotframework/mavenplugin/AcceptanceTestMojo.java

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,25 @@ private int executeRobot(String[] runArguments) throws MojoExecutionException {
7575
return externalExecute(runArguments);
7676
}
7777
}
78-
78+
7979
private int externalExecute(String[] runArguments) throws MojoExecutionException {
8080
try {
81-
return exec(RobotFramework.class, runArguments, externalRunner.getEnvironmentVariables());
81+
if (externalRunner.getRunWithPython()) {
82+
return PythonRunner.exec("robot", runArguments);
83+
} else {
84+
return exec(externalRunner.getRunnerClass(), runArguments, externalRunner.getEnvironmentVariables());
85+
}
8286
} catch (IOException e) {
8387
throw new MojoExecutionException("Executing external robot failed.", e);
8488
} catch (InterruptedException e) {
8589
throw new MojoExecutionException("Executing external robot failed.", e);
8690
}
8791
}
8892

89-
public int exec(Class klass, String[] arguments, Map<String, String> environment) throws IOException,
93+
public int exec(String runnerClass, String[] arguments, Map<String, String> environment) throws IOException,
9094
InterruptedException {
91-
ProcessBuilder builder = new ProcessBuilder(createExternalCommand(klass, arguments, externalRunner.getJvmArgs()));
95+
runnerClass = runnerClass == null ? RobotFramework.class.getCanonicalName() : runnerClass;
96+
ProcessBuilder builder = new ProcessBuilder(createExternalCommand(runnerClass, arguments, externalRunner.getJvmArgs()));
9297
Map<String, String> env = builder.environment();
9398
String classpath = externalRunner.getExcludeDependencies() ? getRobotJar() : getClassPathString();
9499
if (environment.containsKey("CLASSPATH")) {
@@ -104,14 +109,13 @@ public int exec(Class klass, String[] arguments, Map<String, String> environment
104109
return process.waitFor();
105110
}
106111

107-
private List<String> createExternalCommand(Class klass, String[] arguments, List<String> jvmArgs) {
112+
private List<String> createExternalCommand(String runnerClass, String[] arguments, List<String> jvmArgs) {
108113
String javaHome = System.getProperty("java.home");
109114
String javaBin = join(File.separator, javaHome, "bin", "java");
110-
String className = klass.getCanonicalName();
111115
List<String> cmd = new ArrayList<String>();
112116
cmd.add(javaBin);
113117
cmd.addAll(jvmArgs);
114-
cmd.add(className);
118+
cmd.add(runnerClass);
115119
cmd.addAll(Arrays.asList(arguments));
116120
System.out.println("Executing Robot with command:");
117121
System.out.println(cmd);
@@ -225,7 +229,6 @@ private String[] generateRunArguments() {
225229
generatedArguments.addFileToArguments(report, "-r");
226230
generatedArguments.addFileToArguments(debugFile, "-b");
227231
generatedArguments.addFileToArguments(argumentFile, "-A");
228-
generatedArguments.addFileToArguments(runFailed, "-R");
229232

230233
generatedArguments.addNonEmptyStringToArguments(console, "--console");
231234
generatedArguments.addNonEmptyStringToArguments(name, "-N");
@@ -828,15 +831,6 @@ private String[] generateRunArguments() {
828831
*/
829832
private boolean runEmptySuite;
830833

831-
/**
832-
* Re-run failed tests, based on output.xml file. This can also be set via
833-
* commandline using -DrunFailed=path/to/output.xml.
834-
*
835-
* @parameter property="runFailed"
836-
*/
837-
private File runFailed;
838-
839-
840834
/**
841835
* If true, sets the return code to zero regardless of failures in test cases. Error codes are
842836
* returned normally.
@@ -845,36 +839,6 @@ private String[] generateRunArguments() {
845839
*/
846840
private boolean noStatusReturnCode;
847841

848-
/**
849-
* <p>Test are executed in a new process if this configuration is used.</p>
850-
* <p>The classpath for the new process will include by default all the test
851-
* scope dependencies from the pom.</p>
852-
*
853-
* <ul>
854-
* <li>Environment variables can be added with <strong>environmentVariables</strong> map. CLASSPATH environment
855-
* variable is added (prepended) to the default dependencies.</li>
856-
* <li><strong>excludeDependencies</strong> can be used to exclude the test scope dependencies from the classpath of the new process.</li>
857-
* <li><strong>jvmArgs</strong> can be used to specify JVM options</li>
858-
* </ul>
859-
*
860-
* Example:
861-
* <pre><![CDATA[<externalRunner>
862-
* <environmentVariables>
863-
* <foo>bar</foo>
864-
* <CLASSPATH>this-should-be-seen-by-external-process.jar</CLASSPATH>
865-
* </environmentVariables>
866-
* <jvmArgs>
867-
* <jvmArg>-XX:PermSize=128m</jvmArg>
868-
* <jvmArg>-XX:MaxPermSize=256m</jvmArg>
869-
* <jvmArg>-Xmx512m</jvmArg>
870-
* </jvmArgs>
871-
* <excludeDependencies>true</excludeDependencies>
872-
* </externalRunner>]]></pre>
873-
*
874-
* @parameter
875-
*/
876-
private ExternalRunnerConfiguration externalRunner;
877-
878842
/**
879843
* Turn on generic automation mode.
880844
*

src/main/java/org/robotframework/mavenplugin/ExternalRunnerConfiguration.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,35 @@ public class ExternalRunnerConfiguration {
3737
*/
3838
private boolean excludeDependencies;
3939

40+
/**
41+
* Execute with pure Python (needs to be available when running).
42+
*
43+
* @parameter default-value="false"
44+
*/
45+
private boolean runWithPython;
46+
47+
/**
48+
* Runner class to start test run.
49+
*
50+
* @parameter default-value="org.robotframework.RobotFramework"
51+
*/
52+
private String runnerClass;
53+
4054
public Map<String, String> getEnvironmentVariables() {
4155
return environmentVariables != null ? environmentVariables : Collections.EMPTY_MAP;
4256
}
4357
public boolean getExcludeDependencies() {
4458
return excludeDependencies;
4559
}
4660

61+
public boolean getRunWithPython() {
62+
return runWithPython;
63+
}
64+
65+
public String getRunnerClass() {
66+
return runnerClass;
67+
}
68+
4769
/**
4870
* JVM arguments for the new runner process.
4971
*

src/main/java/org/robotframework/mavenplugin/LibDocMojo.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ public void runLibDoc() throws IOException {
5151
if (projectBaseDir == null)
5252
projectBaseDir = new File("");
5353
List<String[]> runArgs = libdoc.generateRunArguments(projectBaseDir);
54-
for (String[] args : runArgs)
55-
RobotFramework.run(args);
54+
for (String[] args : runArgs) {
55+
if (externalRunner != null && externalRunner.getRunWithPython()) {
56+
PythonRunner.run(args);
57+
} else {
58+
RobotFramework.run(args);
59+
}
60+
}
5661
}
5762

5863
/**
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.robotframework.mavenplugin;
2+
3+
import java.io.IOException;
4+
5+
import org.apache.commons.lang3.ArrayUtils;
6+
7+
public class PythonRunner{
8+
public static void run(String[] commandWithRunArguments) {
9+
try {
10+
exec(commandWithRunArguments);
11+
} catch (Exception e) {
12+
// Nothing to do
13+
}
14+
}
15+
16+
public static int exec(String command, String[] runArguments) throws IOException,
17+
InterruptedException {
18+
return exec(ArrayUtils.insert(0, runArguments, command));
19+
}
20+
21+
public static int exec(String[] commandWithRunArguments) throws IOException,
22+
InterruptedException {
23+
Process process = Runtime.getRuntime().exec(String.join(" ", commandWithRunArguments));
24+
StreamReader stdout = new StreamReader(process.getInputStream());
25+
StreamReader stderr = new StreamReader(process.getErrorStream());
26+
stdout.start();
27+
stderr.start();
28+
return process.waitFor();
29+
}
30+
}

src/main/java/org/robotframework/mavenplugin/RebotMojo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ protected void subclassExecute()
5050
public void runRebot()
5151
throws IOException {
5252
this.ensureOutputDirectoryExists();
53-
RobotFramework.run(this.generateRunArguments());
53+
if (externalRunner != null && externalRunner.getRunWithPython()) {
54+
PythonRunner.run(this.generateRunArguments());
55+
} else {
56+
RobotFramework.run(this.generateRunArguments());
57+
}
5458
}
5559

5660

src/main/java/org/robotframework/mavenplugin/TestDocMojo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ public void runTestDoc()
5858
List<String[]> runArgs = testdoc.generateRunArguments(projectBaseDir);
5959
for (String[] args : runArgs) {
6060
getLog().debug("Run arguments -> " + args);
61-
RobotFramework.run(args);
61+
if (externalRunner != null && externalRunner.getRunWithPython()) {
62+
PythonRunner.run(args);
63+
} else {
64+
RobotFramework.run(args);
65+
}
6266
}
6367
}
6468

src/test/java/org/robotframework/mavenplugin/AcceptanceTestAndVerifyMojoIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
import java.io.File;
77
import java.io.IOException;
8-
import java.util.*;
8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
import java.util.List;
911

1012
import org.apache.maven.it.VerificationException;
1113
import org.apache.maven.it.Verifier;
1214
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
13-
import org.codehaus.plexus.component.MapOrientedComponent;
1415

1516
public class AcceptanceTestAndVerifyMojoIT
1617
extends AbstractMojoTestCase {

0 commit comments

Comments
 (0)