]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/javadocexport/JavadocOptionsManager.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / javadocexport / JavadocOptionsManager.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Sebastian Davids, sdavids@gmx.de, - bug 38692
11 * Matt Chapman, mpchapman@gmail.com - 89977 Make JDT .java agnostic
12 *******************************************************************************/
13package org.eclipse.jdt.internal.ui.javadocexport;
14
15import java.io.File;
16import java.io.FileOutputStream;
17import java.io.IOException;
18import java.net.MalformedURLException;
19import java.net.URL;
20import java.util.ArrayList;
21import java.util.List;
22import java.util.StringTokenizer;
23
24import javax.xml.parsers.ParserConfigurationException;
25import javax.xml.transform.TransformerException;
26
27import org.w3c.dom.Document;
28import org.w3c.dom.Element;
29import org.w3c.dom.Node;
30import org.w3c.dom.NodeList;
31
32import org.eclipse.swt.events.SelectionAdapter;
33import org.eclipse.swt.events.SelectionEvent;
34import org.eclipse.swt.widgets.Button;
35
36import org.eclipse.core.filesystem.URIUtil;
37
38import org.eclipse.core.runtime.CoreException;
39import org.eclipse.core.runtime.IAdaptable;
40import org.eclipse.core.runtime.IPath;
41import org.eclipse.core.runtime.IStatus;
42import org.eclipse.core.runtime.MultiStatus;
43import org.eclipse.core.runtime.Path;
44import org.eclipse.core.runtime.Platform;
45import org.eclipse.core.runtime.content.IContentType;
46
47import org.eclipse.core.resources.IContainer;
48import org.eclipse.core.resources.IFile;
49import org.eclipse.core.resources.IResource;
50import org.eclipse.core.resources.IWorkspaceRoot;
51import org.eclipse.core.resources.ResourcesPlugin;
52
53import org.eclipse.jface.dialogs.IDialogConstants;
54import org.eclipse.jface.dialogs.IDialogSettings;
55import org.eclipse.jface.dialogs.MessageDialog;
56import org.eclipse.jface.preference.IPreferenceStore;
57
58import org.eclipse.jdt.core.ICompilationUnit;
59import org.eclipse.jdt.core.IJavaElement;
60import org.eclipse.jdt.core.IJavaProject;
61import org.eclipse.jdt.core.IPackageFragment;
62import org.eclipse.jdt.core.IPackageFragmentRoot;
63import org.eclipse.jdt.core.JavaCore;
64import org.eclipse.jdt.core.JavaModelException;
65
66import org.eclipse.jdt.internal.corext.util.Messages;
67
68import org.eclipse.jdt.launching.ExecutionArguments;
69import org.eclipse.jdt.launching.IVMInstall;
70import org.eclipse.jdt.launching.IVMInstallType;
71import org.eclipse.jdt.launching.JavaRuntime;
72
73import org.eclipse.jdt.ui.JavaUI;
74import org.eclipse.jdt.ui.PreferenceConstants;
75import org.eclipse.jdt.ui.refactoring.RefactoringSaveHelper;
76
77import org.eclipse.jdt.internal.ui.JavaPlugin;
78import org.eclipse.jdt.internal.ui.JavaUIStatus;
79import org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog;
80import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
81import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
82import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
83
84
85public class JavadocOptionsManager {
86
87 private IFile fXmlfile;
88
89 public StatusInfo fWizardStatus;
90
91 public String[] fJavadocCommandHistory;
92
93
94 private IJavaElement[] fSelectedElements;
95 private IJavaElement[] fInitialElements;
96
97 private String fAccess;
98 private String fDocletpath;
99 private String fDocletname;
100 private boolean fFromStandard;
101 private String fStylesheet;
102 private String fAdditionalParams;
103 private String fVMParams;
104 private String fOverview;
105 private String fTitle;
106
107 private String[] fHRefs;
108
109 private IPath[] fSourcepath;
110 private IPath[] fClasspath;
111
112 private boolean fNotree;
113 private boolean fNoindex;
114 private boolean fSplitindex;
115 private boolean fNonavbar;
116 private boolean fNodeprecated;
117 private boolean fNoDeprecatedlist;
118 private boolean fAuthor;
119 private boolean fVersion;
120 private boolean fUse;
121
122 private String fSource;
123
124 private boolean fOpenInBrowser;
125
126 public RecentSettingsStore fRecentSettings;
127
128 //add-on for multi-project version
129 private String fDestination;
130 private String fAntpath;
131
132 public final String PRIVATE= "private"; //$NON-NLS-1$
133 public final String PROTECTED= "protected"; //$NON-NLS-1$
134 public final String PACKAGE= "package"; //$NON-NLS-1$
135 public final String PUBLIC= "public"; //$NON-NLS-1$
136
137 public final String USE= "use"; //$NON-NLS-1$
138 public final String NOTREE= "notree"; //$NON-NLS-1$
139 public final String NOINDEX= "noindex"; //$NON-NLS-1$
140 public final String NONAVBAR= "nonavbar"; //$NON-NLS-1$
141 public final String NODEPRECATED= "nodeprecated"; //$NON-NLS-1$
142 public final String NODEPRECATEDLIST= "nodeprecatedlist"; //$NON-NLS-1$
143 public final String VERSION= "version"; //$NON-NLS-1$
144 public final String AUTHOR= "author"; //$NON-NLS-1$
145 public final String SPLITINDEX= "splitindex"; //$NON-NLS-1$
146 public final String STYLESHEETFILE= "stylesheetfile"; //$NON-NLS-1$
147 public final String OVERVIEW= "overview"; //$NON-NLS-1$
148 public final String DOCLETNAME= "docletname"; //$NON-NLS-1$
149 public final String DOCLETPATH= "docletpath"; //$NON-NLS-1$
150 public final String SOURCEPATH= "sourcepath"; //$NON-NLS-1$
151 public final String CLASSPATH= "classpath"; //$NON-NLS-1$
152 public final String DESTINATION= "destdir"; //$NON-NLS-1$
153 public final String OPENINBROWSER= "openinbrowser"; //$NON-NLS-1$
154
155 public final String VISIBILITY= "access"; //$NON-NLS-1$
156 public final String PACKAGENAMES= "packagenames"; //$NON-NLS-1$
157 public final String SOURCEFILES= "sourcefiles"; //$NON-NLS-1$
158 public final String EXTRAOPTIONS= "additionalparam"; //$NON-NLS-1$
159 public final String VMOPTIONS= "vmparam"; //$NON-NLS-1$
160 //public final String JAVADOCCOMMAND= "javadoccommand"; //$NON-NLS-1$
161 public final String TITLE= "doctitle"; //$NON-NLS-1$
162 public final String HREF= "href"; //$NON-NLS-1$
163
164 public final String NAME= "name"; //$NON-NLS-1$
165 public final String PATH= "path"; //$NON-NLS-1$
166 public final String FROMSTANDARD= "fromStandard"; //$NON-NLS-1$
167 public final String ANTPATH= "antpath"; //$NON-NLS-1$
168 public final String SOURCE= "source"; //$NON-NLS-1$
169
170 private final String SECTION_JAVADOC= "javadoc"; //$NON-NLS-1$
171
172 private static final String JAVADOC_COMMAND_HISTORY= "javadoc_command_history"; //$NON-NLS-1$
173
174 public JavadocOptionsManager(IFile xmlJavadocFile, IDialogSettings dialogSettings, List<?> currSelection) {
175 fXmlfile= xmlJavadocFile;
176 fWizardStatus= new StatusInfo();
177
178 IDialogSettings javadocSection= dialogSettings.getSection(SECTION_JAVADOC);
179
180 String commandHistory= null;
181 if (javadocSection != null) {
182 commandHistory= javadocSection.get(JAVADOC_COMMAND_HISTORY);
183 }
184 fWizardStatus.generated_7526970014727274382(this, xmlJavadocFile, currSelection, javadocSection, commandHistory);
185 }
186
187
188 /*
189 * Returns the Java project that is parent top all selected elements or null if
190 * the elements are from several projects.
191 */
192 private IJavaProject getSingleProjectFromInitialSelection() {
193 IJavaProject res= null;
194 for (int i= 0; i < fInitialElements.length; i++) {
195 IJavaProject curr= fInitialElements[i].getJavaProject();
196 if (res == null) {
197 res= curr;
198 } else if (!res.equals(curr)) {
199 return null;
200 }
201 }
202 if (res != null && res.isOpen()) {
203 return res;
204 }
205 return null;
206 }
207
208
209 public void loadFromDialogStore(IDialogSettings settings, List<?> sel) {
210 fInitialElements= getInitialElementsFromSelection(sel);
211
212 IJavaProject project= getSingleProjectFromInitialSelection();
213
214 fAccess= settings.get(VISIBILITY);
215 if (fAccess == null)
216 fAccess= PROTECTED;
217
218 //this is defaulted to false.
219 fFromStandard= settings.getBoolean(FROMSTANDARD);
220
221 //doclet is loaded even if the standard doclet is being used
222 fDocletpath= settings.get(DOCLETPATH);
223 fDocletname= settings.get(DOCLETNAME);
224 if (fDocletpath == null || fDocletname == null) {
225 fFromStandard= true;
226 fDocletpath= ""; //$NON-NLS-1$
227 fDocletname= ""; //$NON-NLS-1$
228 }
229
230
231 if (project != null) {
232 fAntpath= getRecentSettings().getAntpath(project);
233 } else {
234 fAntpath= settings.get(ANTPATH);
235 if (fAntpath == null) {
236 fAntpath= ""; //$NON-NLS-1$
237 }
238 }
239
240
241 if (project != null) {
242 fDestination= getRecentSettings().getDestination(project);
243 } else {
244 fDestination= settings.get(DESTINATION);
245 if (fDestination == null) {
246 fDestination= ""; //$NON-NLS-1$
247 }
248 }
249
250 fTitle= settings.get(TITLE);
251 if (fTitle == null)
252 fTitle= ""; //$NON-NLS-1$
253
254 fStylesheet= settings.get(STYLESHEETFILE);
255 if (fStylesheet == null)
256 fStylesheet= ""; //$NON-NLS-1$
257
258 fVMParams= settings.get(VMOPTIONS);
259 if (fVMParams == null)
260 fVMParams= ""; //$NON-NLS-1$
261
262 fAdditionalParams= settings.get(EXTRAOPTIONS);
263 if (fAdditionalParams == null)
264 fAdditionalParams= ""; //$NON-NLS-1$
265
266 fOverview= settings.get(OVERVIEW);
267 if (fOverview == null)
268 fOverview= ""; //$NON-NLS-1$
269
270 fUse= loadBoolean(settings.get(USE));
271 fAuthor= loadBoolean(settings.get(AUTHOR));
272 fVersion= loadBoolean(settings.get(VERSION));
273 fNodeprecated= loadBoolean(settings.get(NODEPRECATED));
274 fNoDeprecatedlist= loadBoolean(settings.get(NODEPRECATEDLIST));
275 fNonavbar= loadBoolean(settings.get(NONAVBAR));
276 fNoindex= loadBoolean(settings.get(NOINDEX));
277 fNotree= loadBoolean(settings.get(NOTREE));
278 fSplitindex= loadBoolean(settings.get(SPLITINDEX));
279 fOpenInBrowser= loadBoolean(settings.get(OPENINBROWSER));
280
281 fSource= settings.get(SOURCE);
282 if (project != null) {
283 fSource= project.getOption(JavaCore.COMPILER_SOURCE, true);
284 }
285
286 if (project != null) {
287 fHRefs= getRecentSettings().getHRefs(project);
288 } else {
289 fHRefs= new String[0];
290 }
291 }
292
293
294 //loads defaults for wizard (nothing is stored)
295 public void loadDefaults(List<?> sel) {
296 fInitialElements= getInitialElementsFromSelection(sel);
297
298 IJavaProject project= getSingleProjectFromInitialSelection();
299
300 if (project != null) {
301 fAntpath= getRecentSettings().getAntpath(project);
302 fDestination= getRecentSettings().getDestination(project);
303 fHRefs= getRecentSettings().getHRefs(project);
304 } else {
305 fAntpath= ""; //$NON-NLS-1$
306 fDestination= ""; //$NON-NLS-1$
307 fHRefs= new String[0];
308 }
309
310 fAccess= PUBLIC;
311
312 fDocletname= ""; //$NON-NLS-1$
313 fDocletpath= ""; //$NON-NLS-1$
314 fTitle= ""; //$NON-NLS-1$
315 fStylesheet= ""; //$NON-NLS-1$
316 fVMParams= ""; //$NON-NLS-1$
317 fAdditionalParams= ""; //$NON-NLS-1$
318 fOverview= ""; //$NON-NLS-1$
319
320 fUse= true;
321 fAuthor= true;
322 fVersion= true;
323 fNodeprecated= false;
324 fNoDeprecatedlist= false;
325 fNonavbar= false;
326 fNoindex= false;
327 fNotree= false;
328 fSplitindex= true;
329 fOpenInBrowser= false;
330 fSource= "1.3"; //$NON-NLS-1$
331 if (project != null) {
332 fSource= project.getOption(JavaCore.COMPILER_SOURCE, true);
333 }
334
335 //by default it is empty all project map to the empty string
336 fFromStandard= true;
337 }
338
339 public void loadFromXML(Element element) {
340
341 fAccess= element.getAttribute(VISIBILITY);
342 if (fAccess.length() == 0)
343 fAccess= PROTECTED;
344
345 //Since the selected packages are stored we must locate the project
346 String destination= element.getAttribute(DESTINATION);
347 fDestination= makeAbsolutePathFromRelative(new Path(destination)).toOSString();
348 fFromStandard= true;
349 fDocletname= ""; //$NON-NLS-1$
350 fDocletpath= ""; //$NON-NLS-1$
351
352 if (destination.length() == 0) {
353 NodeList list= element.getChildNodes();
354 for (int i= 0; i < list.getLength(); i++) {
355 Node child= list.item(i);
356 if (child.getNodeName().equals("doclet")) { //$NON-NLS-1$
357 fDocletpath= ((Element) child).getAttribute(PATH);
358 fDocletname= ((Element) child).getAttribute(NAME);
359 if (fDocletpath.length() != 0 || fDocletname.length() != 0) {
360 fFromStandard= false;
361 } else {
362 fDocletname= ""; //$NON-NLS-1$
363 fDocletpath= ""; //$NON-NLS-1$
364 }
365 break;
366 }
367 }
368 }
369
370 fInitialElements= getSelectedElementsFromAnt(element);
371
372
373 //find all the links stored in the ant script
374 NodeList children= element.getChildNodes();
375 fHRefs= new String[children.getLength()];
376 for (int i= 0; i < fHRefs.length; i++) {
377 Node child= children.item(i);
378 if (child.getNodeName().equals("link")) { //$NON-NLS-1$
379 fHRefs[i]= ((Element) child).getAttribute(HREF);
380 }
381 }
382
383 // The ant file for generating the Javadoc is always local.
384 IPath p= fXmlfile.getLocation();
385 if (p != null)
386 fAntpath= p.toOSString();
387 else
388 fAntpath= ""; //$NON-NLS-1$
389
390 fStylesheet= element.getAttribute(STYLESHEETFILE);
391 fTitle= element.getAttribute(TITLE);
392
393
394 StringBuffer additionals= new StringBuffer();
395 StringBuffer vmargs= new StringBuffer();
396 String extraOptions= element.getAttribute(EXTRAOPTIONS);
397 if (extraOptions.length() > 0) {
398 ExecutionArguments tokens= new ExecutionArguments("", extraOptions); //$NON-NLS-1$
399 String[] args= tokens.getProgramArgumentsArray();
400
401 boolean vmarg= false;
402 for (int i= 0; i < args.length; i++) {
403 String curr= args[i];
404 if (curr.length() > 0 && curr.charAt(0) == '-') {
405 // an command
406 vmarg=(curr.length() > 1 && curr.charAt(1) == 'J');
407 }
408 if (vmarg) {
409 vmargs.append(curr).append(' ');
410 } else {
411 additionals.append(curr).append(' ');
412 }
413 }
414 }
415
416 fAdditionalParams= additionals.toString();
417 fVMParams= vmargs.toString();
418 fOverview= element.getAttribute(OVERVIEW);
419
420 fUse= loadBoolean(element.getAttribute(USE));
421 fAuthor= loadBoolean(element.getAttribute(AUTHOR));
422 fVersion= loadBoolean(element.getAttribute(VERSION));
423 fNodeprecated= loadBoolean(element.getAttribute(NODEPRECATED));
424 fNoDeprecatedlist= loadBoolean(element.getAttribute(NODEPRECATEDLIST));
425 fNonavbar= loadBoolean(element.getAttribute(NONAVBAR));
426 fNoindex= loadBoolean(element.getAttribute(NOINDEX));
427 fNotree= loadBoolean(element.getAttribute(NOTREE));
428 fSplitindex= loadBoolean(element.getAttribute(SPLITINDEX));
429
430 fSource= element.getAttribute(SOURCE);
431 }
432
433 /*
434 * Method creates an absolute path to the project. If the path is already
435 * absolute it returns the path. If it encounters any difficulties in
436 * creating the absolute path, the method returns null.
437 *
438 * @param path
439 * @return IPath
440 */
441 private IPath makeAbsolutePathFromRelative(IPath path) {
442 if (!path.isAbsolute()) {
443 if (fXmlfile == null) {
444 return null;
445 }
446 // The XML file is always local. So ok to use getLocation here
447 IPath basePath= fXmlfile.getParent().getLocation(); // relative to the ant file location
448 if (basePath == null) {
449 return null;
450 }
451 return basePath.append(path);
452 }
453 return path;
454 }
455
456 private IContainer[] getSourceContainers(Element element) {
457 String sourcePaths= element.getAttribute(SOURCEPATH);
458
459 if (sourcePaths.endsWith(File.pathSeparator)) {
460 sourcePaths += '.';
461 }
462 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
463
464 ArrayList<IContainer> res= new ArrayList<IContainer>();
465
466 String[] strings= sourcePaths.split(File.pathSeparator);
467 for (int i= 0; i < strings.length; i++) {
468 IPath path= makeAbsolutePathFromRelative(new Path(strings[i].trim()));
469 if (path != null) {
470 IContainer[] containers= root.findContainersForLocationURI(URIUtil.toURI(path.makeAbsolute()));
471 for (int k= 0; k < containers.length; k++) {
472 res.add(containers[k]);
473 }
474 }
475
476 }
477 return res.toArray(new IContainer[res.size()]);
478 }
479
480 private IJavaElement[] getSelectedElementsFromAnt(Element element) {
481 List<IJavaElement> res= new ArrayList<IJavaElement>();
482
483 // get all the packages listed in the ANT file
484 String packagenames= element.getAttribute(PACKAGENAMES);
485 if (packagenames != null) {
486 IContainer[] containers= getSourceContainers(element);
487
488 StringTokenizer tokenizer= new StringTokenizer(packagenames, ","); //$NON-NLS-1$
489 while (tokenizer.hasMoreTokens()) {
490 IPath relPackagePath= new Path(tokenizer.nextToken().trim().replace('.', '/'));
491 for (int i= 0; i < containers.length; i++) {
492 IContainer curr= containers[i];
493 IResource resource= curr.findMember(relPackagePath);
494 if (resource != null) {
495 IJavaElement javaElem= JavaCore.create(resource);
496 if (javaElem instanceof IPackageFragment) {
497 res.add(javaElem);
498 }
499 }
500 }
501 }
502 }
503
504 //get all CompilationUnites listed in the ANT file
505 String sourcefiles= element.getAttribute(SOURCEFILES);
506 if (sourcefiles != null) {
507 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
508
509 StringTokenizer tokenizer= new StringTokenizer(sourcefiles, ","); //$NON-NLS-1$
510 while (tokenizer.hasMoreTokens()) {
511 String name= tokenizer.nextToken().trim();
512 if (JavaCore.isJavaLikeFileName(name)) {
513 IPath path= makeAbsolutePathFromRelative(new Path(name));
514 //if unable to create an absolute path to the resource skip it
515 if (path != null) {
516 IFile[] files= root.findFilesForLocationURI(URIUtil.toURI(path.makeAbsolute()));
517 for (int i= 0; i < files.length; i++) {
518 IJavaElement el= JavaCore.createCompilationUnitFrom(files[i]);
519 if (el != null) {
520 res.add(el);
521 }
522 }
523 }
524 }
525 }
526 }
527 return res.toArray(new IJavaElement[res.size()]);
528 }
529
530 /**
531 * @return Returns the javadocCommandHistory.
532 */
533 public String[] getJavadocCommandHistory() {
534 return fJavadocCommandHistory;
535 }
536
537
538 //it is possible that the package list is empty
539 public StatusInfo getWizardStatus() {
540 return fWizardStatus;
541 }
542
543 public IJavaElement[] getInitialElements() {
544 return fInitialElements;
545 }
546
547 public IJavaElement[] getSourceElements() {
548 return fSelectedElements;
549 }
550
551 public String getAccess() {
552 return fAccess;
553 }
554
555 public String getAntpath() {
556 return fAntpath;
557 }
558
559 public boolean isFromStandard() {
560 return fFromStandard;
561 }
562
563 public String getDestination() {
564 return fDestination;
565 }
566
567 public String getDocletPath() {
568 return fDocletpath;
569 }
570
571 public String getDocletName() {
572 return fDocletname;
573 }
574
575 public String getStyleSheet() {
576 return fStylesheet;
577 }
578
579 public String getOverview() {
580 return fOverview;
581 }
582
583 public String getAdditionalParams() {
584 return fAdditionalParams;
585 }
586
587 public String getVMParams() {
588 return fVMParams;
589 }
590
591 public IPath[] getClasspath() {
592 return fClasspath;
593 }
594
595 public IPath[] getSourcepath() {
596 return fSourcepath;
597 }
598
599 public String getTitle() {
600 return fTitle;
601 }
602
603 public boolean doOpenInBrowser() {
604 return fOpenInBrowser;
605 }
606
607 public String[] getHRefs() {
608 return fHRefs;
609 }
610
611 public boolean getBoolean(String flag) {
612
613 if (flag.equals(AUTHOR))
614 return fAuthor;
615 else if (flag.equals(VERSION))
616 return fVersion;
617 else if (flag.equals(USE))
618 return fUse;
619 else if (flag.equals(NODEPRECATED))
620 return fNodeprecated;
621 else if (flag.equals(NODEPRECATEDLIST))
622 return fNoDeprecatedlist;
623 else if (flag.equals(NOINDEX))
624 return fNoindex;
625 else if (flag.equals(NOTREE))
626 return fNotree;
627 else if (flag.equals(SPLITINDEX))
628 return fSplitindex;
629 else if (flag.equals(NONAVBAR))
630 return fNonavbar;
631 else
632 return false;
633 }
634
635 private boolean loadBoolean(String value) {
636
637 if (value == null || value.length() == 0)
638 return false;
639 else {
640 if (value.equals("true")) //$NON-NLS-1$
641 return true;
642 else
643 return false;
644 }
645 }
646
647 private String flatPathList(IPath[] paths) {
648 StringBuffer buf= new StringBuffer();
649 for (int i= 0; i < paths.length; i++) {
650 if (i > 0) {
651 buf.append(File.pathSeparatorChar);
652 }
653 buf.append(paths[i].toOSString());
654 }
655 return buf.toString();
656 }
657
658 private String flatStringList(String[] paths) {
659 StringBuffer buf= new StringBuffer();
660 for (int i= 0; i < paths.length; i++) {
661 if (i > 0) {
662 buf.append(File.pathSeparatorChar);
663 }
664 buf.append(paths[i]);
665 }
666 return buf.toString();
667 }
668
669 public String[] arrayFromFlatString(String str) {
670 StringTokenizer tok= new StringTokenizer(str, File.pathSeparator);
671 String[] res= new String[tok.countTokens()];
672 for (int i= 0; i < res.length; i++) {
673 res[i]= tok.nextToken();
674 }
675 return res;
676 }
677
678
679 public IStatus getArgumentArray(List<String> vmArgs, List<String> toolArgs) {
680 MultiStatus status= new MultiStatus(JavaUI.ID_PLUGIN, IStatus.OK, JavadocExportMessages.JavadocOptionsManager_status_title, null);
681
682 //bug 38692
683 vmArgs.add(getJavadocCommandHistory()[0]);
684
685 if (fFromStandard) {
686 toolArgs.add("-d"); //$NON-NLS-1$
687 toolArgs.add(fDestination);
688 } else {
689 toolArgs.add("-doclet"); //$NON-NLS-1$
690 toolArgs.add(fDocletname);
691 toolArgs.add("-docletpath"); //$NON-NLS-1$
692 toolArgs.add(fDocletpath);
693 }
694
695 if (fSourcepath.length > 0) {
696 toolArgs.add("-sourcepath"); //$NON-NLS-1$
697 toolArgs.add(flatPathList(fSourcepath));
698 }
699
700 if (fClasspath.length > 0) {
701 toolArgs.add("-classpath"); //$NON-NLS-1$
702 toolArgs.add(flatPathList(fClasspath));
703 }
704 toolArgs.add("-" + fAccess); //$NON-NLS-1$
705
706 if (fFromStandard) {
707 if (fSource.length() > 0 && !fSource.equals("-")) { //$NON-NLS-1$
708 toolArgs.add("-source"); //$NON-NLS-1$
709 toolArgs.add(fSource);
710 }
711
712 if (fUse)
713 toolArgs.add("-use"); //$NON-NLS-1$
714 if (fVersion)
715 toolArgs.add("-version"); //$NON-NLS-1$
716 if (fAuthor)
717 toolArgs.add("-author"); //$NON-NLS-1$
718 if (fNonavbar)
719 toolArgs.add("-nonavbar"); //$NON-NLS-1$
720 if (fNoindex)
721 toolArgs.add("-noindex"); //$NON-NLS-1$
722 if (fNotree)
723 toolArgs.add("-notree"); //$NON-NLS-1$
724 if (fNodeprecated)
725 toolArgs.add("-nodeprecated"); //$NON-NLS-1$
726 if (fNoDeprecatedlist)
727 toolArgs.add("-nodeprecatedlist"); //$NON-NLS-1$
728 if (fSplitindex)
729 toolArgs.add("-splitindex"); //$NON-NLS-1$
730
731 if (fTitle.length() != 0) {
732 toolArgs.add("-doctitle"); //$NON-NLS-1$
733 toolArgs.add(fTitle);
734 }
735
736
737 if (fStylesheet.length() != 0) {
738 toolArgs.add("-stylesheetfile"); //$NON-NLS-1$
739 toolArgs.add(fStylesheet);
740 }
741
742 for (int i= 0; i < fHRefs.length; i++) {
743 toolArgs.add("-link"); //$NON-NLS-1$
744 toolArgs.add(fHRefs[i]);
745 }
746
747 } //end standard options
748
749 String locale= null;
750
751 if (fAdditionalParams.length() + fVMParams.length() != 0) {
752 ExecutionArguments tokens= new ExecutionArguments(fVMParams, fAdditionalParams);
753 String[] vmArgsArray= tokens.getVMArgumentsArray();
754 for (int i= 0; i < vmArgsArray.length; i++) {
755 vmArgs.add(vmArgsArray[i]);
756 }
757 String[] argsArray= tokens.getProgramArgumentsArray();
758 for (int i= 0; i < argsArray.length; i++) {
759 String arg= argsArray[i];
760 if ("-locale".equals(arg) && i + 1 < argsArray.length) { //$NON-NLS-1$
761 locale= argsArray[++i];
762 } else
763 toolArgs.add(arg);
764 }
765 }
766 addProxyOptions(vmArgs);
767
768 if (fOverview.length() != 0) {
769 toolArgs.add("-overview"); //$NON-NLS-1$
770 toolArgs.add(fOverview);
771 }
772
773 for (int i= 0; i < fSelectedElements.length; i++) {
774 IJavaElement curr= fSelectedElements[i];
775 if (curr instanceof IPackageFragment) {
776 toolArgs.add(curr.getElementName());
777 } else if (curr instanceof ICompilationUnit) {
778 // Since the Javadoc tool is running locally we can only create
779 // Javadoc for local resources. So using the location is fine here.
780 IPath p= curr.getResource().getLocation();
781 if (p != null) {
782 toolArgs.add(p.toOSString());
783 } else {
784 String message= JavadocExportMessages.JavadocOptionsManager_status_non_local;
785 status.add(new StatusInfo(IStatus.WARNING, Messages.format(message, BasicElementLabels.getPathLabel(curr.getPath(), false))));
786 }
787 }
788 }
789 // The locale argument needs to be first.
790 if (locale != null) {
791 toolArgs.add(0, "-locale"); //$NON-NLS-1$
792 toolArgs.add(1, locale);
793 }
794
795 return status;
796 }
797
798 private void addProxyOptions(List<String> vmOptions) {
799 // bug 74132
800 String hostPrefix= "-J-Dhttp.proxyHost="; //$NON-NLS-1$
801 String portPrefix= "-J-Dhttp.proxyPort="; //$NON-NLS-1$
802 for (int i= 0; i < vmOptions.size(); i++) {
803 String curr= vmOptions.get(i);
804 if (curr.startsWith(hostPrefix) || curr.startsWith(portPrefix)) {
805 return;
806 }
807 }
808 String proxyHost= System.getProperty("http.proxyHost"); //$NON-NLS-1$
809 if (proxyHost != null) {
810 vmOptions.add(hostPrefix + proxyHost);
811 }
812
813 String proxyPort= System.getProperty("http.proxyPort"); //$NON-NLS-1$
814 if (proxyPort != null) {
815 vmOptions.add(portPrefix + proxyPort);
816 }
817 }
818
819 public Element createXML(IJavaProject[] projects) throws CoreException {
820 if (fAntpath.length() > 0) {
821 try {
822 IPath filePath= Path.fromOSString(fAntpath);
823 IPath directoryPath= filePath.removeLastSegments(1);
824
825 IPath basePath= null;
826 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
827 if (root.findFilesForLocationURI(URIUtil.toURI(filePath.makeAbsolute())).length > 0) {
828 basePath= directoryPath; // only do relative path if ant file is stored in the workspace
829 }
830 JavadocWriter writer= new JavadocWriter(basePath, projects);
831 return writer.createXML(this);
832 } catch (ParserConfigurationException e) {
833 String message= JavadocExportMessages.JavadocOptionsManager_createXM_error;
834 throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, message, e));
835 }
836 }
837 return null;
838 }
839
840
841 public File writeXML(Element javadocElement) throws CoreException {
842 FileOutputStream objectStreamOutput= null;
843 //@change
844 //for now only writing ant files for single project selection
845 try {
846 File file= new File(fAntpath);
847
848 String encoding= "UTF-8"; //$NON-NLS-1$
849 IContentType type= Platform.getContentTypeManager().getContentType("org.eclipse.ant.core.antBuildFile"); //$NON-NLS-1$
850 if (type != null)
851 encoding= type.getDefaultCharset();
852
853 file.getParentFile().mkdirs();
854
855 objectStreamOutput= new FileOutputStream(file);
856 JavadocWriter.writeDocument(javadocElement, encoding, objectStreamOutput);
857 return file;
858 } catch (IOException e) {
859 String message= JavadocExportMessages.JavadocOptionsManager_createXM_error;
860 throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, message, e));
861 } catch (TransformerException e) {
862 String message= JavadocExportMessages.JavadocOptionsManager_createXM_error;
863 throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, message, e));
864 } finally {
865 if (objectStreamOutput != null) {
866 try {
867 objectStreamOutput.close();
868 } catch (IOException e) {
869 }
870 }
871 }
872 }
873
874 public void updateDialogSettings(IDialogSettings dialogSettings, IJavaProject[] checkedProjects) {
875 IDialogSettings settings= dialogSettings.addNewSection(SECTION_JAVADOC);
876
877 settings.put(JAVADOC_COMMAND_HISTORY, flatStringList(fJavadocCommandHistory));
878 if (fJavadocCommandHistory.length > 0) {
879 IPreferenceStore store= PreferenceConstants.getPreferenceStore();
880 store.setValue(PreferenceConstants.JAVADOC_COMMAND, fJavadocCommandHistory[0]);
881 }
882
883
884 settings.put(FROMSTANDARD, fFromStandard);
885
886 settings.put(DOCLETNAME, fDocletname);
887 settings.put(DOCLETPATH, fDocletpath);
888
889 settings.put(VISIBILITY, fAccess);
890
891 settings.put(USE, fUse);
892 settings.put(AUTHOR, fAuthor);
893 settings.put(VERSION, fVersion);
894 settings.put(NODEPRECATED, fNodeprecated);
895 settings.put(NODEPRECATEDLIST, fNoDeprecatedlist);
896 settings.put(SPLITINDEX, fSplitindex);
897 settings.put(NOINDEX, fNoindex);
898 settings.put(NOTREE, fNotree);
899 settings.put(NONAVBAR, fNonavbar);
900 settings.put(OPENINBROWSER, fOpenInBrowser);
901 settings.put(SOURCE, fSource);
902
903 if (fAntpath.length() != 0)
904 settings.put(ANTPATH, fAntpath);
905 if (fDestination.length() != 0)
906 settings.put(DESTINATION, fDestination);
907 if (fAdditionalParams.length() != 0)
908 settings.put(EXTRAOPTIONS, fAdditionalParams);
909 if (fVMParams.length() != 0)
910 settings.put(VMOPTIONS, fVMParams);
911 if (fOverview.length() != 0)
912 settings.put(OVERVIEW, fOverview);
913 if (fStylesheet.length() != 0)
914 settings.put(STYLESHEETFILE, fStylesheet);
915 if (fTitle.length() != 0)
916 settings.put(TITLE, fTitle);
917
918 if (checkedProjects.length == 1) {
919 updateRecentSettings(checkedProjects[0]);
920 }
921 getRecentSettings().store(settings);
922 }
923
924 public void setJavadocCommandHistory(String[] javadocCommandHistory) {
925 fJavadocCommandHistory= javadocCommandHistory;
926 }
927
928 public void setAccess(String access) {
929 fAccess= access;
930 }
931 public void setDestination(String destination) {
932 fDestination= destination;
933 }
934
935 public void setDocletPath(String docletpath) {
936 fDocletpath= docletpath;
937 }
938
939 public void setDocletName(String docletname) {
940 fDocletname= docletname;
941 }
942
943 public void setStyleSheet(String stylesheet) {
944 fStylesheet= stylesheet;
945 }
946
947 public void setOverview(String overview) {
948 fOverview= overview;
949 }
950
951 public void setAdditionalParams(String params) {
952 fAdditionalParams= params;
953 }
954
955 public void setVMParams(String params) {
956 fVMParams= params;
957 }
958
959 public void setGeneralAntpath(String antpath) {
960 fAntpath= antpath;
961 }
962 public void setClasspath(IPath[] classpath) {
963 fClasspath= classpath;
964 }
965
966 public void setSourcepath(IPath[] sourcepath) {
967 fSourcepath= sourcepath;
968 }
969
970 public void setSelectedElements(IJavaElement[] elements) {
971 fSelectedElements= elements;
972 }
973
974 public void setFromStandard(boolean fromStandard) {
975 fFromStandard= fromStandard;
976 }
977
978 public void setTitle(String title) {
979 fTitle= title;
980 }
981
982 public void setOpenInBrowser(boolean openInBrowser) {
983 fOpenInBrowser= openInBrowser;
984 }
985
986 public void setHRefs(String[] hrefs) {
987 fHRefs= hrefs;
988 }
989
990 public void setBoolean(String flag, boolean value) {
991
992 if (flag.equals(AUTHOR))
993 fAuthor= value;
994 else if (flag.equals(USE))
995 fUse= value;
996 else if (flag.equals(VERSION))
997 fVersion= value;
998 else if (flag.equals(NODEPRECATED))
999 fNodeprecated= value;
1000 else if (flag.equals(NODEPRECATEDLIST))
1001 fNoDeprecatedlist= value;
1002 else if (flag.equals(NOINDEX))
1003 fNoindex= value;
1004 else if (flag.equals(NOTREE))
1005 fNotree= value;
1006 else if (flag.equals(SPLITINDEX))
1007 fSplitindex= value;
1008 else if (flag.equals(NONAVBAR))
1009 fNonavbar= value;
1010 }
1011
1012 public void setSource(String source) {
1013 fSource= source;
1014 }
1015
1016 public String getSource() {
1017 return fSource;
1018 }
1019
1020 private IJavaElement[] getInitialElementsFromSelection(List<?> candidates) {
1021 ArrayList<IJavaElement> res= new ArrayList<IJavaElement>();
1022 for (int i= 0; i < candidates.size(); i++) {
1023 try {
1024 IJavaElement elem= getSelectableJavaElement(candidates.get(i));
1025 if (elem != null) {
1026 res.add(elem);
1027 }
1028 } catch (JavaModelException ignore) {
1029 // ignore this
1030 }
1031 }
1032 return res.toArray(new IJavaElement[res.size()]);
1033 }
1034
1035 private IJavaElement getSelectableJavaElement(Object obj) throws JavaModelException {
1036 IJavaElement je= null;
1037 if (obj instanceof IAdaptable) {
1038 je= (IJavaElement) ((IAdaptable) obj).getAdapter(IJavaElement.class);
1039 }
1040
1041 if (je != null) {
1042 switch (je.getElementType()) {
1043 case IJavaElement.JAVA_MODEL :
1044 case IJavaElement.JAVA_PROJECT :
1045 case IJavaElement.CLASS_FILE :
1046 break;
1047 case IJavaElement.PACKAGE_FRAGMENT_ROOT :
1048 if (containsCompilationUnits((IPackageFragmentRoot) je)) {
1049 return je;
1050 }
1051 break;
1052 case IJavaElement.PACKAGE_FRAGMENT :
1053 if (containsCompilationUnits((IPackageFragment) je)) {
1054 return je;
1055 }
1056 break;
1057 default :
1058 ICompilationUnit cu= (ICompilationUnit) je.getAncestor(IJavaElement.COMPILATION_UNIT);
1059 if (cu != null) {
1060 return cu;
1061 }
1062 }
1063 IJavaProject project= je.getJavaProject();
1064 if (isValidProject(project))
1065 return project;
1066 }
1067
1068 return null;
1069 }
1070
1071 private boolean isValidProject(IJavaProject project) {
1072 if (project != null && project.exists() && project.isOpen()) {
1073 return true;
1074 }
1075 return false;
1076 }
1077
1078 private boolean containsCompilationUnits(IPackageFragmentRoot root) throws JavaModelException {
1079 if (root.getKind() != IPackageFragmentRoot.K_SOURCE) {
1080 return false;
1081 }
1082
1083 IJavaElement[] elements= root.getChildren();
1084 for (int i= 0; i < elements.length; i++) {
1085 if (elements[i] instanceof IPackageFragment) {
1086 IPackageFragment fragment= (IPackageFragment) elements[i];
1087 if (containsCompilationUnits(fragment)) {
1088 return true;
1089 }
1090 }
1091 }
1092 return false;
1093 }
1094
1095 private boolean containsCompilationUnits(IPackageFragment pack) throws JavaModelException {
1096 return pack.getCompilationUnits().length > 0;
1097 }
1098
1099 public RecentSettingsStore getRecentSettings() {
1100 return fRecentSettings;
1101 }
1102
1103 /**
1104 * @param project the Java project
1105 */
1106 public void updateRecentSettings(IJavaProject project) {
1107 fRecentSettings.setProjectSettings(project, fDestination, fAntpath, fHRefs);
1108 }
1109
1110
1111 public void generated_7337309767938630209(JavadocSpecificsWizardPage javadocspecificswizardpage) {
1112 setVMParams(javadocspecificswizardpage.fVMOptionsText.getText());
1113 setAdditionalParams(javadocspecificswizardpage.fExtraOptionsText.getText());
1114
1115 if (javadocspecificswizardpage.fOverViewText.getEnabled())
1116 setOverview(javadocspecificswizardpage.fOverViewText.getText());
1117 else
1118 setOverview(""); //$NON-NLS-1$
1119
1120 //for now if there are multiple then the ant file is not stored for specific projects
1121 if (javadocspecificswizardpage.fAntText.getEnabled()) {
1122 setGeneralAntpath(javadocspecificswizardpage.fAntText.getText());
1123 }
1124 setOpenInBrowser(javadocspecificswizardpage.fCheckbrowser.getSelection());
1125 setSource(javadocspecificswizardpage.fSourceCombo.getText());
1126 }
1127
1128
1129 public void generated_7369578845116657446(JavadocTreeWizardPage javadoctreewizardpage) {
1130 javadoctreewizardpage.setDescription(JavadocExportMessages.JavadocTreeWizardPage_javadoctreewizardpage_description);
1131
1132 javadoctreewizardpage.fStore= this;
1133
1134 // Status variables
1135 javadoctreewizardpage.fJavadocStatus= new StatusInfo();
1136 javadoctreewizardpage.fDestinationStatus= new StatusInfo();
1137 javadoctreewizardpage.fDocletStatus= new StatusInfo();
1138 javadoctreewizardpage.fTreeStatus= new StatusInfo();
1139 javadoctreewizardpage.fPreferenceStatus= new StatusInfo();
1140 javadoctreewizardpage.fWizardStatus= getWizardStatus();
1141 }
1142
1143
1144 public void generated_3046707763946870791(final JavadocTreeWizardPage javadoctreewizardpage) {
1145 javadoctreewizardpage.fPrivateVisibility.addSelectionListener(new SelectionAdapter() {
1146 @Override
1147 public void widgetSelected(SelectionEvent e) {
1148 if (((Button) e.widget).getSelection()) {
1149 javadoctreewizardpage.fVisibilitySelection= PRIVATE;
1150 javadoctreewizardpage.fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_privatevisibilitydescription_label);
1151 }
1152 }
1153 });
1154 javadoctreewizardpage.fPackageVisibility.addSelectionListener(new SelectionAdapter() {
1155 @Override
1156 public void widgetSelected(SelectionEvent e) {
1157 if (((Button) e.widget).getSelection()) {
1158 javadoctreewizardpage.fVisibilitySelection= PACKAGE;
1159 javadoctreewizardpage.fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_packagevisibledescription_label);
1160 }
1161 }
1162 });
1163 javadoctreewizardpage.fProtectedVisibility.addSelectionListener(new SelectionAdapter() {
1164 @Override
1165 public void widgetSelected(SelectionEvent e) {
1166 if (((Button) e.widget).getSelection()) {
1167 javadoctreewizardpage.fVisibilitySelection= PROTECTED;
1168 javadoctreewizardpage.fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_protectedvisibilitydescription_label);
1169 }
1170 }
1171 });
1172
1173 javadoctreewizardpage.fPublicVisibility.addSelectionListener(new SelectionAdapter() {
1174 @Override
1175 public void widgetSelected(SelectionEvent e) {
1176 if (((Button) e.widget).getSelection()) {
1177 javadoctreewizardpage.fVisibilitySelection= PUBLIC;
1178 javadoctreewizardpage.fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_publicvisibilitydescription_label);
1179 }
1180 }
1181 });
1182 }
1183
1184
1185 public void generated_5485051453076311573(JavadocTreeWizardPage javadoctreewizardpage) {
1186 javadoctreewizardpage.fVisibilitySelection= getAccess();
1187 javadoctreewizardpage.fPrivateVisibility.setSelection(javadoctreewizardpage.fVisibilitySelection.equals(PRIVATE));
1188 if (javadoctreewizardpage.fPrivateVisibility.getSelection())
1189 javadoctreewizardpage.fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_privatevisibilitydescription_label);
1190
1191 javadoctreewizardpage.fProtectedVisibility.setSelection(javadoctreewizardpage.fVisibilitySelection.equals(PROTECTED));
1192 if (javadoctreewizardpage.fProtectedVisibility.getSelection())
1193 javadoctreewizardpage.fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_protectedvisibilitydescription_label);
1194
1195 javadoctreewizardpage.fPackageVisibility.setSelection(javadoctreewizardpage.fVisibilitySelection.equals(PACKAGE));
1196 if (javadoctreewizardpage.fPackageVisibility.getSelection())
1197 javadoctreewizardpage.fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_packagevisibledescription_label);
1198
1199 javadoctreewizardpage.fPublicVisibility.setSelection(javadoctreewizardpage.fVisibilitySelection.equals(PUBLIC));
1200 if (javadoctreewizardpage.fPublicVisibility.getSelection())
1201 javadoctreewizardpage.fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_publicvisibilitydescription_label);
1202 }
1203
1204
1205 public void generated_5399166640514495003(JavadocTreeWizardPage javadoctreewizardpage) {
1206 if (!isFromStandard()) {
1207 javadoctreewizardpage.fCustomButton.setSelection(true);
1208 javadoctreewizardpage.fDocletText.setText(getDocletPath());
1209 javadoctreewizardpage.fDocletTypeText.setText(getDocletName());
1210 javadoctreewizardpage.fDestinationText.setText(getDestination());
1211 javadoctreewizardpage.fDestinationText.setEnabled(false);
1212 javadoctreewizardpage.fDestinationBrowserButton.setEnabled(false);
1213 javadoctreewizardpage.fDestinationLabel.setEnabled(false);
1214
1215 } else {
1216 javadoctreewizardpage.fStandardButton.setSelection(true);
1217 javadoctreewizardpage.fDestinationText.setText(getDestination());
1218 javadoctreewizardpage.fDocletText.setText(getDocletPath());
1219 javadoctreewizardpage.fDocletTypeText.setText(getDocletName());
1220 javadoctreewizardpage.fDocletText.setEnabled(false);
1221 javadoctreewizardpage.fDocletLabel.setEnabled(false);
1222 javadoctreewizardpage.fDocletTypeText.setEnabled(false);
1223 javadoctreewizardpage.fDocletTypeLabel.setEnabled(false);
1224 }
1225
1226 javadoctreewizardpage.fJavadocCommandText.setItems(getJavadocCommandHistory());
1227 javadoctreewizardpage.fJavadocCommandText.select(0);
1228 }
1229
1230
1231 public void generated_6000579807440075959(JavadocTreeWizardPage javadoctreewizardpage) {
1232 IJavaProject[] checkedProjects= javadoctreewizardpage.getCheckedProjects();
1233
1234 if (javadoctreewizardpage.fCustomButton.getSelection()) {
1235 setDocletName(javadoctreewizardpage.fDocletTypeText.getText());
1236 setDocletPath(javadoctreewizardpage.fDocletText.getText());
1237 setFromStandard(false);
1238 }
1239 if (javadoctreewizardpage.fStandardButton.getSelection()) {
1240 setFromStandard(true);
1241 //the destination used in javadoc generation
1242 setDestination(javadoctreewizardpage.fDestinationText.getText());
1243 }
1244
1245 setSourcepath(javadoctreewizardpage.getSourcePath(checkedProjects));
1246 setClasspath(javadoctreewizardpage.getClassPath(checkedProjects));
1247 setAccess(javadoctreewizardpage.fVisibilitySelection);
1248 setSelectedElements(javadoctreewizardpage.getSourceElements(checkedProjects));
1249
1250 ArrayList<String> commands= new ArrayList<String>();
1251 commands.add(javadoctreewizardpage.fJavadocCommandText.getText()); // must be first
1252 String[] items= javadoctreewizardpage.fJavadocCommandText.getItems();
1253 for (int i= 0; i < items.length; i++) {
1254 String curr= items[i];
1255 if (!commands.contains(curr)) {
1256 commands.add(curr);
1257 }
1258 }
1259 setJavadocCommandHistory(commands.toArray(new String[commands.size()]));
1260 }
1261
1262
1263 public boolean generated_6457194037732839114(JavadocWizard javadocwizard, IJavaProject[] checkedProjects) {
1264 updateDialogSettings(javadocwizard.getDialogSettings(), checkedProjects);
1265
1266 // Wizard should not run with dirty editors
1267 if (!new RefactoringSaveHelper(RefactoringSaveHelper.SAVE_ALL_ALWAYS_ASK).saveEditors(javadocwizard.getShell())) {
1268 return false;
1269 }
1270
1271 javadocwizard.fDestination= Path.fromOSString(getDestination());
1272 javadocwizard.fDestination.toFile().mkdirs();
1273
1274 javadocwizard.fOpenInBrowser= doOpenInBrowser();
1275
1276 //Ask if you wish to set the javadoc location for the projects (all) to
1277 //the location of the newly generated javadoc
1278 if (isFromStandard()) {
1279 try {
1280
1281 URL newURL= javadocwizard.fDestination.toFile().toURI().toURL();
1282 String newExternalForm= newURL.toExternalForm();
1283 List<IJavaProject> projs= new ArrayList<IJavaProject>();
1284 //get javadoc locations for all projects
1285 for (int i= 0; i < checkedProjects.length; i++) {
1286 IJavaProject curr= checkedProjects[i];
1287 URL currURL= JavaUI.getProjectJavadocLocation(curr);
1288 if (currURL == null || !newExternalForm.equals(currURL.toExternalForm())) {
1289 //if not all projects have the same javadoc location ask if you want to change
1290 //them to have the same javadoc location
1291 projs.add(curr);
1292 }
1293 }
1294 if (!projs.isEmpty()) {
1295 javadocwizard.setAllJavadocLocations(projs.toArray(new IJavaProject[projs.size()]), newURL);
1296 }
1297 } catch (MalformedURLException e) {
1298 JavaPlugin.log(e);
1299 }
1300 }
1301
1302 if (javadocwizard.fLastWizardPage.generateAnt()) {
1303 //@Improve: make a better message
1304 OptionalMessageDialog.open(javadocwizard.JAVADOC_ANT_INFORMATION_DIALOG, javadocwizard.getShell(), JavadocExportMessages.JavadocWizard_antInformationDialog_title, null, JavadocExportMessages.JavadocWizard_antInformationDialog_message, MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
1305 try {
1306 Element javadocXMLElement= createXML(checkedProjects);
1307 if (javadocXMLElement != null) {
1308
1309 if (!javadocwizard.fTreeWizardPage.getCustom()) {
1310 for (int i= 0; i < javadocwizard.fContributedJavadocWizardPages.length; i++) {
1311 javadocwizard.fContributedJavadocWizardPages[i].updateAntScript(javadocXMLElement);
1312 }
1313 }
1314 File file= writeXML(javadocXMLElement);
1315 IFile[] files= javadocwizard.fRoot.findFilesForLocationURI(file.toURI());
1316 if (files != null) {
1317 for (int i= 0; i < files.length; i++) {
1318 files[i].refreshLocal(IResource.DEPTH_ONE, null);
1319 }
1320 }
1321 }
1322
1323 } catch (CoreException e) {
1324 ExceptionHandler.handle(e, javadocwizard.getShell(),JavadocExportMessages.JavadocWizard_error_writeANT_title, JavadocExportMessages.JavadocWizard_error_writeANT_message);
1325 }
1326 }
1327
1328 if (!javadocwizard.executeJavadocGeneration())
1329 return false;
1330
1331 return true;
1332 }
1333
1334
1335 public void generated_7186628189988278499(JavadocWizard javadocwizard) {
1336 javadocwizard.fContributedJavadocWizardPages= ContributedJavadocWizardPage.getContributedPages(this);
1337
1338 javadocwizard.fTreeWizardPage= new JavadocTreeWizardPage(javadocwizard.TREE_PAGE_DESC, this);
1339 javadocwizard.fLastWizardPage= new JavadocSpecificsWizardPage(javadocwizard.SPECIFICS_PAGE_DESC, javadocwizard.fTreeWizardPage, this);
1340 javadocwizard.fStandardDocletWizardPage= new JavadocStandardWizardPage(javadocwizard.STANDARD_PAGE_DESC, javadocwizard.fTreeWizardPage, this);
1341 }
1342
1343
1344 public Element generated_3249893167774712372(JavadocWriter javadocwriter, Document document, Element project) {
1345 document.appendChild(project);
1346
1347 project.setAttribute("default", "javadoc"); //$NON-NLS-1$ //$NON-NLS-2$
1348
1349 Element javadocTarget= document.createElement("target"); //$NON-NLS-1$
1350 project.appendChild(javadocTarget);
1351 javadocTarget.setAttribute("name", "javadoc"); //$NON-NLS-1$ //$NON-NLS-2$
1352
1353 Element xmlJavadocDesc= document.createElement("javadoc"); //$NON-NLS-1$
1354 javadocTarget.appendChild(xmlJavadocDesc);
1355
1356 if (!isFromStandard())
1357 javadocwriter.xmlWriteDoclet(this, document, xmlJavadocDesc);
1358 else
1359 javadocwriter.xmlWriteJavadocStandardParams(this, document, xmlJavadocDesc);
1360 return xmlJavadocDesc;
1361 }
1362
1363
1364 public void generated_8267892255919562318(JavadocWriter javadocwriter, Document document, Element xmlJavadocDesc) {
1365 String destination= javadocwriter.getPathString(Path.fromOSString(getDestination()));
1366
1367 xmlJavadocDesc.setAttribute(DESTINATION, destination);
1368 xmlJavadocDesc.setAttribute(VISIBILITY, getAccess());
1369 String source= getSource();
1370 if (source.length() > 0 && !source.equals("-")) { //$NON-NLS-1$
1371 xmlJavadocDesc.setAttribute(SOURCE, getSource());
1372 }
1373 xmlJavadocDesc.setAttribute(USE, javadocwriter.booleanToString(getBoolean("use"))); //$NON-NLS-1$
1374 xmlJavadocDesc.setAttribute(NOTREE, javadocwriter.booleanToString(getBoolean("notree"))); //$NON-NLS-1$
1375 xmlJavadocDesc.setAttribute(NONAVBAR, javadocwriter.booleanToString(getBoolean("nonavbar"))); //$NON-NLS-1$
1376 xmlJavadocDesc.setAttribute(NOINDEX, javadocwriter.booleanToString(getBoolean("noindex"))); //$NON-NLS-1$
1377 xmlJavadocDesc.setAttribute(SPLITINDEX, javadocwriter.booleanToString(getBoolean("splitindex"))); //$NON-NLS-1$
1378 xmlJavadocDesc.setAttribute(AUTHOR, javadocwriter.booleanToString(getBoolean("author"))); //$NON-NLS-1$
1379 xmlJavadocDesc.setAttribute(VERSION, javadocwriter.booleanToString(getBoolean("version"))); //$NON-NLS-1$
1380 xmlJavadocDesc.setAttribute(NODEPRECATEDLIST, javadocwriter.booleanToString(getBoolean("nodeprecatedlist"))); //$NON-NLS-1$
1381 xmlJavadocDesc.setAttribute(NODEPRECATED, javadocwriter.booleanToString(getBoolean("nodeprecated"))); //$NON-NLS-1$
1382
1383
1384 //set the packages and source files
1385 List<String> packages= new ArrayList<String>();
1386 List<String> sourcefiles= new ArrayList<String>();
1387 javadocwriter.sortSourceElement(getSourceElements(), sourcefiles, packages);
1388 if (!packages.isEmpty())
1389 xmlJavadocDesc.setAttribute(PACKAGENAMES, javadocwriter.toSeparatedList(packages));
1390
1391 if (!sourcefiles.isEmpty())
1392 xmlJavadocDesc.setAttribute(SOURCEFILES, javadocwriter.toSeparatedList(sourcefiles));
1393
1394 xmlJavadocDesc.setAttribute(SOURCEPATH, javadocwriter.getPathString(getSourcepath()));
1395 xmlJavadocDesc.setAttribute(CLASSPATH, javadocwriter.getPathString(getClasspath()));
1396
1397 String overview= getOverview();
1398 if (overview.length() > 0)
1399 xmlJavadocDesc.setAttribute(OVERVIEW, overview);
1400
1401 String styleSheet= getStyleSheet();
1402 if (styleSheet.length() > 0)
1403 xmlJavadocDesc.setAttribute(STYLESHEETFILE, styleSheet);
1404
1405 String title= getTitle();
1406 if (title.length() > 0)
1407 xmlJavadocDesc.setAttribute(TITLE, title);
1408
1409
1410 String vmArgs= getVMParams();
1411 String additionalArgs= getAdditionalParams();
1412 if (vmArgs.length() + additionalArgs.length() > 0) {
1413 String str= vmArgs + ' ' + additionalArgs;
1414 xmlJavadocDesc.setAttribute(EXTRAOPTIONS, str);
1415 }
1416
1417 String[] hrefs= getHRefs();
1418 for (int i= 0; i < hrefs.length; i++) {
1419 Element links= document.createElement("link"); //$NON-NLS-1$
1420 xmlJavadocDesc.appendChild(links);
1421 links.setAttribute(HREF, hrefs[i]);
1422 }
1423 }
1424
1425
1426 public void generated_6293400888425383894(JavadocWriter javadocwriter, Document document, Element xmlJavadocDesc) {
1427 List<String> packages= new ArrayList<String>();
1428 List<String> sourcefiles= new ArrayList<String>();
1429 javadocwriter.sortSourceElement(getSourceElements(), sourcefiles, packages);
1430 if (!packages.isEmpty())
1431 xmlJavadocDesc.setAttribute(PACKAGENAMES, javadocwriter.toSeparatedList(packages));
1432
1433 if (!sourcefiles.isEmpty())
1434 xmlJavadocDesc.setAttribute(SOURCEFILES, javadocwriter.toSeparatedList(sourcefiles));
1435
1436 xmlJavadocDesc.setAttribute(SOURCEPATH, javadocwriter.getPathString(getSourcepath()));
1437 xmlJavadocDesc.setAttribute(CLASSPATH, javadocwriter.getPathString(getClasspath()));
1438 xmlJavadocDesc.setAttribute(VISIBILITY, getAccess());
1439
1440 Element doclet= document.createElement("doclet"); //$NON-NLS-1$
1441 xmlJavadocDesc.appendChild(doclet);
1442 doclet.setAttribute(NAME, getDocletName());
1443 doclet.setAttribute(PATH, getDocletPath());
1444
1445 String str= getOverview();
1446 if (str.length() > 0)
1447 xmlJavadocDesc.setAttribute(OVERVIEW, str);
1448
1449 str= getAdditionalParams();
1450 if (str.length() > 0)
1451 xmlJavadocDesc.setAttribute(EXTRAOPTIONS, str);
1452 }
1453
1454
1455 public static String initJavadocCommandDefault() {
1456 IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
1457 String cmd= store.getString(PreferenceConstants.JAVADOC_COMMAND); // old location
1458 if (cmd != null && cmd.length() > 0) {
1459 store.setToDefault(PreferenceConstants.JAVADOC_COMMAND);
1460 return cmd;
1461 }
1462
1463 File file= findJavaDocCommand();
1464 if (file != null) {
1465 return file.getPath();
1466 }
1467 return ""; //$NON-NLS-1$
1468 }
1469
1470
1471 private static File findJavaDocCommand() {
1472 IVMInstall install= JavaRuntime.getDefaultVMInstall();
1473 if (install != null) {
1474 File res= getCommand(install);
1475 if (res != null) {
1476 return res;
1477 }
1478 }
1479
1480 IVMInstallType[] jreTypes= JavaRuntime.getVMInstallTypes();
1481 for (int i= 0; i < jreTypes.length; i++) {
1482 IVMInstallType jreType= jreTypes[i];
1483 IVMInstall[] installs= jreType.getVMInstalls();
1484 for (int k= 0; k < installs.length; k++) {
1485 File res= getCommand(installs[k]);
1486 if (res != null) {
1487 return res;
1488 }
1489 }
1490 }
1491 return null;
1492 }
1493
1494 private static File getCommand(IVMInstall install) {
1495 File installLocation= install.getInstallLocation();
1496 if (installLocation != null) {
1497 File javaDocCommand= new File(installLocation, "bin/javadoc"); //$NON-NLS-1$
1498 if (javaDocCommand.isFile()) {
1499 return javaDocCommand;
1500 }
1501 javaDocCommand= new File(installLocation, "bin/javadoc.exe"); //$NON-NLS-1$
1502 if (javaDocCommand.isFile()) {
1503 return javaDocCommand;
1504 }
1505 }
1506 return null;
1507 }
1508
1509
1510
1511
1512}