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

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (+1 lines)
Lines 25-30 Link Here
25
 org.eclipse.jdt.ui.tests.core;x-internal:=true,
25
 org.eclipse.jdt.ui.tests.core;x-internal:=true,
26
 org.eclipse.jdt.ui.tests.core.source;x-internal:=true,
26
 org.eclipse.jdt.ui.tests.core.source;x-internal:=true,
27
 org.eclipse.jdt.ui.tests.dialogs;x-internal:=true,
27
 org.eclipse.jdt.ui.tests.dialogs;x-internal:=true,
28
 org.eclipse.jdt.ui.tests.jarexport;x-internal:=true,
28
 org.eclipse.jdt.ui.tests.leaks;x-internal:=true,
29
 org.eclipse.jdt.ui.tests.leaks;x-internal:=true,
29
 org.eclipse.jdt.ui.tests.model;x-internal:=true,
30
 org.eclipse.jdt.ui.tests.model;x-internal:=true,
30
 org.eclipse.jdt.ui.tests.packageview;x-internal:=true,
31
 org.eclipse.jdt.ui.tests.packageview;x-internal:=true,
(-)test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java (-1 / +26 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.testplugin;
12
package org.eclipse.jdt.testplugin;
12
13
Lines 79-84 Link Here
79
	public static final String JUNIT_SRC_ENCODING= "ISO-8859-1";
80
	public static final String JUNIT_SRC_ENCODING= "ISO-8859-1";
80
	
81
	
81
	public static final IPath MYLIB= new Path("testresources/mylib.jar");
82
	public static final IPath MYLIB= new Path("testresources/mylib.jar");
83
	public static final IPath MYLIB_STDOUT= new Path("testresources/mylib_stdout.jar");
84
	public static final IPath MYLIB_SIG= new Path("testresources/mylib_sig.jar");
82
	public static final IPath NLS_LIB= new Path("testresources/nls.jar");
85
	public static final IPath NLS_LIB= new Path("testresources/nls.jar");
83
	
86
	
84
	private static final int MAX_RETRY= 5;
87
	private static final int MAX_RETRY= 5;
Lines 339-344 Link Here
339
	 * @throws CoreException Creation failed
342
	 * @throws CoreException Creation failed
340
	 */				
343
	 */				
341
	public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] inclusionFilters, IPath[] exclusionFilters) throws CoreException {
344
	public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] inclusionFilters, IPath[] exclusionFilters) throws CoreException {
345
		return addSourceContainer(jproject, containerName, inclusionFilters, exclusionFilters, null);
346
	}
347
	
348
	/**
349
	 * Adds a source container to a IJavaProject.
350
	 * @param jproject The parent project
351
	 * @param containerName The name of the new source container
352
	 * @param inclusionFilters Inclusion filters to set
353
	 * @param exclusionFilters Exclusion filters to set
354
	 * @param outputLocation The location where class files are written to, <b>null</b> for project output folder
355
	 * @return The handle to the new source container
356
	 * @throws CoreException Creation failed
357
	 */
358
	public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] inclusionFilters, IPath[] exclusionFilters, String outputLocation) throws CoreException {
342
		IProject project= jproject.getProject();
359
		IProject project= jproject.getProject();
343
		IContainer container= null;
360
		IContainer container= null;
344
		if (containerName == null || containerName.length() == 0) {
361
		if (containerName == null || containerName.length() == 0) {
Lines 352-358 Link Here
352
		}
369
		}
353
		IPackageFragmentRoot root= jproject.getPackageFragmentRoot(container);
370
		IPackageFragmentRoot root= jproject.getPackageFragmentRoot(container);
354
		
371
		
355
		IClasspathEntry cpe= JavaCore.newSourceEntry(root.getPath(), inclusionFilters, exclusionFilters, null);
372
		IPath outputPath= null;
373
		if (outputLocation != null) {
374
			IFolder folder= project.getFolder(outputLocation);
375
			if (!folder.exists()) {
376
				CoreUtility.createFolder(folder, false, true, null);
377
			}
378
			outputPath= folder.getFullPath();
379
		}
380
		IClasspathEntry cpe= JavaCore.newSourceEntry(root.getPath(), inclusionFilters, exclusionFilters, outputPath);
356
		addToClasspath(jproject, cpe);		
381
		addToClasspath(jproject, cpe);		
357
		return root;
382
		return root;
358
	}
383
	}
(-)ui/org/eclipse/jdt/ui/tests/AutomatedSuite.java (-1 / +5 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.ui.tests;
12
package org.eclipse.jdt.ui.tests;
12
13
Lines 21-26 Link Here
21
import org.eclipse.jdt.ui.tests.buildpath.BuildpathModifierActionTest;
22
import org.eclipse.jdt.ui.tests.buildpath.BuildpathModifierActionTest;
22
import org.eclipse.jdt.ui.tests.callhierarchy.CallHierarchyContentProviderTest;
23
import org.eclipse.jdt.ui.tests.callhierarchy.CallHierarchyContentProviderTest;
23
import org.eclipse.jdt.ui.tests.core.CoreTests;
24
import org.eclipse.jdt.ui.tests.core.CoreTests;
25
import org.eclipse.jdt.ui.tests.jarexport.JarExportTests;
24
import org.eclipse.jdt.ui.tests.packageview.PackageExplorerTests;
26
import org.eclipse.jdt.ui.tests.packageview.PackageExplorerTests;
25
import org.eclipse.jdt.ui.tests.quickfix.QuickFixTest;
27
import org.eclipse.jdt.ui.tests.quickfix.QuickFixTest;
26
import org.eclipse.jdt.ui.tests.search.SearchTest;
28
import org.eclipse.jdt.ui.tests.search.SearchTest;
Lines 67-72 Link Here
67
		addTest(JUnitJUnitTests.suite());
69
		addTest(JUnitJUnitTests.suite());
68
		
70
		
69
		addTest(BuildpathModifierActionTest.suite());
71
		addTest(BuildpathModifierActionTest.suite());
72
		
73
		addTest(JarExportTests.suite());
70
	}
74
	}
71
}
75
}
72
76
(-)testresources/mylib_sig.jar (+21 lines)
Added Link Here
1
PKìKK7META-INF/MANIFEST.MFóMÌËLK-.Ñ
2
K-*ÎÌϳR0Ô3àåâåòKÌMµRÈ­ÌÉLÒwËÏ×KÎI,.æå
3
öp4ÔuÉLj±Rp.
4
ñ÷*ôIÍ+7ˆt?H)u²Ô/*ÌεÅb†
5
{æå¥a5,@?;-Ç7ßÌÕ¢Ê#" [ßÐϱ"/ßÙ);À¯apn£]+?œR,ܲô??M‚C,Lª
6
?-
7
#ÁFPKUÕ9y¥PKíKK7META-INF/MYLIBAKE.SF}ÌOOƒ0ð;	ß¡šV(cƒÄÃþ°?nD„¡áb*R…ֵƷwî`bB<¼——wøÅ´b¸íÑR"$å̆Ue-nI¡­†ŸÃÒÍ7hƒÛ¸cà@sÁå [ÒH°\¿S•Ø_چVD¶Ú3Z^†Øê9µÑGÖÓGTˆè¸[Ú8™•Góµ¿WU	qC\Ð5}Ÿn9×óKùs¯êð|JÏéŸ"î#!š›“í\Œ7—Œñ;®5Jã 9{üDü²œ;|3y?]Z¤¦¤™õ/=Š‘µ‡²p/ì‡Ï]4Kk_u™$ÓüŠ}PKßô\ñhPKíKK7META-INF/MYLIBAKE.DSA3hb‘eãÔjóhûÎËÈδ ‰…Ï ‰…‹‰‘Ñ?ۀ“?U›?™IŠ•Á€¡ˆqA³¬A³¤AÓ5&wÎËí@iv ô9f ÚB°VæP6a&WC~^‡C˜Í#µ¸85ÏPÄ@$À.ÌUž™—žš—”Z”n(`Àåf/(Ê,K,I…‰p#DÄ
8
DA"ÌÂ|n©E©yÉ
9
©É9©E
10
â¼æ†f¦†¦†QüF†¦ÆF0??pTãv Ö?
11
#?#ÏÔØÈð·>¸Q¶TH3è¾×½7OžÜdóޅᰜ}ö@µL×X¥Àߑ¶½¿öýºËàÛéÙ¡9×­dMò?¥%lϞ°tÉüù/Xª”ùï^yýßöcÒ?¬ÃŸ[±L”Ÿåwó·ËGå3™†G‰M4úVúy?vâu­÷Ÿ”˜%ç^ô`<Î$Ê0=! _T™û̦I;›½náþ!óä´ï´^›m{ïôžÕ1f;ÂwVNY¿û—Õ«¦Ÿá>ܶìMé?‘á}»®Dú?+dhlØâ)V¨üÂGCLxûyN£žËڈUu‡Ôôj<X¼NN{ó²Ò‰y‹ë¹)š&}ü?TŨb}fÉÇ}+'t®h¾ÿ0êé|¶IÝiq
12
Õ¡ª)Œ>ÖÿÎ{j17¶0056iH9[åþnö}ɗnÍ Ã|έ8qµëù¬¥S‹¿wM|¥j7ýÏ.¡ùÌ=¢·\ؓ.s/F|Ýۛ‡}“»~&Ö­PépŒW¹÷2"ïñÝdÆ?C®zzwôH­þùà§Í3CŸ0Ã?™ùKEç°f<ÒV:ïhqú[›×ǛÏ6niù?’ž™
13
t™Dü-mW)3»ò2Ì[dr]…`G@û`HNål¾i}VU¿½íÇ)Ñ?…õçÿéß4l<iÐx˜‡* ÝA³$Jæ…%AV=&‰å/¯ò4µñqt[Éù2y´)6q“Ãq¶ågú™Ê¥•oÇ<+ý»ÚŽPKùž!PK²KK7&mylib/Foo$FooInner$FooInnerInner.class…OMKÃ@}Ó¦Ù$¦¶?_W*h~€â¥P‚”Þ7qÑ-Û,$©ÐŸåIðàðG'[)ˆwÙ7óffßÌ|­>>ÑÅ:„ÃùÒè<?X{Âï¶,Uµqx„áL¾ÊÔÈò9½Ïgªhþµ.usC螞M	ÞØ>©ˆ…Ã=ø„A¦Ku·˜çªz”¹Q„$³…4SYé–ÿ½æEׄãì¿9®Ñƒ]T…šèöcÀÙËv,Bì
14
ÆFÖµªnõWM`—nâk—!ôuÂx+´‡øò6Œ‚Yê8Ð;GðÆN£ï‚¶ãuÛ¾Ëo;`È6ao„ì!äªö~PK6ÂrP?PK²KK7mylib/Foo$FooInner.classeOÁJ1}Ón7ÝukëZõªàAÝP¼
15
¢¥÷ì4%M`w+øYž~€%Φ¥ Mț÷f^&“Ÿß¯otq‰#?!]¼]dSçNùÜY«*?€0šË7™i_²‡b®Ê†Þh«›[B÷ì|F&îYÅÜ*JÐCHæÚªûå¢PՓ,Œâæ¹+¥™ÉJ·z?šW]ÆùöËׄøÑ-«RMukís᪄?xÃÄȺVµ@Jˆ6÷WÆõì„ãíÎâ?0ø§qþÚE¼ù7Œ‚Uæ5лøDÿƒI1cè“;ŒÉÊÀqà뻇qL™ö°?cf‡ˆþPK[@¼ÑüPK²KK7mylib/Foo.class…RkOA=¥³]Vå!" hÑ¡Å÷£€Ê£jR«I	¿˜ívZ–´;ÍîTäùYLŠ‘D?šø£Œw¶ò61›™Ù{îœ{fÎÜ_¿¿}G'æð‚£ƒ!Vß­¹¥LNJŽC߶ýÁÎÔl¯šy]ڎbàN͂Ä<Cþ8»¢Á,ñ‹»žÚÊu¢®çª%†Îdjƒ!²"ËÂ$-˂?X=èãè=%RÜ
16
”¨[èGœh²IzCmWfÞø®§ŠÊv=Ë1È0|‚¨(Y]nV*Â70Ì`8´O‰ò¤‰ŒhÅKT+™?Kɦ6b`¸l¡Q㇤ÉW0Å1ÉÐ{榮âyQ‘~Á®†éU>çÇ4ÃÄ1Z?!¾**9ÙôÊk¾/}7?âH2o\ßòåŽ]ª	3¸É`V…z%‚À®’ö`2u^ÜD#úiMáDÑgÕ~ܲpwè…ìFCxe†Ùÿÿ¤½Y]ចûºª¡d;gâ!s<:<öé÷²?Õþó††jÇ"Ãäw
17
Rµ]ø舆r¥G¶ç]Ošõ’ð×õíâyéص
18
ÛwuüŒ¨-7`èÎ5/u¢Y”Mß9Wï0Kk=ë¥ç	?TGŽjÑ4Ât›þbŠÚ£ ÙÐ=B+ÂX#ºyLŠv°8³?î=\8ÀÀf|h÷0ºùcoãc_1±ù£ŸÐ{€Ä»÷-\ßÇì?æZ˜oán>S‰ŒÓÓ- KT®'”ŽÐ×EXO(²ÚBxŠg´v`9œW°J«I¹5ÏûPK#A
19
NVÚPKìKK7UÕ9y¥META-INF/MANIFEST.MFPKíKK7ßô\ñhçMETA-INF/MYLIBAKE.SFPKíKK7ùž!META-INF/MYLIBAKE.DSAPK²KK76ÂrP?&cmylib/Foo$FooInner$FooInnerInner.classPK²KK7[@¼Ñü·mylib/Foo$FooInner.classPK²KK7#A
20
NVÚùmylib/Foo.classPKžŒ
21
(-)ui/org/eclipse/jdt/ui/tests/jarexport/JarExportTests.java (+26 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.ui.tests.jarexport;
13
14
import junit.framework.Test;
15
import junit.framework.TestSuite;
16
17
public class JarExportTests {
18
19
	public static Test suite() {
20
		TestSuite suite= new TestSuite("Test for org.eclipse.jdt.ui.tests.jarexport");
21
		//$JUnit-BEGIN$
22
		suite.addTest(FatJarExportTests.allTests());
23
		//$JUnit-END$
24
		return suite;
25
	}
26
}
(-)testresources/mylib_stdout.jar (+9 lines)
Added Link Here
1
PKÅKK7META-INF/MANIFEST.MFþÊóMÌËLK-.Ñ
2
K-*ÎÌϳR0Ô3àåâåPK²îPK²KK7&mylib/Foo$FooInner$FooInnerInner.class…OMKÃ@}Ó¦Ù$¦¶?_W*h~€â¥P‚”Þ7qÑ-Û,$©ÐŸåIðàðG'[)ˆwÙ7óffßÌ|­>>ÑÅ:„ÃùÒè<?X{Âï¶,Uµqx„áL¾ÊÔÈò9½Ïgªhþµ.usC螞M	ÞØ>©ˆ…Ã=ø„A¦Ku·˜çªz”¹Q„$³…4SYé–ÿ½æEׄãì¿9®Ñƒ]T…šèöcÀÙËv,Bì
3
ÆFÖµªnõWM`—nâk—!ôuÂx+´‡øò6Œ‚Yê8Ð;GðÆN£ï‚¶ãuÛ¾Ëo;`È6ao„ì!äªö~PK6ÂrP?PK²KK7mylib/Foo$FooInner.classeOÁJ1}Ón7ÝukëZõªàAÝP¼
4
¢¥÷ì4%M`w+øYž~€%Φ¥ Mț÷f^&“Ÿß¯otq‰#?!]¼]dSçNùÜY«*?€0šË7™i_²‡b®Ê†Þh«›[B÷ì|F&îYÅÜ*JÐCHæÚªûå¢PՓ,Œâæ¹+¥™ÉJ·z?šW]ÆùöËׄøÑ-«RMukís᪄?xÃÄȺVµ@Jˆ6÷WÆõì„ãíÎâ?0ø§qþÚE¼ù7Œ‚Uæ5лøDÿƒI1cè“;ŒÉÊÀqà뻇qL™ö°?cf‡ˆþPK[@¼ÑüPK²KK7mylib/Foo.class…RkOA=¥³]Vå!" hÑ¡Å÷£€Ê£jR«I	¿˜ívZ–´;ÍîTäùYLŠ‘D?šø£Œw¶ò61›™Ù{îœ{fÎÜ_¿¿}G'æð‚£ƒ!Vß­¹¥LNJŽC߶ýÁÎÔl¯šy]ڎbàN͂Ä<Cþ8»¢Á,ñ‹»žÚÊu¢®çª%†Îdjƒ!²"ËÂ$-˂?X=èãè=%RÜ
5
”¨[èGœh²IzCmWfÞø®§ŠÊv=Ë1È0|‚¨(Y]nV*Â70Ì`8´O‰ò¤‰ŒhÅKT+™?Kɦ6b`¸l¡Q㇤ÉW0Å1ÉÐ{榮âyQ‘~Á®†éU>çÇ4ÃÄ1Z?!¾**9ÙôÊk¾/}7?âH2o\ßòåŽ]ª	3¸É`V…z%‚À®’ö`2u^ÜD#úiMáDÑgÕ~ܲpwè…ìFCxe†Ùÿÿ¤½Y]ចûºª¡d;gâ!s<:<öé÷²?Õþó††jÇ"Ãäw
6
Rµ]ø舆r¥G¶ç]Ošõ’ð×õíâyéص
7
ÛwuüŒ¨-7`èÎ5/u¢Y”Mß9Wï0Kk=ë¥ç	?TGŽjÑ4Ât›þbŠÚ£ ÙÐ=B+ÂX#ºyLŠv°8³?î=\8ÀÀf|h÷0ºùcoãc_1±ù£ŸÐ{€Ä»÷-\ßÇì?æZ˜oán>S‰ŒÓÓ- KT®'”ŽÐ×EXO(²ÚBxŠg´v`9œW°J«I¹5ÏûPK#A
8
NVÚPKÅKK7²îMETA-INF/MANIFEST.MFþÊPK²KK76ÂrP?&amylib/Foo$FooInner$FooInnerInner.classPK²KK7[@¼Ñüµmylib/Foo$FooInner.classPK²KK7#A
9
NVÚ÷mylib/Foo.classPKŠ
(-)ui/org/eclipse/jdt/ui/tests/jarexport/FatJarExportTests.java (+420 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.ui.tests.jarexport;
13
14
import java.io.File;
15
import java.util.Map;
16
import java.util.zip.ZipFile;
17
18
import junit.framework.Test;
19
import junit.framework.TestCase;
20
import junit.framework.TestSuite;
21
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.MultiStatus;
26
import org.eclipse.core.runtime.Path;
27
import org.eclipse.core.runtime.Status;
28
29
import org.eclipse.core.resources.IMarker;
30
import org.eclipse.core.resources.IResource;
31
import org.eclipse.core.resources.IncrementalProjectBuilder;
32
import org.eclipse.core.resources.ResourcesPlugin;
33
34
import org.eclipse.ui.IWorkbenchWindow;
35
import org.eclipse.ui.PlatformUI;
36
37
import org.eclipse.debug.core.DebugPlugin;
38
import org.eclipse.debug.core.ILaunch;
39
import org.eclipse.debug.core.ILaunchConfiguration;
40
import org.eclipse.debug.core.ILaunchConfigurationType;
41
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
42
import org.eclipse.debug.core.ILaunchManager;
43
import org.eclipse.debug.core.Launch;
44
import org.eclipse.debug.core.model.IProcess;
45
46
import org.eclipse.jdt.core.IJavaProject;
47
import org.eclipse.jdt.core.IPackageFragment;
48
import org.eclipse.jdt.core.IPackageFragmentRoot;
49
import org.eclipse.jdt.core.JavaCore;
50
51
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
52
53
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
54
import org.eclipse.jdt.launching.IVMInstall;
55
import org.eclipse.jdt.launching.IVMRunner;
56
import org.eclipse.jdt.launching.JavaRuntime;
57
import org.eclipse.jdt.launching.VMRunnerConfiguration;
58
59
import org.eclipse.jdt.ui.JavaUI;
60
import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable;
61
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
62
63
import org.eclipse.jdt.internal.ui.JavaPlugin;
64
import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil;
65
import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarBuilder;
66
import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarPackageWizardPage;
67
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
68
69
import org.eclipse.jdt.testplugin.JavaProjectHelper;
70
import org.eclipse.jdt.testplugin.JavaTestPlugin;
71
72
import org.eclipse.jdt.ui.tests.core.ProjectTestSetup;
73
74
public class FatJarExportTests extends TestCase {
75
76
	private static final Class THIS= FatJarExportTests.class;
77
78
	public static Test suite() {
79
		return allTests();
80
	}
81
82
	public static Test allTests() {
83
		return new ProjectTestSetup(new TestSuite(THIS));
84
	}
85
86
	private IJavaProject fProject;
87
	private IPackageFragmentRoot fMainRoot;
88
89
	/**
90
	 * {@inheritDoc}
91
	 */
