1 11 package org.eclipse.jdt.ui.jarpackager; 12 13 import java.io.InputStream ; 14 import java.io.OutputStream ; 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 53 public class JarPackageData { 54 55 private String fManifestVersion; 56 57 61 private boolean fExportClassFiles; private boolean fExportOutputFolders; private boolean fExportJavaFiles; 65 68 private boolean fUseSourceFolderHierarchy; 69 70 74 private boolean fBuildIfNeeded; 75 76 79 private Object [] fElements; 81 private IPath fJarLocation; private boolean fOverwrite; 83 private boolean fCompress; 84 85 private boolean fSaveDescription; 86 private IPath fDescriptionLocation; 88 97 private boolean fUsesManifest; 98 private boolean fSaveManifest; 99 private boolean fReuseManifest; 100 private boolean fGenerateManifest; 101 private IPath fManifestLocation; 103 112 private boolean fSealJar; 113 private IPackageFragment[] fPackagesToSeal; 114 private IPackageFragment[] fPackagesToUnseal; 115 116 private IType fManifestMainClass; 117 118 private String fComment; 120 123 private boolean fExportErrors; 124 private boolean fExportWarnings; 125 126 private IManifestProvider fManifestProvider; 128 129 private boolean fIncludeDirectoryEntries; 131 132 private IProject[] fRefactoringProjects= {}; 134 135 private boolean fRefactoringAware= false; 137 138 private boolean fRefactoringStructural= false; 140 141 private boolean fDeprecationAware= true; 143 144 private RefactoringDescriptorProxy[] fRefactoringDescriptors= {}; 146 147 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 171 176 public boolean isCompressed() { 177 return fCompress; 178 } 179 180 185 public void setCompress(boolean state) { 186 fCompress= state; 187 } 188 189 194 public boolean allowOverwrite() { 195 return fOverwrite; 196 } 197 198 203 public void setOverwrite(boolean state) { 204 fOverwrite= state; 205 } 206 207 212 public boolean areClassFilesExported() { 213 return fExportClassFiles; 214 } 215 216 221 public void setExportClassFiles(boolean state) { 222 fExportClassFiles= state; 223 } 224 225 232 public boolean areOutputFoldersExported() { 233 return fExportOutputFolders; 234 } 235 236 243 public void setExportOutputFolders(boolean state) { 244 fExportOutputFolders= state; 245 } 246 247 253 public boolean areGeneratedFilesExported() { 254 return fExportOutputFolders || fExportClassFiles; 255 } 256 257 262 public boolean areJavaFilesExported() { 263 return fExportJavaFiles; 264 } 265 266 271 public void setExportJavaFiles(boolean state) { 272 fExportJavaFiles= state; 273 } 274 275 284 public boolean useSourceFolderHierarchy() { 285 return fUseSourceFolderHierarchy; 286 } 287 288 293 public void setUseSourceFolderHierarchy(boolean state) { 294 fUseSourceFolderHierarchy= state; 295 } 296 297 305 public IPath getAbsoluteJarLocation() { 306 IPath workspaceLocation= ResourcesPlugin.getWorkspace().getRoot().getLocation(); 309 if (!fJarLocation.isAbsolute() && workspaceLocation != null) 310 return workspaceLocation.append(fJarLocation); 312 else 313 return fJarLocation; 314 } 315 316 322 public IPath getJarLocation() { 323 return fJarLocation; 324 } 325 326 331 public void setJarLocation(IPath jarLocation) { 332 fJarLocation= jarLocation; 333 } 334 335 340 public boolean isManifestGenerated() { 341 return fGenerateManifest; 342 } 343 344 349 public void setGenerateManifest(boolean state) { 350 fGenerateManifest= state; 351 } 352 353 360 public boolean isManifestSaved() { 361 return fSaveManifest; 362 } 363 364 371 public void setSaveManifest(boolean state) { 372 fSaveManifest= state; 373 if (!fSaveManifest) 374 setReuseManifest(false); 376 } 377 378 384 public boolean isManifestReused() { 385 return fReuseManifest; 386 } 387 388 393 public void setReuseManifest(boolean state) { 394 fReuseManifest= state; 395 if (fReuseManifest) 396 setSaveManifest(true); 398 } 399 400 406 public IPath getManifestLocation() { 407 return fManifestLocation; 408 } 409 410 415 public void setManifestLocation(IPath manifestLocation) { 416 fManifestLocation= manifestLocation; 417 } 418 419 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 437 public String getManifestVersion() { 438 if (fManifestVersion == null) 439 return "1.0"; return fManifestVersion; 441 } 442 443 448 public void setManifestVersion(String manifestVersion) { 449 fManifestVersion= manifestVersion; 450 } 451 452 457 public boolean usesManifest() { 458 return fUsesManifest; 459 } 460 461 466 public void setUsesManifest(boolean state) { 467 fUsesManifest= state; 468 } 469 470 475 public IManifestProvider getManifestProvider() { 476 if (fManifestProvider == null) 477 fManifestProvider= new ManifestProvider(); 478 return fManifestProvider; 479 } 480 481 486 public void setManifestProvider(IManifestProvider manifestProvider) { 487 fManifestProvider= manifestProvider; 488 } 489 490 501 public boolean isJarSealed() { 502 return fSealJar; 503 } 504 505 517 public void setSealJar(boolean sealJar) { 518 fSealJar= sealJar; 519 } 520 521 532 public void setPackagesToSeal(IPackageFragment[] packagesToSeal) { 533 fPackagesToSeal= packagesToSeal; 534 } 535 536 547 public IPackageFragment[] getPackagesToSeal() { 548 if (fPackagesToSeal == null) 549 return new IPackageFragment[0]; 550 else 551 return fPackagesToSeal; 552 } 553 554 565 public IPackageFragment[] getPackagesToUnseal() { 566 if (fPackagesToUnseal == null) 567 return new IPackageFragment[0]; 568 else 569 return fPackagesToUnseal; 570 } 571 572 583 public void setPackagesToUnseal(IPackageFragment[] packagesToUnseal) { 584 fPackagesToUnseal= packagesToUnseal; 585 } 586 587 597 public boolean isDescriptionSaved() { 598 return fSaveDescription; 599 } 600 601 612 public void setSaveDescription(boolean state) { 613 fSaveDescription= state; 614 } 615 616 623 public IPath getDescriptionLocation() { 624 return fDescriptionLocation; 625 } 626 627 632 public void setDescriptionLocation(IPath descriptionLocation) { 633 fDescriptionLocation= descriptionLocation; 634 } 635 636 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 655 public IType getManifestMainClass() { 656 return fManifestMainClass; 657 } 658 659 664 public void setManifestMainClass(IType manifestMainClass) { 665 fManifestMainClass= manifestMainClass; 666 } 667 668 675 public Object [] getElements() { 676 if (fElements == null) 677 setElements(new Object [0]); 678 return fElements; 679 } 680 681 689 public void setElements(Object [] elements) { 690 fElements= elements; 691 } 692 693 699 public String getComment() { 700 return fComment; 701 } 702 703 709 public void setComment(String comment) { 710 fComment= comment; 711 } 712 713 723 public boolean logErrors() { 724 return true; 725 } 726 727 737 public void setLogErrors(boolean logErrors) { 738 } 740 741 751 public boolean logWarnings() { 752 return true; 753 } 754 755 765 public void setLogWarnings(boolean logWarnings) { 766 } 768 769 774 public boolean areErrorsExported() { 775 return fExportErrors; 776 } 777 778 783 public void setExportErrors(boolean exportErrors) { 784 fExportErrors= exportErrors; 785 } 786 787 792 public boolean exportWarnings() { 793 return fExportWarnings; 794 } 795 796 801 public void setExportWarnings(boolean exportWarnings) { 802 fExportWarnings= exportWarnings; 803 } 804 805 811 public boolean isBuildingIfNeeded() { 812 return fBuildIfNeeded; 813 } 814 815 821 public void setBuildIfNeeded(boolean buildIfNeeded) { 822 fBuildIfNeeded= buildIfNeeded; 823 } 824 826 848 public IFile[] findClassfilesFor(IFile javaFile) throws CoreException { 849 return null; 850 } 851 852 864 public JarWriter2 createJarWriter(Shell parent) throws CoreException { 865 return new JarWriter2(this, parent); 866 } 867 868 880 public JarWriter3 createJarWriter3(Shell parent) throws CoreException { 881 return new JarWriter3(this, parent); 882 } 883 884 892 public IJarExportRunnable createJarExportRunnable(Shell parent) { 893 return new JarFileExportOperation(this, parent); 894 } 895 896 905 public IJarExportRunnable createJarExportRunnable(JarPackageData[] jarPackagesData, Shell parent) { 906 return new JarFileExportOperation(jarPackagesData, parent); 907 } 908 909 919 public IJarDescriptionWriter createJarDescriptionWriter(OutputStream outputStream) { 920 return new JarPackageWriter(outputStream, "UTF-8"); } 922 923 934 public IJarDescriptionWriter createJarDescriptionWriter(OutputStream outputStream, String encoding) { 935 return new JarPackageWriter(outputStream, encoding); 936 } 937 938 947 public IJarDescriptionReader createJarDescriptionReader(InputStream inputStream) { 948 return new JarPackageReader(inputStream); 949 } 950 951 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 970 public boolean isManifestAccessible() { 971 if (isManifestGenerated()) 972 return true; 973 IFile file= getManifestFile(); 974 return file != null && file.isAccessible(); 975 } 976 977 983 public boolean isMainClassValid(IRunnableContext context) { 984 return JarPackagerUtil.isMainClassValid(this, context); 985 } 986 987 994 public boolean areDirectoryEntriesIncluded() { 995 return fIncludeDirectoryEntries; 996 } 997 998 1006 public void setIncludeDirectoryEntries(boolean includeDirectoryEntries) { 1007 fIncludeDirectoryEntries = includeDirectoryEntries; 1008 } 1009 1010 1021 public IProject[] getRefactoringProjects() { 1022 return fRefactoringProjects; 1023 } 1024 1025 1036 public boolean isExportStructuralOnly() { 1037 return fRefactoringStructural; 1038 } 1039 1040 1051 public boolean isRefactoringAware() { 1052 return fRefactoringAware; 1053 } 1054 1055 1066 public boolean isDeprecationAware() { 1067 return fDeprecationAware; 1068 } 1069 1070 1082 public void setRefactoringProjects(IProject[] projects) { 1083 Assert.isNotNull(projects); 1084 fRefactoringProjects= projects; 1085 } 1086 1087 1099 public void setRefactoringAware(boolean aware) { 1100 fRefactoringAware= aware; 1101 } 1102 1103 1115 public void setDeprecationAware(boolean aware) { 1116 fDeprecationAware= aware; 1117 } 1118 1119 1130 public void setRefactoringDescriptors(RefactoringDescriptorProxy[] descriptors) { 1131 Assert.isNotNull(descriptors); 1132 fRefactoringDescriptors= descriptors; 1133 } 1134 1135 1145 public RefactoringDescriptorProxy[] getRefactoringDescriptors() { 1146 return fRefactoringDescriptors; 1147 } 1148 1149 1162 public void setExportStructuralOnly(boolean structural) { 1163 fRefactoringStructural= structural; 1164 } 1165} 1166 | Popular Tags |