本文整理汇总了Java中org.apache.commons.exec.OS.isFamilyWindows方法的典型用法代码示例。如果您正苦于以下问题:Java OS.isFamilyWindows方法的具体用法?Java OS.isFamilyWindows怎么用?Java OS.isFamilyWindows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.exec.OS
的用法示例。
在下文中一共展示了OS.isFamilyWindows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeWSCommand
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
public void executeWSCommand() throws Throwable {
if (OS.isFamilyWindows()) {
throw new SkipException("Test not valid for Windows");
}
JavaProfile profile = new JavaProfile(LaunchMode.JAVA_WEBSTART).addWSArgument("-verbose").addVMArgument("-Dx.y.z=hello");
final CommandLine commandLine = profile.getCommandLine();
AssertJUnit.assertNotNull(commandLine);
AssertJUnit.assertTrue(commandLine.toString().contains("-javaagent:"));
AssertJUnit.assertTrue(commandLine.toString().contains("-verbose"));
AssertJUnit.assertTrue(commandLine.toString().contains("-Dx.y.z=hello"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
commandLine.copyOutputTo(baos);
commandLine.executeAsync();
new Wait("Waiting till the command is complete") {
@Override public boolean until() {
return !commandLine.isRunning();
}
};
BufferedReader reader = new BufferedReader(new StringReader(new String(baos.toByteArray())));
String line = reader.readLine();
while (line != null && !line.contains("Web Start")) {
line = reader.readLine();
}
AssertJUnit.assertTrue(line.contains("Web Start"));
}
示例2: getExecScriptFileOrNull
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
private File getExecScriptFileOrNull(String scriptNameBase) {
String resource = null;
if (OS.isFamilyWindows()) {
resource = scriptNameBase + ".bat";
} else if (OS.isFamilyUnix()) {
resource = scriptNameBase + ".sh";
}
File resourceFile = getClasspathResourceFileOrNull(resource);
// TODO use canExecute here (available since java 1.6)
if (resourceFile != null && !resourceFile.canRead()) {
logger.warn("The resource " + resourceFile.getAbsolutePath() + " is not readable!");
// it is not readable, do not try to execute it
return null;
}
return resourceFile;
}
示例3: findExecutable
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
static String findExecutable( final String executable, final List<String> paths )
{
File f = null;
search: for ( final String path : paths )
{
f = new File( path, executable );
if ( !OS.isFamilyWindows() && f.isFile() )
break;
else
for ( final String extension : getExecutableExtensions() )
{
f = new File( path, executable + extension );
if ( f.isFile() )
break search;
}
}
if ( f == null || !f.exists() )
return null;
return f.getAbsolutePath();
}
示例4: searchForServerDirectory
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
/**
* Search the operating system for an Appium server installation directory.
*
* @return A File representation to the Appium server installation
* directory.
*/
private File searchForServerDirectory() {
if (OS.isFamilyWindows()) {
if (getArch().equals("32")) {
return doesDirectoryExists(System.getenv("ProgramFiles")
+ "/Appium");
} else {
// must be the x86_64
return doesDirectoryExists(System.getenv("ProgramFiles")
+ " (x86)/Appium");
}
} else if (OS.isFamilyMac()) {
return doesDirectoryExists(APPIUM_SERVER_MAC_DEFAULT_DIRECTORY);
}
// server directrory was not found.
throw new ServerDirectoryNotFoundException();
}
示例5: init
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
private void init() throws MojoExecutionException {
// Supply variables that are OS dependent
if (OS.isFamilyWindows()) {
if (command == null) {
command = "taskkill";
}
} else if (OS.isFamilyUnix() || OS.isFamilyMac()) {
if (command == null) {
command = "kill";
}
} else {
if (command == null) {
throw new MojoExecutionException(
"Unknown OS - You must use the 'command' parameter");
}
}
}
示例6: testExecute
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
@Test
public void testExecute() throws MojoExecutionException, IOException {
// PREPARE
final EventStorePostStartMojo testee = new EventStorePostStartMojo();
final File dir = new File("./src/test").getCanonicalFile();
testee.setEventStoreDir(dir);
if (OS.isFamilyWindows()) {
testee.setPostStartCommand(dir + File.separator + "echotest.bat");
} else {
testee.setPostStartCommand(dir + File.separator + "echotest.sh");
}
// TEST
testee.execute();
// VERIFY
assertThat(testee.getMessages()).contains("Hello world!");
}
示例7: checkGivenExecutableIsUsed
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
public void checkGivenExecutableIsUsed() throws Throwable {
JavaProfile profile = new JavaProfile(LaunchMode.JAVA_APPLET);
File f = findFile();
profile.setAppletURL(f.getAbsolutePath());
profile.setStartWindowTitle("Applet Viewer: SwingSet3Init.class");
String actual = "";
if (OS.isFamilyWindows()) {
String path = System.getenv("Path");
String[] split = path.split(";");
File file = new File(split[0]);
File[] listFiles = file.listFiles();
if (listFiles != null) {
for (File listFile : listFiles) {
if (listFile.getName().contains(".exe")) {
profile.setJavaCommand(listFile.getAbsolutePath());
actual = listFile.getAbsolutePath();
break;
}
}
}
} else {
actual = "ls";
profile.setJavaCommand(actual);
}
CommandLine commandLine = profile.getCommandLine();
AssertJUnit.assertTrue(commandLine.toString().contains(actual));
}
示例8: getProcessStatus
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
/**
* get the status of the processname.
*
* @param processname
* the process name
* @return the status of the process
* @throws IOException
* throw IOException if occur error
*/
public static String getProcessStatus(String processname) throws IOException {
if (isLinux() || OS.isFamilyMac()) {
String line = "ps -ef";
String r = run(line);
StringBuilder sb = new StringBuilder();
String[] ss = r.split("\n");
if (ss != null && ss.length > 0) {
for (String s : ss) {
if (s.contains(processname)) {
sb.append(s).append("\n");
}
}
}
return sb.toString();
} else if (OS.isFamilyWindows()) {
String cmd = "tasklist /nh /FI \"IMAGENAME eq " + processname + "\"";
return run(cmd);
} else {
throw new IOException("not support");
}
}
示例9: getStartScriptName
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
public static String getStartScriptName() throws URISyntaxException {
String base="Transkribus.";
if (OS.isFamilyWindows()) {
String exe = base+"exe";
String cmd = "cmd /c start "+exe;
// cmd += "& del "+getCurrentJar().getName(); // this cleans the old version in windows after the new version has started --> should work, as current JVM should exit sooner than new program has started!
return cmd;
} else if (OS.isFamilyMac()) {
return "./"+base+"command";
} else {
return "./"+base+"sh";
}
}
示例10: getClasspathArg
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
private String getClasspathArg() {
String classpath = System.getProperty("java.class.path");
if (OS.isFamilyWindows()) {
// On windows the ";" character is replaced by a space by the
// command interpreter. Thus the classpath is split with the
// ;-token. Therefore the classpath should be quoted with double
// quotes
classpath = "\"\"" + classpath + "\"\"";
} else {
// quote only once
classpath = "\"" + classpath + "\"";
}
return classpath;
}
示例11: createEnvWrapperFile
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
protected File createEnvWrapperFile( File envScript )
throws IOException
{
PrintWriter writer = null;
File tmpFile = null;
try
{
if ( OS.isFamilyWindows() )
{
tmpFile = File.createTempFile( "env", ".bat" );
writer = new PrintWriter( tmpFile );
writer.append( "@echo off" ).println();
writer.append( "call \"" ).append( envScript.getCanonicalPath() ).append( "\"" ).println();
writer.append( "echo " + EnvStreamConsumer.START_PARSING_INDICATOR ).println();
writer.append( "set" ).println();
writer.flush();
}
else
{
tmpFile = File.createTempFile( "env", ".sh" );
// tmpFile.setExecutable( true );//java 6 only
writer = new PrintWriter( tmpFile );
writer.append( "#! /bin/sh" ).println();
writer.append( ". " ).append( envScript.getCanonicalPath() ).println(); // works on all unix??
writer.append( "echo " + EnvStreamConsumer.START_PARSING_INDICATOR ).println();
writer.append( "env" ).println();
writer.flush();
}
}
finally
{
IOUtil.close( writer );
}
return tmpFile;
}
示例12: testGetExecutablePathPreferExecutableExtensionsOnWindows
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
public void testGetExecutablePathPreferExecutableExtensionsOnWindows()
throws IOException
{
// this test is for Windows
if (!OS.isFamilyWindows()) {
return;
}
final ExecMojo realMojo = new ExecMojo();
final String tmp = System.getProperty("java.io.tmpdir");
final File workdir = new File(tmp, "testGetExecutablePathPreferExecutableExtensionsOnWindows");
workdir.mkdirs();
final Map<String, String> enviro = new HashMap<String, String>();
final File f = new File(workdir, "mycmd");
final File fCmd = new File(workdir, "mycmd.cmd");
f.createNewFile();
fCmd.createNewFile();
assertTrue( "file exists...", f.exists() );
assertTrue( "file exists...", fCmd.exists() );
realMojo.setExecutable( "mycmd" );
final CommandLine cmd = realMojo.getExecutablePath( enviro, workdir );
// cmdline argumets are: [/c, %path-to-temp%\mycmd.cmd], so check second argument
assertTrue( "File should have cmd extension",
cmd.getArguments()[1].endsWith( "mycmd.cmd" ) );
f.delete();
fCmd.delete();
assertFalse( "file deleted...", f.exists() );
assertFalse( "file deleted...", fCmd.exists() );
}
示例13: getCommandLineAsString
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
private String getCommandLineAsString( CommandLine commandline )
{
// for the sake of the test comparisons, cut out the eventual
// cmd /c *.bat conversion
String result = commandline.getExecutable();
boolean isCmd = false;
if ( OS.isFamilyWindows() && result.equals( "cmd" ) )
{
result = "";
isCmd = true;
}
String[] arguments = commandline.getArguments();
for ( int i = 0; i < arguments.length; i++ )
{
String arg = arguments[i];
if ( isCmd && i == 0 && "/c".equals( arg ) )
{
continue;
}
if ( isCmd && i == 1 && arg.endsWith( ".bat" ) )
{
arg = arg.substring( 0, arg.length() - ".bat".length() );
}
result += ( result.length() == 0 ? "" : " " ) + arg;
}
return result;
}
示例14: createEnvironmentMap
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
/**
* Creates a map that obeys the casing rules of the current platform for key
* lookup. E.g. on a Windows platform, the map keys will be
* case-insensitive.
*
* @return The map for storage of environment variables, never
* <code>null</code>.
*/
private Map createEnvironmentMap() {
if (OS.isFamilyWindows()) {
return new TreeMap(new Comparator() {
public int compare(Object arg0, Object arg1) {
String key0 = (String) arg0;
String key1 = (String) arg1;
return key0.compareToIgnoreCase(key1);
}
});
} else {
return new HashMap();
}
}
示例15: AppiumServer
import org.apache.commons.exec.OS; //导入方法依赖的package包/类
/**
* Constructs an Appium server instance. Searches automatically for an
* installed Appium server on your machine using the default installation
* location according to your operating system.
*
* The searched directories are: <br><ul><li>Windows OS: "C:/Program
* Files/Appium" & "C:/Program Files (x86)/Appium"</li> <li>Mac OS:
* "/Applications/Appium.app/Contents/Resources" </li></ul>zz
*
* @param serverArguments The server arguments to be used when working with
* the server.
*/
public AppiumServer(ServerArguments serverArguments) {
this._serverArguments = serverArguments;
// search for installed Appium server
_absoluteServerDirectory = searchForServerDirectory();
// make sure to get the node executable file path along with the appium.js path too.
_nodeExecutableFilePath = new File(OS.isFamilyWindows()
? _absoluteServerDirectory + NODE_RELATIVE_PATH_WINDOWS
: _absoluteServerDirectory + NODE_RELATIVE_PATH_MAC_OS);
_appiumJavaScriptFilePath = new File(_absoluteServerDirectory
+ APPIUM_FILE_RELATIVE_PATH);
}