Skip to content

Commit

Permalink
#117 run with mvn, gradle (had to add Preferences to full path); Gradle
Browse files Browse the repository at this point in the history
still has problem
  • Loading branch information
paulvi committed Jan 17, 2014
1 parent 76e798e commit b519fe9
Show file tree
Hide file tree
Showing 15 changed files with 542 additions and 32 deletions.
60 changes: 51 additions & 9 deletions org.nodeclipse.enide.gradle/plugin.xml
Expand Up @@ -19,13 +19,54 @@
id= "org.nodeclipse.enide.gradle.launch.LaunchConfigurationTypeImage" >
</launchConfigurationTypeImage>
</extension>
<!-- build.gradle run as gradle -->
<extension
point="org.eclipse.debug.ui.launchConfigurationTabGroups">
<launchConfigurationTabGroup
class= "org.nodeclipse.enide.gradle.launch.LaunchConfigurationTabGroup"
id= "org.nodeclipse.enide.gradle.launch.LaunchConfigurationTabGroup"
type= "org.nodeclipse.enide.gradle.launch.LaunchConfigurationType" >
</launchConfigurationTabGroup>
</extension>

<!-- build.gradle run as gradle build -->
<extension
point= "org.eclipse.debug.ui.launchShortcuts" >
<shortcut
class= "org.nodeclipse.enide.gradle.launch.LaunchShortcut"
icon= "icons/gradle-icon-16x16_bottom_right_corner_run_half_size.png"
id= "org.nodeclipse.enide.gradle.launch.LaunchShortcut"
label= "gradle build"
modes= "run" >
<configurationType
id= "org.nodeclipse.enide.gradle.launch.LaunchConfigurationType" >
</configurationType>
<contextualLaunch>
<enablement>
<with
variable= "selection" >
<count
value= "1" >
</count>
<iterate>
<or>
<test
property= "org.eclipse.debug.ui.matchesPattern"
value= "*.gradle" >
</test>
</or>
</iterate>
</with>
</enablement>
</contextualLaunch>
</shortcut>
</extension>
<!-- build.gradle run as Gradle GUI -->
<extension
point= "org.eclipse.debug.ui.launchShortcuts" >
<shortcut
class= "org.nodeclipse.enide.gradle.launchgui.LaunchShortcut"
icon= "icons/gradle-icon-16x16_bottom_right_corner_run_half_size.png"
id= "org.nodeclipse.enide.gradle.launchgui.LaunchShortcut"
label= "Gradle GUI"
modes= "run" >
<configurationType
Expand Down Expand Up @@ -53,14 +94,6 @@
</extension>


<extension
point="org.eclipse.debug.ui.launchConfigurationTabGroups">
<launchConfigurationTabGroup
class= "org.nodeclipse.enide.gradle.launch.LaunchConfigurationTabGroup"
id= "org.nodeclipse.enide.gradle.launch.LaunchConfigurationTabGroup"
type= "org.nodeclipse.enide.gradle.launch.LaunchConfigurationType" >
</launchConfigurationTabGroup>
</extension>

<extension
point="org.eclipse.help.toc">
Expand All @@ -70,4 +103,13 @@
</toc>
</extension>

<extension
point="org.eclipse.ui.preferencePages">
<page
class="org.nodeclipse.enide.gradle.preferences.GradlePreferencePage"
id="org.nodeclipse.enide.gradle.preferences.GradlePreferencePage"
name="Gradle(Nodeclipse)">
</page>
</extension>

</plugin>
Expand Up @@ -15,6 +15,7 @@
//import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.debug.core.model.RuntimeProcess;
import org.eclipse.jface.preference.IPreferenceStore;
//import org.eclipse.jface.preference.IPreferenceStore;
//import org.nodeclipse.debug.util.Constants;
//import org.nodeclipse.debug.util.VariablesUtil;
Expand All @@ -24,9 +25,11 @@
//import org.nodeclipse.ui.util.NodeclipseConsole;
import org.nodeclipse.enide.gradle.preferences.GradleConstants;
import org.nodeclipse.enide.gradle.util.VariablesUtil;
import org.nodeclipse.enide.gradle.Activator;
import org.nodeclipse.enide.gradle.preferences.Dialogs;

