Skip to content

Commit

Permalink
released v0.6
Browse files Browse the repository at this point in the history
* fixed issue #108
  • Loading branch information
Clayton7510 committed Aug 27, 2019
1 parent 5bcab39 commit bab5fc3
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 31 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[tf-maven-plugin]:https://search.maven.org/artifact/com.deliveredtechnologies/tf-maven-plugin/0.5.4/maven-plugin
[tf-cmd-api]:https://search.maven.org/artifact/com.deliveredtechnologies/tf-cmd-api/0.5.4/jar
[tf-s3-archetype]:https://search.maven.org/artifact/com.deliveredtechnologies/tf-s3-archetype/0.5.4/jar
[tf-maven-plugin]:https://search.maven.org/artifact/com.deliveredtechnologies/tf-maven-plugin/0.6/maven-plugin
[tf-cmd-api]:https://search.maven.org/artifact/com.deliveredtechnologies/tf-cmd-api/0.6/jar
[tf-s3-archetype]:https://search.maven.org/artifact/com.deliveredtechnologies/tf-s3-archetype/0.6/jar
[tf-maven-plugin-snapshot]:https://oss.sonatype.org/content/repositories/snapshots/com/deliveredtechnologies/tf-maven-plugin/
[tf-cmd-api-snapshot]:https://oss.sonatype.org/content/repositories/snapshots/com/deliveredtechnologies/tf-cmd-api/
[tf-s3-archetype-snapshot]:https://oss.sonatype.org/content/repositories/snapshots/com/deliveredtechnologies/tf-s3-archetype/
[maven-badge]:https://img.shields.io/badge/maven%20central-0.5.4-green.svg
[maven-snapshot-badge]:https://img.shields.io/badge/SNAPSHOT-0.5.4-green.svg
[maven-badge]:https://img.shields.io/badge/maven%20central-0.6-green.svg
[maven-snapshot-badge]:https://img.shields.io/badge/SNAPSHOT-0.6-green.svg
[tf-maven-plugin-synk-badge]:https://snyk.io/test/github/deliveredtechnologies/terraform-maven/badge.svg?targetFile=tf-build-tools%2Ftf-maven-plugin%2Fpom.xml
[tf-maven-plugin-synk]:https://snyk.io/test/github/deliveredtechnologies/terraform-maven?targetFile=tf-build-tools%2Ftf-maven-plugin%2Fpom.xml
[tf-cmd-api-synk-badge]:https://snyk.io/test/github/deliveredtechnologies/terraform-maven/badge.svg?targetFile=tf-build-tools%2Ftf-cmd-api%2Fpom.xml
Expand Down Expand Up @@ -258,7 +258,7 @@ Deletes all 'terraform' files from terraform configurations along with the Terra

```xml
<properties>
<tf-maven-version>0.5.4</tf-maven-version>
<tf-maven-version>0.6</tf-maven-version>
</properties>
```

Expand Down Expand Up @@ -369,15 +369,15 @@ Instead of doing all the above steps you can simply build the module/project by
An example on how to generate the project using an archetype is shown below.

```bash
mvn archetype:generate -B -DarchetypeGroupId=com.deliveredtechnologies -DarchetypeArtifactId="tf-s3-archetype" -DarchetypeVersion=0.5.4 -DgroupId=<custom_group_name> -DartifactId=<custom-artifact_name>
mvn archetype:generate -B -DarchetypeGroupId=com.deliveredtechnologies -DarchetypeArtifactId="tf-s3-archetype" -DarchetypeVersion=0.6 -DgroupId=<custom_group_name> -DartifactId=<custom-artifact_name>
```

Maven Non-Interactive mode creates a project with the name that you passed in <custom_articatId_name> under <custom_groupId_name>.

or

```bash
mvn archetype:generate -DarchetypeGroupId=com.deliveredtechnologies -DarchetypeArtifactId="tf-s3-archetype" -DarchetypeVersion=0.5.4
mvn archetype:generate -DarchetypeGroupId=com.deliveredtechnologies -DarchetypeArtifactId="tf-s3-archetype" -DarchetypeVersion=0.6
```

