KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > ui > jarpackager > JarPackageData


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  *******************************************************************************/

11 package org.eclipse.jdt.ui.jarpackager;
12
13 import java.io.InputStream JavaDoc;
14 import java.io.OutputStream JavaDoc;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.resources.IProject;
18 import org.eclipse.core.resources.ResourcesPlugin;
19
20 import org.eclipse.core.runtime.Assert;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IPath;
23 import org.eclipse.core.runtime.Path;
24
25 import org.eclipse.swt.widgets.Shell;
26
27 import org.eclipse.jface.operation.IRunnableContext;
28
29 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
30
31 import org.eclipse.jdt.core.IPackageFragment;
32 import org.eclipse.jdt.core.IType;
33
34
35 import org.eclipse.jdt.internal.ui.JavaPlugin;
36 import org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation;
37 import org.eclipse.jdt.internal.ui.jarpackager.JarPackageReader;
38 import org.eclipse.jdt.internal.ui.jarpackager.JarPackageWriter;
39 import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil;
40 import org.eclipse.jdt.internal.ui.jarpackager.ManifestProvider;
41 import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
42
43 /**
44  * Model for a JAR package which stores information used during JAR export and
45  * import.
46  * <p>
47  * Clients may subclass.
48  * </p>
49  *
50  * @see org.eclipse.jdt.ui.jarpackager.JarWriter3
51  * @since 2.0
52  */