/**
* `build.gradle` Run As Gradle GUI<br>
* `build.gradle` Run As gradle build<br>
* see LaunchConfigurationDelegate in .debug and .phantomjs, .jjs, .enide.maven module for comparison.
*
* @since 0.10
Expand All @@ -38,20 +41,32 @@ public class LaunchConfigurationDelegate implements ILaunchConfigurationDelegate
public void launch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {

IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();

// Using configuration to build command line
List<String> cmdLine = new ArrayList<String>();

//TODO preferences
cmdLine.add("gradle");
// Gradle installation path should be stored in preference.
String gradlePath= preferenceStore.getString(GradleConstants.GRADLE_PATH);
// Check if the maven location is correctly configured
File mavenFile = new File(gradlePath);
if(!mavenFile.exists()){
// If the location is not valid than show a dialog which prompts the user to goto the preferences page
Dialogs.showPreferencesDialog(GradleConstants.PREFERENCES_PAGE,
"Gradle installation is not correctly configured.\n\n"
+ "Please goto Window -> Preferences -> "+GradleConstants.PREFERENCE_PAGE_NAME
+" and configure the correct location");
return;
}
cmdLine.add(gradlePath);

String file = configuration.getAttribute(GradleConstants.KEY_FILE_PATH, "");
String filePath = ResourcesPlugin.getWorkspace().getRoot().findMember(file).getLocation().toOSString();
// path is relative, so cannot find it, unless get absolute path
cmdLine.add("-b"); // -b, --build-file Specifies the build file.

cmdLine.add(filePath);
cmdLine.add("--gui");
cmdLine.add("build");

String workingDirectory = configuration.getAttribute(GradleConstants.ATTR_WORKING_DIRECTORY, "");
File workingPath = null;
Expand All @@ -68,12 +83,27 @@ public void launch(ILaunchConfiguration configuration, String mode,

Map<String, String> envm = new HashMap<String, String>();
envm = configuration.getAttribute(GradleConstants.ATTR_ENVIRONMENT_VARIABLES, envm);
String[] envp = new String[envm.size()];
String[] envp = new String[envm.size()+2];
int idx = 0;
for(String key : envm.keySet()) {
String value = envm.get(key);
envp[idx++] = key + "=" + value;
}
//ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
//
//Please set the JAVA_HOME variable in your environment to match the
//location of your Java installation.
envp[idx++] = "JAVA_HOME=" + System.getProperty("java.home"); //System.getenv("JAVA_HOME");
envp[idx++] = "GRADLE_HOME=" + System.getenv("GRADLE_HOME");

//FAILURE: Build failed with an exception.
//
//* What went wrong:
//java.lang.ExceptionInInitializerError (no error message)
//
//* Try:
//Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.



// for(String s : cmdLine) NodeclipseConsole.write(s+" ");
Expand Down
Expand Up @@ -20,7 +20,7 @@
//import org.nodeclipse.ui.util.NodeclipseConsole;

/**
* Using "Run As" --> "mvn package Maven build" will lead here
* Using "Run As" --> "gradle build" will lead here
**/
public class LaunchShortcut implements ILaunchShortcut {

Expand Down
@@ -0,0 +1,111 @@
package org.nodeclipse.enide.gradle.launchgui;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
//import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.debug.core.model.RuntimeProcess;
import org.eclipse.jface.preference.IPreferenceStore;
//import org.eclipse.jface.preference.IPreferenceStore;
//import org.nodeclipse.debug.util.Constants;
//import org.nodeclipse.debug.util.VariablesUtil;
//import org.nodeclipse.ui.Activator;
//import org.nodeclipse.ui.preferences.Dialogs;
//import org.nodeclipse.ui.preferences.PreferenceConstants;
//import org.nodeclipse.ui.util.NodeclipseConsole;
import org.nodeclipse.enide.gradle.preferences.GradleConstants;
import org.nodeclipse.enide.gradle.util.VariablesUtil;
import org.nodeclipse.enide.gradle.Activator;
import org.nodeclipse.enide.gradle.preferences.Dialogs;

/**
* `build.gradle` Run As Gradle GUI<br>
* see LaunchConfigurationDelegate in .debug and .phantomjs, .jjs, .enide.maven module for comparison.
*
* @since 0.10
* @author Paul Verest
*/
public class LaunchConfigurationDelegate implements ILaunchConfigurationDelegate {

@Override
public void launch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {

IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();

// Using configuration to build command line
List<String> cmdLine = new ArrayList<String>();

// Gradle installation path should be stored in preference.
String gradlePath= preferenceStore.getString(GradleConstants.GRADLE_PATH);
// Check if the maven location is correctly configured
File mavenFile = new File(gradlePath);
if(!mavenFile.exists()){
// If the location is not valid than show a dialog which prompts the user to goto the preferences page
Dialogs.showPreferencesDialog(GradleConstants.PREFERENCES_PAGE,
"Gradle installation is not correctly configured.\n\n"
+ "Please goto Window -> Preferences -> "+GradleConstants.PREFERENCE_PAGE_NAME
+" and configure the correct location");
return;
}
cmdLine.add(gradlePath);

String file = configuration.getAttribute(GradleConstants.KEY_FILE_PATH, "");
String filePath = ResourcesPlugin.getWorkspace().getRoot().findMember(file).getLocation().toOSString();
// path is relative, so cannot find it, unless get absolute path
cmdLine.add("-b"); // -b, --build-file Specifies the build file.

cmdLine.add(filePath);
cmdLine.add("--gui");

String workingDirectory = configuration.getAttribute(GradleConstants.ATTR_WORKING_DIRECTORY, "");
File workingPath = null;
if(workingDirectory.length() == 0) {
workingPath = (new File(filePath)).getParentFile();
} else {
workingDirectory = VariablesUtil.resolveValue(workingDirectory);
if(workingDirectory == null) {
workingPath = (new File(filePath)).getParentFile();
} else {
workingPath = new File(workingDirectory);
}
}

Map<String, String> envm = new HashMap<String, String>();
envm = configuration.getAttribute(GradleConstants.ATTR_ENVIRONMENT_VARIABLES, envm);
String[] envp = new String[envm.size()+2];
int idx = 0;
for(String key : envm.keySet()) {
String value = envm.get(key);
envp[idx++] = key + "=" + value;
}
//ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
//
//Please set the JAVA_HOME variable in your environment to match the
//location of your Java installation.
envp[idx++] = "JAVA_HOME=" + System.getProperty("java.home"); //System.getenv("JAVA_HOME");
envp[idx++] = "GRADLE_HOME=" + System.getenv("GRADLE_HOME");


// for(String s : cmdLine) NodeclipseConsole.write(s+" ");
// NodeclipseConsole.write("\n");

String[] cmds = {};
cmds = cmdLine.toArray(cmds);
// Launch a process to debug.eg,
Process p = DebugPlugin.exec(cmds, workingPath, envp);
RuntimeProcess process = (RuntimeProcess)DebugPlugin.newProcess(launch, p, GradleConstants.PROCESS_MESSAGE);

}

}
@@ -0,0 +1,27 @@
package org.nodeclipse.enide.gradle.launchgui;

import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
import org.eclipse.debug.ui.CommonTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
//import org.nodeclipse.debug.launch.LaunchConfigurationEnvironmentTab;


/**
* Using "Run"-->"Run Configurations"--> "New Configuration"-- > "Run" will lead
* here.
* @author Paul Verest
**/
public class LaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup {

@Override
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
// new LaunchConfigurationMainTab(),
// new NodeArgumentsTab(),
// new LaunchConfigurationEnvironmentTab(),
new CommonTab()
};
setTabs(tabs);
}
}
@@ -0,0 +1,5 @@
package org.nodeclipse.enide.gradle.launchgui;

public class LaunchConfigurationType {

}

0 comments on commit b519fe9

Please sign in to comment.