}
this.log.info("Executing command line: " + fullCommandLine);
}
// Execute the tool
final ProcessRunner toolProcessRunner = new ProcessRunner();
final boolean executionSuccessful = executeToolProcess(
toolProcessRunner, prCommand, standardInputStream);
// Delete temporary files. However, do NOT delete the output unless the
// execution failed.
final ToolIOProfile outputIOProfile = migrationPath
.getToolOutputProfile();
if ((outputIOProfile.usePipedIO() == false) && executionSuccessful) {
// OK, there should exist an output file. Avoid deleting it.
final String outputFileLabel = outputIOProfile
.getCommandLineFileLabel();
for (String tempFileLabel : temporaryFileMappings.keySet()) {
if (outputFileLabel.equals(tempFileLabel) == false) {
temporaryFileMappings.get(tempFileLabel).delete();
}
}
} else {
// The output has been returned through a pipe, so it is safe to
// delete all files.
for (File tempFile : temporaryFileMappings.values()) {
tempFile.delete();
}
}
if (executionSuccessful == false) {
return buildMigrationResult(migrationPath, digitalObject, null,
toolProcessRunner);
}
// Now create a digital object from the tools output.
DigitalObject.Builder builder;
final ParameterReader parameterReader = new ParameterReader(
toolParameters);
final boolean returnDataByReference = parameterReader
.getBooleanParameter("returnByReference", true);
final ToolIOProfile toolOutputProfile = migrationPath
.getToolOutputProfile();
if (toolOutputProfile.usePipedIO() == false) {
// The tool has written the output to a temporary file. Create a
// digital object based on that.
final File outputFile = temporaryFileMappings.get(toolOutputProfile
.getCommandLineFileLabel());
if (returnDataByReference) {
builder = new DigitalObject.Builder(Content
.byReference(outputFile));
// We cannot tell when the temporary file can be deleted, so let
// it live.
} else {
builder = new DigitalObject.Builder(Content.byValue(outputFile));
// It is now safe to delete the temporary file.
outputFile.delete();
}
} else {
// The tool has written the output to standard output. Create a
// digital object based on that output.
if (returnDataByReference) {
// Direct the standard output contents to a temporary file.
builder = new DigitalObject.Builder(Content
.byReference(toolProcessRunner.getProcessOutput()));
} else {
// Return the standard output contents by value.
builder = new DigitalObject.Builder(Content
.byValue(toolProcessRunner.getProcessOutput()));
}
}
final double migrationDuration = new Date().getTime()
- migrationStartTime.getTime();