92
	protected void setUp() throws Exception {
93
		fProject= ProjectTestSetup.getProject();
94
95
		Map options= fProject.getOptions(false);
96
		String compliance= JavaCore.VERSION_1_4;
97
		JavaModelUtil.setCompilanceOptions(options, compliance);
98
		JavaModelUtil.setDefaultClassfileOptions(options, compliance); // complete compliance options
99
		fProject.setOptions(options);
100
101
		fMainRoot= JavaProjectHelper.addSourceContainer(fProject, "src");
102
		IPackageFragment fragment= fMainRoot.createPackageFragment("org.eclipse.jdt.ui.test", true, null);
103
		StringBuffer buf= new StringBuffer();
104
		buf.append("package org.eclipse.jdt.ui.test;\n");
105
		buf.append("import mylib.Foo;\n");
106
		buf.append("public class Main {\n");
107
		buf.append("    public static void main(String[] args) {\n");
108
		buf.append("        new Foo();\n");
109
		buf.append("        new Foo.FooInner();\n");
110
		buf.append("        new Foo.FooInner.FooInnerInner();\n");
111
		buf.append("    }\n");
112
		buf.append("}\n");
113
		fragment.createCompilationUnit("Main.java", buf.toString(), true, null);
114
	}
115
116
	/**
117
	 * {@inheritDoc}
118
	 */
119
	protected void tearDown() throws Exception {
120
		JavaProjectHelper.clear(fProject, ProjectTestSetup.getDefaultClasspath());
121
	}
122
123
	private static String getFooContent() {
124
		StringBuffer buf= new StringBuffer();
125
		buf.append("package mylib;\n");
126
		buf.append("public class Foo {\n");
127
		buf.append("    public Foo() {\n");
128
		buf.append("        System.out.println(\"created \" + Foo.class.getName());\n");
129
		buf.append("    }\n");
130
		buf.append("    public static class FooInner {\n");
131
		buf.append("        public static class FooInnerInner {\n");
132
		buf.append("        }\n");
133
		buf.append("    }\n");
134
		buf.append("}\n");
135
		return buf.toString();
136
	}
137
138
	private static void createAndRunFatJar(IJavaProject project, String archiveName) throws Exception, CoreException {
139
		// create jar and check contents
140
		IPath jarLocation= assertFatJarExport(project, archiveName + ".jar");
141
142
		// run newly generated jar and check stdout
143
		String stdout= runJar(project, jarLocation.toOSString());
144
		// normalize EndOfLine to \n
145
		stdout= stdout.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
146
		// check for successful call of Foo
147
		String expected= "created mylib.Foo\n";
148
		assertEquals(expected, stdout);
149
	}
150
151
	private static IPath assertFatJarExport(IJavaProject project, String archiveName) throws Exception {
152
		//create class files
153
		ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
154
155
		IMarker[] markers= ResourcesPlugin.getWorkspace().getRoot().findMarkers(null, true, IResource.DEPTH_INFINITE);
156
		for (int i= 0; i < markers.length; i++) {
157
			IMarker marker= markers[i];
158
			if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_ERROR) {
159
				assertTrue((String) marker.getAttribute(IMarker.MESSAGE), false);
160
			}
161
		}
162
163
		//create data
164
		JarPackageData data= createJarPackageData(project, archiveName);
165
166
		//create archive
167
		ZipFile generatedArchive= createArchive(data);
168
169
		//assert archive content as expected
170
		assertNotNull(generatedArchive);
171
		assertNotNull(generatedArchive.getEntry("org/eclipse/jdt/ui/test/Main.class"));
172
		assertNotNull(generatedArchive.getEntry("mylib/Foo.class"));
173
		assertNotNull(generatedArchive.getEntry("mylib/Foo$FooInner.class"));
174
		assertNotNull(generatedArchive.getEntry("mylib/Foo$FooInner$FooInnerInner.class"));
175
176
		return data.getJarLocation();
177
	}
178
179
	private static JarPackageData createJarPackageData(IJavaProject project, String archiveName) throws CoreException {
180
		JarPackageData data= new JarPackageData();
181
		data.setJarBuilder(new FatJarBuilder());
182
183
		IPath destination= ResourcesPlugin.getWorkspace().getRoot().getLocation().append(archiveName);
184
		data.setJarLocation(destination);
185
186
		ILaunchConfiguration launchConfig= createTempLaunchConfig(project);
187
188
		MultiStatus status= new MultiStatus(JavaUI.ID_PLUGIN, 0, "", null);
189
		Object[] children= FatJarPackageWizardPage.getSelectedElementsWithoutContainedChildren(launchConfig, data, new BusyIndicatorRunnableContext(), status);
190
		assertTrue(getProblems(status), status.getSeverity() == IStatus.OK || status.getSeverity() == IStatus.INFO);
191
		data.setElements(children);
192
193
		return data;
194
	}
195
196
	private static String getProblems(MultiStatus status) {
197
		StringBuffer result= new StringBuffer();
198
199
		IStatus[] children= status.getChildren();
200
		for (int i= 0; i < children.length; i++) {
201
			result.append(children[i].getMessage()).append("\n");
202
		}
203
204
		return result.toString();
205
	}
206
207
	/*
208
	 *  From org.eclipse.jdt.internal.debug.ui.launcher.JavaApplicationLaunchShortcut
209
	 *  
210
	 *  For internal use only (testing), clients must not call.
211
	 */
212
	public static ILaunchConfiguration createTempLaunchConfig(IJavaProject project) {
213
		String projectName= project.getElementName();
214
215
		String configname= "fatjar_cfg_eraseme_" + projectName; //$NON-NLS-1$
216
		ILaunchConfiguration config= null;
217
		ILaunchConfigurationWorkingCopy wc= null;
218
		try {
219
			ILaunchManager launchManager= DebugPlugin.getDefault().getLaunchManager();
220
			ILaunchConfigurationType configType= launchManager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
221
			wc= configType.newInstance(null, launchManager.generateUniqueLaunchConfigurationNameFrom(configname));
222
		} catch (CoreException e) {
223
			JavaPlugin.log(e);
224
			return null;
225
		}
226
227
		wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.eclipse.jdt.ui.test.Main");
228
		wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
229
		try {
230
			config= wc.doSave();
231
		} catch (CoreException e) {
232
			JavaPlugin.log(e);
233
		}
234
235
		return config;
236
	}
237
238
	private static ZipFile createArchive(JarPackageData data) throws Exception, CoreException {
239
		IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
240
241
		IJarExportRunnable op= data.createJarExportRunnable(window.getShell());
242
		window.run(false, false, op);
243
244
		IStatus status= op.getStatus();
245
		if (status.getSeverity() == IStatus.ERROR)
246
			throw new CoreException(status);
247
248
		return JarPackagerUtil.getArchiveFile(data.getJarLocation());
249
	}
250
251
	private static String runJar(IJavaProject project, String jarPath) throws CoreException {
252
253
		IVMInstall vmInstall= JavaRuntime.getVMInstall(project);
254
		if (vmInstall == null)
255
			vmInstall= JavaRuntime.getDefaultVMInstall();
256
257
		if (vmInstall == null)
258
			throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), "Could not find a VM Install"));
259
260
		IVMRunner vmRunner= vmInstall.getVMRunner(ILaunchManager.RUN_MODE);
261
		if (vmRunner == null)
262
			throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), "Could not create a VM Runner"));
263
264
		VMRunnerConfiguration vmConfig= new VMRunnerConfiguration("-jar", new String[] {});
265
		vmConfig.setWorkingDirectory(new File(jarPath).getParent());
266
		vmConfig.setProgramArguments(new String[] { jarPath });
267
268
		ILaunch launch= new Launch(null, ILaunchManager.RUN_MODE, null);
269
		vmRunner.run(vmConfig, launch, null);
270
271
		IProcess[] processes= launch.getProcesses();
272
		if (processes.length == 0)
273
			throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), "Could not launch jar"));
274
275
		int timeout= 30;
276
		while (timeout > 0 && !processes[0].isTerminated()) {
277
			try {
278
				Thread.sleep(100);
279
			} catch (InterruptedException e) {
280
			}
281
282
			timeout--;
283
		}
284
		if (!processes[0].isTerminated())
285
			throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), "Process did not terminate within timeout"));
286
287
		int exitCode= processes[0].getExitValue();
288
289
		try {
290
			Thread.sleep(500);
291
		} catch (InterruptedException e) {
292
		}
293
294
		if (exitCode != 0) {
295
			String stdout= processes[0].getStreamsProxy().getOutputStreamMonitor().getContents();
296
			String errout= processes[0].getStreamsProxy().getErrorStreamMonitor().getContents();
297
			
298
			throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), "Run failed: exitcode=" + exitCode + ", stdout=[" + stdout + "], stderr=[" + errout + "]"));
299
		} else {
300
			return processes[0].getStreamsProxy().getOutputStreamMonitor().getContents();
301
		}
302
	}
303
304
	public void testExportSameSrcRoot() throws Exception {
305
		IPackageFragment pack= fMainRoot.createPackageFragment("mylib", true, null);
306
		try {
307
			pack.createCompilationUnit("Foo.java", getFooContent(), true, null);
308
309
			createAndRunFatJar(fProject, getName() + ".jar");
310
		} finally {
311
			pack.delete(true, null);
312
		}
313
	}
314
315
	public void testExportSrcRootWithOutputFolder() throws Exception {
316
		IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(fProject, "other", new IPath[0], new IPath[0], "otherout");
317
		try {
318
			IPackageFragment pack= root.createPackageFragment("mylib", true, null);
319
			pack.createCompilationUnit("Foo.java", getFooContent(), true, null);
320
321
			createAndRunFatJar(fProject, getName() + ".jar");
322
		} finally {
323
			JavaProjectHelper.removeSourceContainer(fProject, root.getElementName());
324
		}
325
	}
326
327
	public void testExportOtherSrcRoot() throws Exception {
328
		IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(fProject, "other");
329
		try {
330
			IPackageFragment pack= root.createPackageFragment("mylib", true, null);
331
			pack.createCompilationUnit("Foo.java", getFooContent(), true, null);
332
333
			createAndRunFatJar(fProject, getName() + ".jar");
334
		} finally {
335
			JavaProjectHelper.removeSourceContainer(fProject, root.getElementName());
336
		}
337
	}
338
339
	public void testExportOtherProject() throws Exception {
340
		IJavaProject otherProject= JavaProjectHelper.createJavaProject("OtherProject", "bin");
341
		try {
342
			otherProject.setRawClasspath(ProjectTestSetup.getDefaultClasspath(), null);
343
344
			IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(otherProject, "other");
345
			IPackageFragment pack= root.createPackageFragment("mylib", true, null);
346
			pack.createCompilationUnit("Foo.java", getFooContent(), true, null);
347
348
			JavaProjectHelper.addRequiredProject(fProject, otherProject);
349
350
			createAndRunFatJar(fProject, getName() + ".jar");
351
		} finally {
352
			JavaProjectHelper.removeFromClasspath(fProject, otherProject.getProject().getFullPath());
353
			JavaProjectHelper.delete(otherProject);
354
		}
355
	}
356
357
	public void testExportInternalLib() throws Exception {
358
		File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB_STDOUT);
359
		IPackageFragmentRoot root= JavaProjectHelper.addLibraryWithImport(fProject, Path.fromOSString(lib.getPath()), null, null);
360
361
		try {
362
			createAndRunFatJar(fProject, getName() + ".jar");
363
		} finally {
364
			JavaProjectHelper.removeFromClasspath(fProject, root.getPath());
365
		}
366
	}
367
368
	public void testExportExternalLib() throws Exception {
369
		File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB_STDOUT);
370
		IPackageFragmentRoot root= JavaProjectHelper.addLibrary(fProject, Path.fromOSString(lib.getPath()));
371
372
		try {
373
			createAndRunFatJar(fProject, getName() + ".jar");
374
		} finally {
375
			JavaProjectHelper.removeFromClasspath(fProject, root.getPath());
376
		}
377
	}
378
379
	public void testClassFolder() throws Exception {
380
		File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB_STDOUT);
381
382
		IPackageFragmentRoot root= JavaProjectHelper.addClassFolderWithImport(fProject, "cf", null, null, lib);
383
		try {
384
			createAndRunFatJar(fProject, getName() + ".jar");
385
		} finally {
386
			JavaProjectHelper.removeFromClasspath(fProject, root.getPath());
387
		}
388
	}
389
390
	public void testVariable() throws Exception {
391
		File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB_STDOUT);
392
		JavaCore.setClasspathVariable("MYLIB", Path.fromOSString(lib.getPath()), null);
393
394
		JavaProjectHelper.addVariableEntry(fProject, new Path("MYLIB"), null, null);
395
		try {
396
			createAndRunFatJar(fProject, getName() + ".jar");
397
		} finally {
398
			JavaProjectHelper.removeFromClasspath(fProject, new Path("MYLIB"));
399
		}
400
	}
401
402
	public void testSignedLibs() throws Exception {
403
		File lib= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.MYLIB_SIG);
404
		IPackageFragmentRoot root= JavaProjectHelper.addLibraryWithImport(fProject, Path.fromOSString(lib.getPath()), null, null);
405
406
		try {
407
			createAndRunFatJar(fProject, getName());
408
		} finally {
409
			JavaProjectHelper.removeFromClasspath(fProject, root.getPath());
410
		}
411
	}
412
413
	public void xtestNoMylib2() throws Exception {
414
		try {
415
			createAndRunFatJar(fProject, getName() + ".jar");
416
		} catch (Throwable e) {
417
			e.printStackTrace();
418
		}
419
	}
420
}
(-)plugin.properties (+3 lines)
Lines 7-12 Link Here
7
#
7
#
8
# Contributors:
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
#     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
###############################################################################
11
###############################################################################
11
12
12
pluginName= Java Development Tools UI
13
pluginName= Java Development Tools UI
Lines 189-194 Link Here
189
jarExportWizard.label=JAR file
190
jarExportWizard.label=JAR file
190
jarExportWizard.description=Export resources into a JAR file on the local file system.
191
jarExportWizard.description=Export resources into a JAR file on the local file system.
191
192
193
fatJarExportWizard.label=Runnable JAR file
194
fatJarExportWizard.description=Export all resources required to run an application into a JAR file on the local file system.
192
195
193
createJarAction.label=Create &JAR
196
createJarAction.label=Create &JAR
194
createJarAction.tooltip=Creates the JAR Based on the Selected JAR Description File
197
createJarAction.tooltip=Creates the JAR Based on the Selected JAR Description File
(-)plugin.xml (+13 lines)
Lines 1932-1937 Link Here
1932
               class="org.eclipse.core.resources.IResource">
1932
               class="org.eclipse.core.resources.IResource">
1933
         </selection>
1933
         </selection>
1934
      </wizard>
1934
      </wizard>
1935
      <wizard
1936
            name="%fatJarExportWizard.label"
1937
            icon="$nl$/icons/full/etool16/exportfatjar_wiz.gif"
1938
            class="org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarPackageWizard"
1939
            category="org.eclipse.jdt.ui.Java"
1940
            id="org.eclipse.jdt.internal.ui.fatjarpackager.JarPackageWizard">
1941
         <description>
1942
            %fatJarExportWizard.description
1943
         </description>
1944
         <selection
1945
               class="org.eclipse.core.resources.IResource">
1946
         </selection>
1947
      </wizard>
1935
   </extension>
1948
   </extension>
1936
   <extension
1949
   <extension
1937
         point="org.eclipse.ui.popupMenus">
1950
         point="org.eclipse.ui.popupMenus">
(-)apichanges_jdt-ui.html (+12 lines)
Lines 107-112 Link Here
107
    </tr> 
107
    </tr> 
108
    <tr>
108
    <tr>
109
      <td>
109
      <td>
110
      Added API for the jar packager:
111
      <ul>
112
      <li>Added <code>org.eclipse.jdt.ui.jarpackager.IJarBuilder</code></li>
113
      <li>Added methods to set and get jar builder in <code>org.eclipse.jdt.ui.jarpackager.JarPackageData</code></li>
114
      <li>Added factories to create jar builders in <code>org.eclipse.jdt.ui.jarpackager.JarPackageData</code></li>
115
      <li>Added methods to set and get launch configuration name in <code>org.eclipse.jdt.ui.jarpackager.JarPackageData</code></li>
116
      <li>Added method <code>org.eclipse.jdt.ui.jarpackager.JarWriter3.addEntry(JarEntry, InputStream)</code></li>
117
      </ul>
118
      </td>
119
    </tr>  
120
    <tr>
121
      <td>
110
      All occurrence actions available in for find occurrence. New actions and constants.
122
      All occurrence actions available in for find occurrence. New actions and constants.
