View | Details | Raw Unified | Return to bug 83258 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (+1 lines)
Lines 24-29 Link Here
24
 org.eclipse.jdt.ui.tests.core;x-internal:=true,
24
 org.eclipse.jdt.ui.tests.core;x-internal:=true,
25
 org.eclipse.jdt.ui.tests.core.source;x-internal:=true,
25
 org.eclipse.jdt.ui.tests.core.source;x-internal:=true,
26
 org.eclipse.jdt.ui.tests.dialogs;x-internal:=true,
26
 org.eclipse.jdt.ui.tests.dialogs;x-internal:=true,
27
 org.eclipse.jdt.ui.tests.jarexport,
27
 org.eclipse.jdt.ui.tests.leaks;x-internal:=true,
28
 org.eclipse.jdt.ui.tests.leaks;x-internal:=true,
28
 org.eclipse.jdt.ui.tests.model;x-internal:=true,
29
 org.eclipse.jdt.ui.tests.model;x-internal:=true,
29
 org.eclipse.jdt.ui.tests.packageview;x-internal:=true,
30
 org.eclipse.jdt.ui.tests.packageview;x-internal:=true,
(-)ui/org/eclipse/jdt/ui/tests/AutomatedSuite.java (-1 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 21-26 Link Here
21
import org.eclipse.jdt.ui.tests.buildpath.BuildpathModifierActionTest;
21
import org.eclipse.jdt.ui.tests.buildpath.BuildpathModifierActionTest;
22
import org.eclipse.jdt.ui.tests.callhierarchy.CallHierarchyContentProviderTest;
22
import org.eclipse.jdt.ui.tests.callhierarchy.CallHierarchyContentProviderTest;
23
import org.eclipse.jdt.ui.tests.core.CoreTests;
23
import org.eclipse.jdt.ui.tests.core.CoreTests;
24
import org.eclipse.jdt.ui.tests.jarexport.JarExportTests;
24
import org.eclipse.jdt.ui.tests.packageview.PackageExplorerTests;
25
import org.eclipse.jdt.ui.tests.packageview.PackageExplorerTests;
25
import org.eclipse.jdt.ui.tests.quickfix.QuickFixTest;
26
import org.eclipse.jdt.ui.tests.quickfix.QuickFixTest;
26
import org.eclipse.jdt.ui.tests.search.SearchTest;
27
import org.eclipse.jdt.ui.tests.search.SearchTest;
Lines 67-72 Link Here
67
		addTest(JUnitJUnitTests.suite());
68
		addTest(JUnitJUnitTests.suite());
68
		
69
		
69
		addTest(BuildpathModifierActionTest.suite());
70
		addTest(BuildpathModifierActionTest.suite());
71
		
72
		addTest(JarExportTests.suite());
70
	}
73
	}
71
}
74
}
72
75
(-)ui/org/eclipse/jdt/ui/tests/jarexport/JarExportTests.java (+25 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.tests.jarexport;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
public class JarExportTests {
17
18
	public static Test suite() {
19
		TestSuite suite= new TestSuite("Test for org.eclipse.jdt.ui.tests.jarexport");
20
		//$JUnit-BEGIN$
21
		suite.addTest(FatJarExportTests.allTests());
22
		//$JUnit-END$
23
		return suite;
24
	}
25
}
(-)ui/org/eclipse/jdt/ui/tests/jarexport/FatJarExportTests.java (+245 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.tests.jarexport;
12
13
import java.io.File;
14
import java.util.zip.ZipFile;
15
16
import junit.framework.Test;
17
import junit.framework.TestCase;
18
import junit.framework.TestSuite;
19
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Path;
24
25
import org.eclipse.core.resources.IMarker;
26
import org.eclipse.core.resources.IResource;
27
import org.eclipse.core.resources.IncrementalProjectBuilder;
28
import org.eclipse.core.resources.ResourcesPlugin;
29
30
import org.eclipse.ui.IWorkbenchWindow;
31
import org.eclipse.ui.PlatformUI;
32
33
import org.eclipse.debug.core.ILaunchConfiguration;
34
35
import org.eclipse.jdt.core.IJavaProject;
36
import org.eclipse.jdt.core.IPackageFragment;
37
import org.eclipse.jdt.core.IPackageFragmentRoot;
38
import org.eclipse.jdt.core.JavaCore;
39
40
import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable;
41
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
42
43
import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil;
44
import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarBuilder;
45
import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarPackageWizardPage;
46
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
47
48
import org.eclipse.jdt.testplugin.JavaProjectHelper;
49
import org.eclipse.jdt.testplugin.JavaTestPlugin;
50
51
import org.eclipse.jdt.ui.tests.core.ProjectTestSetup;
52
53
public class FatJarExportTests extends TestCase {
54
55
	private static final Class THIS= FatJarExportTests.class;
56
	
57
	public static Test suite() {
58
		return allTests();
59
	}
60
61
	public static Test allTests() {
62
		return new ProjectTestSetup(new TestSuite(THIS));
63
	}
64
65
	private IJavaProject fProject;
66
	private IPackageFragmentRoot fMainRoot;
67
68
	/**
69
	 * {@inheritDoc}
70
	 */
71
	protected void setUp() throws Exception {
72
		fProject= ProjectTestSetup.getProject();
73
		
74
		fMainRoot= JavaProjectHelper.addSourceContainer(fProject, "src");
75
		IPackageFragment fragment= fMainRoot.createPackageFragment("org.eclipse.jdt.ui.test", true, null);
76
		StringBuffer buf= new StringBuffer();
77
		buf.append("package org.eclipse.jdt.ui.test;\n");
78
		buf.append("import mylib.Foo;\n");
79
		buf.append("public class Main {\n");
80
		buf.append("    public static void main(String[] args) {\n");
81
		buf.append("        new Foo();\n");
82
		buf.append("        new Foo.FooInner();\n");
83
		buf.append("        new Foo.FooInner.FooInnerInner();\n");
84
		buf.append("    }\n");
85
		buf.append("}\n");
86
		fragment.createCompilationUnit("Main.java", buf.toString(), true, null);
87
	}
88
	
89
	/**
90
	 * {@inheritDoc}
91
	 */
92
	protected void tearDown() throws Exception {
93
		JavaProjectHelper.clear(fProject, ProjectTestSetup.getDefaultClasspath());
94
	}
95
	
96
	private static String getFooContent() {
97
		StringBuffer buf= new StringBuffer();
98
		buf.append("package mylib;\n");
99
		buf.append("public class Foo {\n");
100
		buf.append("    public static class FooInner {\n");
101
		buf.append("        public static class FooInnerInner {\n");
102
		buf.append("        }\n");
103
		buf.append("    }\n");
104
		buf.append("}\n");
105
		return buf.toString();
106
	}
107
	
108
	private static void assertFatJarExport(IJavaProject project, String archiveName) throws Exception {
109
		//create class files
110
		ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
111
	
112
		IMarker[] markers= ResourcesPlugin.getWorkspace().getRoot().findMarkers(null, true, IResource.DEPTH_INFINITE);
113
		for (int i= 0; i < markers.length; i++) {
114
			IMarker marker= markers[i];
115
			if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_ERROR) {
116
				assertTrue((String) marker.getAttribute(IMarker.MESSAGE), false);
117
			}
118
		}
119
		
120
		//create data
121
		JarPackageData data= createJarPackageData(project, archiveName);
122
		
123
		//create archive
124
		ZipFile generatedArchive= createArchive(data);
125
	
126
		//assert archive content as expected
127
		assertNotNull(generatedArchive);
128
		assertNotNull(generatedArchive.getEntry("org/eclipse/jdt/ui/test/Main.class"));
129
		assertNotNull(generatedArchive.getEntry("mylib/Foo.class"));
130
		assertNotNull(generatedArchive.getEntry("mylib/Foo$FooInner.class"));
131
		assertNotNull(generatedArchive.getEntry("mylib/Foo$FooInner$FooInnerInner.class"));
132
	}
133
134
	private static JarPackageData createJarPackageData(IJavaProject project, String archiveName) throws CoreException {
135
		JarPackageData data= new JarPackageData();
136
		data.setJarBuilder(new FatJarBuilder());
137
		
138
		IPath destination= ResourcesPlugin.getWorkspace().getRoot().getLocation().append(archiveName);
139
		data.setJarLocation(destination);
140
		
141
		ILaunchConfiguration launchConfig= FatJarPackageWizardPage.createTempLaunchConfig(project);
142
		Object[] children= FatJarPackageWizardPage.getSelectedElementsWithoutContainedChildren(launchConfig, data, new BusyIndicatorRunnableContext());
143
		data.setElements(children);
144
		return data;
145
	}
146
	
147
	private static ZipFile createArchive(JarPackageData data) throws Exception, CoreException {
148
		IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
149
		
150
		IJarExportRunnable op= data.createJarExportRunnable(window.getShell());
151
		window.run(false, false, op);
152
		
153
		IStatus status= op.getStatus();
154
		if (status.getSeverity() == IStatus.ERROR)
155
			throw new CoreException(status);
156
		
157
		return JarPackagerUtil.getArchiveFile(data.getJarLocation());
158
	}
159
	
160
	public void testExportSameSrcRoot() throws Exception {
161
		IPackageFragment pack= fMainRoot.createPackageFragment("mylib", true, null);
162
		try {
163
			pack.createCompilationUnit("Foo.java", getFooContent(), true, null);
164
			
165
			assertFatJarExport(fProject, getName() + ".jar");
166
		} finally {
167
			pack.delete(true, null);
168
		}
169
	}
170
	
171
	public void testExportOtherSrcRoot() throws Exception {
172
		IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(fProject, "other");
173
		try {
174
			IPackageFragment pack= root.createPackageFragment("mylib", true, null);
175
			pack.createCompilationUnit("Foo.java", getFooContent(), true, null);
176
			
177
			assertFatJarExport(fProject, getName() + ".jar");
178
		} finally {
179
			JavaProjectHelper.removeSourceContainer(fProject, root.getElementName());
180
		}
181
	}
182
	
183
	public void testExportOtherProject() throws Exception {
184
		IJavaProject otherProject= JavaProjectHelper.createJavaProject("OtherProject", "bin");
185
		try {
186
			otherProject.setRawClasspath(ProjectTestSetup.getDefaultClasspath(), null);
187
188
			IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(otherProject, "other");
189
			IPackageFragment pack= root.createPackageFragment("mylib", true, null);
190
			pack.createCompilationUnit("Foo.java", getFooContent(), true, null);
191
			
192
			JavaProjectHelper.addRequiredProject(fProject, otherProject);
193
			
194
			assertFatJarExport(fProject, getName() + ".jar");
195
		} finally {
196
			JavaProjectHelper.removeFromClasspath(fProject, otherProject.getProject().getFullPath());
197
			JavaProjectHelper.delete(otherProject);
198
		}
199
	}
200
	
201
	public void testExportInternalLib() throws Exception {
202
		File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB);
203
		IPackageFragmentRoot root= JavaProjectHelper.addLibraryWithImport(fProject, Path.fromOSString(lib.getPath()), null, null); 
204
205
		try {
206
			assertFatJarExport(fProject, getName() + ".jar");
207
		} finally {
208
			JavaProjectHelper.removeFromClasspath(fProject, root.getPath());
209
		}
210
	}
211
	
212
	public void testExportExternalLib() throws Exception {
213
		File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB);
214
		IPackageFragmentRoot root= JavaProjectHelper.addLibrary(fProject, Path.fromOSString(lib.getPath())); 
215
216
		try {
217
			assertFatJarExport(fProject, getName() + ".jar");
218
		} finally {
219
			JavaProjectHelper.removeFromClasspath(fProject, root.getPath());
220
		}
221
	}
222
	
223
	public void testClassFolder() throws Exception {
224
		File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB);
225
		
226
		IPackageFragmentRoot root= JavaProjectHelper.addClassFolderWithImport(fProject, "cf", null, null, lib);
227
		try {
228
			assertFatJarExport(fProject, getName() + ".jar");
229
		} finally {
230
			JavaProjectHelper.removeFromClasspath(fProject, root.getPath());
231
		}
232
	}
233
	
234
	public void testVariable() throws Exception {
235
		File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB);
236
		JavaCore.setClasspathVariable("MYLIB", Path.fromOSString(lib.getPath()), null);
237
		
238
		JavaProjectHelper.addVariableEntry(fProject, new Path("MYLIB"), null, null);
239
		try {
240
			assertFatJarExport(fProject, getName() + ".jar");
241
		} finally {
242
			JavaProjectHelper.removeFromClasspath(fProject, new Path("MYLIB"));
243
		}
244
	}	
245
}
(-)plugin.properties (+2 lines)
Lines 189-194 Link Here
189
jarExportWizard.label=JAR file
189
jarExportWizard.label=JAR file
190
jarExportWizard.description=Export resources into a JAR file on the local file system.
190
jarExportWizard.description=Export resources into a JAR file on the local file system.
191
191
192
fatJarExportWizard.label=Runnable JAR file
193
fatJarExportWizard.description=Export all resources required to run an application into a JAR file on the local file system.
192
194
193
createJarAction.label=Create &JAR
195
createJarAction.label=Create &JAR
194
createJarAction.tooltip=Creates the JAR Based on the Selected JAR Description File
196
createJarAction.tooltip=Creates the JAR Based on the Selected JAR Description File
(-)plugin.xml (+13 lines)
Lines 1906-1911 Link Here
1906
               class="org.eclipse.core.resources.IResource">
1906
               class="org.eclipse.core.resources.IResource">
1907
         </selection>
1907
         </selection>
1908
      </wizard>
1908
      </wizard>
1909
      <wizard
1910
            name="%fatJarExportWizard.label"
1911
            icon="$nl$/icons/full/etool16/exportfatjar_wiz.gif"
1912
            class="org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarPackageWizard"
1913
            category="org.eclipse.jdt.ui.Java"
1914
            id="org.eclipse.jdt.internal.ui.fatjarpackager.JarPackageWizard">
1915
         <description>
1916
            %fatJarExportWizard.description
1917
         </description>
1918
         <selection
1919
               class="org.eclipse.core.resources.IResource">
1920
         </selection>
1921
      </wizard>
1909
   </extension>
1922
   </extension>
1910
   <extension
1923
   <extension
1911
         point="org.eclipse.ui.popupMenus">
