1 17 package org.apache.tools.ant.util; 18 19 import java.io.File ; 20 21 import junit.framework.AssertionFailedError; 22 import junit.framework.TestCase; 23 24 import org.apache.tools.ant.taskdefs.condition.Os; 25 26 30 public class JavaEnvUtilsTest extends TestCase { 31 public JavaEnvUtilsTest(String s) { 32 super(s); 33 } 34 35 public void testGetExecutableNetware() { 36 if (Os.isName("netware")) { 37 assertEquals("java", JavaEnvUtils.getJreExecutable("java")); 38 assertEquals("javac", JavaEnvUtils.getJdkExecutable("javac")); 39 assertEquals("foo", JavaEnvUtils.getJreExecutable("foo")); 40 assertEquals("foo", JavaEnvUtils.getJdkExecutable("foo")); 41 } 42 } 43 44 public void testGetExecutableWindows() { 45 if (Os.isFamily("windows")) { 46 FileUtils fileUtils = FileUtils.newFileUtils(); 47 String javaHome = 48 fileUtils.normalize(System.getProperty("java.home")) 49 .getAbsolutePath(); 50 51 String j = JavaEnvUtils.getJreExecutable("java"); 52 assertTrue(j.endsWith(".exe")); 53 assertTrue(j+" is absolute", (new File (j)).isAbsolute()); 54 try { 55 assertTrue(j+" is normalized and in the JRE dir", 56 j.startsWith(javaHome)); 57 } catch (AssertionFailedError e) { 58 assertEquals("java.exe", j); 60 } 61 62 j = JavaEnvUtils.getJdkExecutable("javac"); 63 assertTrue(j.endsWith(".exe")); 64 try { 65 assertTrue(j+" is absolute", (new File (j)).isAbsolute()); 66 String javaHomeParent = 67 fileUtils.normalize(javaHome+"/..").getAbsolutePath(); 68 assertTrue(j+" is normalized and in the JDK dir", 69 j.startsWith(javaHomeParent)); 70 71 if (JavaEnvUtils.getJavaVersion() == JavaEnvUtils.JAVA_1_0 || 72 JavaEnvUtils.getJavaVersion() == JavaEnvUtils.JAVA_1_1) { 73 assertTrue(j+" is normalized and in the JRE dir", 74 j.startsWith(javaHome)); 75 } else { 76 assertTrue(j+" is normalized and not in the JRE dir", 77 !j.startsWith(javaHome)); 78 } 79 80 } catch (AssertionFailedError e) { 81 assertEquals("javac.exe", j); 83 } 84 85 assertEquals("foo.exe", JavaEnvUtils.getJreExecutable("foo")); 86 assertEquals("foo.exe", JavaEnvUtils.getJdkExecutable("foo")); 87 } 88 } 89 90 public void testGetExecutableMostPlatforms() { 91 if (!Os.isName("netware") && !Os.isFamily("windows")) { 92 FileUtils fileUtils = FileUtils.newFileUtils(); 93 String javaHome = 94 fileUtils.normalize(System.getProperty("java.home")) 95 .getAbsolutePath(); 96 97 String extension = Os.isFamily("dos") ? ".exe" : ""; 99 100 String j = JavaEnvUtils.getJreExecutable("java"); 101 if (!extension.equals("")) { 102 assertTrue(j.endsWith(extension)); 103 } 104 assertTrue(j+" is absolute", (new File (j)).isAbsolute()); 105 assertTrue(j+" is normalized and in the JRE dir", 106 j.startsWith(javaHome)); 107 108 j = JavaEnvUtils.getJdkExecutable("javac"); 109 if (!extension.equals("")) { 110 assertTrue(j.endsWith(extension)); 111 } 112 assertTrue(j+" is absolute", (new File (j)).isAbsolute()); 113 114 String javaHomeParent = 115 fileUtils.normalize(javaHome+"/..").getAbsolutePath(); 116 assertTrue(j+" is normalized and in the JDK dir", 117 j.startsWith(javaHomeParent)); 118 119 if (JavaEnvUtils.getJavaVersion() == JavaEnvUtils.JAVA_1_0 || 120 JavaEnvUtils.getJavaVersion() == JavaEnvUtils.JAVA_1_1 || 121 Os.isFamily("mac")) { 122 assertTrue(j+" is normalized and in the JRE dir", 123 j.startsWith(javaHome)); 124 } else { 125 assertTrue(j+" is normalized and not in the JRE dir", 126 !j.startsWith(javaHome)); 127 } 128 129 assertEquals("foo"+extension, 130 JavaEnvUtils.getJreExecutable("foo")); 131 assertEquals("foo"+extension, 132 JavaEnvUtils.getJdkExecutable("foo")); 133 } 134 135 } 136 137 } 138 | Popular Tags |