|
Lines 22-28
Link Here
|
| 22 |
import java.util.ArrayList; |
22 |
import java.util.ArrayList; |
| 23 |
import java.util.Arrays; |
23 |
import java.util.Arrays; |
| 24 |
import java.util.List; |
24 |
import java.util.List; |
| 25 |
import java.util.jar.JarFile; |
|
|
| 26 |
import java.util.zip.ZipException; |
25 |
import java.util.zip.ZipException; |
| 27 |
import java.util.zip.ZipFile; |
26 |
import java.util.zip.ZipFile; |
| 28 |
|
27 |
|
|
Lines 532-538
Link Here
|
| 532 |
} |
531 |
} |
| 533 |
return Diagnostic.OK_INSTANCE; |
532 |
return Diagnostic.OK_INSTANCE; |
| 534 |
} |
533 |
} |
| 535 |
|
534 |
|
|
|
535 |
/** |
| 536 |
* Installs the projects described by {@link #getProjectDescriptors}. |
| 537 |
* <p> |
| 538 |
* In EMF 2.4, this worked by obtaining an {@link ImportOperation} for each descriptor from {@link #createImportOperation}, and then creating the project and executing the operation. |
| 539 |
* Beginning in EMF 2.5, {@link #createImportOperation} returns null by default, and {@link #installProject(ProjectDescriptor, IProgressMonitor)} is called to create the project, create the operation, and execute it. |
| 540 |
* This allows the same code that creates the operation to do any cleanup required after executing it. This change was needed to stop extending {@link ImportOperation}, which was an API violation. |
| 541 |
* <p> |
| 542 |
* Note that existing overrides of {@link #createImportOperation} and the methods it calls are still supported; however, it is recommended to switch over to the new design. |
| 543 |
*/ |
| 536 |
protected void installExample(IProgressMonitor progressMonitor) throws Exception |
544 |
protected void installExample(IProgressMonitor progressMonitor) throws Exception |
| 537 |
{ |
545 |
{ |
| 538 |
List<ProjectDescriptor> projectDescriptors = getProjectDescriptors(); |
546 |
List<ProjectDescriptor> projectDescriptors = getProjectDescriptors(); |
|
Lines 540-552
Link Here
|
| 540 |
for (ProjectDescriptor projectDescriptor : projectDescriptors) |
548 |
for (ProjectDescriptor projectDescriptor : projectDescriptors) |
| 541 |
{ |
549 |
{ |
| 542 |
ImportOperation importOperation = createImportOperation(projectDescriptor); |
550 |
ImportOperation importOperation = createImportOperation(projectDescriptor); |
| 543 |
createProject(projectDescriptor, new SubProgressMonitor(progressMonitor, 1)); |
551 |
if (importOperation != null) |
| 544 |
importOperation.setContext(getShell()); |
552 |
{ |
| 545 |
importOperation.run(new SubProgressMonitor(progressMonitor, 1)); |
553 |
installProject(projectDescriptor, importOperation, progressMonitor); |
|
|
554 |
} |
| 555 |
else |
| 556 |
{ |
| 557 |
installProject(projectDescriptor, progressMonitor); |
| 558 |
} |
| 546 |
} |
559 |
} |
| 547 |
progressMonitor.done(); |
560 |
progressMonitor.done(); |
| 548 |
} |
561 |
} |
| 549 |
|
562 |
|
| 550 |
protected void openFiles(IProgressMonitor progressMonitor) |
563 |
protected void openFiles(IProgressMonitor progressMonitor) |
| 551 |
{ |
564 |
{ |
| 552 |
List<FileToOpen> filesToOpen = getFilesToOpen(); |
565 |
List<FileToOpen> filesToOpen = getFilesToOpen(); |
|
Lines 578-583
Link Here
|
| 578 |
DiagnosticDialog.open(getShell(), CommonUIPlugin.INSTANCE.getString("_UI_Error_label"), message, BasicDiagnostic.toDiagnostic(throwable)); |
591 |
DiagnosticDialog.open(getShell(), CommonUIPlugin.INSTANCE.getString("_UI_Error_label"), message, BasicDiagnostic.toDiagnostic(throwable)); |
| 579 |
} |
592 |
} |
| 580 |
|
593 |
|
|
|
594 |
/** |
| 595 |
* Creates the project described by the given <code>projectDescriptor</code> and imports its contents using the given <code>importOperation</code>. |
| 596 |
* @since 2.5 |
| 597 |
*/ |
| 598 |
protected void installProject(ProjectDescriptor projectDescriptor, ImportOperation importOperation, IProgressMonitor progressMonitor) throws Exception |
| 599 |
{ |
| 600 |
createProject(projectDescriptor, new SubProgressMonitor(progressMonitor, 1)); |
| 601 |
importOperation.setContext(getShell()); |
| 602 |
importOperation.run(new SubProgressMonitor(progressMonitor, 1)); |
| 603 |
} |
| 604 |
|
| 581 |
protected void createProject(ProjectDescriptor projectDescriptor, IProgressMonitor monitor) throws CoreException |
605 |
protected void createProject(ProjectDescriptor projectDescriptor, IProgressMonitor monitor) throws CoreException |
| 582 |
{ |
606 |
{ |
| 583 |
monitor.beginTask(CommonUIPlugin.INSTANCE.getString("_UI_CreateProject_message", new String []{ projectDescriptor.getName() }), 3); |
607 |
monitor.beginTask(CommonUIPlugin.INSTANCE.getString("_UI_CreateProject_message", new String []{ projectDescriptor.getName() }), 3); |
|
Lines 589-594
Link Here
|
| 589 |
monitor.done(); |
613 |
monitor.done(); |
| 590 |
} |
614 |
} |
| 591 |
|
615 |
|
|
|
616 |
/** |
| 617 |
* Installs the project described by the given <code>projectDescriptor</code>. |
| 618 |
* This implementation simply looks at the form of its content URI and delegates to {@link #installProjectFromDirectory} |
| 619 |
* or {@link #installProjectFromFile}, as appropriate. |
| 620 |
* @since 2.5 |
| 621 |
*/ |
| 622 |
protected void installProject(ProjectDescriptor projectDescriptor, IProgressMonitor progressMonitor) throws Exception |
| 623 |
{ |
| 624 |
URI contentURI = projectDescriptor.getContentURI(); |
| 625 |
if (contentURI.hasTrailingPathSeparator()) |
| 626 |
{ |
| 627 |
installProjectFromDirectory(projectDescriptor, progressMonitor); |
| 628 |
} |
| 629 |
else |
| 630 |
{ |
| 631 |
installProjectFromFile(projectDescriptor, progressMonitor); |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
/** |
| 636 |
* This method was used in EMF 2.4 and earlier to obtain an <code>ImportOperation</code> for installing a project. |
| 637 |
* This implementation now merely returns null (or throws an exception for unsupported content forms). |
| 638 |
* @deprecated Use {@link #installProject(ProjectDescriptor, IProgressMonitor)}, which also actually creates the project and performs the import. |
| 639 |
*/ |
| 640 |
@Deprecated |
| 592 |
protected ImportOperation createImportOperation(ProjectDescriptor projectDescriptor) throws Exception |
641 |
protected ImportOperation createImportOperation(ProjectDescriptor projectDescriptor) throws Exception |
| 593 |
{ |
642 |
{ |
| 594 |
URI contentURI = projectDescriptor.getContentURI(); |
643 |
URI contentURI = projectDescriptor.getContentURI(); |
|
Lines 602-608
Link Here
|
| 602 |
} |
651 |
} |
| 603 |
} |
652 |
} |
| 604 |
|
653 |
|
| 605 |
protected ImportOperation createDirectoryImportOperation(ProjectDescriptor projectDescriptor) throws Exception |
654 |
/** |
|
|
655 |
* Installs the project described by the given <code>projectDescriptor</code> from a directory. |
| 656 |
* This implementation should handle the directory scenario completely, but will throw an exception if the specified directory is not found or readable. |
| 657 |
* @since 2.5 |
| 658 |
*/ |
| 659 |
protected void installProjectFromDirectory(ProjectDescriptor projectDescriptor, IProgressMonitor progressMonitor) throws Exception |
| 606 |
{ |
660 |
{ |
| 607 |
URI contentURI = projectDescriptor.getContentURI(); |
661 |
URI contentURI = projectDescriptor.getContentURI(); |
| 608 |
if (contentURI.isPlatform()) |
662 |
if (contentURI.isPlatform()) |
|
Lines 610-615
Link Here
|
| 610 |
contentURI = CommonPlugin.asLocalURI(contentURI); |
664 |
contentURI = CommonPlugin.asLocalURI(contentURI); |
| 611 |
} |
665 |
} |
| 612 |
|
666 |
|
|
|
667 |
ImportOperation importOperation = null; |
| 613 |
String location = contentURI.toFileString(); |
668 |
String location = contentURI.toFileString(); |
| 614 |
if (location != null) |
669 |
if (location != null) |
| 615 |
{ |
670 |
{ |
|
Lines 619-638
Link Here
|
| 619 |
List<File> filesToImport = new ArrayList<File>(); |
674 |
List<File> filesToImport = new ArrayList<File>(); |
| 620 |
filesToImport.addAll(Arrays.asList(directory.listFiles())); |
675 |
filesToImport.addAll(Arrays.asList(directory.listFiles())); |
| 621 |
|
676 |
|
| 622 |
ImportOperation importOperation = new ImportOperation( |
677 |
importOperation = new ImportOperation( |
| 623 |
projectDescriptor.getProject().getFullPath(), |
678 |
projectDescriptor.getProject().getFullPath(), |
| 624 |
directory, |
679 |
directory, |
| 625 |
FileSystemStructureProvider.INSTANCE, |
680 |
FileSystemStructureProvider.INSTANCE, |
| 626 |
OVERWRITE_ALL_QUERY, |
681 |
OVERWRITE_ALL_QUERY, |
| 627 |
filesToImport); |
682 |
filesToImport); |
| 628 |
importOperation.setCreateContainerStructure(false); |
683 |
importOperation.setCreateContainerStructure(false); |
| 629 |
return importOperation; |
|
|
| 630 |
} |
684 |
} |
| 631 |
} |
685 |
} |
| 632 |
|
686 |
|
| 633 |
throw new Exception(CommonUIPlugin.INSTANCE.getString("_UI_DirectoryError_message", new String []{ contentURI.toString() })); |
687 |
if (importOperation != null) |
|
|
688 |
{ |
| 689 |
installProject(projectDescriptor, importOperation, progressMonitor); |
| 690 |
} |
| 691 |
else |
| 692 |
{ |
| 693 |
throw new Exception(CommonUIPlugin.INSTANCE.getString("_UI_DirectoryError_message", new String [] { contentURI.toString() })); |
| 694 |
} |
| 634 |
} |
695 |
} |
| 635 |
|
696 |
|
|
|
697 |
/** |
| 698 |
* This method was used in EMF 2.4 and earlier to obtain an <code>ImportOperation</code> for installing a project from a directory. |
| 699 |
* This implementation now merely returns null. |
| 700 |
* @deprecated Use {@link #installProjectFromDirectory}, which also actually creates the project and performs the import. |
| 701 |
*/ |
| 702 |
@Deprecated |
| 703 |
protected ImportOperation createDirectoryImportOperation(ProjectDescriptor projectDescriptor) throws Exception |
| 704 |
{ |
| 705 |
return null; |
| 706 |
} |
| 707 |
|
| 708 |
/** |
| 709 |
* Installs the project described by the given <code>projectDescriptor</code> from a file. |
| 710 |
* This implementation only handles zip files, throwing an exception otherwise. It may be overridden to handle other cases. |
| 711 |
* @since 2.5 |
| 712 |
*/ |
| 713 |
protected void installProjectFromFile(ProjectDescriptor projectDescriptor, IProgressMonitor progressMonitor) throws Exception |
| 714 |
{ |
| 715 |
URI contentURI = projectDescriptor.getContentURI(); |
| 716 |
if (contentURI.isPlatform()) |
| 717 |
{ |
| 718 |
contentURI = CommonPlugin.asLocalURI(contentURI); |
| 719 |
} |
| 720 |
|
| 721 |
ImportOperation importOperation = null; |
| 722 |
ZipFile zipFile = null; |
| 723 |
try |
| 724 |
{ |
| 725 |
String location = contentURI.toFileString(); |
| 726 |
if (location != null) |
| 727 |
{ |
| 728 |
File file = new File(location); |
| 729 |
if (file.isFile() && file.canRead()) |
| 730 |
{ |
| 731 |
zipFile = createZipFile(file); |
| 732 |
if (zipFile != null) |
| 733 |
{ |
| 734 |
ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(zipFile); |
| 735 |
importOperation = new ImportOperation( |
| 736 |
projectDescriptor.getProject().getFullPath(), |
| 737 |
structureProvider.getRoot(), |
| 738 |
structureProvider, |
| 739 |
OVERWRITE_ALL_QUERY); |
| 740 |
} |
| 741 |
} |
| 742 |
} |
| 743 |
|
| 744 |
if (importOperation != null) |
| 745 |
{ |
| 746 |
installProject(projectDescriptor, importOperation, progressMonitor); |
| 747 |
} |
| 748 |
else |
| 749 |
{ |
| 750 |
throw new Exception(CommonUIPlugin.INSTANCE.getString("_UI_FileError_message", new String [] { contentURI.toString() })); |
| 751 |
} |
| 752 |
} |
| 753 |
finally |
| 754 |
{ |
| 755 |
if (zipFile != null) |
| 756 |
{ |
| 757 |
try |
| 758 |
{ |
| 759 |
zipFile.close(); |
| 760 |
} |
| 761 |
catch (IOException e) |
| 762 |
{ |
| 763 |
// Ignore. |
| 764 |
} |
| 765 |
} |
| 766 |
} |
| 767 |
} |
| 768 |
|
| 769 |
/** |
| 770 |
* This method was used in EMF 2.4 and earlier to obtain an <code>ImportOperation</code> for installing a project from a file. |
| 771 |
* This implementation now merely returns null (or throws an exception for unsupported files). |
| 772 |
* @deprecated Use {@link #installProjectFromFile}, which also actually creates the project and performs the import. |
| 773 |
*/ |
| 774 |
@Deprecated |
| 636 |
protected ImportOperation createFileImportOperation(ProjectDescriptor projectDescriptor) throws Exception |
775 |
protected ImportOperation createFileImportOperation(ProjectDescriptor projectDescriptor) throws Exception |
| 637 |
{ |
776 |
{ |
| 638 |
URI contentURI = projectDescriptor.getContentURI(); |
777 |
URI contentURI = projectDescriptor.getContentURI(); |
|
Lines 657-662
Link Here
|
| 657 |
throw new Exception(CommonUIPlugin.INSTANCE.getString("_UI_FileError_message", new String []{ contentURI.toString() })); |
796 |
throw new Exception(CommonUIPlugin.INSTANCE.getString("_UI_FileError_message", new String []{ contentURI.toString() })); |
| 658 |
} |
797 |
} |
| 659 |
|
798 |
|
|
|
799 |
/** |
| 800 |
* Returns a <code>ZipFile</code> for reading from the given file, if it is in fact a zip file; null otherwise. |
| 801 |
* The client is responsible for closing the zip file if it is non-null. |
| 802 |
* @since 2.5.0 |
| 803 |
*/ |
| 804 |
protected ZipFile createZipFile(File file) |
| 805 |
{ |
| 806 |
// Is it important to create a JarFile for .jar files? |
| 807 |
try |
| 808 |
{ |
| 809 |
return new ZipFile(file); |
| 810 |
} |
| 811 |
catch (ZipException e) |
| 812 |
{ |
| 813 |
// Ignore |
| 814 |
} |
| 815 |
catch (IOException e) |
| 816 |
{ |
| 817 |
// Ignore |
| 818 |
} |
| 819 |
return null; |
| 820 |
} |
| 821 |
|
| 822 |
/** |
| 823 |
* This method was used in EMF 2.4 and earlier to test if a <code>File</code> represents a zip file. |
| 824 |
* @deprecated Use {@link #createZipFile}, which doesn't require creating another {@link ZipFile}. |
| 825 |
*/ |
| 826 |
@Deprecated |
| 660 |
protected boolean isZipFile(File file) |
827 |
protected boolean isZipFile(File file) |
| 661 |
{ |
828 |
{ |
| 662 |
try |
829 |
try |
|
Lines 676-713
Link Here
|
| 676 |
return false; |
843 |
return false; |
| 677 |
} |
844 |
} |
| 678 |
|
845 |
|
|
|
846 |
/** |
| 847 |
* This method was used in EMF 2.4 and earlier to obtain an <code>ImportOperation</code> for installing a project from a zip file. |
| 848 |
* This implementation now merely returns null. |
| 849 |
* @deprecated Use {@link #installProjectFromFile}, which handles zip files directly, and also actually creates the project and performs the import. |
| 850 |
*/ |
| 851 |
@Deprecated |
| 679 |
protected ImportOperation createZipImportOperation(ProjectDescriptor projectDescriptor, File file) throws Exception |
852 |
protected ImportOperation createZipImportOperation(ProjectDescriptor projectDescriptor, File file) throws Exception |
| 680 |
{ |
853 |
{ |
| 681 |
final ZipFile zipFile = file.getName().endsWith(".jar") ? new JarFile(file) : new ZipFile(file); |
854 |
return null; |
| 682 |
ZipFileStructureProvider zipFileStructureProvider = new ZipFileStructureProvider(zipFile); |
|
|
| 683 |
|
| 684 |
return |
| 685 |
new ImportOperation |
| 686 |
(projectDescriptor.getProject().getFullPath(), |
| 687 |
zipFileStructureProvider.getRoot(), |
| 688 |
zipFileStructureProvider, |
| 689 |
OVERWRITE_ALL_QUERY) |
| 690 |
{ |
| 691 |
@Override |
| 692 |
protected void execute(IProgressMonitor progressMonitor) |
| 693 |
{ |
| 694 |
try |
| 695 |
{ |
| 696 |
super.execute(progressMonitor); |
| 697 |
} |
| 698 |
finally |
| 699 |
{ |
| 700 |
try |
| 701 |
{ |
| 702 |
zipFile.close(); |
| 703 |
} |
| 704 |
catch (IOException exception) |
| 705 |
{ |
| 706 |
// Ignore. |
| 707 |
} |
| 708 |
} |
| 709 |
} |
| 710 |
}; |
| 711 |
} |
855 |
} |
| 712 |
|
856 |
|
| 713 |
protected IWorkbench getWorkbench() |
857 |
protected IWorkbench getWorkbench() |