package com.github.aureliano.achmed.resources;

import org.apache.log4j.Logger;

import com.github.aureliano.achmed.command.CommandFacade;
import com.github.aureliano.achmed.exception.ExecResourceException;
import com.github.aureliano.achmed.resources.properties.ExecProperties;
import com.github.aureliano.achmed.resources.properties.IResourceProperties;

public class ExecResource implements IResource {

	private static final Logger logger = Logger.getLogger(ExecResource.class);
	
	private ExecProperties properties;
	
	public ExecResource() {
		this.properties = new ExecProperties();
	}
	
	public ExecResource(ExecProperties properties) {
		this.properties = properties;
	}

	public void apply() {
		logger.info(" >>> Apply exec resource with command: " + this.properties.getCommand());
		
		this.properties.configureAttributes();
		int exitStatusCode = CommandFacade.executeCommand(this.properties).getExitStatusCode();
		
		if (exitStatusCode != 0) {
			String message = this.executionErrorMessage(exitStatusCode);
			logger.warn(message);
			
			throw new ExecResourceException(message);
		}
	}
	
	public void setProperties(IResourceProperties properties) {
		this.properties = (ExecProperties) properties;
	}
	
	public IResourceProperties getProperties() {
		return this.properties;
	}

	public ResourceType type() {
		return ResourceType.EXEC;
	}
	
	private String executionErrorMessage(int exitStatusCode) {
		return String.format(
			"Command [%s] exited with status code [%d]",
			this.properties.getCommand(),
			exitStatusCode
		);
	}
}
@@ -132,16 +132,76 @@
 Facade;%0A
+import com.github.aureliano.achmed.command.CommandResponse;%0A
 import c
@@ -892,34 +892,35 @@
 es();%0A%09%09
-int exitStatusCode
+CommandResponse res
  = Comma
@@ -963,58 +963,30 @@
 ies)
-.getExitStatusCode();%0A%09%09%0A%09%09if (exitStatusCode != 0
+;%0A%09%09%0A%09%09if (!res.isOK()
 ) %7B%0A
@@ -1032,30 +1032,19 @@
 Message(
-exitStatusCode
+res
 );%0A%09%09%09lo
@@ -1417,26 +1417,27 @@
 age(
-int exitStatusCode
+CommandResponse res
 ) %7B%0A
@@ -1505,16 +1505,28 @@
 ode %5B%25d%5D
+. Detail: %25s
 %22,%0A%09%09%09th
@@ -1556,17 +1556,24 @@
 d(),%0A%09%09%09
-e
+res.getE
 xitStatu
@@ -1577,16 +1577,37 @@
 atusCode
+(),%0A%09%09%09res.getError()
 %0A%09%09);%0A%09%7D

Use command response object instead of just getting exit status code.