1 19 20 package org.netbeans.modules.j2ee.archive.project; 21 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyChangeSupport ; 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import javax.swing.Icon ; 30 import javax.swing.ImageIcon ; 31 import org.netbeans.api.java.classpath.ClassPath; 32 import org.netbeans.api.java.classpath.GlobalPathRegistry; 33 import org.netbeans.api.project.Project; 34 import org.netbeans.api.project.ProjectInformation; 35 import org.netbeans.api.project.ProjectManager; 36 import org.netbeans.api.project.ant.AntArtifact; 37 import org.netbeans.modules.j2ee.archive.Util; 38 import org.netbeans.modules.j2ee.archive.customizer.ProvidesCustomizer; 39 import org.netbeans.modules.j2ee.common.ui.BrokenServerSupport; 40 import org.netbeans.modules.j2ee.dd.api.application.Application; 41 import org.netbeans.modules.j2ee.dd.api.application.Module; 42 import org.netbeans.modules.j2ee.dd.api.application.Web; 43 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 44 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 45 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 46 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 47 import org.netbeans.modules.schema2beans.BaseBean; 48 import org.netbeans.modules.web.api.webmodule.WebProjectConstants; 49 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 50 import org.netbeans.spi.project.AuxiliaryConfiguration; 51 import org.netbeans.spi.project.ant.AntArtifactProvider; 52 import org.netbeans.spi.project.support.ant.AntProjectHelper; 53 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 54 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 55 import org.netbeans.spi.project.ui.PrivilegedTemplates; 56 import org.netbeans.spi.project.ui.RecommendedTemplates; 57 import org.openide.ErrorManager; 58 import org.openide.filesystems.FileObject; 59 import org.openide.filesystems.FileUtil; 60 import org.openide.util.Lookup; 61 import org.openide.util.Mutex; 62 import org.openide.util.NbBundle; 63 import org.openide.util.Utilities; 64 import org.openide.util.lookup.Lookups; 65 import org.netbeans.spi.project.ui.ProjectOpenedHook; 66 import org.w3c.dom.Element ; 67 import org.w3c.dom.Node ; 68 import org.w3c.dom.NodeList ; 69 import org.w3c.dom.Text ; 70 71 public class ArchiveProject implements org.netbeans.api.project.Project { 72 73 private final AuxiliaryConfiguration aux; 74 private final AntProjectHelper helper; 75 private final PropertyEvaluator eval; 76 private final GeneratedFilesHelper genFilesHelper; 77 private final Lookup lookup; 78 private ArchiveProjectProperties projProperties; 79 private static final Icon ARCHIVE_PROJECT_ICON = new ImageIcon (Utilities.loadImage("org/netbeans/modules/j2ee/archive/project/resources/application_assembler_16.gif")); private final UpdateHelper updateHelper; 81 82 private HashMap nameMap; 83 84 public ArchiveProject(AntProjectHelper helper) { 85 this.helper = helper; 86 this.eval = helper.getStandardPropertyEvaluator(); 87 aux = helper.createAuxiliaryConfiguration(); 88 genFilesHelper = new GeneratedFilesHelper(helper); 89 lookup = new HelpfulLookup(); 90 this.updateHelper = new UpdateHelper(this, this.helper, this.aux, this.genFilesHelper, 91 UpdateHelper.createDefaultNotifier()); 92 nameMap = new HashMap (5); 93 } 94 95 public FileObject getProjectDirectory() { 96 return helper.getProjectDirectory(); 97 } 98 99 public AntProjectHelper getAntProjectHelper() { 100 return helper; 101 } 102 103 public Lookup getLookup() { 104 return lookup; 105 } 106 107 public PropertyEvaluator getPropertyEvaluator(){ 108 return eval; 109 110 } 111 112 public String getProjectProperty(String propName){ 113 114 return (String ) getArchiveProjectProperties().get(propName); 115 } 116 117 public String getEarPath(String key) { 118 return (String ) nameMap.get(key); 119 } 120 121 public void setEarPath(String key, String val) { 122 nameMap.put(key,val); 123 } 124 125 final private static String NAME_LIT = "name"; 127 128 public void setName(final String name) { 129 ProjectManager.mutex().writeAccess(new Mutex.Action() { 130 public Object run() { 131 Element data = helper.getPrimaryConfigurationData(true); 132 NodeList nl = data.getElementsByTagNameNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, NAME_LIT); 134 Element nameEl; 135 if (nl.getLength() == 1) { 136 nameEl = (Element ) nl.item(0); 137 NodeList deadKids = nameEl.getChildNodes(); 138 while (deadKids.getLength() > 0) { 139 nameEl.removeChild(deadKids.item(0)); 140 } 141 } else { 142 nameEl = data.getOwnerDocument().createElementNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, NAME_LIT); 143 data.insertBefore(nameEl, data.getChildNodes().item(0)); 144 } 145 nameEl.appendChild(data.getOwnerDocument().createTextNode(name)); 146 helper.putPrimaryConfigurationData(data, true); 147 return null; 148 } 149 }); 150 } 151 152 153 public String getName() { 154 return (String ) ProjectManager.mutex().readAccess(new Mutex.Action() { 155 public Object run() { 156 Element data = updateHelper.getPrimaryConfigurationData(true); 157 NodeList nl = data.getElementsByTagNameNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, NAME_LIT); 159 if (nl.getLength() == 1) { 160 nl = nl.item(0).getChildNodes(); 161 if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { 162 return ((Text ) nl.item(0)).getNodeValue(); 163 } 164 } 165 return "BINARCHIVE???"; } 167 }); 168 169 } 170 171 public ArchiveProjectProperties getArchiveProjectProperties() { 172 projProperties= new ArchiveProjectProperties(this,getAntProjectHelper()); 173 return projProperties ; 174 } 175 176 178 private final class HelpfulLookup extends Lookup { 181 182 private boolean verbose = Boolean.getBoolean("archiveproject.lookup.verbose"); 183 184 Lookup inner = Lookups.fixed(new Object [] { 185 new Info(), 186 helper.createAuxiliaryConfiguration(), 187 helper.createCacheDirectoryProvider(), 188 helper.createGlobFileBuiltQuery(eval, new String [] {"${src.dir}/*.java"}, 189 new String [] {"${build.classes.dir}/*.class"}), 190 helper.createSharabilityQuery(eval, new String [] {"${src.dir}"}, 191 new String [] {"${build.dir}","${dist.dir}", "${proxy.project.dir}"}), 192 new OpenCloseHook(), 193 new ProvidesAction(ArchiveProject.this), 194 new ProvidesLogicalView(ArchiveProject.this), 195 helper, 196 new ProvidesJ2eeModule(helper, ArchiveProject.this), 197 new J2eeModuleForAddModuleAction(J2eeModule.EAR), 198 new MyAntProvider(), 199 new ProvidesCustomizer(ArchiveProject.this,helper), 200 new RecommendedTemplatesImpl(), 201 new ArchiveProjectOperations(ArchiveProject.this), 202 ArchiveProject.this, 203 new MyOpenHook(), 204 new ProjectXmlSaved(), 205 206 }); 207 public Object lookup(Class clazz) { 208 Object ret = inner.lookup(clazz); 209 if (verbose && null == ret && ErrorManager.getDefault().isNotifiable(ErrorManager.EXCEPTION)) { 210 StackTraceElement [] sTEs = Thread.currentThread().getStackTrace(); 211 ErrorManager.getDefault().log(ErrorManager.EXCEPTION, 212 NbBundle.getMessage(ArchiveProject.class,"LOOKUP_MISS",clazz.getName(),sTEs[3],sTEs[4])); 213 } 214 return ret; 215 } 216 217 public Lookup.Result lookup(Lookup.Template template) { 218 Lookup.Result ret = inner.lookup(template); 219 if (verbose && null == ret && ErrorManager.getDefault().isNotifiable(ErrorManager.EXCEPTION)) { 220 StackTraceElement [] sTEs = Thread.currentThread().getStackTrace(); 221 ErrorManager.getDefault().log(ErrorManager.EXCEPTION, 222 NbBundle.getMessage(ArchiveProject.class,"LOOKUP_MISS",template.toString(),sTEs[3],sTEs[4])); 223 } 224 return ret; 225 } 226 227 228 } 229 230 private final class Info implements ProjectInformation { 231 232 private PropertyChangeSupport pcs = new PropertyChangeSupport (this); 233 234 public String getName() { 235 return ArchiveProject.this.getNamedProjectAttribute(NAME_LIT); 236 } 237 238 public String getDisplayName() { 239 return ArchiveProject.this.getNamedProjectAttribute(NAME_LIT); 240 } 241 242 public Icon getIcon() { 243 return ARCHIVE_PROJECT_ICON; 244 } 245 246 public Project getProject() { 247 return ArchiveProject.this; 248 } 249 250 public void addPropertyChangeListener(PropertyChangeListener listener) { 251 pcs.addPropertyChangeListener(listener); 252 } 253 254 public void removePropertyChangeListener(PropertyChangeListener listener) { 255 pcs.removePropertyChangeListener(listener); 256 } 257 } 258 259 private final class MyAntProvider implements AntArtifactProvider { 260 public AntArtifact[] getBuildArtifacts() { 262 return new AntArtifact[] { 263 helper.createSimpleAntArtifact(WebProjectConstants.ARTIFACT_TYPE_WAR_EAR_ARCHIVE, 264 "dist.archive", helper.getStandardPropertyEvaluator(), "dist", 265 "clean") 266 }; 267 } 268 } 269 270 class OpenCloseHook extends ProjectOpenedHook { 271 272 List <ClassPath[]> paths = new ArrayList <ClassPath[]>(); 273 274 protected void projectOpened() { 275 ProjectManager.mutex().writeAccess(new Mutex.Action() { 276 public Object run() { 277 doRegeneration(); 278 FileObject dir = helper.getProjectDirectory(); 279 FileObject subDir = null; 280 ArchiveProjectProperties app = getArchiveProjectProperties(); 281 282 String type = (String ) app.get(ArchiveProjectProperties.ARCHIVE_TYPE); 283 boolean isEar = ArchiveProjectProperties.PROJECT_TYPE_VALUE_EAR.equals(type); 284 subDir = dir.getFileObject(ArchiveProjectProperties.TMP_PROJ_DIR_VALUE); 285 if (subDir != null) { 286 Project tmpproj = null; 287 try { 288 tmpproj = ProjectManager.getDefault().findProject(subDir); 289 } catch (IllegalArgumentException ex) { 290 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex); 291 } catch (IOException ex) { 292 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex); 293 } 294 ProvidesJ2eeModule tmp = (ProvidesJ2eeModule) ArchiveProject.this.getLookup().lookup(ProvidesJ2eeModule.class); 295 if (null!=tmpproj) { 296 List <FileObject> roots = new ArrayList <FileObject>(); 297 FileObject cpe = tmpproj.getProjectDirectory().getFileObject("src/java"); 298 if (null != cpe) { 299 roots.add(cpe); 300 } 301 cpe = tmpproj.getProjectDirectory().getFileObject("src/conf"); 302 if (null != cpe) { 303 roots.add(cpe); 304 } 305 cpe = tmpproj.getProjectDirectory().getFileObject("web/WEB-INF/classes"); 306 if (null != cpe) { 307 roots.add(cpe); 308 } 309 if (roots.size() > 0) { 310 ClassPath cp = ClassPathSupport.createClassPath(roots.toArray(new FileObject[roots.size()])); ClassPath[] aofcp = new ClassPath[] {cp}; 312 GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, aofcp); 313 GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, aofcp); 314 paths.add(aofcp); 315 } 316 J2eeModuleProvider jmp = (J2eeModuleProvider) tmpproj.getLookup().lookup(J2eeModuleProvider.class); 317 jmp.getConfigSupport().ensureConfigurationReady(); 318 tmp.setInner(jmp); 319 } else { 320 Object mt = isEar?J2eeModule.EAR:J2eeModule.CONN; 321 tmp.setJ2eeModule(new J2eeModuleForAddModuleAction(mt)); 322 tmp.setServerInstanceID((String ) app.get(ArchiveProjectProperties.J2EE_SERVER_INSTANCE)); 323 if (isEar) { 324 tmp.getConfigSupport().ensureConfigurationReady(); 325 } 326 } 327 } 328 329 if (!isEar) { 330 return null; 331 } 332 333 FileObject appXml = getProjectDirectory().getFileObject("nbproject").getFileObject("application.xml"); if (null != appXml) { 336 try { 337 Application appDD = org.netbeans.modules.j2ee.dd.api.application.DDProvider.getDefault().getDDRoot(appXml); 338 Module ms[] = appDD.getModule(); 339 for (Module m : ms) { 340 String archivePath = m.getEjb(); 341 if (null != archivePath) { 342 openSubarchiveProject(archivePath); 343 } else { 344 archivePath = m.getJava(); 345 if (null != archivePath) { 346 openSubarchiveProject(archivePath); 347 } else { 348 archivePath = m.getConnector(); 349 if (null != archivePath) { 350 openSubarchiveProject(archivePath); 351 } else { 352 Web w = m.getWeb(); 353 if (null != w) { 354 archivePath = w.getWebUri(); 355 if (null != archivePath) { 356 openSubarchiveProject(archivePath); 357 } 358 } 359 } 360 } 361 } 362 363 } 364 } catch (IOException ex) { 365 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex); 366 } 367 } else { 368 ErrorManager.getDefault().log(ErrorManager.WARNING, NbBundle.getMessage(ArchiveProject.class,"WARN_EAR_ARCH_MISSING_APPLICATION_XML",getName())); 369 } 370 return null; 371 } 372 }); 373 } 374 375 private void openSubarchiveProject( String pathInEar ) throws IOException { 376 FileObject root = getProjectDirectory(); 377 FileObject subprojRoot = root.getFileObject("subarchives"); 378 String subprojkey = Util.getKey(pathInEar); 379 try { 380 FileObject projDest = subprojRoot.getFileObject(subprojkey); 381 nameMap.put(subprojkey, pathInEar); 382 FileObject fo = (FileObject) projDest.getFileObject(ArchiveProjectProperties.TMP_PROJ_DIR_VALUE); 383 Project tmpproj = ProjectManager.getDefault().findProject(fo); 384 Project subproj = ProjectManager.getDefault().findProject(projDest); 385 MyOpenHook eh = (MyOpenHook) subproj.getLookup().lookup(MyOpenHook.class); 386 eh.regenerateBuildFiles(); 387 ProvidesJ2eeModule tmp = (ProvidesJ2eeModule) subproj.getLookup().lookup(ProvidesJ2eeModule.class); 388 if (null!=tmpproj) { 389 J2eeModuleProvider jmp = (J2eeModuleProvider) tmpproj.getLookup().lookup(J2eeModuleProvider.class); 390 List <FileObject> roots = new ArrayList <FileObject>(); 391 FileObject cpe = tmpproj.getProjectDirectory().getFileObject("src/java"); 392 if (null != cpe) { 393 roots.add(cpe); 394 } 395 cpe = tmpproj.getProjectDirectory().getFileObject("src/conf"); 396 if (null != cpe) { 397 roots.add(cpe); 398 } 399 cpe = tmpproj.getProjectDirectory().getFileObject("web/WEB-INF/classes"); 400 if (null != cpe) { 401 roots.add(cpe); 402 } 403 if (roots.size() > 0) { 404 ClassPath cp = ClassPathSupport.createClassPath(roots.toArray(new FileObject[roots.size()])); ClassPath[] aofcp = new ClassPath[] {cp}; 406 GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, aofcp); 407 GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, aofcp); 408 paths.add(aofcp); 409 } 410 try { 411 jmp.getConfigSupport().ensureConfigurationReady(); 412 } catch (IllegalArgumentException iae) { 413 FileObject tfo = tmpproj.getProjectDirectory(); 416 if (null != tfo) { 417 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, 418 tmpproj.getProjectDirectory().toString()); 419 } else { 420 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, 421 "null"); 422 } 423 throw iae; 424 } 425 tmp.setInner(jmp); 426 } else { 427 Object mt = J2eeModule.CONN; 428 tmp.setJ2eeModule(new J2eeModuleForAddModuleAction(mt)); 429 tmp.setServerInstanceID((String ) getArchiveProjectProperties().get(ArchiveProjectProperties.J2EE_SERVER_INSTANCE)); 430 } 431 } catch (IOException ex) { 432 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex); 433 } 434 } 435 436 protected void projectClosed() { 437 List <ClassPath[]> tmplist = new ArrayList <ClassPath[]>(); 438 for (ClassPath[] aofcp : paths) { 439 GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, aofcp); 440 GlobalPathRegistry.getDefault().unregister(ClassPath.COMPILE, aofcp); 441 tmplist.add(aofcp); 442 } 443 for (ClassPath[] aofcp : tmplist) { 444 paths.remove(aofcp); 445 } 446 } 447 448 } 449 450 class ProjectXmlSaved extends org.netbeans.spi.project.support.ant.ProjectXmlSavedHook { 452 453 protected void projectXmlSaved() throws IOException { 454 FileObject subDir = getProjectDirectory().getFileObject(ArchiveProjectProperties.TMP_PROJ_DIR_VALUE); 455 if (subDir != null) { 456 Project tmpproj = null; 457 try { 458 tmpproj = ProjectManager.getDefault().findProject(subDir); 459 } catch (IllegalArgumentException ex) { 460 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex); 461 } catch (IOException ex) { 462 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex); 463 } 464 ProvidesJ2eeModule tmp = (ProvidesJ2eeModule) ArchiveProject.this.getLookup().lookup(ProvidesJ2eeModule.class); 465 if (null!=tmpproj) { 466 tmp.setServerInstanceID((String ) getArchiveProjectProperties().get(ArchiveProjectProperties.J2EE_SERVER_INSTANCE)); 468 } 469 } 470 } 471 } 472 473 474 475 public String getNamedProjectAttribute(final String attr) { 476 return (String ) ProjectManager.mutex().readAccess(new Mutex.Action() { 477 public Object run() { 478 Element data = helper.getPrimaryConfigurationData(true); 479 NodeList nl = data.getElementsByTagNameNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, attr); 481 if (nl.getLength() == 1) { 482 nl = nl.item(0).getChildNodes(); 483 if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { 484 return ((Text ) nl.item(0)).getNodeValue(); 485 } 486 } 487 return "???"; } 489 }); 490 } 491 492 493 public void setNamedProjectAttribute(final String attr, final String value) { 494 ProjectManager.mutex().writeAccess(new Mutex.Action() { 495 public Object run() { 496 Element data = helper.getPrimaryConfigurationData(true); 497 NodeList nl = data.getElementsByTagNameNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, attr); 499 Element nameEl; 500 if (nl.getLength() == 1) { 501 nameEl = (Element ) nl.item(0); 502 NodeList deadKids = nameEl.getChildNodes(); 503 while (deadKids.getLength() > 0) { 504 nameEl.removeChild(deadKids.item(0)); 505 } 506 } else { 507 nameEl = data.getOwnerDocument().createElementNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, attr); 508 data.insertBefore(nameEl, data.getChildNodes().item(0)); 509 } 510 nameEl.appendChild(data.getOwnerDocument().createTextNode(value)); 511 helper.putPrimaryConfigurationData(data, true); 512 return null; 513 } 514 }); 515 } 516 517 private class J2eeModuleForAddModuleAction implements J2eeModule { 518 519 private Object mt = null; 520 521 J2eeModuleForAddModuleAction(Object mt) { 522 this.mt = mt; 523 } 524 525 public String getModuleVersion() { 526 return J2eeModule.JAVA_EE_5; } 528 529 public Object getModuleType() { 530 return mt; 531 } 532 533 public String getUrl() { 534 return null; 536 } 537 538 public void setUrl(String url) { 539 throw new UnsupportedOperationException (); 540 } 541 542 public FileObject getArchive() throws IOException { 543 FileObject distDir = getProjectDirectory().getFileObject("dist"); 544 FileObject kids[] = distDir.getChildren(); 545 FileObject retVal = null; 546 if (null != kids && kids.length == 1){ 547 retVal = kids[0]; 548 } else if (null != kids && kids.length > 1) { 549 for (FileObject kid : kids) { 550 if (kid.isData() && kid.getNameExt().endsWith("ar")) { 551 retVal = kid; 552 } 553 } 554 } 555 556 return retVal; 557 } 558 559 public Iterator getArchiveContents() throws IOException { 560 throw new UnsupportedOperationException (); 561 } 562 563 public FileObject getContentDirectory() throws IOException { 564 return null; 565 } 566 567 public BaseBean getDeploymentDescriptor(String location) { 568 BaseBean retVal = null; 569 if ("META-INF/application.xml".equals(location)) { 570 String dir = (String )getArchiveProjectProperties().get(ArchiveProjectProperties.PROXY_PROJECT_DIR); 571 FileObject appFile = getProjectDirectory().getFileObject(dir).getFileObject("src").getFileObject("conf").getFileObject("application.xml"); 572 Application appBean; 573 try { 574 appBean = org.netbeans.modules.j2ee.dd.api.application.DDProvider.getDefault().getDDRoot(appFile); 575 retVal = org.netbeans.modules.j2ee.dd.api.application.DDProvider.getDefault().getBaseBean(appBean); 576 } catch (IOException ex) { 577 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex); 578 } 579 } else if ("META-INF/ra.xml".equals(location)) { 580 retVal = null; 581 } else { 582 throw new UnsupportedOperationException (location); 583 } 584 return retVal; 585 } 586 587 public void addVersionListener(J2eeModule.VersionListener listener) { 588 } 590 591 public void removeVersionListener(J2eeModule.VersionListener listener) { 592 } 594 } 595 596 597 598 private static final class RecommendedTemplatesImpl implements RecommendedTemplates, PrivilegedTemplates { 599 600 RecommendedTemplatesImpl() { 601 } 602 603 605 private static final String [] APPLICATION_TYPES = new String [] { 606 "sunresource-types", "XML", "simple-files" }; 610 611 private static final String [] PRIVILEGED_NAMES = new String [] { 612 "Templates/SunResources/JDBC_Connection_Pool", "Templates/SunResources/JDBC_Resource", "Templates/SunResources/JMS_Resource", "Templates/SunResources/JavaMail_Resource", "Templates/Persistence/Schema.dbschema", }; 618 619 public String [] getRecommendedTypes() { 620 return APPLICATION_TYPES; 621 } 622 623 public String [] getPrivilegedTemplates() { 624 return PRIVILEGED_NAMES; 625 } 626 627 } 628 629 class MyOpenHook { 630 631 public void regenerateBuildFiles() { 632 doRegeneration(); 633 } 634 } 635 636 private void doRegeneration() { 637 638 GeneratedFilesHelper gFH = new GeneratedFilesHelper(helper); 639 ArchiveProjectProperties app = getArchiveProjectProperties(); 640 String sourceArchive = eval.evaluate((String )app.get(ArchiveProjectProperties.SOURCE_ARCHIVE)); 641 try { 642 if (sourceArchive.endsWith("war")) gFH.refreshBuildScript(GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 644 ArchiveProject.class.getResource("resources/build-impl-war.xsl"), 645 true); 646 else 647 gFH.refreshBuildScript(GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 649 ArchiveProject.class.getResource("resources/build-impl.xsl"), 650 true); 651 } catch (IllegalStateException ex) { 652 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "IllegalStateException while opening project: " + ex); 653 } catch (IOException ex) { 654 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "IOException while opening project: " + ex); 655 } 656 try { 657 gFH.refreshBuildScript( 658 GeneratedFilesHelper.BUILD_XML_PATH, 659 ArchiveProject.class.getResource("resources/build.xsl"), 660 true); 661 } catch (IllegalStateException ex) { 662 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "IllegalStateException while opening project: " + ex); 663 } catch (IOException ex) { 664 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "IOException while opening project: " + ex); 665 } 666 667 String servInstID = (String ) app.get(ArchiveProjectProperties.J2EE_SERVER_INSTANCE); 668 J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID); 669 if (platform != null) { 670 ArchiveProjectProperties.setServerInstance(ArchiveProject.this, 672 ArchiveProject.this.helper, servInstID); 673 } else { 674 String serverType = (String ) app.get(ArchiveProjectProperties.J2EE_SERVER_TYPE); 677 if (serverType != null) { 678 String [] servInstIDs = Deployment.getDefault().getInstancesOfServer(serverType); 679 if (servInstIDs.length > 0) { 680 ArchiveProjectProperties.setServerInstance(ArchiveProject.this, ArchiveProject.this.helper, servInstIDs[0]); 681 platform = Deployment.getDefault().getJ2eePlatform(servInstIDs[0]); 682 } 683 } 684 if (platform == null) { 685 BrokenServerSupport.showAlert(); 686 } 687 } 688 689 691 FileObject dir = helper.getProjectDirectory(); 693 try { 694 FileUtil.createFolder(dir,ArchiveProjectProperties.SETUP_DIR_VALUE); 695 } catch (IOException ex) { 696 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Error while opening project: " + ex); 697 } 698 } 699 } 700 701 702 | Popular Tags |