1 28 29 30 package org.objectweb.ecm.taskdefs; 31 32 74 public class IR3FeedTask 75 extends org.apache.tools.ant.Task 76 { 77 private java.io.File _idl3file; 79 private java.io.File _generateto; 80 private java.io.File _cfgdir; 81 82 public 84 IR3FeedTask() 85 { 86 _idl3file = null; 88 _generateto = null; 89 _cfgdir = null; 90 } 91 92 96 private void 98 validate() 99 throws org.apache.tools.ant.BuildException 100 { 101 String msg = ""; 102 103 if (!OSHelper.isUnix() && !OSHelper.isWindows()) { 105 msg = "target os must be of unix or windows family"; 106 throw new org.apache.tools.ant.BuildException(msg); 107 } 108 109 if (_idl3file==null) { 111 msg = "idl3file attribute is missing"; 112 throw new org.apache.tools.ant.BuildException(msg); 113 } 114 115 if ((_generateto!=null) && ((!_generateto.exists()) || (!_generateto.isDirectory()))) { 117 msg = "Generation directory does not exist or is not a directory"; 118 throw new org.apache.tools.ant.BuildException(msg); 119 } 120 121 if (_cfgdir==null) { 123 msg = "cfgdir attribute is missing"; 124 throw new org.apache.tools.ant.BuildException(msg); 125 } 126 if ((!_cfgdir.exists()) || (!_cfgdir.isDirectory())) { 127 msg = "Configuration directory does not exist or is not a directory"; 128 throw new org.apache.tools.ant.BuildException(msg); 129 } 130 131 String bindir = getProject().getProperty("OpenCCM.install.bin.dir"); 133 if (bindir==null) { 134 msg = "OpenCCM.install.bin.dir property must be set"; 135 throw new org.apache.tools.ant.BuildException(msg); 136 } 137 } 138 139 private boolean 140 idl3fileUpToDate(java.io.File idl3file, 141 java.io.File gendir) 142 { 143 if (gendir==null) { 145 return false; 146 } 147 148 String fname = idl3file.getName(); 150 int idx = fname.lastIndexOf('.'); 151 fname = fname.substring(0, idx); 152 fname = fname+".idl"; 153 java.io.File idl2file = new java.io.File (gendir, fname); 154 155 if (idl2file.exists() && (idl2file.lastModified()>idl3file.lastModified())) { 156 return true; 157 } 158 159 return false; 160 } 161 162 private void 163 ir3feed(java.io.File cfgdir, 164 java.io.File idl3file) 165 throws org.apache.tools.ant.BuildException 166 { 167 org.apache.tools.ant.taskdefs.ExecTask cmd = null; 169 cmd = (org.apache.tools.ant.taskdefs.ExecTask)getProject().createTask("exec"); 170 171 String cmdname = null; 173 OSHelper.pathConvert(getProject(), "os.OpenCCM.install.bin.dir", "OpenCCM.install.bin.dir"); 175 String bindir = getProject().getProperty("os.OpenCCM.install.bin.dir"); 176 if (OSHelper.isUnix()) { 177 cmdname = bindir+"/ir3_feed"; 178 } 179 else if (OSHelper.isWindows()) { 180 cmdname = bindir+"\\ir3_feed.bat"; 181 } 182 183 cmd.setExecutable(cmdname); 184 185 org.apache.tools.ant.types.Environment.Variable openccm_homedir = null; 187 org.apache.tools.ant.types.Environment.Variable openccm_cfgdir = null; 188 189 OSHelper.pathConvert(getProject(), "os.OpenCCM.install.dir", "OpenCCM.install.dir"); 191 String homedir = getProject().getProperty("os.OpenCCM.install.dir"); 192 openccm_homedir = new org.apache.tools.ant.types.Environment.Variable(); 193 openccm_homedir.setKey("OpenCCM_HOMEDIR"); 194 openccm_homedir.setValue(homedir); 195 cmd.addEnv(openccm_homedir); 196 197 openccm_cfgdir = new org.apache.tools.ant.types.Environment.Variable(); 198 openccm_cfgdir.setKey("OpenCCM_CONFIG_DIR"); 199 openccm_cfgdir.setValue(cfgdir.getPath()); 200 cmd.addEnv(openccm_cfgdir); 201 202 org.apache.tools.ant.types.Commandline.Argument arg = cmd.createArg(); 204 arg.setValue(idl3file.getPath()); 205 206 cmd.execute(); 208 } 209 210 214 final public void 215 setIdl3file(java.io.File file) 216 { 217 _idl3file = file; 218 } 219 220 final public void 221 setGenerateto(java.io.File dir) 222 { 223 _generateto = dir; 224 } 225 226 final public void 227 setCfgdir(java.io.File cfgdir) 228 { 229 _cfgdir = cfgdir; 230 } 231 232 236 final public void 237 execute() 238 throws org.apache.tools.ant.BuildException 239 { 240 validate(); 241 242 if (!idl3fileUpToDate(_idl3file, _generateto)) { 244 log("[execute] OMG IDL3 file is not uptodate"); 245 ir3feed(_cfgdir, _idl3file); 246 } 247 } 248 } 249 | Popular Tags |