1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.eclipse.common.launch; |
17 | |
|
18 | |
import org.eclipse.core.runtime.CoreException; |
19 | |
import org.eclipse.debug.core.DebugPlugin; |
20 | |
import org.eclipse.debug.core.ILaunchConfiguration; |
21 | |
import org.eclipse.debug.core.ILaunchConfigurationType; |
22 | |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
23 | |
import org.eclipse.debug.core.ILaunchManager; |
24 | |
import org.seasar.eclipse.common.CommonPlugin; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 0 | public class LaunchConfigurationFactory { |
31 | |
|
32 | |
public static ILaunchConfiguration create(CreationHandler handler) { |
33 | 0 | ILaunchConfiguration config = null; |
34 | |
try { |
35 | 0 | ILaunchManager manager = DebugPlugin.getDefault() |
36 | |
.getLaunchManager(); |
37 | 0 | ILaunchConfigurationType type = manager |
38 | |
.getLaunchConfigurationType(handler.getTypeName()); |
39 | 0 | ILaunchConfiguration[] configs = manager |
40 | |
.getLaunchConfigurations(type); |
41 | 0 | for (ILaunchConfiguration element : configs) { |
42 | 0 | if (element.getName().equals(handler.getConfigName())) { |
43 | 0 | if (handler.equals(element)) { |
44 | 0 | config = element; |
45 | |
} else { |
46 | 0 | element.delete(); |
47 | |
} |
48 | 0 | break; |
49 | |
} |
50 | |
} |
51 | 0 | if (config == null) { |
52 | 0 | ILaunchConfigurationWorkingCopy copy = type.newInstance(null, |
53 | |
handler.getConfigName()); |
54 | 0 | handler.setUp(copy); |
55 | 0 | config = copy.doSave(); |
56 | |
} |
57 | 0 | } catch (CoreException e) { |
58 | 0 | CommonPlugin.log(e); |
59 | 0 | } |
60 | 0 | return config; |
61 | |
} |
62 | |
|
63 | 0 | public interface CreationHandler { |
64 | |
|
65 | |
String getTypeName(); |
66 | |
|
67 | |
String getConfigName(); |
68 | |
|
69 | |
boolean equals(ILaunchConfiguration config); |
70 | |
|
71 | |
void setUp(ILaunchConfigurationWorkingCopy config); |
72 | |
} |
73 | |
} |