1 package com.bull.eclipse.jonas; 2 3 7 8 import java.io.File ; 9 import java.io.FileInputStream ; 10 import java.io.IOException ; 11 import java.io.InputStream ; 12 import java.util.ArrayList ; 13 import java.util.Arrays ; 14 import java.util.Enumeration ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.StringTokenizer ; 18 import java.util.Vector ; 19 20 import org.eclipse.core.resources.IFile; 21 import org.eclipse.core.resources.IFolder; 22 import org.eclipse.core.resources.IProject; 23 import org.eclipse.core.resources.IProjectNature; 24 import org.eclipse.core.resources.IResource; 25 import org.eclipse.core.resources.IResourceStatus; 26 import org.eclipse.core.runtime.CoreException; 27 import org.eclipse.core.runtime.IPath; 28 import org.eclipse.core.runtime.Path; 29 import org.eclipse.core.runtime.PlatformObject; 30 import org.eclipse.core.runtime.QualifiedName; 31 import org.eclipse.jdt.core.IClasspathEntry; 32 import org.eclipse.jdt.core.IJavaProject; 33 import org.eclipse.jdt.core.JavaCore; 34 35 import com.bull.eclipse.jonas.utils.FileUtil; 36 import com.bull.eclipse.jonas.utils.JDTUtil; 37 import com.bull.eclipse.jonas.utils.TemplateDirUtil; 38 39 40 41 42 public class JonasProject extends PlatformObject implements IProjectNature { 43 44 private static final String PROPERTIES_FILENAME = ".jonasplugin"; 46 private static final String KEY_WEBCONTEXT = "webContext"; 47 private static final String KEY_EXPORTSOURCE = "exportSource"; 48 private static final String KEY_RELOADABLE="reloadable"; 49 private static final String KEY_REDIRECTLOGGER="redirectLogger"; 50 private static final String KEY_WARLOCATION = "warLocation"; 51 private static final String KEY_SRCDIR = "srcDir"; 52 private static final String KEY_SRCEJBDIR = "srcEJBDir"; 53 private static final String KEY_WEBDIRNAME = "webdirName"; 54 private static final String KEY_EXTRARESOURCES = ExtraResourcesEntries.TAG_NAME; 55 56 private static final QualifiedName QN_WEBCONTEXT = new QualifiedName("JonasProject", KEY_WEBCONTEXT); 57 private static final QualifiedName QN_EXPORTSOURCE = new QualifiedName("JonasProject", KEY_EXPORTSOURCE); 58 private static final QualifiedName QN_RELOADABLE = new QualifiedName("JonasProject", KEY_RELOADABLE); 59 private static final QualifiedName QN_REDIRECTLOGGER = new QualifiedName("JonasProject", KEY_REDIRECTLOGGER); 60 private static final QualifiedName QN_WARLOCATION = new QualifiedName("JonasProject", KEY_WARLOCATION); 61 private static final QualifiedName QN_SRCDIR = new QualifiedName("JonasProject", KEY_SRCDIR); 62 private static final QualifiedName QN_SRCEJBDIR = new QualifiedName("JonasProject", KEY_SRCEJBDIR); 63 private static final QualifiedName QN_WEBDIRNAME = new QualifiedName("JonasProject", KEY_WEBDIRNAME); 64 private static final QualifiedName QN_EXTRARESOURCES = new QualifiedName("JonasProject", KEY_EXTRARESOURCES); 65 66 69 protected IProject project; 70 protected IJavaProject javaProject; 71 72 protected String webContext = ""; 73 protected String warLocation = ""; 74 protected boolean exportSource; 75 protected boolean reloadable = true; 76 protected boolean redirectLogger = true; 77 protected String srcDir = ""; 78 protected String srcEJBDir = ""; 79 protected String srcPersistenceDir = "persistence"; 80 protected String webdirName = ""; 81 protected ExtraResourcesEntries extraResourcesEntries; 82 protected Vector packageEJB = null; 83 protected Vector jarEJBName = null; 84 85 protected IFolder webDirFolder; 86 protected IFolder srcDirFolder; 87 protected IFolder srcEJBDirFolder; 88 protected boolean createSamples; 90 94 public IProject getProject() { 95 return project; 96 } 97 98 102 public void setProject(IProject project) { 103 this.project = project; 104 } 105 106 109 public void configure() throws CoreException { 110 } 111 112 115 public void deconfigure() throws CoreException { 116 } 117 118 121 public IJavaProject getJavaProject() { 122 return javaProject; 123 } 124 125 128 public void setJavaProject(IJavaProject javaProject) { 129 this.javaProject = javaProject; 130 this.setProject(javaProject.getProject()); 131 } 132 133 134 static public void addJonasNature(IJavaProject project) { 135 try { 136 JDTUtil.addNatureToProject(project.getProject(), JonasLauncherPlugin.NATURE_ID); 137 } catch(CoreException ex) { 138 JonasLauncherPlugin.log(ex.getMessage()); 139 } 140 } 141 142 static public void removeJonasNature(IJavaProject project) { 143 try { 144 JDTUtil.removeNatureToProject(project.getProject(), JonasLauncherPlugin.NATURE_ID); 145 } catch(CoreException ex) { 146 JonasLauncherPlugin.log(ex.getMessage()); 147 } 148 } 149 150 154 static public JonasProject create(IJavaProject javaProject) { 155 JonasProject result = null; 156 try { 157 result = (JonasProject)javaProject.getProject().getNature(JonasLauncherPlugin.NATURE_ID); 158 if(result != null) 159 result.setJavaProject(javaProject); 160 } catch(CoreException ex) { 161 JonasLauncherPlugin.log(ex.getMessage()); 162 } 163 return result; 164 } 165 166 170 static public JonasProject create(IProject project) { 171 172 IJavaProject javaProject = JavaCore.create(project); 173 if(javaProject != null) { 174 return JonasProject.create(javaProject); 175 } else { 176 return null; 177 } 178 } 179 180 private File getPropertiesFile() { 181 return (this.getProject().getLocation().append(PROPERTIES_FILENAME).toFile()); 182 } 183 184 private String readProperty(String key) { 185 String result = null; 186 187 try { 188 result = FileUtil.readPropertyInXMLFile(getPropertiesFile(), key); 189 } catch (IOException e) { 190 try { 191 result = getJavaProject().getCorrespondingResource().getPersistentProperty(new QualifiedName("JonasProject", key)); 192 } catch (Exception e2) { 193 JonasLauncherPlugin.log(e2); 194 } 195 } 196 197 if(result == null) { 198 result = ""; 199 } 200 201 return result; 202 } 203 204 205 209 public String getWebContext() { 210 return this.readProperty(KEY_WEBCONTEXT); 211 } 212 213 217 public void setWebContext(String wp) { 218 this.webContext = wp; 219 } 220 221 public void updateWebContext(String newContextPath) throws Exception { 222 setWebContext(newContextPath); 223 } 224 225 229 public String getWarLocation() { 230 return this.readProperty(KEY_WARLOCATION); 231 } 232 233 237 public void setWarLocation(String wl) { 238 this.warLocation = wl; 239 } 240 241 242 246 public boolean getExportSource() { 247 return new Boolean (this.readProperty(KEY_EXPORTSOURCE)).booleanValue(); 248 } 249 250 254 public void setExportSource(boolean exportSource) { 255 this.exportSource = exportSource; 256 } 257 258 262 public boolean getReloadable(){ 263 String reloadableProperty = this.readProperty(KEY_RELOADABLE); 264 if(reloadableProperty.equals("")) { 266 reloadableProperty = "true"; 267 } 268 return new Boolean (reloadableProperty).booleanValue(); 269 } 270 271 275 public void setReloadable(boolean reloadable){ 276 this.reloadable = reloadable; 277 } 278 279 283 public boolean getRedirectLogger(){ 284 String redirectLoggerProperty = this.readProperty(KEY_REDIRECTLOGGER); 285 if(redirectLoggerProperty.equals("")) { 287 redirectLoggerProperty = "false"; 288 } 289 return new Boolean (redirectLoggerProperty).booleanValue(); 290 } 291 292 296 public void setRedirectLogger(boolean redirectLogger){ 297 this.redirectLogger = redirectLogger; 298 } 299 300 301 302 306 public String getSrcDir(){ 307 return this.readProperty(KEY_SRCDIR); 308 } 309 310 public String getSrcEJBDir(){ 311 return this.readProperty(KEY_SRCEJBDIR); 312 } 313 314 318 public void setSrcDir(String srcdir){ 319 this.srcDir = srcdir; 320 } 321 322 323 public void setSrcEJBDir(String srcejbdir){ 324 this.srcEJBDir = srcejbdir; 325 } 326 327 331 public String getWebdirName(){ 332 return this.readProperty(KEY_WEBDIRNAME); 333 } 334 335 339 public void setWebdirName(String webdirName){ 340 this.webdirName = webdirName; 341 } 342 343 344 348 public void setExtraResourcesEntries(ExtraResourcesEntries entries) { 349 extraResourcesEntries = entries; 350 } 351 352 355 public ExtraResourcesEntries getExtraResourcesEntries() { 356 try { 357 return ExtraResourcesEntries.xmlUnmarshal(FileUtil.readTextFile(getPropertiesFile())); 358 } catch(IOException ioEx) { 359 return null; 360 } 361 } 362 363 364 367 public void saveProperties() { 368 try { 369 StringBuffer fileContent = new StringBuffer (); 370 fileContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 371 fileContent.append("<jonasProjectProperties>\n"); 372 fileContent.append(" <exportSource>" + exportSource + "</exportSource>\n"); 373 fileContent.append(" <reloadable>" + reloadable + "</reloadable>\n"); 374 fileContent.append(" <redirectLogger>" + redirectLogger + "</redirectLogger>\n"); 375 fileContent.append(" <warLocation>" + warLocation + "</warLocation>\n"); 376 fileContent.append(" <srcDir>" + srcDir + "</srcDir>\n"); 377 fileContent.append(" <srcEJBDir>" + srcEJBDir + "</srcEJBDir>\n"); 378 fileContent.append(" <webdirName>" + webdirName + "</webdirName>\n"); 379 fileContent.append(" <webContext>" + webContext + "</webContext>\n"); 380 if (packageEJB != null) { 381 int i = 1; 382 for (Enumeration e = packageEJB.elements() ; e.hasMoreElements() ;) { 383 fileContent.append(" <ejb" + i + ">" + e.nextElement() + "</ejb" + i + ">\n"); 384 i++; 385 } 386 } 387 if (jarEJBName != null) { 388 int i = 1; 389 for (Enumeration e = jarEJBName.elements() ; e.hasMoreElements() ;) { 390 fileContent.append(" <ejbjarname" + i + ">" + e.nextElement() + "</ejbjarname" + i + ">\n"); 391 i++; 392 } 393 } 394 395 if (extraResourcesEntries != null) { 396 fileContent.append(extraResourcesEntries.xmlMarshal(4)); 397 } 398 fileContent.append("</jonasProjectProperties>\n"); 399 FileUtil.toTextFile(getPropertiesFile(), fileContent.toString()); 400 } catch (Exception ex) { 401 JonasLauncherPlugin.log(ex.getMessage()); 402 } 403 } 404 405 public void saveEJBProperties() { 406 try { 407 StringBuffer fileContent = new StringBuffer (); 408 fileContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 409 fileContent.append("<jonasProjectProperties>\n"); 410 fileContent.append(" <exportSource>" + getExportSource() + "</exportSource>\n"); 411 fileContent.append(" <reloadable>" + getReloadable() + "</reloadable>\n"); 412 fileContent.append(" <redirectLogger>" + getRedirectLogger() + "</redirectLogger>\n"); 413 fileContent.append(" <warLocation>" + getWarLocation() + "</warLocation>\n"); 414 fileContent.append(" <srcDir>" + getSrcDir() + "</srcDir>\n"); 415 fileContent.append(" <srcEJBDir>" + getSrcEJBDir() + "</srcEJBDir>\n"); 416 fileContent.append(" <webdirName>" + getWebdirName() + "</webdirName>\n"); 417 fileContent.append(" <webContext>" + getWebContext() + "</webContext>\n"); 418 if (packageEJB != null) { 419 int i = 1; 420 for (Enumeration e = packageEJB.elements() ; e.hasMoreElements() ;) { 421 fileContent.append(" <ejb" + i + ">" + e.nextElement() + "</ejb" + i + ">\n"); 422 i++; 423 } 424 } 425 if (jarEJBName != null) { 426 int i = 1; 427 for (Enumeration e = jarEJBName.elements() ; e.hasMoreElements() ;) { 428 fileContent.append(" <ejbjarname" + i + ">" + e.nextElement() + "</ejbjarname" + i + ">\n"); 429 i++; 430 } 431 } 432 433 if (getExtraResourcesEntries() != null) { 434 fileContent.append(getExtraResourcesEntries().xmlMarshal(4)); 435 } 436 fileContent.append("</jonasProjectProperties>\n"); 437 FileUtil.toTextFile(getPropertiesFile(), fileContent.toString()); 438 } catch (Exception ex) { 439 JonasLauncherPlugin.log(ex.getMessage()); 440 } 441 } 442 443 446 public void fullConfiguration() throws CoreException, IOException { 447 448 this.createWEBINFFolder(); 449 this.createSrcFolder(); 450 451 this.createWebSample(); 452 453 this.addJonasJarToProjectClasspath(); 454 this.addWEBINFLibJarFilesToProjectClasspath(); 455 456 this.clearDefaultSourceEntries(); 457 this.setClassesAsOutputFolder(); 458 if(classesContainsJavaFiles()) { 459 this.setClassesAsSourceFolder(); 460 } 461 this.setSrcAsSourceFolder(srcDir); 462 463 } 464 465 public void clearDefaultSourceEntries() throws CoreException { 466 467 IClasspathEntry[] entries = javaProject.getRawClasspath(); 468 List cp= new ArrayList (entries.length + 1); 469 for(int i=0; i<entries.length; i++) { 470 if(entries[i].getEntryKind() != IClasspathEntry.CPE_SOURCE) { 471 cp.add(entries[i]); 472 } 473 } 474 javaProject.setRawClasspath((IClasspathEntry[])cp.toArray(new IClasspathEntry[cp.size()]), null); 475 } 476 477 480 public void addJonasJarToProjectClasspath() throws CoreException { 481 482 Vector jonasJarPath = JonasLauncherPlugin.getDefault().getJonasBootstrap().getJonasJarPath(); 483 Vector jonasWebJarPath = JonasLauncherPlugin.getDefault().getJonasBootstrap().getJonasWebJarPath(); 484 485 486 IClasspathEntry[] entries = javaProject.getRawClasspath(); 487 List cp= new ArrayList (entries.length + 1); 488 cp.addAll(Arrays.asList(entries)); 489 490 if(jonasJarPath != null) { 491 for(int i = 0; i < jonasJarPath.size();i++) { 492 cp.add(JavaCore.newVariableEntry(JonasLauncherPlugin.getDefault().getJonasIPath().append((IPath) jonasJarPath.elementAt(i)), null, null)); 493 } 494 } 495 if(jonasWebJarPath != null) { 496 for(int j = 0; j < jonasWebJarPath.size();j++) { 497 cp.add(JavaCore.newVariableEntry(JonasLauncherPlugin.getDefault().getJonasIPath().append((IPath) jonasWebJarPath.elementAt(j)), null, null)); 498 } 499 } 500 501 502 javaProject.setRawClasspath((IClasspathEntry[])cp.toArray(new IClasspathEntry[cp.size()]), null); 503 } 504 505 public void removeJonasJarToProjectClasspath() throws CoreException { 506 507 IClasspathEntry[] entries = javaProject.getRawClasspath(); 508 List cp = new ArrayList (entries.length + 1); 509 cp.addAll(Arrays.asList(entries)); 510 Iterator cpIte = cp.iterator(); 511 List newCp = new ArrayList (); 512 513 while (cpIte.hasNext()) { 514 IClasspathEntry pathEntry = (IClasspathEntry) cpIte.next(); 515 String lastSeg = pathEntry.getPath().lastSegment(); 516 JonasLauncherPlugin.log("Last seg = " + lastSeg); 517 if (lastSeg.equals("jonas.jar") || 518 lastSeg.equals("web_catalina.jar") || 519 lastSeg.equals("mail.jar") || 520 lastSeg.equals("jts-spec1_0.jar") || 521 lastSeg.equals("jta-spec1_0_1.jar") || 522 lastSeg.equals("jms.jar") || 523 lastSeg.equals("servlet-2_4.jar") || 524 lastSeg.equals("jsp-2_0.jar") || 525 lastSeg.equals("jacc-1_0.jar") || 526 lastSeg.equals("javax77.jar") || 527 lastSeg.equals("ejb-2_1-api.jar") || 528 lastSeg.equals("connector-1_5.jar") || 529 lastSeg.equals("activation.jar") || 530 lastSeg.equals("RMI_jonas.jar") || 531 lastSeg.equals("JEREMIE_jonas.jar") || 532 lastSeg.equals("jaxrpc.jar") || 533 lastSeg.equals("commons-discovery.jar") || 534 lastSeg.equals("saaj.jar") || 535 lastSeg.equals("commons-discovery.jar") || 536 lastSeg.equals("commons-logging-api.jar") || 537 lastSeg.equals("ow_jonas.jar") || 538 lastSeg.equals("ow_carol_core.jar") || 539 lastSeg.equals("jotm.jar") || 540 lastSeg.equals("axis.jar")) 541 continue; 542 else 543 newCp.add(pathEntry); 544 545 } 546 javaProject.setRawClasspath((IClasspathEntry[])newCp.toArray(new IClasspathEntry[newCp.size()]), null); 547 } 548 549 550 553 public void addWEBINFLibJarFilesToProjectClasspath() throws CoreException { 554 IFolder libFolder = this.getWebInfFolder().getFolder("lib"); 555 IResource[] libFiles = libFolder.members(); 556 557 IClasspathEntry[] entries = javaProject.getRawClasspath(); 558 List cp= new ArrayList (entries.length + 1); 559 cp.addAll(Arrays.asList(entries)); 560 561 for(int i=0; i<libFiles.length; i++) { 562 if((libFiles[i].getType() == IResource.FILE) && (libFiles[i].getFileExtension().equalsIgnoreCase("jar"))) { 563 cp.add(JavaCore.newLibraryEntry(libFiles[i].getFullPath(), null, null)); 564 } 565 } 566 567 javaProject.setRawClasspath((IClasspathEntry[])cp.toArray(new IClasspathEntry[cp.size()]), null); 568 } 569 570 public IFolder getWebInfFolder() { 571 if (getWebDirFolder() == null) { 572 return project.getFolder("WEB-INF"); 573 } else { 574 return getWebDirFolder().getFolder("WEB-INF"); 575 } 576 } 577 578 579 public IFolder getWebDirFolder() { 583 if (webDirFolder == null) { 584 this.initWebDirFolder(false); 585 } 586 return webDirFolder; 587 } 588 589 public IFolder getSrcDirFolder() { 590 if (srcDirFolder == null) { 591 this.initSrcDirFolder(false); 592 } 593 return srcDirFolder; 594 } 595 596 public IFolder getSrcEJBDirFolder() { 597 if (srcEJBDirFolder == null) { 598 this.initSrcEJBDirFolder(false); 599 } 600 return srcEJBDirFolder; 601 } 602 603 604 605 private IFolder initWebDirFolder(boolean create) { 606 607 StringTokenizer tokenizer = new StringTokenizer (this.getWebdirName(), "/\\:"); 608 IFolder folder = null; 609 try { 610 while (tokenizer.hasMoreTokens()) { 611 String each = tokenizer.nextToken(); 612 if (folder == null) { 613 folder = project.getFolder(each); 614 } else { 615 folder = folder.getFolder(each); 616 } 617 if (create) { 618 this.createFolder(folder); 619 } 620 } 621 } catch (CoreException ex) { 622 JonasLauncherPlugin.log(ex); 623 folder = null; 624 setWebdirName("/"); 625 } 626 this.webDirFolder = folder; 627 return folder; 628 } 629 630 private IFolder initSrcDirFolder(boolean create) { 631 632 StringTokenizer tokenizer = new StringTokenizer (this.getSrcDir(), "/\\:"); 633 IFolder folder = null; 634 try { 635 while (tokenizer.hasMoreTokens()) { 636 String each = tokenizer.nextToken(); 637 if (folder == null) { 638 folder = project.getFolder(each); 639 } else { 640 folder = folder.getFolder(each); 641 } 642 if (create) { 643 this.createFolder(folder); 644 } 645 } 646 } catch (CoreException ex) { 647 JonasLauncherPlugin.log(ex); 648 folder = null; 649 } 650 this.srcDirFolder = folder; 651 return folder; 652 } 653 654 private IFolder initSrcEJBDirFolder(boolean create) { 655 StringTokenizer tokenizer = new StringTokenizer (this.getSrcEJBDir(), "/\\:"); 656 IFolder folder = null; 657 try { 658 while (tokenizer.hasMoreTokens()) { 659 String each = tokenizer.nextToken(); 660 if (folder == null) { 661 folder = project.getFolder(each); 662 } else { 663 folder = folder.getFolder(each); 664 } 665 if (create) { 666 this.createFolder(folder); 667 } 668 } 669 } catch (CoreException ex) { 670 JonasLauncherPlugin.log(ex); 671 folder = null; 672 } 673 this.srcEJBDirFolder = folder; 674 return folder; 675 } 676 677 public void createWEBINFFolder() throws CoreException { 678 IFolder webinfFolder = this.getWebInfFolder(); 679 if ((webDirFolder != null) && (!(webDirFolder.getName().trim()).equals("."))) 680 this.createFolder(webDirFolder); 681 this.createFolder(webinfFolder); 682 this.createFolder(webinfFolder.getFolder("classes")); 683 this.createFolder(webinfFolder.getFolder("lib")); 684 } 685 686 public void createSrcFolder() throws CoreException { 687 688 IFolder srcdirFolder = this.getSrcDirFolder(); 690 if (srcDirFolder != null) 691 this.createFolder(srcdirFolder); 692 } 693 694 704 public void createWebSample() 705 { 706 String template = null; 707 String webxmlTemplate = null; 708 IFile webxml = null; 709 if( ! createSamples ) { 710 template = TemplateDirUtil.getTemplateDir(); 711 webxmlTemplate = template + "/web.xml.empty"; 712 webxml = getWebInfFolder().getFile("web.xml"); 713 createFile( webxmlTemplate, webxml ); 714 return; 715 } 716 717 template = TemplateDirUtil.getTemplateDir(); 718 webxmlTemplate = template + "/web.xml"; 719 webxml = getWebInfFolder().getFile("web.xml"); 720 createFile( webxmlTemplate, webxml ); 721 722 String indexhtmlTemplate = template + "/index.html"; 723 IFile indexhtml = getWebDirFolder().getFile("index.html"); 724 createFile( indexhtmlTemplate, indexhtml ); 725 726 String samplejspTemplate = template + "/sample-jsp.jsp"; 727 IFile samplejsp = getWebDirFolder().getFile("sample-jsp.jsp"); 728 createFile( samplejspTemplate, samplejsp ); 729 730 String sampleservletTemplate = template + "/SampleServlet-src"; 731 IFile sampleservlet = getSrcDirFolder().getFile("SampleServlet.java"); 732 createFile( sampleservletTemplate, sampleservlet ); 733 734 try { 736 StringBuffer fileContent = new StringBuffer (); 737 fileContent.append( 738 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" 739 + "<!DOCTYPE jonas-web-app PUBLIC\n" 740 + " \"-//ObjectWeb//DTD JOnAS Web App 2.6//EN\"\n" 741 + " \"http://www.objectweb.org/jonas/dtds/jonas-web-app_2_6.dtd\">\n" 742 + "\n" 743 + "<jonas-web-app>\n" 744 + "\t<context-root>" + webContext + "</context-root>\n" 745 + "</jonas-web-app>\n" 746 ); 747 IFile jonaswebxml = getWebInfFolder().getFile("jonas-web.xml"); 748 JonasLauncherPlugin.log("JOPE: creating " + jonaswebxml.getFullPath().toString() ); 749 jonaswebxml.create(new java.io.ByteArrayInputStream (fileContent.toString().getBytes()),false,null); 750 } 751 catch( Exception e ) { 752 JonasLauncherPlugin.log("JOPE: exception creating file: " + e ); 753 } 754 } 755 756 757 public void createFile( String from, IFile to ) 758 { 759 JonasLauncherPlugin.log("JOPE: copying " + from + " to " + to.getFullPath().toString() ); 760 try { 761 InputStream stream = new FileInputStream (from); 762 to.create( stream, false, null ); 763 } 764 catch( Exception e ) { 765 JonasLauncherPlugin.log("JOPE: exception copying file: " + e ); 766 } 767 } 768 769 770 public Vector getPackageProjectFolder() { 771 readEJBPkgName(); 772 return packageEJB; 773 } 774 775 private void readEJBPkgName() { 776 if ((packageEJB == null) || (jarEJBName == null)) { 777 int i = 1; 778 boolean isEJB = true; 779 String packEJB = null; 780 String jarName = null; 781 while (isEJB) { 782 packEJB = this.readProperty("ejb" + i); 783 jarName = this.readProperty("ejbjarname" + i); 784 if (packEJB.equals("")) { 785 isEJB = false; 786 } else { 787 if ((new File (this.getProject().getLocation().append(getSrcEJBDir()).append(packEJB).toOSString()).exists())) { 788 if (packageEJB == null) 789 packageEJB = new Vector (); 790 if (jarEJBName == null) 791 jarEJBName = new Vector (); 792 packageEJB.add(packEJB); 793 jarEJBName.add(jarName); 794 } 795 } 796 i++; 797 } 798 } else { 799 for (Enumeration e = packageEJB.elements() ; e.hasMoreElements() ;) { 800 String pkgEJB = (String )e.nextElement(); 801 if (!(new File (this.getProject().getLocation().append(getSrcEJBDir()).append(pkgEJB).toOSString()).exists())) { 802 int i = packageEJB.indexOf(pkgEJB); 803 packageEJB.remove(i); 804 jarEJBName.remove(i); 805 } 806 } 807 } 808 saveEJBProperties(); 809 } 810 public Vector getJarEjbName() { 811 readEJBPkgName(); 812 return jarEJBName; 813 } 814 815 public void setPackageProjectFolder(String packageDir) { 816 if (packageEJB == null) 817 packageEJB = new Vector (); 818 packageDir = packageDir.replace(".".charAt(0),File.separatorChar); 819 JonasLauncherPlugin.log("package = " + packageDir); 820 packageEJB.add(packageDir); 821 saveEJBProperties(); 822 } 823 824 public void setJarEjbName(String jarejbName) { 825 if (jarEJBName == null) 826 jarEJBName = new Vector (); 827 JonasLauncherPlugin.log("jarEJBName = " + jarejbName); 828 jarEJBName.add(jarejbName); 829 saveEJBProperties(); 830 } 831 832 public void setSrcAsSourceFolder(String srcFolder) throws CoreException { 833 this.setFolderAsSourceEntry(project.getFolder(srcFolder)); 834 } 835 836 public String getOutputFolder() { 837 try { 838 String rootPath = project.getLocation().toOSString(); 839 String classesPath = rootPath + File.separator + ".." + File.separator + javaProject.getOutputLocation().toOSString(); 840 return classesPath; 841 } catch (CoreException ce) { 842 JonasLauncherPlugin.log("JOPE: exception getOutputFolder: " + ce ); 843 } 844 return null; 845 } 846 847 public void setClassesAsOutputFolder() throws CoreException { 848 851 854 this.createFolder(project.getFolder("classes")); 855 IFolder classesFolder = project.getFolder("classes"); 856 javaProject.setOutputLocation(classesFolder.getFullPath(),null); 857 858 } 859 860 public void setClassesAsSourceFolder() throws CoreException { 861 IFolder classesFolder = this.getWebInfFolder().getFolder("classes"); 862 this.setFolderAsSourceEntry(classesFolder); 863 } 864 865 866 private void createFolder(IFolder folderHandle) throws CoreException { 867 try { 868 folderHandle.create(false, true, null); } 871 catch (CoreException e) { 872 if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) 874 folderHandle.refreshLocal(IResource.DEPTH_INFINITE, null); else 876 throw e; 877 } 878 } 879 880 public void createSrcEJBFolder() throws CoreException { 881 882 IFolder srcEJBDirFolder = this.getSrcEJBDirFolder(); 884 if (srcEJBDirFolder != null) 885 this.createFolder(srcEJBDirFolder); 886 setSrcAsSourceFolder(srcEJBDir); 887 } 888 889 private void setFolderAsSourceEntry(IFolder folderHandle) throws CoreException { 890 IClasspathEntry[] entries= javaProject.getRawClasspath(); 891 IClasspathEntry[] newEntries= new IClasspathEntry[entries.length + 1]; 892 System.arraycopy(entries,0, newEntries,0, entries.length); 893 newEntries[entries.length] = JavaCore.newSourceEntry(folderHandle.getFullPath()); 894 javaProject.setRawClasspath(newEntries, null); 895 } 896 897 898 899 public void hotDeploy() throws CoreException { 900 String baseDir = JonasLauncherPlugin.getDefault().getBaseDir(); 901 File directoryWeb = null; 902 if (getWebdirName().trim().equals("")) 903 directoryWeb = new File (project.getDescription().getLocation().toOSString()); 904 else 905 directoryWeb = new File (getWebDirFolder().getLocation().toOSString()); 906 File directorySrc = null; 907 if (this.getSrcDir().trim().equals("")) 908 directorySrc = new File (project.getDescription().getLocation().toOSString()); 909 else 910 directorySrc = new File (getSrcDirFolder().getLocation().toOSString()); 911 912 HotDeploy hot = new HotDeploy(baseDir, new Path(directoryWeb.toString()),getWebContext()); 913 hot.copyFileByAnt(); 914 915 } 916 917 921 private boolean classesContainsJavaFiles() { 922 IFolder webinfFolder = this.getWebInfFolder(); 923 IFolder classesFolder = webinfFolder.getFolder("classes"); 924 File f = classesFolder.getLocation().toFile(); 925 926 if (!f.exists()) return false; 927 if (!f.isDirectory()) return false; 928 929 return FileUtil.dirContainsFiles(f, "java", true); 930 } 931 932 public void setCreateSamples( boolean b ) 933 { 934 createSamples = b; 935 } 936 937 public String getSrcPersistenceDir() { 938 return srcPersistenceDir; 939 } 940 public void setSrcPersistenceDir(String srcPersistenceDir) { 941 this.srcPersistenceDir = srcPersistenceDir; 942 } 943 } 944 | Popular Tags |