Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 79721 Details for
Bug 83258
[jar exporter] Deploy java application as executable jar
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
fix
fix_83258.txt (text/plain), 138.91 KB, created by
Benno Baumgartner
on 2007-10-04 09:51:42 EDT
(
hide
)
Description:
fix
Filename:
MIME Type:
Creator:
Benno Baumgartner
Created:
2007-10-04 09:51:42 EDT
Size:
138.91 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui.tests >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/META-INF/MANIFEST.MF,v >retrieving revision 1.4 >diff -u -r1.4 MANIFEST.MF >--- META-INF/MANIFEST.MF 27 Sep 2007 09:32:38 -0000 1.4 >+++ META-INF/MANIFEST.MF 4 Oct 2007 13:50:08 -0000 >@@ -25,6 +25,7 @@ > org.eclipse.jdt.ui.tests.core;x-internal:=true, > org.eclipse.jdt.ui.tests.core.source;x-internal:=true, > org.eclipse.jdt.ui.tests.dialogs;x-internal:=true, >+ org.eclipse.jdt.ui.tests.jarexport;x-internal:=true, > org.eclipse.jdt.ui.tests.leaks;x-internal:=true, > org.eclipse.jdt.ui.tests.model;x-internal:=true, > org.eclipse.jdt.ui.tests.packageview;x-internal:=true, >Index: test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java,v >retrieving revision 1.50 >diff -u -r1.50 JavaProjectHelper.java >--- test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java 29 May 2007 18:18:29 -0000 1.50 >+++ test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java 4 Oct 2007 13:50:08 -0000 >@@ -339,6 +339,20 @@ > * @throws CoreException Creation failed > */ > public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] inclusionFilters, IPath[] exclusionFilters) throws CoreException { >+ return addSourceContainer(jproject, containerName, inclusionFilters, exclusionFilters, null); >+ } >+ >+ /** >+ * Adds a source container to a IJavaProject. >+ * @param jproject The parent project >+ * @param containerName The name of the new source container >+ * @param inclusionFilters Inclusion filters to set >+ * @param exclusionFilters Exclusion filters to set >+ * @param outputLocation The location where class files are written to, <b>null</b> for project output folder >+ * @return The handle to the new source container >+ * @throws CoreException Creation failed >+ */ >+ public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] inclusionFilters, IPath[] exclusionFilters, String outputLocation) throws CoreException { > IProject project= jproject.getProject(); > IContainer container= null; > if (containerName == null || containerName.length() == 0) { >@@ -352,7 +366,15 @@ > } > IPackageFragmentRoot root= jproject.getPackageFragmentRoot(container); > >- IClasspathEntry cpe= JavaCore.newSourceEntry(root.getPath(), inclusionFilters, exclusionFilters, null); >+ IPath outputPath= null; >+ if (outputLocation != null) { >+ IFolder folder= project.getFolder(outputLocation); >+ if (!folder.exists()) { >+ CoreUtility.createFolder(folder, false, true, null); >+ } >+ outputPath= folder.getFullPath(); >+ } >+ IClasspathEntry cpe= JavaCore.newSourceEntry(root.getPath(), inclusionFilters, exclusionFilters, outputPath); > addToClasspath(jproject, cpe); > return root; > } >Index: ui/org/eclipse/jdt/ui/tests/AutomatedSuite.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/AutomatedSuite.java,v >retrieving revision 1.50 >diff -u -r1.50 AutomatedSuite.java >--- ui/org/eclipse/jdt/ui/tests/AutomatedSuite.java 6 Aug 2007 13:55:58 -0000 1.50 >+++ ui/org/eclipse/jdt/ui/tests/AutomatedSuite.java 4 Oct 2007 13:50:08 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -21,6 +21,7 @@ > import org.eclipse.jdt.ui.tests.buildpath.BuildpathModifierActionTest; > import org.eclipse.jdt.ui.tests.callhierarchy.CallHierarchyContentProviderTest; > import org.eclipse.jdt.ui.tests.core.CoreTests; >+import org.eclipse.jdt.ui.tests.jarexport.JarExportTests; > import org.eclipse.jdt.ui.tests.packageview.PackageExplorerTests; > import org.eclipse.jdt.ui.tests.quickfix.QuickFixTest; > import org.eclipse.jdt.ui.tests.search.SearchTest; >@@ -67,6 +68,8 @@ > addTest(JUnitJUnitTests.suite()); > > addTest(BuildpathModifierActionTest.suite()); >+ >+ addTest(JarExportTests.suite()); > } > } > >Index: ui/org/eclipse/jdt/ui/tests/jarexport/JarExportTests.java >=================================================================== >RCS file: ui/org/eclipse/jdt/ui/tests/jarexport/JarExportTests.java >diff -N ui/org/eclipse/jdt/ui/tests/jarexport/JarExportTests.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/ui/tests/jarexport/JarExportTests.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,25 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.ui.tests.jarexport; >+ >+import junit.framework.Test; >+import junit.framework.TestSuite; >+ >+public class JarExportTests { >+ >+ public static Test suite() { >+ TestSuite suite= new TestSuite("Test for org.eclipse.jdt.ui.tests.jarexport"); >+ //$JUnit-BEGIN$ >+ suite.addTest(FatJarExportTests.allTests()); >+ //$JUnit-END$ >+ return suite; >+ } >+} >Index: ui/org/eclipse/jdt/ui/tests/jarexport/FatJarExportTests.java >=================================================================== >RCS file: ui/org/eclipse/jdt/ui/tests/jarexport/FatJarExportTests.java >diff -N ui/org/eclipse/jdt/ui/tests/jarexport/FatJarExportTests.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/ui/tests/jarexport/FatJarExportTests.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,311 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.ui.tests.jarexport; >+ >+import java.io.File; >+import java.util.zip.ZipFile; >+ >+import junit.framework.Test; >+import junit.framework.TestCase; >+import junit.framework.TestSuite; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.MultiStatus; >+import org.eclipse.core.runtime.Path; >+ >+import org.eclipse.core.resources.IMarker; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IncrementalProjectBuilder; >+import org.eclipse.core.resources.ResourcesPlugin; >+ >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PlatformUI; >+ >+import org.eclipse.debug.core.DebugPlugin; >+import org.eclipse.debug.core.ILaunchConfiguration; >+import org.eclipse.debug.core.ILaunchConfigurationType; >+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; >+import org.eclipse.debug.core.ILaunchManager; >+ >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.jdt.core.JavaCore; >+ >+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; >+ >+import org.eclipse.jdt.ui.JavaUI; >+import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable; >+import org.eclipse.jdt.ui.jarpackager.JarPackageData; >+ >+import org.eclipse.jdt.internal.ui.JavaPlugin; >+import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil; >+import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarBuilder; >+import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarPackageWizardPage; >+import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext; >+ >+import org.eclipse.jdt.testplugin.JavaProjectHelper; >+import org.eclipse.jdt.testplugin.JavaTestPlugin; >+ >+import org.eclipse.jdt.ui.tests.core.ProjectTestSetup; >+ >+public class FatJarExportTests extends TestCase { >+ >+ private static final Class THIS= FatJarExportTests.class; >+ >+ public static Test suite() { >+ return allTests(); >+ } >+ >+ public static Test allTests() { >+ return new ProjectTestSetup(new TestSuite(THIS)); >+ } >+ >+ private IJavaProject fProject; >+ private IPackageFragmentRoot fMainRoot; >+ >+ /** >+ * {@inheritDoc} >+ */ >+ protected void setUp() throws Exception { >+ fProject= ProjectTestSetup.getProject(); >+ >+ fMainRoot= JavaProjectHelper.addSourceContainer(fProject, "src"); >+ IPackageFragment fragment= fMainRoot.createPackageFragment("org.eclipse.jdt.ui.test", true, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package org.eclipse.jdt.ui.test;\n"); >+ buf.append("import mylib.Foo;\n"); >+ buf.append("public class Main {\n"); >+ buf.append(" public static void main(String[] args) {\n"); >+ buf.append(" new Foo();\n"); >+ buf.append(" new Foo.FooInner();\n"); >+ buf.append(" new Foo.FooInner.FooInnerInner();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ fragment.createCompilationUnit("Main.java", buf.toString(), true, null); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ protected void tearDown() throws Exception { >+ JavaProjectHelper.clear(fProject, ProjectTestSetup.getDefaultClasspath()); >+ } >+ >+ private static String getFooContent() { >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package mylib;\n"); >+ buf.append("public class Foo {\n"); >+ buf.append(" public static class FooInner {\n"); >+ buf.append(" public static class FooInnerInner {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ return buf.toString(); >+ } >+ >+ private static void assertFatJarExport(IJavaProject project, String archiveName) throws Exception { >+ //create class files >+ ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); >+ >+ IMarker[] markers= ResourcesPlugin.getWorkspace().getRoot().findMarkers(null, true, IResource.DEPTH_INFINITE); >+ for (int i= 0; i < markers.length; i++) { >+ IMarker marker= markers[i]; >+ if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_ERROR) { >+ assertTrue((String) marker.getAttribute(IMarker.MESSAGE), false); >+ } >+ } >+ >+ //create data >+ JarPackageData data= createJarPackageData(project, archiveName); >+ >+ //create archive >+ ZipFile generatedArchive= createArchive(data); >+ >+ //assert archive content as expected >+ assertNotNull(generatedArchive); >+ assertNotNull(generatedArchive.getEntry("org/eclipse/jdt/ui/test/Main.class")); >+ assertNotNull(generatedArchive.getEntry("mylib/Foo.class")); >+ assertNotNull(generatedArchive.getEntry("mylib/Foo$FooInner.class")); >+ assertNotNull(generatedArchive.getEntry("mylib/Foo$FooInner$FooInnerInner.class")); >+ } >+ >+ private static JarPackageData createJarPackageData(IJavaProject project, String archiveName) throws CoreException { >+ JarPackageData data= new JarPackageData(); >+ data.setJarBuilder(new FatJarBuilder()); >+ >+ IPath destination= ResourcesPlugin.getWorkspace().getRoot().getLocation().append(archiveName); >+ data.setJarLocation(destination); >+ >+ ILaunchConfiguration launchConfig= createTempLaunchConfig(project); >+ >+ MultiStatus status= new MultiStatus(JavaUI.ID_PLUGIN, 0, "", null); >+ Object[] children= FatJarPackageWizardPage.getSelectedElementsWithoutContainedChildren(launchConfig, data, new BusyIndicatorRunnableContext(), status); >+ assertTrue(getProblems(status), status.getSeverity() == IStatus.OK || status.getSeverity() == IStatus.INFO); >+ data.setElements(children); >+ return data; >+ } >+ >+ private static String getProblems(MultiStatus status) { >+ StringBuffer result= new StringBuffer(); >+ >+ IStatus[] children= status.getChildren(); >+ for (int i= 0; i < children.length; i++) { >+ result.append(children[i].getMessage()).append("\n"); >+ } >+ >+ return result.toString(); >+ } >+ >+ /* >+ * From org.eclipse.jdt.internal.debug.ui.launcher.JavaApplicationLaunchShortcut >+ * >+ * For internal use only (testing), clients must not call. >+ */ >+ public static ILaunchConfiguration createTempLaunchConfig(IJavaProject project) { >+ String projectName= project.getElementName(); >+ >+ String configname= "fatjar_cfg_eraseme_" + projectName; //$NON-NLS-1$ >+ ILaunchConfiguration config= null; >+ ILaunchConfigurationWorkingCopy wc= null; >+ try { >+ ILaunchManager launchManager= DebugPlugin.getDefault().getLaunchManager(); >+ ILaunchConfigurationType configType= launchManager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION); >+ wc= configType.newInstance(null, launchManager.generateUniqueLaunchConfigurationNameFrom(configname)); >+ } catch (CoreException e) { >+ JavaPlugin.log(e); >+ return null; >+ } >+ >+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.eclipse.jdt.ui.test.Main"); >+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName); >+ try { >+ config= wc.doSave(); >+ } catch (CoreException e) { >+ JavaPlugin.log(e); >+ } >+ >+ return config; >+ } >+ >+ private static ZipFile createArchive(JarPackageData data) throws Exception, CoreException { >+ IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); >+ >+ IJarExportRunnable op= data.createJarExportRunnable(window.getShell()); >+ window.run(false, false, op); >+ >+ IStatus status= op.getStatus(); >+ if (status.getSeverity() == IStatus.ERROR) >+ throw new CoreException(status); >+ >+ return JarPackagerUtil.getArchiveFile(data.getJarLocation()); >+ } >+ >+ public void testExportSameSrcRoot() throws Exception { >+ IPackageFragment pack= fMainRoot.createPackageFragment("mylib", true, null); >+ try { >+ pack.createCompilationUnit("Foo.java", getFooContent(), true, null); >+ >+ assertFatJarExport(fProject, getName() + ".jar"); >+ } finally { >+ pack.delete(true, null); >+ } >+ } >+ >+ public void testExportSrcRootWithOutputFolder() throws Exception { >+ IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(fProject, "other", new IPath[0], new IPath[0], "otherout"); >+ try { >+ IPackageFragment pack= root.createPackageFragment("mylib", true, null); >+ pack.createCompilationUnit("Foo.java", getFooContent(), true, null); >+ >+ assertFatJarExport(fProject, getName() + ".jar"); >+ } finally { >+ JavaProjectHelper.removeSourceContainer(fProject, root.getElementName()); >+ } >+ } >+ >+ public void testExportOtherSrcRoot() throws Exception { >+ IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(fProject, "other"); >+ try { >+ IPackageFragment pack= root.createPackageFragment("mylib", true, null); >+ pack.createCompilationUnit("Foo.java", getFooContent(), true, null); >+ >+ assertFatJarExport(fProject, getName() + ".jar"); >+ } finally { >+ JavaProjectHelper.removeSourceContainer(fProject, root.getElementName()); >+ } >+ } >+ >+ public void testExportOtherProject() throws Exception { >+ IJavaProject otherProject= JavaProjectHelper.createJavaProject("OtherProject", "bin"); >+ try { >+ otherProject.setRawClasspath(ProjectTestSetup.getDefaultClasspath(), null); >+ >+ IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(otherProject, "other"); >+ IPackageFragment pack= root.createPackageFragment("mylib", true, null); >+ pack.createCompilationUnit("Foo.java", getFooContent(), true, null); >+ >+ JavaProjectHelper.addRequiredProject(fProject, otherProject); >+ >+ assertFatJarExport(fProject, getName() + ".jar"); >+ } finally { >+ JavaProjectHelper.removeFromClasspath(fProject, otherProject.getProject().getFullPath()); >+ JavaProjectHelper.delete(otherProject); >+ } >+ } >+ >+ public void testExportInternalLib() throws Exception { >+ File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB); >+ IPackageFragmentRoot root= JavaProjectHelper.addLibraryWithImport(fProject, Path.fromOSString(lib.getPath()), null, null); >+ >+ try { >+ assertFatJarExport(fProject, getName() + ".jar"); >+ } finally { >+ JavaProjectHelper.removeFromClasspath(fProject, root.getPath()); >+ } >+ } >+ >+ public void testExportExternalLib() throws Exception { >+ File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB); >+ IPackageFragmentRoot root= JavaProjectHelper.addLibrary(fProject, Path.fromOSString(lib.getPath())); >+ >+ try { >+ assertFatJarExport(fProject, getName() + ".jar"); >+ } finally { >+ JavaProjectHelper.removeFromClasspath(fProject, root.getPath()); >+ } >+ } >+ >+ public void testClassFolder() throws Exception { >+ File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB); >+ >+ IPackageFragmentRoot root= JavaProjectHelper.addClassFolderWithImport(fProject, "cf", null, null, lib); >+ try { >+ assertFatJarExport(fProject, getName() + ".jar"); >+ } finally { >+ JavaProjectHelper.removeFromClasspath(fProject, root.getPath()); >+ } >+ } >+ >+ public void testVariable() throws Exception { >+ File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB); >+ JavaCore.setClasspathVariable("MYLIB", Path.fromOSString(lib.getPath()), null); >+ >+ JavaProjectHelper.addVariableEntry(fProject, new Path("MYLIB"), null, null); >+ try { >+ assertFatJarExport(fProject, getName() + ".jar"); >+ } finally { >+ JavaProjectHelper.removeFromClasspath(fProject, new Path("MYLIB")); >+ } >+ } >+} >#P org.eclipse.jdt.ui >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/plugin.properties,v >retrieving revision 1.480 >diff -u -r1.480 plugin.properties >--- plugin.properties 2 Oct 2007 12:14:14 -0000 1.480 >+++ plugin.properties 4 Oct 2007 13:50:11 -0000 >@@ -191,6 +191,8 @@ > jarExportWizard.label=JAR file > jarExportWizard.description=Export resources into a JAR file on the local file system. > >+fatJarExportWizard.label=Runnable JAR file >+fatJarExportWizard.description=Export all resources required to run an application into a JAR file on the local file system. > > createJarAction.label=Create &JAR > createJarAction.tooltip=Creates the JAR Based on the Selected JAR Description File >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/plugin.xml,v >retrieving revision 1.764 >diff -u -r1.764 plugin.xml >--- plugin.xml 3 Oct 2007 17:07:13 -0000 1.764 >+++ plugin.xml 4 Oct 2007 13:50:12 -0000 >@@ -1917,6 +1917,19 @@ > class="org.eclipse.core.resources.IResource"> > </selection> > </wizard> >+ <wizard >+ name="%fatJarExportWizard.label" >+ icon="$nl$/icons/full/etool16/exportfatjar_wiz.gif" >+ class="org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarPackageWizard" >+ category="org.eclipse.jdt.ui.Java" >+ id="org.eclipse.jdt.internal.ui.fatjarpackager.JarPackageWizard"> >+ <description> >+ %fatJarExportWizard.description >+ </description> >+ <selection >+ class="org.eclipse.core.resources.IResource"> >+ </selection> >+ </wizard> > </extension> > <extension > point="org.eclipse.ui.popupMenus"> >Index: apichanges_jdt-ui.html >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/apichanges_jdt-ui.html,v >retrieving revision 1.47 >diff -u -r1.47 apichanges_jdt-ui.html >--- apichanges_jdt-ui.html 12 Sep 2007 13:02:18 -0000 1.47 >+++ apichanges_jdt-ui.html 4 Oct 2007 13:50:11 -0000 >@@ -105,6 +105,18 @@ > </ul> > </td> > </tr> >+ <tr> >+ <td> >+ Added API for the jar packager: >+ <ul> >+ <li>Added <code>org.eclipse.jdt.ui.jarpackager.IJarBuilder</code></li> >+ <li>Added methods to set and get jar builder in <code>org.eclipse.jdt.ui.jarpackager.JarPackageData</code></li> >+ <li>Added factories to create jar builders in <code>org.eclipse.jdt.ui.jarpackager.JarPackageData</code></li> >+ <li>Added methods to set and get launch configuration name in <code>org.eclipse.jdt.ui.jarpackager.JarPackageData</code></li> >+ <li>Added method <code>org.eclipse.jdt.ui.jarpackager.JarWriter3.addEntry(JarEntry, InputStream)</code></li> >+ </ul> >+ </td> >+ </tr> > </tbody> > </table> > <p> >Index: ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWizardPage.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWizardPage.java,v >retrieving revision 1.77 >diff -u -r1.77 JarPackageWizardPage.java >--- ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWizardPage.java 29 May 2007 18:41:48 -0000 1.77 >+++ ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWizardPage.java 4 Oct 2007 13:50:13 -0000 >@@ -10,7 +10,6 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.jarpackager; > >-import java.io.File; > import java.lang.reflect.InvocationTargetException; > import java.util.HashSet; > import java.util.Iterator; >@@ -20,7 +19,6 @@ > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Path; > > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IFolder; >@@ -36,10 +34,7 @@ > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.widgets.Button; >-import org.eclipse.swt.widgets.Combo; > import org.eclipse.swt.widgets.Composite; >-import org.eclipse.swt.widgets.Event; >-import org.eclipse.swt.widgets.FileDialog; > import org.eclipse.swt.widgets.Label; > import org.eclipse.swt.widgets.Link; > import org.eclipse.swt.widgets.TreeItem; >@@ -56,7 +51,6 @@ > import org.eclipse.jface.wizard.IWizardPage; > > import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.dialogs.WizardExportResourcesPage; > > import org.eclipse.ltk.core.refactoring.RefactoringCore; > import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService; >@@ -82,13 +76,12 @@ > import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; > import org.eclipse.jdt.internal.ui.filters.EmptyInnerPackageFilter; > import org.eclipse.jdt.internal.ui.util.ExceptionHandler; >-import org.eclipse.jdt.internal.ui.util.SWTUtil; > import org.eclipse.jdt.internal.ui.viewsupport.LibraryFilter; > > /** > * Page 1 of the JAR Package wizard > */ >-class JarPackageWizardPage extends WizardExportResourcesPage implements IJarPackageWizardPage { >+class JarPackageWizardPage extends AbstractJarDestinationWizardPage { > > private JarPackageData fJarPackage; > private IStructuredSelection fInitialSelection; >@@ -101,9 +94,6 @@ > private Button fExportRefactoringsCheckbox; > private Link fRefactoringLink; > >- private Combo fDestinationNamesCombo; >- private Button fDestinationBrowseButton; >- > private Button fCompressCheckbox; > private Button fOverwriteCheckbox; > private Button fIncludeDirectoryEntriesCheckbox; >@@ -116,8 +106,6 @@ > private static final String STORE_EXPORT_OUTPUT_FOLDERS= PAGE_NAME + ".EXPORT_OUTPUT_FOLDER"; //$NON-NLS-1$ > private static final String STORE_EXPORT_JAVA_FILES= PAGE_NAME + ".EXPORT_JAVA_FILES"; //$NON-NLS-1$ > >- private static final String STORE_DESTINATION_NAMES= PAGE_NAME + ".DESTINATION_NAMES_ID"; //$NON-NLS-1$ >- > private static final String STORE_REFACTORINGS= PAGE_NAME + ".REFACTORINGS"; //$NON-NLS-1$ > private static final String STORE_COMPRESS= PAGE_NAME + ".COMPRESS"; //$NON-NLS-1$ > private final static String STORE_OVERWRITE= PAGE_NAME + ".OVERWRITE"; //$NON-NLS-1$ >@@ -129,9 +117,12 @@ > > /** > * Create an instance of this class >+ * >+ * @param jarPackage an object containing all required information to make an export >+ * @param selection the initial selection > */ > public JarPackageWizardPage(JarPackageData jarPackage, IStructuredSelection selection) { >- super(PAGE_NAME, selection); >+ super(PAGE_NAME, selection, jarPackage); > setTitle(JarPackagerMessages.JarPackageWizardPage_title); > setDescription(JarPackagerMessages.JarPackageWizardPage_description); > fJarPackage= jarPackage; >@@ -207,39 +198,6 @@ > } > > /** >- * Answer the contents of the destination specification widget. If this >- * value does not have the required suffix then add it first. >- * >- * @return java.lang.String >- */ >- protected String getDestinationValue() { >- String destinationText= fDestinationNamesCombo.getText().trim(); >- if (destinationText.indexOf('.') < 0) >- destinationText += getOutputSuffix(); >- return destinationText; >- } >- >- /** >- * Answer the string to display in self as the destination type >- * >- * @return java.lang.String >- */ >- protected String getDestinationLabel() { >- return JarPackagerMessages.JarPackageWizardPage_destination_label; >- } >- >- /** >- * Answer the suffix that files exported from this wizard must have. >- * If this suffix is a file extension (which is typically the case) >- * then it must include the leading period character. >- * >- * @return java.lang.String >- */ >- protected String getOutputSuffix() { >- return "." + JarPackagerUtil.JAR_EXTENSION; //$NON-NLS-1$ >- } >- >- /** > * Returns an iterator over this page's collection of currently-specified > * elements to be exported. This is the primary element selection facility > * accessor for subclasses. >@@ -257,15 +215,10 @@ > * <code>internalSaveWidgetValues</code>. > */ > public final void saveWidgetValues() { >+ super.saveWidgetValues(); > // update directory names history > IDialogSettings settings= getDialogSettings(); > if (settings != null) { >- String[] directoryNames= settings.getArray(STORE_DESTINATION_NAMES); >- if (directoryNames == null) >- directoryNames= new String[0]; >- directoryNames= addToHistory(directoryNames, getDestinationValue()); >- settings.put(STORE_DESTINATION_NAMES, directoryNames); >- > settings.put(STORE_EXPORT_CLASS_FILES, fJarPackage.areClassFilesExported()); > settings.put(STORE_EXPORT_OUTPUT_FOLDERS, fJarPackage.areOutputFoldersExported()); > settings.put(STORE_EXPORT_JAVA_FILES, fJarPackage.areJavaFilesExported()); >@@ -298,21 +251,7 @@ > fExportOutputFoldersCheckbox.setSelection(fJarPackage.areOutputFoldersExported()); > fExportJavaFilesCheckbox.setSelection(fJarPackage.areJavaFilesExported()); > >- // destination >- if (fJarPackage.getJarLocation().isEmpty()) >- fDestinationNamesCombo.setText(""); //$NON-NLS-1$ >- else >- fDestinationNamesCombo.setText(fJarPackage.getJarLocation().toOSString()); >- IDialogSettings settings= getDialogSettings(); >- if (settings != null) { >- String[] directoryNames= settings.getArray(STORE_DESTINATION_NAMES); >- if (directoryNames == null) >- return; // ie.- no settings stored >- if (! fDestinationNamesCombo.getText().equals(directoryNames[0])) >- fDestinationNamesCombo.add(fDestinationNamesCombo.getText()); >- for (int i= 0; i < directoryNames.length; i++) >- fDestinationNamesCombo.add(directoryNames[i]); >- } >+ super.restoreWidgetValues(); > > // options > if (fExportRefactoringsCheckbox != null) >@@ -326,6 +265,8 @@ > * Initializes the JAR package from last used wizard page values. > */ > protected void initializeJarPackage() { >+ super.initializeJarPackage(); >+ > IDialogSettings settings= getDialogSettings(); > if (settings != null) { > // source >@@ -339,12 +280,6 @@ > fJarPackage.setCompress(settings.getBoolean(STORE_COMPRESS)); > fJarPackage.setIncludeDirectoryEntries(settings.getBoolean(STORE_INCLUDE_DIRECTORY_ENTRIES)); > fJarPackage.setOverwrite(settings.getBoolean(STORE_OVERWRITE)); >- >- // destination >- String[] directoryNames= settings.getArray(STORE_DESTINATION_NAMES); >- if (directoryNames == null) >- return; // ie.- no settings stored >- fJarPackage.setJarLocation(Path.fromOSString(directoryNames[0])); > } > } > >@@ -365,16 +300,7 @@ > fJarPackage.setExportJavaFiles(fExportJavaFilesCheckbox.getSelection()); > fJarPackage.setElements(getSelectedElements()); > >- // destination >- String comboText= fDestinationNamesCombo.getText(); >- IPath path= Path.fromOSString(comboText); >- >- if (path.segmentCount() > 0 && ensureTargetFileIsValid(path.toFile()) && path.getFileExtension() == null) >- // append .jar >- path= path.addFileExtension(JarPackagerUtil.JAR_EXTENSION); >- >- fJarPackage.setJarLocation(path); >- >+ super.updateModel(); > // options > if (fExportRefactoringsCheckbox != null) > fJarPackage.setRefactoringAware(fExportRefactoringsCheckbox.getSelection()); >@@ -386,85 +312,6 @@ > } > > /** >- * Returns a boolean indicating whether the passed File handle is >- * is valid and available for use. >- * >- * @return boolean >- */ >- protected boolean ensureTargetFileIsValid(File targetFile) { >- if (targetFile.exists() && targetFile.isDirectory() && fDestinationNamesCombo.getText().length() > 0) { >- setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_exportDestinationMustNotBeDirectory); >- fDestinationNamesCombo.setFocus(); >- return false; >- } >- if (targetFile.exists()) { >- if (!targetFile.canWrite()) { >- setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_jarFileExistsAndNotWritable); >- fDestinationNamesCombo.setFocus(); >- return false; >- } >- } >- return true; >- } >- >- /* >- * Overrides method from WizardExportPage >- */ >- protected void createDestinationGroup(Composite parent) { >- >- initializeDialogUnits(parent); >- >- // destination specification group >- Composite destinationSelectionGroup= new Composite(parent, SWT.NONE); >- GridLayout layout= new GridLayout(); >- layout.numColumns= 3; >- destinationSelectionGroup.setLayout(layout); >- destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); >- >- new Label(destinationSelectionGroup, SWT.NONE).setText(getDestinationLabel()); >- >- // destination name entry field >- fDestinationNamesCombo= new Combo(destinationSelectionGroup, SWT.SINGLE | SWT.BORDER); >- fDestinationNamesCombo.addListener(SWT.Modify, this); >- fDestinationNamesCombo.addListener(SWT.Selection, this); >- GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); >- data.widthHint= SIZING_TEXT_FIELD_WIDTH; >- fDestinationNamesCombo.setLayoutData(data); >- >- // destination browse button >- fDestinationBrowseButton= new Button(destinationSelectionGroup, SWT.PUSH); >- fDestinationBrowseButton.setText(JarPackagerMessages.JarPackageWizardPage_browseButton_text); >- fDestinationBrowseButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); >- SWTUtil.setButtonDimensionHint(fDestinationBrowseButton); >- fDestinationBrowseButton.addSelectionListener(new SelectionAdapter() { >- public void widgetSelected(SelectionEvent e) { >- handleDestinationBrowseButtonPressed(); >- } >- }); >- } >- >- /** >- * Open an appropriate destination browser so that the user can specify a source >- * to import from >- */ >- protected void handleDestinationBrowseButtonPressed() { >- FileDialog dialog= new FileDialog(getContainer().getShell(), SWT.SAVE); >- dialog.setFilterExtensions(new String[] {"*.jar", "*.zip"}); //$NON-NLS-1$ //$NON-NLS-2$ >- >- String currentSourceString= getDestinationValue(); >- int lastSeparatorIndex= currentSourceString.lastIndexOf(File.separator); >- if (lastSeparatorIndex != -1) { >- dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex)); >- dialog.setFileName(currentSourceString.substring(lastSeparatorIndex + 1, currentSourceString.length())); >- } >- else >- dialog.setFileName(currentSourceString); >- String selectedFileName= dialog.open(); >- if (selectedFileName != null) >- fDestinationNamesCombo.setText(selectedFileName); >- } >- >- /** > * Returns the resource for the specified path. > * > * @param path the path for which the resource should be returned >@@ -655,21 +502,6 @@ > setErrorMessage(null); > return complete; > } >- >- /* >- * Implements method from Listener >- */ >- public void handleEvent(Event e) { >- if (getControl() == null) >- return; >- update(); >- } >- >- protected void update() { >- updateModel(); >- updateWidgetEnablements(); >- updatePageCompletion(); >- } > > protected void updatePageCompletion() { > boolean pageComplete= isPageComplete(); >@@ -691,51 +523,6 @@ > /* > * Overrides method from WizardDataTransferPage > */ >- protected boolean validateDestinationGroup() { >- if (fDestinationNamesCombo.getText().length() == 0) { >- // Clear error >- if (getErrorMessage() != null) >- setErrorMessage(null); >- if (getMessage() != null) >- setMessage(null); >- return false; >- } >- if (fJarPackage.getAbsoluteJarLocation().toString().endsWith("/")) { //$NON-NLS-1$ >- setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_exportDestinationMustNotBeDirectory); >- fDestinationNamesCombo.setFocus(); >- return false; >- } >- // Check if the Jar is put into the workspace and conflicts with the containers >- // exported. If the workspace isn't on the local files system we are fine since >- // the Jar is always created in the local file system >- IPath workspaceLocation= ResourcesPlugin.getWorkspace().getRoot().getLocation(); >- if (workspaceLocation != null && workspaceLocation.isPrefixOf(fJarPackage.getAbsoluteJarLocation())) { >- int segments= workspaceLocation.matchingFirstSegments(fJarPackage.getAbsoluteJarLocation()); >- IPath path= fJarPackage.getAbsoluteJarLocation().removeFirstSegments(segments); >- IResource resource= ResourcesPlugin.getWorkspace().getRoot().findMember(path); >- if (resource != null && resource.getType() == IResource.FILE) { >- // test if included >- if (JarPackagerUtil.contains(JarPackagerUtil.asResources(fJarPackage.getElements()), (IFile)resource)) { >- setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_cantExportJARIntoItself); >- return false; >- } >- } >- } >- // Inform user about relative directory >- String currentMessage= getMessage(); >- if (!(new File(fDestinationNamesCombo.getText()).isAbsolute())) { >- if (currentMessage == null) >- setMessage(JarPackagerMessages.JarPackageWizardPage_info_relativeExportDestination, IMessageProvider.INFORMATION); >- } else { >- if (currentMessage != null) >- setMessage(null); >- } >- return ensureTargetFileIsValid(fJarPackage.getAbsoluteJarLocation().toFile()); >- } >- >- /* >- * Overrides method from WizardDataTransferPage >- */ > protected boolean validateOptionsGroup() { > return true; > } >@@ -799,13 +586,6 @@ > return null; > } > >- /** >- * Set the current input focus to self's destination entry field >- */ >- protected void giveFocusToDestination() { >- fDestinationNamesCombo.setFocus(); >- } >- > /* > * Overrides method from WizardExportResourcePage > */ >@@ -849,13 +629,6 @@ > } > > /* >- * Implements method from IJarPackageWizardPage. >- */ >- public void finish() { >- saveWidgetValues(); >- } >- >- /* > * Method declared on IWizardPage. > */ > public void setPreviousPage(IWizardPage page) { >Index: ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerUtil.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerUtil.java,v >retrieving revision 1.26 >diff -u -r1.26 JarPackagerUtil.java >--- ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerUtil.java 8 Jun 2006 16:14:26 -0000 1.26 >+++ ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerUtil.java 4 Oct 2007 13:50:13 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -13,20 +13,28 @@ > import java.io.File; > import java.io.IOException; > import java.io.InputStream; >+import java.net.URI; > import java.util.ArrayList; > import java.util.Arrays; > import java.util.Iterator; > import java.util.List; > import java.util.jar.JarEntry; > import java.util.zip.CRC32; >+import java.util.zip.ZipException; >+import java.util.zip.ZipFile; >+ >+import org.eclipse.core.filesystem.EFS; >+import org.eclipse.core.filesystem.IFileStore; > > import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; > > import org.eclipse.core.resources.IContainer; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.ResourcesPlugin; > > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; >@@ -107,14 +115,15 @@ > * Computes and returns the elements as resources. > * The underlying resource is used for Java elements. > * >+ * @param elements elements for which to retrieve the resources from > * @return a List with the selected resources > */ >- public static List asResources(Object[] fSelectedElements) { >- if (fSelectedElements == null) >+ public static List asResources(Object[] elements) { >+ if (elements == null) > return null; >- List selectedResources= new ArrayList(fSelectedElements.length); >- for (int i= 0; i < fSelectedElements.length; i++) { >- Object element= fSelectedElements[i]; >+ List selectedResources= new ArrayList(elements.length); >+ for (int i= 0; i < elements.length; i++) { >+ Object element= elements[i]; > if (element instanceof IJavaElement) { > selectedResources.add(((IJavaElement)element).getResource()); > } >@@ -133,6 +142,7 @@ > /** > * Gets the name of the manifest's main class > * >+ * @param jarPackage > * @return a string with the name > */ > static String getMainClassName(JarPackageData jarPackage) { >@@ -173,6 +183,8 @@ > /** > * Tells whether the specified manifest main class is valid. > * >+ * @param data >+ * @param context > * @return <code>true</code> if a main class is specified and valid > */ > public static boolean isMainClassValid(JarPackageData data, IRunnableContext context) { >@@ -257,4 +269,45 @@ > entry.setSize(size); > entry.setCrc(crc.getValue()); > } >+ >+ /** >+ * The archive file at the given location >+ * >+ * @param location >+ * the location of the archive file >+ * @return the archive or null if it could not be retrieved >+ * @throws CoreException >+ * if the archive could not be read >+ * >+ * @since 3.4 >+ */ >+ public static ZipFile getArchiveFile(IPath location) throws CoreException { >+ File localFile= null; >+ >+ IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(location); >+ if (file != null) { >+ // internal resource >+ URI fileLocation= file.getLocationURI(); >+ >+ IFileStore fileStore= EFS.getStore(fileLocation); >+ localFile= fileStore.toLocalFile(EFS.NONE, null); >+ if (localFile == null) >+ // non local file system >+ localFile= fileStore.toLocalFile(EFS.CACHE, null); >+ } else { >+ // external resource -> it is ok to use toFile() >+ localFile= location.toFile(); >+ } >+ >+ if (localFile == null) >+ return null; >+ >+ try { >+ return new ZipFile(localFile); >+ } catch (ZipException e) { >+ throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, e.getLocalizedMessage(), e)); >+ } catch (IOException e) { >+ throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, e.getLocalizedMessage(), e)); >+ } >+ } > } >\ No newline at end of file >Index: ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.java,v >retrieving revision 1.16 >diff -u -r1.16 JarPackagerMessages.java >--- ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.java 18 Apr 2006 16:27:32 -0000 1.16 >+++ ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.java 4 Oct 2007 13:50:13 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -32,6 +32,8 @@ > > public static String JarFileExportOperation_creationOfSomeJARsFailed; > >+ public static String JarFileExportOperation_OpenZipFileError_message; >+ > public static String JarFileExportOperation_didNotAddManifestToJar; > > public static String JarFileExportOperation_errorCannotCloseConnection; >@@ -48,7 +50,7 @@ > > public static String JarFileExportOperation_errorSavingManifest; > >- public static String JarFileExportOperation_errorSavingModifiedResources; >+ public static String JarFileExportOperation_CloseZipFileError_message; > > public static String JarFileExportOperation_exportedWithCompileErrors; > >@@ -94,10 +96,6 @@ > > public static String JarFileExportOperation_savingFiles; > >- public static String JarFileExportOperation_savingModifiedResources; >- >- public static String JarFileExportOperation_underlyingResourceNotFound; >- > public static String JarManifestWizardPage_description; > > public static String JarManifestWizardPage_error_invalidMainClass; >@@ -248,6 +246,8 @@ > > public static String JarPackageReader_error_tagPathNotFound; > >+ public static String JarPackageReader_error_unknownJarBuilder; >+ > public static String JarPackageReader_jarPackageReaderWarnings; > > public static String JarPackageReader_warning_javaElementDoesNotExist; >@@ -320,38 +320,6 @@ > > public static String JarWriter_error_couldNotTransformToXML; > >- public static String JarWriter_output_compressed; >- >- public static String JarWriter_output_descriptionFile; >- >- public static String JarWriter_output_exportBin; >- >- public static String JarWriter_output_exportJava; >- >- public static String JarWriter_output_exportOutputFolders; >- >- public static String JarWriter_output_generateManifest; >- >- public static String JarWriter_output_jarFileName; >- >- public static String JarWriter_output_jarSealed; >- >- public static String JarWriter_output_lineSeparator; >- >- public static String JarWriter_output_mainClass; >- >- public static String JarWriter_output_manifestName; >- >- public static String JarWriter_output_overwrite; >- >- public static String JarWriter_output_reuseManifest; >- >- public static String JarWriter_output_saveDescription; >- >- public static String JarWriter_output_saveManifest; >- >- public static String JarWriter_output_title; >- > public static String JarWriter_writeProblem; > > public static String JarWriter_writeProblemWithMessage; >Index: ui/org/eclipse/jdt/internal/ui/jarpackager/JarFileExportOperation.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarFileExportOperation.java,v >retrieving revision 1.100 >diff -u -r1.100 JarFileExportOperation.java >--- ui/org/eclipse/jdt/internal/ui/jarpackager/JarFileExportOperation.java 23 Aug 2007 13:48:47 -0000 1.100 >+++ ui/org/eclipse/jdt/internal/ui/jarpackager/JarFileExportOperation.java 4 Oct 2007 13:50:13 -0000 >@@ -29,8 +29,10 @@ > import java.util.Set; > import java.util.jar.Manifest; > import java.util.zip.ZipException; >+import java.util.zip.ZipFile; > > import org.eclipse.core.filesystem.EFS; >+ > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; >@@ -73,10 +75,10 @@ > import org.eclipse.jdt.internal.corext.util.Resources; > > import org.eclipse.jdt.ui.StandardJavaElementContentProvider; >+import org.eclipse.jdt.ui.jarpackager.IJarBuilder; > import org.eclipse.jdt.ui.jarpackager.IJarDescriptionWriter; > import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable; > import org.eclipse.jdt.ui.jarpackager.JarPackageData; >-import org.eclipse.jdt.ui.jarpackager.JarWriter3; > > import org.eclipse.jdt.internal.ui.IJavaStatusConstants; > import org.eclipse.jdt.internal.ui.JavaPlugin; >@@ -100,7 +102,7 @@ > } > } > >- private JarWriter3 fJarWriter; >+ private IJarBuilder fJarBuilder; > private JarPackageData fJarPackage; > private JarPackageData[] fJarPackages; > private Shell fParentShell; >@@ -206,9 +208,21 @@ > continue; > } > >- // Should not happen since we only export source files >- if (resource == null) >+ if (resource == null) { >+ if (element instanceof IPackageFragmentRoot) { >+ IPackageFragmentRoot root= (IPackageFragmentRoot) element; >+ if (root.isArchive()) { >+ try { >+ ZipFile file= JarPackagerUtil.getArchiveFile(root.getPath()); >+ if (file != null) >+ count+= file.size(); >+ } catch (CoreException e) { >+ JavaPlugin.log(e); >+ } >+ } >+ } > continue; >+ } > } > else > resource= (IResource)element; >@@ -340,8 +354,25 @@ > } > > private void exportJavaElement(IProgressMonitor progressMonitor, IJavaElement je) throws InterruptedException { >- if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && ((IPackageFragmentRoot)je).isArchive()) >+ if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && ((IPackageFragmentRoot) je).isArchive()) { >+ IPackageFragmentRoot root= (IPackageFragmentRoot) je; >+ ZipFile jarFile= null; >+ try { >+ jarFile= JarPackagerUtil.getArchiveFile(root.getPath()); >+ fJarBuilder.writeArchive(jarFile, progressMonitor); >+ } catch (CoreException e) { >+ addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_OpenZipFileError_message, new Object[] { root.getElementName(), e.getLocalizedMessage() }), e); >+ } finally { >+ try { >+ if (jarFile != null) { >+ jarFile.close(); >+ } >+ } catch (IOException e) { >+ addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_CloseZipFileError_message, new Object[] { root.getElementName(), e.getLocalizedMessage() }), e); >+ } >+ } > return; >+ } > > Object[] children= fJavaElementContentProvider.getChildren(je); > for (int i= 0; i < children.length; i++) >@@ -365,7 +396,7 @@ > try { > IPath destinationPath= resource.getFullPath().removeFirstSegments(leadingSegmentsToRemove); > progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); >- fJarWriter.write((IFile)resource, destinationPath); >+ fJarBuilder.writeFile((IFile)resource, destinationPath); > } catch (CoreException ex) { > Throwable realEx= ex.getStatus().getException(); > if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$ >@@ -428,7 +459,7 @@ > || (fJarPackage.areJavaFilesExported() && (isNonJavaResource || (pkgRoot != null && !isClassFile(resource)) || (isInClassFolder && isClassFile(resource) && !fJarPackage.areClassFilesExported())))) { > try { > progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); >- fJarWriter.write((IFile) resource, destinationPath); >+ fJarBuilder.writeFile((IFile)resource, destinationPath); > } catch (CoreException ex) { > Throwable realEx= ex.getStatus().getException(); > if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$ >@@ -462,7 +493,7 @@ > IFile file= (IFile)iter.next(); > IPath classFilePath= baseDestinationPath.append(file.getName()); > progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, classFilePath.toString())); >- fJarWriter.write(file, classFilePath); >+ fJarBuilder.writeFile(file, classFilePath); > } > } catch (CoreException ex) { > addToStatus(ex); >@@ -857,8 +888,10 @@ > buildProjects(subProgressMonitor); > } else > progressMonitor.beginTask("", totalWork); //$NON-NLS-1$ >- >- fJarWriter= fJarPackage.createJarWriter3(fParentShell); >+ >+ fJarBuilder = fJarPackage.getJarBuilder(); >+ fJarBuilder.open(fJarPackage, fParentShell, fStatus); >+ > exportSelectedElements(progressMonitor); > if (getStatus().getSeverity() != IStatus.ERROR) { > progressMonitor.subTask(JarPackagerMessages.JarFileExportOperation_savingFiles); >@@ -868,8 +901,8 @@ > addToStatus(ex); > } finally { > try { >- if (fJarWriter != null) >- fJarWriter.close(); >+ if (fJarBuilder != null) >+ fJarBuilder.close(); > } catch (CoreException ex) { > addToStatus(ex); > } >Index: ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.properties,v >retrieving revision 1.58 >diff -u -r1.58 JarPackagerMessages.properties >--- ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.properties 5 Jun 2007 11:40:50 -0000 1.58 >+++ ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.properties 4 Oct 2007 13:50:13 -0000 >@@ -34,9 +34,9 @@ > JarFileExportOperation_exportFinishedWithInfo= JAR export finished. See details for additional information. > JarFileExportOperation_exportFinishedWithWarnings= JAR export finished with warnings. See details for additional information. > JarFileExportOperation_creationOfSomeJARsFailed= Creation of some JARs failed. See details for additional information. >+JarFileExportOperation_OpenZipFileError_message=Could not read jar file ''{0}''. Reason: {1} > JarFileExportOperation_jarCreationFailed= JAR creation failed. See details for additional information. > >-JarFileExportOperation_underlyingResourceNotFound= Underlying resource not found for compilation unit: {0} > JarFileExportOperation_resourceNotFound= Resource not found or not accessible: {0} > JarFileExportOperation_projectNatureNotDeterminable= Project nature could not be determined for: {0} > JarFileExportOperation_javaPackageNotDeterminable= Java package could not be found for: {0} >@@ -45,6 +45,7 @@ > JarFileExportOperation_outputContainerNotAccessible= Output container not accessible > JarFileExportOperation_classFileOnClasspathNotAccessible= class file(s) on classpath not found or not accessible {0} > JarFileExportOperation_classFileWithoutSourceFileAttribute= Could not find source file attribute for: {0} >+JarFileExportOperation_CloseZipFileError_message=Could not close jar file ''{0}''. Reason: {1} > JarFileExportOperation_missingSourceFileAttributeExportedAll= Source name not found in a class file - exported all class files in {0} > JarFileExportOperation_exportedWithCompileErrors= Exported with compile errors: {0} > JarFileExportOperation_exportedWithCompileWarnings= Exported with compile warnings: {0} >@@ -53,7 +54,6 @@ > JarFileExportOperation_exporting= Exporting: {0} > JarFileExportOperation_jarCreationFailedSeeDetails= JAR creation failed. See details for additional information. > JarFileExportOperation_savingFiles= Saving files... >-JarFileExportOperation_savingModifiedResources= Saving modified resources... > JarFileExportOperation_noExportTypeChosen= No export type chosen > JarFileExportOperation_noResourcesSelected= No resources selected > JarFileExportOperation_invalidJarLocation= Invalid JAR location >@@ -68,7 +68,6 @@ > JarFileExportOperation_errorReadingFile= Error reading {0}: {1} > JarFileExportOperation_errorClosingJarPackageDescriptionReader= Error closing JAR package description reader for {0} > JarFileExportOperation_errorDuringProjectBuild= Build failed for project: {0} >-JarFileExportOperation_errorSavingModifiedResources= Unexpected exception while saving modified resources. See log for details. > JarFileExportOperation_errorCannotCloseConnection=Cannot close connection for ''{0}'' > > JarOptionsPage_title= JAR Packaging Options >@@ -118,6 +117,7 @@ > JarPackageReader_error_illegalValueForBooleanAttribute= Invalid format. The value for a boolean attribute is invalid. > JarPackageReader_error_tagNameNotFound= Invalid format. The tag 'name' cannot be found. > JarPackageReader_error_tagPathNotFound= Invalid format. The tag 'path' cannot be found. >+JarPackageReader_error_unknownJarBuilder=Jar builder ''{0}'' is unkown > JarPackageReader_error_tagHandleIdentifierNotFoundOrEmpty= Invalid format: The tag 'handleIdentifier' cannot be found or is empty. > JarPackageReader_warning_javaElementDoesNotExist= Warning: Java element does not exist in workspace > JarPackageReader_error_duplicateTag= Invalid format. {0} is a duplicate tag. >@@ -179,20 +179,4 @@ > JarRefactoringDialog_dialog_title=Refactoring Selection > > JarWriter_error_couldNotGetXmlBuilder = Could not get XML builder >-JarWriter_error_couldNotTransformToXML= Could not transform to XML >-JarWriter_output_title= --- JAR Package Definition: --- >-JarWriter_output_exportBin= Export class files: {0} >-JarWriter_output_exportOutputFolders= Export output folders: {0} >-JarWriter_output_exportJava= Export java files: {0} >-JarWriter_output_jarFileName= JAR file: {0} >-JarWriter_output_compressed= Compressed: {0} >-JarWriter_output_overwrite= Overwrite: {0} >-JarWriter_output_saveDescription= Save description: {0} >-JarWriter_output_descriptionFile= Description file: {0} >-JarWriter_output_lineSeparator= -- >-JarWriter_output_generateManifest= Generate manifest {0} >-JarWriter_output_saveManifest= Save manifest: {0} >-JarWriter_output_reuseManifest= Reuse manifest: {0} >-JarWriter_output_manifestName= Manifest {0} >-JarWriter_output_jarSealed= JAR sealed: {0} >-JarWriter_output_mainClass= Main-Class: {0} >+JarWriter_error_couldNotTransformToXML= Could not transform to XML >\ No newline at end of file >Index: ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageReader.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageReader.java,v >retrieving revision 1.38 >diff -u -r1.38 JarPackageReader.java >--- ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageReader.java 31 Aug 2006 09:59:16 -0000 1.38 >+++ ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageReader.java 4 Oct 2007 13:50:13 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -23,11 +23,6 @@ > import javax.xml.parsers.DocumentBuilderFactory; > import javax.xml.parsers.ParserConfigurationException; > >-import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.IFolder; >-import org.eclipse.core.resources.IProject; >-import org.eclipse.core.resources.ResourcesPlugin; >- > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; >@@ -36,6 +31,10 @@ > import org.eclipse.core.runtime.Path; > import org.eclipse.core.runtime.Status; > >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IFolder; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.ResourcesPlugin; > > import org.eclipse.ltk.core.refactoring.RefactoringCore; > import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; >@@ -43,12 +42,6 @@ > import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService; > import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; > >-import org.w3c.dom.Element; >-import org.w3c.dom.Node; >-import org.w3c.dom.NodeList; >-import org.xml.sax.InputSource; >-import org.xml.sax.SAXException; >- > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IPackageFragment; > import org.eclipse.jdt.core.IType; >@@ -56,11 +49,19 @@ > > import org.eclipse.jdt.internal.corext.util.Messages; > >+import org.eclipse.jdt.ui.jarpackager.IJarBuilder; > import org.eclipse.jdt.ui.jarpackager.IJarDescriptionReader; > import org.eclipse.jdt.ui.jarpackager.JarPackageData; > >-import org.eclipse.jdt.internal.ui.JavaPlugin; > import org.eclipse.jdt.internal.ui.IJavaStatusConstants; >+import org.eclipse.jdt.internal.ui.JavaPlugin; >+import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarBuilder; >+ >+import org.w3c.dom.Element; >+import org.w3c.dom.Node; >+import org.w3c.dom.NodeList; >+import org.xml.sax.InputSource; >+import org.xml.sax.SAXException; > > /** > * Reads data from an InputStream and returns a JarPackage >@@ -74,6 +75,7 @@ > /** > * Reads a Jar Package from the underlying stream. > * It is the client's responsibility to close the stream. >+ * @param inputStream > */ > public JarPackageReader(InputStream inputStream) { > Assert.isNotNull(inputStream); >@@ -139,6 +141,9 @@ > if (jarPackage.areGeneratedFilesExported()) > xmlReadManifest(jarPackage, element); > xmlReadSelectedElements(jarPackage, element); >+ >+ // fatjar read builder props >+ xmlReadFatjar(jarPackage, element); > } > return jarPackage; > } >@@ -403,4 +408,22 @@ > protected void addWarning(String message, Throwable error) { > fWarnings.add(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), 0, message, error)); > } >+ >+ private void xmlReadFatjar(JarPackageData jarPackage, Element element) throws java.io.IOException { >+ if (element.getNodeName().equals("fatjar")) { //$NON-NLS-1$ >+ String id = element.getAttribute("builder"); //$NON-NLS-1$ >+ IJarBuilder builder= jarPackage.getJarBuilder(); >+ if (builder == null || !builder.getId().equals(id)) { >+ if (FatJarBuilder.BUILDER_ID.equals(id)) { >+ jarPackage.setJarBuilder(jarPackage.createFatJarBuilder()); >+ } else if (PlainJarBuilder.BUILDER_ID.equals(id)) { >+ jarPackage.setJarBuilder(jarPackage.createPlainJarBuilder()); >+ } else { >+ throw new IOException(Messages.format(JarPackagerMessages.JarPackageReader_error_unknownJarBuilder, id)); >+ } >+ } >+ jarPackage.setLaunchConfigurationName(element.getAttribute("launchConfig")); //$NON-NLS-1$ >+ } >+ } >+ > } >Index: ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWriter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWriter.java,v >retrieving revision 1.37 >diff -u -r1.37 JarPackageWriter.java >--- ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWriter.java 31 Aug 2006 09:59:16 -0000 1.37 >+++ ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWriter.java 4 Oct 2007 13:50:13 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -34,7 +34,6 @@ > import org.eclipse.core.resources.IProject; > import org.eclipse.core.resources.IResource; > >- > import org.eclipse.ltk.core.refactoring.RefactoringCore; > import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; > import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; >@@ -64,6 +63,9 @@ > /** > * Create a JarPackageWriter on the given output stream. > * It is the clients responsibility to close the output stream. >+ * >+ * @param outputStream >+ * @param encoding > */ > public JarPackageWriter(OutputStream outputStream, String encoding) { > Assert.isNotNull(outputStream); >@@ -84,6 +86,7 @@ > * Writes a XML representation of the JAR specification > * to to the underlying stream. > * >+ * @param jarPackage > * @exception IOException if writing to the underlying stream fails > */ > public void writeXML(JarPackageData jarPackage) throws IOException { >@@ -109,6 +112,8 @@ > xmlWriteManifest(jarPackage, document, xmlJarDesc); > xmlWriteSelectedElements(jarPackage, document, xmlJarDesc); > >+ xmlWriteFatjar(jarPackage, document, xmlJarDesc); >+ > try { > // Write the document to the stream > Transformer transformer=TransformerFactory.newInstance().newTransformer(); >@@ -285,4 +290,11 @@ > public IStatus getStatus() { > return new Status(IStatus.OK, JavaPlugin.getPluginId(), 0, "", null); //$NON-NLS-1$ > } >+ >+ private void xmlWriteFatjar(JarPackageData jarPackage, Document document, Element xmlJarDesc) throws DOMException { >+ Element fatjar= document.createElement("fatjar"); //$NON-NLS-1$ >+ xmlJarDesc.appendChild(fatjar); >+ fatjar.setAttribute("builder", jarPackage.getJarBuilder().getId()); //$NON-NLS-1$ >+ fatjar.setAttribute("launchConfig", jarPackage.getLaunchConfigurationName()); //$NON-NLS-1$ >+ } > } >Index: ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java,v >retrieving revision 1.128 >diff -u -r1.128 JavaPluginImages.java >--- ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java 23 Aug 2007 10:44:59 -0000 1.128 >+++ ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java 4 Oct 2007 13:50:13 -0000 >@@ -394,6 +394,7 @@ > public static final ImageDescriptor DESC_WIZBAN_REFACTOR_PULL_UP= createUnManaged(T_WIZBAN, "pullup_wiz.png"); //$NON-NLS-1$ > public static final ImageDescriptor DESC_WIZBAN_REFACTOR_FIX_DEPRECATION= createUnManaged(T_WIZBAN, "fixdepr_wiz.png"); //$NON-NLS-1$ > public static final ImageDescriptor DESC_WIZBAN_JAR_PACKAGER= createUnManaged(T_WIZBAN, "jar_pack_wiz.png"); //$NON-NLS-1$ >+ public static final ImageDescriptor DESC_WIZBAN_FAT_JAR_PACKAGER= createUnManaged(T_WIZBAN, "fatjar_pack_wiz.png"); //$NON-NLS-1$ > public static final ImageDescriptor DESC_WIZBAN_REFACTOR_EXTRACT_SUPERTYPE= createUnManaged(T_WIZBAN, "extractsupertype_wiz.png"); //$NON-NLS-1$ > public static final ImageDescriptor DESC_WIZBAN_REPLACE_JAR= createUnManaged(T_WIZBAN, "replacejar_wiz.png"); //$NON-NLS-1$ > public static final ImageDescriptor DESC_WIZBAN_JAVA_WORKINGSET= createUnManaged(T_WIZBAN, "java_workingset_wiz.png");//$NON-NLS-1$ >Index: ui/org/eclipse/jdt/ui/jarpackager/JarWriter3.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/jarpackager/JarWriter3.java,v >retrieving revision 1.20 >diff -u -r1.20 JarWriter3.java >--- ui/org/eclipse/jdt/ui/jarpackager/JarWriter3.java 3 Oct 2007 09:16:40 -0000 1.20 >+++ ui/org/eclipse/jdt/ui/jarpackager/JarWriter3.java 4 Oct 2007 13:50:14 -0000 >@@ -233,14 +233,30 @@ > > InputStream contentStream = resource.getContents(false); > >+ addEntry(newEntry, contentStream); >+ } >+ >+ /** >+ * Write the given entry describing the given content to the >+ * current archive >+ * >+ * @param entry the entry to write >+ * @param content the content to write >+ * >+ * @throws IOException If an I/O error occurred >+ * >+ * @since 3.4 >+ */ >+ protected void addEntry(JarEntry entry, InputStream content) throws IOException { >+ byte[] readBuffer= new byte[4096]; > try { >- fJarOutputStream.putNextEntry(newEntry); >+ fJarOutputStream.putNextEntry(entry); > int count; >- while ((count= contentStream.read(readBuffer, 0, readBuffer.length)) != -1) >+ while ((count= content.read(readBuffer, 0, readBuffer.length)) != -1) > fJarOutputStream.write(readBuffer, 0, count); > } finally { >- if (contentStream != null) >- contentStream.close(); >+ if (content != null) >+ content.close(); > > /* > * Commented out because some JREs throw an NPE if a stream >Index: ui/org/eclipse/jdt/ui/jarpackager/JarPackageData.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/jarpackager/JarPackageData.java,v >retrieving revision 1.42 >diff -u -r1.42 JarPackageData.java >--- ui/org/eclipse/jdt/ui/jarpackager/JarPackageData.java 22 Jun 2006 09:14:49 -0000 1.42 >+++ ui/org/eclipse/jdt/ui/jarpackager/JarPackageData.java 4 Oct 2007 13:50:14 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -13,15 +13,15 @@ > import java.io.InputStream; > import java.io.OutputStream; > >-import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.IProject; >-import org.eclipse.core.resources.ResourcesPlugin; >- > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.Path; > >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.ResourcesPlugin; >+ > import org.eclipse.swt.widgets.Shell; > > import org.eclipse.jface.operation.IRunnableContext; >@@ -31,13 +31,13 @@ > import org.eclipse.jdt.core.IPackageFragment; > import org.eclipse.jdt.core.IType; > >- > import org.eclipse.jdt.internal.ui.JavaPlugin; > import org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation; > import org.eclipse.jdt.internal.ui.jarpackager.JarPackageReader; > import org.eclipse.jdt.internal.ui.jarpackager.JarPackageWriter; > import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil; >-import org.eclipse.jdt.internal.ui.jarpackager.ManifestProvider; >+import org.eclipse.jdt.internal.ui.jarpackager.PlainJarBuilder; >+import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarBuilder; > import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext; > > /** >@@ -144,6 +144,12 @@ > // The refactoring descriptors to export > private RefactoringDescriptorProxy[] fRefactoringDescriptors= {}; > >+ // Builder used by the JarFileExportOperation to build the jar file >+ private IJarBuilder fJarBuilder; >+ >+ // The launch configuration used by the fat jar builder to determine dependencies >+ private String fLaunchConfigurationName; >+ > /** > * Creates a new Jar Package Data structure > */ >@@ -474,7 +480,7 @@ > */ > public IManifestProvider getManifestProvider() { > if (fManifestProvider == null) >- fManifestProvider= new ManifestProvider(); >+ return getJarBuilder().getManifestProvider(); > return fManifestProvider; > } > >@@ -876,12 +882,37 @@ > * @throws CoreException if an unexpected exception happens > * > * @since 3.2 >+ * @deprecated use {@link #createPlainJarBuilder()} instead > */ > public JarWriter3 createJarWriter3(Shell parent) throws CoreException { > return new JarWriter3(this, parent); > } > > /** >+ * Creates and returns a jar builder capable of handling >+ * files but not archives. >+ * >+ * @return a new instance of a plain jar builder >+ * >+ * @since 3.4 >+ */ >+ public IJarBuilder createPlainJarBuilder() { >+ return new PlainJarBuilder(); >+ } >+ >+ /** >+ * Creates and returns a jar builder capable of handling >+ * files and archives. >+ * >+ * @return a new instance of a fat jar builder >+ * >+ * @since 3.4 >+ */ >+ public IJarBuilder createFatJarBuilder() { >+ return new FatJarBuilder(); >+ } >+ >+ /** > * Creates and returns a JarExportRunnable. > * > * @param parent the parent for the dialog, >@@ -1162,4 +1193,52 @@ > public void setExportStructuralOnly(boolean structural) { > fRefactoringStructural= structural; > } >+ >+ /** >+ * Returns the jar builder which can be used to build the jar >+ * described by this package data. >+ * >+ * @return the builder to use >+ * @since 3.4 >+ */ >+ public IJarBuilder getJarBuilder() { >+ if (fJarBuilder == null) >+ fJarBuilder= createPlainJarBuilder(); >+ return fJarBuilder; >+ } >+ >+ /** >+ * Set the jar builder to use to build the jar. >+ * >+ * @param jarBuilder >+ * the builder to use >+ * @since 3.4 >+ */ >+ public void setJarBuilder(IJarBuilder jarBuilder) { >+ fJarBuilder= jarBuilder; >+ } >+ >+ /** >+ * Get the name of the launch configuration from >+ * which to retrieve classpath information. >+ * >+ * @return the name of the launch configuration >+ * @since 3.4 >+ */ >+ public String getLaunchConfigurationName() { >+ return fLaunchConfigurationName; >+ } >+ >+ /** >+ * Set the name of the launch configuration form which >+ * to retrieve classpath information. >+ * >+ * @param name >+ * name of the launch configuration >+ * @since 3.4 >+ */ >+ public void setLaunchConfigurationName(String name) { >+ fLaunchConfigurationName= name; >+ } >+ > } >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.56 >diff -u -r1.56 MANIFEST.MF >--- META-INF/MANIFEST.MF 4 Sep 2007 08:40:24 -0000 1.56 >+++ META-INF/MANIFEST.MF 4 Oct 2007 13:50:12 -0000 >@@ -53,6 +53,7 @@ > org.eclipse.jdt.internal.ui.infoviews;x-internal:=true, > org.eclipse.jdt.internal.ui.jarimport;x-internal:=true, > org.eclipse.jdt.internal.ui.jarpackager;x-internal:=true, >+ org.eclipse.jdt.internal.ui.jarpackagerfat;x-internal:=true, > org.eclipse.jdt.internal.ui.javadocexport;x-internal:=true, > org.eclipse.jdt.internal.ui.javaeditor;x-friends:="org.eclipse.jdt.junit", > org.eclipse.jdt.internal.ui.javaeditor.saveparticipant;x-internal:=true, >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizardPage.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizardPage.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizardPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizardPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,515 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackagerfat; >+ >+import java.lang.reflect.InvocationTargetException; >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.MultiStatus; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Status; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.ResourcesPlugin; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Combo; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Listener; >+ >+import org.eclipse.jface.dialogs.Dialog; >+import org.eclipse.jface.dialogs.IDialogSettings; >+import org.eclipse.jface.operation.IRunnableContext; >+import org.eclipse.jface.viewers.IStructuredSelection; >+ >+import org.eclipse.debug.core.DebugPlugin; >+import org.eclipse.debug.core.ILaunchConfiguration; >+import org.eclipse.debug.core.ILaunchConfigurationType; >+import org.eclipse.debug.core.ILaunchManager; >+ >+import org.eclipse.jdt.core.IClasspathEntry; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.search.IJavaSearchScope; >+ >+import org.eclipse.jdt.internal.corext.util.Messages; >+ >+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; >+import org.eclipse.jdt.launching.IRuntimeClasspathEntry; >+import org.eclipse.jdt.launching.JavaRuntime; >+ >+import org.eclipse.jdt.ui.JavaUI; >+import org.eclipse.jdt.ui.jarpackager.JarPackageData; >+ >+import org.eclipse.jdt.internal.ui.JavaPlugin; >+import org.eclipse.jdt.internal.ui.jarpackager.AbstractJarDestinationWizardPage; >+import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil; >+import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory; >+import org.eclipse.jdt.internal.ui.util.MainMethodSearchEngine; >+ >+/** >+ * First page for the runnable jar export wizard >+ * @since 3.4 >+ */ >+public class FatJarPackageWizardPage extends AbstractJarDestinationWizardPage implements Listener { >+ >+ private abstract static class LaunchConfigurationElement { >+ >+ public abstract ILaunchConfiguration getLaunchConfiguration(); >+ >+ public abstract String getLaunchConfigurationName(); >+ >+ public void dispose() { >+ //do nothing >+ } >+ } >+ >+ private static class ExistingLaunchConfigurationElement extends LaunchConfigurationElement { >+ >+ private final ILaunchConfiguration fLaunchConfiguration; >+ private final String fProjectName; >+ >+ public ExistingLaunchConfigurationElement(ILaunchConfiguration launchConfiguration, String projectName) { >+ fLaunchConfiguration= launchConfiguration; >+ fProjectName= projectName; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public ILaunchConfiguration getLaunchConfiguration() { >+ return fLaunchConfiguration; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public String getLaunchConfigurationName() { >+ return fProjectName + " : " + fLaunchConfiguration.getName(); //$NON-NLS-1$ >+ } >+ >+ } >+ >+ private static final String PAGE_NAME= "FatJarPackageWizardPage"; //$NON-NLS-1$ >+ private static final String STORE_LAUNCH_CONFIGURATION_SELECTION_NAME= PAGE_NAME + ".LAUNCH_CONFIGURATION_SELECTION_NAME"; //$NON-NLS-1$ >+ private static final String STORE_DESTINATION_ELEMENT= PAGE_NAME + ".DESTINATION_PATH_SELECTION"; //$NON-NLS-1$ >+ >+ private final JarPackageData fJarPackage; >+ /** >+ * Model for the launch combo box. Element: {@link LaunchConfigurationElement} >+ */ >+ private final ArrayList fLauchConfigurationModel; >+ >+ private Combo fLaunchConfigurationCombo; >+ >+ public FatJarPackageWizardPage(JarPackageData jarPackage, IStructuredSelection selection) { >+ super(PAGE_NAME, selection, jarPackage); >+ setTitle(FatJarPackagerMessages.JarPackageWizardPage_title); >+ setDescription(FatJarPackagerMessages.FatJarPackageWizardPage_description); >+ fJarPackage= jarPackage; >+ fLauchConfigurationModel= new ArrayList(); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void createControl(Composite parent) { >+ Composite composite= new Composite(parent, SWT.NONE); >+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); >+ composite.setLayout(new GridLayout(1, false)); >+ >+ Label description= new Label(composite, SWT.NONE); >+ GridData gridData= new GridData(SWT.BEGINNING, SWT.CENTER, false, false); >+ description.setLayoutData(gridData); >+ description.setText(FatJarPackagerMessages.FatJarPackageWizardPage_launchConfigGroupTitle); >+ >+ createLaunchConfigSelectionGroup(composite); >+ >+ Label label= new Label(composite, SWT.NONE); >+ label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); >+ label.setText(FatJarPackagerMessages.FatJarPackageWizardPage_destinationGroupTitle); >+ >+ createDestinationGroup(composite); >+ >+ restoreWidgetValues(); >+ >+ update(); >+ >+ Dialog.applyDialogFont(composite); >+ setControl(composite); >+ } >+ >+ protected String getDestinationLabel() { >+ return null; >+ } >+ >+ private void createLaunchConfigSelectionGroup(Composite parent) { >+ Composite composite= new Composite(parent, SWT.NONE); >+ composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); >+ composite.setLayout(new GridLayout(1, false)); >+ >+ fLaunchConfigurationCombo= new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); >+ fLaunchConfigurationCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); >+ >+ fLauchConfigurationModel.addAll(Arrays.asList(getLaunchConfigurations())); >+ String[] names= new String[fLauchConfigurationModel.size()]; >+ for (int i= 0, size= fLauchConfigurationModel.size(); i < size; i++) { >+ LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(i); >+ names[i]= element.getLaunchConfigurationName(); >+ } >+ fLaunchConfigurationCombo.setItems(names); >+ >+ fLaunchConfigurationCombo.addListener(SWT.Selection, this); >+ fLaunchConfigurationCombo.addListener(SWT.Modify, this); >+ } >+ >+ protected void updateWidgetEnablements() { >+ } >+ >+ public boolean isPageComplete() { >+ boolean complete= validateDestinationGroup(); >+ complete= validateLaunchConfigurationGroup() && complete; >+ if (complete) >+ setErrorMessage(null); >+ return complete; >+ } >+ >+ private boolean validateLaunchConfigurationGroup() { >+ return fLaunchConfigurationCombo.getSelectionIndex() != -1; >+ } >+ >+ private LaunchConfigurationElement[] getLaunchConfigurations() { >+ ArrayList result= new ArrayList(); >+ >+ try { >+ ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager(); >+ ILaunchConfigurationType type= manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION); >+ ILaunchConfiguration[] launchconfigs= manager.getLaunchConfigurations(type); >+ >+ for (int i= 0; i < launchconfigs.length; i++) { >+ ILaunchConfiguration launchconfig= launchconfigs[i]; >+ >+ String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ >+ result.add(new ExistingLaunchConfigurationElement(launchconfig, projectName)); >+ } >+ } catch (CoreException e) { >+ JavaPlugin.log(e); >+ } >+ >+ return (LaunchConfigurationElement[]) result.toArray(new LaunchConfigurationElement[result.size()]); >+ } >+ >+ public Object[] getSelectedElementsWithoutContainedChildren(MultiStatus status) { >+ try { >+ LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(fLaunchConfigurationCombo.getSelectionIndex()); >+ ILaunchConfiguration launchconfig= element.getLaunchConfiguration(); >+ fJarPackage.setLaunchConfigurationName(element.getLaunchConfigurationName()); >+ >+ return getSelectedElementsWithoutContainedChildren(launchconfig, fJarPackage, getContainer(), status); >+ } catch (CoreException e) { >+ JavaPlugin.log(e); >+ } >+ >+ return null; >+ } >+ >+ private static IJavaProject[] getProjectSearchOrder(String projectName) { >+ >+ ArrayList projectNames= new ArrayList(); >+ projectNames.add(projectName); >+ >+ int nextProject= 0; >+ while (nextProject < projectNames.size()) { >+ String nextProjectName= (String) projectNames.get(nextProject); >+ IJavaProject jproject= getJavaProject(nextProjectName); >+ >+ if (jproject != null) { >+ try { >+ String[] childProjectNames= jproject.getRequiredProjectNames(); >+ for (int i= 0; i < childProjectNames.length; i++) { >+ if (!projectNames.contains(childProjectNames[i])) { >+ projectNames.add(childProjectNames[i]); >+ } >+ } >+ } catch (JavaModelException e) { >+ JavaPlugin.log(e); >+ } >+ } >+ nextProject+= 1; >+ } >+ >+ ArrayList result= new ArrayList(); >+ for (int i= 0, size= projectNames.size(); i < size; i++) { >+ String name= (String) projectNames.get(i); >+ IJavaProject project= getJavaProject(name); >+ if (project != null) >+ result.add(project); >+ } >+ >+ return (IJavaProject[]) result.toArray(new IJavaProject[result.size()]); >+ } >+ >+ private static IJavaProject getJavaProject(String projectName) { >+ IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); >+ if (project == null) >+ return null; >+ >+ IJavaProject result= JavaCore.create(project); >+ if (result == null) >+ return null; >+ >+ if (!result.exists()) >+ return null; >+ >+ return result; >+ } >+ >+ private static IPath[] getClasspath(ILaunchConfiguration configuration) throws CoreException { >+ IRuntimeClasspathEntry[] entries= JavaRuntime.computeUnresolvedRuntimeClasspath(configuration); >+ entries= JavaRuntime.resolveRuntimeClasspath(entries, configuration); >+ >+ ArrayList userEntries= new ArrayList(entries.length); >+ for (int i= 0; i < entries.length; i++) { >+ if (entries[i].getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) { >+ >+ String location= entries[i].getLocation(); >+ if (location != null) { >+ IPath entry= Path.fromOSString(location); >+ if (!userEntries.contains(entry)) { >+ userEntries.add(entry); >+ } >+ } >+ } >+ } >+ return (IPath[]) userEntries.toArray(new IPath[userEntries.size()]); >+ } >+ >+ private static String getMainClass(ILaunchConfiguration launchConfig, MultiStatus status) { >+ String result= null; >+ if (launchConfig != null) { >+ try { >+ result= launchConfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String) null); >+ } catch (CoreException e) { >+ JavaPlugin.log(e); >+ } >+ } >+ if (result == null) { >+ status.add(new Status(IStatus.WARNING, JavaUI.ID_PLUGIN, FatJarPackagerMessages.FatJarPackageWizardPage_LaunchConfigurationWithoutMainType_warning)); >+ result= ""; //$NON-NLS-1$ >+ } >+ return result; >+ } >+ >+ /** >+ * @param classpathEntries the path to the package fragment roots >+ * @param projectName the root of the project dependency tree >+ * @param status a status to report problems to >+ * @return all package fragment roots corresponding to each classpath entry start the search at project with projectName >+ */ >+ private static IPackageFragmentRoot[] getRequiredPackageFragmentRoots(IPath[] classpathEntries, final String projectName, MultiStatus status) { >+ HashSet result= new HashSet(); >+ >+ IJavaProject[] searchOrder= getProjectSearchOrder(projectName); >+ >+ for (int i= 0; i < classpathEntries.length; i++) { >+ IPath entry= classpathEntries[i]; >+ IPackageFragmentRoot[] elements= findRootsForClasspath(entry, searchOrder); >+ if (elements == null) { >+ status.add(new Status(IStatus.WARNING, JavaUI.ID_PLUGIN, Messages.format(FatJarPackagerMessages.FatJarPackageWizardPage_error_missingClassFile, entry))); >+ } else { >+ for (int j= 0; j < elements.length; j++) { >+ result.add(elements[j]); >+ } >+ } >+ } >+ >+ return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]); >+ } >+ >+ private static IPackageFragmentRoot[] findRootsForClasspath(IPath entry, IJavaProject[] searchOrder) { >+ for (int i= 0; i < searchOrder.length; i++) { >+ IPackageFragmentRoot[] elements= findRootsInProject(entry, searchOrder[i]); >+ if (elements.length != 0) { >+ return elements; >+ } >+ } >+ return null; >+ } >+ >+ private static IPackageFragmentRoot[] findRootsInProject(IPath entry, IJavaProject project) { >+ ArrayList result= new ArrayList(); >+ >+ try { >+ IPackageFragmentRoot[] roots= project.getPackageFragmentRoots(); >+ for (int i= 0; i < roots.length; i++) { >+ IPackageFragmentRoot packageFragmentRoot= roots[i]; >+ if (isRootAt(packageFragmentRoot, entry)) >+ result.add(packageFragmentRoot); >+ } >+ } catch (Exception e) { >+ JavaPlugin.log(e); >+ } >+ >+ return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]); >+ } >+ >+ private static boolean isRootAt(IPackageFragmentRoot root, IPath entry) { >+ try { >+ IClasspathEntry cpe= root.getRawClasspathEntry(); >+ if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { >+ IPath outputLocation= cpe.getOutputLocation(); >+ if (outputLocation == null) >+ outputLocation= root.getJavaProject().getOutputLocation(); >+ >+ IPath location= ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation(); >+ if (entry.equals(location)) >+ return true; >+ } >+ } catch (JavaModelException e) { >+ JavaPlugin.log(e); >+ } >+ >+ IResource resource= root.getResource(); >+ if (resource != null && entry.equals(resource.getLocation())) >+ return true; >+ >+ IPath path= root.getPath(); >+ if (path != null && entry.equals(path)) >+ return true; >+ >+ return false; >+ } >+ >+ private static IType findMainMethodByName(String name, IPackageFragmentRoot[] classpathResources, IRunnableContext context) throws CoreException { >+ >+ List resources= JarPackagerUtil.asResources(classpathResources); >+ if (resources == null) { >+ return null; >+ } >+ >+ for (Iterator iterator= resources.iterator(); iterator.hasNext();) { >+ IResource element= (IResource) iterator.next(); >+ if (element == null) >+ iterator.remove(); >+ } >+ >+ IJavaSearchScope searchScope= JavaSearchScopeFactory.getInstance().createJavaSearchScope((IResource[]) resources.toArray(new IResource[resources.size()]), true); >+ MainMethodSearchEngine engine= new MainMethodSearchEngine(); >+ try { >+ IType[] mainTypes= engine.searchMainMethods(context, searchScope, 0); >+ for (int i= 0; i < mainTypes.length; i++) { >+ if (mainTypes[i].getFullyQualifiedName().equals(name)) >+ return mainTypes[i]; >+ } >+ } catch (InvocationTargetException ex) { >+ JavaPlugin.log(ex); >+ } catch (InterruptedException e) { >+ // null >+ } >+ >+ return null; >+ } >+ >+ public void dispose() { >+ super.dispose(); >+ if (fLauchConfigurationModel != null) { >+ for (int i= 0, size= fLauchConfigurationModel.size(); i < size; i++) { >+ LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(i); >+ element.dispose(); >+ } >+ } >+ } >+ >+ protected void restoreWidgetValues() { >+ >+ IDialogSettings settings= getDialogSettings(); >+ if (settings != null) { >+ String name= settings.get(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME); >+ if (name != null) { >+ String[] items= fLaunchConfigurationCombo.getItems(); >+ for (int i= 0; i < items.length; i++) { >+ if (name.equals(items[i])) { >+ fLaunchConfigurationCombo.select(i); >+ } >+ } >+ } >+ >+ String destinationPath= settings.get(STORE_DESTINATION_ELEMENT); >+ if (destinationPath != null && destinationPath.length() > 0) { >+ fJarPackage.setJarLocation(Path.fromOSString(destinationPath)); >+ } >+ } >+ >+ super.restoreWidgetValues(); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ protected void saveWidgetValues() { >+ super.saveWidgetValues(); >+ >+ IDialogSettings settings= getDialogSettings(); >+ if (settings != null) { >+ int index= fLaunchConfigurationCombo.getSelectionIndex(); >+ if (index == -1) { >+ settings.put(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME, ""); //$NON-NLS-1$ >+ } else { >+ String selectedItem= fLaunchConfigurationCombo.getItem(index); >+ settings.put(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME, selectedItem); >+ } >+ >+ IPath location= fJarPackage.getJarLocation(); >+ if (location == null) { >+ settings.put(STORE_DESTINATION_ELEMENT, ""); //$NON-NLS-1$ >+ } else { >+ settings.put(STORE_DESTINATION_ELEMENT, location.toOSString()); >+ } >+ } >+ } >+ >+ /* >+ * For internal use only (testing), clients must not call. >+ */ >+ public static Object[] getSelectedElementsWithoutContainedChildren(ILaunchConfiguration launchconfig, JarPackageData data, IRunnableContext context, MultiStatus status) throws CoreException { >+ if (launchconfig == null) >+ return new Object[0]; >+ >+ String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ >+ >+ IPath[] classpath= getClasspath(launchconfig); >+ IPackageFragmentRoot[] classpathResources= getRequiredPackageFragmentRoots(classpath, projectName, status); >+ >+ String mainClass= getMainClass(launchconfig, status); >+ IType mainType= findMainMethodByName(mainClass, classpathResources, context); >+ if (mainType == null) { >+ status.add(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, FatJarPackagerMessages.FatJarPackageWizardPage_error_noMainMethod)); >+ } >+ data.setManifestMainClass(mainType); >+ >+ return classpathResources; >+ } >+ >+} >Index: ui/org/eclipse/jdt/internal/ui/jarpackager/JarBuilder.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackager/JarBuilder.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackager/JarBuilder.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/jarpackager/JarBuilder.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,64 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackager; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.MultiStatus; >+import org.eclipse.core.runtime.Status; >+ >+import org.eclipse.swt.widgets.Shell; >+ >+import org.eclipse.jdt.ui.jarpackager.IJarBuilder; >+import org.eclipse.jdt.ui.jarpackager.JarPackageData; >+ >+import org.eclipse.jdt.internal.ui.IJavaStatusConstants; >+import org.eclipse.jdt.internal.ui.JavaPlugin; >+ >+/** >+ * Base class for all jar builders. >+ * >+ * @since 3.4 >+ */ >+public abstract class JarBuilder implements IJarBuilder { >+ >+ private MultiStatus fStatus; >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void open(JarPackageData jarPackage, Shell shell, MultiStatus status) throws CoreException { >+ fStatus= status; >+ } >+ >+ //some methods for convenience >+ protected final void addInfo(String message, Throwable error) { >+ fStatus.add(new Status(IStatus.INFO, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, error)); >+ } >+ >+ protected final void addWarning(String message, Throwable error) { >+ fStatus.add(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, error)); >+ } >+ >+ protected final void addError(String message, Throwable error) { >+ fStatus.add(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, error)); >+ } >+ >+ protected final void addToStatus(CoreException ex) { >+ IStatus status= ex.getStatus(); >+ String message= ex.getLocalizedMessage(); >+ if (message == null || message.length() < 1) { >+ message= JarPackagerMessages.JarFileExportOperation_coreErrorDuringExport; >+ status= new Status(status.getSeverity(), status.getPlugin(), status.getCode(), message, ex); >+ } >+ fStatus.add(status); >+ } >+} >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.properties >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.properties >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.properties >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.properties 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,30 @@ >+############################################################################### >+# Copyright (c) 2007 IBM Corporation and others. >+# All rights reserved. This program and the accompanying materials >+# are made available under the terms of the Eclipse Public License v1.0 >+# which accompanies this distribution, and is available at >+# http://www.eclipse.org/legal/epl-v10.html >+# >+# Contributors: >+# IBM Corporation - initial API and implementation >+############################################################################### >+ >+JarPackageWizard_windowTitle= Runnable JAR File Export >+JarPackageWizard_jarExport_title= Runnable JAR File Export >+JarPackageWizard_jarExportError_title= Runnable JAR Export Error >+JarPackageWizard_jarExportError_message= Creation of runnable JAR failed >+ >+JarPackageWizardPage_title= Runnable JAR File Specification >+ >+FatJarBuilder_error_readingArchiveFile=Could not read jar file ''{0}''. Reason: {1} >+ >+FatJarPackageWizard_JarExportProblems_message=Jar export finished with problems. See details for additional infos. >+ >+FatJarPackageWizardPage_description=Select a launch configuration to use to create a runnable JAR. >+FatJarPackageWizardPage_destinationGroupTitle=Select the export destination: >+FatJarPackageWizardPage_error_missingClassFile=Fat Jar Export: Could not find classpath entry for ''{0}'' >+FatJarPackageWizard_IPIssueDialog_message=This operation does repack libraries. Make sure you have the required legal rights to do so. >+FatJarPackageWizard_IPIssueDialog_title=Runnable JAR File Export >+FatJarPackageWizardPage_error_noMainMethod=Could not find main method from given launch configuration. >+FatJarPackageWizardPage_launchConfigGroupTitle=Select the launch configuration: >+FatJarPackageWizardPage_LaunchConfigurationWithoutMainType_warning=The selected launch configuration has no type with a main method attached. The resulting jar will not be runnable. >Index: ui/org/eclipse/jdt/internal/ui/jarpackager/PlainJarBuilder.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackager/PlainJarBuilder.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackager/PlainJarBuilder.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/jarpackager/PlainJarBuilder.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,84 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackager; >+ >+import java.util.zip.ZipFile; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.MultiStatus; >+ >+import org.eclipse.core.resources.IFile; >+ >+import org.eclipse.swt.widgets.Shell; >+ >+import org.eclipse.jdt.ui.jarpackager.IManifestProvider; >+import org.eclipse.jdt.ui.jarpackager.JarPackageData; >+import org.eclipse.jdt.ui.jarpackager.JarWriter3; >+ >+/** >+ * Jar builder for the plain jar exported. Does not export archives. >+ * >+ * @since 3.4 >+ */ >+public class PlainJarBuilder extends JarBuilder { >+ >+ public static final String BUILDER_ID= "org.eclipse.jdt.ui.plain_jar_builder"; //$NON-NLS-1$ >+ >+ private JarPackageData fJarPackage; >+ private JarWriter3 fJarWriter; >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public String getId() { >+ return BUILDER_ID; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public IManifestProvider getManifestProvider() { >+ return new ManifestProvider(); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void open(JarPackageData jarPackage, Shell displayShell, MultiStatus statusMsg) throws CoreException { >+ super.open(jarPackage, displayShell, statusMsg); >+ fJarPackage= jarPackage; >+ fJarWriter= new JarWriter3(fJarPackage, displayShell); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void writeFile(IFile resource, IPath destinationPath) throws CoreException { >+ fJarWriter.write(resource, destinationPath); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void writeArchive(ZipFile archiveRoot, IProgressMonitor progressMonitor) { >+ //do nothing, plain jar builder can not handle archives, use fat jar builder >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void close() throws CoreException { >+ fJarWriter.close(); >+ } >+ >+} >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,48 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackagerfat; >+ >+import org.eclipse.osgi.util.NLS; >+ >+public final class FatJarPackagerMessages extends NLS { >+ >+ private static final String BUNDLE_NAME= "org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarPackagerMessages";//$NON-NLS-1$ >+ >+ public static String JarPackageWizard_jarExport_title; >+ public static String JarPackageWizard_jarExportError_message; >+ public static String JarPackageWizard_jarExportError_title; >+ public static String JarPackageWizard_windowTitle; >+ >+ public static String JarPackageWizardPage_title; >+ >+ public static String FatJarBuilder_error_readingArchiveFile; >+ >+ public static String FatJarPackageWizard_JarExportProblems_message; >+ >+ public static String FatJarPackageWizardPage_destinationGroupTitle; >+ public static String FatJarPackageWizardPage_error_missingClassFile; >+ public static String FatJarPackageWizard_IPIssueDialog_message; >+ >+ public static String FatJarPackageWizard_IPIssueDialog_title; >+ >+ public static String FatJarPackageWizardPage_error_noMainMethod; >+ public static String FatJarPackageWizardPage_launchConfigGroupTitle; >+ public static String FatJarPackageWizardPage_LaunchConfigurationWithoutMainType_warning; >+ public static String FatJarPackageWizardPage_description; >+ >+ static { >+ NLS.initializeMessages(BUNDLE_NAME, FatJarPackagerMessages.class); >+ } >+ >+ private FatJarPackagerMessages() { >+ // Do not instantiate >+ } >+} >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarManifestProvider.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarManifestProvider.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarManifestProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarManifestProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,199 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackagerfat; >+ >+import java.io.IOException; >+import java.io.InputStream; >+import java.util.ArrayList; >+import java.util.Enumeration; >+import java.util.Iterator; >+import java.util.List; >+import java.util.Map; >+import java.util.jar.Attributes; >+import java.util.jar.Manifest; >+import java.util.zip.ZipEntry; >+import java.util.zip.ZipFile; >+ >+import org.eclipse.core.runtime.CoreException; >+ >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+ >+import org.eclipse.jdt.ui.jarpackager.IManifestProvider; >+import org.eclipse.jdt.ui.jarpackager.JarPackageData; >+ >+import org.eclipse.jdt.internal.ui.JavaPlugin; >+import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil; >+ >+/** >+ * A manifest provider creates manifest files for a fat jar. >+ * >+ * @since 3.4 >+ */ >+public class FatJarManifestProvider implements IManifestProvider { >+ >+ private static final String SEALED_VALUE= "true"; //$NON-NLS-1$ >+ private static final String UNSEALED_VALUE= "false"; //$NON-NLS-1$ >+ >+ private FatJarBuilder fBuilder; >+ >+ public FatJarManifestProvider(FatJarBuilder builder) { >+ fBuilder= builder; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public Manifest create(JarPackageData jarPackage) throws CoreException { >+ Manifest result; >+ Manifest ownManifest= createOwn(jarPackage); >+ setManifestClasspath(ownManifest, fBuilder.getManifestClasspath()); >+ if (fBuilder.isMergeManifests()) { >+ List otherManifests= new ArrayList(); >+ Object[] elements= jarPackage.getElements(); >+ for (int i= 0; i < elements.length; i++) { >+ Object element= elements[i]; >+ if (element instanceof IPackageFragmentRoot && ((IPackageFragmentRoot) element).isArchive()) { >+ ZipFile zip= JarPackagerUtil.getArchiveFile(((IPackageFragmentRoot) element).getPath()); >+ Enumeration entries= zip.entries(); >+ while (entries.hasMoreElements()) { >+ ZipEntry entry= (ZipEntry) entries.nextElement(); >+ if (entry.getName().equalsIgnoreCase("META-INF/MANIFEST.MF")) { //$NON-NLS-1$ >+ try { >+ Manifest otherManifest= new Manifest(zip.getInputStream(entry)); >+ otherManifests.add(otherManifest); >+ } catch (IOException e) { >+ JavaPlugin.log(e); >+ } >+ } >+ } >+ } >+ } >+ result= merge(ownManifest, otherManifests); >+ } else { >+ result= ownManifest; >+ } >+ return result; >+ } >+ >+ private void setManifestClasspath(Manifest ownManifest, String manifestClasspath) { >+ if ((manifestClasspath != null) && !manifestClasspath.trim().equals("")) { //$NON-NLS-1$ >+ Attributes mainAttr= ownManifest.getMainAttributes(); >+ mainAttr.putValue("Class-Path", manifestClasspath); //$NON-NLS-1$ >+ } >+ } >+ >+ private Manifest merge(Manifest ownManifest, List otherManifests) { >+ Manifest mergedManifest= new Manifest(ownManifest); >+ Map mergedEntries= mergedManifest.getEntries(); >+ for (Iterator iter= otherManifests.iterator(); iter.hasNext();) { >+ Manifest otherManifest= (Manifest) iter.next(); >+ Map otherEntries= otherManifest.getEntries(); >+ for (Iterator iterator= otherEntries.keySet().iterator(); iterator.hasNext();) { >+ String attributeName= (String) iterator.next(); >+ if (mergedEntries.containsKey(attributeName)) { >+ // TODO: WARNING >+ } else { >+ mergedEntries.put(attributeName, otherEntries.get(attributeName)); >+ } >+ } >+ } >+ return mergedManifest; >+ } >+ >+ private Manifest createOwn(JarPackageData jarPackage) throws CoreException { >+ if (jarPackage.isManifestGenerated()) >+ return createGeneratedManifest(jarPackage); >+ >+ try { >+ return createSuppliedManifest(jarPackage); >+ } catch (IOException ex) { >+ throw JarPackagerUtil.createCoreException(ex.getLocalizedMessage(), ex); >+ } >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public Manifest createDefault(String manifestVersion) { >+ Manifest manifest= new Manifest(); >+ manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, manifestVersion); >+ return manifest; >+ } >+ >+ /** >+ * Hook for subclasses to add additional manifest entries. >+ * >+ * @param manifest the manifest to which the entries should be added >+ * @param jarPackage the JAR package specification >+ */ >+ protected void putAdditionalEntries(Manifest manifest, JarPackageData jarPackage) { >+ } >+ >+ private Manifest createGeneratedManifest(JarPackageData jarPackage) { >+ Manifest manifest= new Manifest(); >+ putVersion(manifest, jarPackage); >+ putSealing(manifest, jarPackage); >+ putMainClass(manifest, jarPackage); >+ putAdditionalEntries(manifest, jarPackage); >+ return manifest; >+ } >+ >+ private void putVersion(Manifest manifest, JarPackageData jarPackage) { >+ manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, jarPackage.getManifestVersion()); >+ } >+ >+ private void putSealing(Manifest manifest, JarPackageData jarPackage) { >+ if (jarPackage.isJarSealed()) { >+ manifest.getMainAttributes().put(Attributes.Name.SEALED, SEALED_VALUE); >+ IPackageFragment[] packages= jarPackage.getPackagesToUnseal(); >+ if (packages != null) { >+ for (int i= 0; i < packages.length; i++) { >+ Attributes attributes= new Attributes(); >+ attributes.put(Attributes.Name.SEALED, UNSEALED_VALUE); >+ manifest.getEntries().put(getInManifestFormat(packages[i]), attributes); >+ } >+ } >+ } else { >+ IPackageFragment[] packages= jarPackage.getPackagesToSeal(); >+ if (packages != null) >+ for (int i= 0; i < packages.length; i++) { >+ Attributes attributes= new Attributes(); >+ attributes.put(Attributes.Name.SEALED, SEALED_VALUE); >+ manifest.getEntries().put(getInManifestFormat(packages[i]), attributes); >+ } >+ } >+ } >+ >+ private void putMainClass(Manifest manifest, JarPackageData jarPackage) { >+ if (jarPackage.getManifestMainClass() != null && jarPackage.getManifestMainClass().getFullyQualifiedName().length() > 0) >+ manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, jarPackage.getManifestMainClass().getFullyQualifiedName()); >+ } >+ >+ private String getInManifestFormat(IPackageFragment packageFragment) { >+ String name= packageFragment.getElementName(); >+ return name.replace('.', '/') + '/'; >+ } >+ >+ private Manifest createSuppliedManifest(JarPackageData jarPackage) throws CoreException, IOException { >+ Manifest manifest; >+ // No need to use buffer here because Manifest(...) does >+ InputStream stream= jarPackage.getManifestFile().getContents(false); >+ try { >+ manifest= new Manifest(stream); >+ } finally { >+ if (stream != null) >+ stream.close(); >+ } >+ return manifest; >+ } >+ >+} >Index: ui/org/eclipse/jdt/ui/jarpackager/IJarBuilder.java >=================================================================== >RCS file: ui/org/eclipse/jdt/ui/jarpackager/IJarBuilder.java >diff -N ui/org/eclipse/jdt/ui/jarpackager/IJarBuilder.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/ui/jarpackager/IJarBuilder.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,102 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.ui.jarpackager; >+ >+import java.util.zip.ZipFile; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.MultiStatus; >+ >+import org.eclipse.core.resources.IFile; >+ >+import org.eclipse.swt.widgets.Shell; >+ >+ >+ >+/** >+ * A jar builder can be used to add elements to a >+ * jar file which is about to be build. >+ * <p> >+ * The protocol defined by this interface is: >+ * <ul> >+ * <li>open is called</li> >+ * <li>addFile and addJar is called multiple times</li> >+ * <li>close is called</li> >+ * </ul> >+ * It is guaranteed that addFile and addJar is only called after >+ * open is called and before close is called. Other methods may >+ * be called any time.</p> >+ * Implementors must be prepared that an instance if the implementation >+ * is reused multiple times.<p> >+ * >+ * <strong>EXPERIMENTAL</strong> This class or interface has been added as part >+ * of a work in progress. This API may change at any given time. Please do not >+ * use this API without consulting with the JDT/UI team. See bug 83258 for discussions. >+ * >+ * @see org.eclipse.jdt.ui.jarpackager.JarPackageData >+ * @since 3.4 >+ */ >+public interface IJarBuilder { >+ >+ /** >+ * @return the unique id of this builder >+ */ >+ public String getId(); >+ >+ /** >+ * @return the manifest provider to build the manifest >+ */ >+ public IManifestProvider getManifestProvider(); >+ >+ /** >+ * Called when building of the jar starts >+ * >+ * @param jarPackage >+ * the package to build >+ * @param shell >+ * shell to show dialogs, <b>null</b> if no dialog must be shown >+ * @param status >+ * a status to use to report status to the user >+ * @throws CoreException >+ */ >+ public void open(JarPackageData jarPackage, Shell shell, MultiStatus status) throws CoreException; >+ >+ /** >+ * Add the given resource to the archive at the given path >+ * >+ * @param resource >+ * the file to be written >+ * @param destinationPath >+ * the path for the file inside the archive >+ * @throws CoreException >+ */ >+ public void writeFile(IFile resource, IPath destinationPath) throws CoreException; >+ >+ /** >+ * Add the given archive to the archive which is about to be build >+ * >+ * @param archive >+ * the archive to add >+ * @param monitor >+ * a monitor to report progress to >+ */ >+ public void writeArchive(ZipFile archive, IProgressMonitor monitor); >+ >+ /** >+ * Called when building of the jar finished. >+ * >+ * @throws CoreException >+ */ >+ public void close() throws CoreException; >+ >+} >Index: ui/org/eclipse/jdt/internal/ui/jarpackager/AbstractJarDestinationWizardPage.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackager/AbstractJarDestinationWizardPage.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackager/AbstractJarDestinationWizardPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/jarpackager/AbstractJarDestinationWizardPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,319 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackager; >+ >+import java.io.File; >+ >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.Path; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.ResourcesPlugin; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Combo; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.FileDialog; >+import org.eclipse.swt.widgets.Label; >+ >+import org.eclipse.jface.dialogs.IDialogSettings; >+import org.eclipse.jface.dialogs.IMessageProvider; >+import org.eclipse.jface.viewers.IStructuredSelection; >+ >+import org.eclipse.ui.dialogs.WizardExportResourcesPage; >+ >+import org.eclipse.jdt.ui.jarpackager.JarPackageData; >+ >+import org.eclipse.jdt.internal.ui.util.SWTUtil; >+ >+/** >+ * A wizard page containing a destination block for a jar file. Including >+ * all required validation code. Clients should overwrite <code>createControl</code>. >+ * >+ * @since 3.4 >+ */ >+public abstract class AbstractJarDestinationWizardPage extends WizardExportResourcesPage implements IJarPackageWizardPage { >+ >+ private final String fStoreDestinationNamesId; >+ >+ private Combo fDestinationNamesCombo; >+ private Button fDestinationBrowseButton; >+ private final JarPackageData fJarPackage; >+ >+ public AbstractJarDestinationWizardPage(String pageName, IStructuredSelection selection, JarPackageData jarPackage) { >+ super(pageName, selection); >+ fStoreDestinationNamesId= pageName + ".DESTINATION_NAMES_ID"; //$NON-NLS-1$ >+ fJarPackage= jarPackage; >+ } >+ >+ /* >+ * Overrides method from WizardExportPage >+ */ >+ protected void createDestinationGroup(Composite parent) { >+ >+ initializeDialogUnits(parent); >+ >+ // destination specification group >+ Composite destinationSelectionGroup= new Composite(parent, SWT.NONE); >+ GridLayout layout= new GridLayout(); >+ layout.numColumns= 3; >+ destinationSelectionGroup.setLayout(layout); >+ destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); >+ >+ String label= getDestinationLabel(); >+ if (label != null) { >+ new Label(destinationSelectionGroup, SWT.NONE).setText(label); >+ } >+ >+ // destination name entry field >+ fDestinationNamesCombo= new Combo(destinationSelectionGroup, SWT.SINGLE | SWT.BORDER); >+ fDestinationNamesCombo.addListener(SWT.Modify, this); >+ fDestinationNamesCombo.addListener(SWT.Selection, this); >+ GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); >+ data.widthHint= SIZING_TEXT_FIELD_WIDTH; >+ data.horizontalSpan= label == null ? 2 : 1; >+ fDestinationNamesCombo.setLayoutData(data); >+ >+ // destination browse button >+ fDestinationBrowseButton= new Button(destinationSelectionGroup, SWT.PUSH); >+ fDestinationBrowseButton.setText(JarPackagerMessages.JarPackageWizardPage_browseButton_text); >+ fDestinationBrowseButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); >+ SWTUtil.setButtonDimensionHint(fDestinationBrowseButton); >+ fDestinationBrowseButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleDestinationBrowseButtonPressed(); >+ } >+ }); >+ } >+ >+ /** >+ * Open an appropriate destination browser so that the user can specify a source >+ * to import from >+ */ >+ protected void handleDestinationBrowseButtonPressed() { >+ FileDialog dialog= new FileDialog(getContainer().getShell(), SWT.SAVE); >+ dialog.setFilterExtensions(new String[] { "*.jar", "*.zip" }); //$NON-NLS-1$ //$NON-NLS-2$ >+ >+ String currentSourceString= getDestinationValue(); >+ int lastSeparatorIndex= currentSourceString.lastIndexOf(File.separator); >+ if (lastSeparatorIndex != -1) { >+ dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex)); >+ dialog.setFileName(currentSourceString.substring(lastSeparatorIndex + 1, currentSourceString.length())); >+ } else >+ dialog.setFileName(currentSourceString); >+ String selectedFileName= dialog.open(); >+ if (selectedFileName != null) >+ fDestinationNamesCombo.setText(selectedFileName); >+ } >+ >+ >+ /** >+ * Answer the contents of the destination specification widget. If this >+ * value does not have the required suffix then add it first. >+ * >+ * @return java.lang.String >+ */ >+ protected String getDestinationValue() { >+ String destinationText= fDestinationNamesCombo.getText().trim(); >+ if (destinationText.indexOf('.') < 0) >+ destinationText+= getOutputSuffix(); >+ return destinationText; >+ } >+ >+ /** >+ * Answer the string to display in self as the destination type >+ * >+ * @return java.lang.String >+ */ >+ protected String getDestinationLabel() { >+ return JarPackagerMessages.JarPackageWizardPage_destination_label; >+ } >+ >+ /** >+ * Answer the suffix that files exported from this wizard must have. >+ * If this suffix is a file extension (which is typically the case) >+ * then it must include the leading period character. >+ * >+ * @return java.lang.String >+ */ >+ protected String getOutputSuffix() { >+ return "." + JarPackagerUtil.JAR_EXTENSION; //$NON-NLS-1$ >+ } >+ >+ protected void restoreWidgetValues() { >+ // destination >+ if (fJarPackage.getJarLocation().isEmpty()) >+ fDestinationNamesCombo.setText(""); //$NON-NLS-1$ >+ else >+ fDestinationNamesCombo.setText(fJarPackage.getJarLocation().toOSString()); >+ IDialogSettings settings= getDialogSettings(); >+ if (settings != null) { >+ String[] directoryNames= settings.getArray(fStoreDestinationNamesId); >+ if (directoryNames == null) >+ return; // ie.- no settings stored >+ if (!fDestinationNamesCombo.getText().equals(directoryNames[0])) >+ fDestinationNamesCombo.add(fDestinationNamesCombo.getText()); >+ for (int i= 0; i < directoryNames.length; i++) >+ fDestinationNamesCombo.add(directoryNames[i]); >+ } >+ } >+ >+ protected void updateModel() { >+ // destination >+ String comboText= fDestinationNamesCombo.getText(); >+ IPath path= Path.fromOSString(comboText); >+ >+ if (path.segmentCount() > 0 && ensureTargetFileIsValid(path.toFile()) && path.getFileExtension() == null) >+ // append .jar >+ path= path.addFileExtension(JarPackagerUtil.JAR_EXTENSION); >+ >+ fJarPackage.setJarLocation(path); >+ } >+ >+ /** >+ * Returns a boolean indicating whether the passed File handle is >+ * is valid and available for use. >+ * >+ * @param targetFile the target >+ * @return boolean >+ */ >+ protected boolean ensureTargetFileIsValid(File targetFile) { >+ if (targetFile.exists() && targetFile.isDirectory() && fDestinationNamesCombo.getText().length() > 0) { >+ setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_exportDestinationMustNotBeDirectory); >+ fDestinationNamesCombo.setFocus(); >+ return false; >+ } >+ if (targetFile.exists()) { >+ if (!targetFile.canWrite()) { >+ setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_jarFileExistsAndNotWritable); >+ fDestinationNamesCombo.setFocus(); >+ return false; >+ } >+ } >+ return true; >+ } >+ >+ /* >+ * Overrides method from WizardDataTransferPage >+ */ >+ protected boolean validateDestinationGroup() { >+ if (fDestinationNamesCombo.getText().length() == 0) { >+ // Clear error >+ if (getErrorMessage() != null) >+ setErrorMessage(null); >+ if (getMessage() != null) >+ setMessage(null); >+ return false; >+ } >+ if (fJarPackage.getAbsoluteJarLocation().toString().endsWith("/")) { //$NON-NLS-1$ >+ setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_exportDestinationMustNotBeDirectory); >+ fDestinationNamesCombo.setFocus(); >+ return false; >+ } >+ // Check if the Jar is put into the workspace and conflicts with the containers >+ // exported. If the workspace isn't on the local files system we are fine since >+ // the Jar is always created in the local file system >+ IPath workspaceLocation= ResourcesPlugin.getWorkspace().getRoot().getLocation(); >+ if (workspaceLocation != null && workspaceLocation.isPrefixOf(fJarPackage.getAbsoluteJarLocation())) { >+ int segments= workspaceLocation.matchingFirstSegments(fJarPackage.getAbsoluteJarLocation()); >+ IPath path= fJarPackage.getAbsoluteJarLocation().removeFirstSegments(segments); >+ IResource resource= ResourcesPlugin.getWorkspace().getRoot().findMember(path); >+ if (resource != null && resource.getType() == IResource.FILE) { >+ // test if included >+ if (JarPackagerUtil.contains(JarPackagerUtil.asResources(fJarPackage.getElements()), (IFile) resource)) { >+ setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_cantExportJARIntoItself); >+ return false; >+ } >+ } >+ } >+ // Inform user about relative directory >+ String currentMessage= getMessage(); >+ if (!(new File(fDestinationNamesCombo.getText()).isAbsolute())) { >+ if (currentMessage == null) >+ setMessage(JarPackagerMessages.JarPackageWizardPage_info_relativeExportDestination, IMessageProvider.INFORMATION); >+ } else { >+ if (currentMessage != null) >+ setMessage(null); >+ } >+ return ensureTargetFileIsValid(fJarPackage.getAbsoluteJarLocation().toFile()); >+ } >+ >+ /** >+ * Set the current input focus to self's destination entry field >+ */ >+ protected void giveFocusToDestination() { >+ fDestinationNamesCombo.setFocus(); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ protected void saveWidgetValues() { >+ IDialogSettings settings= getDialogSettings(); >+ if (settings != null) { >+ String[] directoryNames= settings.getArray(fStoreDestinationNamesId); >+ if (directoryNames == null) >+ directoryNames= new String[0]; >+ directoryNames= addToHistory(directoryNames, getDestinationValue()); >+ settings.put(fStoreDestinationNamesId, directoryNames); >+ } >+ } >+ >+ /** >+ * Initializes the JAR package from last used wizard page values. >+ */ >+ protected void initializeJarPackage() { >+ IDialogSettings settings= getDialogSettings(); >+ if (settings != null) { >+ // destination >+ String[] directoryNames= settings.getArray(fStoreDestinationNamesId); >+ if (directoryNames == null) >+ return; // ie.- no settings stored >+ fJarPackage.setJarLocation(Path.fromOSString(directoryNames[0])); >+ } >+ } >+ >+ /* >+ * Implements method from IJarPackageWizardPage. >+ */ >+ public void finish() { >+ saveWidgetValues(); >+ } >+ >+ /* >+ * Implements method from Listener >+ */ >+ public void handleEvent(Event e) { >+ if (getControl() == null) >+ return; >+ update(); >+ } >+ >+ protected void update() { >+ updateModel(); >+ updateWidgetEnablements(); >+ updatePageCompletion(); >+ } >+ >+ protected void updatePageCompletion() { >+ boolean pageComplete= isPageComplete(); >+ setPageComplete(pageComplete); >+ if (pageComplete) >+ setErrorMessage(null); >+ } >+} >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/JarWriter4.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/JarWriter4.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/JarWriter4.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/jarpackagerfat/JarWriter4.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,57 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackagerfat; >+ >+import java.io.File; >+import java.io.IOException; >+import java.util.jar.JarEntry; >+import java.util.zip.ZipEntry; >+import java.util.zip.ZipFile; >+ >+import org.eclipse.core.runtime.CoreException; >+ >+import org.eclipse.swt.widgets.Shell; >+ >+import org.eclipse.jdt.ui.jarpackager.JarPackageData; >+import org.eclipse.jdt.ui.jarpackager.JarWriter3; >+ >+/** >+ * @since 3.4 >+ */ >+public class JarWriter4 extends JarWriter3 { >+ >+ private final JarPackageData fJarPackage; >+ >+ public JarWriter4(JarPackageData jarPackage, Shell parent) throws CoreException { >+ super(jarPackage, parent); >+ fJarPackage= jarPackage; >+ } >+ >+ public void addZipEntry(ZipEntry zipEntry, ZipFile zipFile, String path) throws IOException, CoreException { >+ JarEntry newEntry= new JarEntry(path.replace(File.separatorChar, '/')); >+ >+ if (fJarPackage.isCompressed()) >+ newEntry.setMethod(ZipEntry.DEFLATED); >+ // Entry is filled automatically. >+ else { >+ newEntry.setMethod(ZipEntry.STORED); >+ newEntry.setSize(zipEntry.getSize()); >+ newEntry.setCompressedSize(zipEntry.getCrc()); >+ } >+ >+ long lastModified= System.currentTimeMillis(); >+ >+ // Set modification time >+ newEntry.setTime(lastModified); >+ >+ addEntry(newEntry, zipFile.getInputStream(zipEntry)); >+ } >+} >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarBuilder.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarBuilder.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarBuilder.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarBuilder.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,125 @@ >+package org.eclipse.jdt.internal.ui.jarpackagerfat; >+ >+import java.io.IOException; >+import java.util.Enumeration; >+import java.util.zip.ZipEntry; >+import java.util.zip.ZipException; >+import java.util.zip.ZipFile; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.MultiStatus; >+import org.eclipse.core.runtime.OperationCanceledException; >+ >+import org.eclipse.core.resources.IFile; >+ >+import org.eclipse.swt.widgets.Shell; >+ >+import org.eclipse.jdt.internal.corext.util.Messages; >+ >+import org.eclipse.jdt.ui.jarpackager.IManifestProvider; >+import org.eclipse.jdt.ui.jarpackager.JarPackageData; >+ >+import org.eclipse.jdt.internal.ui.jarpackager.JarBuilder; >+ >+public class FatJarBuilder extends JarBuilder { >+ >+ public static final String BUILDER_ID= "org.eclipse.jdt.ui.fat_jar_builder"; //$NON-NLS-1$ >+ >+ private JarPackageData fJarPackage; >+ private JarWriter4 fJarWriter; >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public String getId() { >+ return BUILDER_ID; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public IManifestProvider getManifestProvider() { >+ return new FatJarManifestProvider(this); >+ } >+ >+ public String getManifestClasspath() { >+ return "."; //$NON-NLS-1$ >+ } >+ >+ public boolean isMergeManifests() { >+ return true; >+ } >+ >+ public boolean isRemoveSigners() { >+ return true; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void open(JarPackageData jarPackage, Shell displayShell, MultiStatus status) throws CoreException { >+ super.open(jarPackage, displayShell, status); >+ fJarPackage= jarPackage; >+ fJarWriter= new JarWriter4(fJarPackage, displayShell); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void writeFile(IFile resource, IPath destinationPath) throws CoreException { >+ fJarWriter.write(resource, destinationPath); >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void writeArchive(ZipFile jarFile, IProgressMonitor progressMonitor) { >+ Enumeration jarEntriesEnum= jarFile.entries(); >+ while (jarEntriesEnum.hasMoreElements()) { >+ ZipEntry jarEntry= (ZipEntry) jarEntriesEnum.nextElement(); >+ if (!jarEntry.isDirectory()) { >+ String entryName= jarEntry.getName(); >+ addFile(entryName, jarEntry, jarFile); >+ } >+ progressMonitor.worked(1); >+ if (progressMonitor.isCanceled()) >+ throw new OperationCanceledException(); >+ } >+ } >+ >+ private void addFile(String destinationPath, ZipEntry jarEntry, ZipFile zipFile) { >+ // Handle META-INF/MANIFEST.MF >+ if (destinationPath.equalsIgnoreCase("META-INF/MANIFEST.MF") //$NON-NLS-1$ >+ || (isRemoveSigners() && destinationPath.startsWith("META-INF/") && destinationPath.endsWith(".SF"))) { //$NON-NLS-1$//$NON-NLS-2$ >+ return; >+ } >+ try { >+ fJarWriter.addZipEntry(jarEntry, zipFile, destinationPath); >+ } catch (CoreException ex) { >+ Throwable realEx= ex.getStatus().getException(); >+ if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$ >+ addWarning(ex.getMessage(), realEx); >+ else >+ addToStatus(ex); >+ } catch (IOException ex) { >+ if (ex instanceof ZipException && ex.getMessage() != null && ex.getMessage().startsWith("duplicate entry:")) {//$NON-NLS-1$ >+ // ignore duplicates in META-INF (*.SF, *.RSA) >+ if (!destinationPath.startsWith("META-INF/")) { //$NON-NLS-1$ >+ addWarning(ex.getMessage(), ex); >+ } >+ } else >+ addWarning(Messages.format(FatJarPackagerMessages.FatJarBuilder_error_readingArchiveFile, new Object[] { zipFile.getName(), ex.getLocalizedMessage() }), ex); >+ } >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void close() throws CoreException { >+ if (fJarWriter != null) { >+ fJarWriter.close(); >+ } >+ } >+} >Index: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizard.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizard.java >diff -N ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizard.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizard.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,241 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.internal.ui.jarpackagerfat; >+ >+import java.lang.reflect.InvocationTargetException; >+import java.util.HashSet; >+import java.util.Iterator; >+ >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.MultiStatus; >+ >+import org.eclipse.swt.widgets.Shell; >+ >+import org.eclipse.jface.dialogs.ErrorDialog; >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.jface.dialogs.IDialogSettings; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.window.Window; >+import org.eclipse.jface.wizard.IWizardPage; >+import org.eclipse.jface.wizard.Wizard; >+ >+import org.eclipse.ui.IExportWizard; >+import org.eclipse.ui.IWorkbench; >+ >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+ >+import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable; >+import org.eclipse.jdt.ui.jarpackager.JarPackageData; >+ >+import org.eclipse.jdt.internal.ui.JavaPlugin; >+import org.eclipse.jdt.internal.ui.JavaPluginImages; >+import org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog; >+import org.eclipse.jdt.internal.ui.util.ExceptionHandler; >+ >+/** >+ * Wizard for exporting resources from the workspace to a Fat Java Archive (JAR) file. >+ * The exported jar will contain all required libraries. >+ * >+ * @since 3.4 >+ */ >+public class FatJarPackageWizard extends Wizard implements IExportWizard { >+ >+ private static final class IPIssueWarningDialog extends OptionalMessageDialog { >+ >+ private static final String ID= "RunnableJar.export.ipwarning"; //$NON-NLS-1$ >+ >+ protected IPIssueWarningDialog(Shell parent, String title, String message) { >+ super(ID, parent, title, null, message, MessageDialog.WARNING, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0); >+ } >+ >+ } >+ >+ private static String DIALOG_SETTINGS_KEY= "FatJarPackageWizard"; //$NON-NLS-1$ >+ >+ private boolean fHasNewDialogSettings; >+ private boolean fInitializeFromJarPackage; >+ private JarPackageData fJarPackage; >+ private FatJarPackageWizardPage fJarPackageWizardPage; >+ private IStructuredSelection fSelection; >+ >+ /** >+ * Creates a wizard for exporting workspace resources to a JAR file. >+ */ >+ public FatJarPackageWizard() { >+ IDialogSettings workbenchSettings= JavaPlugin.getDefault().getDialogSettings(); >+ IDialogSettings section= workbenchSettings.getSection(DIALOG_SETTINGS_KEY); >+ if (section == null) >+ fHasNewDialogSettings= true; >+ else { >+ fHasNewDialogSettings= false; >+ setDialogSettings(section); >+ } >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void addPages() { >+ super.addPages(); >+ fJarPackageWizardPage= new FatJarPackageWizardPage(fJarPackage, fSelection); >+ addPage(fJarPackageWizardPage); >+ } >+ >+ /** >+ * Exports the JAR package. >+ * >+ * @param op the operation to run >+ * @param wizardPageStatus the status returned by the wizard page >+ * @return a boolean indicating success or failure >+ */ >+ protected boolean executeExportOperation(IJarExportRunnable op, IStatus wizardPageStatus) { >+ try { >+ getContainer().run(true, true, op); >+ } catch (InterruptedException e) { >+ return false; >+ } catch (InvocationTargetException ex) { >+ if (ex.getTargetException() != null) { >+ ExceptionHandler.handle(ex, getShell(), FatJarPackagerMessages.JarPackageWizard_jarExportError_title, FatJarPackagerMessages.JarPackageWizard_jarExportError_message); >+ return false; >+ } >+ } >+ IStatus status= op.getStatus(); >+ if (!status.isOK()) { >+ if (!wizardPageStatus.isOK()) { >+ if (!(status instanceof MultiStatus)) >+ status= new MultiStatus(status.getPlugin(), status.getCode(), status.getMessage(), status.getException()); >+ >+ ((MultiStatus) status).add(wizardPageStatus); >+ } >+ ErrorDialog.openError(getShell(), FatJarPackagerMessages.JarPackageWizard_jarExport_title, null, status); >+ return !(status.matches(IStatus.ERROR)); >+ } else if (!wizardPageStatus.isOK()) { >+ ErrorDialog.openError(getShell(), FatJarPackagerMessages.JarPackageWizard_jarExport_title, null, wizardPageStatus); >+ } >+ return true; >+ } >+ >+ public IWizardPage getNextPage(IWizardPage page) { >+ return super.getNextPage(page); >+ } >+ >+ public IWizardPage getPreviousPage(IWizardPage page) { >+ return super.getPreviousPage(page); >+ } >+ >+ /** >+ * @return all java projects which contain the selected elements in the active workbench window >+ */ >+ protected IStructuredSelection getSelectedJavaProjects() { >+ ISelection currentSelection= JavaPlugin.getActiveWorkbenchWindow().getSelectionService().getSelection(); >+ if (currentSelection instanceof IStructuredSelection) { >+ IStructuredSelection structuredSelection= (IStructuredSelection) currentSelection; >+ HashSet selectedElements= new HashSet(); >+ Iterator iter= structuredSelection.iterator(); >+ while (iter.hasNext()) { >+ Object selectedElement= iter.next(); >+ if (selectedElement instanceof IJavaElement) { >+ IJavaProject javaProject= ((IJavaElement) selectedElement).getJavaProject(); >+ if (javaProject != null) >+ selectedElements.add(javaProject); >+ } >+ } >+ return new StructuredSelection(selectedElements); >+ } else >+ return StructuredSelection.EMPTY; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public void init(IWorkbench workbench, IStructuredSelection selection) { >+ fSelection= getSelectedJavaProjects(); >+ fJarPackage= new JarPackageData(); >+ setInitializeFromJarPackage(false); >+ setWindowTitle(FatJarPackagerMessages.JarPackageWizard_windowTitle); >+ setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_FAT_JAR_PACKAGER); >+ setNeedsProgressMonitor(true); >+ } >+ >+ /** >+ * Initializes this wizard from the given JAR package description. >+ * >+ * @param workbench >+ * the workbench which launched this wizard >+ * @param jarPackage >+ * the JAR package description used to initialize this wizard >+ */ >+ public void init(IWorkbench workbench, JarPackageData jarPackage) { >+ Assert.isNotNull(workbench); >+ Assert.isNotNull(jarPackage); >+ fJarPackage= jarPackage; >+ setInitializeFromJarPackage(true); >+ setWindowTitle(FatJarPackagerMessages.JarPackageWizard_windowTitle); >+ setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_FAT_JAR_PACKAGER); >+ setNeedsProgressMonitor(true); >+ } >+ >+ boolean isInitializingFromJarPackage() { >+ return fInitializeFromJarPackage; >+ } >+ >+ /** >+ * {@inheritDoc} >+ */ >+ public boolean performFinish() { >+ fJarPackage.setJarBuilder(new FatJarBuilder()); >+ MultiStatus status= new MultiStatus(JavaPlugin.getPluginId(), IStatus.OK, FatJarPackagerMessages.FatJarPackageWizard_JarExportProblems_message, null); >+ Object[] elements= fJarPackageWizardPage.getSelectedElementsWithoutContainedChildren(status); >+ fJarPackage.setElements(elements); >+ >+ if (OptionalMessageDialog.isDialogEnabled(IPIssueWarningDialog.ID) && hasArchive(elements)) { >+ IPIssueWarningDialog dialog= new IPIssueWarningDialog(getShell(), FatJarPackagerMessages.FatJarPackageWizard_IPIssueDialog_title, >+ FatJarPackagerMessages.FatJarPackageWizard_IPIssueDialog_message); >+ if (dialog.open() != Window.OK) >+ return false; >+ } >+ >+ if (!executeExportOperation(fJarPackage.createJarExportRunnable(getShell()), status)) >+ return false; >+ >+ // Save the dialog settings >+ if (fHasNewDialogSettings) { >+ IDialogSettings workbenchSettings= JavaPlugin.getDefault().getDialogSettings(); >+ IDialogSettings section= workbenchSettings.getSection(DIALOG_SETTINGS_KEY); >+ section= workbenchSettings.addNewSection(DIALOG_SETTINGS_KEY); >+ setDialogSettings(section); >+ } >+ >+ fJarPackageWizardPage.finish(); >+ return true; >+ } >+ >+ private boolean hasArchive(Object[] elements) { >+ for (int i= 0; i < elements.length; i++) { >+ if (elements[i] instanceof IPackageFragmentRoot) { >+ IPackageFragmentRoot root= (IPackageFragmentRoot) elements[i]; >+ if (root.isArchive()) >+ return true; >+ } >+ } >+ return false; >+ } >+ >+ void setInitializeFromJarPackage(boolean state) { >+ fInitializeFromJarPackage= state; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 83258
:
79147
|
79149
|
79409
|
79480
|
79721
|
79792
|
79929
|
79930
|
80060
|
80120
|
80161
|
80203
|
80263
|
83768