List of usage examples for org.apache.commons.lang SystemUtils IS_OS_WINDOWS
boolean IS_OS_WINDOWS
To view the source code for org.apache.commons.lang SystemUtils IS_OS_WINDOWS.
Click Source Link
Is true
if this is Windows.
The field will return false
if OS_NAME
is null
.
From source file:org.apache.cxf.maven_plugin.Java2WSMojo.java
private File getJavaExecutable() throws IOException { String exe = (SystemUtils.IS_OS_WINDOWS && !javaExecutable.endsWith(".exe")) ? ".exe" : ""; File javaExe = new File(javaExecutable + exe); if (!javaExe.isFile()) { throw new IOException("The java executable '" + javaExe + "' doesn't exist or is not a file. Verify the <javaExecutable/> parameter."); }/*from w w w . j a v a 2s.c o m*/ return javaExe; }
From source file:org.apache.falcon.security.AuthenticationInitializationServiceTest.java
@Test public void testKerberosAuthenticationWithKeytabFileNotReadable() { /* Return if OS is Windows because of JDK issue for setReadable */ if (SystemUtils.IS_OS_WINDOWS) { return;//from w ww. j a va 2 s. c om } File tempFile = new File(".keytabFile"); try { assert tempFile.createNewFile(); assert tempFile.setReadable(false); StartupProperties.get().setProperty(SecurityUtil.AUTHENTICATION_TYPE, KerberosAuthenticationHandler.TYPE); StartupProperties.get().setProperty(AuthenticationInitializationService.KERBEROS_KEYTAB, tempFile.toString()); authenticationService.init(); Assert.fail("The keytab file is not readable! must have been thrown."); } catch (Exception e) { Assert.assertEquals(e.getCause().getClass(), IllegalArgumentException.class); } finally { assert tempFile.delete(); } }
From source file:org.apache.flume.client.avro.TestReliableSpoolingFileEventReader.java
@Test public void testConsumeFileRandomlyNewFile() throws Exception { // Atomic moves are not supported in Windows. if (SystemUtils.IS_OS_WINDOWS) { return;//from w ww . ja v a2 s . c o m } final ReliableEventReader reader = new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR) .consumeOrder(ConsumeOrder.RANDOM).build(); File fileName = new File(WORK_DIR, "new-file"); FileUtils.write(fileName, "New file created in the end. Shoud be read randomly.\n"); Set<String> expected = Sets.newHashSet(); int totalFiles = WORK_DIR.listFiles().length; final Set<String> actual = Sets.newHashSet(); ExecutorService executor = Executors.newSingleThreadExecutor(); final Semaphore semaphore1 = new Semaphore(0); final Semaphore semaphore2 = new Semaphore(0); Future<Void> wait = executor.submit(new Callable<Void>() { @Override public Void call() throws Exception { readEventsForFilesInDir(WORK_DIR, reader, actual, semaphore1, semaphore2); return null; } }); semaphore1.acquire(); File finalFile = new File(WORK_DIR, "t-file"); FileUtils.write(finalFile, "Last file"); semaphore2.release(); wait.get(); int listFilesCount = ((ReliableSpoolingFileEventReader) reader).getListFilesCount(); finalFile.delete(); createExpectedFromFilesInSetup(expected); expected.add(""); expected.add("New file created in the end. Shoud be read randomly."); expected.add("Last file"); Assert.assertTrue(listFilesCount < (totalFiles + 2)); Assert.assertEquals(expected, actual); }
From source file:org.apache.geode.util.test.TestUtil.java
private static String compatibleWithWindows(String path) { return SystemUtils.IS_OS_WINDOWS ? path.substring(1) : path; }
From source file:org.apache.ivy.core.retrieve.RetrieveTest.java
public void testRetrieveWithSymlinksMass() throws Exception { if (SystemUtils.IS_OS_WINDOWS) { return;//from w w w. j ava 2 s . c om } // mod1.1 depends on mod1.2 ResolveReport report = ivy.resolve( new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURI().toURL(), getResolveOptions(new String[] { "*" })); assertNotNull(report); ModuleDescriptor md = report.getModuleDescriptor(); assertNotNull(md); RetrieveOptions options = getRetrieveOptions().setMakeSymlinksInMass(true); String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]"; ivy.retrieve(md.getModuleRevisionId(), pattern, options); assertLink( IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar", "default")); pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]"; ivy.retrieve(md.getModuleRevisionId(), pattern, options); assertLink( IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar", "default")); }
From source file:org.apache.maven.plugin.jar.JarSignMojo.java
private static File getJDKCommandExe(String command) { String fullCommand = command + (SystemUtils.IS_OS_WINDOWS ? ".exe" : ""); File exe;/*w ww. j a v a 2 s. c om*/ // For IBM's JDK 1.2 if (SystemUtils.IS_OS_AIX) { exe = new File(SystemUtils.getJavaHome() + "/../sh", fullCommand); } else if (SystemUtils.IS_OS_MAC_OSX) { exe = new File(SystemUtils.getJavaHome() + "/bin", fullCommand); } else { exe = new File(SystemUtils.getJavaHome() + "/../bin", fullCommand); } return exe; }
From source file:org.apache.maven.plugin.javadoc.AbstractJavadocMojo.java
/** * Get the path of the Javadoc tool executable depending the user entry or try to find it depending the OS * or the <code>java.home</code> system property or the <code>JAVA_HOME</code> environment variable. * * @return the path of the Javadoc tool//from w ww . j a v a2 s . c o m * @throws IOException if not found */ private String getJavadocExecutable() throws IOException { Toolchain tc = getToolchain(); if (tc != null) { getLog().info("Toolchain in javadoc-plugin: " + tc); if (javadocExecutable != null) { getLog().warn( "Toolchains are ignored, 'javadocExecutable' parameter is set to " + javadocExecutable); } else { javadocExecutable = tc.findTool("javadoc"); } } String javadocCommand = "javadoc" + (SystemUtils.IS_OS_WINDOWS ? ".exe" : ""); File javadocExe; // ---------------------------------------------------------------------- // The javadoc executable is defined by the user // ---------------------------------------------------------------------- if (StringUtils.isNotEmpty(javadocExecutable)) { javadocExe = new File(javadocExecutable); if (javadocExe.isDirectory()) { javadocExe = new File(javadocExe, javadocCommand); } if (SystemUtils.IS_OS_WINDOWS && javadocExe.getName().indexOf('.') < 0) { javadocExe = new File(javadocExe.getPath() + ".exe"); } if (!javadocExe.isFile()) { throw new IOException("The javadoc executable '" + javadocExe + "' doesn't exist or is not a file. Verify the <javadocExecutable/> parameter."); } return javadocExe.getAbsolutePath(); } // ---------------------------------------------------------------------- // Try to find javadocExe from System.getProperty( "java.home" ) // By default, System.getProperty( "java.home" ) = JRE_HOME and JRE_HOME // should be in the JDK_HOME // ---------------------------------------------------------------------- // For IBM's JDK 1.2 if (SystemUtils.IS_OS_AIX) { javadocExe = new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh", javadocCommand); } else if (SystemUtils.IS_OS_MAC_OSX) { javadocExe = new File(SystemUtils.getJavaHome() + File.separator + "bin", javadocCommand); } else { javadocExe = new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "bin", javadocCommand); } // ---------------------------------------------------------------------- // Try to find javadocExe from JAVA_HOME environment variable // ---------------------------------------------------------------------- if (!javadocExe.exists() || !javadocExe.isFile()) { Properties env = CommandLineUtils.getSystemEnvVars(); String javaHome = env.getProperty("JAVA_HOME"); if (StringUtils.isEmpty(javaHome)) { throw new IOException("The environment variable JAVA_HOME is not correctly set."); } if ((!new File(javaHome).getCanonicalFile().exists()) || (new File(javaHome).getCanonicalFile().isFile())) { throw new IOException("The environment variable JAVA_HOME=" + javaHome + " doesn't exist or is not a valid directory."); } javadocExe = new File(javaHome + File.separator + "bin", javadocCommand); } if (!javadocExe.getCanonicalFile().exists() || !javadocExe.getCanonicalFile().isFile()) { throw new IOException("The javadoc executable '" + javadocExe + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable."); } return javadocExe.getAbsolutePath(); }
From source file:org.apache.maven.plugin.javadoc.AbstractJavadocMojo.java
/** * Write a debug javadoc script in case of command line error or in debug mode. * * @param cmdLine the current command line as string, not null. * @param javadocOutputDirectory the output dir, not null. * @see #executeJavadocCommandLine(Commandline, File) * @since 2.6//from w ww .j a va2s . c o m */ private void writeDebugJavadocScript(String cmdLine, File javadocOutputDirectory) { File commandLineFile = new File(javadocOutputDirectory, DEBUG_JAVADOC_SCRIPT_NAME); commandLineFile.getParentFile().mkdirs(); try { FileUtils.fileWrite(commandLineFile.getAbsolutePath(), null /* platform encoding */, cmdLine); if (!SystemUtils.IS_OS_WINDOWS) { Runtime.getRuntime().exec(new String[] { "chmod", "a+x", commandLineFile.getAbsolutePath() }); } } catch (IOException e) { logError("Unable to write '" + commandLineFile.getName() + "' debug script file", e); } }
From source file:org.apache.maven.plugin.javadoc.JavadocReportTest.java
/** * Method to test proxy support in the javadoc * * @throws Exception if any//from w ww . j a v a 2 s . c o m */ public void testProxy() throws Exception { Settings settings = new Settings(); Proxy proxy = new Proxy(); // dummy proxy proxy.setActive(true); proxy.setHost("127.0.0.1"); proxy.setPort(80); proxy.setProtocol("http"); proxy.setUsername("toto"); proxy.setPassword("toto"); proxy.setNonProxyHosts("www.google.com|*.somewhere.com"); settings.addProxy(proxy); File testPom = new File(getBasedir(), "src/test/resources/unit/proxy-test/proxy-test-plugin-config.xml"); JavadocReport mojo = (JavadocReport) lookupMojo("javadoc", testPom); assertNotNull(mojo); setVariableValueToObject(mojo, "settings", settings); setVariableValueToObject(mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories()); mojo.execute(); File commandLine = new File(getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + (SystemUtils.IS_OS_WINDOWS ? "bat" : "sh")); assertTrue(FileUtils.fileExists(commandLine.getAbsolutePath())); String readed = readFile(commandLine); assertTrue(readed.contains("-J-Dhttp.proxySet=true")); assertTrue(readed.contains("-J-Dhttp.proxyHost=127.0.0.1")); assertTrue(readed.contains("-J-Dhttp.proxyPort=80")); assertTrue(readed.contains("-J-Dhttp.proxyUser=\\\"toto\\\"")); assertTrue(readed.contains("-J-Dhttp.proxyPassword=\\\"toto\\\"")); assertTrue(readed.contains("-J-Dhttp.nonProxyHosts=\\\"www.google.com|*.somewhere.com\\\"")); File options = new File(getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/options"); assertTrue(FileUtils.fileExists(options.getAbsolutePath())); String optionsContent = readFile(options); // NO -link expected assertFalse(optionsContent.contains("-link")); // real proxy ProxyServer proxyServer = null; AuthAsyncProxyServlet proxyServlet; try { proxyServlet = new AuthAsyncProxyServlet(); proxyServer = new ProxyServer(proxyServlet); proxyServer.start(); settings = new Settings(); proxy = new Proxy(); proxy.setActive(true); proxy.setHost(proxyServer.getHostName()); proxy.setPort(proxyServer.getPort()); proxy.setProtocol("http"); settings.addProxy(proxy); mojo = (JavadocReport) lookupMojo("javadoc", testPom); setVariableValueToObject(mojo, "settings", settings); setVariableValueToObject(mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories()); mojo.execute(); readed = readFile(commandLine); assertTrue(readed.contains("-J-Dhttp.proxySet=true")); assertTrue(readed.contains("-J-Dhttp.proxyHost=" + proxyServer.getHostName())); assertTrue(readed.contains("-J-Dhttp.proxyPort=" + proxyServer.getPort())); optionsContent = readFile(options); // -link expected // TODO: This got disabled for now! // This test fails since the last commit but I actually think it only ever worked by accident. // It did rely on a commons-logging-1.0.4.pom which got resolved by a test which did run previously. // But after updating to commons-logging.1.1.1 there is no pre-resolved artifact available in // target/local-repo anymore, thus the javadoc link info cannot get built and the test fails // I'll for now just disable this line of code, because the test as far as I can see _never_ // did go upstream. The remoteRepository list used is always empty!. // // assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) ); } finally { if (proxyServer != null) { proxyServer.stop(); } } // auth proxy Map<String, String> authentications = new HashMap<String, String>(); authentications.put("foo", "bar"); try { proxyServlet = new AuthAsyncProxyServlet(authentications); proxyServer = new ProxyServer(proxyServlet); proxyServer.start(); settings = new Settings(); proxy = new Proxy(); proxy.setActive(true); proxy.setHost(proxyServer.getHostName()); proxy.setPort(proxyServer.getPort()); proxy.setProtocol("http"); proxy.setUsername("foo"); proxy.setPassword("bar"); settings.addProxy(proxy); mojo = (JavadocReport) lookupMojo("javadoc", testPom); setVariableValueToObject(mojo, "settings", settings); setVariableValueToObject(mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories()); mojo.execute(); readed = readFile(commandLine); assertTrue(readed.contains("-J-Dhttp.proxySet=true")); assertTrue(readed.contains("-J-Dhttp.proxyHost=" + proxyServer.getHostName())); assertTrue(readed.contains("-J-Dhttp.proxyPort=" + proxyServer.getPort())); assertTrue(readed.contains("-J-Dhttp.proxyUser=\\\"foo\\\"")); assertTrue(readed.contains("-J-Dhttp.proxyPassword=\\\"bar\\\"")); optionsContent = readFile(options); // -link expected // see comment above (line 829) // assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) ); } finally { if (proxyServer != null) { proxyServer.stop(); } } }
From source file:org.apache.maven.plugin.jdeps.AbstractJDepsMojo.java
private String getJDepsExecutable() throws IOException { Toolchain tc = getToolchain();/* ww w .j a va 2s . c o m*/ String jdepsExecutable = null; if (tc != null) { jdepsExecutable = tc.findTool("jdeps"); } String jdepsCommand = "jdeps" + (SystemUtils.IS_OS_WINDOWS ? ".exe" : ""); File jdepsExe; if (StringUtils.isNotEmpty(jdepsExecutable)) { jdepsExe = new File(jdepsExecutable); if (jdepsExe.isDirectory()) { jdepsExe = new File(jdepsExe, jdepsCommand); } if (SystemUtils.IS_OS_WINDOWS && jdepsExe.getName().indexOf('.') < 0) { jdepsExe = new File(jdepsExe.getPath() + ".exe"); } if (!jdepsExe.isFile()) { throw new IOException("The jdeps executable '" + jdepsExe + "' doesn't exist or is not a file."); } return jdepsExe.getAbsolutePath(); } // ---------------------------------------------------------------------- // Try to find jdepsExe from System.getProperty( "java.home" ) // By default, System.getProperty( "java.home" ) = JRE_HOME and JRE_HOME // should be in the JDK_HOME // ---------------------------------------------------------------------- // For IBM's JDK 1.2 if (SystemUtils.IS_OS_AIX) { jdepsExe = new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh", jdepsCommand); } // For Apple's JDK 1.6.x (and older?) on Mac OSX // CHECKSTYLE_OFF: MagicNumber else if (SystemUtils.IS_OS_MAC_OSX && SystemUtils.JAVA_VERSION_FLOAT < 1.7f) // CHECKSTYLE_ON: MagicNumber { jdepsExe = new File(SystemUtils.getJavaHome() + File.separator + "bin", jdepsCommand); } else { jdepsExe = new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "bin", jdepsCommand); } // ---------------------------------------------------------------------- // Try to find jdepsExe from JAVA_HOME environment variable // ---------------------------------------------------------------------- if (!jdepsExe.exists() || !jdepsExe.isFile()) { Properties env = CommandLineUtils.getSystemEnvVars(); String javaHome = env.getProperty("JAVA_HOME"); if (StringUtils.isEmpty(javaHome)) { throw new IOException("The environment variable JAVA_HOME is not correctly set."); } if ((!new File(javaHome).getCanonicalFile().exists()) || (new File(javaHome).getCanonicalFile().isFile())) { throw new IOException("The environment variable JAVA_HOME=" + javaHome + " doesn't exist or is not a valid directory."); } jdepsExe = new File(javaHome + File.separator + "bin", jdepsCommand); } if (!jdepsExe.getCanonicalFile().exists() || !jdepsExe.getCanonicalFile().isFile()) { throw new IOException("The jdeps executable '" + jdepsExe + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable."); } return jdepsExe.getAbsolutePath(); }