111
      <ul>
123
      <ul>
112
      <li>FindBreakContinueTargetOccurrencesAction</li>
124
      <li>FindBreakContinueTargetOccurrencesAction</li>
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWizardPage.java (-237 / +11 lines)
Lines 7-16 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackager;
12
package org.eclipse.jdt.internal.ui.jarpackager;
12
13
13
import java.io.File;
14
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.HashSet;
15
import java.util.HashSet;
16
import java.util.Iterator;
16
import java.util.Iterator;
Lines 20-26 Link Here
20
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Path;
24
23
25
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.resources.IFile;
26
import org.eclipse.core.resources.IFolder;
25
import org.eclipse.core.resources.IFolder;
Lines 36-45 Link Here
36
import org.eclipse.swt.layout.GridData;
35
import org.eclipse.swt.layout.GridData;
37
import org.eclipse.swt.layout.GridLayout;
36
import org.eclipse.swt.layout.GridLayout;
38
import org.eclipse.swt.widgets.Button;
37
import org.eclipse.swt.widgets.Button;
39
import org.eclipse.swt.widgets.Combo;
40
import org.eclipse.swt.widgets.Composite;
38
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;
39
import org.eclipse.swt.widgets.Label;
44
import org.eclipse.swt.widgets.Link;
40
import org.eclipse.swt.widgets.Link;
45
import org.eclipse.swt.widgets.TreeItem;
41
import org.eclipse.swt.widgets.TreeItem;
Lines 56-62 Link Here
56
import org.eclipse.jface.wizard.IWizardPage;
52
import org.eclipse.jface.wizard.IWizardPage;
57
53
58
import org.eclipse.ui.PlatformUI;
54
import org.eclipse.ui.PlatformUI;
59
import org.eclipse.ui.dialogs.WizardExportResourcesPage;
60
55
61
import org.eclipse.ltk.core.refactoring.RefactoringCore;
56
import org.eclipse.ltk.core.refactoring.RefactoringCore;
62
import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService;
57
import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService;
Lines 82-94 Link Here
82
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
77
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
83
import org.eclipse.jdt.internal.ui.filters.EmptyInnerPackageFilter;
78
import org.eclipse.jdt.internal.ui.filters.EmptyInnerPackageFilter;
84
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
79
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;
80
import org.eclipse.jdt.internal.ui.viewsupport.LibraryFilter;
87
81
88
/**
82
/**
89
 *	Page 1 of the JAR Package wizard
83
 *	Page 1 of the JAR Package wizard
90
 */
84
 */
91
class JarPackageWizardPage extends WizardExportResourcesPage implements IJarPackageWizardPage {
85
class JarPackageWizardPage extends AbstractJarDestinationWizardPage {
92
86
93
	private JarPackageData fJarPackage;
87
	private JarPackageData fJarPackage;
94
	private IStructuredSelection fInitialSelection;
88
	private IStructuredSelection fInitialSelection;
Lines 101-109 Link Here
101
	private Button	fExportRefactoringsCheckbox;
95
	private Button	fExportRefactoringsCheckbox;
102
	private Link fRefactoringLink;
96
	private Link fRefactoringLink;
103
	
97
	
104
	private Combo	fDestinationNamesCombo;
105
	private Button	fDestinationBrowseButton;
106
	
107
	private Button		fCompressCheckbox;
98
	private Button		fCompressCheckbox;
108
	private Button		fOverwriteCheckbox;
99
	private Button		fOverwriteCheckbox;
109
	private Button		fIncludeDirectoryEntriesCheckbox;
100
	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$
107
	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$
108
	private static final String STORE_EXPORT_JAVA_FILES= PAGE_NAME + ".EXPORT_JAVA_FILES"; //$NON-NLS-1$
118
	
109
	
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$
110
	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$
111
	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$
112
	private final static String STORE_OVERWRITE= PAGE_NAME + ".OVERWRITE"; //$NON-NLS-1$
Lines 129-137 Link Here
129
	
118
	
130
	/**
119
	/**
131
	 *	Create an instance of this class
120
	 *	Create an instance of this class
121
	 *
122
	 * @param jarPackage an object containing all required information to make an export
123
	 * @param selection the initial selection
132
	 */
124
	 */
133
	public JarPackageWizardPage(JarPackageData jarPackage, IStructuredSelection selection) {
125
	public JarPackageWizardPage(JarPackageData jarPackage, IStructuredSelection selection) {
134
		super(PAGE_NAME, selection);
126
		super(PAGE_NAME, selection, jarPackage);
135
		setTitle(JarPackagerMessages.JarPackageWizardPage_title); 
127
		setTitle(JarPackagerMessages.JarPackageWizardPage_title); 
136
		setDescription(JarPackagerMessages.JarPackageWizardPage_description); 
128
		setDescription(JarPackagerMessages.JarPackageWizardPage_description); 
137
		fJarPackage= jarPackage;
129
		fJarPackage= jarPackage;
Lines 207-245 Link Here
207
	}
199
	}
208
200
209
	/**
201
	/**
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 
202
	 * Returns an iterator over this page's collection of currently-specified 
244
	 * elements to be exported. This is the primary element selection facility
203
	 * elements to be exported. This is the primary element selection facility
245
	 * accessor for subclasses.
204
	 * accessor for subclasses.
Lines 257-271 Link Here
257
	 * <code>internalSaveWidgetValues</code>.
216
	 * <code>internalSaveWidgetValues</code>.
258
	 */
217
	 */
259
	public final void saveWidgetValues() {
218
	public final void saveWidgetValues() {
219
		super.saveWidgetValues();
260
		// update directory names history
220
		// update directory names history
261
		IDialogSettings settings= getDialogSettings();
221
		IDialogSettings settings= getDialogSettings();
262
		if (settings != null) {
222
		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());
223
			settings.put(STORE_EXPORT_CLASS_FILES, fJarPackage.areClassFilesExported());
270
			settings.put(STORE_EXPORT_OUTPUT_FOLDERS, fJarPackage.areOutputFoldersExported());
224
			settings.put(STORE_EXPORT_OUTPUT_FOLDERS, fJarPackage.areOutputFoldersExported());
271
			settings.put(STORE_EXPORT_JAVA_FILES, fJarPackage.areJavaFilesExported());
225
			settings.put(STORE_EXPORT_JAVA_FILES, fJarPackage.areJavaFilesExported());
Lines 298-318 Link Here
298
		fExportOutputFoldersCheckbox.setSelection(fJarPackage.areOutputFoldersExported());
252
		fExportOutputFoldersCheckbox.setSelection(fJarPackage.areOutputFoldersExported());
299
		fExportJavaFilesCheckbox.setSelection(fJarPackage.areJavaFilesExported());
253
		fExportJavaFilesCheckbox.setSelection(fJarPackage.areJavaFilesExported());
300
254
301
		// destination
255
		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
		
256
		
317
		// options
257
		// options
318
		if (fExportRefactoringsCheckbox != null)
258
		if (fExportRefactoringsCheckbox != null)
Lines 326-331 Link Here
326
	 *	Initializes the JAR package from last used wizard page values.
266
	 *	Initializes the JAR package from last used wizard page values.
327
	 */
267
	 */
328
	protected void initializeJarPackage() {
268
	protected void initializeJarPackage() {
269
		super.initializeJarPackage();
270
		
329
		IDialogSettings settings= getDialogSettings();
271
		IDialogSettings settings= getDialogSettings();
330
		if (settings != null) {
272
		if (settings != null) {
331
			// source
273
			// source
Lines 339-350 Link Here
339
			fJarPackage.setCompress(settings.getBoolean(STORE_COMPRESS));
281
			fJarPackage.setCompress(settings.getBoolean(STORE_COMPRESS));
340
			fJarPackage.setIncludeDirectoryEntries(settings.getBoolean(STORE_INCLUDE_DIRECTORY_ENTRIES));
282
			fJarPackage.setIncludeDirectoryEntries(settings.getBoolean(STORE_INCLUDE_DIRECTORY_ENTRIES));
341
			fJarPackage.setOverwrite(settings.getBoolean(STORE_OVERWRITE));
283
			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
		}
284
		}
349
	}
285
	}
350
286
Lines 365-380 Link Here
365
		fJarPackage.setExportJavaFiles(fExportJavaFilesCheckbox.getSelection());
301
		fJarPackage.setExportJavaFiles(fExportJavaFilesCheckbox.getSelection());
366
		fJarPackage.setElements(getSelectedElements());
302
		fJarPackage.setElements(getSelectedElements());
367
303
368
		// destination
304
		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
305
		// options
379
		if (fExportRefactoringsCheckbox != null)
306
		if (fExportRefactoringsCheckbox != null)
380
			fJarPackage.setRefactoringAware(fExportRefactoringsCheckbox.getSelection());
307
			fJarPackage.setRefactoringAware(fExportRefactoringsCheckbox.getSelection());
Lines 386-470 Link Here
386
	}
313
	}
387
314
388
	/**
315
	/**
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.
316
	 * Returns the resource for the specified path.
469
	 *
317
	 *
470
	 * @param path	the path for which the resource should be returned
318
	 * @param path	the path for which the resource should be returned
Lines 655-675 Link Here
655
			setErrorMessage(null);
503
			setErrorMessage(null);
656
		return complete;
504
		return complete;
657
	}
505
	}
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
	
506
	
674
	protected void updatePageCompletion() {
507
	protected void updatePageCompletion() {
675
		boolean pageComplete= isPageComplete();
508
		boolean pageComplete= isPageComplete();
Lines 691-741 Link Here
691
	/*
524
	/*
692
	 * Overrides method from WizardDataTransferPage
525
	 * Overrides method from WizardDataTransferPage
693
	 */
526
	 */
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() {
527
	protected boolean validateOptionsGroup() {
740
		return true;
528
		return true;
741
	}
529
	}
Lines 799-811 Link Here
799
			return null;
587
			return null;
800
	}
588
	}
801
589
802
	/**
803
	 * Set the current input focus to self's destination entry field
804
 	 */
805
	protected void giveFocusToDestination() {
806
		fDestinationNamesCombo.setFocus();
807
	}
808
809
	/* 
590
	/* 
810
	 * Overrides method from WizardExportResourcePage
591
	 * Overrides method from WizardExportResourcePage
811
	 */
592
	 */
Lines 849-861 Link Here
849
	}
630
	}
850
631
851
	/* 
632
	/* 
852
	 * Implements method from IJarPackageWizardPage.
853
	 */
854
	public void finish() {
855
		saveWidgetValues();
856
	}
857
858
	/* 
859
	 * Method declared on IWizardPage.
633
	 * Method declared on IWizardPage.
860
	 */
634
	 */
861
	public void setPreviousPage(IWizardPage page) {
635
	public void setPreviousPage(IWizardPage page) {
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerUtil.java (-6 / +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 7-32 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackager;
12
package org.eclipse.jdt.internal.ui.jarpackager;
12
13
13
import java.io.File;
14
import java.io.File;
14
import java.io.IOException;
15
import java.io.IOException;
15
import java.io.InputStream;
16
import java.io.InputStream;
17
import java.net.URI;
16
import java.util.ArrayList;
18
import java.util.ArrayList;
17
import java.util.Arrays;
19
import java.util.Arrays;
18
import java.util.Iterator;
20
import java.util.Iterator;
19
import java.util.List;
21
import java.util.List;
20
import java.util.jar.JarEntry;
22
import java.util.jar.JarEntry;
21
import java.util.zip.CRC32;
23
import java.util.zip.CRC32;
24
import java.util.zip.ZipException;
25
import java.util.zip.ZipFile;
26
27
import org.eclipse.core.filesystem.EFS;
28
import org.eclipse.core.filesystem.IFileStore;
22
29
23
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.IStatus;
32
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.Status;
33
import org.eclipse.core.runtime.Status;
26
34
27
import org.eclipse.core.resources.IContainer;
35
import org.eclipse.core.resources.IContainer;
28
import org.eclipse.core.resources.IFile;
36
import org.eclipse.core.resources.IFile;
29
import org.eclipse.core.resources.IResource;
37
import org.eclipse.core.resources.IResource;
38
import org.eclipse.core.resources.ResourcesPlugin;
30
39
31
import org.eclipse.swt.widgets.Display;
40
import org.eclipse.swt.widgets.Display;
32
import org.eclipse.swt.widgets.Shell;
41
import org.eclipse.swt.widgets.Shell;
Lines 107-120 Link Here
107
	 * Computes and returns the elements as resources.
116
	 * Computes and returns the elements as resources.
108
	 * The underlying resource is used for Java elements.
117
	 * The underlying resource is used for Java elements.
109
	 * 
118
	 * 
119
	 * @param elements elements for which to retrieve the resources from
110
	 * @return a List with the selected resources
120
	 * @return a List with the selected resources
111
	 */
121
	 */
112
	public static List asResources(Object[] fSelectedElements) {
122
	public static List asResources(Object[] elements) {
113
		if (fSelectedElements == null)
123
		if (elements == null)
114
			return null;
124
			return null;
115
		List selectedResources= new ArrayList(fSelectedElements.length);
125
		List selectedResources= new ArrayList(elements.length);
116
		for (int i= 0; i < fSelectedElements.length; i++) {
126
		for (int i= 0; i < elements.length; i++) {
117
			Object element= fSelectedElements[i];
127
			Object element= elements[i];
118
			if (element instanceof IJavaElement) {
128
			if (element instanceof IJavaElement) {
119
				selectedResources.add(((IJavaElement)element).getResource());
129
				selectedResources.add(((IJavaElement)element).getResource());
120
			}
130
			}
Lines 133-138 Link Here
133
	/**
143
	/**
134
	 * Gets the name of the manifest's main class
144
	 * Gets the name of the manifest's main class
135
	 * 
145
	 * 
146
	 * @param jarPackage 
136
	 * @return a string with the name
147
	 * @return a string with the name
137
	 */
148
	 */
138
	static String getMainClassName(JarPackageData jarPackage) {
149
	static String getMainClassName(JarPackageData jarPackage) {
Lines 173-178 Link Here
173
	/**
184
	/**
174
	 * Tells whether the specified manifest main class is valid.
185
	 * Tells whether the specified manifest main class is valid.
175
	 * 
186
	 * 
187
	 * @param data 
188
	 * @param context 
176
	 * @return <code>true</code> if a main class is specified and valid
189
	 * @return <code>true</code> if a main class is specified and valid
177
	 */
190
	 */
178
	public static boolean isMainClassValid(JarPackageData data, IRunnableContext context) {
191
	public static boolean isMainClassValid(JarPackageData data, IRunnableContext context) {
Lines 257-260 Link Here
257
		entry.setSize(size);
270
		entry.setSize(size);
258
		entry.setCrc(crc.getValue());
271
		entry.setCrc(crc.getValue());
259
	}
272
	}
273
	
274
	/**
275
	 * The archive file at the given location
276
	 * 
277
	 * @param location
278
	 *        the location of the archive file
279
	 * @return the archive or null if it could not be retrieved
280
	 * @throws CoreException
281
	 *         if the archive could not be read
282
	 * 
283
	 * @since 3.4
284
	 */
285
	public static ZipFile getArchiveFile(IPath location) throws CoreException {
286
		File localFile= null;
287
288
		IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(location);
289
		if (file != null) {
290
			// internal resource
291
			URI fileLocation= file.getLocationURI();
292
293
			IFileStore fileStore= EFS.getStore(fileLocation);
294
			localFile= fileStore.toLocalFile(EFS.NONE, null);
295
			if (localFile == null)
296
				// non local file system
297
				localFile= fileStore.toLocalFile(EFS.CACHE, null);
298
		} else {
299
			// external resource -> it is ok to use toFile()
300
			localFile= location.toFile();
301
		}
302
303
		if (localFile == null)
304
			return null;
305
306
		try {
307
			return new ZipFile(localFile);
308
		} catch (ZipException e) {
309
			throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, e.getLocalizedMessage(), e));
310
		} catch (IOException e) {
311
			throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, e.getLocalizedMessage(), e));
312
		}
313
	}
260
}
314
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.java (-38 / +7 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackager;
12
package org.eclipse.jdt.internal.ui.jarpackager;
12
13
Lines 32-37 Link Here
32
33
33
	public static String JarFileExportOperation_creationOfSomeJARsFailed;
34
	public static String JarFileExportOperation_creationOfSomeJARsFailed;
34
35
36
	public static String JarFileExportOperation_OpenZipFileError_message;
37
35
	public static String JarFileExportOperation_didNotAddManifestToJar;
38
	public static String JarFileExportOperation_didNotAddManifestToJar;
36
39
37
	public static String JarFileExportOperation_errorCannotCloseConnection;
40
	public static String JarFileExportOperation_errorCannotCloseConnection;
Lines 48-54 Link Here
48
51
49
	public static String JarFileExportOperation_errorSavingManifest;
52
	public static String JarFileExportOperation_errorSavingManifest;
50
53
51
	public static String JarFileExportOperation_errorSavingModifiedResources;
54
	public static String JarFileExportOperation_CloseZipFileError_message;
52
55
53
	public static String JarFileExportOperation_exportedWithCompileErrors;
56
	public static String JarFileExportOperation_exportedWithCompileErrors;
54
57
Lines 94-103 Link Here
94
97
95
	public static String JarFileExportOperation_savingFiles;
98
	public static String JarFileExportOperation_savingFiles;
96
99
97
	public static String JarFileExportOperation_savingModifiedResources;
98
99
	public static String JarFileExportOperation_underlyingResourceNotFound;
100
101
	public static String JarManifestWizardPage_description;
100
	public static String JarManifestWizardPage_description;
102
101
103
	public static String JarManifestWizardPage_error_invalidMainClass;
102
	public static String JarManifestWizardPage_error_invalidMainClass;
Lines 248-253 Link Here
248
247
249
	public static String JarPackageReader_error_tagPathNotFound;
248
	public static String JarPackageReader_error_tagPathNotFound;
250
249
250
	public static String JarPackageReader_error_unknownJarBuilder;
251
251
	public static String JarPackageReader_jarPackageReaderWarnings;
252
	public static String JarPackageReader_jarPackageReaderWarnings;
252
253
253
	public static String JarPackageReader_warning_javaElementDoesNotExist;
254
	public static String JarPackageReader_warning_javaElementDoesNotExist;
Lines 320-357 Link Here
320
321
321
	public static String JarWriter_error_couldNotTransformToXML;
322
	public static String JarWriter_error_couldNotTransformToXML;
322
323
323
	public static String JarWriter_output_compressed;
324
325
	public static String JarWriter_output_descriptionFile;
326
327
	public static String JarWriter_output_exportBin;
328
329
	public static String JarWriter_output_exportJava;
330
331
	public static String JarWriter_output_exportOutputFolders;
332
333
	public static String JarWriter_output_generateManifest;
334
335
	public static String JarWriter_output_jarFileName;
336
337
	public static String JarWriter_output_jarSealed;
338
339
	public static String JarWriter_output_lineSeparator;
340
341
	public static String JarWriter_output_mainClass;
342
343
	public static String JarWriter_output_manifestName;
344
345
	public static String JarWriter_output_overwrite;
346
347
	public static String JarWriter_output_reuseManifest;
348
349
	public static String JarWriter_output_saveDescription;
350
351
	public static String JarWriter_output_saveManifest;
352
353
	public static String JarWriter_output_title;
354
355
	public static String JarWriter_writeProblem;
324
	public static String JarWriter_writeProblem;
356
325
357
	public static String JarWriter_writeProblemWithMessage;
326
	public static String JarWriter_writeProblemWithMessage;
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarFileExportOperation.java (-13 / +47 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Matt Chapman, mpchapman@gmail.com - 89977 Make JDT .java agnostic
10
 *     Matt Chapman, mpchapman@gmail.com - 89977 Make JDT .java agnostic
11
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.jarpackager;
13
package org.eclipse.jdt.internal.ui.jarpackager;
13
14
Lines 29-36 Link Here
29
import java.util.Set;
30
import java.util.Set;
30
import java.util.jar.Manifest;
31
import java.util.jar.Manifest;
31
import java.util.zip.ZipException;
32
import java.util.zip.ZipException;
33
import java.util.zip.ZipFile;
32
34
33
import org.eclipse.core.filesystem.EFS;
35
import org.eclipse.core.filesystem.EFS;
36
34
import org.eclipse.core.runtime.CoreException;
37
import org.eclipse.core.runtime.CoreException;
35
import org.eclipse.core.runtime.IPath;
38
import org.eclipse.core.runtime.IPath;
36
import org.eclipse.core.runtime.IProgressMonitor;
39
import org.eclipse.core.runtime.IProgressMonitor;
Lines 73-82 Link Here
73
import org.eclipse.jdt.internal.corext.util.Resources;
76
import org.eclipse.jdt.internal.corext.util.Resources;
74
77
75
import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
78
import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
79
import org.eclipse.jdt.ui.jarpackager.IJarBuilder;
76
import org.eclipse.jdt.ui.jarpackager.IJarDescriptionWriter;
80
import org.eclipse.jdt.ui.jarpackager.IJarDescriptionWriter;
77
import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable;
81
import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable;
78
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
82
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
79
import org.eclipse.jdt.ui.jarpackager.JarWriter3;
80
83
81
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
84
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
82
import org.eclipse.jdt.internal.ui.JavaPlugin;
85
import org.eclipse.jdt.internal.ui.JavaPlugin;
Lines 100-106 Link Here
100
		}
103
		}
101
	}
104
	}
102
105
103
	private JarWriter3 fJarWriter;
106
	private IJarBuilder fJarBuilder;
104
	private JarPackageData fJarPackage;
107
	private JarPackageData fJarPackage;
105
	private JarPackageData[] fJarPackages;
108
	private JarPackageData[] fJarPackages;
106
	private Shell fParentShell;
109
	private Shell fParentShell;
Lines 206-214 Link Here
206
					continue;
209
					continue;
207
				}
210
				}
