Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Robot Framework 5.0 #43

Merged
merged 14 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 114 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@
</developers>

<properties>
<jenkins.version>2.176.3</jenkins.version>
<structs.version>1.17</structs.version>
<workflow-step-api.version>2.19</workflow-step-api.version>
<workflow-api.version>2.30</workflow-api.version>
<junit.version>1.23</junit.version>
<workflow-cps.version>2.66</workflow-cps.version>
<workflow-support.version>3.2</workflow-support.version>
<jenkins.version>2.277.4</jenkins.version>
<structs.version>1.22</structs.version>
<workflow-step-api.version>2.23</workflow-step-api.version>
<workflow-api.version>2.41</workflow-api.version>
<junit.version>1.49</junit.version>
<workflow-cps.version>2.90</workflow-cps.version>
<workflow-support.version>3.7</workflow-support.version>
<matrix-project.version>1.7.1</matrix-project.version>
<token-macro.version>2.0</token-macro.version>
<maven-git-code-format.version>1.25</maven-git-code-format.version>
<script-security.version>1.56</script-security.version>
<blueocean-rest-impl.version>1.19.0</blueocean-rest-impl.version>
<mailer.version>1.20</mailer.version>
<script-security.version>1.76</script-security.version>
<blueocean-rest-impl.version>1.25.0</blueocean-rest-impl.version>
<mailer.version>1.34</mailer.version>
<workflow-durable-task-step.version>2.13</workflow-durable-task-step.version>
<workflow-job.version>2.11.2</workflow-job.version>
<workflow-job.version>2.40</workflow-job.version>
<workflow-basic-steps.version>2.6</workflow-basic-steps.version>
<java.level>8</java.level>
</properties>
Expand All @@ -62,7 +62,17 @@
<url>https://www.github.com/jenkinsci/robot-plugin</url>
<tag>robot-2.0.0</tag>
</scm>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.222.x</artifactId>
<version>10</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down Expand Up @@ -99,13 +109,13 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>${workflow-basic-steps.version}</version>
<!-- <version>${workflow-basic-steps.version}</version>-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>${workflow-durable-task-step.version}</version>
<!-- <version>${workflow-durable-task-step.version}</version>-->
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -123,7 +133,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>${matrix-project.version}</version>
<!-- <version>${matrix-project.version}</version>-->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -149,6 +159,95 @@
<version>${mailer.version}</version>
<optional>true</optional>
</dependency>

<!-- RequireUpperBounds -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jackson2-api</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>display-url-api</artifactId>
<version>2.3.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>variant</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>2.3.17</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>symbol-annotation</artifactId>
<version>1.22</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>6.15</version>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>snakeyaml-api</artifactId>
<version>1.27.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.30</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-tree</artifactId>
<version>9.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-analysis</artifactId>
<version>9.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<version>9.0</version>
</dependency>

</dependencies>