53 public class JarPackageData {
54
55     private String JavaDoc fManifestVersion;
56
57     /*
58      * What to export - internal locations
59      * The list fExported* is null if fExport* is false)
60      */

61     private boolean fExportClassFiles; // export generated class files and resources
62
private boolean fExportOutputFolders; // export all output folder of enclosing projects
63
private boolean fExportJavaFiles; // export java files and resources
64

65     /*
66      * Source folder hierarchy is created in the JAR if true
67      */

68     private boolean fUseSourceFolderHierarchy;
69
70     /*
71      * Projects of which files are exported will be built if true
72      * and auto-build is off.
73      */

74     private boolean fBuildIfNeeded;
75
76     /*
77      * Leaf elements (no containers) to export
78      */

79     private Object JavaDoc[] fElements; // inside workspace
80

81     private IPath fJarLocation; // external location
82
private boolean fOverwrite;
83     private boolean fCompress;
84     
85     private boolean fSaveDescription;
86     private IPath fDescriptionLocation; // internal location
87

88     /*
89      * A normal JAR has a manifest (fUsesManifest is true)
90      * The manifest can be contributed in two ways
91      * - it can be generated (fGenerateManifest is true) and
92      * - saved (fSaveManifest is true)
93      * - saved and reused (fReuseManifest is true implies: fSaveManifest is true)
94      * - it can be specified (fGenerateManifest is false and the
95      * manifest location must be specified (fManifestLocation))
96      */

97     private boolean fUsesManifest;
98     private boolean fSaveManifest;
99     private boolean fReuseManifest;
100     private boolean fGenerateManifest;
101     private IPath fManifestLocation; // internal location
102

103     /*
104      * Sealing: a JAR can be
105      * - sealed (fSealJar is true) and a list of
106      * unsealed packages can be defined (fPackagesToUnseal)
107      * while the list of sealed packages is ignored
108      * - unsealed (fSealJar is false) and the list of
109      * sealed packages can be defined (fPackagesToSeal)
110      * while the list of unsealed packages is ignored
111      */

112     private boolean fSealJar;
113     private IPackageFragment[] fPackagesToSeal;
114     private IPackageFragment[] fPackagesToUnseal;
115
116     private IType fManifestMainClass;
117     
118     private String JavaDoc fComment; // the JAR comment
119

120     /*
121      * Error handling
122      */

123     private boolean fExportErrors;
124     private boolean fExportWarnings;
125     
126     // The provider for the manifest file
127
private IManifestProvider fManifestProvider;
128     
129     // Add directory entries to the jar
130
private boolean fIncludeDirectoryEntries;
131
132     // Projects for which to store refactoring information
133
private IProject[] fRefactoringProjects= {};
134
135     // Should the package be refactoring aware?
136
private boolean fRefactoringAware= false;
137
138     // Should the exporter only export refactorings causing structural changes?
139
private boolean fRefactoringStructural= false;
140
141     // Should the exporter include deprecation resolving information?
142
private boolean fDeprecationAware= true;
143
144     // The refactoring descriptors to export
145
private RefactoringDescriptorProxy[] fRefactoringDescriptors= {};
146
147     /**
148      * Creates a new Jar Package Data structure
149      */

150     public JarPackageData() {
151         setExportClassFiles(true);
152         setExportOutputFolders(false);
153         setUseSourceFolderHierarchy(false);
154         setCompress(true);
155         setSaveDescription(false);
156         setJarLocation(Path.EMPTY);
157         setDescriptionLocation(Path.EMPTY);
158         setUsesManifest(true);
159         setGenerateManifest(true);
160         setReuseManifest(false);
161         setSaveManifest(false);
162         setManifestLocation(Path.EMPTY);
163         setExportErrors(true);
164         setExportWarnings(true);
165         setBuildIfNeeded(true);
166         setIncludeDirectoryEntries(false);
167     }
168
169     // ----------- Accessors -----------
170

171     /**
172      * Tells whether the JAR is compressed or not.
173      *
174      * @return <code>true</code> if the JAR is compressed
175      */

176     public boolean isCompressed() {
177         return fCompress;
178     }
179
180     /**
181      * Set whether the JAR is compressed or not.
182      *
183      * @param state a boolean indicating the new state
184      */

185     public void setCompress(boolean state) {
186         fCompress= state;
187     }
188
189     /**
190      * Tells whether files can be overwritten without warning.
191      *
192      * @return <code>true</code> if files can be overwritten without warning
193      */

194     public boolean allowOverwrite() {
195         return fOverwrite;
196     }
197
198     /**
199      * Sets whether files can be overwritten without warning.
200      *
201      * @param state a boolean indicating the new state
202      */

203     public void setOverwrite(boolean state) {
204         fOverwrite= state;
205     }
206
207     /**
208      * Tells whether class files and resources are exported.
209      *
210      * @return <code>true</code> if class files and resources are exported
211      */

212     public boolean areClassFilesExported() {
213         return fExportClassFiles;
214     }
215
216     /**
217      * Sets option to export class files and resources.
218      *
219      * @param state a boolean indicating the new state
220      */

221     public void setExportClassFiles(boolean state) {
222         fExportClassFiles= state;
223     }
224     
225     /**
226      * Tells whether all output folders for the
227      * enclosing projects of the exported elements.
228      *
229      * @return <code>true</code> if output folder are exported
230      * @since 3.0
231      */

232     public boolean areOutputFoldersExported() {
233         return fExportOutputFolders;
234     }
235
236     /**
237      * Sets option to export all output folders for the
238      * enclosing projects of the exported elements.
239      *
240      * @param state a boolean indicating the new state
241      * @since 3.0
242      */

243     public void setExportOutputFolders(boolean state) {
244         fExportOutputFolders= state;
245     }
246
247     /**
248      * Tells whether files created by the Java builder are exported.
249      *
250      * @return <code>true</code> if output folder are exported
251      * @since 3.0
252      */

253     public boolean areGeneratedFilesExported() {
254         return fExportOutputFolders || fExportClassFiles;
255     }
256
257     /**
258      * Tells whether java files and resources are exported.
259      *
260      * @return <code>true</code> if java files and resources are exported
261      */

262     public boolean areJavaFilesExported() {
263         return fExportJavaFiles;
264     }
265
266     /**
267      * Sets the option to export Java source and resources.
268      *
269      * @param state the new state
270      */

271     public void setExportJavaFiles(boolean state) {
272         fExportJavaFiles= state;
273     }
274
275     /**
276      * Tells whether the source folder hierarchy is used.
277      * <p>
278      * Using the source folder hierarchy only makes sense if
279      * java files are but class files aren't exported.
280      * </p>
281      *
282      * @return <code>true</code> if source folder hierarchy is used
283      */

284     public boolean useSourceFolderHierarchy() {
285         return fUseSourceFolderHierarchy;
286     }
287     
288     /**
289      * Set the option to export the source folder hierarchy.
290      *
291      * @param state the new state
292      */

293     public void setUseSourceFolderHierarchy(boolean state) {
294         fUseSourceFolderHierarchy= state;
295     }
296     
297     /**
298      * Gets the absolute location of the JAR file.
299      * This path is normally external to the workspace.
300      *
301      * @return the absolute path representing the location of the JAR file
302      *
303      * @since 3.0
304      */

305     public IPath getAbsoluteJarLocation() {
306         // The workspace root is always local to the file system.
307
// So getLocation is OK here.
308
IPath workspaceLocation= ResourcesPlugin.getWorkspace().getRoot().getLocation();
309         if (!fJarLocation.isAbsolute() && workspaceLocation != null)
310             // prepend workspace path
311
return workspaceLocation.append(fJarLocation);
312         else
313             return fJarLocation;
314     }
315
316     /**
317      * Gets the location of the JAR file.
318      * This path is normally external to the workspace.
319      *
320      * @return the path representing the location of the JAR file
321      */

322     public IPath getJarLocation() {
323         return fJarLocation;
324     }
325
326     /**
327      * Sets the JAR file location.
328      *
329      * @param jarLocation a path denoting the location of the JAR file
330      */

331     public void setJarLocation(IPath jarLocation) {
332         fJarLocation= jarLocation;
333     }
334
335     /**
336      * Tells whether the manifest file must be generated.
337      *
338      * @return <code>true</code> if the manifest has to be generated
339      */

340     public boolean isManifestGenerated() {
341         return fGenerateManifest;
342     }
343     
344     /**
345      * Set whether a manifest must be generated or not.
346      *
347      * @param state the new state
348      */

349     public void setGenerateManifest(boolean state) {
350         fGenerateManifest= state;
351     }
352     
353     /**
354      * Tells whether the manifest file must be saved to the
355      * specified file during the export operation.
356      *
357      * @return <code>true</code> if the manifest must be saved
358      * @see #getManifestLocation()
359      */

360     public boolean isManifestSaved() {
361         return fSaveManifest;
362     }
363
364     /**
365      * Sets whether the manifest file must be saved during export
366      * operation or not.
367      *
368      * @param state the new state
369      * @see #getManifestLocation()
370      */

371     public void setSaveManifest(boolean state) {
372         fSaveManifest= state;
373         if (!fSaveManifest)
374             // can't reuse manifest if it is not saved
375
setReuseManifest(false);
376     }
377
378     /**
379      * Tells whether a previously generated manifest should be reused.
380      *
381      * @return <code>true</code> if the generated manifest will be reused when regenerating this JAR,
382      * <code>false</code> if the manifest has to be regenerated
383      */

384     public boolean isManifestReused() {
385         return fReuseManifest;
386     }
387
388     /**
389      * Sets whether a previously generated manifest should be reused.
390      *
391      * @param state the new state
392      */

393     public void setReuseManifest(boolean state) {
394         fReuseManifest= state;
395         if (fReuseManifest)
396             // manifest must be saved in order to be reused
397
setSaveManifest(true);
398     }
399
400     /**
401      * Returns the location of a user-defined manifest file.
402      *
403      * @return the path of the user-defined manifest file location,
404      * or <code>null</code> if none is specified
405      */

406     public IPath getManifestLocation() {
407         return fManifestLocation;
408     }
409
410     /**
411      * Sets the location of a user-defined manifest file.
412      *
413      * @param manifestLocation the path of the user-define manifest location
414      */

415     public void setManifestLocation(IPath manifestLocation) {
416         fManifestLocation= manifestLocation;
417     }
418
419     /**
420      * Gets the manifest file (as workspace resource).
421      *
422      * @return a file which points to the manifest
423      */

424     public IFile getManifestFile() {
425         IPath path= getManifestLocation();
426         if (path.isValidPath(path.toString()) && path.segmentCount() >= 2)
427             return JavaPlugin.getWorkspace().getRoot().getFile(path);
428         else
429             return null;
430     }
431     
432     /**
433      * Gets the manifest version.
434      *
435      * @return a string containing the manifest version
436      */

437     public String JavaDoc getManifestVersion() {
438         if (fManifestVersion == null)
439             return "1.0"; //$NON-NLS-1$
440
return fManifestVersion;
441     }
442     
443     /**
444      * Sets the manifest version.
445      *
446      * @param manifestVersion the string which contains the manifest version
447      */

448     public void setManifestVersion(String JavaDoc manifestVersion) {
449         fManifestVersion= manifestVersion;
450     }
451     
452     /**
453      * Answers whether a manifest must be included in the JAR.
454      *
455      * @return <code>true</code> if a manifest has to be included
456      */

457     public boolean usesManifest() {
458         return fUsesManifest;
459     }
460     
461     /**
462      * Sets whether a manifest must be included in the JAR.
463      *
464      * @param state the new state
465      */

466     public void setUsesManifest(boolean state) {
467         fUsesManifest= state;
468     }
469     
470     /**
471      * Gets the manifest provider for this JAR package.
472      *
473      * @return the IManifestProvider
474      */

475     public IManifestProvider getManifestProvider() {
476         if (fManifestProvider == null)
477             fManifestProvider= new ManifestProvider();
478         return fManifestProvider;
479     }
480     
481     /**
482      * Sets the manifest provider.
483      *
484      * @param manifestProvider the ManifestProvider to set
485      */

486     public void setManifestProvider(IManifestProvider manifestProvider) {
487         fManifestProvider= manifestProvider;
488     }
489     
490     /**
491      * Answers whether the JAR itself is sealed.
492      * The manifest will contain a "Sealed: true" statement.
493      * <p>
494      * This option should only be considered when the
495      * manifest file is generated.
496      * </p>
497      *
498      * @return <code>true</code> if the JAR must be sealed
499      * @see #isManifestGenerated()
500      */

501     public boolean isJarSealed() {
502         return fSealJar;
503     }
504
505     /**
506      * Sets whether the JAR itself is sealed.
507      * The manifest will contain the following entry:
508      * Sealed: true
509      * <p>
510      * This option should only be considered when the
511      * manifest file is generated.
512      * </p>
513      *
514      * @param sealJar <code>true</code> if the JAR must be sealed
515      * @see #isManifestGenerated()
516      */

517     public void setSealJar(boolean sealJar) {
518         fSealJar= sealJar;
519     }
520
521     /**
522      * Sets the packages which should be sealed.
523      * The following entry will be added to the manifest file for each package:
524      * Name: &lt;name of the package&gt;
525      * Sealed: true
526      * <p>
527      * This should only be used if the JAR itself is not sealed.
528      * </p>
529      *
530      * @param packagesToSeal an array of <code>IPackageFragment</code> to seal
531      */

532     public void setPackagesToSeal(IPackageFragment[] packagesToSeal) {
533         fPackagesToSeal= packagesToSeal;
534     }
535
536     /**
537      * Gets the packages which should be sealed.
538      * The following entry will be added to the manifest file for each package:
539      * Name: &lt;name of the package&gt;
540      * Sealed: true
541      * <p>
542      * This should only be used if the JAR itself is not sealed.
543      * </p>
544      *
545      * @return an array of <code>IPackageFragment</code>
546      */

547     public IPackageFragment[] getPackagesToSeal() {
548         if (fPackagesToSeal == null)
549             return new IPackageFragment[0];
550         else
551             return fPackagesToSeal;
552     }
553
554     /**
555      * Gets the packages which should explicitly be unsealed.
556      * The following entry will be added to the manifest file for each package:
557      * Name: &lt;name of the package&gt;
558      * Sealed: false
559      * <p>
560      * This should only be used if the JAR itself is sealed.
561      * </p>
562      *
563      * @return an array of <code>IPackageFragment</code>
564      */

565     public IPackageFragment[] getPackagesToUnseal() {
566         if (fPackagesToUnseal == null)
567             return new IPackageFragment[0];
568         else
569             return fPackagesToUnseal;
570     }
571
572     /**
573      * Set the packages which should explicitly be unsealed.
574      * The following entry will be added to the manifest file for each package:
575      * Name: &lt;name of the package&gt;
576      * Sealed: false
577      * <p>
578      * This should only be used if the JAR itself is sealed.
579      * </p>
580      *
581      * @param packagesToUnseal an array of <code>IPackageFragment</code>
582      */

583     public void setPackagesToUnseal(IPackageFragment[] packagesToUnseal) {
584         fPackagesToUnseal= packagesToUnseal;
585     }
586
587     /**
588      * Tells whether a description of this JAR package must be saved
589      * to a file by a JAR description writer during the export operation.
590      * <p>
591      * The JAR writer defines the format of the file.
592      * </p>
593      *
594      * @return <code>true</code> if this JAR package will be saved
595      * @see #getDescriptionLocation()
596      */

597     public boolean isDescriptionSaved() {
598         return fSaveDescription;
599     }
600     
601     /**
602      * Set whether a description of this JAR package must be saved
603      * to a file by a JAR description writer during the export operation.
604      * <p>
605      * The format is defined by the client who implements the
606      * reader/writer pair.
607      * </p>
608      * @param state a boolean containing the new state
609      * @see #getDescriptionLocation()
610      * @see IJarDescriptionWriter
611      */

612     public void setSaveDescription(boolean state) {
613         fSaveDescription= state;
614     }
615     
616     /**
617      * Returns the location of file containing the description of a JAR.
618      * This location is inside the workspace.
619      *
620      * @return the path of the description file location,
621      * or <code>null</code> if none is specified
622      */

623     public IPath getDescriptionLocation() {
624         return fDescriptionLocation;
625     }
626
627     /**
628      * Set the location of the JAR description file.
629      *
630      * @param descriptionLocation the path of location
631      */

632     public void setDescriptionLocation(IPath descriptionLocation) {
633         fDescriptionLocation= descriptionLocation;
634     }
635
636     /**
637      * Gets the description file (as workspace resource).
638      *
639      * @return a file which points to the description
640      */

641     public IFile getDescriptionFile() {
642         IPath path= getDescriptionLocation();
643         if (path.isValidPath(path.toString()) && path.segmentCount() >= 2)
644             return JavaPlugin.getWorkspace().getRoot().getFile(path);
645         else
646             return null;
647     }
648     
649     /**
650      * Gets the manifest's main class.
651      *
652      * @return the type which contains the main class or,
653      * <code>null</code> if none is specified
654      */

655     public IType getManifestMainClass() {
656         return fManifestMainClass;
657     }
658
659     /**
660      * Set the manifest's main class.
661      *
662      * @param manifestMainClass the type with the main class for the manifest file
663      */

664     public void setManifestMainClass(IType manifestMainClass) {
665         fManifestMainClass= manifestMainClass;
666     }
667
668     /**
669      * Returns the elements which will be exported.
670      * These elements are leaf objects e.g. <code>IFile</code>
671      * and not containers.
672      *
673      * @return an array of leaf objects
674      */

675     public Object JavaDoc[] getElements() {
676         if (fElements == null)
677             setElements(new Object JavaDoc[0]);
678         return fElements;
679     }
680
681     /**
682      * Set the elements which will be exported.
683      *
684      * These elements are leaf objects e.g. <code>IFile</code>.
685      * and not containers.
686      *
687      * @param elements an array with leaf objects
688      */

689     public void setElements(Object JavaDoc[] elements) {
690         fElements= elements;
691     }
692
693     /**
694      * Returns the JAR's comment.
695      *
696      * @return the comment string or <code>null</code>
697      * if the JAR does not contain a comment
698      */

699     public String JavaDoc getComment() {
700         return fComment;
701     }
702
703     /**
704      * Sets the JAR's comment.
705      *
706      * @param comment a string or <code>null</code>
707      * if the JAR does not contain a comment
708      */

709     public void setComment(String JavaDoc comment) {
710         fComment= comment;
711     }
712
713     /**
714      * Tell whether errors are logged.
715      * <p>
716      * The export operation decides where and
717      * how the errors are logged.
718      * </p>
719      *
720      * @return <code>true</code> if errors are logged
721      * @deprecated will be removed in final 2.0
722      */

723     public boolean logErrors() {
724         return true;
725     }
726
727     /**
728      * Sets whether errors are logged.
729      * <p>
730      * The export operation decides where and
731      * how the errors are logged.
732      * </p>
733      *
734      * @param logErrors <code>true</code> if errors are logged
735      * @deprecated will be removed in final 2.0
736      */

737     public void setLogErrors(boolean logErrors) {
738         // always true
739
}
740         
741     /**
742      * Tells whether warnings are logged or not.
743      * <p>
744      * The export operation decides where and
745      * how the warnings are logged.
746      * </p>
747      *
748      * @return <code>true</code> if warnings are logged
749      * @deprecated will be removed in final 2.0
750      */

751     public boolean logWarnings() {
752         return true;
753     }
754     
755     /**
756      * Sets if warnings are logged.
757      * <p>
758      * The export operation decides where and
759      * how the warnings are logged.
760      * </p>
761      *
762      * @param logWarnings <code>true</code> if warnings are logged
763      * @deprecated will be removed in final 2.0
764      */

765     public void setLogWarnings(boolean logWarnings) {
766         // always true
767
}
768     
769     /**
770      * Answers if compilation units with errors are exported.
771      *
772      * @return <code>true</code> if CUs with errors should be exported
773      */

774     public boolean areErrorsExported() {
775         return fExportErrors;
776     }
777     
778     /**
779      * Sets if compilation units with errors are exported.
780      *
781      * @param exportErrors <code>true</code> if CUs with errors should be exported
782      */

783     public void setExportErrors(boolean exportErrors) {
784         fExportErrors= exportErrors;
785     }
786     
787     /**
788      * Answers if compilation units with warnings are exported.
789      *
790      * @return <code>true</code> if CUs with warnings should be exported
791      */

792     public boolean exportWarnings() {
793         return fExportWarnings;
794     }
795     
796     /**
797      * Sets if compilation units with warnings are exported.
798      *
799      * @param exportWarnings <code>true</code> if CUs with warnings should be exported
800      */

801     public void setExportWarnings(boolean exportWarnings) {
802         fExportWarnings= exportWarnings;
803     }
804     
805     /**
806      * Answers if a build should be performed before exporting files.
807      * This flag is only considered if auto-build is off.
808      *
809      * @return a boolean telling if a build should be performed
810      */

811     public boolean isBuildingIfNeeded() {
812         return fBuildIfNeeded;
813     }
814     
815     /**
816      * Sets if a build should be performed before exporting files.
817      * This flag is only considered if auto-build is off.
818      *
819      * @param buildIfNeeded a boolean telling if a build should be performed
820      */

821     public void setBuildIfNeeded(boolean buildIfNeeded) {
822         fBuildIfNeeded= buildIfNeeded;
823     }
824     // ----------- Utility methods -----------
825

826     /**
827      * Finds the class files for the given java file
828      * and returns them.
829      * <p>
830      * This is a hook for subclasses which want to implement
831      * a different strategy for finding the class files. The default
832      * strategy is to query the class files for the source file
833      * name attribute. If this attribute is missing then all class
834      * files in the corresponding output folder are exported.
835      * </p>
836      * <p>
837      * A CoreException can be thrown if an error occurs during this
838      * operation. The <code>CoreException</code> will not stop the export
839      * process but adds the status object to the status of the
840      * export runnable.
841      * </p>
842      *
843      * @param javaFile a .java file
844      * @return an array with class files or <code>null</code> to used the default strategy
845      * @throws CoreException if find failed, e.g. I/O error or resource out of sync
846      * @see IJarExportRunnable#getStatus()
847      */

848     public IFile[] findClassfilesFor(IFile javaFile) throws CoreException {
849         return null;
850     }
851
852     /**
853      * Creates and returns a JarWriter for this JAR package.
854      *
855      * @param parent the shell used to display question dialogs,
856      * or <code>null</code> if "false/no/cancel" is the answer
857      * and no dialog should be shown
858      * @return a JarWriter2
859      * @see JarWriter2
860      * @throws CoreException if an unexpected exception happens
861      *
862      * @deprecated Use {@link #createJarWriter3(Shell)} instead
863      */

864     public JarWriter2 createJarWriter(Shell parent) throws CoreException {
865         return new JarWriter2(this, parent);
866     }
867     
868     /**
869      * Creates and returns a JarWriter for this JAR package.
870      *
871      * @param parent the shell used to display question dialogs,
872      * or <code>null</code> if "false/no/cancel" is the answer
873      * and no dialog should be shown
874      * @return a JarWriter3
875      * @see JarWriter3
876      * @throws CoreException if an unexpected exception happens
877      *
878      * @since 3.2
879      */

880     public JarWriter3 createJarWriter3(Shell parent) throws CoreException {
881         return new JarWriter3(this, parent);
882     }
883     
884     /**
885      * Creates and returns a JarExportRunnable.
886      *
887      * @param parent the parent for the dialog,
888      * or <code>null</code> if no questions should be asked and
889      * no checks for unsaved files should be made.
890      * @return a JarExportRunnable
891      */

892     public IJarExportRunnable createJarExportRunnable(Shell parent) {
893         return new JarFileExportOperation(this, parent);
894     }
895     
896     /**
897      * Creates and returns a JarExportRunnable for a list of JAR package
898      * data objects.
899      *
900      * @param jarPackagesData an array with JAR package data objects
901      * @param parent the parent for the dialog,
902      * or <code>null</code> if no dialog should be presented
903      * @return the {@link IJarExportRunnable}
904      */

905     public IJarExportRunnable createJarExportRunnable(JarPackageData[] jarPackagesData, Shell parent) {
906         return new JarFileExportOperation(jarPackagesData, parent);
907     }
908     
909     /**
910      * Creates and returns a JAR package data description writer
911      * for this JAR package data object.
912      * <p>
913      * It is the client's responsibility to close this writer.
914      * </p>
915      * @param outputStream the output stream to write to
916      * @return a JarWriter
917      * @deprecated Use {@link #createJarDescriptionWriter(OutputStream, String)} instead
918      */

919     public IJarDescriptionWriter createJarDescriptionWriter(OutputStream JavaDoc outputStream) {
920         return new JarPackageWriter(outputStream, "UTF-8"); //$NON-NLS-1$
921
}
922
923     /**
924      * Creates and returns a JAR package data description writer
925      * for this JAR package data object.
926      * <p>
927      * It is the client's responsibility to close this writer.
928      * </p>
929      * @param outputStream the output stream to write to
930      * @param encoding the encoding to use
931      * @return a JarWriter
932      * @since 3.3
933      */

934     public IJarDescriptionWriter createJarDescriptionWriter(OutputStream JavaDoc outputStream, String JavaDoc encoding) {
935         return new JarPackageWriter(outputStream, encoding);
936     }
937
938     /**
939      * Creates and returns a JAR package data description reader
940      * for this JAR package data object.
941      * <p>
942      * It is the client's responsibility to close this reader.
943      * </p>
944      * @param inputStream the input stream to read from
945      * @return a JarWriter
946      */

947     public IJarDescriptionReader createJarDescriptionReader(InputStream JavaDoc inputStream) {
948         return new JarPackageReader(inputStream);
949     }
950     
951     /**
952      * Tells whether this JAR package data can be used to generate
953      * a valid JAR.
954      *
955      * @return <code>true</code> if the JAR Package info is valid
956      */

957     public boolean isValid() {
958         return (areGeneratedFilesExported() || areJavaFilesExported())
959             && getElements() != null && getElements().length > 0
960             && getAbsoluteJarLocation() != null
961             && isManifestAccessible()
962             && isMainClassValid(new BusyIndicatorRunnableContext());
963     }
964
965     /**
966      * Tells whether a manifest is available.
967      *
968      * @return <code>true</code> if the manifest is generated or the provided one is accessible
969      */

970     public boolean isManifestAccessible() {
971         if (isManifestGenerated())
972             return true;
973         IFile file= getManifestFile();
974         return file != null && file.isAccessible();
975     }
976
977     /**
978      * Tells whether the specified manifest main class is valid.
979      *
980      * @param context the {@link IRunnableContext}
981      * @return <code>true</code> if a main class is specified and valid
982      */

983     public boolean isMainClassValid(IRunnableContext context) {
984         return JarPackagerUtil.isMainClassValid(this, context);
985     }
986
987     /**
988      * Tells whether directory entries are added to the jar.
989      *
990      * @return <code>true</code> if directory entries are to be included
991      *
992      * @since 3.1
993      */

994     public boolean areDirectoryEntriesIncluded() {
995         return fIncludeDirectoryEntries;
996     }
997
998     /**
999      * Sets the option to include directory entries into the jar.
1000     *
1001     * @param includeDirectoryEntries <code>true</code> to include
1002     * directory entries <code>false</code> otherwise
1003     *
1004     * @since 3.1
1005     */

1006    public void setIncludeDirectoryEntries(boolean includeDirectoryEntries) {
1007        fIncludeDirectoryEntries = includeDirectoryEntries;
1008    }
1009
1010    /**
1011     * Returns the projects for which refactoring information should be stored.
1012     * <p>
1013     * This information is used for JAR export.
1014     * </p>
1015     *
1016     * @return the projects for which refactoring information should be stored,
1017     * or an empty array
1018     *
1019     * @since 3.2
1020     */

1021    public IProject[] getRefactoringProjects() {
1022        return fRefactoringProjects;
1023    }
1024
1025    /**
1026     * Is the JAR export wizard only exporting refactorings causing structural
1027     * changes?
1028     * <p>
1029     * This information is used for JAR export.
1030     * </p>
1031     *
1032     * @return <code>true</code> if exporting structural changes only,
1033     * <code>false</code> otherwise
1034     * @since 3.2
1035     */

1036    public boolean isExportStructuralOnly() {
1037        return fRefactoringStructural;
1038    }
1039
1040    /**
1041     * Is the JAR package refactoring aware?
1042     * <p>
1043     * This information is used both in JAR export and import
1044     * </p>
1045     *
1046     * @return <code>true</code> if it is refactoring aware,
1047     * <code>false</code> otherwise
1048     *
1049     * @since 3.2
1050     */

1051    public boolean isRefactoringAware() {
1052        return fRefactoringAware;
1053    }
1054
1055    /**
1056     * Is the JAR package deprecation aware?
1057     * <p>
1058     * This information is used in JAR export.
1059     * </p>
1060     *
1061     * @return <code>true</code> if it is deprecation aware,
1062     * <code>false</code> otherwise
1063     *
1064     * @since 3.2
1065     */

1066    public boolean isDeprecationAware() {
1067        return fDeprecationAware;
1068    }
1069
1070    /**
1071     * Sets the projects for which refactoring information should be stored.
1072     * <p>
1073     * This information is used for JAR export.
1074     * </p>
1075     *
1076     * @param projects
1077     * the projects for which refactoring information should be
1078     * stored
1079     *
1080     * @since 3.2
1081     */

1082    public void setRefactoringProjects(IProject[] projects) {
1083        Assert.isNotNull(projects);
1084        fRefactoringProjects= projects;
1085    }
1086
1087    /**
1088     * Determines whether the jar package is refactoring aware.
1089     * <p>
1090     * This information is used both in JAR export and import.
1091     * </p>
1092     *
1093     * @param aware
1094     * <code>true</code> if it is refactoring aware,
1095     * <code>false</code> otherwise
1096     *
1097     * @since 3.2
1098     */

1099    public void setRefactoringAware(boolean aware) {
1100        fRefactoringAware= aware;
1101    }
1102
1103    /**
1104     * Determines whether the jar package is deprecation aware.
1105     * <p>
1106     * This information is used in JAR export.
1107     * </p>
1108     *
1109     * @param aware
1110     * <code>true</code> if it is deprecation aware,
1111     * <code>false</code> otherwise
1112     *
1113     * @since 3.2
1114     */

1115    public void setDeprecationAware(boolean aware) {
1116        fDeprecationAware= aware;
1117    }
1118
1119    /**
1120     * Sets the refactoring descriptors to export.
1121     * <p>
1122     * This information is used in JAR export.
1123     * </p>
1124     *
1125     * @param descriptors
1126     * the refactoring descriptors
1127     *
1128     * @since 3.2
1129     */

1130    public void setRefactoringDescriptors(RefactoringDescriptorProxy[] descriptors) {
1131        Assert.isNotNull(descriptors);
1132        fRefactoringDescriptors= descriptors;
1133    }
1134
1135    /**
1136     * Returns the refactoring descriptors to export.
1137     * <p>
1138     * This information is used in JAR export.
1139     * </p>
1140     *
1141     * @return the refactoring descriptors to export
1142     *
1143     * @since 3.2
1144     */

1145    public RefactoringDescriptorProxy[] getRefactoringDescriptors() {
1146        return fRefactoringDescriptors;
1147    }
1148
1149    /**
1150     * Determines whether the jar packager exports only refactorings causing
1151     * structural changes.
1152     * <p>
1153     * This information is used for JAR export.
1154     * </p>
1155     *
1156     * @param structural
1157     * <code>true</code> if it exports only refactorings causing
1158     * structural changes, <code>false</code> otherwise
1159     *
1160     * @since 3.2
1161     */

1162    public void setExportStructuralOnly(boolean structural) {
1163        fRefactoringStructural= structural;
1164    }
1165}
1166
Popular Tags