1924
         point="org.eclipse.ui.popupMenus">
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWizardPage.java (-237 / +10 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackager;
11
package org.eclipse.jdt.internal.ui.jarpackager;
12
12
13
import java.io.File;
14
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
15
import java.util.HashSet;
14
import java.util.HashSet;
16
import java.util.Iterator;
15
import java.util.Iterator;
Lines 20-26 Link Here
20
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Path;
24
22
25
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IFile;
26
import org.eclipse.core.resources.IFolder;
24
import org.eclipse.core.resources.IFolder;
Lines 36-45 Link Here
36
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridData;
37
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.layout.GridLayout;
38
import org.eclipse.swt.widgets.Button;
36
import org.eclipse.swt.widgets.Button;
39
import org.eclipse.swt.widgets.Combo;
40
import org.eclipse.swt.widgets.Composite;
37
import org.eclipse.swt.widgets.Composite;
41
import org.eclipse.swt.widgets.Event;
42
import org.eclipse.swt.widgets.FileDialog;
43
import org.eclipse.swt.widgets.Label;
38
import org.eclipse.swt.widgets.Label;
44
import org.eclipse.swt.widgets.Link;
39
import org.eclipse.swt.widgets.Link;
45
import org.eclipse.swt.widgets.TreeItem;
40
import org.eclipse.swt.widgets.TreeItem;
Lines 56-62 Link Here
56
import org.eclipse.jface.wizard.IWizardPage;
51
import org.eclipse.jface.wizard.IWizardPage;
57
52
58
import org.eclipse.ui.PlatformUI;
53
import org.eclipse.ui.PlatformUI;
59
import org.eclipse.ui.dialogs.WizardExportResourcesPage;
60
54
61
import org.eclipse.ltk.core.refactoring.RefactoringCore;
55
import org.eclipse.ltk.core.refactoring.RefactoringCore;
62
import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService;
56
import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService;
Lines 82-94 Link Here
82
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
76
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
83
import org.eclipse.jdt.internal.ui.filters.EmptyInnerPackageFilter;
77
import org.eclipse.jdt.internal.ui.filters.EmptyInnerPackageFilter;
84
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
78
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
85
import org.eclipse.jdt.internal.ui.util.SWTUtil;
86
import org.eclipse.jdt.internal.ui.viewsupport.LibraryFilter;
79
import org.eclipse.jdt.internal.ui.viewsupport.LibraryFilter;
87
80
88
/**
81
/**
89
 *	Page 1 of the JAR Package wizard
82
 *	Page 1 of the JAR Package wizard
90
 */
83
 */
91
class JarPackageWizardPage extends WizardExportResourcesPage implements IJarPackageWizardPage {
84
class JarPackageWizardPage extends AbstractJarDestinationWizardPage {
92
85
93
	private JarPackageData fJarPackage;
86
	private JarPackageData fJarPackage;
94
	private IStructuredSelection fInitialSelection;
87
	private IStructuredSelection fInitialSelection;
Lines 101-109 Link Here
101
	private Button	fExportRefactoringsCheckbox;
94
	private Button	fExportRefactoringsCheckbox;
102
	private Link fRefactoringLink;
95
	private Link fRefactoringLink;
103
	
96
	
104
	private Combo	fDestinationNamesCombo;
105
	private Button	fDestinationBrowseButton;
106
	
107
	private Button		fCompressCheckbox;
97
	private Button		fCompressCheckbox;
108
	private Button		fOverwriteCheckbox;
98
	private Button		fOverwriteCheckbox;
109
	private Button		fIncludeDirectoryEntriesCheckbox;
99
	private Button		fIncludeDirectoryEntriesCheckbox;
Lines 116-123 Link Here
116
	private static final String STORE_EXPORT_OUTPUT_FOLDERS= PAGE_NAME + ".EXPORT_OUTPUT_FOLDER"; //$NON-NLS-1$
106
	private static final String STORE_EXPORT_OUTPUT_FOLDERS= PAGE_NAME + ".EXPORT_OUTPUT_FOLDER"; //$NON-NLS-1$
117
	private static final String STORE_EXPORT_JAVA_FILES= PAGE_NAME + ".EXPORT_JAVA_FILES"; //$NON-NLS-1$
107
	private static final String STORE_EXPORT_JAVA_FILES= PAGE_NAME + ".EXPORT_JAVA_FILES"; //$NON-NLS-1$
118
	
108
	
119
	private static final String STORE_DESTINATION_NAMES= PAGE_NAME + ".DESTINATION_NAMES_ID"; //$NON-NLS-1$
120
	
121
	private static final String STORE_REFACTORINGS= PAGE_NAME + ".REFACTORINGS"; //$NON-NLS-1$
109
	private static final String STORE_REFACTORINGS= PAGE_NAME + ".REFACTORINGS"; //$NON-NLS-1$
122
	private static final String STORE_COMPRESS= PAGE_NAME + ".COMPRESS"; //$NON-NLS-1$
110
	private static final String STORE_COMPRESS= PAGE_NAME + ".COMPRESS"; //$NON-NLS-1$
123
	private final static String STORE_OVERWRITE= PAGE_NAME + ".OVERWRITE"; //$NON-NLS-1$
111
	private final static String STORE_OVERWRITE= PAGE_NAME + ".OVERWRITE"; //$NON-NLS-1$
Lines 129-137 Link Here
129
	
117
	
130
	/**
118
	/**
131
	 *	Create an instance of this class
119
	 *	Create an instance of this class
120
	 *
121
	 * @param jarPackage an object containing all required information to make an export
122
	 * @param selection the initial selection
132
	 */
123
	 */
133
	public JarPackageWizardPage(JarPackageData jarPackage, IStructuredSelection selection) {
124
	public JarPackageWizardPage(JarPackageData jarPackage, IStructuredSelection selection) {
134
		super(PAGE_NAME, selection);
125
		super(PAGE_NAME, selection, jarPackage);
135
		setTitle(JarPackagerMessages.JarPackageWizardPage_title); 
126
		setTitle(JarPackagerMessages.JarPackageWizardPage_title); 
136
		setDescription(JarPackagerMessages.JarPackageWizardPage_description); 
127
		setDescription(JarPackagerMessages.JarPackageWizardPage_description); 
137
		fJarPackage= jarPackage;
128
		fJarPackage= jarPackage;
Lines 207-245 Link Here
207
	}
198
	}
208
199
209
	/**
200
	/**
210
	 * Answer the contents of the destination specification widget. If this
211
	 * value does not have the required suffix then add it first.
212
	 * 
213
	 * @return java.lang.String
214
	 */
215
	protected String getDestinationValue() {
216
		String destinationText= fDestinationNamesCombo.getText().trim();
217
		if (destinationText.indexOf('.') < 0)
218
			destinationText += getOutputSuffix();
219
		return destinationText;
220
	}
221
222
	/**
223
	 *	Answer the string to display in self as the destination type
224
	 *
225
	 *	@return java.lang.String
226
	 */
227
	protected String getDestinationLabel() {
228
		return JarPackagerMessages.JarPackageWizardPage_destination_label; 
229
	}
230
231
	/**
232
	 *	Answer the suffix that files exported from this wizard must have.
233
	 *	If this suffix is a file extension (which is typically the case)
234
	 *	then it must include the leading period character.
235
	 *
236
	 *	@return java.lang.String
237
	 */
238
	protected String getOutputSuffix() {
239
		return "." + JarPackagerUtil.JAR_EXTENSION; //$NON-NLS-1$
240
	}
241
242
	/**
243
	 * Returns an iterator over this page's collection of currently-specified 
201
	 * Returns an iterator over this page's collection of currently-specified 
244
	 * elements to be exported. This is the primary element selection facility
202
	 * elements to be exported. This is the primary element selection facility
245
	 * accessor for subclasses.
203
	 * accessor for subclasses.
Lines 257-271 Link Here
257
	 * <code>internalSaveWidgetValues</code>.
215
	 * <code>internalSaveWidgetValues</code>.
258
	 */
216
	 */
259
	public final void saveWidgetValues() {
217
	public final void saveWidgetValues() {
218
		super.saveWidgetValues();
260
		// update directory names history
219
		// update directory names history
261
		IDialogSettings settings= getDialogSettings();
220
		IDialogSettings settings= getDialogSettings();
262
		if (settings != null) {
221
		if (settings != null) {
263
			String[] directoryNames= settings.getArray(STORE_DESTINATION_NAMES);
264
			if (directoryNames == null)
265
				directoryNames= new String[0];
266
			directoryNames= addToHistory(directoryNames, getDestinationValue());
267
			settings.put(STORE_DESTINATION_NAMES, directoryNames);
268
269
			settings.put(STORE_EXPORT_CLASS_FILES, fJarPackage.areClassFilesExported());
222
			settings.put(STORE_EXPORT_CLASS_FILES, fJarPackage.areClassFilesExported());
270
			settings.put(STORE_EXPORT_OUTPUT_FOLDERS, fJarPackage.areOutputFoldersExported());
223
			settings.put(STORE_EXPORT_OUTPUT_FOLDERS, fJarPackage.areOutputFoldersExported());
271
			settings.put(STORE_EXPORT_JAVA_FILES, fJarPackage.areJavaFilesExported());
224
			settings.put(STORE_EXPORT_JAVA_FILES, fJarPackage.areJavaFilesExported());
Lines 298-318 Link Here
298
		fExportOutputFoldersCheckbox.setSelection(fJarPackage.areOutputFoldersExported());
251
		fExportOutputFoldersCheckbox.setSelection(fJarPackage.areOutputFoldersExported());
299
		fExportJavaFilesCheckbox.setSelection(fJarPackage.areJavaFilesExported());
252
		fExportJavaFilesCheckbox.setSelection(fJarPackage.areJavaFilesExported());
300
253
301
		// destination
254
		super.restoreWidgetValues();
302
		if (fJarPackage.getJarLocation().isEmpty())
303
			fDestinationNamesCombo.setText(""); //$NON-NLS-1$
304
		else
305
			fDestinationNamesCombo.setText(fJarPackage.getJarLocation().toOSString());
306
		IDialogSettings settings= getDialogSettings();
307
		if (settings != null) {
308
			String[] directoryNames= settings.getArray(STORE_DESTINATION_NAMES);
309
			if (directoryNames == null)
310
				return; // ie.- no settings stored
311
			if (! fDestinationNamesCombo.getText().equals(directoryNames[0]))
312
				fDestinationNamesCombo.add(fDestinationNamesCombo.getText());
313
			for (int i= 0; i < directoryNames.length; i++)
314
				fDestinationNamesCombo.add(directoryNames[i]);
315
		}
316
		
255
		
317
		// options
256
		// options
318
		if (fExportRefactoringsCheckbox != null)
257
		if (fExportRefactoringsCheckbox != null)
Lines 326-331 Link Here
326
	 *	Initializes the JAR package from last used wizard page values.
265
	 *	Initializes the JAR package from last used wizard page values.
327
	 */
266
	 */
328
	protected void initializeJarPackage() {
267
	protected void initializeJarPackage() {
268
		super.initializeJarPackage();
269
		
329
		IDialogSettings settings= getDialogSettings();
270
		IDialogSettings settings= getDialogSettings();
330
		if (settings != null) {
271
		if (settings != null) {
331
			// source
272
			// source
Lines 339-350 Link Here
339
			fJarPackage.setCompress(settings.getBoolean(STORE_COMPRESS));
280
			fJarPackage.setCompress(settings.getBoolean(STORE_COMPRESS));
340
			fJarPackage.setIncludeDirectoryEntries(settings.getBoolean(STORE_INCLUDE_DIRECTORY_ENTRIES));
281
			fJarPackage.setIncludeDirectoryEntries(settings.getBoolean(STORE_INCLUDE_DIRECTORY_ENTRIES));
341
			fJarPackage.setOverwrite(settings.getBoolean(STORE_OVERWRITE));
282
			fJarPackage.setOverwrite(settings.getBoolean(STORE_OVERWRITE));
342
						
343
			// destination
344
			String[] directoryNames= settings.getArray(STORE_DESTINATION_NAMES);
345
			if (directoryNames == null)
346
				return; // ie.- no settings stored
347
			fJarPackage.setJarLocation(Path.fromOSString(directoryNames[0]));
348
		}
283
		}
349
	}
284
	}
350
285
Lines 365-380 Link Here
365
		fJarPackage.setExportJavaFiles(fExportJavaFilesCheckbox.getSelection());
300
		fJarPackage.setExportJavaFiles(fExportJavaFilesCheckbox.getSelection());
366
		fJarPackage.setElements(getSelectedElements());
301
		fJarPackage.setElements(getSelectedElements());
367
302
368
		// destination
303
		super.updateModel();
369
		String comboText= fDestinationNamesCombo.getText();
370
		IPath path= Path.fromOSString(comboText);
371
372
		if (path.segmentCount() > 0 && ensureTargetFileIsValid(path.toFile()) && path.getFileExtension() == null) 
373
			// append .jar
374
			path= path.addFileExtension(JarPackagerUtil.JAR_EXTENSION);
375
376
		fJarPackage.setJarLocation(path);
377
378
		// options
304
		// options
379
		if (fExportRefactoringsCheckbox != null)
305
		if (fExportRefactoringsCheckbox != null)
380
			fJarPackage.setRefactoringAware(fExportRefactoringsCheckbox.getSelection());
306
			fJarPackage.setRefactoringAware(fExportRefactoringsCheckbox.getSelection());
Lines 386-470 Link Here
386
	}
312
	}
387
313
388
	/**
314
	/**
389
	 * Returns a boolean indicating whether the passed File handle is
390
	 * is valid and available for use.
391
	 *
392
	 * @return boolean
393
	 */
394
	protected boolean ensureTargetFileIsValid(File targetFile) {
395
		if (targetFile.exists() && targetFile.isDirectory() && fDestinationNamesCombo.getText().length() > 0) {
396
			setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_exportDestinationMustNotBeDirectory); 
397
			fDestinationNamesCombo.setFocus();
398
			return false;
399
		}
400
		if (targetFile.exists()) {
401
			if (!targetFile.canWrite()) {
402
				setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_jarFileExistsAndNotWritable); 
403
				fDestinationNamesCombo.setFocus();
404
				return false;
405
			}
406
		}
407
		return true;
408
	}
409
410
	/*
411
	 * Overrides method from WizardExportPage
412
	 */
413
	protected void createDestinationGroup(Composite parent) {
414
		
415
		initializeDialogUnits(parent);
416
		
417
		// destination specification group
418
		Composite destinationSelectionGroup= new Composite(parent, SWT.NONE);
419
		GridLayout layout= new GridLayout();
420
		layout.numColumns= 3;
421
		destinationSelectionGroup.setLayout(layout);
422
		destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
423
424
		new Label(destinationSelectionGroup, SWT.NONE).setText(getDestinationLabel());
425
426
		// destination name entry field
427
		fDestinationNamesCombo= new Combo(destinationSelectionGroup, SWT.SINGLE | SWT.BORDER);
428
		fDestinationNamesCombo.addListener(SWT.Modify, this);
429
		fDestinationNamesCombo.addListener(SWT.Selection, this);
430
		GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
431
		data.widthHint= SIZING_TEXT_FIELD_WIDTH;
432
		fDestinationNamesCombo.setLayoutData(data);
433
434
		// destination browse button
435
		fDestinationBrowseButton= new Button(destinationSelectionGroup, SWT.PUSH);
436
		fDestinationBrowseButton.setText(JarPackagerMessages.JarPackageWizardPage_browseButton_text); 
437
		fDestinationBrowseButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
438
		SWTUtil.setButtonDimensionHint(fDestinationBrowseButton);
439
		fDestinationBrowseButton.addSelectionListener(new SelectionAdapter() {
440
			public void widgetSelected(SelectionEvent e) {
441
				handleDestinationBrowseButtonPressed();
442
			}
443
		});
444
	}
445
446
	/**
447
	 *	Open an appropriate destination browser so that the user can specify a source
448
	 *	to import from
449
	 */
450
	protected void handleDestinationBrowseButtonPressed() {
451
		FileDialog dialog= new FileDialog(getContainer().getShell(), SWT.SAVE);
452
		dialog.setFilterExtensions(new String[] {"*.jar", "*.zip"}); //$NON-NLS-1$ //$NON-NLS-2$
453
454
		String currentSourceString= getDestinationValue();
455
		int lastSeparatorIndex= currentSourceString.lastIndexOf(File.separator);
456
		if (lastSeparatorIndex != -1) {
457
			dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex));
458
			dialog.setFileName(currentSourceString.substring(lastSeparatorIndex + 1, currentSourceString.length()));
459
		}
460
		else
461
			dialog.setFileName(currentSourceString);
462
		String selectedFileName= dialog.open();
463
		if (selectedFileName != null)
464
			fDestinationNamesCombo.setText(selectedFileName);
465
	}
466
467
	/**
468
	 * Returns the resource for the specified path.
315
	 * Returns the resource for the specified path.
469
	 *
316
	 *
470
	 * @param path	the path for which the resource should be returned
317
	 * @param path	the path for which the resource should be returned
Lines 655-675 Link Here
655
			setErrorMessage(null);
502
			setErrorMessage(null);
656
		return complete;
503
		return complete;
657
	}
504
	}
658
659
	/*
660
	 * Implements method from Listener
661
	 */	
662
	public void handleEvent(Event e) {
663
		if (getControl() == null)
664
			return;
665
		update();
666
	}
667
	
668
	protected void update() {
669
		updateModel();
670
		updateWidgetEnablements();
671
		updatePageCompletion();
672
	}
673
	
505
	
674
	protected void updatePageCompletion() {
506
	protected void updatePageCompletion() {
675
		boolean pageComplete= isPageComplete();
507
		boolean pageComplete= isPageComplete();
Lines 691-741 Link Here
691
	/*
523
	/*
692
	 * Overrides method from WizardDataTransferPage
524
	 * Overrides method from WizardDataTransferPage
693
	 */
525
	 */
694
	protected boolean validateDestinationGroup() {
695
		if (fDestinationNamesCombo.getText().length() == 0) {
696
			// Clear error 
697
			if (getErrorMessage() != null)
698
				setErrorMessage(null);
699
			if (getMessage() != null)
700
				setMessage(null);
701
			return false;
702
		}
703
		if (fJarPackage.getAbsoluteJarLocation().toString().endsWith("/")) { //$NON-NLS-1$
704
			setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_exportDestinationMustNotBeDirectory); 
705
			fDestinationNamesCombo.setFocus();
706
			return false;
707
		}
708
		// Check if the Jar is put into the workspace and conflicts with the containers
709
		// exported. If the workspace isn't on the local files system we are fine since
710
		// the Jar is always created in the local file system
711
		IPath workspaceLocation= ResourcesPlugin.getWorkspace().getRoot().getLocation();
712
		if (workspaceLocation != null && workspaceLocation.isPrefixOf(fJarPackage.getAbsoluteJarLocation())) {
713
			int segments= workspaceLocation.matchingFirstSegments(fJarPackage.getAbsoluteJarLocation());
714
			IPath path= fJarPackage.getAbsoluteJarLocation().removeFirstSegments(segments);
715
			IResource resource= ResourcesPlugin.getWorkspace().getRoot().findMember(path);
716
			if (resource != null && resource.getType() == IResource.FILE) {
717
				// test if included
718
				if (JarPackagerUtil.contains(JarPackagerUtil.asResources(fJarPackage.getElements()), (IFile)resource)) {
719
					setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_cantExportJARIntoItself); 
720
					return false;
721
				}
722
			}
723
		}
724
		// Inform user about relative directory
725
		String currentMessage= getMessage();
726
		if (!(new File(fDestinationNamesCombo.getText()).isAbsolute())) {
727
			if (currentMessage == null)
728
				setMessage(JarPackagerMessages.JarPackageWizardPage_info_relativeExportDestination, IMessageProvider.INFORMATION); 
729
		} else {
730
			if (currentMessage != null)
731
				setMessage(null);
732
		}
733
		return ensureTargetFileIsValid(fJarPackage.getAbsoluteJarLocation().toFile());
734
	}
735
736
	/*
737
	 * Overrides method from WizardDataTransferPage
738
	 */
739
	protected boolean validateOptionsGroup() {
526
	protected boolean validateOptionsGroup() {
740
		return true;
527
		return true;
741
	}
528
	}
Lines 799-811 Link Here
799
			return null;
586
			return null;
800
	}
587
	}
801
588
802
	/**
803
	 * Set the current input focus to self's destination entry field
804
 	 */
805
	protected void giveFocusToDestination() {
806
		fDestinationNamesCombo.setFocus();
807
	}
808
809
	/* 
589
	/* 
810
	 * Overrides method from WizardExportResourcePage
590
	 * Overrides method from WizardExportResourcePage
811
	 */
591
	 */
Lines 849-861 Link Here
849
	}
629
	}
850
630
851
	/* 
631
	/* 
852
	 * Implements method from IJarPackageWizardPage.
853
	 */
854
	public void finish() {
855
		saveWidgetValues();
856
	}
857
858
	/* 
859
	 * Method declared on IWizardPage.
632
	 * Method declared on IWizardPage.
860
	 */
633
	 */