208
				
211
				
209
				// Should not happen since we only export source files
212
				if (resource == null) {
210
				if (resource == null)
213
					if (element instanceof IPackageFragmentRoot) {
214
						IPackageFragmentRoot root= (IPackageFragmentRoot) element;
215
						if (root.isArchive()) {
216
							try {
217
								ZipFile file= JarPackagerUtil.getArchiveFile(root.getPath());
218
								if (file != null)
219
									count+= file.size();
220
							} catch (CoreException e) {
221
								JavaPlugin.log(e);
222
							}
223
						}
224
					}
211
					continue;
225
					continue;
226
				}
212
			}
227
			}
213
			else
228
			else
214
				resource= (IResource)element;
229
				resource= (IResource)element;
Lines 340-347 Link Here
340
	}
355
	}
341
356
342
	private void exportJavaElement(IProgressMonitor progressMonitor, IJavaElement je) throws InterruptedException {
357
	private void exportJavaElement(IProgressMonitor progressMonitor, IJavaElement je) throws InterruptedException {
343
		if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && ((IPackageFragmentRoot)je).isArchive())
358
		if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && ((IPackageFragmentRoot) je).isArchive()) {
359
			IPackageFragmentRoot root= (IPackageFragmentRoot) je;
360
			ZipFile jarFile= null;
361
			try {
362
				jarFile= JarPackagerUtil.getArchiveFile(root.getPath());
363
				fJarBuilder.writeArchive(jarFile, progressMonitor);
364
			} catch (CoreException e) {
365
				addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_OpenZipFileError_message, new Object[] { root.getElementName(), e.getLocalizedMessage() }), e);
366
			} finally {
367
				try {
368
					if (jarFile != null) {
369
						jarFile.close();
370
					}
371
				} catch (IOException e) {
372
					addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_CloseZipFileError_message, new Object[] { root.getElementName(), e.getLocalizedMessage() }), e);
373
				}
374
			}
344
			return;
375
			return;
376
		}
345
377
346
		Object[] children= fJavaElementContentProvider.getChildren(je);
378
		Object[] children= fJavaElementContentProvider.getChildren(je);
347
		for (int i= 0; i < children.length; i++)
379
		for (int i= 0; i < children.length; i++)
Lines 365-371 Link Here
365
			try {
397
			try {
366
				IPath destinationPath= resource.getFullPath().removeFirstSegments(leadingSegmentsToRemove);
398
				IPath destinationPath= resource.getFullPath().removeFirstSegments(leadingSegmentsToRemove);
367
				progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); 
399
				progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); 
368
				fJarWriter.write((IFile)resource, destinationPath);
400
				fJarBuilder.writeFile((IFile)resource, destinationPath);
369
			} catch (CoreException ex) {
401
			} catch (CoreException ex) {
370
				Throwable realEx= ex.getStatus().getException();
402
				Throwable realEx= ex.getStatus().getException();
371
				if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$
403
				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())))) {
460
			|| (fJarPackage.areJavaFilesExported() && (isNonJavaResource || (pkgRoot != null && !isClassFile(resource)) || (isInClassFolder && isClassFile(resource) && !fJarPackage.areClassFilesExported())))) {
429
			try {
461
			try {
430
				progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); 
462
				progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, destinationPath.toString())); 
431
				fJarWriter.write((IFile) resource, destinationPath);
463
				fJarBuilder.writeFile((IFile)resource, destinationPath);
432
			} catch (CoreException ex) {
464
			} catch (CoreException ex) {
433
				Throwable realEx= ex.getStatus().getException();
465
				Throwable realEx= ex.getStatus().getException();
434
				if (realEx instanceof ZipException && realEx.getMessage() != null && realEx.getMessage().startsWith("duplicate entry:")) //$NON-NLS-1$
466
				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();
494
					IFile file= (IFile)iter.next();
463
					IPath classFilePath= baseDestinationPath.append(file.getName());
495
					IPath classFilePath= baseDestinationPath.append(file.getName());
464
					progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, classFilePath.toString())); 
496
					progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, classFilePath.toString())); 
465
					fJarWriter.write(file, classFilePath);
497
					fJarBuilder.writeFile(file, classFilePath);
466
				}
498
				}
467
			} catch (CoreException ex) {
499
			} catch (CoreException ex) {
468
				addToStatus(ex);
500
				addToStatus(ex);
Lines 798-804 Link Here
798
		return fStatus;
830
		return fStatus;
799
	}
831
	}
800
832
801
	private boolean canBeExported(boolean hasErrors, boolean hasWarnings) throws CoreException {
833
	private boolean canBeExported(boolean hasErrors, boolean hasWarnings) {
802
		return (!hasErrors && !hasWarnings)
834
		return (!hasErrors && !hasWarnings)
803
			|| (hasErrors && fJarPackage.areErrorsExported())
835
			|| (hasErrors && fJarPackage.areErrorsExported())
804
			|| (hasWarnings && fJarPackage.exportWarnings());
836
			|| (hasWarnings && fJarPackage.exportWarnings());
Lines 857-864 Link Here
857
				buildProjects(subProgressMonitor);
889
				buildProjects(subProgressMonitor);
858
			} else
890
			} else
859
				progressMonitor.beginTask("", totalWork); //$NON-NLS-1$
891
				progressMonitor.beginTask("", totalWork); //$NON-NLS-1$
860
						
892
			
861
			fJarWriter= fJarPackage.createJarWriter3(fParentShell);
893
			fJarBuilder = fJarPackage.getJarBuilder();
894
			fJarBuilder.open(fJarPackage, fParentShell, fStatus);
895
			
862
			exportSelectedElements(progressMonitor);
896
			exportSelectedElements(progressMonitor);
863
			if (getStatus().getSeverity() != IStatus.ERROR) {
897
			if (getStatus().getSeverity() != IStatus.ERROR) {
864
				progressMonitor.subTask(JarPackagerMessages.JarFileExportOperation_savingFiles); 
898
				progressMonitor.subTask(JarPackagerMessages.JarFileExportOperation_savingFiles); 
Lines 868-875 Link Here
868
			addToStatus(ex);
902
			addToStatus(ex);
869
		} finally {
903
		} finally {
870
			try {
904
			try {
871
				if (fJarWriter != null)
905
				if (fJarBuilder != null)
872
					fJarWriter.close();
906
					fJarBuilder.close();
873
			} catch (CoreException ex) {
907
			} catch (CoreException ex) {
874
				addToStatus(ex);
908
				addToStatus(ex);
875
			}
909
			}
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackagerMessages.properties (-20 / +5 lines)
Lines 7-12 Link Here
7
#
7
#
8
# Contributors:
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
#     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
###############################################################################
11
###############################################################################
11
12
12
CreateJarActionDelegate_jarExportError_title= JAR Export Error
13
CreateJarActionDelegate_jarExportError_title= JAR Export Error
Lines 34-42 Link Here
34
JarFileExportOperation_exportFinishedWithInfo= JAR export finished. See details for additional information.
35
JarFileExportOperation_exportFinishedWithInfo= JAR export finished. See details for additional information.
35
JarFileExportOperation_exportFinishedWithWarnings= JAR export finished with warnings. See details for additional information.
36
JarFileExportOperation_exportFinishedWithWarnings= JAR export finished with warnings. See details for additional information.
36
JarFileExportOperation_creationOfSomeJARsFailed= Creation of some JARs failed. See details for additional information.
37
JarFileExportOperation_creationOfSomeJARsFailed= Creation of some JARs failed. See details for additional information.
38
JarFileExportOperation_OpenZipFileError_message=Could not read jar file ''{0}''. Reason: {1}
37
JarFileExportOperation_jarCreationFailed= JAR creation failed. See details for additional information.
39
JarFileExportOperation_jarCreationFailed= JAR creation failed. See details for additional information.
38
40
39
JarFileExportOperation_underlyingResourceNotFound= Underlying resource not found for compilation unit: {0}
40
JarFileExportOperation_resourceNotFound= Resource not found or not accessible: {0}
41
JarFileExportOperation_resourceNotFound= Resource not found or not accessible: {0}
41
JarFileExportOperation_projectNatureNotDeterminable= Project nature could not be determined for: {0}
42
JarFileExportOperation_projectNatureNotDeterminable= Project nature could not be determined for: {0}
42
JarFileExportOperation_javaPackageNotDeterminable= Java package could not be found for: {0}
43
JarFileExportOperation_javaPackageNotDeterminable= Java package could not be found for: {0}
Lines 45-50 Link Here
45
JarFileExportOperation_outputContainerNotAccessible= Output container not accessible
46
JarFileExportOperation_outputContainerNotAccessible= Output container not accessible
46
JarFileExportOperation_classFileOnClasspathNotAccessible= class file(s) on classpath not found or not accessible {0}
47
JarFileExportOperation_classFileOnClasspathNotAccessible= class file(s) on classpath not found or not accessible {0}
47
JarFileExportOperation_classFileWithoutSourceFileAttribute= Could not find source file attribute for: {0}
48
JarFileExportOperation_classFileWithoutSourceFileAttribute= Could not find source file attribute for: {0}
49
JarFileExportOperation_CloseZipFileError_message=Could not close jar file ''{0}''. Reason: {1}
48
JarFileExportOperation_missingSourceFileAttributeExportedAll= Source name not found in a class file - exported all class files in {0}
50
JarFileExportOperation_missingSourceFileAttributeExportedAll= Source name not found in a class file - exported all class files in {0}
49
JarFileExportOperation_exportedWithCompileErrors= Exported with compile errors: {0}
51
JarFileExportOperation_exportedWithCompileErrors= Exported with compile errors: {0}
50
JarFileExportOperation_exportedWithCompileWarnings= Exported with compile warnings: {0}
52
JarFileExportOperation_exportedWithCompileWarnings= Exported with compile warnings: {0}
Lines 53-59 Link Here
53
JarFileExportOperation_exporting= Exporting: {0}
55
JarFileExportOperation_exporting= Exporting: {0}
54
JarFileExportOperation_jarCreationFailedSeeDetails= JAR creation failed. See details for additional information.
56
JarFileExportOperation_jarCreationFailedSeeDetails= JAR creation failed. See details for additional information.
55
JarFileExportOperation_savingFiles= Saving files...
57
JarFileExportOperation_savingFiles= Saving files...
56
JarFileExportOperation_savingModifiedResources= Saving modified resources...
57
JarFileExportOperation_noExportTypeChosen= No export type chosen
58
JarFileExportOperation_noExportTypeChosen= No export type chosen
58
JarFileExportOperation_noResourcesSelected= No resources selected
59
JarFileExportOperation_noResourcesSelected= No resources selected
59
JarFileExportOperation_invalidJarLocation= Invalid JAR location
60
JarFileExportOperation_invalidJarLocation= Invalid JAR location
Lines 68-74 Link Here
68
JarFileExportOperation_errorReadingFile= Error reading {0}: {1}
69
JarFileExportOperation_errorReadingFile= Error reading {0}: {1}
69
JarFileExportOperation_errorClosingJarPackageDescriptionReader= Error closing JAR package description reader for {0}
70
JarFileExportOperation_errorClosingJarPackageDescriptionReader= Error closing JAR package description reader for {0}
70
JarFileExportOperation_errorDuringProjectBuild= Build failed for project: {0}
71
JarFileExportOperation_errorDuringProjectBuild= Build failed for project: {0}
71
JarFileExportOperation_errorSavingModifiedResources= Unexpected exception while saving modified resources. See log for details.
72
JarFileExportOperation_errorCannotCloseConnection=Cannot close connection for ''{0}''
72
JarFileExportOperation_errorCannotCloseConnection=Cannot close connection for ''{0}''
73
73
74
JarOptionsPage_title= JAR Packaging Options
74
JarOptionsPage_title= JAR Packaging Options
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.
Lines 179-198 Link Here
179
JarRefactoringDialog_dialog_title=Refactoring Selection
180
JarRefactoringDialog_dialog_title=Refactoring Selection
180
181
181
JarWriter_error_couldNotGetXmlBuilder = Could not get XML builder
182
JarWriter_error_couldNotGetXmlBuilder = Could not get XML builder
182
JarWriter_error_couldNotTransformToXML= Could not transform to XML
183
JarWriter_error_couldNotTransformToXML= Could not transform to XML
183
JarWriter_output_title= --- JAR Package Definition: ---
184
JarWriter_output_exportBin= Export class files: {0}
185
JarWriter_output_exportOutputFolders= Export output folders: {0}
186
JarWriter_output_exportJava= Export java files: {0}
187
JarWriter_output_jarFileName= JAR file: {0}
188
JarWriter_output_compressed= Compressed: {0}
189
JarWriter_output_overwrite= Overwrite: {0}
190
JarWriter_output_saveDescription= Save description: {0}
191
JarWriter_output_descriptionFile= Description file: {0}
192
JarWriter_output_lineSeparator= --
193
JarWriter_output_generateManifest= Generate manifest {0}
194
JarWriter_output_saveManifest= Save manifest: {0}
195
JarWriter_output_reuseManifest= Reuse manifest: {0}
196
JarWriter_output_manifestName= Manifest {0}
197
JarWriter_output_jarSealed= JAR sealed: {0}
198
JarWriter_output_mainClass= Main-Class: {0}
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageReader.java (-13 / +37 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackager;
12
package org.eclipse.jdt.internal.ui.jarpackager;
12
13
Lines 23-33 Link Here
23
import javax.xml.parsers.DocumentBuilderFactory;
24
import javax.xml.parsers.DocumentBuilderFactory;
24
import javax.xml.parsers.ParserConfigurationException;
25
import javax.xml.parsers.ParserConfigurationException;
25
26
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;
27
import org.eclipse.core.runtime.Assert;
32
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.IPath;
Lines 36-41 Link Here
36
import org.eclipse.core.runtime.Path;
32
import org.eclipse.core.runtime.Path;
37
import org.eclipse.core.runtime.Status;
33
import org.eclipse.core.runtime.Status;
38
34
35
import org.eclipse.core.resources.IFile;
36
import org.eclipse.core.resources.IFolder;
37
import org.eclipse.core.resources.IProject;
38
import org.eclipse.core.resources.ResourcesPlugin;
39
39
40
import org.eclipse.ltk.core.refactoring.RefactoringCore;
40
import org.eclipse.ltk.core.refactoring.RefactoringCore;
41
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
41
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
Lines 43-54 Link Here
43
import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService;
43
import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService;
44
import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
44
import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
45
45
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;
46
import org.eclipse.jdt.core.IJavaElement;
53
import org.eclipse.jdt.core.IPackageFragment;
47
import org.eclipse.jdt.core.IPackageFragment;
54
import org.eclipse.jdt.core.IType;
48
import org.eclipse.jdt.core.IType;
Lines 56-66 Link Here
56
50
57
import org.eclipse.jdt.internal.corext.util.Messages;
51
import org.eclipse.jdt.internal.corext.util.Messages;
58
52
53
import org.eclipse.jdt.ui.jarpackager.IJarBuilder;
59
import org.eclipse.jdt.ui.jarpackager.IJarDescriptionReader;
54
import org.eclipse.jdt.ui.jarpackager.IJarDescriptionReader;
60
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
55
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
61
56
62
import org.eclipse.jdt.internal.ui.JavaPlugin;
63
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
57
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
58
import org.eclipse.jdt.internal.ui.JavaPlugin;
59
import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarBuilder;
60
61
import org.w3c.dom.Element;
62
import org.w3c.dom.Node;
63
import org.w3c.dom.NodeList;
64
import org.xml.sax.InputSource;
65
import org.xml.sax.SAXException;
64
66
65
/**
67
/**
66
 * Reads data from an InputStream and returns a JarPackage
68
 * Reads data from an InputStream and returns a JarPackage
Lines 74-79 Link Here
74
	/**
76
	/**
75
	 * Reads a Jar Package from the underlying stream.
77
	 * Reads a Jar Package from the underlying stream.
76
	 * It is the client's responsibility to close the stream.
78
	 * It is the client's responsibility to close the stream.
79
	 * @param inputStream 
77
	 */
80
	 */
78
	public JarPackageReader(InputStream inputStream) {
81
	public JarPackageReader(InputStream inputStream) {
79
		Assert.isNotNull(inputStream);
82
		Assert.isNotNull(inputStream);
Lines 139-144 Link Here
139
			if (jarPackage.areGeneratedFilesExported())
142
			if (jarPackage.areGeneratedFilesExported())
140
				xmlReadManifest(jarPackage, element);
143
				xmlReadManifest(jarPackage, element);
141
			xmlReadSelectedElements(jarPackage, element);
144
			xmlReadSelectedElements(jarPackage, element);
145
			
146
			// fatjar read builder props
147
			xmlReadFatjar(jarPackage, element);
142
		}
148
		}
143
		return jarPackage;
149
		return jarPackage;
144
	}
150
	}
Lines 403-406 Link Here
403
	protected void addWarning(String message, Throwable error) {
409
	protected void addWarning(String message, Throwable error) {
404
		fWarnings.add(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), 0, message, error));
410
		fWarnings.add(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), 0, message, error));