<distributionManagement>
Expand Down
122 changes: 90 additions & 32 deletions src/main/java/hudson/plugins/robot/RobotParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,24 @@ private RobotCaseResult processTest(XMLStreamReader reader, RobotSuiteResult res
StringBuilder stackTrace = new StringBuilder();

//parse stacktrace
String xmlTag = ignoreUntilStarts(reader, "kw", "for", "if", "doc", "tags", "tag", "status");
while (xmlTag.equals("kw") || xmlTag.equals("for") || xmlTag.equals("if")) {
if (xmlTag.equals("if")) {
stackTrace.append(processIf(reader, 0));
} else if (xmlTag.equals("for")) {
stackTrace.append(processForLoop(reader, 0));
} else {
stackTrace.append(processKeyword(reader, 0));
String[] possible_elements = {"kw", "for", "if", "try", "while", "doc", "tags", "tag", "status"};
String[] elements = {"kw", "for", "if", "try", "while"};
String xmlTag = ignoreUntilStarts(reader, possible_elements);
while (isNameInElements(xmlTag, elements)) {
switch (xmlTag) {
case "if":
case "try":
stackTrace.append(processBranchable(reader, 0));
break;
case "for":
case "while":
stackTrace.append(processLoop(reader, 0));
break;
default:
stackTrace.append(processKeyword(reader, 0));
break;
}
xmlTag = ignoreUntilStarts(reader, "kw", "for", "if", "doc", "tags", "tag", "status");
xmlTag = ignoreUntilStarts(reader, possible_elements);
}

caseResult.setStackTrace(stackTrace.toString().trim().replaceAll("\n+", "\n"));
Expand Down Expand Up @@ -341,12 +349,16 @@ private RobotCaseResult processTest(XMLStreamReader reader, RobotSuiteResult res
return caseResult;
}

private String processForLoop(XMLStreamReader reader, int nestedCount) throws XMLStreamException {
private String processLoop(XMLStreamReader reader, int nestedCount) throws XMLStreamException {
StringBuilder stackTrace = new StringBuilder();
String indentation = getSpacesPerNestedLevel(nestedCount);
stackTrace.append(indentation + "FOR " + reader.getAttributeValue(null, "flavor"));
String kind = reader.getLocalName();
stackTrace.append(indentation + kind.toUpperCase());
if (kind.equals("for")) {
stackTrace.append(" " + reader.getAttributeValue(null, "flavor"));
}
while (reader.hasNext()) {
if (reader.isEndElement() && reader.getLocalName().equals("for")) {
if (reader.isEndElement() && reader.getLocalName().equals(kind)) {
break;
}
if (reader.isStartElement() && reader.getLocalName().equals("iter")) {
Expand All @@ -366,14 +378,25 @@ private String processIteration(XMLStreamReader reader, int nestedCount) throws
}
if (reader.isStartElement()) {
String xmlTag = reader.getLocalName();
if (xmlTag.equals("for")) {
stackTrace.append(processForLoop(reader, nestedCount));
}
if (xmlTag.equals("kw")) {
stackTrace.append(processKeyword(reader, nestedCount));
}
if (xmlTag.equals("if")) {
stackTrace.append(processIf(reader, nestedCount));
switch (xmlTag) {
case "for":
case "while":
stackTrace.append(processLoop(reader, nestedCount));
break;
case "kw":
stackTrace.append(processKeyword(reader, nestedCount));
break;
case "if":
case "try":
stackTrace.append(processBranchable(reader, nestedCount));
break;
case "return":
case "break":
case "continue":
stackTrace.append(processReturnBreakContinue(reader, nestedCount));
break;
default:
break;
}
}
reader.next();
Expand All @@ -382,11 +405,12 @@ private String processIteration(XMLStreamReader reader, int nestedCount) throws
return stackTrace.toString();
}

private String processIf(XMLStreamReader reader, int nestedCount) throws XMLStreamException {
private String processBranchable(XMLStreamReader reader, int nestedCount) throws XMLStreamException {
StringBuilder stackTrace = new StringBuilder();
String indentation = getSpacesPerNestedLevel(nestedCount);
String kind = reader.getLocalName();
while (reader.hasNext()) {
if (reader.isEndElement() && reader.getLocalName().equals("if")) {
if (reader.isEndElement() && reader.getLocalName().equals(kind)) {
break;
}
if (reader.isStartElement() && reader.getLocalName().equals("branch")) {
Expand All @@ -407,14 +431,25 @@ private String processBranch(XMLStreamReader reader, int nestedCount) throws XML
}
if (reader.isStartElement()) {
String xmlTag = reader.getLocalName();
if (xmlTag.equals("for")) {
stackTrace.append(processForLoop(reader, nestedCount));
}
if (xmlTag.equals("kw")) {
stackTrace.append(processKeyword(reader, nestedCount));
}
if (xmlTag.equals("if")) {
stackTrace.append(processIf(reader, nestedCount));
switch (xmlTag) {
case "for":
case "while":
stackTrace.append(processLoop(reader, nestedCount));
break;
case "kw":
stackTrace.append(processKeyword(reader, nestedCount));
break;
case "if":
case "try":
stackTrace.append(processBranchable(reader, nestedCount));
break;
case "return":
case "break":
case "continue":
stackTrace.append(processReturnBreakContinue(reader, nestedCount));
break;
default:
break;
}
}
reader.next();
Expand All @@ -440,13 +475,20 @@ private String processKeyword(XMLStreamReader reader, int nestedCount) throws XM
stackTrace.append(processArgs(reader));
continue; // processArgs returns with us already in <kw>. We don't want to use reader.next()
case "for":
stackTrace.append(processForLoop(reader, nestedCount+1));
case "while":
stackTrace.append(processLoop(reader, nestedCount+1));
break;
case "kw":
stackTrace.append(processKeyword(reader, nestedCount+1));
break;
case "if":
stackTrace.append(processIf(reader, nestedCount+1));
case "try":
stackTrace.append(processBranchable(reader, nestedCount+1));
break;
case "return":
case "break":
case "continue":
stackTrace.append(processReturnBreakContinue(reader, nestedCount+1));
break;
default:
break;
Expand Down Expand Up @@ -500,6 +542,22 @@ private List<String> processTags(XMLStreamReader reader) throws XMLStreamExcepti
return tagList;
}

private String processReturnBreakContinue(XMLStreamReader reader, int nestedCount) throws XMLStreamException {
StringBuilder stringBuilder = new StringBuilder();
String kind = reader.getLocalName();
stringBuilder.append(getSpacesPerNestedLevel(nestedCount)).append(kind.toUpperCase());
while(reader.hasNext()) {
if (reader.isEndElement() && reader.getLocalName().equals(kind)) {
break;
}
if (reader.isStartElement() && reader.getLocalName().equals("kw")) {
stringBuilder.append(processKeyword(reader, nestedCount+1));
}
reader.next();
}
return stringBuilder.toString();
}

private static void setCriticalityIfAvailable(XMLStreamReader reader, RobotCaseResult caseResult) {
String criticality = reader.getAttributeValue(null, "critical");
if (criticality != null) {
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/hudson/plugins/robot/RobotParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ public void testRobot4If() {
final String dir = ".";
final String mask = "robot4_if_output.xml";
parse(dir, mask);
}

/** Robot Framework 5.0 introduced TRY-EXCEPT, WHILE,
* BREAK, and CONTINUE. The output file contains simple
* test cases which use new features.
*/
@Test
public void testRobot5TryExceptFinallyWhileContinue() {
final String dir = "robot5";
final String mask = "basic_new_features_output.xml";
parse(dir, mask);
}
}
Loading