Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2007 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.internal.ui.jarpackagerfat; |
12 |
|
13 |
import java.lang.reflect.InvocationTargetException; |
14 |
import java.util.ArrayList; |
15 |
import java.util.Arrays; |
16 |
import java.util.HashSet; |
17 |
import java.util.Iterator; |
18 |
import java.util.List; |
19 |
|
20 |
import org.eclipse.core.runtime.CoreException; |
21 |
import org.eclipse.core.runtime.IPath; |
22 |
import org.eclipse.core.runtime.IStatus; |
23 |
import org.eclipse.core.runtime.Path; |
24 |
import org.eclipse.core.runtime.Status; |
25 |
|
26 |
import org.eclipse.core.resources.IProject; |
27 |
import org.eclipse.core.resources.IResource; |
28 |
import org.eclipse.core.resources.ResourcesPlugin; |
29 |
|
30 |
import org.eclipse.swt.SWT; |
31 |
import org.eclipse.swt.layout.GridData; |
32 |
import org.eclipse.swt.layout.GridLayout; |
33 |
import org.eclipse.swt.widgets.Combo; |
34 |
import org.eclipse.swt.widgets.Composite; |
35 |
import org.eclipse.swt.widgets.Label; |
36 |
import org.eclipse.swt.widgets.Listener; |
37 |
|
38 |
import org.eclipse.jface.dialogs.Dialog; |
39 |
import org.eclipse.jface.dialogs.IDialogSettings; |
40 |
import org.eclipse.jface.operation.IRunnableContext; |
41 |
import org.eclipse.jface.viewers.StructuredSelection; |
42 |
|
43 |
import org.eclipse.debug.core.DebugPlugin; |
44 |
import org.eclipse.debug.core.ILaunchConfiguration; |
45 |
import org.eclipse.debug.core.ILaunchConfigurationType; |
46 |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
47 |
import org.eclipse.debug.core.ILaunchManager; |
48 |
|
49 |
import org.eclipse.jdt.core.IClasspathEntry; |
50 |
import org.eclipse.jdt.core.IJavaProject; |
51 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
52 |
import org.eclipse.jdt.core.IType; |
53 |
import org.eclipse.jdt.core.JavaCore; |
54 |
import org.eclipse.jdt.core.JavaModelException; |
55 |
import org.eclipse.jdt.core.search.IJavaSearchScope; |
56 |
|
57 |
import org.eclipse.jdt.internal.corext.util.Messages; |
58 |
|
59 |
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
60 |
import org.eclipse.jdt.launching.IRuntimeClasspathEntry; |
61 |
import org.eclipse.jdt.launching.JavaRuntime; |
62 |
|
63 |
import org.eclipse.jdt.ui.JavaUI; |
64 |
import org.eclipse.jdt.ui.jarpackager.JarPackageData; |
65 |
|
66 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
67 |
import org.eclipse.jdt.internal.ui.jarpackager.AbstractJarDestinationWizardPage; |
68 |
import org.eclipse.jdt.internal.ui.jarpackager.JarPackagerUtil; |
69 |
import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory; |
70 |
import org.eclipse.jdt.internal.ui.util.MainMethodSearchEngine; |
71 |
|
72 |
/** |
73 |
* First page for the runnable jar export wizard |
74 |
* @since 3.4 |
75 |
*/ |
76 |
public class FatJarPackageWizardPage extends AbstractJarDestinationWizardPage implements Listener { |
77 |
|
78 |
private abstract static class LaunchConfigurationElement { |
79 |
|
80 |
public abstract ILaunchConfiguration getLaunchConfiguration(); |
81 |
|
82 |
public abstract String getLaunchConfigurationName(); |
83 |
|
84 |
public void dispose() { |
85 |
//do nothing |
86 |
} |
87 |
} |
88 |
|
89 |
private static class ExistingLaunchConfigurationElement extends LaunchConfigurationElement { |
90 |
|
91 |
private ILaunchConfiguration fLaunchConfiguration; |
92 |
private final String fProjectName; |
93 |
|
94 |
public ExistingLaunchConfigurationElement(ILaunchConfiguration launchConfiguration, String projectName) { |
95 |
fLaunchConfiguration= launchConfiguration; |
96 |
fProjectName= projectName; |
97 |
} |
98 |
|
99 |
/** |
100 |
* {@inheritDoc} |
101 |
*/ |
102 |
public ILaunchConfiguration getLaunchConfiguration() { |
103 |
return fLaunchConfiguration; |
104 |
} |
105 |
|
106 |
/** |
107 |
* {@inheritDoc} |
108 |
*/ |
109 |
public String getLaunchConfigurationName() { |
110 |
return fProjectName + " : " + fLaunchConfiguration.getName(); //$NON-NLS-1$ |
111 |
} |
112 |
|
113 |
} |
114 |
|
115 |
private static class DefaultLaunchConfigurationElement extends LaunchConfigurationElement { |
116 |
|
117 |
private IJavaProject fJavaProject; |
118 |
private ILaunchConfiguration fLaunchConfiguration; |
119 |
|
120 |
public DefaultLaunchConfigurationElement(IJavaProject javaProject) { |
121 |
fJavaProject= javaProject; |
122 |
} |
123 |
|
124 |
/** |
125 |
* {@inheritDoc} |
126 |
*/ |
127 |
public ILaunchConfiguration getLaunchConfiguration() { |
128 |
if (fLaunchConfiguration == null) |
129 |
fLaunchConfiguration= createTempLaunchConfig(fJavaProject); |
130 |
|
131 |
return fLaunchConfiguration; |
132 |
} |
133 |
|
134 |
/** |
135 |
* {@inheritDoc} |
136 |
*/ |
137 |
public String getLaunchConfigurationName() { |
138 |
return Messages.format(FatJarPackagerMessages.FatJarPackageWizardPage_defaultLaunchConfigName, fJavaProject.getElementName()); |
139 |
} |
140 |
|
141 |
/** |
142 |
* {@inheritDoc} |
143 |
*/ |
144 |
public void dispose() { |
145 |
if (fLaunchConfiguration != null) { |
146 |
try { |
147 |
fLaunchConfiguration.delete(); |
148 |
fLaunchConfiguration= null; |
149 |
} catch (CoreException e) { |
150 |
JavaPlugin.log(e); |
151 |
} |
152 |
} |
153 |
} |
154 |
} |
155 |
|
156 |
private static final String PAGE_NAME= "FatJarPackageWizardPage"; //$NON-NLS-1$ |
157 |
private static final String STORE_LAUNCH_CONFIGURATION_SELECTION_NAME= PAGE_NAME + ".LAUNCH_CONFIGURATION_SELECTION_NAME"; //$NON-NLS-1$ |
158 |
private static final String STORE_DESTINATION_ELEMENT= PAGE_NAME + ".DESTINATION_PATH_SELECTION"; //$NON-NLS-1$ |
159 |
|
160 |
private final JarPackageData fJarPackage; |
161 |
/** |
162 |
* Model for the launch combo box. Element: {@link LaunchConfigurationElement} |
163 |
*/ |
164 |
private final ArrayList fLauchConfigurationModel; |
165 |
|
166 |
private Combo fLaunchConfigurationCombo; |
167 |
|
168 |
public FatJarPackageWizardPage(JarPackageData jarPackage) { |
169 |
super(PAGE_NAME, StructuredSelection.EMPTY, jarPackage); |
170 |
setTitle(FatJarPackagerMessages.JarPackageWizardPage_title); |
171 |
setDescription(FatJarPackagerMessages.FatJarPackageWizardPage_description); |
172 |
fJarPackage= jarPackage; |
173 |
fLauchConfigurationModel= new ArrayList(); |
174 |
} |
175 |
|
176 |
/** |
177 |
* {@inheritDoc} |
178 |
*/ |
179 |
public void createControl(Composite parent) { |
180 |
Composite composite= new Composite(parent, SWT.NONE); |
181 |
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
182 |
composite.setLayout(new GridLayout(1, false)); |
183 |
|
184 |
Label description= new Label(composite, SWT.NONE); |
185 |
GridData gridData= new GridData(SWT.BEGINNING, SWT.CENTER, false, false); |
186 |
description.setLayoutData(gridData); |
187 |
description.setText(FatJarPackagerMessages.FatJarPackageWizardPage_launchConfigGroupTitle); |
188 |
|
189 |
createLaunchConfigSelectionGroup(composite); |
190 |
|
191 |
Label label= new Label(composite, SWT.NONE); |
192 |
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); |
193 |
label.setText(FatJarPackagerMessages.FatJarPackageWizardPage_destinationGroupTitle); |
194 |
|
195 |
createDestinationGroup(composite); |
196 |
|
197 |
restoreWidgetValues(); |
198 |
|
199 |
update(); |
200 |
|
201 |
Dialog.applyDialogFont(composite); |
202 |
setControl(composite); |
203 |
} |
204 |
|
205 |
protected String getDestinationLabel() { |
206 |
return null; |
207 |
} |
208 |
|
209 |
private void createLaunchConfigSelectionGroup(Composite parent) { |
210 |
Composite composite= new Composite(parent, SWT.NONE); |
211 |
composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); |
212 |
composite.setLayout(new GridLayout(1, false)); |
213 |
|
214 |
fLaunchConfigurationCombo= new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); |
215 |
fLaunchConfigurationCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
216 |
|
217 |
fLauchConfigurationModel.addAll(Arrays.asList(getLaunchConfigurations())); |
218 |
String[] names= new String[fLauchConfigurationModel.size()]; |
219 |
for (int i= 0, size= fLauchConfigurationModel.size(); i < size; i++) { |
220 |
LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(i); |
221 |
names[i]= element.getLaunchConfigurationName(); |
222 |
} |
223 |
fLaunchConfigurationCombo.setItems(names); |
224 |
|
225 |
fLaunchConfigurationCombo.addListener(SWT.Selection, this); |
226 |
fLaunchConfigurationCombo.addListener(SWT.Modify, this); |
227 |
} |
228 |
|
229 |
protected void updateWidgetEnablements() { |
230 |
} |
231 |
|
232 |
public boolean isPageComplete() { |
233 |
boolean complete= validateDestinationGroup(); |
234 |
complete= validateLaunchConfigurationGroup() && complete; |
235 |
if (complete) |
236 |
setErrorMessage(null); |
237 |
return complete; |
238 |
} |
239 |
|
240 |
private boolean validateLaunchConfigurationGroup() { |
241 |
return fLaunchConfigurationCombo.getSelectionIndex() != -1; |
242 |
} |
243 |
|
244 |
private LaunchConfigurationElement[] getLaunchConfigurations() { |
245 |
ArrayList result= new ArrayList(); |
246 |
|
247 |
HashSet projectNamesWithLaunchConfig= new HashSet(); |
248 |
try { |
249 |
ILaunchConfiguration[] launchconfigs= DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(); |
250 |
|
251 |
for (int i= 0; i < launchconfigs.length; i++) { |
252 |
ILaunchConfiguration launchconfig= launchconfigs[i]; |
253 |
|
254 |
String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ |
255 |
result.add(new ExistingLaunchConfigurationElement(launchconfig, projectName)); |
256 |
projectNamesWithLaunchConfig.add(projectName); |
257 |
} |
258 |
} catch (CoreException e) { |
259 |
JavaPlugin.log(e); |
260 |
} |
261 |
|
262 |
IJavaProject[] javaProjects= getJavaProjects(); |
263 |
for (int i= 0; i < javaProjects.length; i++) { |
264 |
if (!projectNamesWithLaunchConfig.contains(javaProjects[i].getElementName())) { |
265 |
result.add(new DefaultLaunchConfigurationElement(javaProjects[i])); |
266 |
} |
267 |
} |
268 |
|
269 |
return (LaunchConfigurationElement[]) result.toArray(new LaunchConfigurationElement[result.size()]); |
270 |
} |
271 |
|
272 |
private IJavaProject[] getJavaProjects() { |
273 |
ArrayList result= new ArrayList(); |
274 |
|
275 |
IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); |
276 |
for (int i= 0; i < projects.length; i++) { |
277 |
IJavaProject javaProject= JavaCore.create(projects[i]); |
278 |
if (javaProject != null && javaProject.exists()) { |
279 |
result.add(javaProject); |
280 |
} |
281 |
} |
282 |
|
283 |
return (IJavaProject[]) result.toArray(new IJavaProject[result.size()]); |
284 |
} |
285 |
|
286 |
public Object[] getSelectedElementsWithoutContainedChildren() { |
287 |
try { |
288 |
LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(fLaunchConfigurationCombo.getSelectionIndex()); |
289 |
ILaunchConfiguration launchconfig= element.getLaunchConfiguration(); |
290 |
fJarPackage.setLaunchConfigurationName(element.getLaunchConfigurationName()); |
291 |
|
292 |
return getSelectedElementsWithoutContainedChildren(launchconfig, fJarPackage, getContainer()); |
293 |
} catch (CoreException e) { |
294 |
JavaPlugin.log(e); |
295 |
} |
296 |
|
297 |
return null; |
298 |
} |
299 |
|
300 |
private static String[] getProjectSearchOrder(String projectName) { |
301 |
|
302 |
ArrayList result= new ArrayList(); |
303 |
result.add(projectName); |
304 |
|
305 |
int nextProject= 0; |
306 |
while (nextProject < result.size()) { |
307 |
String nextProjectName= (String) result.get(nextProject); |
308 |
IJavaProject jproject= getJavaProject(nextProjectName); |
309 |
|
310 |
if (jproject != null) { |
311 |
try { |
312 |
String[] childProjectNames= jproject.getRequiredProjectNames(); |
313 |
for (int i= 0; i < childProjectNames.length; i++) { |
314 |
if (!result.contains(childProjectNames[i])) { |
315 |
result.add(childProjectNames[i]); |
316 |
} |
317 |
} |
318 |
} catch (JavaModelException e) { |
319 |
JavaPlugin.log(e); |
320 |
} |
321 |
} |
322 |
nextProject+= 1; |
323 |
} |
324 |
|
325 |
return (String[]) result.toArray(new String[result.size()]); |
326 |
} |
327 |
|
328 |
private static IJavaProject getJavaProject(String projectName) { |
329 |
IJavaProject result= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName)); |
330 |
if (result == null) |
331 |
return null; |
332 |
|
333 |
if (!result.exists()) |
334 |
return null; |
335 |
|
336 |
return result; |
337 |
} |
338 |
|
339 |
private static String[] getClasspath(ILaunchConfiguration configuration) throws CoreException { |
340 |
IRuntimeClasspathEntry[] entries= JavaRuntime.computeUnresolvedRuntimeClasspath(configuration); |
341 |
entries= JavaRuntime.resolveRuntimeClasspath(entries, configuration); |
342 |
List userEntries= new ArrayList(entries.length); |
343 |
for (int i= 0; i < entries.length; i++) { |
344 |
if (entries[i].getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) { |
345 |
String location= entries[i].getLocation(); |
346 |
if (location != null) { |
347 |
userEntries.add(location); |
348 |
} |
349 |
} |
350 |
} |
351 |
return (String[]) userEntries.toArray(new String[userEntries.size()]); |
352 |
} |
353 |
|
354 |
private static String getMainClass(ILaunchConfiguration launchConfig) { |
355 |
String result= null; |
356 |
if (launchConfig != null) { |
357 |
try { |
358 |
result= launchConfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String) null); |
359 |
} catch (CoreException ignore) { |
360 |
} |
361 |
} |
362 |
if (result == null) { |
363 |
result= ""; //$NON-NLS-1$ |
364 |
} |
365 |
return result; |
366 |
} |
367 |
|
368 |
private static IPackageFragmentRoot[] getRequiredPackageFragmentRoots(final String[] classpathEntries, final String[] projectNames) { |
369 |
ArrayList result= new ArrayList(); |
370 |
|
371 |
for (int i= 0; i < classpathEntries.length; i++) { |
372 |
String path= classpathEntries[i]; |
373 |
IPackageFragmentRoot[] elements= findRootsForClasspath(path, projectNames); |
374 |
if (elements.length == 0) { |
375 |
JavaPlugin.log(new Status(IStatus.WARNING, JavaUI.ID_PLUGIN, Messages.format(FatJarPackagerMessages.FatJarPackageWizardPage_error_missingClassFile, path))); |
376 |
} |
377 |
|
378 |
for (int j= 0; j < elements.length; j++) { |
379 |
result.add(elements[j]); |
380 |
} |
381 |
} |
382 |
|
383 |
return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]); |
384 |
} |
385 |
|
386 |
private static IPackageFragmentRoot[] findRootsForClasspath(String path, String[] projectNames) { |
387 |
|
388 |
path= path.replace('\\', '/'); |
389 |
for (int i= 0; i < projectNames.length; i++) { |
390 |
IJavaProject javaProject= getJavaProject(projectNames[i]); |
391 |
if (javaProject != null) { |
392 |
IPackageFragmentRoot[] elements= findRootsInProject(path, javaProject); |
393 |
if (elements.length > 0) { |
394 |
return elements; |
395 |
} |
396 |
} |
397 |
} |
398 |
return new IPackageFragmentRoot[0]; |
399 |
} |
400 |
|
401 |
private static IPackageFragmentRoot[] findRootsInProject(String path, IJavaProject project) { |
402 |
ArrayList result= new ArrayList(); |
403 |
|
404 |
try { |
405 |
IPackageFragmentRoot[] roots= project.getPackageFragmentRoots(); |
406 |
for (int i= 0; i < roots.length; i++) { |
407 |
IPackageFragmentRoot packageFragmentRoot= roots[i]; |
408 |
if (isRootAt(packageFragmentRoot, path)) |
409 |
result.add(packageFragmentRoot); |
410 |
} |
411 |
} catch (Exception e) { |
412 |
JavaPlugin.log(e); |
413 |
} |
414 |
|
415 |
return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]); |
416 |
} |
417 |
|
418 |
private static boolean isRootAt(IPackageFragmentRoot pfr, String path) { |
419 |
try { |
420 |
IClasspathEntry cpe= pfr.getRawClasspathEntry(); |
421 |
if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { |
422 |
IPath relIPath= pfr.getJavaProject().getOutputLocation(); |
423 |
IPath iPath= pfr.getJavaModel().getWorkspace().getRoot().findMember(relIPath, true).getLocation(); |
424 |
if (iPath != null) { |
425 |
String strPath= iPath.toString(); |
426 |
if (path.equals(strPath)) { |
427 |
return true; |
428 |
} |
429 |
} |
430 |
} |
431 |
} catch (JavaModelException e) { |
432 |
JavaPlugin.log(e); |
433 |
} |
434 |
|
435 |
IResource res= pfr.getResource(); |
436 |
if (res != null) { |
437 |
IPath iPath= res.getLocation(); |
438 |
if (iPath != null) { |
439 |
String strPath= iPath.toString(); |
440 |
if (path.equals(strPath)) { |
441 |
return true; |
442 |
} |
443 |
} |
444 |
} |
445 |
|
446 |
IPath iPath= pfr.getPath(); |
447 |
if (iPath != null) { |
448 |
String strPath= iPath.toString(); |
449 |
if (path.equals(strPath)) { |
450 |
return true; |
451 |
} |
452 |
} |
453 |
|
454 |
return false; |
455 |
} |
456 |
|
457 |
private static IType findMainMethodByName(String name, IPackageFragmentRoot[] classpathResources, IRunnableContext context) throws CoreException { |
458 |
|
459 |
List resources= JarPackagerUtil.asResources(classpathResources); |
460 |
if (resources == null) |
461 |
throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, FatJarPackagerMessages.FatJarPackageWizardPage_error_noMainMethod)); |
462 |
|
463 |
for (Iterator iterator= resources.iterator(); iterator.hasNext();) { |
464 |
IResource element= (IResource) iterator.next(); |
465 |
if (element == null) |
466 |
iterator.remove(); |
467 |
} |
468 |
|
469 |
IJavaSearchScope searchScope= JavaSearchScopeFactory.getInstance().createJavaSearchScope((IResource[]) resources.toArray(new IResource[resources.size()]), true); |
470 |
MainMethodSearchEngine engine= new MainMethodSearchEngine(); |
471 |
try { |
472 |
IType[] mainTypes= engine.searchMainMethods(context, searchScope, 0); |
473 |
for (int i= 0; i < mainTypes.length; i++) { |
474 |
if (mainTypes[i].getFullyQualifiedName().equals(name)) |
475 |
return mainTypes[i]; |
476 |
} |
477 |
} catch (InvocationTargetException ex) { |
478 |
JavaPlugin.log(ex); |
479 |
} catch (InterruptedException e) { |
480 |
// null |
481 |
} |
482 |
|
483 |
return null; |
484 |
} |
485 |
|
486 |
public void dispose() { |
487 |
super.dispose(); |
488 |
if (fLauchConfigurationModel != null) { |
489 |
for (int i= 0, size= fLauchConfigurationModel.size(); i < size; i++) { |
490 |
LaunchConfigurationElement element= (LaunchConfigurationElement) fLauchConfigurationModel.get(i); |
491 |
element.dispose(); |
492 |
} |
493 |
} |
494 |
} |
495 |
|
496 |
protected void restoreWidgetValues() { |
497 |
|
498 |
IDialogSettings settings= getDialogSettings(); |
499 |
if (settings != null) { |
500 |
String name= settings.get(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME); |
501 |
if (name != null) { |
502 |
String[] items= fLaunchConfigurationCombo.getItems(); |
503 |
for (int i= 0; i < items.length; i++) { |
504 |
if (name.equals(items[i])) { |
505 |
fLaunchConfigurationCombo.select(i); |
506 |
} |
507 |
} |
508 |
} |
509 |
|
510 |
String destinationPath= settings.get(STORE_DESTINATION_ELEMENT); |
511 |
if (destinationPath != null && destinationPath.length() > 0) { |
512 |
fJarPackage.setJarLocation(Path.fromOSString(destinationPath)); |
513 |
} |
514 |
} |
515 |
|
516 |
super.restoreWidgetValues(); |
517 |
} |
518 |
|
519 |
/** |
520 |
* {@inheritDoc} |
521 |
*/ |
522 |
protected void saveWidgetValues() { |
523 |
super.saveWidgetValues(); |
524 |
|
525 |
IDialogSettings settings= getDialogSettings(); |
526 |
if (settings != null) { |
527 |
int index= fLaunchConfigurationCombo.getSelectionIndex(); |
528 |
if (index == -1) { |
529 |
settings.put(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME, ""); //$NON-NLS-1$ |
530 |
} else { |
531 |
String selectedItem= fLaunchConfigurationCombo.getItem(index); |
532 |
settings.put(STORE_LAUNCH_CONFIGURATION_SELECTION_NAME, selectedItem); |
533 |
} |
534 |
|
535 |
IPath location= fJarPackage.getJarLocation(); |
536 |
if (location == null) { |
537 |
settings.put(STORE_DESTINATION_ELEMENT, ""); //$NON-NLS-1$ |
538 |
} else { |
539 |
settings.put(STORE_DESTINATION_ELEMENT, location.toOSString()); |
540 |
} |
541 |
} |
542 |
} |
543 |
|
544 |
/* |
545 |
* For internal use only (testing), clients must not call. |
546 |
*/ |
547 |
public static Object[] getSelectedElementsWithoutContainedChildren(ILaunchConfiguration launchconfig, JarPackageData data, IRunnableContext context) throws CoreException { |
548 |
if (launchconfig == null) |
549 |
return new Object[0]; |
550 |
|
551 |
String projectName= launchconfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ |
552 |
|
553 |
String[] searchOrder= getProjectSearchOrder(projectName); |
554 |
String[] classpath= getClasspath(launchconfig); |
555 |
IPackageFragmentRoot[] classpathResources= getRequiredPackageFragmentRoots(classpath, searchOrder); |
556 |
|
557 |
String mainClass= getMainClass(launchconfig); |
558 |
data.setManifestMainClass(findMainMethodByName(mainClass, classpathResources, context)); |
559 |
|
560 |
return classpathResources; |
561 |
} |
562 |
|
563 |
/* |
564 |
* From org.eclipse.jdt.internal.debug.ui.launcher.JavaApplicationLaunchShortcut |
565 |
* |
566 |
* For internal use only (testing), clients must not call. |
567 |
*/ |
568 |
public static ILaunchConfiguration createTempLaunchConfig(IJavaProject project) { |
569 |
String projectName= project.getElementName(); |
570 |
|
571 |
String configname= "fatjar_cfg_eraseme_" + projectName; //$NON-NLS-1$ |
572 |
ILaunchConfiguration config= null; |
573 |
ILaunchConfigurationWorkingCopy wc= null; |
574 |
try { |
575 |
ILaunchManager launchManager= DebugPlugin.getDefault().getLaunchManager(); |
576 |
ILaunchConfigurationType configType= launchManager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION); |
577 |
wc= configType.newInstance(null, launchManager.generateUniqueLaunchConfigurationNameFrom(configname)); |
578 |
} catch (CoreException e) { |
579 |
JavaPlugin.log(e); |
580 |
return null; |
581 |
} |
582 |
|
583 |
//TODO |
584 |
// IType[] mainTypes= findMainTypes(project); |
585 |
// if (mainTypes.length == 1) |
586 |
// wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, mainTypes[0].getElementName()); |
587 |
|
588 |
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName); |
589 |
try { |
590 |
config= wc.doSave(); |
591 |
} catch (CoreException e) { |
592 |
JavaPlugin.log(e); |
593 |
} |
594 |
|
595 |
return config; |
596 |
} |
597 |
|
598 |
} |