1 28 29 package org.objectweb.openccm.task; 30 31 import java.io.File ; 33 import java.util.ArrayList ; 34 import java.util.Iterator ; 35 import java.util.List ; 36 import org.apache.tools.ant.BuildException; 37 import org.apache.tools.ant.Task; 38 import org.apache.tools.ant.taskdefs.Delete; 39 40 47 public class OpenCCMTask 48 extends Task 49 { 50 56 57 protected List runnable_elements_; 58 59 60 protected IR3Start ir3_start_; 61 62 63 private boolean no_mappings_; 64 65 66 private boolean ccm_installed; 67 68 74 77 public 78 OpenCCMTask() 79 { 80 runnable_elements_ = new ArrayList (); 82 ir3_start_ = null; 83 ccm_installed = false; 84 } 85 86 92 93 98 private void 99 create_directory(String dir) 100 { 101 new File (dir).mkdir(); 102 } 103 104 107 private void 108 ccm_install(String config_dir) 109 { 110 if ( new File (config_dir).exists() ) 111 { 112 ccm_installed = true ; 113 System.out.println("An OpenCCM Platform has been found in "+config_dir+", we'll use it for code generation purpose."); 114 } 115 else 116 { 117 System.out.println("An OpenCCM Platform will be temporary installed in "+config_dir+" for code generation purpose."); 118 119 System.out.println("Creating the " + config_dir + " directory."); 120 create_directory(config_dir); 121 122 System.out.println("OpenCCM Platform is installed."); 123 } 124 } 125 126 129 private void 130 ccm_deinstall(String config_dir) 131 { 132 if ( !ccm_installed ) 134 { 135 Delete delete_task = new Delete(); 136 137 delete_task.setProject( getProject() ); 138 delete_task.setTaskName("ccm_deinstall"); 139 delete_task.setDir(new File (config_dir)); 140 delete_task.execute(); 141 } 142 } 143 144 147 private void 148 ir3_start(String config_dir) 149 { 150 if ( new File ( 151 getProject().getProperty("OpenCCM_CONFIG_DIR") 152 +System.getProperty("file.separator") 153 +"IR3.IOR") 154 .exists() ) 155 { 156 System.out.println("An Interface Repository has been found, we'll use it for code generation purpose."); 157 } 158 else 159 { 160 System.out.println("An Interface Repository will be temporary started for code generation purpose."); 161 162 ir3_start_ = new IR3Start( getProject().getProperties() ); 164 ir3_start_.setNo_mappings(no_mappings_); 165 ir3_start_.run(true); 166 167 System.out.println("Interface Repository is started."); 168 } 169 } 170 171 174 private void 175 ir3_stop() 176 { 177 if( ir3_start_ != null ) 179 { 180 ir3_start_.stop(); 182 } 183 } 184 185 190 private void 191 run_elements() 192 throws BuildException 193 { 194 for (Iterator it = runnable_elements_.iterator(); it.hasNext();) 195 { 196 ((Runnable ) it.next()).run(); 197 } 198 } 199 200 205 private void 206 run_openccm_build() 207 throws BuildException 208 { 209 IR3Feed ir3_feed = null; 210 String idl_dir = null; 211 212 ir3_start( getProject().getProperty("OpenCCM_CONFIG_DIR") ); 213 214 idl_dir = getProject().getProperty("OpenCCM_idl_dir"); 216 217 run_elements(); 219 220 } 221 222 228 233 public void 234 setNo_mappings(boolean b) 235 { 236 this.no_mappings_ = b; 237 } 238 239 244 public void 245 execute() 246 throws BuildException 247 { 248 ccm_install( getProject().getProperty("OpenCCM_CONFIG_DIR") ); 250 251 try 252 { 253 run_openccm_build(); 254 }catch (BuildException e){ 255 ir3_stop(); 257 ccm_deinstall( getProject().getProperty("OpenCCM_CONFIG_DIR") ); 258 throw new BuildException("OpenCCM build failed!"); 259 } 260 261 ir3_stop(); 263 264 ccm_deinstall( getProject().getProperty("OpenCCM_CONFIG_DIR") ); 266 } 267 268 271 public IR3Feed 272 createIr3_feed() 273 { 274 IR3Feed ir3_feed = null; 275 276 ir3_feed = new IR3Feed( getProject().getProperties() ); 277 runnable_elements_.add(ir3_feed); 279 280 return ir3_feed; 281 } 282 283 286 public IR3toIDL3 287 createIr3_idl3() 288 { 289 IR3toIDL3 ir3_idl3 = null; 290 291 ir3_idl3 = new IR3toIDL3( getProject().getProperties() ); 292 runnable_elements_.add(ir3_idl3); 294 295 return ir3_idl3; 296 } 297 298 301 public IR3toIDL2 302 createIr3_idl2() 303 { 304 IR3toIDL2 ir3_idl2 = null; 305 306 ir3_idl2 = new IR3toIDL2( getProject().getProperties() ); 307 runnable_elements_.add(ir3_idl2); 309 310 return ir3_idl2; 311 } 312 313 316 public PSDLtoPSDL 317 createPsdl() 318 { 319 PSDLtoPSDL psdl_psdl = null; 320 321 psdl_psdl = new PSDLtoPSDL( getProject().getProperties() ); 322 runnable_elements_.add(psdl_psdl); 324 325 return psdl_psdl; 326 } 327 328 331 public CIDLtoCIDL 332 createCidl() 333 { 334 CIDLtoCIDL cidl_cidl = null; 335 336 cidl_cidl = new CIDLtoCIDL( getProject().getProperties() ); 337 runnable_elements_.add(cidl_cidl); 339 340 return cidl_cidl; 341 } 342 343 346 public PsdlToJava 347 createPsdl_java() 348 { 349 PsdlToJava psdl_java = null; 350 351 psdl_java = new PsdlToJava( getProject().getProperties() ); 352 runnable_elements_.add(psdl_java); 354 355 return psdl_java; 356 } 357 358 361 public IR3toJava 362 createIr3_java() 363 { 364 IR3toJava ir3_java = null; 365 366 ir3_java = new IR3toJava( getProject().getProperties() ); 367 runnable_elements_.add(ir3_java); 369 370 return ir3_java; 371 } 372 373 376 public CIDLtoCIF 377 createCidl_cif() 378 { 379 CIDLtoCIF cidl_cif = null; 380 381 cidl_cif = new CIDLtoCIF( getProject().getProperties() ); 382 runnable_elements_.add(cidl_cif); 384 385 return cidl_cif; 386 } 387 } 388 | Popular Tags |