After running the above command mvn interactive console prompts for the required arguments (ex: groupId and artifactId) and creates the project accordingly.
Expand Down
2 changes: 1 addition & 1 deletion examples/tf-s3-consumer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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>
<properties>
<tf-maven-version>0.5.4</tf-maven-version>
<tf-maven-version>0.6</tf-maven-version>
</properties>
<artifactId>tf-s3-consumer</artifactId>
<groupId>com.deliveredtechnologies.example.maven.tf</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/tf-s3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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>
<properties>
<tf-maven-version>0.5.4</tf-maven-version>
<tf-maven-version>0.6</tf-maven-version>
</properties>
<artifactId>tf-s3</artifactId>
<groupId>com.deliveredtechnologies.example.maven.tf</groupId>
Expand Down
2 changes: 1 addition & 1 deletion tf-build-tools/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="1"/>
<property name="allowedAbbreviationLength" value="2"/>
</module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="CustomImportOrder">
Expand Down
2 changes: 1 addition & 1 deletion tf-build-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.deliveredtechnologies</groupId>
<artifactId>tf-build-tools</artifactId>
<packaging>pom</packaging>
<version>0.5.4</version>
<version>0.6</version>
<description>Terraform Build Tools: The parent POM project for Java and Terraform Tools</description>
<modules>
<module>tf-cmd-api</module>
Expand Down
2 changes: 1 addition & 1 deletion tf-build-tools/tf-cmd-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tf-build-tools</artifactId>
<groupId>com.deliveredtechnologies</groupId>
<version>0.5.4</version>
<version>0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>tf-cmd-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,26 @@ public class CommandLine implements Executable {
private static int DEFAULT_TIMEOUT = 600000;

private Path directory;
private boolean inheritIO;
private Optional<Logger> logger;

public CommandLine(Path directory) {
this(directory, null);
}

public CommandLine(Path directory, Logger logger) {
this(directory, true, logger);
}

/**
* CommandLine Constructor.
* @param directory the directory in which to run the command
* @param inheritIO true if the process running the command should inherit the stdout of the parent process
* @param logger SLF4J Logger
*/
public CommandLine(Path directory, boolean inheritIO, Logger logger) {
this.logger = Optional.ofNullable(logger);
this.inheritIO = inheritIO;
this.directory = directory;
}

Expand All @@ -40,35 +52,45 @@ public CommandLine(Path directory, Logger logger) {
public String execute(String command, int timeout) throws IOException, InterruptedException {
boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");

Process process;
ProcessBuilder processBuilder;
Optional<String> output;
Optional<String> error;
if (isWindows) {
String[] cmd = new String[] {
"cmd.exe",
"/c",
command
};
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
processBuilder = new ProcessBuilder(cmd);
processBuilder.directory(directory.toAbsolutePath().toFile());
process = processBuilder.start();
} else {
String[] cmd = new String[] {
"bash",
"-c",
command
};
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
processBuilder = new ProcessBuilder(cmd);
processBuilder.directory(directory.toFile());
}

Process process;
if (inheritIO) {
processBuilder = processBuilder.inheritIO();
output = Optional.empty();
error = Optional.empty();
process = processBuilder.start();
} else {
process = processBuilder.start();
output = Optional.ofNullable(IOUtils.toString(new InputStreamReader(process.getInputStream())));
error = Optional.ofNullable(IOUtils.toString(new InputStreamReader(process.getErrorStream())));
}

String output = IOUtils.toString(new InputStreamReader(process.getInputStream()));
String error = IOUtils.toString(new InputStreamReader(process.getErrorStream()));
process.waitFor(timeout, TimeUnit.MILLISECONDS);

if (process.exitValue() > 0) {
throw new IOException("Exit value was greater than zero!\n" + error);
throw new IOException("Exit value was greater than zero!\n" + error.orElse(""));
}
return output;
return output.orElse("");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.deliveredtechnologies.terraform.api;

import com.deliveredtechnologies.io.CommandLine;
import com.deliveredtechnologies.io.Executable;
import com.deliveredtechnologies.terraform.TerraformCommand;
import com.deliveredtechnologies.terraform.TerraformCommandLineDecorator;
import com.deliveredtechnologies.terraform.TerraformException;
import com.deliveredtechnologies.terraform.TerraformUtils;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Properties;
Expand All @@ -15,12 +18,12 @@ public class TerraformOutput implements TerraformOperation<String> {
this.terraform = terraform;
}

public TerraformOutput() throws IOException {
this(new TerraformCommandLineDecorator(TerraformCommand.OUTPUT));
public TerraformOutput() throws IOException, TerraformException {
this(new String());
}

public TerraformOutput(String tfRootDir) throws IOException, TerraformException {
this(new TerraformCommandLineDecorator(TerraformCommand.OUTPUT, tfRootDir));
this(new TerraformCommandLineDecorator(TerraformCommand.OUTPUT, new CommandLine(tfRootDir == null || tfRootDir.isEmpty() ? TerraformUtils.getDefaultTerraformRootModuleDir() : TerraformUtils.getTerraformRootModuleDir(tfRootDir), false, LoggerFactory.getLogger(CommandLine.class))));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URISyntaxException;
Expand All @@ -25,7 +26,7 @@ public void setup() throws URISyntaxException {
@Test
public void executeRunsCommandOnCommandLineShellAndReturnsTheOutput() throws IOException, InterruptedException {
String echoString = "Hello World!";
Executable commandLine = new CommandLine(directory);
Executable commandLine = new CommandLine(directory, false, LoggerFactory.getLogger(CommandLine.class));
String output = commandLine.execute(String.format("echo %1$s", echoString));
Assert.assertEquals(String.format("%1$s%n", echoString), output);

Expand All @@ -38,7 +39,7 @@ public void executeRunsInTheSpecifiedDirectory() throws IOException, Interrupted
boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
Path path = Paths.get("src", "main", "tf", "root");
FileUtils.forceMkdir(path.toFile());
Executable commandLine = new CommandLine(path);
Executable commandLine = new CommandLine(path, false, LoggerFactory.getLogger(CommandLine.class));;
if (isWindows) {
String output = commandLine.execute("cd");
Assert.assertEquals(String.format("%1$s%n", path.toAbsolutePath().toString()), output);
Expand All @@ -52,7 +53,7 @@ public void executeRunsInTheSpecifiedDirectory() throws IOException, Interrupted
@Test(expected = IOException.class)
public void executeThatErrorsOnItsCommandThrowsTheErrorOutput() throws IOException, InterruptedException {
String errorCommand = "exit 1";
Executable commandLine = new CommandLine(directory);
Executable commandLine = new CommandLine(directory, false, LoggerFactory.getLogger(CommandLine.class));
String output = commandLine.execute(errorCommand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ public void terraformOutputCallsOutputCommandWithTimeout() throws InterruptedExc
Assert.assertEquals(successResponse, terraformOutput.execute(properties));
Mockito.verify(commandLine, Mockito.times(1)).execute(Mockito.anyString(), Mockito.anyInt());
}

@Test(expected = TerraformException.class)
public void terraformExecuteThrowsTerraformException() throws IOException, InterruptedException, TerraformException {
Mockito.when(terraform.execute(Mockito.anyString())).thenThrow(new IOException());

TerraformOutput terraformOutput = new TerraformOutput(terraform);
terraformOutput.execute(properties);
}
}
2 changes: 1 addition & 1 deletion tf-build-tools/tf-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.deliveredtechnologies</groupId>
<artifactId>tf-build-tools</artifactId>
<version>0.5.4</version>
<version>0.6</version>
</parent>
<artifactId>tf-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ protected final void execute(TerraformOperation<T> tfOperation, Properties prope
try {
Object response = tfOperation.execute(properties);
if (response instanceof String) {
getLog().info((String) response);
String responseString = (String)response;
if (!responseString.isEmpty()) {
getLog().info((String) response);
}
}
} catch (TerraformException e) {
throw new MojoExecutionException("Failed to execute terraform operation", e);
Expand Down
2 changes: 1 addition & 1 deletion tf-build-tools/tf-s3-archetype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.deliveredtechnologies</groupId>
<version>0.5.4</version>
<version>0.6</version>
<artifactId>tf-build-tools</artifactId>
</parent>
<artifactId>tf-s3-archetype</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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>
<properties>
<tf-maven-version>0.5.4-SNAPSHOT</tf-maven-version>
<tf-maven-version>0.6</tf-maven-version>
</properties>
<artifactId>${artifactId}</artifactId>
<groupId>${groupId}</groupId>
Expand Down

0 comments on commit bab5fc3

Please sign in to comment.