861
	public void setPreviousPage(IWizardPage page) {
634
	public void setPreviousPage(IWizardPage page) {
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerUtil.java (-7 / +60 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-32 Link Here
13
import java.io.File;
13
import java.io.File;
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.io.InputStream;
15
import java.io.InputStream;
16
import java.net.URI;
16
import java.util.ArrayList;
17
import java.util.ArrayList;
17
import java.util.Arrays;
18
import java.util.Arrays;
18
import java.util.Iterator;
19
import java.util.Iterator;
19
import java.util.List;
20
import java.util.List;
20
import java.util.jar.JarEntry;
21
import java.util.jar.JarEntry;
21
import java.util.zip.CRC32;
22
import java.util.zip.CRC32;
23
import java.util.zip.ZipException;
24
import java.util.zip.ZipFile;
25
26
import org.eclipse.core.filesystem.EFS;
27
import org.eclipse.core.filesystem.IFileStore;
22
28
23
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.Status;
32
import org.eclipse.core.runtime.Status;
26
33
27
import org.eclipse.core.resources.IContainer;
34
import org.eclipse.core.resources.IContainer;
28
import org.eclipse.core.resources.IFile;
35
import org.eclipse.core.resources.IFile;
29
import org.eclipse.core.resources.IResource;
36
import org.eclipse.core.resources.IResource;
37
import org.eclipse.core.resources.ResourcesPlugin;
30
38
31
import org.eclipse.swt.widgets.Display;
39
import org.eclipse.swt.widgets.Display;
32
import org.eclipse.swt.widgets.Shell;
40
import org.eclipse.swt.widgets.Shell;
Lines 107-120 Link Here
107
	 * Computes and returns the elements as resources.
115
	 * Computes and returns the elements as resources.
108
	 * The underlying resource is used for Java elements.
116
	 * The underlying resource is used for Java elements.
109
	 * 
117
	 * 
118
	 * @param elements elements for which to retrieve the resources from
110
	 * @return a List with the selected resources
119
	 * @return a List with the selected resources
111
	 */
120
	 */
112
	public static List asResources(Object[] fSelectedElements) {
121
	public static List asResources(Object[] elements) {
113
		if (fSelectedElements == null)
122
		if (elements == null)
114
			return null;
123
			return null;
115
		List selectedResources= new ArrayList(fSelectedElements.length);
124
		List selectedResources= new ArrayList(elements.length);
116
		for (int i= 0; i < fSelectedElements.length; i++) {
125
		for (int i= 0; i < elements.length; i++) {
117
			Object element= fSelectedElements[i];
126
			Object element= elements[i];
118
			if (element instanceof IJavaElement) {
127
			if (element instanceof IJavaElement) {
119
				selectedResources.add(((IJavaElement)element).getResource());
128
				selectedResources.add(((IJavaElement)element).getResource());
120
			}
129
			}
Lines 133-138 Link Here
133
	/**
142
	/**
134
	 * Gets the name of the manifest's main class
143
	 * Gets the name of the manifest's main class
135
	 * 
144
	 * 
145
	 * @param jarPackage 
136
	 * @return a string with the name
146
	 * @return a string with the name
137
	 */
147
	 */
138
	static String getMainClassName(JarPackageData jarPackage) {
148
	static String getMainClassName(JarPackageData jarPackage) {
Lines 171-178 Link Here
171
	}
181
	}
172
182
173
	/**
183
	/**
174
	 * Tells whether the specified manifest main class is valid.
184
	 * Tells whether the specified manifest main class is valid.\
175
	 * 
185
	 * 
186
	 * @param data 
187
	 * @param context 
176
	 * @return <code>true</code> if a main class is specified and valid
188
	 * @return <code>true</code> if a main class is specified and valid
177
	 */
189
	 */
178
	public static boolean isMainClassValid(JarPackageData data, IRunnableContext context) {
190
	public static boolean isMainClassValid(JarPackageData data, IRunnableContext context) {
Lines 257-260 Link Here
257
		entry.setSize(size);
269
		entry.setSize(size);
258
		entry.setCrc(crc.getValue());
270
		entry.setCrc(crc.getValue());
259
	}
271
	}
272
	
273
	/**
274
	 * The archive file at the given location
275
	 * 
276
	 * @param location
277
	 *        the location of the archive file
278
	 * @return the archive or null if it could not be retrieved
279
	 * @throws CoreException
280
	 *         if the archive could not be read
281
	 * 
282
	 * @since 3.4
283
	 */
284
	public static ZipFile getArchiveFile(IPath location) throws CoreException {
285
		File localFile= null;
286
287
		IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(location);
288
		if (file != null) {
289
			// internal resource
290
			URI fileLocation= file.getLocationURI();
291
292
			IFileStore fileStore= EFS.getStore(fileLocation);
293
			localFile= fileStore.toLocalFile(EFS.NONE, null);
294
			if (localFile == null)
295
				// non local file system
296
				localFile= fileStore.toLocalFile(EFS.CACHE, null);
297
		} else {
298
			// external resource -> it is ok to use toFile()
299
			localFile= location.toFile();
300
		}
301
302
		if (localFile == null)
303
			return null;
304
305
		try {
306
			return new ZipFile(localFile);
307
		} catch (ZipException e) {
308
			throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, e.getLocalizedMessage(), e));
309
		} catch (IOException e) {
310
			throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, e.getLocalizedMessage(), e));
311
		}
312
	}
260
}
313
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.java (+2 lines)
Lines 248-253 Link Here
248
248
249
	public static String JarPackageReader_error_tagPathNotFound;
249
	public static String JarPackageReader_error_tagPathNotFound;
250
250
251
	public static String JarPackageReader_error_unknownJarBuilder;
252
251
	public static String JarPackageReader_jarPackageReaderWarnings;
253
	public static String JarPackageReader_jarPackageReaderWarnings;
252
254
253
	public static String JarPackageReader_warning_javaElementDoesNotExist;
255
	public static String JarPackageReader_warning_javaElementDoesNotExist;
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarFileExportOperation.java (-12 / +30 lines)
Lines 29-36 Link Here
29
import java.util.Set;
29
import java.util.Set;
30
import java.util.jar.Manifest;
30
import java.util.jar.Manifest;
31
import java.util.zip.ZipException;
31
import java.util.zip.ZipException;
32
import java.util.zip.ZipFile;
32
33
33
import org.eclipse.core.filesystem.EFS;
34
import org.eclipse.core.filesystem.EFS;
35
34
import org.eclipse.core.runtime.CoreException;
36
import org.eclipse.core.runtime.CoreException;
35
import org.eclipse.core.runtime.IPath;
37
import org.eclipse.core.runtime.IPath;
36
import org.eclipse.core.runtime.IProgressMonitor;
38
import org.eclipse.core.runtime.IProgressMonitor;
Lines 76-82 Link Here
76
import org.eclipse.jdt.ui.jarpackager.IJarDescriptionWriter;
78
import org.eclipse.jdt.ui.jarpackager.IJarDescriptionWriter;
77
import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable;
79
import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable;
78
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
80
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
79
import org.eclipse.jdt.ui.jarpackager.JarWriter3;
80
81
81
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
82
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
82
import org.eclipse.jdt.internal.ui.JavaPlugin;
83
import org.eclipse.jdt.internal.ui.JavaPlugin;
Lines 100-106 Link Here
100
		}
101
		}
101
	}
102
	}
102
103
103
	private JarWriter3 fJarWriter;
104
	private JarBuilder fJarBuilder;
104
	private JarPackageData fJarPackage;
105
	private JarPackageData fJarPackage;
105
	private JarPackageData[] fJarPackages;
106
	private JarPackageData[] fJarPackages;
106
	private Shell fParentShell;
107
	private Shell fParentShell;
Lines 206-214 Link Here
206
					continue;
207
					continue;
207
				}
208
				}
208
				
209
				
209
				// Should not happen since we only export source files
210
				if (resource == null) {
210
				if (resource == null)
211
					if (element instanceof IPackageFragmentRoot) {
212
						IPackageFragmentRoot root= (IPackageFragmentRoot) element;
213
						if (root.isArchive()) {
214
							try {
215
								ZipFile file= JarPackagerUtil.getArchiveFile(root.getPath());
216
								if (file != null)
217
									count+= file.size();
218
							} catch (CoreException e) {
219
								JavaPlugin.log(e);
220
							}
221
						}
222
					}
211
					continue;
223
					continue;
224
				}
212
			}
225
			}
213
			else
226
			else
214
				resource= (IResource)element;
227
				resource= (IResource)element;
Lines 340-347 Link Here
340
	}
353
	}
341
354
342
	private void exportJavaElement(IProgressMonitor progressMonitor, IJavaElement je) throws InterruptedException {
355
	private void exportJavaElement(IProgressMonitor progressMonitor, IJavaElement je) throws InterruptedException {
343
		if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && ((IPackageFragmentRoot)je).isArchive())
356
		if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && ((IPackageFragmentRoot)je).isArchive()) {
357
			fJarBuilder.addJar((IPackageFragmentRoot) je, progressMonitor);
344
			return;
358
			return;
359
		}
345
360
346
		Object[] children= fJavaElementContentProvider.getChildren(je);
361
		Object[] children= fJavaElementContentProvider.getChildren(je);
347
		for (int i= 0; i < children.length; i++)
362
		for (int i= 0; i < children.length; i++)
Lines 365-371 Link Here
365
			try {
380
			try {
366
				IPath destinationPath= resource.getFullPath().removeFirstSegments(leadingSegmentsToRemove);
381
				IPath destinationPath= resource.getFullPath().removeFirstSegments(leadingSegmentsToRemove);
367
				progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); 
382
				progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); 
368
				fJarWriter.write((IFile)resource, destinationPath);
383
				fJarBuilder.addFile((IFile)resource, destinationPath);
369
			} catch (CoreException ex) {
384
			} catch (CoreException ex) {
370
				Throwable realEx= ex.getStatus().getException();
385
				Throwable realEx= ex.getStatus().getException();
371
				if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$
386
				if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$
Lines 428-434 Link Here
428
			|| (fJarPackage.areJavaFilesExported() && (isNonJavaResource || (pkgRoot != null && !isClassFile(resource)) || (isInClassFolder && isClassFile(resource) && !fJarPackage.areClassFilesExported())))) {
443
			|| (fJarPackage.areJavaFilesExported() && (isNonJavaResource || (pkgRoot != null && !isClassFile(resource)) || (isInClassFolder && isClassFile(resource) && !fJarPackage.areClassFilesExported())))) {
429
			try {
444
			try {
430
				progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); 
445
				progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); 
431
				fJarWriter.write((IFile) resource, destinationPath);
446
				fJarBuilder.addFile((IFile)resource, destinationPath);
432
			} catch (CoreException ex) {
447
			} catch (CoreException ex) {
433
				Throwable realEx= ex.getStatus().getException();
448
				Throwable realEx= ex.getStatus().getException();
434
				if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$
449
				if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$
Lines 462-468 Link Here
462
					IFile file= (IFile)iter.next();
477
					IFile file= (IFile)iter.next();
463
					IPath classFilePath= baseDestinationPath.append(file.getName());
478
					IPath classFilePath= baseDestinationPath.append(file.getName());
464
					progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, classFilePath.toString())); 
479
					progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, classFilePath.toString())); 
465
					fJarWriter.write(file, classFilePath);
480
					fJarBuilder.addFile(file, classFilePath);
466
				}
481
				}
467
			} catch (CoreException ex) {
482
			} catch (CoreException ex) {
468
				addToStatus(ex);
483
				addToStatus(ex);
Lines 857-864 Link Here
857
				buildProjects(subProgressMonitor);
872
				buildProjects(subProgressMonitor);
858
			} else
873
			} else
859
				progressMonitor.beginTask("", totalWork); //$NON-NLS-1$
874
				progressMonitor.beginTask("", totalWork); //$NON-NLS-1$
860
						
875
			
861
			fJarWriter= fJarPackage.createJarWriter3(fParentShell);
876
			fJarBuilder = fJarPackage.getJarBuilder();
877
			fJarPackage.setManifestProvider(fJarBuilder.getManifestProvider());
878
			fJarBuilder.open(fJarPackage, fParentShell, fStatus);
879
			
862
			exportSelectedElements(progressMonitor);
880
			exportSelectedElements(progressMonitor);
863
			if (getStatus().getSeverity() != IStatus.ERROR) {
881
			if (getStatus().getSeverity() != IStatus.ERROR) {
864
				progressMonitor.subTask(JarPackagerMessages.JarFileExportOperation_savingFiles); 
882
				progressMonitor.subTask(JarPackagerMessages.JarFileExportOperation_savingFiles); 
Lines 868-875 Link Here
868
			addToStatus(ex);
886
			addToStatus(ex);
869
		} finally {
887
		} finally {
870
			try {
888
			try {
871
				if (fJarWriter != null)
889
				if (fJarBuilder != null)
872
					fJarWriter.close();
890
					fJarBuilder.close();
873
			} catch (CoreException ex) {
891
			} catch (CoreException ex) {
874
				addToStatus(ex);
892
				addToStatus(ex);
875
			}
893
			}
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.properties (+1 lines)
Lines 118-123 Link Here
118
JarPackageReader_error_illegalValueForBooleanAttribute= Invalid format. The value for a boolean attribute is invalid.
118
JarPackageReader_error_illegalValueForBooleanAttribute= Invalid format. The value for a boolean attribute is invalid.
119
JarPackageReader_error_tagNameNotFound= Invalid format.  The tag 'name' cannot be found.
119
JarPackageReader_error_tagNameNotFound= Invalid format.  The tag 'name' cannot be found.
120
JarPackageReader_error_tagPathNotFound= Invalid format.  The tag 'path' cannot be found.
120
JarPackageReader_error_tagPathNotFound= Invalid format.  The tag 'path' cannot be found.
121
JarPackageReader_error_unknownJarBuilder=Jar builder ''{0}'' is unkown
121
JarPackageReader_error_tagHandleIdentifierNotFoundOrEmpty= Invalid format: The tag 'handleIdentifier' cannot be found or is empty.
122
JarPackageReader_error_tagHandleIdentifierNotFoundOrEmpty= Invalid format: The tag 'handleIdentifier' cannot be found or is empty.
122
JarPackageReader_warning_javaElementDoesNotExist= Warning: Java element does not exist in workspace
123
JarPackageReader_warning_javaElementDoesNotExist= Warning: Java element does not exist in workspace
123
JarPackageReader_error_duplicateTag= Invalid format. {0} is a duplicate tag.
124
JarPackageReader_error_duplicateTag= Invalid format. {0} is a duplicate tag.
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageReader.java (-13 / +32 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 23-33 Link Here
23
import javax.xml.parsers.DocumentBuilderFactory;
23
import javax.xml.parsers.DocumentBuilderFactory;
24
import javax.xml.parsers.ParserConfigurationException;
24
import javax.xml.parsers.ParserConfigurationException;
25
25
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.resources.IFolder;
28
import org.eclipse.core.resources.IProject;
29
import org.eclipse.core.resources.ResourcesPlugin;
30
31
import org.eclipse.core.runtime.Assert;
26
import org.eclipse.core.runtime.Assert;
32
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.core.runtime.IPath;
Lines 36-41 Link Here
36
import org.eclipse.core.runtime.Path;
31
import org.eclipse.core.runtime.Path;
37
import org.eclipse.core.runtime.Status;
32
import org.eclipse.core.runtime.Status;
38
33
34
import org.eclipse.core.resources.IFile;
35
import org.eclipse.core.resources.IFolder;
36
import org.eclipse.core.resources.IProject;
37
import org.eclipse.core.resources.ResourcesPlugin;
39
38
40
import org.eclipse.ltk.core.refactoring.RefactoringCore;
39
import org.eclipse.ltk.core.refactoring.RefactoringCore;
41
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
40
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
Lines 43-54 Link Here
43
import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService;
42
import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService;
44
import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
43
import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
45
44
46
import org.w3c.dom.Element;
47
import org.w3c.dom.Node;
48
import org.w3c.dom.NodeList;
49
import org.xml.sax.InputSource;
50
import org.xml.sax.SAXException;
51
52
import org.eclipse.jdt.core.IJavaElement;
45
import org.eclipse.jdt.core.IJavaElement;
53
import org.eclipse.jdt.core.IPackageFragment;
46
import org.eclipse.jdt.core.IPackageFragment;
54
import org.eclipse.jdt.core.IType;
47
import org.eclipse.jdt.core.IType;
Lines 59-66 Link Here
59
import org.eclipse.jdt.ui.jarpackager.IJarDescriptionReader;
52
import org.eclipse.jdt.ui.jarpackager.IJarDescriptionReader;
60
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
53
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
61
54
62
import org.eclipse.jdt.internal.ui.JavaPlugin;
63
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
55
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
56
import org.eclipse.jdt.internal.ui.JavaPlugin;
57
import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarBuilder;
58
59
import org.w3c.dom.Element;
60
import org.w3c.dom.Node;
61
import org.w3c.dom.NodeList;
62
import org.xml.sax.InputSource;
63
import org.xml.sax.SAXException;
64
64
65
/**
65
/**
66
 * Reads data from an InputStream and returns a JarPackage
66
 * Reads data from an InputStream and returns a JarPackage
Lines 74-79 Link Here
74
	/**
74
	/**
75
	 * Reads a Jar Package from the underlying stream.
75
	 * Reads a Jar Package from the underlying stream.
76
	 * It is the client's responsibility to close the stream.
76
	 * It is the client's responsibility to close the stream.
77
	 * @param inputStream 
77
	 */
78
	 */
78
	public JarPackageReader(InputStream inputStream) {
79
	public JarPackageReader(InputStream inputStream) {
79
		Assert.isNotNull(inputStream);
80
		Assert.isNotNull(inputStream);
Lines 139-144 Link Here
139
			if (jarPackage.areGeneratedFilesExported())
140
			if (jarPackage.areGeneratedFilesExported())
140
				xmlReadManifest(jarPackage, element);
141
				xmlReadManifest(jarPackage, element);
141
			xmlReadSelectedElements(jarPackage, element);
142
			xmlReadSelectedElements(jarPackage, element);
143
			
144
			// fatjar read builder props
145
			xmlReadFatjar(jarPackage, element);
142
		}
146
		}
143
		return jarPackage;
147
		return jarPackage;
144
	}
148
	}
Lines 403-406 Link Here
403
	protected void addWarning(String message, Throwable error) {
407
	protected void addWarning(String message, Throwable error) {
404
		fWarnings.add(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), 0, message, error));
408
		fWarnings.add(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), 0, message, error));
405
	}
409
	}
410
411
	private void xmlReadFatjar(JarPackageData jarPackage, Element element) throws java.io.IOException {
412
		if (element.getNodeName().equals("fatjar")) { //$NON-NLS-1$
413
			String id = element.getAttribute("builder"); //$NON-NLS-1$
414
			if (FatJarBuilder.BUILDER_ID.equals(id)) {
415
				jarPackage.setJarBuilder(new FatJarBuilder());
416
			} else if (PlainJarBuilder.BUILDER_ID.equals(id)) {
417
				//the default anyway
418
			} else {
419
				throw new IOException(Messages.format(JarPackagerMessages.JarPackageReader_error_unknownJarBuilder, id)); 
420
			}
421
			jarPackage.setLaunchConfigurationName(element.getAttribute("launchConfig")); //$NON-NLS-1$
422
		}
423
	}
