本文整理汇总了Java中org.alfresco.util.exec.RuntimeExec.ExecutionResult类的典型用法代码示例。如果您正苦于以下问题:Java ExecutionResult类的具体用法?Java ExecutionResult怎么用?Java ExecutionResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExecutionResult类属于org.alfresco.util.exec.RuntimeExec包,在下文中一共展示了ExecutionResult类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
private synchronized void execute()
{
// have we already done this?
if (executed)
{
return;
}
executed = true;
for (RuntimeExec command : shutdownCommands)
{
ExecutionResult result = command.execute();
// check for failure
if (!result.getSuccess())
{
logger.error("Shutdown command execution failed. Continuing with other commands.: \n" + result);
}
}
// done
if (logger.isDebugEnabled())
{
logger.debug("Executed shutdown commands");
}
}
示例2: testStreams
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
public void testStreams() throws Exception
{
RuntimeExec exec = new RuntimeExec();
// This test will return different results on Windows and Linux!
// note that some Unix variants will error without a path
HashMap<String, String[]> commandMap = new HashMap<String, String[]>(5);
commandMap.put("*", new String[] {"find", "/", "-maxdepth", "1", "-name", "var"});
commandMap.put("Windows.*", new String[] {"find", "/?"});
exec.setCommandsAndArguments(commandMap);
// execute
ExecutionResult ret = exec.execute();
String out = ret.getStdOut();
String err = ret.getStdErr();
assertEquals("Didn't expect error code", 0, ret.getExitValue());
assertEquals("Didn't expect any error output", 0, err.length());
assertTrue("No output found", out.length() > 0);
}
示例3: testFailureModeOfMissingCommand
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
public void testFailureModeOfMissingCommand()
{
File dir = new File(DIR);
dir.mkdir();
assertTrue("Directory not created", dir.exists());
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(APP_CONTEXT_XML);
try
{
RuntimeExec failureExec = (RuntimeExec) ctx.getBean("commandFailureGuaranteed");
assertNotNull(failureExec);
// Execute it
ExecutionResult result = failureExec.execute();
assertEquals("Expected first error code in list", 666, result.getExitValue());
}
finally
{
ctx.close();
}
}
示例4: afterPropertiesSet
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
/**
* Checks for the JMagick and ImageMagick dependencies, using the common
* {@link #transformInternal(File, String, File, String, TransformationOptions) transformation method} to check
* that the sample image can be converted.
*/
@Override
public void afterPropertiesSet()
{
if (executer == null)
{
throw new AlfrescoRuntimeException("System runtime executer not set");
}
super.afterPropertiesSet();
if (isAvailable())
{
try
{
// On some platforms / versions, the -version command seems to return an error code whilst still
// returning output, so let's not worry about the exit code!
ExecutionResult result = this.checkCommand.execute();
this.versionString = result.getStdOut().trim();
}
catch (Throwable e)
{
setAvailable(false);
logger.error(getClass().getSimpleName() + " not available: "
+ (e.getMessage() != null ? e.getMessage() : ""));
// debug so that we can trace the issue if required
logger.debug(e);
}
}
}
示例5: afterPropertiesSet
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
/**
* Executes the check command, if present. Any errors will result in this component
* being rendered unusable within the transformer registry, but may still be called
* directly.
*/
public void afterPropertiesSet()
{
if (transformCommand == null)
{
throw new AlfrescoRuntimeException("Mandatory property 'transformCommand' not set");
}
// execute the command
if (checkCommand != null)
{
ExecutionResult result = checkCommand.execute();
// check the return code
if (this.available = result.getSuccess())
{
this.versionString = result.getStdOut().trim();
}
else
{
logger.error("Failed to start a runtime executable content transformer: \n" + result);
}
}
else
{
// no check - just assume it is available
available = true;
}
}
示例6: afterPropertiesSet
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception
{
PropertyCheck.mandatory(this, "executer", executer);
PropertyCheck.mandatory(this, "checkCommand", checkCommand);
// check availability
try
{
ExecutionResult result = this.checkCommand.execute();
if(result.getSuccess())
{
this.versionString = result.getStdOut().trim();
setAvailable(true);
logger.info("Using PDF Renderer: "+this.versionString);
}
else
{
setAvailable(false);
logger.error("Alfresco-PDF-Renderer is not available for transformations.\n"+result.toString());
}
}
catch (Throwable e)
{
setAvailable(false);
logger.error(getClass().getSimpleName() + " not available: " + (e.getMessage() != null ? e.getMessage() : ""));
// debug so that we can trace the issue if required
logger.debug(e);
}
}
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:AlfrescoPdfRendererContentTransformerWorker.java
示例7: updateOSNameAttributeForLinux
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
/**
* Adds a Linux version
*
* @param osName os.name attribute
* @return String
*/
public static String updateOSNameAttributeForLinux(String osName)
{
RuntimeExec exec = new RuntimeExec();
Map<String, String[]> commandMap = new HashMap<String, String[]>(3, 1.0f);
commandMap.put("Linux", new String[] { "lsb_release", "-d" });
exec.setCommandsAndArguments(commandMap);
ExecutionResult ret = exec.execute();
if (ret.getSuccess())
{
osName += " (" + ret.getStdOut().replace("\n", "") + ")";
}
else
{
commandMap.put("Linux", new String[] { "uname", "-a" });
exec.setCommandsAndArguments(commandMap);
ret = exec.execute();
if (ret.getSuccess())
{
osName += " (" + ret.getStdOut().replace("\n", "") + ")";
}
else
{
osName += " (Unknown)";
}
}
return osName;
}
示例8: RuntimeExecBootstrapBean
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
/**
* Initializes the bean
* <ul>
* <li>failOnError = true</li>
* <li>killProcessesOnShutdown = true</li>
* <li>enabled = true</li>
* </ul>
*/
public RuntimeExecBootstrapBean()
{
this.startupCommands = Collections.emptyList();
this.executionResults = new ArrayList<ExecutionResult>(1);
failOnError = true;
killProcessesOnShutdown = true;
enabled = true;
}
示例9: doShutdown
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
private void doShutdown()
{
if (!killProcessesOnShutdown)
{
// Do not force a kill
return;
}
for (ExecutionResult executionResult : executionResults)
{
executionResult.killProcess();
}
}
示例10: longishRunningProcess
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
private void longishRunningProcess(int runFor, long timeout)
{
long marginOfError = 3000;
boolean shouldComplete = timeout <= 0;
assertTrue("The timeout when set must be more than "+marginOfError+"ms", shouldComplete || timeout >= marginOfError);
assertTrue("The timeout when set plus "+marginOfError+"ms must less than the runFor value", shouldComplete || timeout+marginOfError <= runFor);
long minTime = (shouldComplete ? runFor : timeout) - marginOfError;
long maxTime = (shouldComplete ? runFor : timeout) + marginOfError;
RuntimeExec exec = new RuntimeExec();
// This test will return different results on Windows and Linux!
// note that some Unix variants will error without a path
HashMap<String, String[]> commandMap = new HashMap<String, String[]>();
commandMap.put("*", new String[] {"sleep", ""+(runFor/1000)});
commandMap.put("Windows.*", new String[] {"ping", "-n", ""+(runFor/1000+1), "127.0.0.1"}); // don't you just love Microsoft
// execute
exec.setCommandsAndArguments(commandMap);
long time = System.currentTimeMillis();
ExecutionResult ret = exec.execute(Collections.<String,String>emptyMap(), timeout);
time = System.currentTimeMillis()-time;
String out = ret.getStdOut();
String err = ret.getStdErr();
assertTrue("Command was too fast "+time+"ms", time >= minTime);
assertTrue("Command was too slow "+time+"ms", time <= maxTime);
if (shouldComplete)
assertEquals("Didn't expect error code", 0, ret.getExitValue());
else
assertFalse("Didn't expect success code", 0 == ret.getExitValue());
}
示例11: transformInternal
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
/**
* Transform the image content from the source file to the target file
*/
@Override
protected void transformInternal(File sourceFile, String sourceMimetype,
File targetFile, String targetMimetype, TransformationOptions options) throws Exception
{
Map<String, String> properties = new HashMap<String, String>(5);
// set properties
if (options instanceof ImageTransformationOptions)
{
ImageTransformationOptions imageOptions = (ImageTransformationOptions)options;
CropSourceOptions cropOptions = imageOptions.getSourceOptions(CropSourceOptions.class);
ImageResizeOptions resizeOptions = imageOptions.getResizeOptions();
String commandOptions = imageOptions.getCommandOptions();
if (commandOptions == null)
{
commandOptions = "";
}
// MNT-10882 : JPEG File Format, does not save the alpha (transparency) channel.
if (MimetypeMap.MIMETYPE_IMAGE_JPEG.equalsIgnoreCase(targetMimetype) && isAlphaOptionSupported())
{
commandOptions += " -alpha remove";
}
if (imageOptions.isAutoOrient())
{
commandOptions = commandOptions + " -auto-orient";
}
if (cropOptions != null)
{
commandOptions = commandOptions + " " + getImageCropCommandOptions(cropOptions);
}
if (resizeOptions != null)
{
commandOptions = commandOptions + " " + getImageResizeCommandOptions(resizeOptions);
}
properties.put(KEY_OPTIONS, commandOptions);
}
properties.put(VAR_SOURCE, sourceFile.getAbsolutePath() +
getSourcePageRange(options, sourceMimetype, targetMimetype));
properties.put(VAR_TARGET, targetFile.getAbsolutePath());
// execute the statement
long timeoutMs = options.getTimeoutMs();
RuntimeExec.ExecutionResult result = executer.execute(properties, timeoutMs);
if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0)
{
throw new ContentIOException("Failed to perform ImageMagick transformation: \n" + result);
}
// success
if (logger.isDebugEnabled())
{
logger.debug("ImageMagick executed successfully: \n" + executer);
}
}
示例12: transformInternal
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
/**
* Transform the pdf content from the source file to the target file
*/
private void transformInternal(File sourceFile, String sourceMimetype, File targetFile, String targetMimetype, TransformationOptions options) throws Exception
{
Map<String, String> properties = new HashMap<String, String>(5);
// set properties
if (options instanceof ImageTransformationOptions)
{
ImageTransformationOptions imageOptions = (ImageTransformationOptions) options;
ImageResizeOptions resizeOptions = imageOptions.getResizeOptions();
String commandOptions = imageOptions.getCommandOptions();
if (commandOptions == null)
{
commandOptions = "";
}
if(resizeOptions != null)
{
if (resizeOptions.getHeight() > -1)
{
commandOptions += " --height=" + resizeOptions.getHeight();
}
if (resizeOptions.getWidth() > -1)
{
commandOptions += " --width=" + resizeOptions.getHeight();
}
if (resizeOptions.getAllowEnlargement())
{
commandOptions += " --allow-enlargement";
}
if (resizeOptions.isMaintainAspectRatio())
{
commandOptions += " --maintain-aspect-ratio";
}
}
commandOptions += " --page=" + getSourcePageRange(imageOptions, sourceMimetype, targetMimetype);
properties.put(KEY_OPTIONS, commandOptions);
}
properties.put(VAR_SOURCE, sourceFile.getAbsolutePath());
properties.put(VAR_TARGET, targetFile.getAbsolutePath());
// execute the statement
long timeoutMs = options.getTimeoutMs();
RuntimeExec.ExecutionResult result = executer.execute(properties, timeoutMs);
if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0)
{
throw new ContentIOException("Failed to perform alfresco-pdf-renderer transformation: \n" + result);
}
// success
if (logger.isDebugEnabled())
{
logger.debug("alfresco-pdf-renderer executed successfully: \n" + executer);
}
}
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:58,代码来源:AlfrescoPdfRendererContentTransformerWorker.java
示例13: onBootstrap
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
@Override
protected synchronized void onBootstrap(ApplicationEvent event)
{
// If the command is disabled then do nothing.
if (this.enabled == false)
{
if (logger.isDebugEnabled())
{
logger.debug("Bootstrap execution of " + startupCommands.size() + " was not enabled");
}
return;
}
// execute
for (RuntimeExec command : startupCommands)
{
ExecutionResult result = command.execute();
// check for failure
if (!result.getSuccess())
{
String msg = "Bootstrap command failed: \n" + result;
if (failOnError)
{
throw new AlfrescoRuntimeException(msg);
}
else
{
logger.error(msg);
}
}
else
{
// It executed, so keep track of it
executionResults.add(result);
}
}
if (killProcessesOnShutdown)
{
// Force a shutdown on VM termination as we can't rely on the Spring context termination
this.shutdownThread = new KillProcessShutdownThread();
Runtime.getRuntime().addShutdownHook(this.shutdownThread);
}
// done
if (logger.isDebugEnabled())
{
logger.debug("Bootstrap execution of " + startupCommands.size() + " commands was successful");
}
}
示例14: unmountFilesystem
import org.alfresco.util.exec.RuntimeExec.ExecutionResult; //导入依赖的package包/类
/**
* Unmount a remote CIFS shared filesystem
*
* @param driveLetter String
* @param mountPoint String
* @exception CifsMountException
*/
public void unmountFilesystem( String driveLetter, String mountPoint)
throws CifsMountException
{
// Create the command line launcher
RuntimeExec exec = new RuntimeExec();
// Create the command map and properties
Map<String, String> commandMap = new HashMap<String, String>( 1);
Map<String, String> defProperties = new HashMap<String, String>( 10);
// Determine the platform type and build the appropriate command line string
Platform.Type platform = Platform.isPlatformType();
switch ( platform)
{
// Windows
case WINDOWS:
commandMap.put( "Windows.*", WindowsUnMountCmd);
break;
// Linux
case LINUX:
commandMap.put( "Linux", LinuxUnMountCmd);
break;
// Mac OS X
case MACOSX:
commandMap.put( "Mac OS X", MacOSXUnMountCmd);
break;
}
// Set the command map
exec.setCommandMap( commandMap);
// Build the command line properties list
defProperties.put( "drive", driveLetter);
defProperties.put( "mountpoint", mountPoint);
exec.setDefaultProperties(defProperties);
// Get the command to be used on this platform
if ( logger.isDebugEnabled())
logger.debug( "UnMount CIFS share, cmdLine=" + Arrays.toString(exec.getCommand()));
// Run the command
ExecutionResult execRes = exec.execute();
if ( logger.isDebugEnabled())
logger.debug( "UnMount result=" + execRes);
// Check if the command was successful
if ( execRes.getSuccess() == false)
throw new CifsMountException( execRes.getExitValue(), execRes.getStdOut(), execRes.getStdErr());
}