protected String getJdkToolPathname(final String jdkToolExecutableName, final GemFireException throwable) { assertNotNull(jdkToolExecutableName, "The JDK tool executable name cannot be null!"); assertNotNull(throwable, "The GemFireException cannot be null!"); final Stack<String> pathnames = new Stack<String>(); pathnames.push(jdkToolExecutableName); pathnames.push(IOUtils.appendToPath(System.getenv("JAVA_HOME"), "..", "bin", jdkToolExecutableName)); pathnames.push(IOUtils.appendToPath(System.getenv("JAVA_HOME"), "bin", jdkToolExecutableName)); pathnames.push(IOUtils.appendToPath(JAVA_HOME, "..", "bin", jdkToolExecutableName)); pathnames.push(IOUtils.appendToPath(JAVA_HOME, "bin", jdkToolExecutableName)); return getJdkToolPathname(pathnames, throwable); }
@Test(expected = NullPointerException.class) public void testGetJdkToolPathnameWithNullGemFireException() { try { getLauncherLifecycleCommands().getJdkToolPathname(new Stack<String>(), null); } catch (NullPointerException expected) { assertEquals("The GemFireException cannot be null!", expected.getMessage()); throw expected; } }
protected String getJdkToolPathname(final String jdkToolExecutableName, final GemFireException throwable) { assertNotNull(jdkToolExecutableName, "The JDK tool executable name cannot be null!"); assertNotNull(throwable, "The GemFireException cannot be null!"); Stack<String> pathnames = new Stack<>(); pathnames.push(jdkToolExecutableName); pathnames.push(IOUtils.appendToPath(System.getenv("JAVA_HOME"), "..", "bin", jdkToolExecutableName)); pathnames.push(IOUtils.appendToPath(System.getenv("JAVA_HOME"), "bin", jdkToolExecutableName)); pathnames.push(IOUtils.appendToPath(JAVA_HOME, "..", "bin", jdkToolExecutableName)); pathnames.push(IOUtils.appendToPath(JAVA_HOME, "bin", jdkToolExecutableName)); return getJdkToolPathname(pathnames, throwable); }
protected String getJConsolePathname() { return getJdkToolPathname("jconsole" + getExecutableSuffix(), new JConsoleNotFoundException(CliStrings.START_JCONSOLE__NOT_FOUND_ERROR_MESSAGE)); }
@Test(expected = NullPointerException.class) public void testGetJdkToolPathnameWithNullPathnames() { try { getLauncherLifecycleCommands().getJdkToolPathname((Stack<String>) null, new GemFireException() { }); } catch (NullPointerException expected) { assertEquals("The JDK tool executable pathnames cannot be null!", expected.getMessage()); throw expected; } }
protected String getJConsolePathname() { return getJdkToolPathname("jconsole" + getExecutableSuffix(), new JConsoleNotFoundException(CliStrings.START_JCONSOLE__NOT_FOUND_ERROR_MESSAGE)); }
protected String getJdkToolPathname(final Stack<String> pathnames, final GemFireException throwable) { assertNotNull(pathnames, "The JDK tool executable pathnames cannot be null!"); assertNotNull(throwable, "The GemFireException cannot be null!"); try { // assume 'java.home' JVM System property refers to the JDK installation directory. note, however, that the // 'java.home' JVM System property usually refers to the JRE used to launch this application return IOUtils.verifyPathnameExists(pathnames.pop()); } catch (EmptyStackException ignore) { throw throwable; } catch (FileNotFoundException ignore) { return getJdkToolPathname(pathnames, throwable); } }
protected String getJdkToolPathname(final Stack<String> pathnames, final GemFireException throwable) { assertNotNull(pathnames, "The JDK tool executable pathnames cannot be null!"); assertNotNull(throwable, "The GemFireException cannot be null!"); try { // assume 'java.home' JVM System property refers to the JDK installation directory. note, however, that the // 'java.home' JVM System property usually refers to the JRE used to launch this application return IOUtils.verifyPathnameExists(pathnames.pop()); } catch (EmptyStackException ignore) { throw throwable; } catch (FileNotFoundException ignore) { return getJdkToolPathname(pathnames, throwable); } }
@Test public void testGetJavaPathname() { assertEquals(IOUtils.appendToPath(System.getProperty("java.home"), "bin", "java" + LauncherLifecycleCommands.getExecutableSuffix()), getLauncherLifecycleCommands().getJdkToolPathname("java" + LauncherLifecycleCommands.getExecutableSuffix(), new GemFireException() { })); }
@Test public void testGetJdkToolPathnameForNonExistingTool() { try { final GemFireException expected = new GemFireException() { @Override public String getMessage() { return "expected"; } }; getLauncherLifecycleCommands().getJdkToolPathname("nonExistingTool.exe", expected); } catch (GemFireException expected) { assertEquals("expected", expected.getMessage()); } }
protected String getJVisualVMPathname() { if (SystemUtils.isMacOSX()) { try { return IOUtils.verifyPathnameExists("/System/Library/Java/Support/VisualVM.bundle/Contents/Home/bin/jvisualvm"); } catch (FileNotFoundException e) { throw new VisualVmNotFoundException(CliStrings.START_JVISUALVM__NOT_FOUND_ERROR_MESSAGE, e); } } else { // Linux, Solaris, Windows, etc... try { return getJdkToolPathname("jvisualvm" + getExecutableSuffix(), new VisualVmNotFoundException(CliStrings.START_JVISUALVM__NOT_FOUND_ERROR_MESSAGE)); } catch (VisualVmNotFoundException e) { if (!SystemUtils.isJavaVersionAtLeast("1.6")) { throw new VisualVmNotFoundException(CliStrings.START_JVISUALVM__EXPECTED_JDK_VERSION_ERROR_MESSAGE); } throw e; } } }
protected String getJVisualVMPathname() { if (SystemUtils.isMacOSX()) { try { return IOUtils.verifyPathnameExists("/System/Library/Java/Support/VisualVM.bundle/Contents/Home/bin/jvisualvm"); } catch (FileNotFoundException e) { throw new VisualVmNotFoundException(CliStrings.START_JVISUALVM__NOT_FOUND_ERROR_MESSAGE, e); } } else { // Linux, Solaris, Windows, etc... try { return getJdkToolPathname("jvisualvm" + getExecutableSuffix(), new VisualVmNotFoundException(CliStrings.START_JVISUALVM__NOT_FOUND_ERROR_MESSAGE)); } catch (VisualVmNotFoundException e) { if (!SystemUtils.isJavaVersionAtLeast("1.6")) { throw new VisualVmNotFoundException(CliStrings.START_JVISUALVM__EXPECTED_JDK_VERSION_ERROR_MESSAGE); } throw e; } } }