424
406
}
425
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWriter.java (-2 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 34-40 Link Here
34
import org.eclipse.core.resources.IProject;
34
import org.eclipse.core.resources.IProject;
35
import org.eclipse.core.resources.IResource;
35
import org.eclipse.core.resources.IResource;
36
36
37
38
import org.eclipse.ltk.core.refactoring.RefactoringCore;
37
import org.eclipse.ltk.core.refactoring.RefactoringCore;
39
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
38
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
40
import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
39
import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
Lines 64-69 Link Here
64
	/**
63
	/**
65
	 * Create a JarPackageWriter on the given output stream.
64
	 * Create a JarPackageWriter on the given output stream.
66
	 * It is the clients responsibility to close the output stream.
65
	 * It is the clients responsibility to close the output stream.
66
	 * 
67
	 * @param outputStream 
68
	 * @param encoding 
67
	 */
69
	 */
68
	public JarPackageWriter(OutputStream outputStream, String encoding) {
70
	public JarPackageWriter(OutputStream outputStream, String encoding) {
69
		Assert.isNotNull(outputStream);
71
		Assert.isNotNull(outputStream);
Lines 84-89 Link Here
84
	 * Writes a XML representation of the JAR specification
86
	 * Writes a XML representation of the JAR specification
85
	 * to to the underlying stream.
87
	 * to to the underlying stream.
86
	 * 
88
	 * 
89
	 * @param jarPackage 
87
	 * @exception IOException	if writing to the underlying stream fails
90
	 * @exception IOException	if writing to the underlying stream fails
88
	 */
91
	 */
89
	public void writeXML(JarPackageData jarPackage) throws IOException {
92
	public void writeXML(JarPackageData jarPackage) throws IOException {
Lines 109-114 Link Here
109
			xmlWriteManifest(jarPackage, document, xmlJarDesc);
112
			xmlWriteManifest(jarPackage, document, xmlJarDesc);
110
		xmlWriteSelectedElements(jarPackage, document, xmlJarDesc);
113
		xmlWriteSelectedElements(jarPackage, document, xmlJarDesc);
111
114
115
		xmlWriteFatjar(jarPackage, document, xmlJarDesc);
116
112
		try {
117
		try {
113
			// Write the document to the stream
118
			// Write the document to the stream
114
			Transformer transformer=TransformerFactory.newInstance().newTransformer();
119
			Transformer transformer=TransformerFactory.newInstance().newTransformer();
Lines 285-288 Link Here
285
	public IStatus getStatus() {
290
	public IStatus getStatus() {
286
		return new Status(IStatus.OK, JavaPlugin.getPluginId(), 0, "", null); //$NON-NLS-1$
291
		return new Status(IStatus.OK, JavaPlugin.getPluginId(), 0, "", null); //$NON-NLS-1$
287
	}
292
	}
293
		
294
	private void xmlWriteFatjar(JarPackageData jarPackage, Document document, Element xmlJarDesc) throws DOMException {
295
		Element fatjar= document.createElement("fatjar"); //$NON-NLS-1$
296
		xmlJarDesc.appendChild(fatjar);
297
		fatjar.setAttribute("builder", jarPackage.getJarBuilder().getId()); //$NON-NLS-1$
298
		fatjar.setAttribute("launchConfig", jarPackage.getLaunchConfigurationName()); //$NON-NLS-1$
299
	}
288
}
300
}
(-)ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java (+1 lines)
Lines 394-399 Link Here
394
	public static final ImageDescriptor DESC_WIZBAN_REFACTOR_PULL_UP= createUnManaged(T_WIZBAN, "pullup_wiz.png");	//$NON-NLS-1$
394
	public static final ImageDescriptor DESC_WIZBAN_REFACTOR_PULL_UP= createUnManaged(T_WIZBAN, "pullup_wiz.png");	//$NON-NLS-1$
395
	public static final ImageDescriptor DESC_WIZBAN_REFACTOR_FIX_DEPRECATION= createUnManaged(T_WIZBAN, "fixdepr_wiz.png");	//$NON-NLS-1$
395
	public static final ImageDescriptor DESC_WIZBAN_REFACTOR_FIX_DEPRECATION= createUnManaged(T_WIZBAN, "fixdepr_wiz.png");	//$NON-NLS-1$
396
	public static final ImageDescriptor DESC_WIZBAN_JAR_PACKAGER= createUnManaged(T_WIZBAN, "jar_pack_wiz.png"); 		//$NON-NLS-1$
396
	public static final ImageDescriptor DESC_WIZBAN_JAR_PACKAGER= createUnManaged(T_WIZBAN, "jar_pack_wiz.png"); 		//$NON-NLS-1$
397
	public static final ImageDescriptor DESC_WIZBAN_FAT_JAR_PACKAGER= createUnManaged(T_WIZBAN, "fatjar_pack_wiz.png"); 		//$NON-NLS-1$
397
	public static final ImageDescriptor DESC_WIZBAN_REFACTOR_EXTRACT_SUPERTYPE= createUnManaged(T_WIZBAN, "extractsupertype_wiz.png");	//$NON-NLS-1$
398
	public static final ImageDescriptor DESC_WIZBAN_REFACTOR_EXTRACT_SUPERTYPE= createUnManaged(T_WIZBAN, "extractsupertype_wiz.png");	//$NON-NLS-1$
398
	public static final ImageDescriptor DESC_WIZBAN_REPLACE_JAR= createUnManaged(T_WIZBAN, "replacejar_wiz.png"); 		//$NON-NLS-1$
399
	public static final ImageDescriptor DESC_WIZBAN_REPLACE_JAR= createUnManaged(T_WIZBAN, "replacejar_wiz.png"); 		//$NON-NLS-1$
399
	public static final ImageDescriptor DESC_WIZBAN_JAVA_WORKINGSET= createUnManaged(T_WIZBAN, "java_workingset_wiz.png");//$NON-NLS-1$
400
	public static final ImageDescriptor DESC_WIZBAN_JAVA_WORKINGSET= createUnManaged(T_WIZBAN, "java_workingset_wiz.png");//$NON-NLS-1$
(-)ui/org/eclipse/jdt/ui/jarpackager/JarWriter3.java (-1 / +47 lines)
Lines 50-56 Link Here
50
50
51
import org.eclipse.swt.widgets.Shell;
51
import org.eclipse.swt.widgets.Shell;
52
52
53
54
import org.eclipse.ltk.core.refactoring.RefactoringCore;
53
import org.eclipse.ltk.core.refactoring.RefactoringCore;
55
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
54
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
56
import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
55
import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
Lines 162-167 Link Here
162
	 * 
161
	 * 
163
	 * @throws IOException
162
	 * @throws IOException
164
	 *             if an I/O error has occurred
163
	 *             if an I/O error has occurred
164
	 * @throws CoreException 
165
	 */
165
	 */
166
	protected void addDirectories(IResource resource, IPath destinationPath) throws IOException, CoreException {
166
	protected void addDirectories(IResource resource, IPath destinationPath) throws IOException, CoreException {
167
		IContainer parent= null;
167
		IContainer parent= null;
Lines 250-255 Link Here
250
			// fJarOutputStream.closeEntry();
250
			// fJarOutputStream.closeEntry();
251
		}
251
		}
252
	}
252
	}
253
	
254
	/**
255
	 * Creates a new JarEntry with the passed path and contents, and writes it
256
	 * to the current archive.
257
	 *
258
	 * @param	contentStream		the content to write
259
	 * @param	path				the path inside the archive
260
	 * 
261
     * @throws	IOException			if an I/O error has occurred
262
	 * @throws	CoreException 		if the resource can-t be accessed
263
	 * 
264
	 * @since 3.4
265
	 */
266
	public void addStream(InputStream contentStream, String path) throws IOException, CoreException {
267
		JarEntry newEntry= new JarEntry(path.replace(File.separatorChar, '/'));
268
		byte[] readBuffer= new byte[4096];             
269
		
270
		if (fJarPackage.isCompressed())
271
			newEntry.setMethod(ZipEntry.DEFLATED);
272
			// Entry is filled automatically.
273
		else {
274
			newEntry.setMethod(ZipEntry.STORED);
275
			// JarPackagerUtil.calculateCrcAndSize(newEntry, resource.getContents(false), readBuffer);
276
		}
277
		
278
		long lastModified= System.currentTimeMillis();
279
		
280
		// Set modification time
281
		newEntry.setTime(lastModified);
282
		
283
		try {		
284
			fJarOutputStream.putNextEntry(newEntry);
285
			int count;
286
			while ((count= contentStream.read(readBuffer, 0, readBuffer.length)) != -1)
287
				fJarOutputStream.write(readBuffer, 0, count);
288
		} finally  {
289
			/*
290
			 * Commented out because some JREs throw an NPE if a stream
291
			 * is closed twice. This works because
292
			 * a) putNextEntry closes the previous entry
293
			 * b) closing the stream closes the last entry
294
			 */
295
			// fJarOutputStream.closeEntry();
296
		}
297
	}
253
298
254
	/**
299
	/**
255
	 * Creates a new JAR file entry containing the refactoring history.
300
	 * Creates a new JAR file entry containing the refactoring history.
Lines 427-432 Link Here
427
	 *             if the meta file could not be found
472
	 *             if the meta file could not be found
428
	 * @throws IOException
473
	 * @throws IOException
429
	 *             if an input/output error occurs
474
	 *             if an input/output error occurs
475
	 * @throws CoreException 
430
	 */
476
	 */
431
	private void writeMetaData(final JarPackageData data, final File file, final IPath path) throws FileNotFoundException, IOException, CoreException {
477
	private void writeMetaData(final JarPackageData data, final File file, final IPath path) throws FileNotFoundException, IOException, CoreException {
432
		Assert.isNotNull(data);
478
		Assert.isNotNull(data);
(-)ui/org/eclipse/jdt/ui/jarpackager/JarPackageData.java (-6 / +57 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-27 Link Here
13
import java.io.InputStream;
13
import java.io.InputStream;
14
import java.io.OutputStream;
14
import java.io.OutputStream;
15
15
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
20
import org.eclipse.core.runtime.Assert;
16
import org.eclipse.core.runtime.Assert;
21
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.Path;
19
import org.eclipse.core.runtime.Path;
24
20
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.ResourcesPlugin;
24
25
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.swt.widgets.Shell;
26
26
27
import org.eclipse.jface.operation.IRunnableContext;
27
import org.eclipse.jface.operation.IRunnableContext;
Lines 31-43 Link Here
31
import org.eclipse.jdt.core.IPackageFragment;
31
import org.eclipse.jdt.core.IPackageFragment;
32
import org.eclipse.jdt.core.IType;
32
import org.eclipse.jdt.core.IType;
33
33
34
35
import org.eclipse.jdt.internal.ui.JavaPlugin;
34
import org.eclipse.jdt.internal.ui.JavaPlugin;
35
import org.eclipse.jdt.internal.ui.jarpackager.JarBuilder;
36
import org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation;
36
import org.eclipse.jdt.internal.ui.jarpackager.JarFileExportOperation;
37
import org.eclipse.jdt.internal.ui.jarpackager.JarPackageReader;
37
import org.eclipse.jdt.internal.ui.jarpackager.JarPackageReader;
38
import org.eclipse.jdt.internal.ui.jarpackager.JarPackageWriter;
38
import org.eclipse.jdt.internal.ui.jarpackager.JarPackageWriter;
39
import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil;
39
import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil;
40
import org.eclipse.jdt.internal.ui.jarpackager.ManifestProvider;
40
import org.eclipse.jdt.internal.ui.jarpackager.ManifestProvider;
41
import org.eclipse.jdt.internal.ui.jarpackager.PlainJarBuilder;
41
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
42
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
42
43
43
/**
44
/**
Lines 144-153 Link Here
144
	// The refactoring descriptors to export
145
	// The refactoring descriptors to export
145
	private RefactoringDescriptorProxy[] fRefactoringDescriptors= {};
146
	private RefactoringDescriptorProxy[] fRefactoringDescriptors= {};
146
147
148
	// Builder used by the JarFileExportOperation to build the jar file
149
	private JarBuilder fJarBuilder;
150
	
151
	// The launch configuration used by the fat jar builder to determine dependencies
152
 	private String  fLaunchConfigurationName;
153
147
	/**
154
	/**
148
	 * Creates a new Jar Package Data structure
155
	 * Creates a new Jar Package Data structure
149
	 */
156
	 */
150
	public JarPackageData() {
157
	public JarPackageData() {
158
		setJarBuilder(new PlainJarBuilder());
151
		setExportClassFiles(true);
159
		setExportClassFiles(true);
152
		setExportOutputFolders(false);
160
		setExportOutputFolders(false);
153
		setUseSourceFolderHierarchy(false);
161
		setUseSourceFolderHierarchy(false);
Lines 1162-1165 Link Here
1162
	public void setExportStructuralOnly(boolean structural) {
1170
	public void setExportStructuralOnly(boolean structural) {
1163
		fRefactoringStructural= structural;
1171
		fRefactoringStructural= structural;
1164
	}
1172
	}
1173
	
1174
	/**
1175
	 * Returns the jar builder to use to build the jar described by this package data.
1176
	 * 
1177
	 * @return the builder to use
1178
	 * @since 3.4
1179
	 */
1180
	public JarBuilder getJarBuilder() {
1181
		return fJarBuilder;
1182
	}
1183
1184
	/**
1185
	 * Set the jar builder to use to build the jar.
1186
	 * 
1187
	 * @param jarBuilder
1188
	 *        the builder to use
1189
	 * @since 3.4
1190
	 */
1191
	public void setJarBuilder(JarBuilder jarBuilder) {
1192
		fJarBuilder= jarBuilder;
1193
	}
1194
1195
	/**
1196
	 * Get the name of the launch configuration from which to create an executable jar.
1197
	 * 
1198
	 * @return the name of the launch configuration
1199
	 * @since 3.4
1200
	 */
1201
	public String getLaunchConfigurationName() {
1202
		return fLaunchConfigurationName;
1203
	}
1204
1205
	/**
1206
	 * Set the name of the launch configuration form which to create an executable jar.
1207
	 * 
1208
	 * @param name
1209
	 *        name of the launch configuration
1210
	 * @since 3.4
1211
	 */
1212
	public void setLaunchConfigurationName(String name) {
1213
		fLaunchConfigurationName= name;
1214
	}
1215
1165
}
1216
}
(-)META-INF/MANIFEST.MF (-3 / +4 lines)
Lines 40-46 Link Here
40
 org.eclipse.jdt.internal.corext.refactoring.util;x-internal:=true,
40
 org.eclipse.jdt.internal.corext.refactoring.util;x-internal:=true,
41
 org.eclipse.jdt.internal.corext.template.java;x-internal:=true,
41
 org.eclipse.jdt.internal.corext.template.java;x-internal:=true,
42
 org.eclipse.jdt.internal.corext.util;x-friends:="org.eclipse.jdt.junit",
42
 org.eclipse.jdt.internal.corext.util;x-friends:="org.eclipse.jdt.junit",
43
 org.eclipse.jdt.internal.ui;x-friends:="org.eclipse.jdt.junit, org.eclipse.jdt.apt.ui",
43
 org.eclipse.jdt.internal.ui;x-friends:="org.eclipse.jdt.junit,org.eclipse.jdt.apt.ui",
44
 org.eclipse.jdt.internal.ui.actions;x-friends:="org.eclipse.jdt.junit",
44
 org.eclipse.jdt.internal.ui.actions;x-friends:="org.eclipse.jdt.junit",
45
 org.eclipse.jdt.internal.ui.browsing;x-internal:=true,
45
 org.eclipse.jdt.internal.ui.browsing;x-internal:=true,
46
 org.eclipse.jdt.internal.ui.callhierarchy;x-internal:=true,
46
 org.eclipse.jdt.internal.ui.callhierarchy;x-internal:=true,
Lines 53-58 Link Here
53
 org.eclipse.jdt.internal.ui.infoviews;x-internal:=true,
53
 org.eclipse.jdt.internal.ui.infoviews;x-internal:=true,
54
 org.eclipse.jdt.internal.ui.jarimport;x-internal:=true,
54
 org.eclipse.jdt.internal.ui.jarimport;x-internal:=true,
55
 org.eclipse.jdt.internal.ui.jarpackager;x-internal:=true,
55
 org.eclipse.jdt.internal.ui.jarpackager;x-internal:=true,
56
 org.eclipse.jdt.internal.ui.jarpackagerfat;x-internal:=true,
56
 org.eclipse.jdt.internal.ui.javadocexport;x-internal:=true,
57
 org.eclipse.jdt.internal.ui.javadocexport;x-internal:=true,
57
 org.eclipse.jdt.internal.ui.javaeditor;x-friends:="org.eclipse.jdt.junit",
58
 org.eclipse.jdt.internal.ui.javaeditor;x-friends:="org.eclipse.jdt.junit",
58
 org.eclipse.jdt.internal.ui.javaeditor.saveparticipant;x-internal:=true,
59
 org.eclipse.jdt.internal.ui.javaeditor.saveparticipant;x-internal:=true,
Lines 87-95 Link Here
87
 org.eclipse.jdt.internal.ui.text.template.contentassist;x-internal:=true,
88
 org.eclipse.jdt.internal.ui.text.template.contentassist;x-internal:=true,
88
 org.eclipse.jdt.internal.ui.text.template.preferences;x-internal:=true,
89
 org.eclipse.jdt.internal.ui.text.template.preferences;x-internal:=true,
89
 org.eclipse.jdt.internal.ui.typehierarchy;x-internal:=true,
90
 org.eclipse.jdt.internal.ui.typehierarchy;x-internal:=true,
90
 org.eclipse.jdt.internal.ui.util;x-friends:="org.eclipse.jdt.junit, org.eclipse.jdt.apt.ui",
91
 org.eclipse.jdt.internal.ui.util;x-friends:="org.eclipse.jdt.junit,org.eclipse.jdt.apt.ui",
91
 org.eclipse.jdt.internal.ui.viewsupport;x-friends:="org.eclipse.jdt.junit",
92
 org.eclipse.jdt.internal.ui.viewsupport;x-friends:="org.eclipse.jdt.junit",
92
 org.eclipse.jdt.internal.ui.wizards;x-friends:="org.eclipse.jdt.junit, org.eclipse.jdt.apt.ui",
93
 org.eclipse.jdt.internal.ui.wizards;x-friends:="org.eclipse.jdt.junit,org.eclipse.jdt.apt.ui",
93
 org.eclipse.jdt.internal.ui.wizards.buildpaths;x-internal:=true,
94
 org.eclipse.jdt.internal.ui.wizards.buildpaths;x-internal:=true,
94
 org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage;x-internal:=true,
95
 org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage;x-internal:=true,
95
 org.eclipse.jdt.internal.ui.wizards.dialogfields;x-friends:="org.eclipse.jdt.apt.ui",
96
 org.eclipse.jdt.internal.ui.wizards.dialogfields;x-friends:="org.eclipse.jdt.apt.ui",
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/JarBuilderProperties.java (+170 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackagerfat;
12
13
import java.io.IOException;
14
import java.io.StringReader;
15
import java.io.StringWriter;
16
17
import javax.xml.parsers.DocumentBuilder;
18
import javax.xml.parsers.DocumentBuilderFactory;
19
import javax.xml.parsers.ParserConfigurationException;
20
import javax.xml.transform.OutputKeys;
21
import javax.xml.transform.Transformer;
22
import javax.xml.transform.TransformerException;
23
import javax.xml.transform.TransformerFactory;
24
import javax.xml.transform.dom.DOMSource;
25
import javax.xml.transform.stream.StreamResult;
26
27
import org.w3c.dom.Document;
28
import org.w3c.dom.Element;
29
import org.w3c.dom.NamedNodeMap;
30
import org.w3c.dom.Node;
31
import org.xml.sax.InputSource;
32
import org.xml.sax.SAXException;
33
34
/**
35
 * TODO: Remove, not used?
36
 * @since 3.4
37
 */
38
public class JarBuilderProperties {
39
40
	private JarBuilderProperty[] fProperties;
41
42
	public JarBuilderProperties(JarBuilderProperty[] properties) {
43
		fProperties= properties;
44
	}
45
46
	public JarBuilderProperty[] getProperties() {
47
		return fProperties;
48
	}
49
50
	public String xmlExport() throws IOException {
51
52
		String result;
53
		DocumentBuilder docBuilder= null;
54
		DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
55
		factory.setValidating(false);
56
		try {
57
			docBuilder= factory.newDocumentBuilder();
58
		} catch (ParserConfigurationException ex) {
59
			throw new IOException(FatJarPackagerMessages.JarWriter_error_couldNotGetXmlBuilder);
60
		}
61
		Document document= docBuilder.newDocument();
62
63
		xmlExport(document, null);
64
65
		try {
66
			// Write the document to the stream
67
			Transformer transformer= TransformerFactory.newInstance().newTransformer();
68
			transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
69
			transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
70
			transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
71
			transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
72
			transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$
73
			DOMSource source= new DOMSource(document);
74
			StringWriter writer= new StringWriter();
75
			StreamResult strResult= new StreamResult(writer);
76
			transformer.transform(source, strResult);
77
			result= writer.toString();
78
		} catch (TransformerException e) {
79
			throw new IOException(FatJarPackagerMessages.JarWriter_error_couldNotTransformToXML);
80
		}
81
82
		return result.trim();
83
	}
84
85
	public void xmlExport(Document document, Element parent) {
86
		// Create the document
87
		Element xmlProps= document.createElement("props"); //$NON-NLS-1$
88
		if (parent == null) {
89
			document.appendChild(xmlProps);
90
		} else {
91
			parent.appendChild(xmlProps);
92
		}
93
94
		for (int i= 0; i < fProperties.length; i++) {
95
			JarBuilderProperty property= fProperties[i];
96
			xmlProps.setAttribute(property.getName(), property.getValue());
97
		}
98
99
	}
100
101
	public void xmlImport(String propertiesImportData) throws IOException {
102
103
		DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
104
		factory.setValidating(false);
105
		DocumentBuilder parser= null;
106
		Element xmlProps= null;
107
		try {
108
			parser= factory.newDocumentBuilder();
109
			StringReader reader= new StringReader(propertiesImportData);
110
			xmlProps= parser.parse(new InputSource(reader)).getDocumentElement();
111
		} catch (ParserConfigurationException ex) {
112
			throw new IOException(ex.getLocalizedMessage());
113
		} catch (SAXException ex) {
114
			throw new IOException(ex.getLocalizedMessage());
115
		} finally {
116
		}
117
		xmlImport(xmlProps);
118
	}
119
120
	public void xmlImport(Element xmlProps) throws IOException {
121
122
		if (!xmlProps.getNodeName().equals("props")) { //$NON-NLS-1$
123
			throw new IOException("invalid XML format <props>"); //$NON-NLS-1$
124
		}
125
		NamedNodeMap map= xmlProps.getAttributes();
126
		for (int j= 0; j < map.getLength(); j++) {
127
			Node item= map.item(j);
128
			String name= item.getNodeName();
129
			String value= item.getNodeValue();
130
			setProperty(name, value);
131
		}
132
	}
133
134
135
	private boolean setProperty(String name, String value) {
136
		boolean result= false;
137
		for (int i= 0; i < fProperties.length; i++) {
138
			JarBuilderProperty property= fProperties[i];
139
			if (name.equals(property.getName())) {
140
				property.setValue(value);
141
				result= true;
142
				break;
143
			}
144
		}
145
		return result;
146
	}
147
148
	public String toString() {
149
		String result;
150
		try {
151
			result= xmlExport();
152
		} catch (IOException e) {
153
			result= "<error>" + e.getLocalizedMessage() + "</error>"; //$NON-NLS-1$ //$NON-NLS-2$
154
		}
155
		return result;
156
	}
157
158
	public JarBuilderProperty getProperty(String propertyName) {
159
		JarBuilderProperty result= null;
160
		JarBuilderProperty[] props= getProperties();
161
		for (int i= 0; i < props.length; i++) {
162
			if (propertyName.equals(props[i].getName())) {
163
				result= props[i];
164
				break;
165
			}
166
		}
167
		return result;
168
	}
169
170
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizardPage.java (+598 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackagerfat;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.HashSet;
17
import java.util.Iterator;
18
import java.util.List;
19
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.core.runtime.Status;
25
26
import org.eclipse.core.resources.IProject;
27
import org.eclipse.core.resources.IResource;
28
import org.eclipse.core.resources.ResourcesPlugin;
29
30
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.layout.GridData;
32
import org.eclipse.swt.layout.GridLayout;
33
import org.eclipse.swt.widgets.Combo;
34
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Label;
36
import org.eclipse.swt.widgets.Listener;
37
38
import org.eclipse.jface.dialogs.Dialog;
39
import org.eclipse.jface.dialogs.IDialogSettings;
40
import org.eclipse.jface.operation.IRunnableContext;
41
import org.eclipse.jface.viewers.StructuredSelection;
42
43
import org.eclipse.debug.core.DebugPlugin;
44
import org.eclipse.debug.core.ILaunchConfiguration;
45
import org.eclipse.debug.core.ILaunchConfigurationType;
46
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
47
import org.eclipse.debug.core.ILaunchManager;
48
49
import org.eclipse.jdt.core.IClasspathEntry;
50
import org.eclipse.jdt.core.IJavaProject;
51
import org.eclipse.jdt.core.IPackageFragmentRoot;
52
import org.eclipse.jdt.core.IType;
53
import org.eclipse.jdt.core.JavaCore;
54
import org.eclipse.jdt.core.JavaModelException;
55
import org.eclipse.jdt.core.search.IJavaSearchScope;
56
57
import org.eclipse.jdt.internal.corext.util.Messages;
58
59
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
60
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
61
import org.eclipse.jdt.launching.JavaRuntime;
62
63
import org.eclipse.jdt.ui.JavaUI;
64
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
65
66
import org.eclipse.jdt.internal.ui.JavaPlugin;
67
import org.eclipse.jdt.internal.ui.jarpackager.AbstractJarDestinationWizardPage;
68
import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil;
69
import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
70
import org.eclipse.jdt.internal.ui.util.MainMethodSearchEngine;
71
72
/**
73
 * First page for the runnable jar export wizard
74
 * @since 3.4
75
 */
76
public class FatJarPackageWizardPage extends AbstractJarDestinationWizardPage implements Listener {
77
78
	private abstract static class LaunchConfigurationElement {
79
80
		public abstract ILaunchConfiguration getLaunchConfiguration();
81
82
		public abstract String getLaunchConfigurationName();
83
84
		public void dispose() {
85
			//do nothing
86
		}
87
	}
88
89
	private static class ExistingLaunchConfigurationElement extends LaunchConfigurationElement {
90
91
		private ILaunchConfiguration fLaunchConfiguration;
92
		private final String fProjectName;
93
94
		public ExistingLaunchConfigurationElement(ILaunchConfiguration launchConfiguration, String projectName) {
95
			fLaunchConfiguration= launchConfiguration;
96
			fProjectName= projectName;
97
		}
98
99
		/**
100
		 * {@inheritDoc}
101
		 */
102
		public ILaunchConfiguration getLaunchConfiguration() {
103
			return fLaunchConfiguration;
104
		}
105
106
		/**
107
		 * {@inheritDoc}
108
		 */
109
		public String getLaunchConfigurationName() {
110
			return fProjectName + " : " + fLaunchConfiguration.getName(); //$NON-NLS-1$
111
		}
112
113
	}
114
115
	private static class DefaultLaunchConfigurationElement extends LaunchConfigurationElement {
116
		
117
		private IJavaProject fJavaProject;
118
		private ILaunchConfiguration fLaunchConfiguration;
119
120
		public DefaultLaunchConfigurationElement(IJavaProject javaProject) {
121
			fJavaProject= javaProject;
122
		}
123
124
		/**
125
		 * {@inheritDoc}
126
		 */
127
		public ILaunchConfiguration getLaunchConfiguration() {
128
			if (fLaunchConfiguration == null)
129
				fLaunchConfiguration= createTempLaunchConfig(fJavaProject);
130
131
			return fLaunchConfiguration;
132
		}
133
134
		/**
135
		 * {@inheritDoc}
136
		 */
137
		public String getLaunchConfigurationName() {
138
			return Messages.format(FatJarPackagerMessages.FatJarPackageWizardPage_defaultLaunchConfigName, fJavaProject.getElementName());
139
		}
140
141
		/**
142
		 * {@inheritDoc}
143
		 */
144
		public void dispose() {
145
			if (fLaunchConfiguration != null) {
146
				try {
147
					fLaunchConfiguration.delete();
148
					fLaunchConfiguration= null;
149
				} catch (CoreException e) {
150
					JavaPlugin.log(e);
151
				}
152
			}
153
		}
154
	}
155
156
	private static final String PAGE_NAME= "FatJarPackageWizardPage"; //$NON-NLS-1$
157
	private static final String STORE_LAUNCH_CONFIGURATION_SELECTION_NAME= PAGE_NAME + ".LAUNCH_CONFIGURATION_SELECTION_NAME"; //$NON-NLS-1$
158
	private static final String STORE_DESTINATION_ELEMENT= PAGE_NAME + ".DESTINATION_PATH_SELECTION"; //$NON-NLS-1$
159
160
	private final JarPackageData fJarPackage;
161
	/**
162
	 * Model for the launch combo box. Element: {@link LaunchConfigurationElement}
163
	 */
164
	private final ArrayList fLauchConfigurationModel;
165
	
166
	private Combo fLaunchConfigurationCombo;
167
168
	public FatJarPackageWizardPage(JarPackageData jarPackage) {
169
		super(PAGE_NAME, StructuredSelection.EMPTY, jarPackage);
170
		setTitle(FatJarPackagerMessages.JarPackageWizardPage_title);
171
		setDescription(FatJarPackagerMessages.FatJarPackageWizardPage_description);
172
		fJarPackage= jarPackage;
173
		fLauchConfigurationModel= new ArrayList();
174
	}
175
176
	/**
177
	 * {@inheritDoc}
178
	 */
179
	public void createControl(Composite parent) {
180
		Composite composite= new Composite(parent, SWT.NONE);
181
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
182
		composite.setLayout(new GridLayout(1, false));
183
		
184
		Label description= new Label(composite, SWT.NONE);
185
		GridData gridData= new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
186
		description.setLayoutData(gridData);
187
		description.setText(FatJarPackagerMessages.FatJarPackageWizardPage_launchConfigGroupTitle);
188
		
189
		createLaunchConfigSelectionGroup(composite);
190
		
191
		Label label= new Label(composite, SWT.NONE);
192
		label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
193
		label.setText(FatJarPackagerMessages.FatJarPackageWizardPage_destinationGroupTitle);
194
		
195
		createDestinationGroup(composite);
196
	
197
		restoreWidgetValues();
198
		
199
		update();
200
201
		Dialog.applyDialogFont(composite);
202
		setControl(composite);
203
	}
204
205
	protected String getDestinationLabel() {
206
		return null;
207
	}
208
	
209
	private void createLaunchConfigSelectionGroup(Composite parent) {
210
		Composite composite= new Composite(parent, SWT.NONE);
211
		composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
212
		composite.setLayout(new GridLayout(1, false));
213
214
		fLaunchConfigurationCombo= new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
215
		fLaunchConfigurationCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
216
217
		fLauchConfigurationModel.addAll(Arrays.asList(getLaunchConfigurations()));
218
		String[] names= new String[fLauchConfigurationModel.size()];
219
		for (int i= 0, size= fLauchConfigurationModel.size(); i < size; i++) {
220
			LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(i);
221
			names[i]= element.getLaunchConfigurationName();
222
		}
223
		fLaunchConfigurationCombo.setItems(names);
224
225
		fLaunchConfigurationCombo.addListener(SWT.Selection, this);
226
		fLaunchConfigurationCombo.addListener(SWT.Modify, this);
227
	}
228
229
	protected void updateWidgetEnablements() {
230
	}
231
232
	public boolean isPageComplete() {
233
		boolean complete= validateDestinationGroup();
234
		complete= validateLaunchConfigurationGroup() && complete;
235
		if (complete)
236
			setErrorMessage(null);
237
		return complete;
238
	}
239
240
	private boolean validateLaunchConfigurationGroup() {
241
		return fLaunchConfigurationCombo.getSelectionIndex() != -1;
242
	}
243
244
	private LaunchConfigurationElement[] getLaunchConfigurations() {
245
		ArrayList result= new ArrayList();
246
247
		HashSet projectNamesWithLaunchConfig= new HashSet();
248
		try {
249
			ILaunchConfiguration[] launchconfigs= DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations();
250
251
			for (int i= 0; i < launchconfigs.length; i++) {
252
				ILaunchConfiguration launchconfig= launchconfigs[i];
253
254
				String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
255
				result.add(new ExistingLaunchConfigurationElement(launchconfig, projectName));
256
				projectNamesWithLaunchConfig.add(projectName);
257
			}
258
		} catch (CoreException e) {
259
			JavaPlugin.log(e);
260
		}
261
262
		IJavaProject[] javaProjects= getJavaProjects();
263
		for (int i= 0; i < javaProjects.length; i++) {
264
			if (!projectNamesWithLaunchConfig.contains(javaProjects[i].getElementName())) {
265
				result.add(new DefaultLaunchConfigurationElement(javaProjects[i]));
266
			}
267
		}
268
269
		return (LaunchConfigurationElement[]) result.toArray(new LaunchConfigurationElement[result.size()]);
270
	}
271
272
	private IJavaProject[] getJavaProjects() {
273
		ArrayList result= new ArrayList();
274
275
		IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
276
		for (int i= 0; i < projects.length; i++) {
277
			IJavaProject javaProject= JavaCore.create(projects[i]);
278
			if (javaProject != null && javaProject.exists()) {
279
				result.add(javaProject);
280
			}
281
		}
282
283
		return (IJavaProject[]) result.toArray(new IJavaProject[result.size()]);
284
	}
285
286
	public Object[] getSelectedElementsWithoutContainedChildren() {
287
		try {
288
			LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(fLaunchConfigurationCombo.getSelectionIndex());
289
			ILaunchConfiguration launchconfig= element.getLaunchConfiguration();
290
			fJarPackage.setLaunchConfigurationName(element.getLaunchConfigurationName());
291
292
			return getSelectedElementsWithoutContainedChildren(launchconfig, fJarPackage, getContainer());
293
		} catch (CoreException e) {
294
			JavaPlugin.log(e);
295
		}
296
297
		return null;
298
	}
299
300
	private static String[] getProjectSearchOrder(String projectName) {
301
302
		ArrayList result= new ArrayList();
303
		result.add(projectName);
304
305
		int nextProject= 0;
306
		while (nextProject < result.size()) {
307
			String nextProjectName= (String) result.get(nextProject);
308
			IJavaProject jproject= getJavaProject(nextProjectName);
309
310
			if (jproject != null) {
311
				try {
312
					String[] childProjectNames= jproject.getRequiredProjectNames();
313
					for (int i= 0; i < childProjectNames.length; i++) {
314
						if (!result.contains(childProjectNames[i])) {
315
							result.add(childProjectNames[i]);
316
						}
317
					}
318
				} catch (JavaModelException e) {
319
					JavaPlugin.log(e);
320
				}
321
			}
322
			nextProject+= 1;
323
		}
324
325
		return (String[]) result.toArray(new String[result.size()]);
326
	}
327
328
	private static IJavaProject getJavaProject(String projectName) {
329
		IJavaProject result= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName));
330
		if (result == null)
331
			return null;
332
333
		if (!result.exists())
334
			return null;
335
336
		return result;
337
	}
338
339
	private static String[] getClasspath(ILaunchConfiguration configuration) throws CoreException {
340
		IRuntimeClasspathEntry[] entries= JavaRuntime.computeUnresolvedRuntimeClasspath(configuration);
341
		entries= JavaRuntime.resolveRuntimeClasspath(entries, configuration);
342
		List userEntries= new ArrayList(entries.length);
343
		for (int i= 0; i < entries.length; i++) {
344
			if (entries[i].getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) {
345
				String location= entries[i].getLocation();
346
				if (location != null) {
347
					userEntries.add(location);
348
				}
349
			}
350
		}
351
		return (String[]) userEntries.toArray(new String[userEntries.size()]);
352
	}
353
354
	private static String getMainClass(ILaunchConfiguration launchConfig) {
355
		String result= null;
356
		if (launchConfig != null) {
357
			try {
358
				result= launchConfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String) null);
359
			} catch (CoreException ignore) {
360
			}
361
		}
362
		if (result == null) {
363
			result= ""; //$NON-NLS-1$
364
		}
365
		return result;
366
	}
367
368
	private static IPackageFragmentRoot[] getRequiredPackageFragmentRoots(final String[] classpathEntries, final String[] projectNames) {
369
		ArrayList result= new ArrayList();
370
371
		for (int i= 0; i < classpathEntries.length; i++) {
372
			String path= classpathEntries[i];
373
			IPackageFragmentRoot[] elements= findRootsForClasspath(path, projectNames);
374
			if (elements.length == 0) {
375
				JavaPlugin.log(new Status(IStatus.WARNING, JavaUI.ID_PLUGIN, Messages.format(FatJarPackagerMessages.FatJarPackageWizardPage_error_missingClassFile, path)));
376
			}
377
			
378
			for (int j= 0; j < elements.length; j++) {
379
				result.add(elements[j]);
380
			}
381
		}
382
		
383
		return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]);
384
	}
385
386
	private static IPackageFragmentRoot[] findRootsForClasspath(String path, String[] projectNames) {
387
388
		path= path.replace('\\', '/');
389
		for (int i= 0; i < projectNames.length; i++) {
390
			IJavaProject javaProject= getJavaProject(projectNames[i]);
391
			if (javaProject != null) {
392
				IPackageFragmentRoot[] elements= findRootsInProject(path, javaProject);
393
				if (elements.length > 0) {
394
					return elements;
395
				}
396
			}
397
		}
398
		return new IPackageFragmentRoot[0];
399
	}
400
401
	private static IPackageFragmentRoot[] findRootsInProject(String path, IJavaProject project) {
402
		ArrayList result= new ArrayList();
403
404
		try {
405
			IPackageFragmentRoot[] roots= project.getPackageFragmentRoots();
406
			for (int i= 0; i < roots.length; i++) {
407
				IPackageFragmentRoot packageFragmentRoot= roots[i];
408
				if (isRootAt(packageFragmentRoot, path))
409
					result.add(packageFragmentRoot);
410
			}
411
		} catch (Exception e) {
412
			JavaPlugin.log(e);
413
		}
414
415
		return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]);
416
	}
417
418
	private static boolean isRootAt(IPackageFragmentRoot pfr, String path) {
419
		try {
420
			IClasspathEntry cpe= pfr.getRawClasspathEntry();
421
			if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
422
				IPath relIPath= pfr.getJavaProject().getOutputLocation();
423
				IPath iPath= pfr.getJavaModel().getWorkspace().getRoot().findMember(relIPath, true).getLocation();
424
				if (iPath != null) {
425
					String strPath= iPath.toString();
426
					if (path.equals(strPath)) {
427
						return true;
428
					}
429
				}
430
			}
431
		} catch (JavaModelException e) {
432
			JavaPlugin.log(e);
433
		}
434
435
		IResource res= pfr.getResource();
436
		if (res != null) {
437
			IPath iPath= res.getLocation();
438
			if (iPath != null) {
439
				String strPath= iPath.toString();
440
				if (path.equals(strPath)) {
441
					return true;
442
				}
443
			}
444
		}
445
446
		IPath iPath= pfr.getPath();
447
		if (iPath != null) {
448
			String strPath= iPath.toString();
449
			if (path.equals(strPath)) {
450
				return true;
451
			}
452
		}
453
454
		return false;
455
	}
456
457
	private static IType findMainMethodByName(String name, IPackageFragmentRoot[] classpathResources, IRunnableContext context) throws CoreException {
458
		
459
		List resources= JarPackagerUtil.asResources(classpathResources);
460
		if (resources == null)
461
			throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, FatJarPackagerMessages.FatJarPackageWizardPage_error_noMainMethod));
