Skip to content

Commit d55a82b

Browse files
author
Paul Verest
committed
gradle jettyEclipseRun
1 parent 49579f1 commit d55a82b

File tree

6 files changed

+238
-1
lines changed

6 files changed

+238
-1
lines changed

org.nodeclipse.enide.gradle/plugin.xml

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
class= "org.nodeclipse.enide.gradle.launch.jetty.LaunchShortcut"
9595
icon= "icons/gradle-icon-16x16_bottom_right_corner_run_half_size.png"
9696
id= "org.nodeclipse.enide.gradle.launch.jetty.LaunchShortcut"
97-
label= "gradle jetty:run Gradle start"
97+
label= "gradle jettyRun Gradle start"
9898
modes= "run" >
9999
<configurationType
100100
id= "org.nodeclipse.enide.gradle.launch.jetty.LaunchConfigurationType" >
@@ -120,6 +120,64 @@
120120
</shortcut>
121121
</extension>
122122

123+
<!-- for gradle jettyEclipseRun -->
124+
<extension
125+
point="org.eclipse.debug.core.launchConfigurationTypes">
126+
<launchConfigurationType
127+
delegate="org.nodeclipse.enide.gradle.launch.jettyeclipse.LaunchConfigurationDelegate"
128+
id="org.nodeclipse.enide.gradle.launch.jettyeclipse.LaunchConfigurationType"
129+
modes="run"
130+
name="gradle jettyEclipseRun">
131+
</launchConfigurationType>
132+
</extension>
133+
<extension
134+
point= "org.eclipse.debug.ui.launchConfigurationTypeImages" >
135+
<launchConfigurationTypeImage
136+
configTypeID= "org.nodeclipse.enide.gradle.launch.jettyeclipse.LaunchConfigurationType"
137+
icon= "icons/gradle-icon-16x16.png"
138+
id= "org.nodeclipse.enide.gradle.launch.jettyeclipse.LaunchConfigurationTypeImage" >
139+
</launchConfigurationTypeImage>
140+
</extension>
141+
<extension
142+
point="org.eclipse.debug.ui.launchConfigurationTabGroups">
143+
<launchConfigurationTabGroup
144+
class= "org.nodeclipse.enide.gradle.launch.jettyeclipse.LaunchConfigurationTabGroup"
145+
id= "org.nodeclipse.enide.gradle.launch.jettyeclipse.LaunchConfigurationTabGroup"
146+
type= "org.nodeclipse.enide.gradle.launch.jettyeclipse.LaunchConfigurationType" >
147+
</launchConfigurationTabGroup>
148+
</extension>
149+
<!-- build.gradle run as gradle jettyEclipseRun -->
150+
<extension
151+
point= "org.eclipse.debug.ui.launchShortcuts" >
152+
<shortcut
153+
class= "org.nodeclipse.enide.gradle.launch.jettyeclipse.LaunchShortcut"
154+
icon= "icons/gradle-icon-16x16_bottom_right_corner_run_half_size.png"
155+
id= "org.nodeclipse.enide.gradle.launch.jettyeclipse.LaunchShortcut"
156+
label= "gradle jettyEclipseRun Gradle start"
157+
modes= "run" >
158+
<configurationType
159+
id= "org.nodeclipse.enide.gradle.launch.jettyeclipse.LaunchConfigurationType" >
160+
</configurationType>
161+
<contextualLaunch>
162+
<enablement>
163+
<with
164+
variable= "selection" >
165+
<count
166+
value= "1" >
167+
</count>
168+
<iterate>
169+
<or>
170+
<test
171+
property= "org.eclipse.debug.ui.matchesPattern"
172+
value= "*.gradle" >
173+
</test>
174+
</or>
175+
</iterate>
176+
</with>
177+
</enablement>
178+
</contextualLaunch>
179+
</shortcut>
180+
</extension>
123181

124182

