Skip to content

Commit

Permalink
Adds env arg for validate task (#88)
Browse files Browse the repository at this point in the history
* Adds env arg for validate task

---------

Signed-off-by: Haroon Sheikh <[email protected]>
  • Loading branch information
haroon-sheikh authored Mar 26, 2024
1 parent 3755ee0 commit cc5ddac
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Add the below snippet to pom.xml
<plugin>
<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-maven-plugin</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>
</plugin>
</plugins>
</build>
Expand Down Expand Up @@ -101,7 +101,7 @@ Run gauge specs in project as a part of maven test phase by adding the below exe
<plugin>
<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-maven-plugin</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>
<executions>
<execution>
<phase>test</phase>
Expand Down Expand Up @@ -147,7 +147,7 @@ Validate gauge specs in project as a part of maven test-compile phase by adding
<plugin>
<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-maven-plugin</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>
<executions>
<execution>
<phase>test-compile</phase>
Expand Down Expand Up @@ -175,7 +175,7 @@ Add the following execution to pom.xml to run both goals:
<plugin>
<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-maven-plugin</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>
<executions>
<execution>
<id>validate</id>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-maven-plugin</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>
<packaging>maven-plugin</packaging>
<name>Gauge Maven Plugin</name>
<url>https://github.com/getgauge-contrib/gauge-maven-plugin</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public class GaugeValidationMojo extends AbstractMojo {
@Parameter(property = "project.testClasspathElements", required = true, readonly = true)
private List<String> classpath;

/**
* Gauge environment to validate specs against
*/
@Parameter(defaultValue = "${gauge.exec.env}", property = "env", required = false)
private String env;

/**
* Additional flags for gauge execution
*/
Expand Down Expand Up @@ -89,6 +95,7 @@ public ArrayList<String> getCommand() {
ArrayList<String> command = new ArrayList<String>();
command.add(GAUGE);
command.add(VALIDATE);
addEnv(command);
addAdditionalFlags(command);
addSpecsDir(command);
return command;
Expand All @@ -102,6 +109,13 @@ private void addSpecsDir(ArrayList<String> command) {
}
}

private void addEnv(ArrayList<String> command) {
if (this.env != null && this.env.trim().length() > 0) {
command.add(GaugeCommand.ENV_FLAG);
command.add(env);
}
}

private void addAdditionalFlags(ArrayList<String> command) {
if (flags != null) {
command.addAll(flags);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/archetype-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<dependency>
<groupId>com.thoughtworks.gauge</groupId>
<artifactId>gauge-java</artifactId>
<version>0.3.4</version>
<version>0.10.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -22,7 +22,7 @@
<plugin>
<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-maven-plugin</artifactId>
<version>1.1.0</version>
<version>${version}</version>
<executions>
<execution>
<phase>test</phase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,17 @@ public void testGetCommandWithMultipleSpecs() throws Exception {
assertEquals(expected, actual);
}

public void testGerCommandWithHideSuggestion() throws Exception {
public void testGetCommandWithEnvironmentArg() throws Exception {
File testPom = getPomFile("validate_env.xml");

GaugeValidationMojo mojo = (GaugeValidationMojo) lookupMojo(GaugeValidationMojo.GAUGE_VALIDATION_MOJO_NAME, testPom);

ArrayList<String> actual = mojo.getCommand();
List<String> expected = Arrays.asList("gauge", "validate", "--env", "test", getPath(getBasedir(), "specs"));
assertEquals(expected, actual);
}

public void testGetCommandWithHideSuggestion() throws Exception {
File testPom = getPomFile("validate_flags.xml");

GaugeValidationMojo mojo = (GaugeValidationMojo) lookupMojo(GaugeValidationMojo.GAUGE_VALIDATION_MOJO_NAME, testPom);
Expand Down
27 changes: 27 additions & 0 deletions src/test/resources/poms/validate_env.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.foo</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>


<build>
<plugins>
<plugin>
<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<env>test</env>
<specsDir>specs</specsDir>
</configuration>
</plugin>
</plugins>

</build>

</project>

0 comments on commit cc5ddac

Please sign in to comment.