462
463
		for (Iterator iterator= resources.iterator(); iterator.hasNext();) {
464
			IResource element= (IResource) iterator.next();
465
			if (element == null)
466
				iterator.remove();
467
		}
468
		
469
		IJavaSearchScope searchScope= JavaSearchScopeFactory.getInstance().createJavaSearchScope((IResource[]) resources.toArray(new IResource[resources.size()]), true);
470
		MainMethodSearchEngine engine= new MainMethodSearchEngine();
471
		try {
472
			IType[] mainTypes= engine.searchMainMethods(context, searchScope, 0);
473
			for (int i= 0; i < mainTypes.length; i++) {
474
				if (mainTypes[i].getFullyQualifiedName().equals(name))
475
					return mainTypes[i];
476
			}
477
		} catch (InvocationTargetException ex) {
478
			JavaPlugin.log(ex);
479
		} catch (InterruptedException e) {
480
			// null
481
		}
482
		
483
		return null;
484
	}
485
	
486
	public void dispose() {
487
		super.dispose();
488
		if (fLauchConfigurationModel != null) {
489
			for (int i= 0, size= fLauchConfigurationModel.size(); i < size; i++) {
490
				LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(i);
491
				element.dispose();
492
			}
493
		}
494
	}
495
	
496
	protected void restoreWidgetValues() {
497
		
498
		IDialogSettings settings= getDialogSettings();
499
		if (settings != null) {
500
			String name= settings.get(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME);
501
			if (name != null) {
502
				String[] items= fLaunchConfigurationCombo.getItems();
503
				for (int i= 0; i < items.length; i++) {
504
					if (name.equals(items[i])) {
505
						fLaunchConfigurationCombo.select(i);
506
					}
507
				}
508
			}
509
			
510
			String destinationPath= settings.get(STORE_DESTINATION_ELEMENT);
511
			if (destinationPath != null && destinationPath.length() > 0) {
512
				fJarPackage.setJarLocation(Path.fromOSString(destinationPath));
513
			}
514
		}
515
		
516
		super.restoreWidgetValues();
517
	}
