1 28 29 30 package org.objectweb.ecm.taskdefs; 31 32 35 public class OSHelper 36 { 37 static private String _ospath; 39 static private boolean _isunix; 40 static private boolean _iswindows; 41 static private String _osfamily; 42 43 static { 45 _ospath = null; 46 _isunix = org.apache.tools.ant.taskdefs.condition.Os.isFamily("unix"); 47 _iswindows = org.apache.tools.ant.taskdefs.condition.Os.isFamily("windows"); 48 49 if (_isunix) { 50 _osfamily = "unix"; 51 } 52 else if (_iswindows) { 53 _osfamily = "windows"; 54 } 55 } 56 57 61 static public boolean 62 isUnix() 63 { 64 return _isunix; 65 } 66 67 static public boolean 68 isWindows() 69 { 70 return _iswindows; 71 } 72 73 static public String 74 osFamily() 75 { 76 return _osfamily; 77 } 78 79 static public String 80 osPath() 81 { 82 if (_ospath==null) { 83 java.util.Vector procenv = org.apache.tools.ant.taskdefs.Execute.getProcEnvironment(); 84 String vname = null; 85 if (isUnix()) { 86 vname = "PATH"; 87 } 88 else if (isWindows()) { 89 vname = "Path"; 90 } 91 92 String [] vars = (String [])procenv.toArray(new String [0]); 93 for (int i=0;i<vars.length;i++) { 94 if (vars[i].startsWith(vname)) { 95 int idx = vars[i].indexOf('='); 96 _ospath = vars[i].substring(idx+1); 97 break; 98 } 99 } 100 101 } 102 103 105 return _ospath; 106 } 107 108 static public String 109 envVar(String vname) 110 { 111 java.util.Vector procenv = org.apache.tools.ant.taskdefs.Execute.getProcEnvironment(); 112 String [] vars = (String [])procenv.toArray(new String [0]); 113 for (int i=0;i<vars.length;i++) { 114 if (vars[i].startsWith(vname)) { 115 int idx = vars[i].indexOf('='); 116 return vars[i].substring(idx+1); 117 } 118 } 119 120 return null; 121 } 122 123 static public void 124 pathConvert(org.apache.tools.ant.Project project, 125 String prop, String spath) 126 { 127 org.apache.tools.ant.taskdefs.PathConvert pconvert = null; 128 org.apache.tools.ant.types.Path path = null; 129 pconvert = (org.apache.tools.ant.taskdefs.PathConvert)project.createTask("pathconvert"); 130 pconvert.setTargetos(osFamily()); 131 pconvert.setProperty(prop); 132 path = pconvert.createPath(); 133 134 String rpath = project.getProperty(spath); 136 if (rpath!=null) { 137 path.setPath(rpath); 138 } 139 else { 141 path.setPath(spath); 142 } 143 144 pconvert.execute(); 145 } 146 } 147 | Popular Tags |