ATS-213 : Transformers should have unique option name

This commit is contained in:
Cezar Leahu
2018-12-11 16:02:04 +00:00
parent d50cc236ab
commit 54a7b07e55
8 changed files with 159 additions and 87 deletions

View File

@@ -8,32 +8,24 @@ import java.util.Map;
import org.alfresco.transformer.exceptions.TransformException;
import org.alfresco.util.exec.RuntimeExec;
import org.alfresco.util.exec.RuntimeExec.ExecutionResult;
/**
*/
public abstract class AbstractCommandExecutor implements CommandExecutor
{
private RuntimeExec transformCommand = createTransformCommand();
private RuntimeExec checkCommand = createCheckCommand();
private final RuntimeExec transformCommand = createTransformCommand();
private final RuntimeExec checkCommand = createCheckCommand();
protected abstract RuntimeExec createTransformCommand();
protected abstract RuntimeExec createCheckCommand();
// todo remove these setters and and make the fields final
public void setTransformCommand(RuntimeExec re) {
transformCommand = re;
}
public void setCheckCommand(RuntimeExec re) {
checkCommand = re;
}
@Override
public void run(Map<String, String> properties, File targetFile, Long timeout)
{
timeout = timeout != null && timeout > 0 ? timeout : 0;
RuntimeExec.ExecutionResult result = transformCommand.execute(properties, timeout);
final ExecutionResult result = transformCommand.execute(properties, timeout);
if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0)
{
@@ -51,24 +43,23 @@ public abstract class AbstractCommandExecutor implements CommandExecutor
@Override
public String version()
{
String version = "Version not checked";
if (checkCommand != null)
{
RuntimeExec.ExecutionResult result = checkCommand.execute();
final ExecutionResult result = checkCommand.execute();
if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0)
{
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
"Transformer version check exit code was not 0: \n" + result);
}
version = result.getStdOut().trim();
final String version = result.getStdOut().trim();
if (version.isEmpty())
{
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
"Transformer version check failed to create any output");
}
return version;
}
return version;
return "Version not checked";
}
}