518
	
519
	/**
520
	 * {@inheritDoc}
521
	 */
522
	protected void saveWidgetValues() {
523
		super.saveWidgetValues();
524
		
525
		IDialogSettings settings= getDialogSettings();
526
		if (settings != null) {
527
			int index= fLaunchConfigurationCombo.getSelectionIndex();
528
			if (index == -1) {
529
				settings.put(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME, ""); //$NON-NLS-1$
530
			} else {
531
				String selectedItem= fLaunchConfigurationCombo.getItem(index);
532
				settings.put(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME, selectedItem);
533
			}
534
			
535
			IPath location= fJarPackage.getJarLocation();
536
			if (location == null) {
537
				settings.put(STORE_DESTINATION_ELEMENT, ""); //$NON-NLS-1$
538
			} else {
539
				settings.put(STORE_DESTINATION_ELEMENT, location.toOSString());
540
			}
541
		}
542
	}
543
	
544
	/*
545
	 * For internal use only (testing), clients must not call.
546
	 */
547
	public static Object[] getSelectedElementsWithoutContainedChildren(ILaunchConfiguration launchconfig, JarPackageData data, IRunnableContext context)  throws CoreException {
548
		if (launchconfig == null)
549
			return new Object[0];
550
551
		String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
552
553
		String[] searchOrder= getProjectSearchOrder(projectName);
554
		String[] classpath= getClasspath(launchconfig);
555
		IPackageFragmentRoot[] classpathResources= getRequiredPackageFragmentRoots(classpath, searchOrder);
556
557
		String mainClass= getMainClass(launchconfig);
558
		data.setManifestMainClass(findMainMethodByName(mainClass, classpathResources, context));
559
560
		return classpathResources;
561
	}
562
	
563
	/*
564
	 *  From org.eclipse.jdt.internal.debug.ui.launcher.JavaApplicationLaunchShortcut
565
	 *  
566
	 *  For internal use only (testing), clients must not call.
567
	 */
568
	public static ILaunchConfiguration createTempLaunchConfig(IJavaProject project) {
569
		String projectName= project.getElementName();
570
571
		String configname= "fatjar_cfg_eraseme_" + projectName; //$NON-NLS-1$
572
		ILaunchConfiguration config= null;
573
		ILaunchConfigurationWorkingCopy wc= null;
574
		try {
575
			ILaunchManager launchManager= DebugPlugin.getDefault().getLaunchManager();
576
			ILaunchConfigurationType configType= launchManager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
577
			wc= configType.newInstance(null, launchManager.generateUniqueLaunchConfigurationNameFrom(configname));
578
		} catch (CoreException e) {
579
			JavaPlugin.log(e);
580
			return null;
581
		}
582
		 
583
		//TODO
584
//		IType[] mainTypes= findMainTypes(project);
585
//		if (mainTypes.length == 1)
586
//			wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, mainTypes[0].getElementName());
587
		
588
		wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
589
		try {
590
			config= wc.doSave();
591
		} catch (CoreException e) {
592
			JavaPlugin.log(e);
593
		}
594
		
595
		return config;
596
	}
597
598
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarBuilder.java (+117 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackager;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.MultiStatus;
18
import org.eclipse.core.runtime.Status;
19
20
import org.eclipse.core.resources.IFile;
21
22
import org.eclipse.swt.widgets.Shell;
23
24
import org.eclipse.jdt.core.IPackageFragmentRoot;
25
26
import org.eclipse.jdt.ui.jarpackager.IManifestProvider;
27
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
28
29
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
30
import org.eclipse.jdt.internal.ui.JavaPlugin;
31
32
/**
33
 * Base class for all jar builders. A jar builder is used by
34
 * the {@link JarFileExportOperation} to build a jar file.
35
 *
36
 * @since 3.4
37
 */
38
public abstract class JarBuilder {
39
40
	private MultiStatus fStatus;
41
42
	/**
43
	 * @return the unique id of this builder
44
	 */
45
	public abstract String getId();
46
47
	/**
48
	 * @return the manifest provider to build the manifest
49
	 */
50
	public abstract IManifestProvider getManifestProvider();
51
52
	/**
53
	 * Called when building of the jar starts
54
	 * 
55
	 * @param jarPackage
56
	 *        the package to build
57
	 * @param shell
58
	 *        shell to show dialogs in, <b>null</b> if no dialog must be shown
59
	 * @param status
60
	 *        a status to use to report status to the user
61
	 * @throws CoreException
62
	 */
63
	public void open(JarPackageData jarPackage, Shell shell, MultiStatus status) throws CoreException {
64
		fStatus= status;
65
	}
66
67
	/**
68
	 * Add the given resource to the archive at the given path
69
	 * 
70
	 * @param resource
71
	 *        the file to be written
72
	 * @param destinationPath
73
	 *        the path for the file inside the archive
74
	 * @throws CoreException 
75
	 */
76
	public abstract void addFile(IFile resource, IPath destinationPath) throws CoreException;
77
78
	/**
79
	 * Add the given package fragment root to the archive. The root is an archive.
80
	 * 
81
	 * @param root
82
	 *        the package fragment root to add
83
	 * @param monitor
84
	 *        a monitor to report progress to
85
	 */
86
	public abstract void addJar(IPackageFragmentRoot root, IProgressMonitor monitor);
87
88
	/**
89
	 * Called when building of the jar finished.
90
	 * 
91
	 * @throws CoreException
92
	 */
93
	public abstract void close() throws CoreException;
94
95
	//some methods for convenience
96
	protected final void addInfo(String message, Throwable error) {
97
		fStatus.add(new Status(IStatus.INFO, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, error));
98
	}
99
100
	protected final void addWarning(String message, Throwable error) {
101
		fStatus.add(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, error));
102
	}
103
104
	protected final void addError(String message, Throwable error) {
105
		fStatus.add(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, error));
106
	}
107
108
	protected final void addToStatus(CoreException ex) {
109
		IStatus status= ex.getStatus();
110
		String message= ex.getLocalizedMessage();
111
		if (message == null || message.length() < 1) {
112
			message= JarPackagerMessages.JarFileExportOperation_coreErrorDuringExport;
113
			status= new Status(status.getSeverity(), status.getPlugin(), status.getCode(), message, ex);
114
		}
115
		fStatus.add(status);
116
	}