125183
<!-- for GUI -->
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.nodeclipse.enide.gradle.launch.jettyeclipse;
2+
3+
import java.util.List;
4+
5+
import org.eclipse.core.runtime.CoreException;
6+
import org.eclipse.debug.core.ILaunchConfiguration;
7+
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
8+
import org.eclipse.jface.preference.IPreferenceStore;
9+
10+
/**
11+
* `build.gradle` Run As Gradle GUI<br>
12+
* http://www.gradle.org/docs/current/userguide/web_project_tutorial.html
13+
*
14+
* @since 0.11
15+
* @author Paul Verest
16+
*/
17+
public class LaunchConfigurationDelegate
18+
extends org.nodeclipse.enide.gradle.launch.LaunchConfigurationDelegate
19+
implements ILaunchConfigurationDelegate {
20+
21+
@Override
22+
protected void specialOptions(ILaunchConfiguration configuration,
23+
IPreferenceStore preferenceStore, List<String> cmdLine) throws CoreException {
24+
cmdLine.add("jettyEclipseRun");
25+
}
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.nodeclipse.enide.gradle.launch.jettyeclipse;
2+
3+
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
4+
import org.eclipse.debug.ui.CommonTab;
5+
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
6+
import org.eclipse.debug.ui.ILaunchConfigurationTab;
7+
//import org.nodeclipse.debug.launch.LaunchConfigurationEnvironmentTab;
8+
9+
10+
/**
11+
* Using "Run"-->"Run Configurations"--> "New Configuration"-- > "Run" will lead
12+
* here.
13+
* @author Paul Verest
14+
**/
15+
public class LaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup {
16+
17+
@Override
18+
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
19+
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
20+
// new LaunchConfigurationMainTab(),
21+
// new NodeArgumentsTab(),
22+
// new LaunchConfigurationEnvironmentTab(),
23+
new CommonTab()
24+
};
25+
setTabs(tabs);
26+
}
27+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.nodeclipse.enide.gradle.launch.jettyeclipse;
2+
3+
public class LaunchConfigurationType {
4+
5+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package org.nodeclipse.enide.gradle.launch.jettyeclipse;
2+
3+
import org.eclipse.core.resources.IFile;
4+
import org.eclipse.core.runtime.CoreException;
5+
import org.eclipse.debug.core.DebugPlugin;
6+
import org.eclipse.debug.core.ILaunchConfiguration;
7+
import org.eclipse.debug.core.ILaunchConfigurationType;
8+
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
9+
import org.eclipse.debug.core.ILaunchManager;
10+
import org.eclipse.debug.ui.DebugUITools;
11+
import org.eclipse.debug.ui.ILaunchShortcut;
12+
import org.eclipse.jface.dialogs.MessageDialog;
13+
import org.eclipse.jface.viewers.ISelection;
14+
import org.eclipse.jface.viewers.IStructuredSelection;
15+
import org.eclipse.ui.IEditorPart;
16+
import org.eclipse.ui.IEditorInput;
17+
import org.eclipse.ui.IFileEditorInput;
18+
import org.nodeclipse.enide.gradle.preferences.GradleConstants;
19+
import org.nodeclipse.enide.gradle.util.NodeclipseLogger;
20+
//import org.nodeclipse.ui.util.NodeclipseConsole;
21+
22+
/**
23+
* Using "Run As" --> "gradle jettyRun" will lead here
24+
**/
25+
public class LaunchShortcut implements ILaunchShortcut {
26+
27+
/**
28+
* (non-Javadoc)
29+
*
30+
* @see org.eclipse.debug.ui.ILaunchShortcut#launch(org.eclipse.jface.viewers
31+
* .ISelection, java.lang.String)
32+
**/
33+
@Override
34+
public void launch(ISelection selection, String mode) {
35+
try {
36+
Object selectObj = ((IStructuredSelection) selection).getFirstElement();
37+
if (selectObj instanceof IFile) {
38+
launchFile((IFile) selectObj, mode);
39+
} else {
40+
MessageDialog.openWarning(null, "Warning", "Not implemeneted yet!");
41+
}
42+
} catch (CoreException e) {
43+
//NodeclipseConsole.write(e.getLocalizedMessage()+"\n");
44+
NodeclipseLogger.log(e.getLocalizedMessage()+"\n");
45+
}
46+
}
47+
48+
/**
49+
* (non-Javadoc)
50+
*
51+
* @see org.eclipse.debug.ui.ILaunchShortcut#launch(org.eclipse.ui.IEditorPart,
52+
* java.lang.String)
53+
**/
54+
@Override
55+
public void launch(IEditorPart editor, String mode) {
56+
try {
57+
IEditorInput editorInput = editor.getEditorInput();
58+
if (editorInput instanceof IFileEditorInput) {
59+
IFile selectObj = ((IFileEditorInput) editorInput).getFile();
60+
launchFile((IFile) selectObj, mode);
61+
} else {
62+
MessageDialog.openWarning(null, "Warning", "Not implemeneted yet!");
63+
}
64+
} catch (CoreException e) {
65+
//NodeclipseConsole.write(e.getLocalizedMessage()+"\n");
66+
NodeclipseLogger.log(e.getLocalizedMessage()+"\n");
67+
}
68+
}
69+
70+
/**
71+
* Launch an file,using the file information, which means using default
72+
* launch configurations.
73+
*
74+
* @param file
75+
* @param mode
76+
*/
77+
private void launchFile(IFile file, String mode) throws CoreException {
78+
// check for an existing launch config for the file
79+
String path = file.getFullPath().toString();
80+
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
81+
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(GradleConstants.LAUNCH_JETTYECLIPSE_CONFIGURATION_TYPE_ID);
82+
ILaunchConfiguration configuration = createLaunchConfiguration(type, path, file);
83+
DebugUITools.launch(configuration, mode);
84+
// then execution goes in LaunchConfigurationDelegate.java launch() method
85+
}
86+
87+
/**
88+
* Create a new configuration and set useful data.
89+
*
90+
* @param type
91+
* @param path
92+
* @param file
93+
* @return
94+
* @throws CoreException
95+
*/
96+
private ILaunchConfiguration createLaunchConfiguration(ILaunchConfigurationType type, String path, IFile file) throws CoreException {
97+
String configname = file.getFullPath().toString().replace('/', '-');
98+
if(configname.startsWith("-")) {
99+
configname = configname.substring(1);
100+
}
101+
102+
ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(type);
103+
for(ILaunchConfiguration config : configs) {
104+
if(configname.equals(config.getName())) {
105+
return config;
106+
}
107+
}
108+
109+
// create a new configuration for the file
110+
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, configname);
111+
workingCopy.setAttribute(GradleConstants.KEY_FILE_PATH, path);
112+
setMoreAttributes(workingCopy);
113+
return workingCopy.doSave();
114+
}
115+
116+
protected void setMoreAttributes(ILaunchConfigurationWorkingCopy workingCopy) {
117+
//NodeclipseConsole.write(this.getClass().getName()+"\n");
118+
NodeclipseLogger.log(this.getClass().getName()+"\n");
119+
}
120+
}

org.nodeclipse.enide.gradle/src/org/nodeclipse/enide/gradle/preferences/GradleConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public class GradleConstants {
55
public static final String PLUGIN_ID = "org.nodeclipse.enide.gradle";
66
public static final String LAUNCH_CONFIGURATION_TYPE_ID = "org.nodeclipse.enide.gradle.launch.LaunchConfigurationType";
77
public static final String LAUNCH_JETTY_CONFIGURATION_TYPE_ID = "org.nodeclipse.enide.gradle.launch.jetty.LaunchConfigurationType";
8+
public static final String LAUNCH_JETTYECLIPSE_CONFIGURATION_TYPE_ID = "org.nodeclipse.enide.gradle.launch.jettyeclipse.LaunchConfigurationType";
89
public static final String LAUNCHGUI_CONFIGURATION_TYPE_ID = "org.nodeclipse.enide.gradle.launchgui.LaunchConfigurationType";
910

1011
public static final String PROCESS_MESSAGE = "Gradle Process";

0 commit comments

Comments
 (0)