1 13 14 package org.eclipse.jdt.internal.ui.javadocexport; 15 16 import java.io.File ; 17 import java.io.FileOutputStream ; 18 import java.io.IOException ; 19 import java.util.ArrayList ; 20 import java.util.List ; 21 import java.util.StringTokenizer ; 22 23 import javax.xml.parsers.ParserConfigurationException ; 24 import javax.xml.transform.TransformerException ; 25 26 import org.eclipse.core.runtime.CoreException; 27 import org.eclipse.core.runtime.IAdaptable; 28 import org.eclipse.core.runtime.IPath; 29 import org.eclipse.core.runtime.IStatus; 30 import org.eclipse.core.runtime.MultiStatus; 31 import org.eclipse.core.runtime.Path; 32 import org.eclipse.core.runtime.Platform; 33 import org.eclipse.core.runtime.content.IContentType; 34 35 import org.eclipse.core.resources.IContainer; 36 import org.eclipse.core.resources.IFile; 37 import org.eclipse.core.resources.IResource; 38 import org.eclipse.core.resources.IWorkspaceRoot; 39 import org.eclipse.core.resources.ResourcesPlugin; 40 41 import org.eclipse.jface.dialogs.IDialogSettings; 42 import org.eclipse.jface.preference.IPreferenceStore; 43 44 import org.eclipse.jdt.core.ICompilationUnit; 45 import org.eclipse.jdt.core.IJavaElement; 46 import org.eclipse.jdt.core.IJavaProject; 47 import org.eclipse.jdt.core.IPackageFragment; 48 import org.eclipse.jdt.core.IPackageFragmentRoot; 49 import org.eclipse.jdt.core.JavaCore; 50 import org.eclipse.jdt.core.JavaModelException; 51 52 import org.eclipse.jdt.internal.corext.util.Messages; 53 54 import org.eclipse.jdt.launching.ExecutionArguments; 55 import org.eclipse.jdt.launching.IVMInstall; 56 import org.eclipse.jdt.launching.IVMInstallType; 57 import org.eclipse.jdt.launching.JavaRuntime; 58 59 import org.eclipse.jdt.ui.JavaUI; 60 import org.eclipse.jdt.ui.PreferenceConstants; 61 62 import org.eclipse.jdt.internal.ui.JavaPlugin; 63 import org.eclipse.jdt.internal.ui.JavaUIStatus; 64 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; 65 66 import org.w3c.dom.Element ; 67 import org.w3c.dom.Node ; 68 import org.w3c.dom.NodeList ; 69 import org.xml.sax.SAXException ; 70 71 public class JavadocOptionsManager { 72 73 private IFile fXmlfile; 74 75 private StatusInfo fWizardStatus; 76 77 private String [] fJavadocCommandHistory; 78 79 80 private IJavaElement[] fSelectedElements; 81 private IJavaElement[] fInitialElements; 82 83 private String fAccess; 84 private String fDocletpath; 85 private String fDocletname; 86 private boolean fFromStandard; 87 private String fStylesheet; 88 private String fAdditionalParams; 89 private String fVMParams; 90 private String fOverview; 91 private String fTitle; 92 93 private String [] fHRefs; 94 95 private IPath[] fSourcepath; 96 private IPath[] fClasspath; 97 98 private boolean fNotree; 99 private boolean fNoindex; 100 private boolean fSplitindex; 101 private boolean fNonavbar; 102 private boolean fNodeprecated; 103 private boolean fNoDeprecatedlist; 104 private boolean fAuthor; 105 private boolean fVersion; 106 private boolean fUse; 107 108 private String fSource; 109 110 private boolean fOpenInBrowser; 111 112 private RecentSettingsStore fRecentSettings; 113 114 private String fDestination; 116 private String fAntpath; 117 118 public final String PRIVATE= "private"; public final String PROTECTED= "protected"; public final String PACKAGE= "package"; public final String PUBLIC= "public"; 123 public final String USE= "use"; public final String NOTREE= "notree"; public final String NOINDEX= "noindex"; public final String NONAVBAR= "nonavbar"; public final String NODEPRECATED= "nodeprecated"; public final String NODEPRECATEDLIST= "nodeprecatedlist"; public final String VERSION= "version"; public final String AUTHOR= "author"; public final String SPLITINDEX= "splitindex"; public final String STYLESHEETFILE= "stylesheetfile"; public final String OVERVIEW= "overview"; public final String DOCLETNAME= "docletname"; public final String DOCLETPATH= "docletpath"; public final String SOURCEPATH= "sourcepath"; public final String CLASSPATH= "classpath"; public final String DESTINATION= "destdir"; public final String OPENINBROWSER= "openinbrowser"; 141 public final String VISIBILITY= "access"; public final String PACKAGENAMES= "packagenames"; public final String SOURCEFILES= "sourcefiles"; public final String EXTRAOPTIONS= "additionalparam"; public final String VMOPTIONS= "vmparam"; public final String TITLE= "doctitle"; public final String HREF= "href"; 150 public final String NAME= "name"; public final String PATH= "path"; public final String FROMSTANDARD= "fromStandard"; public final String ANTPATH= "antpath"; public final String SOURCE= "source"; 156 private final String SECTION_JAVADOC= "javadoc"; 158 private static final String JAVADOC_COMMAND_HISTORY= "javadoc_command_history"; 160 public JavadocOptionsManager(IFile xmlJavadocFile, IDialogSettings dialogSettings, List currSelection) { 161 fXmlfile= xmlJavadocFile; 162 fWizardStatus= new StatusInfo(); 163 164 IDialogSettings javadocSection= dialogSettings.getSection(SECTION_JAVADOC); 165 166 String commandHistory= null; 167 if (javadocSection != null) { 168 commandHistory= javadocSection.get(JAVADOC_COMMAND_HISTORY); 169 } 170 if (commandHistory == null || commandHistory.length() == 0) { 171 commandHistory= initJavadocCommandDefault(); 172 } 173 fJavadocCommandHistory= arrayFromFlatString(commandHistory); 174 175 fRecentSettings= new RecentSettingsStore(javadocSection); 176 177 if (xmlJavadocFile != null) { 178 try { 179 JavadocReader reader= new JavadocReader(xmlJavadocFile.getContents()); 180 Element element= reader.readXML(); 181 if (element != null) { 182 loadFromXML(element); 183 return; 184 } 185 fWizardStatus.setWarning(JavadocExportMessages.JavadocOptionsManager_antfileincorrectCE_warning); 186 } catch (CoreException e) { 187 JavaPlugin.log(e); 188 fWizardStatus.setWarning(JavadocExportMessages.JavadocOptionsManager_antfileincorrectCE_warning); 189 } catch (IOException e) { 190 JavaPlugin.log(e); 191 fWizardStatus.setWarning(JavadocExportMessages.JavadocOptionsManager_antfileincorrectIOE_warning); 192 } catch (SAXException e) { 193 fWizardStatus.setWarning(JavadocExportMessages.JavadocOptionsManager_antfileincorrectSAXE_warning); 194 } 195 } 196 if (javadocSection != null) { 197 loadFromDialogStore(javadocSection, currSelection); 198 } else { 199 loadDefaults(currSelection); 200 } 201 } 202 203 204 208 private IJavaProject getSingleProjectFromInitialSelection() { 209 IJavaProject res= null; 210 for (int i= 0; i < fInitialElements.length; i++) { 211 IJavaProject curr= fInitialElements[i].getJavaProject(); 212 if (res == null) { 213 res= curr; 214 } else if (!res.equals(curr)) { 215 return null; 216 } 217 } 218 if (res != null && res.isOpen()) { 219 return res; 220 } 221 return null; 222 } 223 224 225 private void loadFromDialogStore(IDialogSettings settings, List sel) { 226 fInitialElements= getInitialElementsFromSelection(sel); 227 228 IJavaProject project= getSingleProjectFromInitialSelection(); 229 230 fAccess= settings.get(VISIBILITY); 231 if (fAccess == null) 232 fAccess= PROTECTED; 233 234 fFromStandard= settings.getBoolean(FROMSTANDARD); 236 237 fDocletpath= settings.get(DOCLETPATH); 239 fDocletname= settings.get(DOCLETNAME); 240 if (fDocletpath == null || fDocletname == null) { 241 fFromStandard= true; 242 fDocletpath= ""; fDocletname= ""; } 245 246 247 if (project != null) { 248 fAntpath= getRecentSettings().getAntpath(project); 249 } else { 250 fAntpath= settings.get(ANTPATH); 251 if (fAntpath == null) { 252 fAntpath= ""; } 254 } 255 256 257 if (project != null) { 258 fDestination= getRecentSettings().getDestination(project); 259 } else { 260 fDestination= settings.get(DESTINATION); 261 if (fDestination == null) { 262 fDestination= ""; } 264 } 265 266 fTitle= settings.get(TITLE); 267 if (fTitle == null) 268 fTitle= ""; 270 fStylesheet= settings.get(STYLESHEETFILE); 271 if (fStylesheet == null) 272 fStylesheet= ""; 274 fVMParams= settings.get(VMOPTIONS); 275 if (fVMParams == null) 276 fVMParams= ""; 278 fAdditionalParams= settings.get(EXTRAOPTIONS); 279 if (fAdditionalParams == null) 280 fAdditionalParams= ""; 282 fOverview= settings.get(OVERVIEW); 283 if (fOverview == null) 284 fOverview= ""; 286 fUse= loadBoolean(settings.get(USE)); 287 fAuthor= loadBoolean(settings.get(AUTHOR)); 288 fVersion= loadBoolean(settings.get(VERSION)); 289 fNodeprecated= loadBoolean(settings.get(NODEPRECATED)); 290 fNoDeprecatedlist= loadBoolean(settings.get(NODEPRECATEDLIST)); 291 fNonavbar= loadBoolean(settings.get(NONAVBAR)); 292 fNoindex= loadBoolean(settings.get(NOINDEX)); 293 fNotree= loadBoolean(settings.get(NOTREE)); 294 fSplitindex= loadBoolean(settings.get(SPLITINDEX)); 295 fOpenInBrowser= loadBoolean(settings.get(OPENINBROWSER)); 296 297 fSource= settings.get(SOURCE); 298 if (project != null) { 299 fSource= project.getOption(JavaCore.COMPILER_SOURCE, true); 300 } 301 302 if (project != null) { 303 fHRefs= getRecentSettings().getHRefs(project); 304 } else { 305 fHRefs= new String [0]; 306 } 307 } 308 309 310 private void loadDefaults(List sel) { 312 fInitialElements= getInitialElementsFromSelection(sel); 313 314 IJavaProject project= getSingleProjectFromInitialSelection(); 315 316 if (project != null) { 317 fAntpath= getRecentSettings().getAntpath(project); 318 fDestination= getRecentSettings().getDestination(project); 319 fHRefs= getRecentSettings().getHRefs(project); 320 } else { 321 fAntpath= ""; fDestination= ""; fHRefs= new String [0]; 324 } 325 326 fAccess= PUBLIC; 327 328 fDocletname= ""; fDocletpath= ""; fTitle= ""; fStylesheet= ""; fVMParams= ""; fAdditionalParams= ""; fOverview= ""; 336 fUse= true; 337 fAuthor= true; 338 fVersion= true; 339 fNodeprecated= false; 340 fNoDeprecatedlist= false; 341 fNonavbar= false; 342 fNoindex= false; 343 fNotree= false; 344 fSplitindex= true; 345 fOpenInBrowser= false; 346 fSource= "1.3"; if (project != null) { 348 fSource= project.getOption(JavaCore.COMPILER_SOURCE, true); 349 } 350 351 fFromStandard= true; 353 } 354 355 private void loadFromXML(Element element) { 356 357 fAccess= element.getAttribute(VISIBILITY); 358 if (fAccess.length() == 0) 359 fAccess= PROTECTED; 360 361 String destination= element.getAttribute(DESTINATION); 363 fDestination= makeAbsolutePathFromRelative(new Path(destination)).toOSString(); 364 fFromStandard= true; 365 fDocletname= ""; fDocletpath= ""; 368 if (destination.length() == 0) { 369 NodeList list= element.getChildNodes(); 370 for (int i= 0; i < list.getLength(); i++) { 371 Node child= list.item(i); 372 if (child.getNodeName().equals("doclet")) { fDocletpath= ((Element) child).getAttribute(PATH); 374 fDocletname= ((Element) child).getAttribute(NAME); 375 if (fDocletpath.length() != 0 || fDocletname.length() != 0) { 376 fFromStandard= false; 377 } else { 378 fDocletname= ""; fDocletpath= ""; } 381 break; 382 } 383 } 384 } 385 386 fInitialElements= getSelectedElementsFromAnt(element); 387 388 389 NodeList children= element.getChildNodes(); 391 fHRefs= new String [children.getLength()]; 392 for (int i= 0; i < fHRefs.length; i++) { 393 Node child= children.item(i); 394 if (child.getNodeName().equals("link")) { fHRefs[i]= ((Element) child).getAttribute(HREF); 396 } 397 } 398 399 IPath p= fXmlfile.getLocation(); 401 if (p != null) 402 fAntpath= p.toOSString(); 403 else 404 fAntpath= ""; 406 fStylesheet= element.getAttribute(STYLESHEETFILE); 407 fTitle= element.getAttribute(TITLE); 408 409 410 StringBuffer additionals= new StringBuffer (); 411 StringBuffer vmargs= new StringBuffer (); 412 String extraOptions= element.getAttribute(EXTRAOPTIONS); 413 if (extraOptions.length() > 0) { 414 ExecutionArguments tokens= new ExecutionArguments("", extraOptions); String [] args= tokens.getProgramArgumentsArray(); 416 417 boolean vmarg= false; 418 for (int i= 0; i < args.length; i++) { 419 String curr= args[i]; 420 if (curr.length() > 0 && curr.charAt(0) == '-') { 421 vmarg=(curr.length() > 1 && curr.charAt(1) == 'J'); 423 } 424 if (vmarg) { 425 vmargs.append(curr).append(' '); 426 } else { 427 additionals.append(curr).append(' '); 428 } 429 } 430 } 431 432 fAdditionalParams= additionals.toString(); 433 fVMParams= vmargs.toString(); 434 fOverview= element.getAttribute(OVERVIEW); 435 436 fUse= loadBoolean(element.getAttribute(USE)); 437 fAuthor= loadBoolean(element.getAttribute(AUTHOR)); 438 fVersion= loadBoolean(element.getAttribute(VERSION)); 439 fNodeprecated= loadBoolean(element.getAttribute(NODEPRECATED)); 440 fNoDeprecatedlist= loadBoolean(element.getAttribute(NODEPRECATEDLIST)); 441 fNonavbar= loadBoolean(element.getAttribute(NONAVBAR)); 442 fNoindex= loadBoolean(element.getAttribute(NOINDEX)); 443 fNotree= loadBoolean(element.getAttribute(NOTREE)); 444 fSplitindex= loadBoolean(element.getAttribute(SPLITINDEX)); 445 446 fSource= element.getAttribute(SOURCE); 447 } 448 449 457 private IPath makeAbsolutePathFromRelative(IPath path) { 458 if (!path.isAbsolute()) { 459 if (fXmlfile == null) { 460 return null; 461 } 462 IPath basePath= fXmlfile.getParent().getLocation(); if (basePath == null) { 465 return null; 466 } 467 return basePath.append(path); 468 } 469 return path; 470 } 471 472 private IContainer[] getSourceContainers(Element element) { 473 String sourcePaths= element.getAttribute(SOURCEPATH); 474 475 if (sourcePaths.endsWith(File.pathSeparator)) { 476 sourcePaths += '.'; 477 } 478 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); 479 480 ArrayList res= new ArrayList (); 481 482 String [] strings= sourcePaths.split(File.pathSeparator); 483 for (int i= 0; i < strings.length; i++) { 484 IPath path= makeAbsolutePathFromRelative(new Path(strings[i].trim())); 485 if (path != null) { 486 IContainer[] containers= root.findContainersForLocation(path); 487 for (int k= 0; k < containers.length; k++) { 488 res.add(containers[k]); 489 } 490 } 491 492 } 493 return (IContainer[]) res.toArray(new IContainer[res.size()]); 494 } 495 496 private IJavaElement[] getSelectedElementsFromAnt(Element element) { 497 List res= new ArrayList (); 498 499 String packagenames= element.getAttribute(PACKAGENAMES); 501 if (packagenames != null) { 502 IContainer[] containers= getSourceContainers(element); 503 504 StringTokenizer tokenizer= new StringTokenizer (packagenames, ","); while (tokenizer.hasMoreTokens()) { 506 IPath relPackagePath= new Path(tokenizer.nextToken().trim().replace('.', '/')); 507 for (int i= 0; i < containers.length; i++) { 508 IContainer curr= containers[i]; 509 IResource resource= curr.findMember(relPackagePath); 510 if (resource != null) { 511 IJavaElement javaElem= JavaCore.create(resource); 512 if (javaElem instanceof IPackageFragment) { 513 res.add(javaElem); 514 } 515 } 516 } 517 } 518 } 519 520 String sourcefiles= element.getAttribute(SOURCEFILES); 522 if (sourcefiles != null) { 523 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); 524 525 StringTokenizer tokenizer= new StringTokenizer (sourcefiles, ","); while (tokenizer.hasMoreTokens()) { 527 String name= tokenizer.nextToken().trim(); 528 if (JavaCore.isJavaLikeFileName(name)) { 529 IPath path= makeAbsolutePathFromRelative(new Path(name)); 530 if (path != null) { 532 IFile[] files= root.findFilesForLocation(path); 533 for (int i= 0; i < files.length; i++) { 534 IJavaElement el= JavaCore.createCompilationUnitFrom(files[i]); 535 if (el != null) { 536 res.add(el); 537 } 538 } 539 } 540 } 541 } 542 } 543 return (IJavaElement[]) res.toArray(new IJavaElement[res.size()]); 544 } 545 546 549 public String [] getJavadocCommandHistory() { 550 return fJavadocCommandHistory; 551 } 552 553 554 public StatusInfo getWizardStatus() { 556 return fWizardStatus; 557 } 558 559 public IJavaElement[] getInitialElements() { 560 return fInitialElements; 561 } 562 563 public IJavaElement[] getSourceElements() { 564 return fSelectedElements; 565 } 566 567 public String getAccess() { 568 return fAccess; 569 } 570 571 public String getAntpath() { 572 return fAntpath; 573 } 574 575 public boolean isFromStandard() { 576 return fFromStandard; 577 } 578 579 public String getDestination() { 580 return fDestination; 581 } 582 583 public String getDocletPath() { 584 return fDocletpath; 585 } 586 587 public String getDocletName() { 588 return fDocletname; 589 } 590 591 public String getStyleSheet() { 592 return fStylesheet; 593 } 594 595 public String getOverview() { 596 return fOverview; 597 } 598 599 public String getAdditionalParams() { 600 return fAdditionalParams; 601 } 602 603 public String getVMParams() { 604 return fVMParams; 605 } 606 607 public IPath[] getClasspath() { 608 return fClasspath; 609 } 610 611 public IPath[] getSourcepath() { 612 return fSourcepath; 613 } 614 615 public String getTitle() { 616 return fTitle; 617 } 618 619 public boolean doOpenInBrowser() { 620 return fOpenInBrowser; 621 } 622 623 public String [] getHRefs() { 624 return fHRefs; 625 } 626 627 public boolean getBoolean(String flag) { 628 629 if (flag.equals(AUTHOR)) 630 return fAuthor; 631 else if (flag.equals(VERSION)) 632 return fVersion; 633 else if (flag.equals(USE)) 634 return fUse; 635 else if (flag.equals(NODEPRECATED)) 636 return fNodeprecated; 637 else if (flag.equals(NODEPRECATEDLIST)) 638 return fNoDeprecatedlist; 639 else if (flag.equals(NOINDEX)) 640 return fNoindex; 641 else if (flag.equals(NOTREE)) 642 return fNotree; 643 else if (flag.equals(SPLITINDEX)) 644 return fSplitindex; 645 else if (flag.equals(NONAVBAR)) 646 return fNonavbar; 647 else 648 return false; 649 } 650 651 private boolean loadBoolean(String value) { 652 653 if (value == null || value.length() == 0) 654 return false; 655 else { 656 if (value.equals("true")) return true; 658 else 659 return false; 660 } 661 } 662 663 private String flatPathList(IPath[] paths) { 664 StringBuffer buf= new StringBuffer (); 665 for (int i= 0; i < paths.length; i++) { 666 if (i > 0) { 667 buf.append(File.pathSeparatorChar); 668 } 669 buf.append(paths[i].toOSString()); 670 } 671 return buf.toString(); 672 } 673 674 private String flatStringList(String [] paths) { 675 StringBuffer buf= new StringBuffer (); 676 for (int i= 0; i < paths.length; i++) { 677 if (i > 0) { 678 buf.append(File.pathSeparatorChar); 679 } 680 buf.append(paths[i]); 681 } 682 return buf.toString(); 683 } 684 685 private String [] arrayFromFlatString(String str) { 686 StringTokenizer tok= new StringTokenizer (str, File.pathSeparator); 687 String [] res= new String [tok.countTokens()]; 688 for (int i= 0; i < res.length; i++) { 689 res[i]= tok.nextToken(); 690 } 691 return res; 692 } 693 694 695 public IStatus getArgumentArray(List vmArgs, List toolArgs) { 696 MultiStatus status= new MultiStatus(JavaUI.ID_PLUGIN, IStatus.OK, JavadocExportMessages.JavadocOptionsManager_status_title, null); 697 698 vmArgs.add(getJavadocCommandHistory()[0]); 700 701 if (fFromStandard) { 702 toolArgs.add("-d"); toolArgs.add(fDestination); 704 } else { 705 toolArgs.add("-doclet"); toolArgs.add(fDocletname); 707 toolArgs.add("-docletpath"); toolArgs.add(fDocletpath); 709 } 710 711 if (fSourcepath.length > 0) { 712 toolArgs.add("-sourcepath"); toolArgs.add(flatPathList(fSourcepath)); 714 } 715 716 if (fClasspath.length > 0) { 717 toolArgs.add("-classpath"); toolArgs.add(flatPathList(fClasspath)); 719 } 720 toolArgs.add("-" + fAccess); 722 if (fFromStandard) { 723 if (fSource.length() > 0 && !fSource.equals("-")) { toolArgs.add("-source"); toolArgs.add(fSource); 726 } 727 728 if (fUse) 729 toolArgs.add("-use"); if (fVersion) 731 toolArgs.add("-version"); if (fAuthor) 733 toolArgs.add("-author"); if (fNonavbar) 735 toolArgs.add("-nonavbar"); if (fNoindex) 737 toolArgs.add("-noindex"); if (fNotree) 739 toolArgs.add("-notree"); if (fNodeprecated) 741 toolArgs.add("-nodeprecated"); if (fNoDeprecatedlist) 743 toolArgs.add("-nodeprecatedlist"); if (fSplitindex) 745 toolArgs.add("-splitindex"); 747 if (fTitle.length() != 0) { 748 toolArgs.add("-doctitle"); toolArgs.add(fTitle); 750 } 751 752 753 if (fStylesheet.length() != 0) { 754 toolArgs.add("-stylesheetfile"); toolArgs.add(fStylesheet); 756 } 757 758 for (int i= 0; i < fHRefs.length; i++) { 759 toolArgs.add("-link"); toolArgs.add(fHRefs[i]); 761 } 762 763 } 765 if (fAdditionalParams.length() + fVMParams.length() != 0) { 766 ExecutionArguments tokens= new ExecutionArguments(fVMParams, fAdditionalParams); 767 String [] vmArgsArray= tokens.getVMArgumentsArray(); 768 for (int i= 0; i < vmArgsArray.length; i++) { 769 vmArgs.add(vmArgsArray[i]); 770 } 771 String [] argsArray= tokens.getProgramArgumentsArray(); 772 for (int i= 0; i < argsArray.length; i++) { 773 toolArgs.add(argsArray[i]); 774 } 775 } 776 addProxyOptions(vmArgs); 777 778 if (fOverview.length() != 0) { 779 toolArgs.add("-overview"); toolArgs.add(fOverview); 781 } 782 783 for (int i= 0; i < fSelectedElements.length; i++) { 784 IJavaElement curr= fSelectedElements[i]; 785 if (curr instanceof IPackageFragment) { 786 toolArgs.add(curr.getElementName()); 787 } else if (curr instanceof ICompilationUnit) { 788 IPath p= curr.getResource().getLocation(); 791 if (p != null) { 792 toolArgs.add(p.toOSString()); 793 } else { 794 String message= JavadocExportMessages.JavadocOptionsManager_status_non_local; 795 status.add(new StatusInfo(IStatus.WARNING, Messages.format(message, curr.getPath().makeRelative().toString()))); 796 } 797 } 798 } 799 return status; 800 } 801 802 private void addProxyOptions(List vmOptions) { 803 String hostPrefix= "-J-Dhttp.proxyHost="; String portPrefix= "-J-Dhttp.proxyPort="; for (int i= 0; i < vmOptions.size(); i++) { 807 String curr= (String ) vmOptions.get(i); 808 if (curr.startsWith(hostPrefix) || curr.startsWith(portPrefix)) { 809 return; 810 } 811 } 812 String proxyHost= System.getProperty("http.proxyHost"); if (proxyHost != null) { 814 vmOptions.add(hostPrefix + proxyHost); 815 } 816 817 String proxyPort= System.getProperty("http.proxyPort"); if (proxyPort != null) { 819 vmOptions.add(portPrefix + proxyPort); 820 } 821 } 822 823 824 public File createXML(IJavaProject[] projects) throws CoreException { 825 FileOutputStream objectStreamOutput= null; 826 try { 829 if (fAntpath.length() > 0) { 830 File file= new File (fAntpath); 831 832 String encoding= "UTF-8"; IContentType type= Platform.getContentTypeManager().getContentType("org.eclipse.ant.core.antBuildFile"); if (type != null) 835 encoding= type.getDefaultCharset(); 836 IPath filePath= Path.fromOSString(fAntpath); 837 IPath directoryPath= filePath.removeLastSegments(1); 838 839 IPath basePath= null; 840 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); 841 if (root.findFilesForLocation(filePath).length > 0) { 842 basePath= directoryPath; } 844 845 directoryPath.toFile().mkdirs(); 846 847 objectStreamOutput= new FileOutputStream (file); 848 JavadocWriter writer= new JavadocWriter(objectStreamOutput, encoding, basePath, projects); 849 writer.writeXML(this); 850 return file; 851 } 852 } catch (IOException e) { 853 String message= JavadocExportMessages.JavadocOptionsManager_createXM_error; 854 throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, message, e)); 855 } catch (ParserConfigurationException e) { 856 String message= JavadocExportMessages.JavadocOptionsManager_createXM_error; 857 throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, message, e)); 858 } catch (TransformerException e) { 859 String message= JavadocExportMessages.JavadocOptionsManager_createXM_error; 860 throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, message, e)); 861 } finally { 862 if (objectStreamOutput != null) { 863 try { 864 objectStreamOutput.close(); 865 } catch (IOException e) { 866 } 867 } 868 } 869 return null; 870 } 871 872 public void updateDialogSettings(IDialogSettings dialogSettings, IJavaProject[] checkedProjects) { 873 IDialogSettings settings= dialogSettings.addNewSection(SECTION_JAVADOC); 874 875 settings.put(JAVADOC_COMMAND_HISTORY, flatStringList(fJavadocCommandHistory)); 876 if (fJavadocCommandHistory.length > 0) { 877 IPreferenceStore store= PreferenceConstants.getPreferenceStore(); 878 store.setValue(PreferenceConstants.JAVADOC_COMMAND, fJavadocCommandHistory[0]); 879 } 880 881 882 settings.put(FROMSTANDARD, fFromStandard); 883 884 settings.put(DOCLETNAME, fDocletname); 885 settings.put(DOCLETPATH, fDocletpath); 886 887 settings.put(VISIBILITY, fAccess); 888 889 settings.put(USE, fUse); 890 settings.put(AUTHOR, fAuthor); 891 settings.put(VERSION, fVersion); 892 settings.put(NODEPRECATED, fNodeprecated); 893 settings.put(NODEPRECATEDLIST, fNoDeprecatedlist); 894 settings.put(SPLITINDEX, fSplitindex); 895 settings.put(NOINDEX, fNoindex); 896 settings.put(NOTREE, fNotree); 897 settings.put(NONAVBAR, fNonavbar); 898 settings.put(OPENINBROWSER, fOpenInBrowser); 899 settings.put(SOURCE, fSource); 900 901 if (fAntpath.length() != 0) 902 settings.put(ANTPATH, fAntpath); 903 if (fDestination.length() != 0) 904 settings.put(DESTINATION, fDestination); 905 if (fAdditionalParams.length() != 0) 906 settings.put(EXTRAOPTIONS, fAdditionalParams); 907 if (fVMParams.length() != 0) 908 settings.put(VMOPTIONS, fVMParams); 909 if (fOverview.length() != 0) 910 settings.put(OVERVIEW, fOverview); 911 if (fStylesheet.length() != 0) 912 settings.put(STYLESHEETFILE, fStylesheet); 913 if (fTitle.length() != 0) 914 settings.put(TITLE, fTitle); 915 916 if (checkedProjects.length == 1) { 917 updateRecentSettings(checkedProjects[0]); 918 } 919 getRecentSettings().store(settings); 920 } 921 922 public void setJavadocCommandHistory(String [] javadocCommandHistory) { 923 fJavadocCommandHistory= javadocCommandHistory; 924 } 925 926 public void setAccess(String access) { 927 fAccess= access; 928 } 929 public void setDestination(String destination) { 930 fDestination= destination; 931 } 932 933 public void setDocletPath(String docletpath) { 934 fDocletpath= docletpath; 935 } 936 937 public void setDocletName(String docletname) { 938 fDocletname= docletname; 939 } 940 941 public void setStyleSheet(String stylesheet) { 942 fStylesheet= stylesheet; 943 } 944 945 public void setOverview(String overview) { 946 fOverview= overview; 947 } 948 949 public void setAdditionalParams(String params) { 950 fAdditionalParams= params; 951 } 952 953 public void setVMParams(String params) { 954 fVMParams= params; 955 } 956 957 public void setGeneralAntpath(String antpath) { 958 fAntpath= antpath; 959 } 960 public void setClasspath(IPath[] classpath) { 961 fClasspath= classpath; 962 } 963 964 public void setSourcepath(IPath[] sourcepath) { 965 fSourcepath= sourcepath; 966 } 967 968 public void setSelectedElements(IJavaElement[] elements) { 969 fSelectedElements= elements; 970 } 971 972 public void setFromStandard(boolean fromStandard) { 973 fFromStandard= fromStandard; 974 } 975 976 public void setTitle(String title) { 977 fTitle= title; 978 } 979 980 public void setOpenInBrowser(boolean openInBrowser) { 981 fOpenInBrowser= openInBrowser; 982 } 983 984 public void setHRefs(String [] hrefs) { 985 fHRefs= hrefs; 986 } 987 988 public void setBoolean(String flag, boolean value) { 989 990 if (flag.equals(AUTHOR)) 991 fAuthor= value; 992 else if (flag.equals(USE)) 993 fUse= value; 994 else if (flag.equals(VERSION)) 995 fVersion= value; 996 else if (flag.equals(NODEPRECATED)) 997 fNodeprecated= value; 998 else if (flag.equals(NODEPRECATEDLIST)) 999 fNoDeprecatedlist= value; 1000 else if (flag.equals(NOINDEX)) 1001 fNoindex= value; 1002 else if (flag.equals(NOTREE)) 1003 fNotree= value; 1004 else if (flag.equals(SPLITINDEX)) 1005 fSplitindex= value; 1006 else if (flag.equals(NONAVBAR)) 1007 fNonavbar= value; 1008 } 1009 1010 public void setSource(String source) { 1011 fSource= source; 1012 } 1013 1014 public String getSource() { 1015 return fSource; 1016 } 1017 1018 private IJavaElement[] getInitialElementsFromSelection(List candidates) { 1019 ArrayList res= new ArrayList (); 1020 for (int i= 0; i < candidates.size(); i++) { 1021 try { 1022 IJavaElement elem= getSelectableJavaElement(candidates.get(i)); 1023 if (elem != null) { 1024 res.add(elem); 1025 } 1026 } catch (JavaModelException ignore) { 1027 } 1029 } 1030 return (IJavaElement[]) res.toArray(new IJavaElement[res.size()]); 1031 } 1032 1033 private IJavaElement getSelectableJavaElement(Object obj) throws JavaModelException { 1034 IJavaElement je= null; 1035 if (obj instanceof IAdaptable) { 1036 je= (IJavaElement) ((IAdaptable) obj).getAdapter(IJavaElement.class); 1037 } 1038 1039 if (je != null) { 1040 switch (je.getElementType()) { 1041 case IJavaElement.JAVA_MODEL : 1042 case IJavaElement.JAVA_PROJECT : 1043 case IJavaElement.CLASS_FILE : 1044 break; 1045 case IJavaElement.PACKAGE_FRAGMENT_ROOT : 1046 if (containsCompilationUnits((IPackageFragmentRoot) je)) { 1047 return je; 1048 } 1049 break; 1050 case IJavaElement.PACKAGE_FRAGMENT : 1051 if (containsCompilationUnits((IPackageFragment) je)) { 1052 return je; 1053 } 1054 break; 1055 default : 1056 ICompilationUnit cu= (ICompilationUnit) je.getAncestor(IJavaElement.COMPILATION_UNIT); 1057 if (cu != null) { 1058 return cu; 1059 } 1060 } 1061 IJavaProject project= je.getJavaProject(); 1062 if (isValidProject(project)) 1063 return project; 1064 } 1065 1066 return null; 1067 } 1068 1069 private boolean isValidProject(IJavaProject project) throws JavaModelException { 1070 if (project != null && project.exists() && project.isOpen()) { 1071 return true; 1072 } 1073 return false; 1074 } 1075 1076 private boolean containsCompilationUnits(IPackageFragmentRoot root) throws JavaModelException { 1077 if (root.getKind() != IPackageFragmentRoot.K_SOURCE) { 1078 return false; 1079 } 1080 1081 IJavaElement[] elements= root.getChildren(); 1082 for (int i= 0; i < elements.length; i++) { 1083 if (elements[i] instanceof IPackageFragment) { 1084 IPackageFragment fragment= (IPackageFragment) elements[i]; 1085 if (containsCompilationUnits(fragment)) { 1086 return true; 1087 } 1088 } 1089 } 1090 return false; 1091 } 1092 1093 private boolean containsCompilationUnits(IPackageFragment pack) throws JavaModelException { 1094 return pack.getCompilationUnits().length > 0; 1095 } 1096 1097 public RecentSettingsStore getRecentSettings() { 1098 return fRecentSettings; 1099 } 1100 1101 1104 public void updateRecentSettings(IJavaProject project) { 1105 fRecentSettings.setProjectSettings(project, fDestination, fAntpath, fHRefs); 1106 } 1107 1108 1109 private static String initJavadocCommandDefault() { 1110 IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); 1111 String cmd= store.getString(PreferenceConstants.JAVADOC_COMMAND); if (cmd != null && cmd.length() > 0) { 1113 store.setToDefault(PreferenceConstants.JAVADOC_COMMAND); 1114 return cmd; 1115 } 1116 1117 File file= findJavaDocCommand(); 1118 if (file != null) { 1119 return file.getPath(); 1120 } 1121 return ""; } 1123 1124 1125 private static File findJavaDocCommand() { 1126 IVMInstall install= JavaRuntime.getDefaultVMInstall(); 1127 if (install != null) { 1128 File res= getCommand(install); 1129 if (res != null) { 1130 return res; 1131 } 1132 } 1133 1134 IVMInstallType[] jreTypes= JavaRuntime.getVMInstallTypes(); 1135 for (int i= 0; i < jreTypes.length; i++) { 1136 IVMInstallType jreType= jreTypes[i]; 1137 IVMInstall[] installs= jreType.getVMInstalls(); 1138 for (int k= 0; k < installs.length; k++) { 1139 File res= getCommand(installs[k]); 1140 if (res != null) { 1141 return res; 1142 } 1143 } 1144 } 1145 return null; 1146 } 1147 1148 private static File getCommand(IVMInstall install) { 1149 File installLocation= install.getInstallLocation(); 1150 if (installLocation != null) { 1151 File javaDocCommand= new File (installLocation, "bin/javadoc"); if (javaDocCommand.isFile()) { 1153 return javaDocCommand; 1154 } 1155 javaDocCommand= new File (installLocation, "bin/javadoc.exe"); if (javaDocCommand.isFile()) { 1157 return javaDocCommand; 1158 } 1159 } 1160 return null; 1161 } 1162 1163 1164 1165 1166} 1167 | Popular Tags |