117
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.properties (+28 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2007 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
JarPackageWizard_windowTitle= Runnable JAR Export
13
JarPackageWizard_jarExport_title= Runnable JAR Export
14
FatJarBuilder_error_exportingStream=Exporting stream to {0} failed.
15
FatJarBuilder_error_readingArchiveFile=Could not read jar file ''{0}''. Reason: {1}
16
FatJarPackageWizardPage_defaultLaunchConfigName={0} : <default>
17
FatJarPackageWizardPage_description=Select a launch configuration to use to create a runnable JAR.
18
FatJarPackageWizardPage_destinationGroupTitle=Select the export destination:
19
FatJarPackageWizardPage_error_missingClassFile=Fat Jar Export: Could not find classpath entry for '{0}'
20
FatJarPackageWizardPage_error_noMainMethod=Could not find main method from given launch configuration.
21
FatJarPackageWizardPage_launchConfigGroupTitle=Select the launch configuration:
22
JarPackageWizard_jarExportError_title= Runnable JAR Export Error
23
JarPackageWizard_jarExportError_message= Creation of runnable JAR failed
24
25
JarPackageWizardPage_title= Runnable JAR File Specification
26
27
JarWriter_error_couldNotGetXmlBuilder = Could not get XML builder
28
JarWriter_error_couldNotTransformToXML= Could not transform to XML
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/PlainJarBuilder.java (+84 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackager;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.MultiStatus;
17
18
import org.eclipse.core.resources.IFile;
19
20
import org.eclipse.swt.widgets.Shell;
21
22
import org.eclipse.jdt.core.IPackageFragmentRoot;
23
24
import org.eclipse.jdt.ui.jarpackager.IManifestProvider;
25
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
26
import org.eclipse.jdt.ui.jarpackager.JarWriter3;
27
28
/**
29
 * Jar builder for the plain jar exported. Does not export required archives.
30
 * 
31
 * @since 3.4
32
 */
33
public class PlainJarBuilder extends JarBuilder {
34
	
35
	public static final String BUILDER_ID= "org.eclipse.jdt.ui.plain_jar_builder"; //$NON-NLS-1$
36
	
37
	private JarPackageData fJarPackage;
38
	private JarWriter3 fJarWriter;
39
	
40
	/**
41
	 * {@inheritDoc}
42
	 */
43
	public String getId() {
44
		return BUILDER_ID;
45
	}
46
	
47
	/**
48
	 * {@inheritDoc}
49
	 */
50
	public IManifestProvider getManifestProvider() {
51
		return new ManifestProvider();
52
	}
53
54
	/**
55
	 * {@inheritDoc}
56
	 */
57
	public void open(JarPackageData jarPackage, Shell displayShell, MultiStatus statusMsg) throws CoreException {
58
		super.open(jarPackage, displayShell, statusMsg);
59
		fJarPackage = jarPackage;
60
		fJarWriter = new JarWriter3(fJarPackage, displayShell);
61
	}
62
63
	/**
64
	 * {@inheritDoc}
65
	 */
66
	public void addFile(IFile resource, IPath destinationPath) throws CoreException {
67
		fJarWriter.write(resource, destinationPath);
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 */
73
	public void addJar(IPackageFragmentRoot archiveRoot, IProgressMonitor progressMonitor) {
74
		//do nothing, plain jar builder can not handle archives, use fat jar builder
75
	}
76
	
77
	/**
78
	 * {@inheritDoc}
79
	 */
80
	public void close() throws CoreException {
81
		fJarWriter.close();
82
	}
83
84
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackagerfat;
12
13
import org.eclipse.osgi.util.NLS;
14
15
public final class FatJarPackagerMessages extends NLS {
16
17
	private static final String BUNDLE_NAME= "org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarPackagerMessages";//$NON-NLS-1$
18
19
	public static String JarPackageWizard_jarExport_title;
20
	public static String JarPackageWizard_jarExportError_message;
21
	public static String FatJarBuilder_error_exportingStream;
22
23
	public static String FatJarBuilder_error_readingArchiveFile;
24
25
	public static String FatJarPackageWizardPage_defaultLaunchConfigName;
26
27
	public static String FatJarPackageWizardPage_destinationGroupTitle;
28
29
	public static String FatJarPackageWizardPage_error_missingClassFile;
30
31
	public static String FatJarPackageWizardPage_error_noMainMethod;
32
33
	public static String FatJarPackageWizardPage_launchConfigGroupTitle;
34
35
	public static String FatJarPackageWizardPage_description;
36
37
	public static String JarPackageWizard_jarExportError_title;
38
	public static String JarPackageWizard_windowTitle;
39
40
	public static String JarPackageWizardPage_title;
41
42
	public static String JarWriter_error_couldNotGetXmlBuilder;
43
	public static String JarWriter_error_couldNotTransformToXML;
44
45
	static {
46
		NLS.initializeMessages(BUNDLE_NAME, FatJarPackagerMessages.class);
47
	}
48
49
	private FatJarPackagerMessages() {
50
		// Do not instantiate
51
	}
52
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarManifestProvider.java (+202 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackagerfat;
12
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.util.ArrayList;
16
import java.util.Enumeration;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
import java.util.jar.Attributes;
21
import java.util.jar.Manifest;
22
import java.util.zip.ZipEntry;
23
import java.util.zip.ZipFile;
24
25
import org.eclipse.core.runtime.CoreException;
26
27
import org.eclipse.jdt.core.IPackageFragment;
28
import org.eclipse.jdt.core.IPackageFragmentRoot;
29
30
import org.eclipse.jdt.ui.jarpackager.IManifestProvider;
31
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
32
33
import org.eclipse.jdt.internal.ui.JavaPlugin;
34
import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil;
35
36
/**
37
 * A manifest provider creates manifest files for a fat jar.
38
 * 
39
 * @since 3.4
40
 */
41
public class FatJarManifestProvider implements IManifestProvider {
42
43
	private static final String SEALED_VALUE= "true"; //$NON-NLS-1$
44
	private static final String UNSEALED_VALUE= "false"; //$NON-NLS-1$
45
	
46
	private FatJarBuilder fBuilder;
47
	
48
	public FatJarManifestProvider(FatJarBuilder builder) {
49
		fBuilder = builder;
50
	}
51
52
	/**
53
	 * {@inheritDoc}
54
	 */
55
	public Manifest create(JarPackageData jarPackage) throws CoreException {
56
		Manifest result;
57
		Manifest ownManifest = createOwn(jarPackage);
58
		setManifestClasspath(ownManifest, fBuilder.getManifestClasspath());
59
		if (fBuilder.isMergeManifests()) {
60
			List otherManifests = new ArrayList(); 
61
			Object[] elements = jarPackage.getElements();
62
			for (int i = 0; i < elements.length; i++) {
63
				Object element = elements[i];
64
				if (element instanceof IPackageFragmentRoot && ((IPackageFragmentRoot)element).isArchive()) {
65
					ZipFile zip = JarPackagerUtil.getArchiveFile(((IPackageFragmentRoot) element).getPath());
66
					Enumeration entries = zip.entries();
67
					while (entries.hasMoreElements()) {
68
						ZipEntry entry = (ZipEntry)entries.nextElement();
69
						if (entry.getName().equalsIgnoreCase("META-INF/MANIFEST.MF")) { //$NON-NLS-1$
70
							try {
71
								Manifest otherManifest = new Manifest(zip.getInputStream(entry));
72
								otherManifests.add(otherManifest);
73
							} catch (IOException e) {
74
								JavaPlugin.log(e);
75
							}
76
						}
77
					}
78
				}
79
			}
80
			result = merge(ownManifest, otherManifests);
81
		}
82
		else {
83
			result = ownManifest;
84
		}
85
		return result;
86
	}
87
88
	private void setManifestClasspath(Manifest ownManifest, String manifestClasspath) {
89
		if ((manifestClasspath != null) && !manifestClasspath.trim().equals("")) { //$NON-NLS-1$
90
			Attributes mainAttr = ownManifest.getMainAttributes();
91
			mainAttr.putValue("Class-Path", manifestClasspath); //$NON-NLS-1$
92
		}
93
	}
94
95
	private Manifest merge(Manifest ownManifest, List otherManifests) {
96
		Manifest mergedManifest = new Manifest(ownManifest);
97
		Map mergedEntries = mergedManifest.getEntries();
98
		for (Iterator iter = otherManifests.iterator(); iter.hasNext();) {
99
			Manifest otherManifest = (Manifest)iter.next();
100
			Map otherEntries = otherManifest.getEntries();
101
			for (Iterator iterator = otherEntries.keySet().iterator(); iterator.hasNext();) {
102
				String attributeName = (String)iterator.next();
103
				if (mergedEntries.containsKey(attributeName)) {
104
					// TODO: WARNING
105
				}
106
				else {
107
					mergedEntries.put(attributeName, otherEntries.get(attributeName));
108
				}
109
			}
110
		}
111
		return mergedManifest;
112
	}
113
114
	private Manifest createOwn(JarPackageData jarPackage) throws CoreException {
115
		if (jarPackage.isManifestGenerated())
116
			return createGeneratedManifest(jarPackage);
117
118
		try {
119
			return createSuppliedManifest(jarPackage);
120
		} catch (IOException ex) {
121
			throw JarPackagerUtil.createCoreException(ex.getLocalizedMessage(), ex);
122
		}
123
	}	
124
	
125
	/**
126
	 * {@inheritDoc}
127
	 */
128
	public Manifest createDefault(String manifestVersion) {
129
		Manifest manifest= new Manifest();
130
		manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, manifestVersion);
131
		return manifest;
132
	}
133
134
	/**
135
	 * Hook for subclasses to add additional manifest entries.
136
	 * 
137
	 * @param	manifest	the manifest to which the entries should be added
138
	 * @param	jarPackage	the JAR package specification
139
	 */
140
	protected void putAdditionalEntries(Manifest manifest, JarPackageData jarPackage) {
141
	}
142
143
	private Manifest createGeneratedManifest(JarPackageData jarPackage) {
144
		Manifest manifest= new Manifest();
145
		putVersion(manifest, jarPackage);
146
		putSealing(manifest, jarPackage);
147
		putMainClass(manifest, jarPackage);
148
		putAdditionalEntries(manifest, jarPackage);
149
		return manifest;
150
	}
151
152
	private void putVersion(Manifest manifest, JarPackageData jarPackage) {
153
		manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, jarPackage.getManifestVersion());
154
	}
155
		
156
	private void putSealing(Manifest manifest, JarPackageData jarPackage) {
157
		if (jarPackage.isJarSealed()) {
158
			manifest.getMainAttributes().put(Attributes.Name.SEALED, SEALED_VALUE);
159
			IPackageFragment[] packages= jarPackage.getPackagesToUnseal();
160
			if (packages != null) {
161
				for (int i= 0; i < packages.length; i++) {
162
					Attributes attributes= new Attributes();
163
					attributes.put(Attributes.Name.SEALED, UNSEALED_VALUE);
164
					manifest.getEntries().put(getInManifestFormat(packages[i]), attributes);
165
				}
166
			}
167
		}
168
		else {
169
			IPackageFragment[] packages= jarPackage.getPackagesToSeal();
170
			if (packages != null)
171
				for (int i= 0; i < packages.length; i++) {
172
					Attributes attributes= new Attributes();
173
					attributes.put(Attributes.Name.SEALED, SEALED_VALUE);
174
					manifest.getEntries().put(getInManifestFormat(packages[i]), attributes);
175
				}
176
		}
177
	}
178
	
179
	private void putMainClass(Manifest manifest, JarPackageData jarPackage) {
180
		if (jarPackage.getManifestMainClass() != null && jarPackage.getManifestMainClass().getFullyQualifiedName().length() > 0)
181
			manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, jarPackage.getManifestMainClass().getFullyQualifiedName());
182
	}
183
	
184
	private String getInManifestFormat(IPackageFragment packageFragment) {
185
		String name= packageFragment.getElementName();
186
		return name.replace('.', '/') + '/';
187
	}
188
189
	private Manifest createSuppliedManifest(JarPackageData jarPackage) throws CoreException, IOException {
190
		Manifest manifest;
191
		// No need to use buffer here because Manifest(...) does
192
		InputStream stream= jarPackage.getManifestFile().getContents(false);
193
		try {
194
			manifest= new Manifest(stream);
195
		} finally {
196
			if (stream != null)
197
				stream.close();
198
		}
199
		return manifest;
200
	}
201
202
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/AbstractJarDestinationWizardPage.java (+320 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackager;
12
13
import java.io.File;
14
15
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.Path;
17
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.ResourcesPlugin;
21
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.events.SelectionAdapter;
24
import org.eclipse.swt.events.SelectionEvent;
25
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.widgets.Button;
28
import org.eclipse.swt.widgets.Combo;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Event;
31
import org.eclipse.swt.widgets.FileDialog;
32
import org.eclipse.swt.widgets.Label;
33
34
import org.eclipse.jface.dialogs.IDialogSettings;
35
import org.eclipse.jface.dialogs.IMessageProvider;
36
import org.eclipse.jface.viewers.IStructuredSelection;
37
38
import org.eclipse.ui.dialogs.WizardExportResourcesPage;
39
40
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
41
42
import org.eclipse.jdt.internal.ui.util.SWTUtil;
43
44
/**
45
 * A wizard page containing a destination block for a jar file. Including
46
 * all required validation code. Clients should overwrite <code>createControl</code>.
47
 * 
48
 * @since 3.4
49
 */
50
public abstract class AbstractJarDestinationWizardPage extends WizardExportResourcesPage implements IJarPackageWizardPage {
51
	
52
	private final String fStoreDestinationNamesId;
53
	
54
	private Combo	fDestinationNamesCombo;
55
	private Button	fDestinationBrowseButton;
56
	private final JarPackageData fJarPackage;
57
58
	public AbstractJarDestinationWizardPage(String pageName, IStructuredSelection selection, JarPackageData jarPackage) {
59
		super(pageName, selection);
60
		fStoreDestinationNamesId= pageName + ".DESTINATION_NAMES_ID"; //$NON-NLS-1$
61
		fJarPackage= jarPackage;
62
	}
63
	
64
	/*
65
	 * Overrides method from WizardExportPage
66
	 */
67
	protected void createDestinationGroup(Composite parent) {
68
		
69
		initializeDialogUnits(parent);
70
		
71
		// destination specification group
72
		Composite destinationSelectionGroup= new Composite(parent, SWT.NONE);
73
		GridLayout layout= new GridLayout();
74
		layout.numColumns= 3;
75
		destinationSelectionGroup.setLayout(layout);
76
		destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
77
78
		String label= getDestinationLabel();
79
		if (label != null) {
80
			new Label(destinationSelectionGroup, SWT.NONE).setText(label);
81
		}
82
83
		// destination name entry field
84
		fDestinationNamesCombo= new Combo(destinationSelectionGroup, SWT.SINGLE | SWT.BORDER);
85
		fDestinationNamesCombo.addListener(SWT.Modify, this);
86
		fDestinationNamesCombo.addListener(SWT.Selection, this);
87
		GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
88
		data.widthHint= SIZING_TEXT_FIELD_WIDTH;
89
		data.horizontalSpan= label == null ? 2 : 1;
90
		fDestinationNamesCombo.setLayoutData(data);
91
92
		// destination browse button
93
		fDestinationBrowseButton= new Button(destinationSelectionGroup, SWT.PUSH);
94
		fDestinationBrowseButton.setText(JarPackagerMessages.JarPackageWizardPage_browseButton_text); 
95
		fDestinationBrowseButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
96
		SWTUtil.setButtonDimensionHint(fDestinationBrowseButton);
97
		fDestinationBrowseButton.addSelectionListener(new SelectionAdapter() {
98
			public void widgetSelected(SelectionEvent e) {
99
				handleDestinationBrowseButtonPressed();
100
			}
101
		});
102
	}
103
	
104
	/**
105
	 *	Open an appropriate destination browser so that the user can specify a source
106
	 *	to import from
107
	 */
108
	protected void handleDestinationBrowseButtonPressed() {
109
		FileDialog dialog= new FileDialog(getContainer().getShell(), SWT.SAVE);
110
		dialog.setFilterExtensions(new String[] {"*.jar", "*.zip"}); //$NON-NLS-1$ //$NON-NLS-2$
111
112
		String currentSourceString= getDestinationValue();
113
		int lastSeparatorIndex= currentSourceString.lastIndexOf(File.separator);
114
		if (lastSeparatorIndex != -1) {
115
			dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex));
116
			dialog.setFileName(currentSourceString.substring(lastSeparatorIndex + 1, currentSourceString.length()));
117
		}
118
		else
119
			dialog.setFileName(currentSourceString);
120
		String selectedFileName= dialog.open();
121
		if (selectedFileName != null)
122
			fDestinationNamesCombo.setText(selectedFileName);
123
	}
124
	
125
126
	/**
127
	 * Answer the contents of the destination specification widget. If this
128
	 * value does not have the required suffix then add it first.
129
	 * 
130
	 * @return java.lang.String
131
	 */
132
	protected String getDestinationValue() {
133
		String destinationText= fDestinationNamesCombo.getText().trim();
134
		if (destinationText.indexOf('.') < 0)
135
			destinationText += getOutputSuffix();
136
		return destinationText;
137
	}
138
139
	/**
140
	 *	Answer the string to display in self as the destination type
141
	 *
142
	 *	@return java.lang.String
143
	 */
144
	protected String getDestinationLabel() {
145
		return JarPackagerMessages.JarPackageWizardPage_destination_label; 
146
	}
147
148
	/**
149
	 *	Answer the suffix that files exported from this wizard must have.
150
	 *	If this suffix is a file extension (which is typically the case)
151
	 *	then it must include the leading period character.
152
	 *
153
	 *	@return java.lang.String
154
	 */
155
	protected String getOutputSuffix() {
156
		return "." + JarPackagerUtil.JAR_EXTENSION; //$NON-NLS-1$
157
	}
158
	
159
	protected void restoreWidgetValues() {
160
		// destination
161
		if (fJarPackage.getJarLocation().isEmpty())
162
			fDestinationNamesCombo.setText(""); //$NON-NLS-1$
163
		else
164
			fDestinationNamesCombo.setText(fJarPackage.getJarLocation().toOSString());
165
		IDialogSettings settings= getDialogSettings();
166
		if (settings != null) {
167
			String[] directoryNames= settings.getArray(fStoreDestinationNamesId);
168
			if (directoryNames == null)
169
				return; // ie.- no settings stored
170
			if (! fDestinationNamesCombo.getText().equals(directoryNames[0]))
171
				fDestinationNamesCombo.add(fDestinationNamesCombo.getText());
172
			for (int i= 0; i < directoryNames.length; i++)
173
				fDestinationNamesCombo.add(directoryNames[i]);
174
		}
175
	}
176
177
	protected void updateModel() {
178
		// destination
179
		String comboText= fDestinationNamesCombo.getText();
180
		IPath path= Path.fromOSString(comboText);
181
182
		if (path.segmentCount() > 0 && ensureTargetFileIsValid(path.toFile()) && path.getFileExtension() == null) 
183
			// append .jar
184
			path= path.addFileExtension(JarPackagerUtil.JAR_EXTENSION);
185
186
		fJarPackage.setJarLocation(path);
187
	}
188
	
189
	/**
190
	 * Returns a boolean indicating whether the passed File handle is
191
	 * is valid and available for use.
192
	 *
193
	 * @param targetFile the target
194
	 * @return boolean
195
	 */
196
	protected boolean ensureTargetFileIsValid(File targetFile) {
197
		if (targetFile.exists() && targetFile.isDirectory() && fDestinationNamesCombo.getText().length() > 0) {
198
			setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_exportDestinationMustNotBeDirectory); 
199
			fDestinationNamesCombo.setFocus();
200
			return false;
201
		}
202
		if (targetFile.exists()) {
203
			if (!targetFile.canWrite()) {
204
				setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_jarFileExistsAndNotWritable); 
205
				fDestinationNamesCombo.setFocus();
206
				return false;
207
			}
208
		}
209
		return true;
210
	}
211
	
212
	/*
213
	 * Overrides method from WizardDataTransferPage
214
	 */
215
	protected boolean validateDestinationGroup() {
216
		if (fDestinationNamesCombo.getText().length() == 0) {
217
			// Clear error 
218
			if (getErrorMessage() != null)
219
				setErrorMessage(null);
220
			if (getMessage() != null)
221
				setMessage(null);
222
			return false;
223
		}
224
		if (fJarPackage.getAbsoluteJarLocation().toString().endsWith("/")) { //$NON-NLS-1$
225
			setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_exportDestinationMustNotBeDirectory); 
226
			fDestinationNamesCombo.setFocus();
227
			return false;
228
		}
229
		// Check if the Jar is put into the workspace and conflicts with the containers
230
		// exported. If the workspace isn't on the local files system we are fine since
231
		// the Jar is always created in the local file system
232
		IPath workspaceLocation= ResourcesPlugin.getWorkspace().getRoot().getLocation();
233
		if (workspaceLocation != null && workspaceLocation.isPrefixOf(fJarPackage.getAbsoluteJarLocation())) {
234
			int segments= workspaceLocation.matchingFirstSegments(fJarPackage.getAbsoluteJarLocation());
235
			IPath path= fJarPackage.getAbsoluteJarLocation().removeFirstSegments(segments);
236
			IResource resource= ResourcesPlugin.getWorkspace().getRoot().findMember(path);
237
			if (resource != null && resource.getType() == IResource.FILE) {
238
				// test if included
239
				if (JarPackagerUtil.contains(JarPackagerUtil.asResources(fJarPackage.getElements()), (IFile)resource)) {
240
					setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_cantExportJARIntoItself); 
241
					return false;
242
				}
243
			}
244
		}
245
		// Inform user about relative directory
246
		String currentMessage= getMessage();
247
		if (!(new File(fDestinationNamesCombo.getText()).isAbsolute())) {
248
			if (currentMessage == null)
249
				setMessage(JarPackagerMessages.JarPackageWizardPage_info_relativeExportDestination, IMessageProvider.INFORMATION); 
250
		} else {
251
			if (currentMessage != null)
252
				setMessage(null);
253
		}
254
		return ensureTargetFileIsValid(fJarPackage.getAbsoluteJarLocation().toFile());
255
	}
256
	
257
	/**
258
	 * Set the current input focus to self's destination entry field
259
 	 */
260
	protected void giveFocusToDestination() {
261
		fDestinationNamesCombo.setFocus();
262
	}
263
	
264
	/**
265
	 * {@inheritDoc}
266
	 */
267
	protected void saveWidgetValues() {
268
		IDialogSettings settings= getDialogSettings();
269
		if (settings != null) {
270
			String[] directoryNames= settings.getArray(fStoreDestinationNamesId);
271
			if (directoryNames == null)
272
				directoryNames= new String[0];
273
			directoryNames= addToHistory(directoryNames, getDestinationValue());
274
			settings.put(fStoreDestinationNamesId, directoryNames);
275
		}
276
	}
277
278
	/**
279
	 *	Initializes the JAR package from last used wizard page values.
280
	 */
281
	protected void initializeJarPackage() {
282
		IDialogSettings settings= getDialogSettings();
283
		if (settings != null) {
284
			// destination
285
			String[] directoryNames= settings.getArray(fStoreDestinationNamesId);
286
			if (directoryNames == null)
287
				return; // ie.- no settings stored
288
			fJarPackage.setJarLocation(Path.fromOSString(directoryNames[0]));
289
		}
290
	}
291
	
292
	/* 
293
	 * Implements method from IJarPackageWizardPage.
294
	 */
295
	public void finish() {
296
		saveWidgetValues();
297
	}
298
	
299
	/*
300
	 * Implements method from Listener
301
	 */	
302
	public void handleEvent(Event e) {
303
		if (getControl() == null)
304
			return;
305
		update();
306
	}
307
	
308
	protected void update() {
309
		updateModel();
310
		updateWidgetEnablements();
311
		updatePageCompletion();
312
	}
313
	
314
	protected void updatePageCompletion() {
315
		boolean pageComplete= isPageComplete();
316
		setPageComplete(pageComplete);
317
		if (pageComplete)
318
			setErrorMessage(null);
319
	}
