1 48 package net.sf.antcontrib.platform; 49 50 import org.apache.tools.ant.BuildException; 51 import org.apache.tools.ant.Task; 52 53 79 public class OsFamily extends Task 80 { 81 private String property; 82 83 public OsFamily() 84 { 85 } 86 87 public void setProperty(String property) 88 { 89 this.property = property; 90 } 91 92 public void execute() 93 throws BuildException 94 { 95 if (property == null) 96 throw new BuildException("The attribute 'property' is required " + 97 "for the OsFamily task."); 98 99 String osName = System.getProperty("os.name").toLowerCase(); 100 String pathSep = System.getProperty("path.separator"); 101 String family = null; 102 103 if (osName.indexOf("windows") != -1) 104 { 105 family = "windows"; 106 } 107 else if (pathSep.equals(";")) 108 { 109 family = "dos"; 110 } 111 else if (osName.indexOf("mac") != -1) 112 { 113 if (osName.endsWith("x")) 114 family = "unix"; 115 else 116 family = "mac"; 117 } 118 else if (pathSep.equals(":")) 119 { 120 family = "unix"; 121 } 122 123 if (family != null) 124 getProject().setProperty(property, family); 125 } 126 } 127 | Popular Tags |