1 package org.enhydra.kelp.ant.node; 2 3 4 import org.enhydra.kelp.ant.AntFacade; 6 import org.enhydra.kelp.ant.node.AntNodeReader; 7 import org.enhydra.kelp.common.node.OtterNode; 9 import org.enhydra.kelp.common.node.OtterFolderNode; 10 import org.enhydra.kelp.common.node.OtterDocumentNode; 11 import org.enhydra.kelp.common.node.OtterProject; 12 import org.enhydra.kelp.common.node.OtterFileNode; 13 import org.enhydra.kelp.common.node.OtterTextFileNode; 14 import org.enhydra.kelp.common.node.OtterNodeFactory; 15 import org.enhydra.tool.common.PathHandle; 17 import org.enhydra.tool.ToolBoxInfo; 18 import java.io.File ; 20 import java.util.ArrayList ; 21 import java.io.FileReader ; 22 import java.io.BufferedReader ; 23 import java.io.IOException ; 24 import java.io.FileWriter ; 25 import java.io.BufferedWriter ; 26 import java.io.PrintWriter ; 27 import java.util.HashMap ; 28 29 42 43 public class AntProject extends OtterProject { 44 45 public final static String PROJECT_NAME = "project.name"; 47 public final static String RESOURCES_DIR = "resources.dir"; 48 public final static String SRC_DIR = "src.dir"; 49 public final static String CLASSES_DIR = "classes.dir"; 50 public final static String CLASS_PATH = "class.path"; 51 public final static String ENHYDRA_DIR = "enhydra.dir"; 52 public final static String OUTPUT_FILE_NAME = "output.file.name"; public final static String XMLC_INVOKE = "xmlc.invoke"; 55 public final static String XMLC_VERBOSE = "xmlc.verbose"; 56 public final static String XMLC_PACKAGE_NAME = "xmlc.package.name"; 57 public final static String XMLC_LOG_ENABLED = "xmlc.log.enabled"; 58 public final static String XMLC_DEFAULT_PACKAGE = "xmlc.default.package"; public final static String XMLC_GENERETED_SRC_DIR ="xmlc.src.dir"; 60 public final static String XMLC_OPTIONS_FILE = "xmlc.options.file"; 61 public final static String XMLC_INCLUDES = "xmlc.includes"; 62 public final static String XMLC_RESOURCES_ALL = "xmlc.resources.all"; 63 public final static String XMLC_RESOURCES_SELECTED = "xmlc.resources.selected"; 64 public final static String XMLC_RESOURCE_EXTENSIONS = "xmlc.resources.all"; 65 public final static String DEPLOY_INVOKE = "deploy.invoke"; 67 public final static String DEPLOY_CONTENT_ENABLED = "deploy.content.enabled"; 68 public final static String DEPLOY_INPUT_ENABLED = "deploy.input.enabled"; 69 public final static String DEPLOY_WAR_ENABLED = "deploy.war.enabled"; 70 public final static String DEPLOY_WAR_ENHYDRA_LIBS = "deploy.war.enhydra.libs"; 71 private final static String DEPLOY_WAR_ENHYDRA_LIBS_TRUE = "enhydra.libs.true"; 72 private final static String DEPLOY_WAR_ENHYDRA_LIBS_FALSE = "enhydra.libs.false"; 73 public final static String INPUT_DIR = "input.dir"; 74 public final static String OUTPUT_DIR = "output.dir"; 75 public final static String CONTENT_DIR = "content.dir"; 76 public final static String CONTENT_PACKAGE_DIR = "content.package.dir"; 77 public final static String CONTENT_TYPE_EXTENSIONS = "content.types.selected"; 78 public final static String DODS_GENERATED_SRC_DIR = "dods.src.dir"; 80 public final static String DODS_DOML = "dods.doml"; 81 public final static String DODS_ACTION = "dods.action"; 82 public final static String DODS_TEMPLATE_SET = "dods.template.set"; 83 public final static String DODS_INVOKE = "dods.invoke"; 84 85 86 private String workingDir = null; 87 private String enhydraDir = ToolBoxInfo.getEnhydraRoot(); 88 private String rootPath; 89 private AntNodeFactory factory = new AntNodeFactory(); 90 private AntFacade antFacade = null; 91 private boolean webType; 92 private AntNodeReader nodeReader = null; 93 private String outputFileName = null; 94 private boolean outputFileEnabled = false; 95 private String defaultPackage = ""; 96 97 public AntProject(String rootPath) throws Exception { 98 workingDir = rootPath; 99 antFacade = new AntFacade(this); 100 webType = true; 101 nodeReader = new AntNodeReader(this); 102 defaultPackage = new String (this.getProperty(PROJECT_NAME)+".presentation"); 103 if (antFacade.getPropertyLocation(CONTENT_DIR) == null) { 104 webType = false; 105 } 106 } 107 108 public OtterFileNode[] getAllInput() { 109 return nodeReader.getTextFileNodes(this.getProperty(AntProject.INPUT_DIR)); 110 } 111 public void configureRunClass() { 112 113 } 114 public OtterFileNode[] findFileNodesByType(String [] parm1) { 115 return new OtterFileNode[0]; 116 117 } 118 public void save() { 119 antFacade.save(); 120 } 121 public OtterDocumentNode[] getAllDocuments() { 122 return nodeReader.getDocumentNodes(this.getProperty(AntProject.RESOURCES_DIR)); 123 } 124 128 public void setAllDocuments(OtterDocumentNode[] docNodes){ 129 130 ArrayList selectedList = new ArrayList (); 131 for(int i=0;i<docNodes.length;i++){ 132 if(docNodes[i].isSelected()) 133 selectedList.add(docNodes[i]); 134 } 135 Object [] objs = selectedList.toArray(); 136 OtterDocumentNode[] selectedDocNodes = new OtterDocumentNode[objs.length]; 137 for(int i=0;i<objs.length;i++){ 138 selectedDocNodes[i] = (OtterDocumentNode)objs[i]; 139 } 140 141 if(selectedDocNodes.length == docNodes.length){ this.setProperty(this.XMLC_INCLUDES,this.XMLC_RESOURCES_ALL); antFacade.replacePatternset(this.XMLC_RESOURCES_SELECTED, new String [0]); }else{ 145 String resourceDir = relativeToAbsolute(getProperty(this.RESOURCES_DIR)); 146 this.setProperty(this.XMLC_INCLUDES,this.XMLC_RESOURCES_SELECTED); String [] selectedPaths = new String [selectedDocNodes.length]; 148 for(int i=0;i<selectedDocNodes.length;i++){ 149 selectedPaths[i] = selectedDocNodes[i].getFilePath(); 150 selectedPaths[i] = absoluteToRelative(resourceDir, selectedPaths[i]); } 152 antFacade.replacePatternset(this.XMLC_RESOURCES_SELECTED, selectedPaths); 153 } 154 } 155 159 public OtterDocumentNode[] getSelectedDocuments() { 160 String [] docPaths = antFacade.getPatternset(this.XMLC_RESOURCES_SELECTED); 161 OtterDocumentNode[] docNodes = null; 162 if(docPaths!=null){ 163 docNodes = new OtterDocumentNode[docPaths.length]; 164 for(int i=0; i<docPaths.length; i++){ 165 docNodes[i] = factory.createDocumentNode(this, resourceRelativeToAbsolute(docPaths[i])); 166 } 167 }else{ 168 docNodes = new OtterDocumentNode[0]; 169 } 170 return docNodes; 171 } 172 public String getRootPath() { 173 return getWorkingPath(); } 175 176 public Object getNativeNode() { 177 return null; 178 179 } 180 public String getProperty(String property) { 181 String s = null; 182 if (property.equalsIgnoreCase(NAME_WORKING_DIR)){ 183 s = workingDir; 184 } else if(property.equalsIgnoreCase(ENHYDRA_DIR)){ 185 s = enhydraDir; 186 } else if(property.equalsIgnoreCase(RESOURCES_DIR)){ 187 s = relativeToAbsolute(antFacade.getPropertyValue(RESOURCES_DIR)); 188 } else if(property.equalsIgnoreCase(DODS_DOML)){ 189 s = relativeToAbsolute(antFacade.getPropertyLocation(DODS_DOML)); 190 } else if (property.equalsIgnoreCase(AntProject.XMLC_INVOKE)) { 191 boolean checkInvoke = antFacade.checkDependedTarget("make","xmlc"); 192 if(checkInvoke) 193 s = "true"; 194 else 195 s = "false"; 196 } else if (property.equalsIgnoreCase(AntProject.DODS_INVOKE)) { 197 boolean checkInvoke = antFacade.checkDependedTarget("make","dods"); 198 if(checkInvoke) 199 s = "true"; 200 else 201 s = "false"; 202 } else if (property.equalsIgnoreCase(AntProject.DODS_TEMPLATE_SET)) { 203 s = antFacade.getPropertyValue(property); 204 } else if (property.equalsIgnoreCase(AntProject.DODS_ACTION)) { 205 s = antFacade.getPropertyValue(property); 206 } else if (property.equalsIgnoreCase(AntProject.DEPLOY_CONTENT_ENABLED)) { 207 boolean checkInvoke = antFacade.checkDependedTarget("deploy","content"); 208 if(checkInvoke) 209 s = "true"; 210 else 211 s = "false"; 212 } else if (property.equalsIgnoreCase(AntProject.DEPLOY_INPUT_ENABLED)) { 213 boolean checkInvoke = antFacade.checkDependedTarget("deploy","input"); 214 if(checkInvoke) 215 s = "true"; 216 else 217 s = "false"; 218 } else if (property.equalsIgnoreCase(AntProject.DEPLOY_WAR_ENABLED)) { 219 boolean checkInvoke = antFacade.checkDependedTarget("deploy","makeWAR"); 220 if(checkInvoke) 221 s = "true"; 222 else 223 s = "false"; 224 } else if (property.equalsIgnoreCase(AntProject.DEPLOY_INVOKE)) { 225 boolean checkInvoke = antFacade.checkDependedTarget("make","deploy"); 226 if(checkInvoke) 227 s = "true"; 228 else 229 s = "false"; 230 } else if (property.equalsIgnoreCase(AntProject.DEPLOY_WAR_ENHYDRA_LIBS)) { 231 String value = antFacade.getPropertyValue(property); 232 if(value.equalsIgnoreCase(this.DEPLOY_WAR_ENHYDRA_LIBS_TRUE)) 233 s = "true"; 234 else 235 s = "false"; 236 } else if (property.equalsIgnoreCase(AntProject.OUTPUT_FILE_NAME)) { 237 s = outputFileName; 238 } else if (property.equalsIgnoreCase(AntProject.XMLC_DEFAULT_PACKAGE)) { 239 s = defaultPackage; 240 } else if (s == null) { 241 if ((s = antFacade.getPropertyValue(property)) == null) 242 s = relativeToAbsolute(antFacade.getPropertyLocation(property)); 243 } 244 return s; 245 246 } 247 248 public void setProperty(String property, String value) { 249 if(property.equalsIgnoreCase(DEPLOY_INVOKE)){ 250 if (value.equalsIgnoreCase("true")) { 251 antFacade.addDependedTarget("make", "deploy"); 252 } 253 else { 254 antFacade.removeDependedTarget("make", "deploy"); 255 } 256 } else if(property.equalsIgnoreCase(OUTPUT_DIR)) { 257 String relativePath = absoluteToRelative(this.getWorkingPath(),value); 258 antFacade.setPropertyLocation(property, relativePath); 259 } else if(property.equalsIgnoreCase(DODS_DOML)) { 260 String relativePath = absoluteToRelative(this.getWorkingPath(),value); 261 antFacade.setPropertyLocation(property, relativePath); 262 } else if(property.equalsIgnoreCase(DODS_ACTION)) { 263 antFacade.setPropertyValue(property, value); 264 } else if(property.equalsIgnoreCase(DODS_TEMPLATE_SET)) { 265 antFacade.setPropertyValue(property, value); 266 } else if(property.equalsIgnoreCase(INPUT_DIR)) { 267 String relativePath = absoluteToRelative(this.getWorkingPath(),value); 268 antFacade.setPropertyLocation(property, relativePath); 269 } else if(property.equalsIgnoreCase(DEPLOY_INPUT_ENABLED)){ 270 if (value.equalsIgnoreCase("true")) { 271 antFacade.addDependedTarget("deploy", "input"); 272 } 273 else { 274 antFacade.removeDependedTarget("deploy", "input"); 275 } 276 } else if(property.equalsIgnoreCase(DEPLOY_CONTENT_ENABLED)){ 277 if (value.equalsIgnoreCase("true")) { 278 antFacade.addDependedTarget("deploy", "content"); 279 } 280 else { 281 antFacade.removeDependedTarget("deploy", "content"); 282 } 283 } else if(property.equalsIgnoreCase(DEPLOY_WAR_ENABLED)){ 284 if (value.equalsIgnoreCase("true")) { 285 antFacade.addDependedTarget("deploy", "makeWAR"); 286 } 287 else { 288 antFacade.removeDependedTarget("deploy", "makeWAR"); 289 } 290 } else if(property.equalsIgnoreCase(DEPLOY_WAR_ENHYDRA_LIBS)){ 291 if (value.equalsIgnoreCase("true")) 292 antFacade.setPropertyValue(property,DEPLOY_WAR_ENHYDRA_LIBS_TRUE); 293 else 294 antFacade.setPropertyValue(property,DEPLOY_WAR_ENHYDRA_LIBS_FALSE); 295 296 } else if(property.equalsIgnoreCase(XMLC_OPTIONS_FILE)){ 297 antFacade.setPropertyValue(property, value); 298 } else if(property.equalsIgnoreCase(XMLC_INVOKE)){ 299 if (value.equalsIgnoreCase("true")) { 300 antFacade.addDependedTarget("make", "xmlc"); 301 } 302 else { 303 antFacade.removeDependedTarget("make", "xmlc"); 304 } 305 }else if(property.equalsIgnoreCase(DODS_INVOKE)){ 306 if (value.equalsIgnoreCase("true")) { 307 antFacade.addDependedTarget("make", "dods"); 308 } 309 else { 310 antFacade.removeDependedTarget("make", "dods"); 311 } 312 } else if(property.equalsIgnoreCase(XMLC_VERBOSE)) { 313 antFacade.setPropertyValue(property, value); 314 } else if(property.equalsIgnoreCase(XMLC_PACKAGE_NAME)) { 315 antFacade.setPropertyValue(property, value); 316 } else if(property.equalsIgnoreCase(OUTPUT_FILE_NAME)) { 317 outputFileName = value; 318 }else if(property.equalsIgnoreCase(this.XMLC_INCLUDES)) { 319 antFacade.setPropertyValue(property,value); 320 } 321 } 323 324 public void setProperty(String property, int value) { 325 setProperty(property,Integer.toString(value)); 326 } 327 328 public void setNativeNode(Object parm1) { 329 ; } 331 public String [] getSourcePathArray() { 332 return null; 334 } 335 336 public String getSourcePath() { 337 return getProperty(AntProject.SRC_DIR); 338 } 339 public boolean isOpenBuild() { 340 return true; 341 342 } 343 public String getClassPath() { 344 return getProperty(AntProject.CLASS_PATH); } 347 public boolean isDefaultProject() { 348 return false; 349 } 350 public OtterTextFileNode[] getAllDeploymentDescs() { 351 return new OtterTextFileNode[0]; 353 } 354 public Object getNativeProject() { 355 return null; } 357 public OtterNodeFactory getNodeFactory() { 358 return factory; 359 360 } 361 public OtterNode getParent() { 362 return null; 363 } 364 365 public String getWorkingPath() { 366 return getProperty(NAME_WORKING_DIR); } 368 369 public void setWorkingPath(String path) { 370 setProperty(NAME_WORKING_DIR,path); 371 } 372 public OtterProject getProject() { 373 return this; 374 } 375 public String getClassOutputPath() { 376 return getProperty(AntProject.CLASSES_DIR); 377 } 378 public void setClassOutputPath(String p) { 379 setProperty(AntProject.CLASSES_DIR,p); 380 } 381 public String getCodeGenDefaultDestination() { 382 return rootPath+"/xmlc_generated_source"; 384 } 385 public void setSourcePathArray(String [] parm1) { 386 387 } 388 389 public OtterTextFileNode getFirstPolicy() { 390 return null; 391 392 } 393 394 398 private String relativePathAdapter(String path) { 399 String newPath = null; 400 File file = new File (path); 401 if (!file.isAbsolute()) 402 newPath = "./" + path; 403 else 404 newPath = path; 405 return newPath; 406 } 407 412 private String relativeToAbsolute(String relativePath){ 413 if(relativePath!=null){ 414 PathHandle workDirHandle = PathHandle.createPathHandle(workingDir); 415 PathHandle absoluteHandle = workDirHandle.expandRelativePath(relativePathAdapter(relativePath)); 416 return absoluteHandle.getPath(); 417 }else 418 return null; 419 } 420 421 private String resourceRelativeToAbsolute(String relativePath){ 422 if(relativePath!=null){ 423 String resourceDir = relativeToAbsolute(getProperty(this.RESOURCES_DIR)); 424 PathHandle resourseHandle = PathHandle.createPathHandle(resourceDir); 425 PathHandle absoluteHandle = resourseHandle.expandRelativePath(relativePathAdapter(relativePath)); 426 return absoluteHandle.getPath(); 427 }else 428 return null; 429 } 430 431 private String absoluteToRelative(String homePath,String inPath){ 432 PathHandle homePathHandle = PathHandle.createPathHandle(homePath); 433 PathHandle inPathHandle = PathHandle.createPathHandle(inPath); 434 String relativePath = homePathHandle.getRelativePath(inPathHandle); 435 if(relativePath.startsWith("./")) 437 relativePath = relativePath.substring(2); 438 return relativePath; 439 } 440 444 public String [] getXMLCOptionsFileParams() { 445 String optFilePath = getProperty(AntProject.XMLC_OPTIONS_FILE); 446 optFilePath = relativePathAdapter(optFilePath); 447 PathHandle resourcesHandle = 448 PathHandle.createPathHandle(getProperty(AntProject.RESOURCES_DIR)); 449 PathHandle optFileHandle = resourcesHandle.expandRelativePath(optFilePath); 450 FileReader optFileReader = null; 451 BufferedReader br = null; 452 ArrayList optionsList = new ArrayList (); 453 try { 454 optFileReader = new FileReader (optFileHandle.getFile()); 455 br = new BufferedReader (optFileReader, 4096); 456 String optLine = br.readLine(); 457 while(optLine != null) { 458 if (!optLine.equals("")) 459 optionsList.add(optLine); 460 optLine = br.readLine(); 461 } 462 br.close(); 463 } 464 catch (IOException ex) { 465 ex.printStackTrace(); 466 } 467 Object [] objs = optionsList.toArray(); 468 String [] options = new String [objs.length]; 469 for (int i = 0; i < objs.length; i++) { 470 options[i] = (String )objs[i]; 471 } 472 473 return options; 474 } 475 476 480 public void setXMLCOptionsFileParams(String [] options) { 481 String optFilePath = getProperty(AntProject.XMLC_OPTIONS_FILE); 482 optFilePath = relativePathAdapter(optFilePath); 483 PathHandle resourcesHandle = 484 PathHandle.createPathHandle(getProperty(AntProject.RESOURCES_DIR)); 485 PathHandle optFileHandle = resourcesHandle.expandRelativePath(optFilePath); 486 FileWriter fw; 487 try { 488 fw = new FileWriter (optFileHandle.getFile()); 489 } catch(IOException e) {return;} 490 BufferedWriter bw = new BufferedWriter (fw, 4096); 491 PrintWriter prw = new PrintWriter (bw, false ); 492 for (int i = 0; i < options.length; i++) { 493 prw.println(options[i]); 494 } 495 prw.println(); 496 prw.flush(); 497 prw.close(); 498 } 499 500 504 public boolean isWebType() { 505 return webType; 506 } 507 508 public String [] getExtensions(String patternsetId) { 509 String [] extensions = antFacade.getPatternset(patternsetId); 510 for (int i = 0; i < extensions.length; i++) { 511 extensions[i] = extensions[i].substring(extensions[i].indexOf("**/*.")+5); 512 extensions[i] = extensions[i].trim(); 513 } 514 return extensions; 515 } 516 517 public void setExtensions(String patternsetId, String [] extensions) { 518 String [] expandedExts = new String [extensions.length]; 519 for (int i = 0; i < extensions.length; i++) { 520 expandedExts[i] = "**/*." + extensions[i]; 521 } 522 antFacade.replacePatternset(patternsetId, expandedExts); 523 } 524 525 526 public HashMap getReplacements() { 527 return antFacade.getInputFilters(); 528 } 529 530 public void setReplacements(HashMap replacements) { 531 antFacade.replaceInputFilters(replacements); 532 } 533 534 public boolean isOutputFileEnabled() { 535 return outputFileEnabled; 536 } 537 538 public void setOutputFileEnabled(boolean enable) { 539 outputFileEnabled = enable; 540 } 541 542 548 public String getOutputFilename() { 549 String out = null; 550 551 out = getProperty(OUTPUT_FILE_NAME); 552 return out; 553 } 554 555 561 public void setOutputFilename(String n) { 562 setProperty(OUTPUT_FILE_NAME, n); 563 } 564 } 565 566 | Popular Tags |