320
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarBuilder.java (+206 lines)
Added Link Here
1
package org.eclipse.jdt.internal.ui.jarpackagerfat;
2
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.util.Enumeration;
6
import java.util.zip.ZipEntry;
7
import java.util.zip.ZipException;
8
import java.util.zip.ZipFile;
9
10
import org.eclipse.core.runtime.CoreException;
11
import org.eclipse.core.runtime.IPath;
12
import org.eclipse.core.runtime.IProgressMonitor;
13
import org.eclipse.core.runtime.MultiStatus;
14
import org.eclipse.core.runtime.OperationCanceledException;
15
16
import org.eclipse.core.resources.IFile;
17
18
import org.eclipse.swt.widgets.Shell;
19
20
import org.eclipse.jdt.core.IPackageFragmentRoot;
21
22
import org.eclipse.jdt.internal.corext.util.Messages;
23
24
import org.eclipse.jdt.ui.jarpackager.IManifestProvider;
25
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
26
import org.eclipse.jdt.ui.jarpackager.JarWriter3;
27
28
import org.eclipse.jdt.internal.ui.jarpackager.JarBuilder;
29
import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil;
30
31
public class FatJarBuilder extends JarBuilder {
32
33
	public static final String BUILDER_ID= "org.eclipse.jdt.ui.fat_jar_builder"; //$NON-NLS-1$
34
35
//	private static final String PROPS_MERGEMANIFESTS= "mergemanifests"; //$NON-NLS-1$
36
//	private static final String PROPS_REMOVESIGNERS= "removesigners"; //$NON-NLS-1$
37
//	private static final String PROPS_MANIFESTCLASSPATH= "manifestclasspath"; //$NON-NLS-1$
38
39
	private boolean fMergeManifests;
40
	private boolean fRemoveSigners;
41
	private String fManifestClasspath;
42
43
	private JarPackageData fJarPackage;
44
	private JarWriter3 fJarWriter;
45
	
46
	/**
47
	 * {@inheritDoc}
48
	 */
49
	public String getId() {
50
		return BUILDER_ID;
51
	}
52
	
53
	/**
54
	 * {@inheritDoc}
55
	 */
56
	public IManifestProvider getManifestProvider() {
57
		return new FatJarManifestProvider(this);
58
	}
59
	
60
	public String getManifestClasspath() {
61
		return fManifestClasspath;
62
	}
63
64
	public boolean isMergeManifests() {
65
		return fMergeManifests;
66
	}
67
68
	public boolean isRemoveSigners() {
69
		return fRemoveSigners;
70
	}
71
72
	/**
73
	 * {@inheritDoc}
74
	 */
75
	public void open(JarPackageData jarPackage, Shell displayShell, MultiStatus status) throws CoreException {
76
		super.open(jarPackage, displayShell, status);
77
//		ExecutableJarBuilderProperty[] jarBuilderProperties= getExecutableJarBuilderProperties();
78
79
		fMergeManifests= true;//getBooleanValue(jarBuilderProperties, PROPS_MERGEMANIFESTS, true);
80
		fRemoveSigners= true;//getBooleanValue(jarBuilderProperties, PROPS_REMOVESIGNERS, true);
81
		fManifestClasspath= "";//getValue(jarBuilderProperties, PROPS_MANIFESTCLASSPATH, ""); //$NON-NLS-1$
82
83
		fJarPackage= jarPackage;
84
		fJarWriter= new JarWriter3(fJarPackage, displayShell);
85
	}
86
	
87
	/**
88
	 * {@inheritDoc}
89
	 */
90
	public void addFile(IFile resource, IPath destinationPath) throws CoreException {
91
		fJarWriter.write(resource, destinationPath);
92
	}
93
94
	/**
95
	 * {@inheritDoc}
96
	 */
97
	public void addJar(IPackageFragmentRoot archiveRoot, IProgressMonitor progressMonitor) {
98
		try {
99
			ZipFile jarFile= JarPackagerUtil.getArchiveFile(archiveRoot.getPath());
100
			String readableJarName= archiveRoot.getElementName();
101
			addJar(readableJarName, jarFile, progressMonitor);
102
			jarFile.close();
103
		} catch (IOException ex) {
104
			addJarWarning(archiveRoot.getElementName(), ex);
105
		} catch (CoreException ex) {
106
			addJarWarning(archiveRoot.getElementName(), ex);
107
		}
108
	}
109
	
110
	private void addJar(String readableJarName, ZipFile jarFile, IProgressMonitor progressMonitor) {
111
		Enumeration jarEntriesEnum= jarFile.entries();
112
		while (jarEntriesEnum.hasMoreElements()) {
113
			ZipEntry jarEntry= (ZipEntry) jarEntriesEnum.nextElement();
114
			if (!jarEntry.isDirectory()) {
115
				String entryName= jarEntry.getName();
116
				InputStream stream= null;
117
				try {
118
					stream= jarFile.getInputStream(jarEntry);
119
					addFile(entryName, stream);
120
					stream.close();
121
				} catch (IOException e) {
122
					addJarWarning(readableJarName, e);
123
				}
124
			}
125
			progressMonitor.worked(1);
126
			if (progressMonitor.isCanceled())
127
				throw new OperationCanceledException();
128
		}
129
	}
130
131
	private void addFile(String destinationPath, InputStream fileStream) {
132
		// Handle META-INF/MANIFEST.MF 
133
		if (destinationPath.equalsIgnoreCase("META-INF/MANIFEST.MF") //$NON-NLS-1$
134
				|| (isRemoveSigners() && destinationPath.startsWith("META-INF/") && destinationPath.endsWith(".SF"))) {  //$NON-NLS-1$//$NON-NLS-2$
135
			return;
136
		}
137
		try {
138
			fJarWriter.addStream(fileStream, destinationPath);
139
		} catch (CoreException ex) {
140
			Throwable realEx= ex.getStatus().getException();
141
			if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$
142
				addWarning(ex.getMessage(), realEx);
143
			else
144
				addToStatus(ex);
145
		} catch (IOException ex) {
146
			if (ex instanceof ZipException && ex.getMessage() != null && ex.getMessage().startsWith("duplicate entry:")) {//$NON-NLS-1$
147
				// ignore duplicates in META-INF (*.SF, *.RSA)
148
				if (!destinationPath.startsWith("META-INF/")) { //$NON-NLS-1$
149
					addWarning(ex.getMessage(), ex);
150
				}
151
			} else
152
				addError(Messages.format(FatJarPackagerMessages.FatJarBuilder_error_exportingStream, destinationPath), ex);
153
		}
154
	}
155
	
156
	/**
157
	 * {@inheritDoc}
158
	 */
159
	public void close() throws CoreException {
160
		if (fJarWriter != null) {
161
			fJarWriter.close();
162
		}
163
	}
164
	
165
	private void addJarWarning(String archiveRootName, Throwable ex) {
166
		addWarning(Messages.format(FatJarPackagerMessages.FatJarBuilder_error_readingArchiveFile, new Object[] {archiveRootName, ex.getLocalizedMessage()}), ex);
167
	}
168
169
//	private static String getValue(ExecutableJarBuilderProperty[] jarBuilderProperties, String name, String defaultValue) {
170
//		String result= defaultValue;
171
//		if ((name != null) && (jarBuilderProperties != null)) {
172
//			for (int i= 0; i < jarBuilderProperties.length; i++) {
173
//				if (name.equals(jarBuilderProperties[i].getName())) {
174
//					result= jarBuilderProperties[i].getValue();
175
//					break;
176
//				}
177
//			}
178
//		}
179
//		return result;
180
//	}
181
//
182
//	private static boolean getBooleanValue(ExecutableJarBuilderProperty[] jarBuilderProperties, String name, boolean defaultValue) {
183
//		boolean result= defaultValue;
184
//		if (name != null) {
185
//			for (int i= 0; i < jarBuilderProperties.length; i++) {
186
//				if (name.equals(jarBuilderProperties[i].getName())) {
187
//					result= jarBuilderProperties[i].getBooleanValue();
188
//					break;
189
//				}
190
//			}
191
//		}
192
//		return result;
193
//	}
194
//
195
//	private static ExecutableJarBuilderProperty[] getExecutableJarBuilderProperties() {
196
//		ExecutableJarBuilderProperty[] jbProperties= {
197
//				new ExecutableJarBuilderProperty(ExecutableJarBuilderProperty.PROPERTYTYPE_BOOLEAN, "mergemanifests", "true", //$NON-NLS-2$
198
//						"Merge attributes from all included libs together. Use this if the output jar produces an 'SecurityException: no manifiest section for signature file entry ...'"),
199
//				new ExecutableJarBuilderProperty(ExecutableJarBuilderProperty.PROPERTYTYPE_BOOLEAN, "removesigners", "true", //$NON-NLS-2$
200
//						"Remove signer files (*.SF) in META-INF. Use this if the output jar produces an 'SecurityException: invalid SHA1 signature file digest for ...'"),
201
//				new ExecutableJarBuilderProperty(ExecutableJarBuilderProperty.PROPERTYTYPE_STRING, "manifestclasspath", "", //$NON-NLS-2$
202
//						"Define the Class-Path attribute separated by spaces. Folders must end with an '/'. Example: '. xclasses/ lib/test.jar'"), };
203
//		return jbProperties;
204
//	}
205
206
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/JarBuilderProperty.java (+79 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackagerfat;
12
13
/**
14
 * TODO: Remove, not used?
15
 * @since 3.4
16
 */
17
public class JarBuilderProperty {
18
19
	public final static int PROPERTYTYPE_STRING= 1;
20
	public final static int PROPERTYTYPE_BOOLEAN= 2;
21
22
	private int propertyType;
23
	private String name;
24
	private String value;
25
	private String tip;
26
27
	public JarBuilderProperty(int propertyType, String name, String value, String tip) {
28
		this.propertyType= propertyType;
29
		this.name= name;
30
		this.value= value;
31
		this.tip= tip;
32
	}
33
34
	public int getType() {
35
		return propertyType;
36
	}
37
38
	public boolean isBooleanType() {
39
		return getType() == PROPERTYTYPE_BOOLEAN;
40
	}
41
42
	public boolean isStringType() {
43
		return getType() == PROPERTYTYPE_STRING;
44
	}
45
46
	public String getName() {
47
		return name;
48
	}
49
50
	public String getTip() {
51
		return tip;
52
	}
53
54
	public String getValue() {
55
		return value;
56
	}
57
58
	public void setValue(String value) {
59
		this.value= value;
60
	}
61
62
	public boolean getBooleanValue() {
63
		return (value != null) && Boolean.getBoolean(value);
64
	}
65
66
	public void setBooleanValue(boolean value) {
67
		this.value= Boolean.toString(value);
68
	}
69
70
	public void exportToString(StringBuffer out) {
71
		out.append("<prop name=\"").append(getName()).append("\" value=\"").append(getValue()).append("\" />"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
72
	}
73
74
	public String toString() {
75
		StringBuffer result= new StringBuffer();
76
		result.append("P[").append(Integer.toString(propertyType)).append("|").append(getName()).append("='").append(getValue()).append("']"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
77
		return result.toString();
78
	}
79
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizard.java (+249 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackagerfat;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.List;
17
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IStatus;
21
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.IResource;
24
25
import org.eclipse.jface.dialogs.ErrorDialog;
26
import org.eclipse.jface.dialogs.IDialogSettings;
27
import org.eclipse.jface.viewers.ISelection;
28
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.jface.viewers.StructuredSelection;
30
import org.eclipse.jface.wizard.IWizardPage;
31
import org.eclipse.jface.wizard.Wizard;
32
33
import org.eclipse.ui.IExportWizard;
34
import org.eclipse.ui.IWorkbench;
35
36
import org.eclipse.jdt.core.IClassFile;
37
import org.eclipse.jdt.core.ICompilationUnit;
38
import org.eclipse.jdt.core.IJavaElement;
39
import org.eclipse.jdt.core.IOpenable;
40
import org.eclipse.jdt.core.IPackageFragmentRoot;
41
import org.eclipse.jdt.core.JavaCore;
42
43
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
44
45
import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable;
46
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
47
48
import org.eclipse.jdt.internal.ui.JavaPlugin;
49
import org.eclipse.jdt.internal.ui.JavaPluginImages;
50
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
51
52
/**
53
 * Wizard for exporting resources from the workspace to a Fat Java Archive (JAR) file.
54
 * The exported jar will contain all required libraries.
55
 * 
56
 * @since 3.4
57
 */
58
public class FatJarPackageWizard extends Wizard implements IExportWizard {
59
60
	private static String DIALOG_SETTINGS_KEY= "JarPackageWizard"; //$NON-NLS-1$
61
62
	private boolean fHasNewDialogSettings;
63
	private boolean fInitializeFromJarPackage;
64
	private JarPackageData fJarPackage;
65
	private FatJarPackageWizardPage fJarPackageWizardPage;
66
67
	/**
68
	 * Creates a wizard for exporting workspace resources to a JAR file.
69
	 */
70
	public FatJarPackageWizard() {
71
		IDialogSettings workbenchSettings= JavaPlugin.getDefault().getDialogSettings();
72
		IDialogSettings section= workbenchSettings.getSection(DIALOG_SETTINGS_KEY);
73
		if (section == null)
74
			fHasNewDialogSettings= true;
75
		else {
76
			fHasNewDialogSettings= false;
77
			setDialogSettings(section);
78
		}
79
	}
80
81
	private void addJavaElement(List selectedElements, IJavaElement je) {
82
		if (je.getElementType() == IJavaElement.COMPILATION_UNIT)
83
			selectedElements.add(je);
84
		else if (je.getElementType() == IJavaElement.CLASS_FILE)
85
			selectedElements.add(je);
86
		else if (je.getElementType() == IJavaElement.JAVA_PROJECT)
87
			selectedElements.add(je);
88
		else if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
89
			if (!JavaModelUtil.getPackageFragmentRoot(je).isArchive())
90
				selectedElements.add(je);
91
		} else if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) {
92
			if (!((IPackageFragmentRoot) je).isArchive())
93
				selectedElements.add(je);
94
		} else {
95
			IOpenable openable= je.getOpenable();
96
			if (openable instanceof ICompilationUnit)
97
				selectedElements.add(((ICompilationUnit) openable).getPrimary());
98
			else if (openable instanceof IClassFile && !JavaModelUtil.getPackageFragmentRoot(je).isArchive())
99
				selectedElements.add(openable);
100
		}
101
	}
102
103
	/**
104
	 * {@inheritDoc}
105
	 */
106
	public void addPages() {
107
		super.addPages();
108
		fJarPackageWizardPage= new FatJarPackageWizardPage(fJarPackage);
109
		addPage(fJarPackageWizardPage);
110
	}
111
112
	private void addProject(List selectedElements, IProject project) {
113
		try {
114
			if (project.hasNature(JavaCore.NATURE_ID))
115
				selectedElements.add(JavaCore.create(project));
116
		} catch (CoreException ex) {
117
			// ignore selected element
118
		}
119
	}
120
121
	private void addResource(List selectedElements, IResource resource) {
122
		IJavaElement je= JavaCore.create(resource);
123
		if (je != null && je.exists() && je.getElementType() == IJavaElement.COMPILATION_UNIT)
124
			selectedElements.add(je);
125
		else
126
			selectedElements.add(resource);
127
	}
128
129
	/**
130
	 * Exports the JAR package.
131
	 * 
132
	 * @param op the operation to run
133
	 * @return a boolean indicating success or failure
134
	 */
135
	protected boolean executeExportOperation(IJarExportRunnable op) {
136
		try {
137
			getContainer().run(true, true, op);
138
		} catch (InterruptedException e) {
139
			return false;
140
		} catch (InvocationTargetException ex) {
141
			if (ex.getTargetException() != null) {
142
				ExceptionHandler.handle(ex, getShell(), FatJarPackagerMessages.JarPackageWizard_jarExportError_title, FatJarPackagerMessages.JarPackageWizard_jarExportError_message);
143
				return false;
144
			}
145
		}
146
		IStatus status= op.getStatus();
147
		if (!status.isOK()) {
148
			ErrorDialog.openError(getShell(), FatJarPackagerMessages.JarPackageWizard_jarExport_title, null, status);
149
			return !(status.matches(IStatus.ERROR));
150
		}
151
		return true;
152
	}
153
154
	public IWizardPage getNextPage(IWizardPage page) {
155
		return super.getNextPage(page);
156
	}
157
158
	public IWizardPage getPreviousPage(IWizardPage page) {
159
		return super.getPreviousPage(page);
160
	}
161
162
	/**
163
	 * Gets the current workspace page selection and converts it to a valid
164
	 * selection for this wizard: - resources and projects are OK - CUs are OK -
165
	 * Java projects are OK - Source package fragments and source packages
166
	 * fragement roots are ok - Java elements below a CU are converted to their
167
	 * CU - all other input elements are ignored
168
	 * 
169
	 * @return a valid structured selection based on the current selection
170
	 */
171
	protected IStructuredSelection getValidSelection() {
172
		ISelection currentSelection= JavaPlugin.getActiveWorkbenchWindow().getSelectionService().getSelection();
173
		if (currentSelection instanceof IStructuredSelection) {
174
			IStructuredSelection structuredSelection= (IStructuredSelection) currentSelection;
175
			List selectedElements= new ArrayList(structuredSelection.size());
176
			Iterator iter= structuredSelection.iterator();
177
			while (iter.hasNext()) {
178
				Object selectedElement= iter.next();
179
				if (selectedElement instanceof IProject)
180
					addProject(selectedElements, (IProject) selectedElement);
181
				else if (selectedElement instanceof IResource)
182
					addResource(selectedElements, (IResource) selectedElement);
183
				else if (selectedElement instanceof IJavaElement)
184
					addJavaElement(selectedElements, (IJavaElement) selectedElement);
185
			}
186
			return new StructuredSelection(selectedElements);
187
		} else
188
			return StructuredSelection.EMPTY;
189
	}
190
191
	/**
192
	 * {@inheritDoc}
193
	 */
194
	public void init(IWorkbench workbench, IStructuredSelection selection) {
195
		fJarPackage= new JarPackageData();
196
		setInitializeFromJarPackage(false);
197
		setWindowTitle(FatJarPackagerMessages.JarPackageWizard_windowTitle);
198
		setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_FAT_JAR_PACKAGER);
199
		setNeedsProgressMonitor(true);
200
	}
201
202
	/**
203
	 * Initializes this wizard from the given JAR package description.
204
	 * 
205
	 * @param workbench
206
	 *            the workbench which launched this wizard
207
	 * @param jarPackage
208
	 *            the JAR package description used to initialize this wizard
209
	 */
210
	public void init(IWorkbench workbench, JarPackageData jarPackage) {
211
		Assert.isNotNull(workbench);
212
		Assert.isNotNull(jarPackage);
213
		fJarPackage= jarPackage;
214
		setInitializeFromJarPackage(true);
215
		setWindowTitle(FatJarPackagerMessages.JarPackageWizard_windowTitle);
216
		setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_FAT_JAR_PACKAGER);
217
		setNeedsProgressMonitor(true);
218
	}
219
220
	boolean isInitializingFromJarPackage() {
221
		return fInitializeFromJarPackage;
222
	}
223
224
	/**
225
	 * {@inheritDoc}
226
	 */
227
	public boolean performFinish() {
228
		fJarPackage.setJarBuilder(new FatJarBuilder());
229
		fJarPackage.setElements(fJarPackageWizardPage.getSelectedElementsWithoutContainedChildren());
230
231
		if (!executeExportOperation(fJarPackage.createJarExportRunnable(getShell())))
232
			return false;
233
234
		// Save the dialog settings
235
		if (fHasNewDialogSettings) {
236
			IDialogSettings workbenchSettings= JavaPlugin.getDefault().getDialogSettings();
237
			IDialogSettings section= workbenchSettings.getSection(DIALOG_SETTINGS_KEY);
238
			section= workbenchSettings.addNewSection(DIALOG_SETTINGS_KEY);
239
			setDialogSettings(section);
240
		}
241
		
242
		fJarPackageWizardPage.finish();
243
		return true;
244
	}
245
246
	void setInitializeFromJarPackage(boolean state) {
247
		fInitializeFromJarPackage= state;
248
	}
249
}

Return to bug 83258