Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngel Misevski2016-06-21 14:53:17 +0000
committerIlya Buziuk2016-07-01 21:56:59 +0000
commit78d4ad6e07970e0a6bd4e908dfb0fef99e56a360 (patch)
treed900e3722cf979c339bcec68ec53afa30c9f3788
parent6f79b6829bf67f1880d421bc659620817245ab38 (diff)
downloadwebtools.jsdt-78d4ad6e07970e0a6bd4e908dfb0fef99e56a360.tar.gz
webtools.jsdt-78d4ad6e07970e0a6bd4e908dfb0fef99e56a360.tar.xz
webtools.jsdt-78d4ad6e07970e0a6bd4e908dfb0fef99e56a360.zip
Bug 486232, Bug 486233 - Adding Launch Configurations for Grunt/Gulp
Change-Id: I403696e6719dc4d45c31b50c72bb83f17e3d161c Signed-off-by: Angel Misevski <amisevsk@redhat.com>
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/Messages.java1
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/build/system/launch/LaunchConfigurationAutoFill.java25
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/build/system/launch/ui/GenericBuildSystemTab.java8
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/messages.properties1
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/GruntConstants.java3
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/Messages.java1
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/GruntLaunchConfigurationDelegate.java9
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/shortcut/GruntLaunch.java27
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/ui/GruntLaunchTab.java51
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/messages.properties1
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/util/GruntVisitor.java7
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/GulpConstants.java3
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/Messages.java1
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/GulpLaunchConfigurationDelegate.java7
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/shortcut/GulpLaunch.java30
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/ui/GulpLaunchTab.java52
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/messages.properties1
-rw-r--r--tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/BuildSystemVisitorTest.java11
18 files changed, 178 insertions, 61 deletions
diff --git a/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/Messages.java b/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/Messages.java
index 7b31ec85e..21a4f9b9d 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/Messages.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/Messages.java
@@ -26,6 +26,7 @@ public class Messages extends NLS {
public static String LaunchTab_Browse;
public static String LaunchTab_DialogTitle;
public static String LaunchTab_DialogMessage;
+ public static String LaunchTab_Parameters;
static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/build/system/launch/LaunchConfigurationAutoFill.java b/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/build/system/launch/LaunchConfigurationAutoFill.java
index 9f4fc90f7..6c35ae503 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/build/system/launch/LaunchConfigurationAutoFill.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/build/system/launch/LaunchConfigurationAutoFill.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.js.common.build.system.launch;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.wst.jsdt.js.common.CommonPlugin;
@@ -19,20 +22,32 @@ import org.eclipse.wst.jsdt.js.common.build.system.ITask;
* @author "Ilya Buziuk (ibuziuk)"
*/
public class LaunchConfigurationAutoFill {
-
- public static ILaunchConfiguration chooseLaunchConfiguration(ILaunchConfiguration[] configurations, ITask task, String attribute) {
+
+ /**
+ * Filters configurations for launch configurations with the same build file as a task.
+ *
+ * @param configurations - the launch configurations to filter
+ * @param task - the target task
+ * @param buildAttribute - the name of the launch configuration attribute that stores the build file.
+ * @return an array of launch configurations that target the same build file as task
+ */
+ public static ILaunchConfiguration[] getAllLaunchConfigurations(
+ ILaunchConfiguration[] configurations, ITask task, String buildAttribute) {
+
+ List<ILaunchConfiguration> validConfigs = new ArrayList<>();
try {
for (ILaunchConfiguration conf : configurations) {
- String buildFileAttribute = conf.getAttribute(attribute, (String) null);
+ String buildFileAttribute = conf.getAttribute(buildAttribute, (String) null);
String buildFilePath = task.getBuildFile().getLocation().toOSString();
// Launch Configuration per build file (i.e. Gruntfile.js / gulpfile.js)
if (buildFilePath.equals(buildFileAttribute)) {
- return conf;
+ validConfigs.add(conf);
}
}
} catch (CoreException e) {
CommonPlugin.logError(e, e.getMessage());
}
- return null;
+
+ return validConfigs.toArray(new ILaunchConfiguration[validConfigs.size()]);
}
}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/build/system/launch/ui/GenericBuildSystemTab.java b/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/build/system/launch/ui/GenericBuildSystemTab.java
index 9ab23744e..703f940c2 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/build/system/launch/ui/GenericBuildSystemTab.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/build/system/launch/ui/GenericBuildSystemTab.java
@@ -47,6 +47,7 @@ public abstract class GenericBuildSystemTab extends AbstractLaunchConfigurationT
private WidgetListener defaultListener = new WidgetListener();
protected Text buildFileText;
protected Combo tasksCommbo;
+ protected Text parametersText;
protected abstract String[] getTasksFromFile(IFile file) throws JavaScriptModelException;
@@ -57,6 +58,7 @@ public abstract class GenericBuildSystemTab extends AbstractLaunchConfigurationT
((GridLayout) comp.getLayout()).verticalSpacing = 0;
createBuildFileEditor(comp);
createTaskComboEditor(comp);
+ createParametersText(comp);
setControl(comp);
}
@@ -66,6 +68,12 @@ public abstract class GenericBuildSystemTab extends AbstractLaunchConfigurationT
tasksCommbo.addModifyListener(defaultListener);
}
+ private void createParametersText(Composite parent) {
+ Group group = SWTFactory.createGroup(parent, Messages.LaunchTab_Parameters, 1, 1, GridData.FILL_HORIZONTAL);
+ parametersText = SWTFactory.createSingleText(group, 1);
+ parametersText.addModifyListener(defaultListener);
+ }
+
private void createBuildFileEditor(Composite parent) {
Group group = SWTFactory.createGroup(parent, Messages.LaunchTab_BuildFile, 2, 1, GridData.FILL_HORIZONTAL);
buildFileText = SWTFactory.createSingleText(group, 1);
diff --git a/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/messages.properties b/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/messages.properties
index 6069f6909..21fb27bc4 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/messages.properties
+++ b/nodejs/org.eclipse.wst.jsdt.js.common/src/org/eclipse/wst/jsdt/js/common/messages.properties
@@ -14,5 +14,6 @@ LaunchTab_BuildFile=Build File:
LaunchTab_DialogTitle=Build File
LaunchTab_DialogMessage=Select a Build File
LaunchTab_Browse=Browse
+LaunchTab_Parameters=Parameters
LaunchError_Title=Error Occurred
LaunchError_Message=Launch Error \ No newline at end of file
diff --git a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/GruntConstants.java b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/GruntConstants.java
index 1aca8c3bc..a25d93273 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/GruntConstants.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/GruntConstants.java
@@ -26,8 +26,11 @@ public final class GruntConstants {
public static final String DIR = GruntPlugin.PLUGIN_ID + ".DIR"; //$NON-NLS-1$
public static final String COMMAND = GruntPlugin.PLUGIN_ID + ".COMMAND"; //$NON-NLS-1$
public static final String BUILD_FILE = GruntPlugin.PLUGIN_ID + ".BUILD_FILE"; //$NON-NLS-1$
+ public static final String PARAMETERS = GruntPlugin.PLUGIN_ID + ".PARAMETERS"; //$NON-NLS-1$
public static final String GRUNT = "grunt"; //$NON-NLS-1$
public static final String GRUNT_FILE_JS = "gruntfile.js"; //$NON-NLS-1$
+ public static final String DEFAULT_COMMAND = "default"; //$NON-NLS-1$
+ public static final String GRUNT_NO_COLOR = "--no-color";
}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/Messages.java b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/Messages.java
index 7bbfd4a01..4586cbc96 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/Messages.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/Messages.java
@@ -22,6 +22,7 @@ public class Messages extends NLS {
public static String GruntLaunchError_Message;
public static String GruntLaunchTab_Main;
public static String GruntLaunchTab_ErrorNotExist;
+ public static String GruntLaunchTab_WarningTaskNotExist;
static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/GruntLaunchConfigurationDelegate.java b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/GruntLaunchConfigurationDelegate.java
index 2ac169e56..7b668efb0 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/GruntLaunchConfigurationDelegate.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/GruntLaunchConfigurationDelegate.java
@@ -34,11 +34,12 @@ public class GruntLaunchConfigurationDelegate implements ILaunchConfigurationDel
String projectName = conf.getAttribute(GruntConstants.PROJECT, (String) null);
String dirPath = conf.getAttribute(GruntConstants.DIR, (String) null);
String commandName = conf.getAttribute(GruntConstants.COMMAND, (String) null);
+ String parameters = conf.getAttribute(GruntConstants.PARAMETERS, (String) null);
IProject project = WorkbenchResourceUtil.getProject(projectName);
if (project != null && project.exists()) {
IPath dir = (dirPath == null) ? project.getLocation() : new Path(dirPath);
- CLICommand command = generateCLICommand(commandName);
+ CLICommand command = generateCLICommand(commandName, parameters);
launchGrunt(project, dir, command, monitor);
}
}
@@ -52,8 +53,10 @@ public class GruntLaunchConfigurationDelegate implements ILaunchConfigurationDel
}
}
- protected CLICommand generateCLICommand(String commandName) {
- return new CLICommand(GruntConstants.GRUNT, commandName, null, null);
+ protected CLICommand generateCLICommand(String commandName, String parameters) {
+ // ANSI color codes are not supported.
+ String[] options = {GruntConstants.GRUNT_NO_COLOR};
+ return new CLICommand(GruntConstants.GRUNT, commandName, parameters, options);
}
}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/shortcut/GruntLaunch.java b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/shortcut/GruntLaunch.java
index 0c0e796b2..79bd5ca7e 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/shortcut/GruntLaunch.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/shortcut/GruntLaunch.java
@@ -63,19 +63,22 @@ public class GruntLaunch implements ILaunchShortcut {
ILaunchConfiguration[] configurations = DebugPlugin.getDefault()
.getLaunchManager().getLaunchConfigurations(gruntLaunchConfiguraionType);
- ILaunchConfiguration existingConfiguraion = LaunchConfigurationAutoFill
- .chooseLaunchConfiguration(configurations, task, GruntConstants.BUILD_FILE);
-
- if (existingConfiguraion != null) {
- ILaunchConfigurationWorkingCopy wc = existingConfiguraion.getWorkingCopy();
- // Updating task in the existing launch
- wc.setAttribute(GruntConstants.COMMAND, task.getName());
- existingConfiguraion = wc.doSave();
- DebugUITools.launch(existingConfiguraion, mode);
- // Creating Launch Configuration from scratch
- } else if (buildFile != null){
+ // Get only configurations for this Gruntfile.
+ ILaunchConfiguration[] existingConfigurations = LaunchConfigurationAutoFill
+ .getAllLaunchConfigurations(configurations, task, GruntConstants.BUILD_FILE);
+
+ for (ILaunchConfiguration conf : existingConfigurations) {
+ if (conf.getAttribute(GruntConstants.COMMAND, (String) null).equals(task.getName())) {
+ DebugUITools.launch(conf, mode);
+ return;
+ }
+ }
+
+ // No configuration found; create a new one.
+ if (buildFile != null){
IProject project = buildFile.getProject();
- ILaunchConfigurationWorkingCopy newConfiguration = createEmptyLaunchConfiguration(project.getName() + " [" + buildFile.getName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
+ ILaunchConfigurationWorkingCopy newConfiguration = createEmptyLaunchConfiguration(
+ project.getName() + " - " + task.getName() + " [" + buildFile.getName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
newConfiguration.setAttribute(GruntConstants.BUILD_FILE, buildFile.getLocation().toOSString());
newConfiguration.setAttribute(GruntConstants.PROJECT, project.getName());
newConfiguration.setAttribute(GruntConstants.DIR, buildFile.getParent().getLocation().toOSString());
diff --git a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/ui/GruntLaunchTab.java b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/ui/GruntLaunchTab.java
index 436273766..aae6c5bd7 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/ui/GruntLaunchTab.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/launch/ui/GruntLaunchTab.java
@@ -11,6 +11,8 @@
package org.eclipse.wst.jsdt.js.grunt.internal.launch.ui;
import java.io.File;
+import java.util.Arrays;
+import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -38,6 +40,7 @@ public class GruntLaunchTab extends GenericBuildSystemTab {
@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
setErrorMessage(null);
+ setWarningMessage(null);
String buildFilePath = buildFileText.getText();
File file = WorkbenchResourceUtil.getFile(buildFilePath);
@@ -46,6 +49,26 @@ public class GruntLaunchTab extends GenericBuildSystemTab {
return false;
}
+ // Check if the selected task exists in the Gruntfile, display warning if it does not.
+ try {
+ String task = tasksCommbo.getText();
+ if (task.isEmpty()) {
+ return true;
+ }
+ String rootTask = task.split(":")[0];
+ IFile ifile = WorkbenchResourceUtil.getFileForLocation(file.getAbsolutePath());
+
+ List<String> availTasks = Arrays.asList(getTaskNames(
+ ASTUtil.getTasks(buildFilePath, new GruntVisitor(ifile))));
+
+ if (!availTasks.contains(rootTask)) {
+ setWarningMessage(Messages.GruntLaunchTab_WarningTaskNotExist);
+ }
+
+ } catch (JavaScriptModelException e) {
+ GruntPlugin.logError(e, e.getMessage());
+ }
+
return true;
}
@@ -69,17 +92,28 @@ public class GruntLaunchTab extends GenericBuildSystemTab {
ifile = WorkbenchResourceUtil.getFileForLocation(file.getAbsolutePath());
}
-
+ // If launch config has a defined task, use that, if not use 'default'. If there is
+ // no default, leave task field blank.
+ String task = lc.getAttribute(GruntConstants.COMMAND, (String) null);
Set<ITask> tasks = ASTUtil.getTasks(buildFileLocation, new GruntVisitor(ifile));
- if (!tasks.isEmpty()) {
- updateTasks(getTaskNames(tasks));
- String task = lc.getAttribute(GruntConstants.COMMAND, (String) null);
- if (task != null && tasks.contains(task)) {
- tasksCommbo.setText(task);
+ List<String> tasknames = Arrays.asList(getTaskNames(tasks));
+ updateTasks(getTaskNames(tasks));
+ if (task != null && !task.isEmpty()) {
+ tasksCommbo.setText(task);
+ } else {
+ if (tasknames.contains(GruntConstants.DEFAULT_COMMAND)) {
+ tasksCommbo.setText(GruntConstants.DEFAULT_COMMAND);
} else {
- tasksCommbo.setText(tasks.iterator().next().getName());
+ tasksCommbo.setText("");
}
- }
+ }
+
+ String params = lc.getAttribute(GruntConstants.PARAMETERS, (String) null);
+ if (params != null) {
+ parametersText.setText(params);
+ } else {
+ parametersText.setText("");
+ }
} catch (CoreException e) {
GruntPlugin.logError(e, e.getMessage());
}
@@ -94,6 +128,7 @@ public class GruntLaunchTab extends GenericBuildSystemTab {
wc.setAttribute(GruntConstants.PROJECT, project.getName());
wc.setAttribute(GruntConstants.DIR, buildFile.getParent().getLocation().toOSString());
wc.setAttribute(GruntConstants.COMMAND, tasksCommbo.getText());
+ wc.setAttribute(GruntConstants.PARAMETERS, parametersText.getText());
}
}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/messages.properties b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/messages.properties
index 7e75f10d5..e0adfe346 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/messages.properties
+++ b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/internal/messages.properties
@@ -10,5 +10,6 @@
###############################################################################
GruntLaunchTab_Main=Main
GruntLaunchTab_ErrorNotExist=Build File does not exist
+GruntLaunchTab_WarningTaskNotExist=Task not found in Gruntfile
GruntLaunchError_Title=Error Occurred
GruntLaunchError_Message=Grunt Launch Error \ No newline at end of file
diff --git a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/util/GruntVisitor.java b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/util/GruntVisitor.java
index dc11fc470..00a58d13d 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/util/GruntVisitor.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.grunt/src/org/eclipse/wst/jsdt/js/grunt/util/GruntVisitor.java
@@ -32,6 +32,7 @@ public class GruntVisitor extends BuildSystemVisitor {
private static final String GRUNT_INIT_CONFIG = "grunt.initConfig"; //$NON-NLS-1$
private static final String GRUNT_REGISTER_TASK = "grunt.registerTask"; //$NON-NLS-1$
private static final String GRUNT_REGISTER_MULTI_TASK = "grunt.registerMultiTask"; //$NON-NLS-1$
+ private static final String GRUNT_PROPERTY_IGNORE = "pkg"; //$NON-NLS-1$
private Set<ITask> tasks;
private IFile file;
@@ -52,7 +53,8 @@ public class GruntVisitor extends BuildSystemVisitor {
// http://gruntjs.com/api/grunt.task#grunt.task.registertask
if (GRUNT_REGISTER_TASK.equals(expression.toString())) {
- if (argSize == 2) {
+ if (argSize == 2 || argSize == 3) {
+ // Register task supports an optional description field as argument 1.
Expression task = arguments.get(0);
tasks.add(new GruntTask(ASTUtil.beautify(task), file, false, new Location(task.getStartPosition(), task.getLength())));
}
@@ -73,6 +75,9 @@ public class GruntVisitor extends BuildSystemVisitor {
List<ObjectLiteralField> fields = jsObject.fields();
for (ObjectLiteralField f : fields) {
Expression field = f.getFieldName();
+ if (field.toString().equals(GRUNT_PROPERTY_IGNORE)){
+ continue;
+ }
tasks.add(new GruntTask((field.toString()), file, false, new Location(field.getStartPosition(), field.getLength())));
}
}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/GulpConstants.java b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/GulpConstants.java
index b88dac595..779cb8d7e 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/GulpConstants.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/GulpConstants.java
@@ -26,8 +26,9 @@ public final class GulpConstants {
public static final String DIR = GulpPlugin.PLUGIN_ID + ".DIR"; //$NON-NLS-1$
public static final String COMMAND = GulpPlugin.PLUGIN_ID + ".COMMAND"; //$NON-NLS-1$
public static final String BUILD_FILE = GulpPlugin.PLUGIN_ID + ".BUILD_FILE"; //$NON-NLS-1$
+ public static final String PARAMETERS = GulpPlugin.PLUGIN_ID + ".PARAMETERS"; //$NON-NLS-1$
public static final String GULP = "gulp"; //$NON-NLS-1$
public static final String GULP_FILE_JS = "gilpfile.js"; //$NON-NLS-1$
-
+ public static final String DEFAULT_COMMAND = "default"; //$NON-NLS-1$
}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/Messages.java b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/Messages.java
index 4d83b6ef5..0f349d701 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/Messages.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/Messages.java
@@ -22,6 +22,7 @@ public class Messages extends NLS {
public static String GulpLaunchError_Message;
public static String GulpLaunchTab_Main;
public static String GulpLaunchTab_ErrorNotExist;
+ public static String GulpLaunchTab_WarningTaskNotExist;
static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/GulpLaunchConfigurationDelegate.java b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/GulpLaunchConfigurationDelegate.java
index b591c29b6..85a588dcb 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/GulpLaunchConfigurationDelegate.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/GulpLaunchConfigurationDelegate.java
@@ -34,11 +34,12 @@ public class GulpLaunchConfigurationDelegate implements ILaunchConfigurationDele
String projectName = conf.getAttribute(GulpConstants.PROJECT, (String) null);
String dirPath = conf.getAttribute(GulpConstants.DIR, (String) null);
String commandName = conf.getAttribute(GulpConstants.COMMAND, (String) null);
+ String parameters = conf.getAttribute(GulpConstants.PARAMETERS, (String) null);
IProject project = WorkbenchResourceUtil.getProject(projectName);
if (project != null && project.exists()) {
IPath dir = (dirPath == null) ? project.getLocation() : new Path(dirPath);
- CLICommand command = generateCLICommand(commandName);
+ CLICommand command = generateCLICommand(commandName, parameters);
launchGulp(project, dir, command, monitor);
}
}
@@ -52,8 +53,8 @@ public class GulpLaunchConfigurationDelegate implements ILaunchConfigurationDele
}
}
- protected CLICommand generateCLICommand(String commandName) {
- return new CLICommand(GulpConstants.GULP, commandName, null, null);
+ protected CLICommand generateCLICommand(String commandName, String parameters) {
+ return new CLICommand(GulpConstants.GULP, commandName, parameters, null);
}
}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/shortcut/GulpLaunch.java b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/shortcut/GulpLaunch.java
index a29f32a65..1a4773968 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/shortcut/GulpLaunch.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/shortcut/GulpLaunch.java
@@ -55,26 +55,28 @@ public class GulpLaunch implements ILaunchShortcut {
protected void launch(ITask task, String mode) {
try {
IFile buildFile = task.getBuildFile();
- ILaunchConfigurationType gulpLaunchConfiguraionType = DebugPlugin.getDefault().getLaunchManager()
+ ILaunchConfigurationType gulpLaunchConfigurationType = DebugPlugin.getDefault().getLaunchManager()
.getLaunchConfigurationType(GulpConstants.LAUNCH_CONFIGURATION_ID);
// Check if configuration already exists
ILaunchConfiguration[] configurations = DebugPlugin.getDefault()
- .getLaunchManager().getLaunchConfigurations(gulpLaunchConfiguraionType);
+ .getLaunchManager().getLaunchConfigurations(gulpLaunchConfigurationType);
- ILaunchConfiguration existingConfiguraion = LaunchConfigurationAutoFill
- .chooseLaunchConfiguration(configurations, task, GulpConstants.BUILD_FILE);
-
- if (existingConfiguraion != null) {
- ILaunchConfigurationWorkingCopy wc = existingConfiguraion.getWorkingCopy();
- // Updating task in the existing launch
- wc.setAttribute(GulpConstants.COMMAND, task.getName());
- existingConfiguraion = wc.doSave();
- DebugUITools.launch(existingConfiguraion, mode);
- // Creating Launch Configuration from scratch
- } else if (buildFile != null){
+ ILaunchConfiguration[] existingConfigurations = LaunchConfigurationAutoFill
+ .getAllLaunchConfigurations(configurations, task, GulpConstants.BUILD_FILE);
+
+ for (ILaunchConfiguration conf : existingConfigurations) {
+ if (conf.getAttribute(GulpConstants.COMMAND, (String) null).equals(task.getName())) {
+ DebugUITools.launch(conf, mode);
+ return;
+ }
+ }
+
+ // Existing configuration not found, create new Launch Configuration from scratch
+ if (buildFile != null){
IProject project = buildFile.getProject();
- ILaunchConfigurationWorkingCopy newConfiguration = createEmptyLaunchConfiguration(project.getName() + " [" + buildFile.getName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
+ ILaunchConfigurationWorkingCopy newConfiguration = createEmptyLaunchConfiguration(
+ project.getName() + " - " + task.getName() + " [" + buildFile.getName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
newConfiguration.setAttribute(GulpConstants.BUILD_FILE, buildFile.getLocation().toOSString());
newConfiguration.setAttribute(GulpConstants.PROJECT, project.getName());
newConfiguration.setAttribute(GulpConstants.DIR, buildFile.getParent().getLocation().toOSString());
diff --git a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/ui/GulpLaunchTab.java b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/ui/GulpLaunchTab.java
index 2dc85d90c..5b4f85762 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/ui/GulpLaunchTab.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/launch/ui/GulpLaunchTab.java
@@ -11,6 +11,8 @@
package org.eclipse.wst.jsdt.js.gulp.internal.launch.ui;
import java.io.File;
+import java.util.Arrays;
+import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -38,6 +40,7 @@ public class GulpLaunchTab extends GenericBuildSystemTab {
@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
setErrorMessage(null);
+ setWarningMessage(null);
String buildFilePath = buildFileText.getText();
File file = WorkbenchResourceUtil.getFile(buildFilePath);
@@ -46,6 +49,23 @@ public class GulpLaunchTab extends GenericBuildSystemTab {
return false;
}
+ // Check if the entered task exists in the Gulpfile, display warning if it does not.
+ try {
+ String task = tasksCommbo.getText();
+ if (task.isEmpty()) {
+ return true;
+ }
+ IFile ifile = WorkbenchResourceUtil.getFileForLocation(file.getAbsolutePath());
+ List<String> availTasks = Arrays.asList(getTaskNames(
+ ASTUtil.getTasks(buildFilePath, new GulpVisitor(ifile))));
+
+ if (!availTasks.contains(task)) {
+ setWarningMessage(Messages.GulpLaunchTab_WarningTaskNotExist);
+ }
+ } catch (JavaScriptModelException e) {
+ GulpPlugin.logError(e, e.getMessage());
+ }
+
return true;
}
@@ -62,26 +82,33 @@ public class GulpLaunchTab extends GenericBuildSystemTab {
try {
buildFileLocation = lc.getAttribute(GulpConstants.BUILD_FILE, (String) null);
buildFileText.setText(buildFileLocation != null ? buildFileLocation : ""); //$NON-NLS-1$
-
-
+
File file = WorkbenchResourceUtil.getFile(buildFileLocation);
IFile ifile = null;
if (file != null) {
ifile = WorkbenchResourceUtil.getFileForLocation(file.getAbsolutePath());
}
-
-
+
Set<ITask> tasks = ASTUtil.getTasks(buildFileLocation, new GulpVisitor(ifile));
-
- if (!tasks.isEmpty()) {
- updateTasks(getTaskNames(tasks));
- String task = lc.getAttribute(GulpConstants.COMMAND, (String) null);
- if (task != null && tasks.contains(task)) {
- tasksCommbo.setText(task);
+ List<String> tasknames = Arrays.asList(getTaskNames(tasks));
+ updateTasks(getTaskNames(tasks));
+ String task = lc.getAttribute(GulpConstants.COMMAND, (String) null);
+ if (task != null && !task.isEmpty()) {
+ tasksCommbo.setText(task);
+ } else {
+ if (tasknames.contains(GulpConstants.DEFAULT_COMMAND)) {
+ tasksCommbo.setText(GulpConstants.DEFAULT_COMMAND);
} else {
- tasksCommbo.setText(tasks.iterator().next().getName());
+ tasksCommbo.setText("");
}
- }
+ }
+
+ String params = lc.getAttribute(GulpConstants.PARAMETERS, (String) null);
+ if (params != null) {
+ parametersText.setText(params);
+ } else {
+ parametersText.setText("");
+ }
} catch (CoreException e) {
GulpPlugin.logError(e, e.getMessage());
}
@@ -96,6 +123,7 @@ public class GulpLaunchTab extends GenericBuildSystemTab {
wc.setAttribute(GulpConstants.PROJECT, project.getName());
wc.setAttribute(GulpConstants.DIR, buildFile.getParent().getLocation().toOSString());
wc.setAttribute(GulpConstants.COMMAND, tasksCommbo.getText());
+ wc.setAttribute(GulpConstants.PARAMETERS, parametersText.getText());
}
}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/messages.properties b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/messages.properties
index 14bcb20fc..ef7fb9341 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/messages.properties
+++ b/nodejs/org.eclipse.wst.jsdt.js.gulp/src/org/eclipse/wst/jsdt/js/gulp/internal/messages.properties
@@ -10,5 +10,6 @@
###############################################################################
GulpLaunchTab_Main=Main
GulpLaunchTab_ErrorNotExist=Build File does not exist
+GulpLaunchTab_WarningTaskNotExist=Task not found in Gulpfile
GulpLaunchError_Title=Error Occurred
GulpLaunchError_Message=Gulp Launch Error \ No newline at end of file
diff --git a/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/BuildSystemVisitorTest.java b/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/BuildSystemVisitorTest.java
index 4152eea5e..47528d666 100644
--- a/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/BuildSystemVisitorTest.java
+++ b/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/BuildSystemVisitorTest.java
@@ -32,6 +32,7 @@ import org.eclipse.wst.jsdt.js.common.tests.suites.TestRunner;
import org.eclipse.wst.jsdt.js.common.tests.util.ResourceUtil;
import org.eclipse.wst.jsdt.js.grunt.util.GruntVisitor;
import org.eclipse.wst.jsdt.js.gulp.util.GulpVisitor;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -61,6 +62,12 @@ public class BuildSystemVisitorTest {
gulpfile.create(new FileInputStream(gulp.getAbsolutePath()), true, null);
}
+ @AfterClass
+ public static void teardown() throws CoreException {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("TestJsProject");
+ project.delete(true, true, null);
+ }
+
@Test
public void GruntTasksTest() {
try {
@@ -69,8 +76,8 @@ public class BuildSystemVisitorTest {
unit.accept(visitor);
Set<ITask> tasks = visitor.getTasks();
assertTrue("Task list is empty", !tasks.isEmpty());
- // There are 8 tasks defined in gruntfile.js
- assertTrue("Not all grunt tasks were found", tasks.size() == 8);
+ // There are 7 tasks defined in gruntfile.js
+ assertTrue("Not all grunt tasks were found", tasks.size() == 7);
} catch (CoreException e) {
fail("Exception occured while reading file");
}

Back to the top