405
	}
411
	}
412
413
	private void xmlReadFatjar(JarPackageData jarPackage, Element element) throws java.io.IOException {
414
		if (element.getNodeName().equals("fatjar")) { //$NON-NLS-1$
415
			String id = element.getAttribute("builder"); //$NON-NLS-1$
416
			IJarBuilder builder= jarPackage.getJarBuilder();
417
			if (builder == null || !builder.getId().equals(id)) {
418
				if (FatJarBuilder.BUILDER_ID.equals(id)) {
419
					jarPackage.setJarBuilder(jarPackage.createFatJarBuilder());
420
				} else if (PlainJarBuilder.BUILDER_ID.equals(id)) {
421
					jarPackage.setJarBuilder(jarPackage.createPlainJarBuilder());
422
				} else {
423
					throw new IOException(Messages.format(JarPackagerMessages.JarPackageReader_error_unknownJarBuilder, id));
424
				}
425
			}
426
			jarPackage.setLaunchConfigurationName(element.getAttribute("launchConfig")); //$NON-NLS-1$
427
		}
428
	}
429
406
}
430
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWriter.java (-2 / +15 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.jarpackager;
12
package org.eclipse.jdt.internal.ui.jarpackager;
12
13
Lines 34-40 Link Here
34
import org.eclipse.core.resources.IProject;
35
import org.eclipse.core.resources.IProject;
35
import org.eclipse.core.resources.IResource;
36
import org.eclipse.core.resources.IResource;
36
37
37
38
import org.eclipse.ltk.core.refactoring.RefactoringCore;
38
import org.eclipse.ltk.core.refactoring.RefactoringCore;
39
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
39
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
40
import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
40
import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
Lines 64-69 Link Here
64
	/**
64
	/**
65
	 * Create a JarPackageWriter on the given output stream.
65
	 * Create a JarPackageWriter on the given output stream.
66
	 * It is the clients responsibility to close the output stream.
66
	 * It is the clients responsibility to close the output stream.
67
	 * 
68
	 * @param outputStream 
69
	 * @param encoding 
67
	 */
70
	 */
68
	public JarPackageWriter(OutputStream outputStream, String encoding) {
71
	public JarPackageWriter(OutputStream outputStream, String encoding) {
69
		Assert.isNotNull(outputStream);
72
		Assert.isNotNull(outputStream);
Lines 84-89 Link Here
84
	 * Writes a XML representation of the JAR specification
87
	 * Writes a XML representation of the JAR specification
85
	 * to to the underlying stream.
88
	 * to to the underlying stream.
86
	 * 
89
	 * 
90
	 * @param jarPackage 
87
	 * @exception IOException	if writing to the underlying stream fails
91
	 * @exception IOException	if writing to the underlying stream fails
88
	 */
92
	 */
89
	public void writeXML(JarPackageData jarPackage) throws IOException {
93
	public void writeXML(JarPackageData jarPackage) throws IOException {
Lines 109-114 Link Here
109
			xmlWriteManifest(jarPackage, document, xmlJarDesc);
113
			xmlWriteManifest(jarPackage, document, xmlJarDesc);
110
		xmlWriteSelectedElements(jarPackage, document, xmlJarDesc);
114
		xmlWriteSelectedElements(jarPackage, document, xmlJarDesc);
111
115
116
		xmlWriteFatjar(jarPackage, document, xmlJarDesc);
117
112
		try {
118
		try {
113
			// Write the document to the stream
119
			// Write the document to the stream
114
			Transformer transformer=TransformerFactory.newInstance().newTransformer();
120
			Transformer transformer=TransformerFactory.newInstance().newTransformer();
Lines 285-288 Link Here
285
	public IStatus getStatus() {
291
	public IStatus getStatus() {
286
		return new Status(IStatus.OK, JavaPlugin.getPluginId(), 0, "", null); //$NON-NLS-1$
292
		return new Status(IStatus.OK, JavaPlugin.getPluginId(), 0, "", null); //$NON-NLS-1$
287
	}
293
	}
294
		
295
	private void xmlWriteFatjar(JarPackageData jarPackage, Document document, Element xmlJarDesc) throws DOMException {
296
		Element fatjar= document.createElement("fatjar"); //$NON-NLS-1$
297
		xmlJarDesc.appendChild(fatjar);
298
		fatjar.setAttribute("builder", jarPackage.getJarBuilder().getId()); //$NON-NLS-1$
299
		fatjar.setAttribute("launchConfig", jarPackage.getLaunchConfigurationName()); //$NON-NLS-1$
300
	}
288
}
301
}
(-)ui/org/eclipse/jdt/internal/ui/JavaPluginImages.java (+2 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui;
12
package org.eclipse.jdt.internal.ui;
12
13
Lines 394-399 Link Here
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_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$
396
	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$
397
	public static final ImageDescriptor DESC_WIZBAN_JAR_PACKAGER= createUnManaged(T_WIZBAN, "jar_pack_wiz.png"); 		//$NON-NLS-1$
398
	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$
399
	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$
400
	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$
401
	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 (-4 / +21 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.ui.jarpackager;
12
package org.eclipse.jdt.ui.jarpackager;
12
13
Lines 233-246 Link Here
233
234
234
		InputStream contentStream = resource.getContents(false);
235
		InputStream contentStream = resource.getContents(false);
235
236
237
		addEntry(newEntry, contentStream);
238
	}
239
240
	/**
241
	 * Write the given entry describing the given content to the
242
	 * current archive
243
	 * 
244
	 * @param   entry            the entry to write
245
	 * @param   content          the content to write
246
	 * 
247
	 * @throws IOException       If an I/O error occurred
248
	 * 
249
	 * @since 3.4
250
	 */
251
	protected void addEntry(JarEntry entry, InputStream content) throws IOException {
252
		byte[] readBuffer= new byte[4096];
236
		try {		
253
		try {		
237
			fJarOutputStream.putNextEntry(newEntry);
254
			fJarOutputStream.putNextEntry(entry);
238
			int count;
255
			int count;
239
			while ((count= contentStream.read(readBuffer, 0, readBuffer.length)) != -1)
256
			while ((count= content.read(readBuffer, 0, readBuffer.length)) != -1)
240
				fJarOutputStream.write(readBuffer, 0, count);
257
				fJarOutputStream.write(readBuffer, 0, count);
241
		} finally  {
258
		} finally  {
242
			if (contentStream != null)
259
			if (content != null)
243
				contentStream.close();
260
				content.close();
244
261
245
			/*
262
			/*
246
			 * Commented out because some JREs throw an NPE if a stream
263
			 * Commented out because some JREs throw an NPE if a stream
(-)ui/org/eclipse/jdt/ui/jarpackager/JarPackageData.java (-8 / +88 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 7-27 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.ui.jarpackager;
12
package org.eclipse.jdt.ui.jarpackager;
12
13
13
import java.io.InputStream;
14
import java.io.InputStream;
14
import java.io.OutputStream;
15
import java.io.OutputStream;
15
16
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;
17
import org.eclipse.core.runtime.Assert;
21
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.Path;
20
import org.eclipse.core.runtime.Path;
24
21
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.resources.ResourcesPlugin;
25
25
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.swt.widgets.Shell;
26
27
27
import org.eclipse.jface.operation.IRunnableContext;
28
import org.eclipse.jface.operation.IRunnableContext;
Lines 31-43 Link Here
31
import org.eclipse.jdt.core.IPackageFragment;
32
import org.eclipse.jdt.core.IPackageFragment;
32
import org.eclipse.jdt.core.IType;
33
import org.eclipse.jdt.core.IType;
33
34
34
35
import org.eclipse.jdt.internal.ui.JavaPlugin;
35
import org.eclipse.jdt.internal.ui.JavaPlugin;
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.PlainJarBuilder;
41
import org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarBuilder;
41
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
42
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
42
43
43
/**
44
/**
Lines 144-149 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 IJarBuilder 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
	 */
Lines 474-480 Link Here
474
	 */
481
	 */
475
	public IManifestProvider getManifestProvider() {
482
	public IManifestProvider getManifestProvider() {
476
		if (fManifestProvider == null)
483
		if (fManifestProvider == null)
477
			fManifestProvider= new ManifestProvider();
484
			return getJarBuilder().getManifestProvider();
478
		return fManifestProvider;
485
		return fManifestProvider;
479
	}
486
	}
480
	
487
	
Lines 876-887 Link Here
876
	 * @throws CoreException if an unexpected exception happens
883
	 * @throws CoreException if an unexpected exception happens
877
	 * 
884
	 * 
878
	 * @since 3.2
885
	 * @since 3.2
886
	 * @deprecated use {@link #createPlainJarBuilder()} instead
879
	 */
887
	 */
880
	public JarWriter3 createJarWriter3(Shell parent) throws CoreException {
888
	public JarWriter3 createJarWriter3(Shell parent) throws CoreException {
881
		return new JarWriter3(this, parent);
889
		return new JarWriter3(this, parent);
882
	}
890
	}
883
	
891
	
884
	/**
892
	/**
893
	 * Creates and returns a jar builder capable of handling
894
	 * files but not archives.
895
	 * 
896
	 * @return a new instance of a plain jar builder
897
	 * 
898
	 * @since 3.4
899
	 */
900
	public IJarBuilder createPlainJarBuilder() {
901
		return new PlainJarBuilder();
902
	}
903
904
	/**
905
	 * Creates and returns a jar builder capable of handling 
906
	 * files and archives.
907
	 * 
908
	 * @return a new instance of a fat jar builder
909
	 * 
910
	 * @since 3.4
911
	 */
912
	public IJarBuilder createFatJarBuilder() {
913
		return new FatJarBuilder();
914
	}
915
	
916
	/**
885
	 * Creates and returns a JarExportRunnable.
917
	 * Creates and returns a JarExportRunnable.
886
	 *
918
	 *
887
	 * @param	parent	the parent for the dialog,
919
	 * @param	parent	the parent for the dialog,
Lines 1162-1165 Link Here
1162
	public void setExportStructuralOnly(boolean structural) {
1194
	public void setExportStructuralOnly(boolean structural) {
1163
		fRefactoringStructural= structural;
1195
		fRefactoringStructural= structural;
1164
	}
1196
	}
1197
	
1198
	/**
1199
	 * Returns the jar builder which can be used to build the jar 
1200
	 * described by this package data.
1201
	 * 
1202
	 * @return the builder to use
1203
	 * @since 3.4
1204
	 */
1205
	public IJarBuilder getJarBuilder() {
1206
		if (fJarBuilder == null)
1207
			fJarBuilder= createPlainJarBuilder();
1208
		return fJarBuilder;
1209
	}
1210
1211
	/**
1212
	 * Set the jar builder to use to build the jar.
1213
	 * 
1214
	 * @param jarBuilder
1215
	 *        the builder to use
1216
	 * @since 3.4
1217
	 */
1218
	public void setJarBuilder(IJarBuilder jarBuilder) {
1219
		fJarBuilder= jarBuilder;
1220
	}
1221
1222
	/**
1223
	 * Get the name of the launch configuration from 
1224
	 * which to retrieve classpath information.
1225
	 * 
1226
	 * @return the name of the launch configuration
1227
	 * @since 3.4
1228
	 */
1229
	public String getLaunchConfigurationName() {
1230
		return fLaunchConfigurationName;
1231
	}
1232
1233
	/**
1234
	 * Set the name of the launch configuration form which 
1235
	 * to retrieve classpath information.
1236
	 * 
1237
	 * @param name
1238
	 *        name of the launch configuration
1239
	 * @since 3.4
1240
	 */
1241
	public void setLaunchConfigurationName(String name) {
1242
		fLaunchConfigurationName= name;
1243
	}
1244
1165
}
1245
}
(-)META-INF/MANIFEST.MF (+1 lines)
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,
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizardPage.java (+524 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.jarpackagerfat;
13
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.ArrayList;
16
import java.util.Arrays;
17
import java.util.HashSet;
18
import java.util.Iterator;
19
import java.util.List;
20
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.MultiStatus;
25
import org.eclipse.core.runtime.Path;
26
import org.eclipse.core.runtime.Status;
27
28
import org.eclipse.core.resources.IProject;
29
import org.eclipse.core.resources.IResource;
30
import org.eclipse.core.resources.ResourcesPlugin;
31
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.widgets.Combo;
36
import org.eclipse.swt.widgets.Composite;
37
import org.eclipse.swt.widgets.Label;
38
import org.eclipse.swt.widgets.Listener;
39
40
import org.eclipse.jface.dialogs.Dialog;
41
import org.eclipse.jface.dialogs.IDialogSettings;
42
import org.eclipse.jface.operation.IRunnableContext;
43
import org.eclipse.jface.viewers.IStructuredSelection;
44
45
import org.eclipse.debug.core.DebugPlugin;
46
import org.eclipse.debug.core.ILaunchConfiguration;
47
import org.eclipse.debug.core.ILaunchConfigurationType;
48
import org.eclipse.debug.core.ILaunchManager;
49
50
import org.eclipse.jdt.core.IClasspathEntry;
51
import org.eclipse.jdt.core.IJavaProject;
52
import org.eclipse.jdt.core.IPackageFragmentRoot;
53
import org.eclipse.jdt.core.IType;
54
import org.eclipse.jdt.core.JavaCore;
55
import org.eclipse.jdt.core.JavaModelException;
56
import org.eclipse.jdt.core.search.IJavaSearchScope;
57
58
import org.eclipse.jdt.internal.corext.util.Messages;
59
60
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
61
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
62
import org.eclipse.jdt.launching.JavaRuntime;
63
64
import org.eclipse.jdt.ui.JavaUI;
65
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
66
67
import org.eclipse.jdt.internal.ui.JavaPlugin;
68
import org.eclipse.jdt.internal.ui.jarpackager.AbstractJarDestinationWizardPage;
69
import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil;
70
import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
71
import org.eclipse.jdt.internal.ui.util.MainMethodSearchEngine;
72
73
/**
74
 * First page for the runnable jar export wizard
75
 * @since 3.4
76
 */
77
public class FatJarPackageWizardPage extends AbstractJarDestinationWizardPage implements Listener {
78
79
	private abstract static class LaunchConfigurationElement {
80
81
		public abstract ILaunchConfiguration getLaunchConfiguration();
82
83
		public abstract String getLaunchConfigurationName();
84
85
		public void dispose() {
86
			//do nothing
87
		}
88
	}
89
90
	private static class ExistingLaunchConfigurationElement extends LaunchConfigurationElement {
91
92
		private final ILaunchConfiguration fLaunchConfiguration;
93
		private final String fProjectName;
94
95
		public ExistingLaunchConfigurationElement(ILaunchConfiguration launchConfiguration, String projectName) {
96
			fLaunchConfiguration= launchConfiguration;
97
			fProjectName= projectName;
98
		}
99
100
		/**
101
		 * {@inheritDoc}
102
		 */
103
		public ILaunchConfiguration getLaunchConfiguration() {
104
			return fLaunchConfiguration;
105
		}
106
107
		/**
108
		 * {@inheritDoc}
109
		 */
110
		public String getLaunchConfigurationName() {
111
			StringBuffer result= new StringBuffer();
112
			
113
			result.append(fLaunchConfiguration.getName());
114
			result.append(" - "); //$NON-NLS-1$
115
			result.append(fProjectName);
116
			
117
			return result.toString();
118
		}
119
120
	}
121
122
	private static final String PAGE_NAME= "FatJarPackageWizardPage"; //$NON-NLS-1$
123
	private static final String STORE_LAUNCH_CONFIGURATION_SELECTION_NAME= PAGE_NAME + ".LAUNCH_CONFIGURATION_SELECTION_NAME"; //$NON-NLS-1$
124
	private static final String STORE_DESTINATION_ELEMENT= PAGE_NAME + ".DESTINATION_PATH_SELECTION"; //$NON-NLS-1$
125
126
	private final JarPackageData fJarPackage;
127
	/**
128
	 * Model for the launch combo box. Element: {@link LaunchConfigurationElement}
129
	 */
130
	private final ArrayList fLauchConfigurationModel;
131
132
	private Combo fLaunchConfigurationCombo;
133
134
	public FatJarPackageWizardPage(JarPackageData jarPackage, IStructuredSelection selection) {
135
		super(PAGE_NAME, selection, jarPackage);
136
		setTitle(FatJarPackagerMessages.JarPackageWizardPage_title);
137
		setDescription(FatJarPackagerMessages.FatJarPackageWizardPage_description);
138
		fJarPackage= jarPackage;
139
		fLauchConfigurationModel= new ArrayList();
140
	}
141
142
	/**
143
	 * {@inheritDoc}
144
	 */
145
	public void createControl(Composite parent) {
146
		Composite composite= new Composite(parent, SWT.NONE);
147
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
148
		composite.setLayout(new GridLayout(1, false));
149
150
		Label description= new Label(composite, SWT.NONE);
151
		GridData gridData= new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
152
		description.setLayoutData(gridData);
153
		description.setText(FatJarPackagerMessages.FatJarPackageWizardPage_launchConfigGroupTitle);
154
155
		createLaunchConfigSelectionGroup(composite);
156
157
		Label label= new Label(composite, SWT.NONE);
158
		label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
159
		label.setText(FatJarPackagerMessages.FatJarPackageWizardPage_destinationGroupTitle);
160
161
		createDestinationGroup(composite);
162
163
		restoreWidgetValues();
164
165
		update();
166
167
		Dialog.applyDialogFont(composite);
168
		setControl(composite);
169
	}
170
171
	protected String getDestinationLabel() {
172
		return null;
173
	}
174
175
	private void createLaunchConfigSelectionGroup(Composite parent) {
176
		Composite composite= new Composite(parent, SWT.NONE);
177
		composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
178
		GridLayout layout= new GridLayout(1, false);
179
		layout.marginWidth= 0;
180
		composite.setLayout(layout);
181
182
		fLaunchConfigurationCombo= new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
183
		fLaunchConfigurationCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
184
185
		fLauchConfigurationModel.addAll(Arrays.asList(getLaunchConfigurations()));
186
		String[] names= new String[fLauchConfigurationModel.size()];
187
		for (int i= 0, size= fLauchConfigurationModel.size(); i < size; i++) {
188
			LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(i);
189
			names[i]= element.getLaunchConfigurationName();
190
		}
191
		fLaunchConfigurationCombo.setItems(names);
192
193
		fLaunchConfigurationCombo.addListener(SWT.Selection, this);
194
		fLaunchConfigurationCombo.addListener(SWT.Modify, this);
195
	}
196
197
	protected void updateWidgetEnablements() {
198
	}
199
200
	public boolean isPageComplete() {
201
		boolean complete= validateDestinationGroup();
202
		complete= validateLaunchConfigurationGroup() && complete;
203
		if (complete)
204
			setErrorMessage(null);
205
		return complete;
206
	}
207
208
	private boolean validateLaunchConfigurationGroup() {
209
		return fLaunchConfigurationCombo.getSelectionIndex() != -1;
210
	}
211
212
	private LaunchConfigurationElement[] getLaunchConfigurations() {
213
		ArrayList result= new ArrayList();
214
215
		try {
216
			ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
217
			ILaunchConfigurationType type= manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
218
			ILaunchConfiguration[] launchconfigs= manager.getLaunchConfigurations(type);
219
220
			for (int i= 0; i < launchconfigs.length; i++) {
221
				ILaunchConfiguration launchconfig= launchconfigs[i];
222
223
				String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
224
				result.add(new ExistingLaunchConfigurationElement(launchconfig, projectName));
225
			}
226
		} catch (CoreException e) {
227
			JavaPlugin.log(e);
228
		}
229
230
		return (LaunchConfigurationElement[]) result.toArray(new LaunchConfigurationElement[result.size()]);
231
	}
232
233
	public Object[] getSelectedElementsWithoutContainedChildren(MultiStatus status) {
234
		try {
235
			LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(fLaunchConfigurationCombo.getSelectionIndex());
236
			ILaunchConfiguration launchconfig= element.getLaunchConfiguration();
237
			fJarPackage.setLaunchConfigurationName(element.getLaunchConfigurationName());
238
239
			return getSelectedElementsWithoutContainedChildren(launchconfig, fJarPackage, getContainer(), status);
240
		} catch (CoreException e) {
241
			JavaPlugin.log(e);
242
		}
243
244
		return null;
245
	}
246
247
	private static IJavaProject[] getProjectSearchOrder(String projectName) {
248
249
		ArrayList projectNames= new ArrayList();
250
		projectNames.add(projectName);
251
252
		int nextProject= 0;
253
		while (nextProject < projectNames.size()) {
254
			String nextProjectName= (String) projectNames.get(nextProject);
255
			IJavaProject jproject= getJavaProject(nextProjectName);
256
257
			if (jproject != null) {
258
				try {
259
					String[] childProjectNames= jproject.getRequiredProjectNames();
260
					for (int i= 0; i < childProjectNames.length; i++) {
261
						if (!projectNames.contains(childProjectNames[i])) {
262
							projectNames.add(childProjectNames[i]);
263
						}
264
					}
265
				} catch (JavaModelException e) {
266
					JavaPlugin.log(e);
267
				}
268
			}
269
			nextProject+= 1;
270
		}
271
272
		ArrayList result= new ArrayList();
273
		for (int i= 0, size= projectNames.size(); i < size; i++) {
274
			String name= (String) projectNames.get(i);
275
			IJavaProject project= getJavaProject(name);
276
			if (project != null)
277
				result.add(project);
278
		}
279
280
		return (IJavaProject[]) result.toArray(new IJavaProject[result.size()]);
281
	}
282
283
	private static IJavaProject getJavaProject(String projectName) {
284
		IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
285
		if (project == null)
286
			return null;
287
288
		IJavaProject result= JavaCore.create(project);
289
		if (result == null)
290
			return null;
291
292
		if (!result.exists())
293
			return null;
294
295
		return result;
296
	}
297
298
	private static IPath[] getClasspath(ILaunchConfiguration configuration) throws CoreException {
299
		IRuntimeClasspathEntry[] entries= JavaRuntime.computeUnresolvedRuntimeClasspath(configuration);
300
		entries= JavaRuntime.resolveRuntimeClasspath(entries, configuration);
301
302
		ArrayList userEntries= new ArrayList(entries.length);
303
		for (int i= 0; i < entries.length; i++) {
304
			if (entries[i].getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) {
305
306
				String location= entries[i].getLocation();
307
				if (location != null) {
308
					IPath entry= Path.fromOSString(location);
309
					if (!userEntries.contains(entry)) {
310
						userEntries.add(entry);
311
					}
312
				}
313
			}
314
		}
315
		return (IPath[]) userEntries.toArray(new IPath[userEntries.size()]);
316
	}
317
318
	private static String getMainClass(ILaunchConfiguration launchConfig, MultiStatus status) {
319
		String result= null;
320
		if (launchConfig != null) {
321
			try {
322
				result= launchConfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String) null);
323
			} catch (CoreException e) {
324
				JavaPlugin.log(e);
325
			}
326
		}
327
		if (result == null) {
328
			status.add(new Status(IStatus.WARNING, JavaUI.ID_PLUGIN, FatJarPackagerMessages.FatJarPackageWizardPage_LaunchConfigurationWithoutMainType_warning));
329
			result= ""; //$NON-NLS-1$
330
		}
331
		return result;
332
	}
333
334
	/**
335
	 * @param classpathEntries the path to the package fragment roots
336
	 * @param projectName the root of the project dependency tree
337
	 * @param status a status to report problems to
338
	 * @return all package fragment roots corresponding to each classpath entry start the search at project with projectName
339
	 */
340
	private static IPackageFragmentRoot[] getRequiredPackageFragmentRoots(IPath[] classpathEntries, final String projectName, MultiStatus status) {
341
		HashSet result= new HashSet();
342
343
		IJavaProject[] searchOrder= getProjectSearchOrder(projectName);
344
345
		for (int i= 0; i < classpathEntries.length; i++) {
346
			IPath entry= classpathEntries[i];
347
			IPackageFragmentRoot[] elements= findRootsForClasspath(entry, searchOrder);
348
			if (elements == null) {
349
				status.add(new Status(IStatus.WARNING, JavaUI.ID_PLUGIN, Messages.format(FatJarPackagerMessages.FatJarPackageWizardPage_error_missingClassFile, entry)));
350
			} else {
351
				for (int j= 0; j < elements.length; j++) {
352
					result.add(elements[j]);
353
				}
354
			}
355
		}
356
357
		return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]);
358
	}
359
360
	private static IPackageFragmentRoot[] findRootsForClasspath(IPath entry, IJavaProject[] searchOrder) {
361
		for (int i= 0; i < searchOrder.length; i++) {
362
			IPackageFragmentRoot[] elements= findRootsInProject(entry, searchOrder[i]);
363
			if (elements.length != 0) {
364
				return elements;
365
			}
366
		}
367
		return null;
368
	}
369
370
	private static IPackageFragmentRoot[] findRootsInProject(IPath entry, IJavaProject project) {
371
		ArrayList result= new ArrayList();
372
373
		try {
374
			IPackageFragmentRoot[] roots= project.getPackageFragmentRoots();
375
			for (int i= 0; i < roots.length; i++) {
376
				IPackageFragmentRoot packageFragmentRoot= roots[i];
377
				if (isRootAt(packageFragmentRoot, entry))
378
					result.add(packageFragmentRoot);
379
			}
380
		} catch (Exception e) {
381
			JavaPlugin.log(e);
382
		}
383
384
		return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]);
385
	}
386
387
	private static boolean isRootAt(IPackageFragmentRoot root, IPath entry) {
388
		try {
389
			IClasspathEntry cpe= root.getRawClasspathEntry();
390
			if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
391
				IPath outputLocation= cpe.getOutputLocation();
392
				if (outputLocation == null)
393
					outputLocation= root.getJavaProject().getOutputLocation();
394
395
				IPath location= ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation();
396
				if (entry.equals(location))
397
					return true;
398
			}
399
		} catch (JavaModelException e) {
400
			JavaPlugin.log(e);
401
		}
402
403
		IResource resource= root.getResource();
404
		if (resource != null && entry.equals(resource.getLocation()))
405
			return true;
406
407
		IPath path= root.getPath();
408
		if (path != null && entry.equals(path))
409
			return true;
410
411
		return false;
412
	}
413
414
	private static IType findMainMethodByName(String name, IPackageFragmentRoot[] classpathResources, IRunnableContext context) {
415
416
		List resources= JarPackagerUtil.asResources(classpathResources);
417
		if (resources == null) {
418
			return null;
419
		}
420
421
		for (Iterator iterator= resources.iterator(); iterator.hasNext();) {
422
			IResource element= (IResource) iterator.next();
423
			if (element == null)
424
				iterator.remove();
425
		}
426
427
		IJavaSearchScope searchScope= JavaSearchScopeFactory.getInstance().createJavaSearchScope((IResource[]) resources.toArray(new IResource[resources.size()]), true);
428
		MainMethodSearchEngine engine= new MainMethodSearchEngine();
429
		try {
430
			IType[] mainTypes= engine.searchMainMethods(context, searchScope, 0);
431
			for (int i= 0; i < mainTypes.length; i++) {
432
				if (mainTypes[i].getFullyQualifiedName().equals(name))
433
					return mainTypes[i];
434
			}
435
		} catch (InvocationTargetException ex) {
436
			JavaPlugin.log(ex);
437
		} catch (InterruptedException e) {
438
			// null
439
		}
440
441
		return null;
442
	}
443
444
	public void dispose() {
445
		super.dispose();
446
		if (fLauchConfigurationModel != null) {
447
			for (int i= 0, size= fLauchConfigurationModel.size(); i < size; i++) {
448
				LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(i);
449
				element.dispose();
450
			}
451
		}
452
	}
453
454
	protected void restoreWidgetValues() {
455
456
		IDialogSettings settings= getDialogSettings();
457
		if (settings != null) {
458
			String name= settings.get(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME);
459
			if (name != null) {
460
				String[] items= fLaunchConfigurationCombo.getItems();
461
				for (int i= 0; i < items.length; i++) {
462
					if (name.equals(items[i])) {
463
						fLaunchConfigurationCombo.select(i);
464
					}
465
				}
466
			}
467
468
			String destinationPath= settings.get(STORE_DESTINATION_ELEMENT);
469
			if (destinationPath != null && destinationPath.length() > 0) {
470
				fJarPackage.setJarLocation(Path.fromOSString(destinationPath));
471
			}
472
		}
473
474
		super.restoreWidgetValues();
475
	}
476
477
	/**
478
	 * {@inheritDoc}
479
	 */
480
	protected void saveWidgetValues() {
481
		super.saveWidgetValues();
482
483
		IDialogSettings settings= getDialogSettings();
484
		if (settings != null) {
485
			int index= fLaunchConfigurationCombo.getSelectionIndex();
486
			if (index == -1) {
487
				settings.put(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME, ""); //$NON-NLS-1$
488
			} else {
489
				String selectedItem= fLaunchConfigurationCombo.getItem(index);
490
				settings.put(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME, selectedItem);
491
			}
492
493
			IPath location= fJarPackage.getJarLocation();
494
			if (location == null) {
495
				settings.put(STORE_DESTINATION_ELEMENT, ""); //$NON-NLS-1$
496
			} else {
497
				settings.put(STORE_DESTINATION_ELEMENT, location.toOSString());
498
			}
499
		}
500
	}
501
502
	/*
503
	 * For internal use only (testing), clients must not call.
504
	 */
505
	public static Object[] getSelectedElementsWithoutContainedChildren(ILaunchConfiguration launchconfig, JarPackageData data, IRunnableContext context, MultiStatus status) throws CoreException {
506
		if (launchconfig == null)
507
			return new Object[0];
508
509
		String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
510
511
		IPath[] classpath= getClasspath(launchconfig);
512
		IPackageFragmentRoot[] classpathResources= getRequiredPackageFragmentRoots(classpath, projectName, status);
513
514
		String mainClass= getMainClass(launchconfig, status);
515
		IType mainType= findMainMethodByName(mainClass, classpathResources, context);
516
		if (mainType == null) {
517
			status.add(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, FatJarPackagerMessages.FatJarPackageWizardPage_error_noMainMethod));
518
		}
519
		data.setManifestMainClass(mainType);
520
521
		return classpathResources;
522
	}
523
524
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/JarBuilder.java (+65 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.jarpackager;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.MultiStatus;
17
import org.eclipse.core.runtime.Status;
18
19
import org.eclipse.swt.widgets.Shell;
20
21
import org.eclipse.jdt.ui.jarpackager.IJarBuilder;
22
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
23
24
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
25
import org.eclipse.jdt.internal.ui.JavaPlugin;
26
27
/**
28
 * Base class for all jar builders. 
29
 * 
30
 * @since 3.4
31
 */
32
public abstract class JarBuilder implements IJarBuilder {
33
34
	private MultiStatus fStatus;
35
36
	/**
37
	 * {@inheritDoc}
38
	 */
39
	public void open(JarPackageData jarPackage, Shell shell, MultiStatus status) throws CoreException {
40
		fStatus= status;
41
	}
42
43
	//some methods for convenience
44
	protected final void addInfo(String message, Throwable error) {
45
		fStatus.add(new Status(IStatus.INFO, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, error));
46
	}
47
48
	protected final void addWarning(String message, Throwable error) {
49
		fStatus.add(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, error));
50
	}
51
52
	protected final void addError(String message, Throwable error) {
53
		fStatus.add(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, error));
54
	}
55
56
	protected final void addToStatus(CoreException ex) {
57
		IStatus status= ex.getStatus();
58
		String message= ex.getLocalizedMessage();
59
		if (message == null || message.length() < 1) {
60
			message= JarPackagerMessages.JarFileExportOperation_coreErrorDuringExport;
61
			status= new Status(status.getSeverity(), status.getPlugin(), status.getCode(), message, ex);
62
		}
63
		fStatus.add(status);
64
	}
65
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.properties (+31 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
#     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
###############################################################################
12
13
JarPackageWizard_windowTitle= Runnable JAR File Export
14
JarPackageWizard_jarExport_title= Runnable JAR File Export
15
JarPackageWizard_jarExportError_title= Runnable JAR Export Error
16
JarPackageWizard_jarExportError_message= Creation of runnable JAR failed
17
18
JarPackageWizardPage_title= Runnable JAR File Specification
19
20
FatJarBuilder_error_readingArchiveFile=Could not read jar file ''{0}''. Reason: {1}
21
22
FatJarPackageWizard_JarExportProblems_message=Jar export finished with problems. See details for additional infos.
23
24
FatJarPackageWizardPage_description=Select a launch configuration to use to create a runnable JAR.
25
FatJarPackageWizardPage_destinationGroupTitle=Select the export destination:
26
FatJarPackageWizardPage_error_missingClassFile=Fat Jar Export: Could not find classpath entry for ''{0}''
27
FatJarPackageWizard_IPIssueDialog_message=This operation does repack libraries. Make sure you have the required legal rights to do so.
28
FatJarPackageWizard_IPIssueDialog_title=Runnable JAR File Export
29
FatJarPackageWizardPage_error_noMainMethod=Could not find main method from given launch configuration.
30
FatJarPackageWizardPage_launchConfigGroupTitle=Select the launch configuration:
31
FatJarPackageWizardPage_LaunchConfigurationWithoutMainType_warning=The selected launch configuration has no type with a main method attached. The resulting jar will not be runnable.
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/PlainJarBuilder.java (+85 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.jarpackager;
13
14
import java.util.zip.ZipFile;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.MultiStatus;
20
21
import org.eclipse.core.resources.IFile;
22
23
import org.eclipse.swt.widgets.Shell;
24
25
import org.eclipse.jdt.ui.jarpackager.IManifestProvider;
26
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
27
import org.eclipse.jdt.ui.jarpackager.JarWriter3;
28
29
/**
30
 * Jar builder for the plain jar exported. Does not export archives.
31
 * 
32
 * @since 3.4
33
 */
34
public class PlainJarBuilder extends JarBuilder {
35
36
	public static final String BUILDER_ID= "org.eclipse.jdt.ui.plain_jar_builder"; //$NON-NLS-1$
37
38
	private JarPackageData fJarPackage;
39
	private JarWriter3 fJarWriter;
40
41
	/**
42
	 * {@inheritDoc}
43
	 */
44
	public String getId() {
45
		return BUILDER_ID;
46
	}
47
48
	/**
49
	 * {@inheritDoc}
50
	 */
51
	public IManifestProvider getManifestProvider() {
52
		return new ManifestProvider();
53
	}
54
55
	/**
56
	 * {@inheritDoc}
57
	 */
58
	public void open(JarPackageData jarPackage, Shell displayShell, MultiStatus statusMsg) throws CoreException {
59
		super.open(jarPackage, displayShell, statusMsg);
60
		fJarPackage= jarPackage;
61
		fJarWriter= new JarWriter3(fJarPackage, displayShell);
62
	}
63
64
	/**
65
	 * {@inheritDoc}
66
	 */
67
	public void writeFile(IFile resource, IPath destinationPath) throws CoreException {
68
		fJarWriter.write(resource, destinationPath);
69
	}
70
71
	/**
72
	 * {@inheritDoc}
73
	 */
74
	public void writeArchive(ZipFile archiveRoot, IProgressMonitor progressMonitor) {
75
		//do nothing, plain jar builder can not handle archives, use fat jar builder
76
	}
77
78
	/**
79
	 * {@inheritDoc}
80
	 */
81
	public void close() throws CoreException {
82
		fJarWriter.close();
83
	}
84
85
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackagerMessages.java (+49 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.jarpackagerfat;
13
14
import org.eclipse.osgi.util.NLS;
15
16
public final class FatJarPackagerMessages extends NLS {
17
18
	private static final String BUNDLE_NAME= "org.eclipse.jdt.internal.ui.jarpackagerfat.FatJarPackagerMessages";//$NON-NLS-1$
19
20
	public static String JarPackageWizard_jarExport_title;
21
	public static String JarPackageWizard_jarExportError_message;
22
	public static String JarPackageWizard_jarExportError_title;
23
	public static String JarPackageWizard_windowTitle;
24
25
	public static String JarPackageWizardPage_title;
26
27
	public static String FatJarBuilder_error_readingArchiveFile;
28
29
	public static String FatJarPackageWizard_JarExportProblems_message;
30
31
	public static String FatJarPackageWizardPage_destinationGroupTitle;
32
	public static String FatJarPackageWizardPage_error_missingClassFile;
33
	public static String FatJarPackageWizard_IPIssueDialog_message;
34
35
	public static String FatJarPackageWizard_IPIssueDialog_title;
36
37
	public static String FatJarPackageWizardPage_error_noMainMethod;
38
	public static String FatJarPackageWizardPage_launchConfigGroupTitle;
39
	public static String FatJarPackageWizardPage_LaunchConfigurationWithoutMainType_warning;
40
	public static String FatJarPackageWizardPage_description;
41
42
	static {
43
		NLS.initializeMessages(BUNDLE_NAME, FatJarPackagerMessages.class);
44
	}
45
46
	private FatJarPackagerMessages() {
47
		// Do not instantiate
48
	}
49
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarManifestProvider.java (+200 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.jarpackagerfat;
13
14
import java.io.IOException;
15
import java.io.InputStream;
16
import java.util.ArrayList;
17
import java.util.Enumeration;
18
import java.util.Iterator;
19
import java.util.List;
20
import java.util.Map;
21
import java.util.jar.Attributes;
22
import java.util.jar.Manifest;
23
import java.util.zip.ZipEntry;
24
import java.util.zip.ZipFile;
25
26
import org.eclipse.core.runtime.CoreException;
27
28
import org.eclipse.jdt.core.IPackageFragment;
29
import org.eclipse.jdt.core.IPackageFragmentRoot;
30
31
import org.eclipse.jdt.ui.jarpackager.IManifestProvider;
32
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
33
34
import org.eclipse.jdt.internal.ui.JavaPlugin;
35
import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil;
36
37
/**
38
 * A manifest provider creates manifest files for a fat jar.
39
 * 
40
 * @since 3.4
41
 */
42
public class FatJarManifestProvider implements IManifestProvider {
43
44
	private static final String SEALED_VALUE= "true"; //$NON-NLS-1$
45
	private static final String UNSEALED_VALUE= "false"; //$NON-NLS-1$
46
47
	private FatJarBuilder fBuilder;
48
49
	public FatJarManifestProvider(FatJarBuilder builder) {
50
		fBuilder= builder;
51
	}
52
53
	/**
54
	 * {@inheritDoc}
55
	 */
56
	public Manifest create(JarPackageData jarPackage) throws CoreException {
57
		Manifest result;
58
		Manifest ownManifest= createOwn(jarPackage);
59
		setManifestClasspath(ownManifest, fBuilder.getManifestClasspath());
60
		if (fBuilder.isMergeManifests()) {
61
			List otherManifests= new ArrayList();
62
			Object[] elements= jarPackage.getElements();
63
			for (int i= 0; i < elements.length; i++) {
64
				Object element= elements[i];
65
				if (element instanceof IPackageFragmentRoot && ((IPackageFragmentRoot) element).isArchive()) {
66
					ZipFile zip= JarPackagerUtil.getArchiveFile(((IPackageFragmentRoot) element).getPath());
67
					Enumeration entries= zip.entries();
68
					while (entries.hasMoreElements()) {
69
						ZipEntry entry= (ZipEntry) entries.nextElement();
70
						if (entry.getName().equalsIgnoreCase("META-INF/MANIFEST.MF")) { //$NON-NLS-1$
71
							try {
72
								Manifest otherManifest= new Manifest(zip.getInputStream(entry));
73
								otherManifests.add(otherManifest);
74
							} catch (IOException e) {
75
								JavaPlugin.log(e);
76
							}
77
						}
78
					}
79
				}
80
			}
81
			result= merge(ownManifest, otherManifests);
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
				} else {
106
					mergedEntries.put(attributeName, otherEntries.get(attributeName));
107
				}
108
			}
109
		}
110
		return mergedManifest;
111
	}
112
113
	private Manifest createOwn(JarPackageData jarPackage) throws CoreException {
114
		if (jarPackage.isManifestGenerated())
115
			return createGeneratedManifest(jarPackage);
116
117
		try {
118
			return createSuppliedManifest(jarPackage);
119
		} catch (IOException ex) {
120
			throw JarPackagerUtil.createCoreException(ex.getLocalizedMessage(), ex);
121
		}
122
	}
123
124
	/**
125
	 * {@inheritDoc}
126
	 */
127
	public Manifest createDefault(String manifestVersion) {
128
		Manifest manifest= new Manifest();
129
		manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, manifestVersion);
130
		return manifest;
131
	}
132
133
	/**
134
	 * Hook for subclasses to add additional manifest entries.
135
	 * 
136
	 * @param	manifest	the manifest to which the entries should be added
137
	 * @param	jarPackage	the JAR package specification
138
	 */
139
	protected void putAdditionalEntries(Manifest manifest, JarPackageData jarPackage) {
140
	}
141
142
	private Manifest createGeneratedManifest(JarPackageData jarPackage) {
143
		Manifest manifest= new Manifest();
144
		putVersion(manifest, jarPackage);
145
		putSealing(manifest, jarPackage);
146
		putMainClass(manifest, jarPackage);
147
		putAdditionalEntries(manifest, jarPackage);
148
		return manifest;
149
	}
150
151
	private void putVersion(Manifest manifest, JarPackageData jarPackage) {
152
		manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, jarPackage.getManifestVersion());
153
	}
154
155
	private void putSealing(Manifest manifest, JarPackageData jarPackage) {
156
		if (jarPackage.isJarSealed()) {
157
			manifest.getMainAttributes().put(Attributes.Name.SEALED, SEALED_VALUE);
158
			IPackageFragment[] packages= jarPackage.getPackagesToUnseal();
159
			if (packages != null) {
160
				for (int i= 0; i < packages.length; i++) {
161
					Attributes attributes= new Attributes();
162
					attributes.put(Attributes.Name.SEALED, UNSEALED_VALUE);
163
					manifest.getEntries().put(getInManifestFormat(packages[i]), attributes);
164
				}
165
			}
166
		} else {
167
			IPackageFragment[] packages= jarPackage.getPackagesToSeal();
168
			if (packages != null)
169
				for (int i= 0; i < packages.length; i++) {
170
					Attributes attributes= new Attributes();
171
					attributes.put(Attributes.Name.SEALED, SEALED_VALUE);
172
					manifest.getEntries().put(getInManifestFormat(packages[i]), attributes);
173
				}
174
		}
175
	}
176
177
	private void putMainClass(Manifest manifest, JarPackageData jarPackage) {
178
		if (jarPackage.getManifestMainClass() != null && jarPackage.getManifestMainClass().getFullyQualifiedName().length() > 0)
179
			manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, jarPackage.getManifestMainClass().getFullyQualifiedName());
180
	}
181
182
	private String getInManifestFormat(IPackageFragment packageFragment) {
183
		String name= packageFragment.getElementName();
184
		return name.replace('.', '/') + '/';
185
	}
186
187
	private Manifest createSuppliedManifest(JarPackageData jarPackage) throws CoreException, IOException {
188
		Manifest manifest;
189
		// No need to use buffer here because Manifest(...) does
190
		InputStream stream= jarPackage.getManifestFile().getContents(false);
191
		try {
192
			manifest= new Manifest(stream);
193
		} finally {
194
			if (stream != null)
195
				stream.close();
196
		}
197
		return manifest;
198
	}
199
200
}
(-)ui/org/eclipse/jdt/ui/jarpackager/IJarBuilder.java (+103 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.ui.jarpackager;
13
14
import java.util.zip.ZipFile;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.MultiStatus;
20
21
import org.eclipse.core.resources.IFile;
22
23
import org.eclipse.swt.widgets.Shell;
24
25
26
27
/**
28
 * A jar builder can be used to add elements to a
29
 * jar file which is about to be build.
30
 * <p>
31
 * The protocol defined by this interface is:
32
 * <ul>
33
 * <li>open is called</li>
34
 * <li>addFile and addJar is called multiple times</li>
35
 * <li>close is called</li>
36
 * </ul>
37
 * It is guaranteed that addFile and addJar is only called after
38
 * open is called and before close is called. Other methods may
39
 * be called any time.</p>
40
 * Implementors must be prepared that an instance if the implementation
41
 * is reused multiple times.<p>
42
 * 
43
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as part
44
 * of a work in progress. This API may change at any given time. Please do not
45
 * use this API without consulting with the JDT/UI team. See bug 83258 for discussions.
46
 * 
47
 * @see org.eclipse.jdt.ui.jarpackager.JarPackageData
48
 * @since 3.4
49
 */
50
public interface IJarBuilder {
51
52
	/**
53
	 * @return the unique id of this builder
54
	 */
55
	public String getId();
56
57
	/**
58
	 * @return the manifest provider to build the manifest
59
	 */
60
	public IManifestProvider getManifestProvider();
61
62
	/**
63
	 * Called when building of the jar starts
64
	 * 
65
	 * @param jarPackage
66
	 *        the package to build
67
	 * @param shell
68
	 *        shell to show dialogs, <b>null</b> if no dialog must be shown
69
	 * @param status
70
	 *        a status to use to report status to the user
71
	 * @throws CoreException
72
	 */
73
	public void open(JarPackageData jarPackage, Shell shell, MultiStatus status) throws CoreException;
74
75
	/**
76
	 * Add the given resource to the archive at the given path
77
	 * 
78
	 * @param resource
79
	 *        the file to be written
80
	 * @param destinationPath
81
	 *        the path for the file inside the archive
82
	 * @throws CoreException 
83
	 */
84
	public void writeFile(IFile resource, IPath destinationPath) throws CoreException;
85
86
	/**
87
	 * Add the given archive to the archive which is about to be build
88
	 * 
89
	 * @param archive
90
	 *        the archive to add
91
	 * @param monitor
92
	 *        a monitor to report progress to
93
	 */
94
	public void writeArchive(ZipFile archive, IProgressMonitor monitor);
95
96
	/**
97
	 * Called when building of the jar finished.
98
	 * 
99
	 * @throws CoreException
100
	 */
101
	public void close() throws CoreException;
102
103
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackager/AbstractJarDestinationWizardPage.java (+322 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.jarpackager;
13
14
import java.io.File;
15
16
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.Path;
18
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.ResourcesPlugin;
22
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.events.SelectionAdapter;
25
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.layout.GridData;
27
import org.eclipse.swt.layout.GridLayout;
28
import org.eclipse.swt.widgets.Button;
29
import org.eclipse.swt.widgets.Combo;
30
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.swt.widgets.Event;
32
import org.eclipse.swt.widgets.FileDialog;
33
import org.eclipse.swt.widgets.Label;
34
35
import org.eclipse.jface.dialogs.IDialogSettings;
36
import org.eclipse.jface.dialogs.IMessageProvider;
37
import org.eclipse.jface.viewers.IStructuredSelection;
38
39
import org.eclipse.ui.dialogs.WizardExportResourcesPage;
40
41
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
42
43
import org.eclipse.jdt.internal.ui.util.SWTUtil;
44
45
/**
46
 * A wizard page containing a destination block for a jar file. Including
47
 * all required validation code. Clients should overwrite <code>createControl</code>.
48
 * 
49
 * @since 3.4
50
 */
51
public abstract class AbstractJarDestinationWizardPage extends WizardExportResourcesPage implements IJarPackageWizardPage {
52
53
	private final String fStoreDestinationNamesId;
54
55
	private Combo fDestinationNamesCombo;
56
	private Button fDestinationBrowseButton;
57
	private final JarPackageData fJarPackage;
58
59
	public AbstractJarDestinationWizardPage(String pageName, IStructuredSelection selection, JarPackageData jarPackage) {
60
		super(pageName, selection);
61
		fStoreDestinationNamesId= pageName + ".DESTINATION_NAMES_ID"; //$NON-NLS-1$
62
		fJarPackage= jarPackage;
63
	}
64
65
	/*
66
	 * Overrides method from WizardExportPage
67
	 */
68
	protected void createDestinationGroup(Composite parent) {
69
70
		initializeDialogUnits(parent);
71
72
		// destination specification group
73
		Composite destinationSelectionGroup= new Composite(parent, SWT.NONE);
74
		GridLayout layout= new GridLayout();
75
		layout.numColumns= 3;
76
		destinationSelectionGroup.setLayout(layout);
77
		destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
78
79
		String label= getDestinationLabel();
80
		if (label != null) {
81
			new Label(destinationSelectionGroup, SWT.NONE).setText(label);
82
		} else {
83
			layout.marginWidth= 0;
84
		}
85
86
		// destination name entry field
87
		fDestinationNamesCombo= new Combo(destinationSelectionGroup, SWT.SINGLE | SWT.BORDER);
88
		fDestinationNamesCombo.addListener(SWT.Modify, this);
89
		fDestinationNamesCombo.addListener(SWT.Selection, this);
90
		GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
91
		data.widthHint= SIZING_TEXT_FIELD_WIDTH;
92
		data.horizontalSpan= label == null ? 2 : 1;
93
		fDestinationNamesCombo.setLayoutData(data);
94
95
		// destination browse button
96
		fDestinationBrowseButton= new Button(destinationSelectionGroup, SWT.PUSH);
97
		fDestinationBrowseButton.setText(JarPackagerMessages.JarPackageWizardPage_browseButton_text);
98
		fDestinationBrowseButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
99
		SWTUtil.setButtonDimensionHint(fDestinationBrowseButton);
100
		fDestinationBrowseButton.addSelectionListener(new SelectionAdapter() {
101
			public void widgetSelected(SelectionEvent e) {
102
				handleDestinationBrowseButtonPressed();
103
			}
104
		});
105
	}
106
107
	/**
108
	 *	Open an appropriate destination browser so that the user can specify a source
109
	 *	to import from
110
	 */
111
	protected void handleDestinationBrowseButtonPressed() {
112
		FileDialog dialog= new FileDialog(getContainer().getShell(), SWT.SAVE);
113
		dialog.setFilterExtensions(new String[] { "*.jar", "*.zip" }); //$NON-NLS-1$ //$NON-NLS-2$
114
115
		String currentSourceString= getDestinationValue();
116
		int lastSeparatorIndex= currentSourceString.lastIndexOf(File.separator);
117
		if (lastSeparatorIndex != -1) {
118
			dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex));
119
			dialog.setFileName(currentSourceString.substring(lastSeparatorIndex + 1, currentSourceString.length()));
120
		} else
121
			dialog.setFileName(currentSourceString);
122
		String selectedFileName= dialog.open();
123
		if (selectedFileName != null)
124
			fDestinationNamesCombo.setText(selectedFileName);
125
	}
126
127
128
	/**
129
	 * Answer the contents of the destination specification widget. If this
130
	 * value does not have the required suffix then add it first.
131
	 * 
132
	 * @return java.lang.String
133
	 */
134
	protected String getDestinationValue() {
135
		String destinationText= fDestinationNamesCombo.getText().trim();
136
		if (destinationText.indexOf('.') < 0)
137
			destinationText+= getOutputSuffix();
138
		return destinationText;
139
	}
140
141
	/**
142
	 *	Answer the string to display in self as the destination type
143
	 *
144
	 *	@return java.lang.String
145
	 */
146
	protected String getDestinationLabel() {
147
		return JarPackagerMessages.JarPackageWizardPage_destination_label;
148
	}
149
150
	/**
151
	 *	Answer the suffix that files exported from this wizard must have.
152
	 *	If this suffix is a file extension (which is typically the case)
153
	 *	then it must include the leading period character.
154
	 *
155
	 *	@return java.lang.String
156
	 */
157
	protected String getOutputSuffix() {
158
		return "." + JarPackagerUtil.JAR_EXTENSION; //$NON-NLS-1$
159
	}
160
161
	protected void restoreWidgetValues() {
162
		// destination
163
		if (fJarPackage.getJarLocation().isEmpty())
164
			fDestinationNamesCombo.setText(""); //$NON-NLS-1$
165
		else
166
			fDestinationNamesCombo.setText(fJarPackage.getJarLocation().toOSString());
167
		IDialogSettings settings= getDialogSettings();
168
		if (settings != null) {
169
			String[] directoryNames= settings.getArray(fStoreDestinationNamesId);
170
			if (directoryNames == null)
171
				return; // ie.- no settings stored
172
			if (!fDestinationNamesCombo.getText().equals(directoryNames[0]))
173
				fDestinationNamesCombo.add(fDestinationNamesCombo.getText());
174
			for (int i= 0; i < directoryNames.length; i++)
175
				fDestinationNamesCombo.add(directoryNames[i]);
176
		}
177
	}
178
179
	protected void updateModel() {
180
		// destination
181
		String comboText= fDestinationNamesCombo.getText();
182
		IPath path= Path.fromOSString(comboText);
183
184
		if (path.segmentCount() > 0 && ensureTargetFileIsValid(path.toFile()) && path.getFileExtension() == null)
185
			// append .jar
186
			path= path.addFileExtension(JarPackagerUtil.JAR_EXTENSION);
187
188
		fJarPackage.setJarLocation(path);
189
	}
190
191
	/**
192
	 * Returns a boolean indicating whether the passed File handle is
193
	 * is valid and available for use.
194
	 *
195
	 * @param targetFile the target
196
	 * @return boolean
197
	 */
198
	protected boolean ensureTargetFileIsValid(File targetFile) {
199
		if (targetFile.exists() && targetFile.isDirectory() && fDestinationNamesCombo.getText().length() > 0) {
200
			setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_exportDestinationMustNotBeDirectory);
201
			fDestinationNamesCombo.setFocus();
202
			return false;
203
		}
204
		if (targetFile.exists()) {
205
			if (!targetFile.canWrite()) {
206
				setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_jarFileExistsAndNotWritable);
207
				fDestinationNamesCombo.setFocus();
208
				return false;
209
			}
210
		}
211
		return true;
212
	}
213
214
	/*
215
	 * Overrides method from WizardDataTransferPage
216
	 */
217
	protected boolean validateDestinationGroup() {
218
		if (fDestinationNamesCombo.getText().length() == 0) {
219
			// Clear error 
220
			if (getErrorMessage() != null)
221
				setErrorMessage(null);
222
			if (getMessage() != null)
223
				setMessage(null);
224
			return false;
225
		}
226
		if (fJarPackage.getAbsoluteJarLocation().toString().endsWith("/")) { //$NON-NLS-1$
227
			setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_exportDestinationMustNotBeDirectory);
228
			fDestinationNamesCombo.setFocus();
229
			return false;
230
		}
231
		// Check if the Jar is put into the workspace and conflicts with the containers
232
		// exported. If the workspace isn't on the local files system we are fine since
233
		// the Jar is always created in the local file system
234
		IPath workspaceLocation= ResourcesPlugin.getWorkspace().getRoot().getLocation();
235
		if (workspaceLocation != null && workspaceLocation.isPrefixOf(fJarPackage.getAbsoluteJarLocation())) {
236
			int segments= workspaceLocation.matchingFirstSegments(fJarPackage.getAbsoluteJarLocation());
237
			IPath path= fJarPackage.getAbsoluteJarLocation().removeFirstSegments(segments);
238
			IResource resource= ResourcesPlugin.getWorkspace().getRoot().findMember(path);
239
			if (resource != null && resource.getType() == IResource.FILE) {
240
				// test if included
241
				if (JarPackagerUtil.contains(JarPackagerUtil.asResources(fJarPackage.getElements()), (IFile) resource)) {
242
					setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_cantExportJARIntoItself);
243
					return false;
244
				}
245
			}
246
		}
247
		// Inform user about relative directory
248
		String currentMessage= getMessage();
249
		if (!(new File(fDestinationNamesCombo.getText()).isAbsolute())) {
250
			if (currentMessage == null)
251
				setMessage(JarPackagerMessages.JarPackageWizardPage_info_relativeExportDestination, IMessageProvider.INFORMATION);
252
		} else {
253
			if (currentMessage != null)
254
				setMessage(null);
255
		}
256
		return ensureTargetFileIsValid(fJarPackage.getAbsoluteJarLocation().toFile());
257
	}
258
259
	/**
260
	 * Set the current input focus to self's destination entry field
261
	 */
262
	protected void giveFocusToDestination() {
263
		fDestinationNamesCombo.setFocus();
264
	}
265
266
	/**
267
	 * {@inheritDoc}
268
	 */
269
	protected void saveWidgetValues() {
270
		IDialogSettings settings= getDialogSettings();
271
		if (settings != null) {
272
			String[] directoryNames= settings.getArray(fStoreDestinationNamesId);
273
			if (directoryNames == null)
274
				directoryNames= new String[0];
275
			directoryNames= addToHistory(directoryNames, getDestinationValue());
276
			settings.put(fStoreDestinationNamesId, directoryNames);
277
		}
278
	}
279
280
	/**
281
	 *	Initializes the JAR package from last used wizard page values.
282
	 */
283
	protected void initializeJarPackage() {
284
		IDialogSettings settings= getDialogSettings();
285
		if (settings != null) {
286
			// destination
287
			String[] directoryNames= settings.getArray(fStoreDestinationNamesId);
288
			if (directoryNames == null)
289
				return; // ie.- no settings stored
290
			fJarPackage.setJarLocation(Path.fromOSString(directoryNames[0]));
291
		}
292
	}
293
294
	/* 
295
	 * Implements method from IJarPackageWizardPage.
296
	 */
297
	public void finish() {
298
		saveWidgetValues();
299
	}
300
301
	/*
302
	 * Implements method from Listener
303
	 */
304
	public void handleEvent(Event e) {
305
		if (getControl() == null)
306
			return;
307
		update();
308
	}
309
310
	protected void update() {
311
		updateModel();
312
		updateWidgetEnablements();
313
		updatePageCompletion();
314
	}
315
316
	protected void updatePageCompletion() {
317
		boolean pageComplete= isPageComplete();
318
		setPageComplete(pageComplete);
319
		if (pageComplete)
320
			setErrorMessage(null);
321
	}
322
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/JarWriter4.java (+58 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.jarpackagerfat;
13
14
import java.io.File;
15
import java.io.IOException;
16
import java.util.jar.JarEntry;
17
import java.util.zip.ZipEntry;
18
import java.util.zip.ZipFile;
19
20
import org.eclipse.core.runtime.CoreException;
21
22
import org.eclipse.swt.widgets.Shell;
23
24
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
25
import org.eclipse.jdt.ui.jarpackager.JarWriter3;
26
27
/**
28
 * @since 3.4
29
 */
30
public class JarWriter4 extends JarWriter3 {
31
32
	private final JarPackageData fJarPackage;
33
34
	public JarWriter4(JarPackageData jarPackage, Shell parent) throws CoreException {
35
		super(jarPackage, parent);
36
		fJarPackage= jarPackage;
37
	}
38
39
	public void addZipEntry(ZipEntry zipEntry, ZipFile zipFile, String path) throws IOException {
40
		JarEntry newEntry= new JarEntry(path.replace(File.separatorChar, '/'));
41
42
		if (fJarPackage.isCompressed())
43
			newEntry.setMethod(ZipEntry.DEFLATED);
44
			// Entry is filled automatically.
45
		else {
46
			newEntry.setMethod(ZipEntry.STORED);
47
			newEntry.setSize(zipEntry.getSize());
48
			newEntry.setCompressedSize(zipEntry.getCrc());
49
		}
50
51
		long lastModified= System.currentTimeMillis();
52
53
		// Set modification time
54
		newEntry.setTime(lastModified);
55
56
		addEntry(newEntry, zipFile.getInputStream(zipEntry));
57
	}
58
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarBuilder.java (+130 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.jarpackagerfat;
13
14
import java.io.IOException;
15
import java.util.Enumeration;
16
import java.util.zip.ZipEntry;
17
import java.util.zip.ZipException;
18
import java.util.zip.ZipFile;
19
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.MultiStatus;
24
import org.eclipse.core.runtime.OperationCanceledException;
25
26
import org.eclipse.core.resources.IFile;
27
28
import org.eclipse.swt.widgets.Shell;
29
30
import org.eclipse.jdt.internal.corext.util.Messages;
31
32
import org.eclipse.jdt.ui.jarpackager.IManifestProvider;
33
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
34
35
import org.eclipse.jdt.internal.ui.jarpackager.JarBuilder;
36
37
public class FatJarBuilder extends JarBuilder {
38
39
	public static final String BUILDER_ID= "org.eclipse.jdt.ui.fat_jar_builder"; //$NON-NLS-1$
40
41
	private JarPackageData fJarPackage;
42
	private JarWriter4 fJarWriter;
43
44
	/**
45
	 * {@inheritDoc}
46
	 */
47
	public String getId() {
48
		return BUILDER_ID;
49
	}
50
51
	/**
52
	 * {@inheritDoc}
53
	 */
54
	public IManifestProvider getManifestProvider() {
55
		return new FatJarManifestProvider(this);
56
	}
57
58
	public String getManifestClasspath() {
59
		return "."; //$NON-NLS-1$
60
	}
61
62
	public boolean isMergeManifests() {
63
		return true;
64
	}
65
66
	public boolean isRemoveSigners() {
67
		return true;
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 */
73
	public void open(JarPackageData jarPackage, Shell displayShell, MultiStatus status) throws CoreException {
74
		super.open(jarPackage, displayShell, status);
75
		fJarPackage= jarPackage;
76
		fJarWriter= new JarWriter4(fJarPackage, displayShell);
77
	}
78
79
	/**
80
	 * {@inheritDoc}
81
	 */
82
	public void writeFile(IFile resource, IPath destinationPath) throws CoreException {
83
		fJarWriter.write(resource, destinationPath);
84
	}
85
86
	/**
87
	 * {@inheritDoc}
88
	 */
89
	public void writeArchive(ZipFile jarFile, IProgressMonitor progressMonitor) {
90
		Enumeration jarEntriesEnum= jarFile.entries();
91
		while (jarEntriesEnum.hasMoreElements()) {
92
			ZipEntry jarEntry= (ZipEntry) jarEntriesEnum.nextElement();
93
			if (!jarEntry.isDirectory()) {
94
				String entryName= jarEntry.getName();
95
				addFile(entryName, jarEntry, jarFile);
96
			}
97
			progressMonitor.worked(1);
98
			if (progressMonitor.isCanceled())
99
				throw new OperationCanceledException();
100
		}
101
	}
102
103
	private void addFile(String destinationPath, ZipEntry jarEntry, ZipFile zipFile) {
104
		// Handle META-INF/MANIFEST.MF 
105
		if (destinationPath.equalsIgnoreCase("META-INF/MANIFEST.MF") //$NON-NLS-1$
106
				|| (isRemoveSigners() && destinationPath.startsWith("META-INF/") && destinationPath.endsWith(".SF"))) { //$NON-NLS-1$//$NON-NLS-2$
107
			return;
108
		}
109
		try {
110
			fJarWriter.addZipEntry(jarEntry, zipFile, destinationPath);
111
		} catch (IOException ex) {
112
			if (ex instanceof ZipException && ex.getMessage() != null && ex.getMessage().startsWith("duplicate entry:")) {//$NON-NLS-1$
113
				// ignore duplicates in META-INF (*.SF, *.RSA)
114
				if (!destinationPath.startsWith("META-INF/")) { //$NON-NLS-1$
115
					addWarning(ex.getMessage(), ex);
116
				}
117
			} else
118
				addWarning(Messages.format(FatJarPackagerMessages.FatJarBuilder_error_readingArchiveFile, new Object[] { zipFile.getName(), ex.getLocalizedMessage() }), ex);
119
		}
120
	}
121
122
	/**
123
	 * {@inheritDoc}
124
	 */
125
	public void close() throws CoreException {
126
		if (fJarWriter != null) {
127
			fJarWriter.close();
128
		}
129
	}
130
}
(-)ui/org/eclipse/jdt/internal/ui/jarpackagerfat/FatJarPackageWizard.java (+242 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
 *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.jarpackagerfat;
13
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.HashSet;
16
import java.util.Iterator;
17
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.MultiStatus;
21
22
import org.eclipse.swt.widgets.Shell;
23
24
import org.eclipse.jface.dialogs.ErrorDialog;
25
import org.eclipse.jface.dialogs.IDialogConstants;
26
import org.eclipse.jface.dialogs.IDialogSettings;
27
import org.eclipse.jface.dialogs.MessageDialog;
28
import org.eclipse.jface.viewers.ISelection;
29
import org.eclipse.jface.viewers.IStructuredSelection;
30
import org.eclipse.jface.viewers.StructuredSelection;
31
import org.eclipse.jface.window.Window;
32
import org.eclipse.jface.wizard.IWizardPage;
33
import org.eclipse.jface.wizard.Wizard;
34
35
import org.eclipse.ui.IExportWizard;
36
import org.eclipse.ui.IWorkbench;
37
38
import org.eclipse.jdt.core.IJavaElement;
39
import org.eclipse.jdt.core.IJavaProject;
40
import org.eclipse.jdt.core.IPackageFragmentRoot;
41
42
import org.eclipse.jdt.ui.jarpackager.IJarExportRunnable;
43
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
44
45
import org.eclipse.jdt.internal.ui.JavaPlugin;
46
import org.eclipse.jdt.internal.ui.JavaPluginImages;
47
import org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog;
48
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
49
50
/**
51
 * Wizard for exporting resources from the workspace to a Fat Java Archive (JAR) file.
52
 * The exported jar will contain all required libraries.
53
 * 
54
 * @since 3.4
55
 */
56
public class FatJarPackageWizard extends Wizard implements IExportWizard {
57
58
	private static final class IPIssueWarningDialog extends OptionalMessageDialog {
59
60
		private static final String ID= "RunnableJar.export.ipwarning"; //$NON-NLS-1$
61
62
		protected IPIssueWarningDialog(Shell parent, String title, String message) {
63
			super(ID, parent, title, null, message, MessageDialog.WARNING, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
64
		}
65
66
	}
67
68
	private static String DIALOG_SETTINGS_KEY= "FatJarPackageWizard"; //$NON-NLS-1$
69
70
	private boolean fHasNewDialogSettings;
71
	private boolean fInitializeFromJarPackage;
72
	private JarPackageData fJarPackage;
73
	private FatJarPackageWizardPage fJarPackageWizardPage;
74
	private IStructuredSelection fSelection;
75
76
	/**
77
	 * Creates a wizard for exporting workspace resources to a JAR file.
78
	 */
79
	public FatJarPackageWizard() {
80
		IDialogSettings workbenchSettings= JavaPlugin.getDefault().getDialogSettings();
81
		IDialogSettings section= workbenchSettings.getSection(DIALOG_SETTINGS_KEY);
82
		if (section == null)
83
			fHasNewDialogSettings= true;
84
		else {
85
			fHasNewDialogSettings= false;
86
			setDialogSettings(section);
87
		}
88
	}
89
90
	/**
91
	 * {@inheritDoc}
92
	 */
93
	public void addPages() {
94
		super.addPages();
95
		fJarPackageWizardPage= new FatJarPackageWizardPage(fJarPackage, fSelection);
96
		addPage(fJarPackageWizardPage);
97
	}
98
99
	/**
100
	 * Exports the JAR package.
101
	 * 
102
	 * @param op the operation to run
103
	 * @param wizardPageStatus the status returned by the wizard page
104
	 * @return a boolean indicating success or failure
105
	 */
106
	protected boolean executeExportOperation(IJarExportRunnable op, IStatus wizardPageStatus) {
107
		try {
108
			getContainer().run(true, true, op);
109
		} catch (InterruptedException e) {
110
			return false;
111
		} catch (InvocationTargetException ex) {
112
			if (ex.getTargetException() != null) {
113
				ExceptionHandler.handle(ex, getShell(), FatJarPackagerMessages.JarPackageWizard_jarExportError_title, FatJarPackagerMessages.JarPackageWizard_jarExportError_message);
114
				return false;
115
			}
116
		}
117
		IStatus status= op.getStatus();
118
		if (!status.isOK()) {
119
			if (!wizardPageStatus.isOK()) {
120
				if (!(status instanceof MultiStatus))
121
					status= new MultiStatus(status.getPlugin(), status.getCode(), status.getMessage(), status.getException());
122
123
				((MultiStatus) status).add(wizardPageStatus);
124
			}
125
			ErrorDialog.openError(getShell(), FatJarPackagerMessages.JarPackageWizard_jarExport_title, null, status);
126
			return !(status.matches(IStatus.ERROR));
127
		} else if (!wizardPageStatus.isOK()) {
128
			ErrorDialog.openError(getShell(), FatJarPackagerMessages.JarPackageWizard_jarExport_title, null, wizardPageStatus);
129
		}
130
		return true;
131
	}
132
133
	public IWizardPage getNextPage(IWizardPage page) {
134
		return super.getNextPage(page);
135
	}
136
137
	public IWizardPage getPreviousPage(IWizardPage page) {
138
		return super.getPreviousPage(page);
139
	}
140
141
	/**
142
	 * @return all java projects which contain the selected elements in the active workbench window
143
	 */
144
	protected IStructuredSelection getSelectedJavaProjects() {
145
		ISelection currentSelection= JavaPlugin.getActiveWorkbenchWindow().getSelectionService().getSelection();
146
		if (currentSelection instanceof IStructuredSelection) {
147
			IStructuredSelection structuredSelection= (IStructuredSelection) currentSelection;
148
			HashSet selectedElements= new HashSet();
149
			Iterator iter= structuredSelection.iterator();
150
			while (iter.hasNext()) {
151
				Object selectedElement= iter.next();
152
				if (selectedElement instanceof IJavaElement) {
153
					IJavaProject javaProject= ((IJavaElement) selectedElement).getJavaProject();
154
					if (javaProject != null)
155
						selectedElements.add(javaProject);
156
				}
157
			}
158
			return new StructuredSelection(selectedElements);
159
		} else
160
			return StructuredSelection.EMPTY;
161
	}
162
163
	/**
164
	 * {@inheritDoc}
165
	 */
166
	public void init(IWorkbench workbench, IStructuredSelection selection) {
167
		fSelection= getSelectedJavaProjects();
168
		fJarPackage= new JarPackageData();
169
		setInitializeFromJarPackage(false);
170
		setWindowTitle(FatJarPackagerMessages.JarPackageWizard_windowTitle);
171
		setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_FAT_JAR_PACKAGER);
172
		setNeedsProgressMonitor(true);
173
	}
174
175
	/**
176
	 * Initializes this wizard from the given JAR package description.
177
	 * 
178
	 * @param workbench
179
	 *            the workbench which launched this wizard
180
	 * @param jarPackage
181
	 *            the JAR package description used to initialize this wizard
182
	 */
183
	public void init(IWorkbench workbench, JarPackageData jarPackage) {
184
		Assert.isNotNull(workbench);
185
		Assert.isNotNull(jarPackage);
186
		fJarPackage= jarPackage;
187
		setInitializeFromJarPackage(true);
188
		setWindowTitle(FatJarPackagerMessages.JarPackageWizard_windowTitle);
189
		setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_FAT_JAR_PACKAGER);
190
		setNeedsProgressMonitor(true);
191
	}
192
193
	boolean isInitializingFromJarPackage() {
194
		return fInitializeFromJarPackage;
195
	}
196
197
	/**
198
	 * {@inheritDoc}
199
	 */
200
	public boolean performFinish() {
201
		fJarPackage.setJarBuilder(new FatJarBuilder());
202
		MultiStatus status= new MultiStatus(JavaPlugin.getPluginId(), IStatus.OK, FatJarPackagerMessages.FatJarPackageWizard_JarExportProblems_message, null);
203
		Object[] elements= fJarPackageWizardPage.getSelectedElementsWithoutContainedChildren(status);
204
		fJarPackage.setElements(elements);
205
206
		if (OptionalMessageDialog.isDialogEnabled(IPIssueWarningDialog.ID) && hasArchive(elements)) {
207
			IPIssueWarningDialog dialog= new IPIssueWarningDialog(getShell(), FatJarPackagerMessages.FatJarPackageWizard_IPIssueDialog_title,
208
					FatJarPackagerMessages.FatJarPackageWizard_IPIssueDialog_message);
209
			if (dialog.open() != Window.OK)
210
				return false;
211
		}
212
213
		if (!executeExportOperation(fJarPackage.createJarExportRunnable(getShell()), status))
214
			return false;
215
216
		// Save the dialog settings
217
		if (fHasNewDialogSettings) {
218
			IDialogSettings workbenchSettings= JavaPlugin.getDefault().getDialogSettings();
219
			IDialogSettings section= workbenchSettings.getSection(DIALOG_SETTINGS_KEY);
220
			section= workbenchSettings.addNewSection(DIALOG_SETTINGS_KEY);
221
			setDialogSettings(section);
222
		}
223
224
		fJarPackageWizardPage.finish();
225
		return true;
226
	}
227
228
	private boolean hasArchive(Object[] elements) {
229
		for (int i= 0; i < elements.length; i++) {
230
			if (elements[i] instanceof IPackageFragmentRoot) {
231
				IPackageFragmentRoot root= (IPackageFragmentRoot) elements[i];
232
				if (root.isArchive())
233
					return true;
234
			}
235
		}
236
		return false;
237
	}
238
239
	void setInitializeFromJarPackage(boolean state) {
240
		fInitializeFromJarPackage= state;
241
	}
242
}
(-)3.4/external_contributors.txt (+4 lines)
Lines 8-10 Link Here
8
Stephan Herrmann (stephan@cs.tu-berlin.de):
8
Stephan Herrmann (stephan@cs.tu-berlin.de):
9
- bug 75800: [call hierarchy] should allow searches for fields
9
- bug 75800: [call hierarchy] should allow searches for fields
10
10
11
M4
12
==
13
Ferenc Hechler (ferenc_hechler@users.sourceforge.net):
14
- bug 83258 [jar exporter] Deploy java application as executable jar

Return to bug 83258