diff options
author | alopezvenegas | 2016-03-16 22:50:29 +0000 |
---|---|---|
committer | Victor Rubezhny | 2016-03-17 14:31:23 +0000 |
commit | 1df68cd994e83e256a37c28d0b4452797b419253 (patch) | |
tree | 51974e9a6273a22486d0d2cea7725cc12b154b80 | |
parent | 629f22fade95afab67024c3e66afef0b22329795 (diff) | |
download | webtools.jsdt-1df68cd994e83e256a37c28d0b4452797b419253.tar.gz webtools.jsdt-1df68cd994e83e256a37c28d0b4452797b419253.tar.xz webtools.jsdt-1df68cd994e83e256a37c28d0b4452797b419253.zip |
Bug 484597 - Launch configuration for node.js applications
Added Node.js launch configuration and a launch shortcut for this
configuration, these commit depends on bug489148 and bug359436
Change-Id: Iea9dc42ba5385839f976ac7bac478d5cd061a56c
Signed-off-by: alopezvenegas <adalbert@mx1.ibm.com>
28 files changed, 1762 insertions, 0 deletions
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/.classpath b/nodejs/org.eclipse.wst.jsdt.js.node/.classpath new file mode 100644 index 000000000..b1dabee38 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/.project b/nodejs/org.eclipse.wst.jsdt.js.node/.project new file mode 100644 index 000000000..c78039c2c --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.wst.jsdt.js.node</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/.settings/org.eclipse.jdt.core.prefs b/nodejs/org.eclipse.wst.jsdt.js.node/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..11f6e462d --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/META-INF/MANIFEST.MF b/nodejs/org.eclipse.wst.jsdt.js.node/META-INF/MANIFEST.MF new file mode 100644 index 000000000..3c4f25a55 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Node +Bundle-SymbolicName: org.eclipse.wst.jsdt.js.node;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.wst.jsdt.js.node.NodePlugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.core.resources;bundle-version="[3.10.1,4.0.0)", + org.eclipse.wst.jsdt.js.common, + org.eclipse.wst.jsdt.core, + org.eclipse.debug.ui, + org.eclipse.ui.ide;bundle-version="[3.11.0,4.0.0)", + org.eclipse.core.variables, + org.eclipse.core.expressions, + com.google.gson;bundle-version="[2.2.4,3.0.0)", + org.eclipse.wst.jsdt.js.node.common, + org.eclipse.wst.jsdt.chromium.debug.core, + org.eclipse.debug.core +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-ActivationPolicy: lazy diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/about.html b/nodejs/org.eclipse.wst.jsdt.js.node/about.html new file mode 100644 index 000000000..c258ef55d --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 5, 2006</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/build.properties b/nodejs/org.eclipse.wst.jsdt.js.node/build.properties new file mode 100644 index 000000000..b1f81c601 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = target/classes +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + icons/ diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/icons/transparent.gif b/nodejs/org.eclipse.wst.jsdt.js.node/icons/transparent.gif Binary files differnew file mode 100644 index 000000000..a9a3cdcd2 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/icons/transparent.gif diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/icons/variable_tab.gif b/nodejs/org.eclipse.wst.jsdt.js.node/icons/variable_tab.gif Binary files differnew file mode 100644 index 000000000..4b95e5a5d --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/icons/variable_tab.gif diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/plugin.properties b/nodejs/org.eclipse.wst.jsdt.js.node/plugin.properties new file mode 100644 index 000000000..146b8d2c2 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/plugin.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2015 Red Hat, Inc. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Red Hat Inc. - initial API and implementation and/or initial documentation +############################################################################### +providerName = Eclipse Web Tools Platform +bundleName = Eclipse Node Tools
\ No newline at end of file diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/plugin.xml b/nodejs/org.eclipse.wst.jsdt.js.node/plugin.xml new file mode 100644 index 000000000..a780a6ccf --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/plugin.xml @@ -0,0 +1,89 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension point="org.eclipse.core.expressions.propertyTesters"> + <propertyTester + id="org.eclipse.wst.jsdt.js.node.packageJson.propertyTester" + type="org.eclipse.core.resources.IResource" + namespace="org.eclipse.wst.jsdt.js.node.packageJson" + properties="hasPackageJson" + class="org.eclipse.wst.jsdt.js.node.internal.propertytesters.PackageJsonPropertyTester"> + </propertyTester> + </extension> + <extension + point="org.eclipse.debug.ui.launchShortcuts"> + <shortcut + class="org.eclipse.wst.jsdt.js.node.internal.launch.shortcut.NodeLaunch" + description="Node" + helpContextId="org.eclipse.ui.externaltools.launchShortcutHelpContext.NodeShortcut" + icon="icons/transparent.gif" + id="org.eclipse.wst.jsdt.js.node.internal.launch.shortcut.NodeLaunch" + label="Node" + modes="run,debug"> + <contextualLaunch> + <enablement> + <with + variable= "selection"> + <count + value= "1" > + </count> + <iterate> + <or> + <and> + <instanceof value="org.eclipse.core.resources.IFile"/> + <test property="org.eclipse.debug.ui.matchesPattern" value="package.json"/> + </and> + <and> + <instanceof value="org.eclipse.core.resources.IProject"/> + <test property="org.eclipse.wst.jsdt.js.node.packageJson.hasPackageJson" value="true" forcePluginActivation="true"/> + </and> + </or> + </iterate> + </with> + </enablement> + </contextualLaunch> + </shortcut> + </extension> + + <extension + point="org.eclipse.debug.core.launchConfigurationTypes"> + <launchConfigurationType + id="org.eclipse.wst.jsdt.js.node.NodeLaunchConfigurationType" + delegate="org.eclipse.wst.jsdt.js.node.internal.launch.NodeLaunchConfigurationDelegate" + modes="run,debug" + name="Node"> + </launchConfigurationType> + </extension> + + <extension + point="org.eclipse.debug.ui.launchConfigurationTypeImages"> + <launchConfigurationTypeImage + configTypeID="org.eclipse.wst.jsdt.js.node.NodeLaunchConfigurationType" + icon="icons/transparent.gif" + id="org.eclipse.wst.jsdt.js.NodeLaunchConfigurationTypeImage"> + </launchConfigurationTypeImage> + </extension> + + <extension point="org.eclipse.debug.ui.launchConfigurationTabGroups"> + <launchConfigurationTabGroup + type="org.eclipse.wst.jsdt.js.node.NodeLaunchConfigurationType" + class="org.eclipse.wst.jsdt.js.node.internal.launch.ui.NodeLaunchTabGroup" + id="org.eclipse.wst.jsdt.js.node.tabgroup"> + </launchConfigurationTabGroup> + </extension> + <extension + point="org.eclipse.wst.jsdt.core.JSRuntimeType"> + <runtimeType + id="org.eclipse.wst.jsdt.js.node.runtimeType" + name="Node.js Runtime"> + </runtimeType> + </extension> + <extension + point="org.eclipse.wst.jsdt.core.JSRuntimeInstallProvider"> + <runtimeProvider + class="org.eclipse.wst.jsdt.js.node.runtime.NodeJSRuntimeProvider" + runtimeTypeId="org.eclipse.wst.jsdt.js.node.runtimeType"> + </runtimeProvider> + </extension> +</plugin> + diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/pom.xml b/nodejs/org.eclipse.wst.jsdt.js.node/pom.xml new file mode 100644 index 000000000..b8f1b35db --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/pom.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2016 Eclipse Foundation and others. + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Distribution License v1.0 + which accompanies this distribution, and is available at + http://www.eclipse.org/org/documents/edl-v10.php + + Contributors: + Adalberto Lopez Venegas (IBM Corporation) - initial implementation +--> + +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.eclipse.webtools.jsdt</groupId> + <artifactId>nodejs</artifactId> + <version>3.6.0-SNAPSHOT</version> + </parent> + + <groupId>org.eclipse.webtools.jsdt.nodejs</groupId> + <artifactId>org.eclipse.wst.jsdt.js.node</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>eclipse-plugin</packaging> +</project> diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/NodePlugin.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/NodePlugin.java new file mode 100644 index 000000000..ef4108111 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/NodePlugin.java @@ -0,0 +1,75 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class NodePlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.wst.jsdt.js.node"; //$NON-NLS-1$
+
+ // The shared instance
+ private static NodePlugin plugin;
+
+ public NodePlugin() {
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ public static NodePlugin getDefault() {
+ return plugin;
+ }
+
+ public static void logError(Throwable e) {
+ getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e));
+ }
+
+ public static void logError(Throwable e, String message) {
+ getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, e));
+ }
+
+ public static void logError(String message) {
+ getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, null));
+ }
+
+ public static void logInfo(String info) {
+ getDefault().getLog().log(new Status(IStatus.INFO, PLUGIN_ID, info));
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given plug-in
+ * relative path
+ *
+ * @param path
+ * the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+
+}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/Messages.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/Messages.java new file mode 100644 index 000000000..8e820aadb --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/Messages.java @@ -0,0 +1,40 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = Messages.class.getName().toString().toLowerCase();
+
+ //Launch node application configuration
+ public static String LAUNCH_CONFIGURATION_ARGUMENTS_TAB;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB;
+ public static String LAUNCH_CONFIGURATION_ARGUMENTS_TAB_NODE_ARGUMENTS_TEXT;
+ public static String LAUNCH_CONFIGURATION_ARGUMENTS_TAB_APP_ARGUMENTS_TEXT;
+ public static String LAUNCH_CONFIGURATION_ARGUMENTS_TAB_VARIABLES_TEXT;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_MAIN_FILE_TEXT;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_WORKSPACE_BUTTON;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_TITLE;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_DESCRIPTION;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_MAIN_FILE_DOES_NOT_EXIST;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_MAIN_FILE;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/NodeConstants.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/NodeConstants.java new file mode 100644 index 000000000..8f4d66236 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/NodeConstants.java @@ -0,0 +1,29 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node.internal;
+
+/**
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class NodeConstants {
+ public static final String LAUNCH_CONFIGURATION_TYPE_ID = "org.eclipse.wst.jsdt.js.node.NodeLaunchConfigurationType";
+ public static final String CHROMIUM_LAUNCH_CONFIGURATION_TYPE_ID = "org.eclipse.wst.jsdt.chromium.debug.ui.LaunchType$StandaloneV8";
+ public static final String EMPTY = "";
+ public static final String ATTR_WORKING_DIRECTORY = "attr_working_directory";
+ public static final String ATTR_APP_PATH = "attr_app_path";
+ public static final String ATTR_NODE_ARGUMENTS = "attr_node_arguments";
+ public static final String ATTR_APP_ARGUMENTS = "attr_app_arguments";
+ public static final String ATTR_APP_PROJECT = "attr_app_project";
+ public static final String PROCESS_MESSAGE = "Node.js process";
+ public static final String PACKAGE_JSON = "package.json";
+ public static final String DEFAULT_HOST = "localhost";
+ public static final int DEFAULT_PORT = 5858;
+}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/NodeLaunchConfigurationDelegate.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/NodeLaunchConfigurationDelegate.java new file mode 100644 index 000000000..dd45ebf9a --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/NodeLaunchConfigurationDelegate.java @@ -0,0 +1,186 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node.internal.launch;
+
+import java.io.File;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.jsdt.chromium.debug.core.model.LaunchParams;
+import org.eclipse.wst.jsdt.core.runtime.IBaseJSRuntimeInstall;
+import org.eclipse.wst.jsdt.core.runtime.IJSRunner;
+import org.eclipse.wst.jsdt.core.runtime.JSRunnerConfiguration;
+import org.eclipse.wst.jsdt.core.runtime.JSRuntimeManager;
+import org.eclipse.wst.jsdt.js.node.internal.NodeConstants;
+import org.eclipse.wst.jsdt.js.node.internal.util.LaunchConfigurationUtil;
+import org.eclipse.wst.jsdt.launching.ExecutionArguments;
+
+/**
+ * Launch configuration delegate for node application
+ *
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class NodeLaunchConfigurationDelegate extends LaunchConfigurationDelegate {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.
+ * eclipse.debug.core.ILaunchConfiguration, java.lang.String,
+ * org.eclipse.debug.core.ILaunch,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+
+ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+
+ monitor.beginTask(NLS.bind("{0}...", new String[]{configuration.getName()}), 3); //$NON-NLS-1$
+ // check for cancellation
+ if (monitor.isCanceled()) {
+ return;
+ }
+
+ try {
+ String mainTypeName = configuration.getAttribute(NodeConstants.ATTR_APP_PATH, NodeConstants.EMPTY);
+ IJSRunner runner = getJSRunner(configuration, mode);
+
+ File workingDir = verifyWorkingDirectory(configuration);
+ String workingDirName = null;
+ if (workingDir != null) {
+ workingDirName = workingDir.getAbsolutePath();
+ }
+
+ // Environment variables
+ String[] envp= getEnvironment(configuration);
+
+ // Program & VM arguments
+ String pgmArgs = getProgramArguments(configuration);
+ String nodeArgs = getNodeArguments(configuration);
+ if (mode.equals(ILaunchManager.DEBUG_MODE) && !nodeArgs.contains(ILaunchManager.DEBUG_MODE)) {
+ // Adding the "debug" flag first
+ nodeArgs = "debug " + nodeArgs; //$NON-NLS-1$
+ }
+ ExecutionArguments execArgs = new ExecutionArguments(nodeArgs, pgmArgs);
+
+ // Create VM config
+ JSRunnerConfiguration runConfig = new JSRunnerConfiguration(mainTypeName);
+ runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
+ runConfig.setEnvironment(envp);
+ runConfig.setJSRuntimeArguments(execArgs.getVMArgumentsArray());
+ runConfig.setWorkingDirectory(workingDirName);
+
+ // check for cancellation
+ if (monitor.isCanceled()) {
+ return;
+ }
+
+ // done the verification phase
+ monitor.worked(1);
+
+ // Launch the configuration - 1 unit of work
+ runner.run(runConfig, launch, monitor);
+
+ if(mode.equals(ILaunchManager.DEBUG_MODE)){
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(NodeConstants.CHROMIUM_LAUNCH_CONFIGURATION_TYPE_ID);
+ IContainer container = null;
+ ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(container, configuration.getName());
+
+ workingCopy.setAttribute(LaunchParams.CHROMIUM_DEBUG_HOST, NodeConstants.DEFAULT_HOST);
+ workingCopy.setAttribute(LaunchParams.CHROMIUM_DEBUG_PORT, NodeConstants.DEFAULT_PORT);
+ workingCopy.setAttribute(LaunchParams.ADD_NETWORK_CONSOLE, false);
+ ILaunchConfiguration chromiumConfiguration = workingCopy;
+ try {
+ TimeUnit.SECONDS.sleep(3);
+ } catch (InterruptedException e) {
+ }
+ DebugUITools.launch(chromiumConfiguration, mode);
+ }
+
+ // check for cancellation
+ if (monitor.isCanceled()) {
+ return;
+ }
+ }
+ finally {
+ monitor.done();
+ }
+
+ }
+
+ public IJSRunner getJSRunner(ILaunchConfiguration configuration, String mode) throws CoreException {
+ IBaseJSRuntimeInstall runtimeInstall = verifyJSRuntimeInstall(configuration);
+ IJSRunner runner = runtimeInstall.getJSRunner(mode);
+ if (runner == null) {
+ return null;
+ }
+ return runner;
+ }
+
+ public IBaseJSRuntimeInstall verifyJSRuntimeInstall(ILaunchConfiguration configuration)
+ throws CoreException {
+ return getJSRuntimeInstall(configuration);
+ }
+
+ public IBaseJSRuntimeInstall getJSRuntimeInstall(ILaunchConfiguration configuration)
+ throws CoreException {
+ String jsRuntimeInstallId = "nodejsGlobal"; //$NON-NLS-1$
+ return JSRuntimeManager.getDefault().getJSRuntimeInstall(jsRuntimeInstallId);
+ }
+
+ public File verifyWorkingDirectory(ILaunchConfiguration configuration)
+ throws CoreException {
+ File workingPath = null;
+ String workingDirectory = configuration.getAttribute(NodeConstants.ATTR_WORKING_DIRECTORY, NodeConstants.EMPTY);
+ if (workingDirectory.equals(NodeConstants.EMPTY)) {
+ workingDirectory = configuration.getAttribute(NodeConstants.ATTR_APP_PROJECT, NodeConstants.EMPTY);
+ }
+ if (workingDirectory.length() > 0){
+ workingDirectory = LaunchConfigurationUtil.resolveValue(workingDirectory);
+ if(workingDirectory != null){
+ workingPath = new File(workingDirectory);
+ }
+ }
+ return workingPath;
+ }
+
+ public String[] getEnvironment(ILaunchConfiguration configuration) throws CoreException {
+ return DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration);
+ }
+
+ public String getProgramArguments(ILaunchConfiguration configuration)
+ throws CoreException {
+ String appArguments = configuration.getAttribute(NodeConstants.ATTR_APP_ARGUMENTS, NodeConstants.EMPTY);
+ return VariablesPlugin.getDefault().getStringVariableManager()
+ .performStringSubstitution(appArguments);
+ }
+
+ public String getNodeArguments(ILaunchConfiguration configuration) throws CoreException {
+ String nodeArguments = configuration.getAttribute(NodeConstants.ATTR_NODE_ARGUMENTS, NodeConstants.EMPTY);
+ String args = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(nodeArguments);
+ return args;
+ }
+}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/shortcut/NodeLaunch.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/shortcut/NodeLaunch.java new file mode 100644 index 000000000..c28cb9efa --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/shortcut/NodeLaunch.java @@ -0,0 +1,149 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node.internal.launch.shortcut;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.ILaunchShortcut;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.wst.jsdt.js.node.NodePlugin;
+import org.eclipse.wst.jsdt.js.node.common.json.objects.PackageJson;
+import org.eclipse.wst.jsdt.js.node.common.util.PackageJsonUtil;
+import org.eclipse.wst.jsdt.js.node.internal.NodeConstants;
+import org.eclipse.wst.jsdt.js.node.internal.util.LaunchConfigurationUtil;
+
+/**
+ * Launch configuration shortcut for node application
+ *
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class NodeLaunch implements ILaunchShortcut{
+ @Override
+ public void launch(ISelection selection, String mode) {
+ try {
+ Object objSelected = ((IStructuredSelection) selection).getFirstElement();
+ if (objSelected instanceof IFile) {
+ launchFile((IFile) objSelected, mode);
+ } else if (objSelected instanceof IContainer) {
+ launchContainer((IContainer) objSelected, mode);
+ }
+ } catch (CoreException e) {
+ NodePlugin.logError(e.getLocalizedMessage());
+ }
+ }
+
+ @Override
+ public void launch(IEditorPart editor, String mode) {
+ try {
+ IEditorInput editorInput = editor.getEditorInput();
+ if (editorInput instanceof IFileEditorInput) {
+ IFile file = ((IFileEditorInput) editorInput).getFile();
+ launchFile((IFile) file, mode);
+ }
+ } catch (CoreException e) {
+ NodePlugin.logError(e.getLocalizedMessage());
+ }
+ }
+
+ private void launchContainer(IContainer container, String mode) throws CoreException {
+ String path = container.getFullPath().toString();
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(NodeConstants.LAUNCH_CONFIGURATION_TYPE_ID);
+ ILaunchConfiguration configuration = createLaunchConfiguration(type, path, container);
+ launchHelper(configuration, mode);
+ }
+
+ protected void launchHelper(ILaunchConfiguration configuration, String mode){
+ String mainScript = null;
+ try {
+ mainScript = configuration.getAttribute(NodeConstants.ATTR_APP_PATH, NodeConstants.EMPTY);
+ if (mainScript != null && mainScript.equals(NodeConstants.EMPTY)) {
+ Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
+ String groupId = DebugUITools.getLaunchGroup(configuration, mode).getIdentifier();
+ DebugUITools.openLaunchConfigurationDialogOnGroup(shell,new StructuredSelection(configuration), groupId);
+ }
+ if (mainScript != null && !mainScript.equals(NodeConstants.EMPTY)) {
+ DebugUITools.launch(configuration, mode);
+ }
+ } catch (CoreException e) {
+ NodePlugin.logError(e.getLocalizedMessage());
+ }
+ }
+
+ private void launchFile(IFile file, String mode) throws CoreException {
+ String path = ResourcesPlugin.getWorkspace().getRoot().findMember(file.getFullPath().toString()).getLocation()
+ .toOSString();
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(NodeConstants.LAUNCH_CONFIGURATION_TYPE_ID);
+ ILaunchConfiguration configuration = createLaunchConfiguration(type, path, file);
+ launchHelper(configuration, mode);
+ }
+
+ private ILaunchConfiguration createLaunchConfiguration(ILaunchConfigurationType type, String path, IResource file)
+ throws CoreException {
+ IFile configFile = null;
+ if(file.getType() == IResource.PROJECT || file.getType() == IResource.FOLDER){
+ path = NodeConstants.EMPTY;
+ PackageJson packageJson = PackageJsonUtil.readPackageJsonFromIResource(file);
+ if(packageJson.getMain() != null){
+ IFile mainFile = file.getProject().getFile(packageJson.getMain());
+ if(mainFile != null && mainFile.isAccessible()){
+ configFile = mainFile;
+ }
+ }
+ if(configFile != null) {
+ path = ResourcesPlugin.getWorkspace().getRoot().findMember(configFile.getFullPath()).getLocation().toOSString();
+ }
+ }
+ else if (file.getType() == IResource.FILE){
+ configFile = (IFile) file;
+ }
+
+ ILaunchConfiguration config = LaunchConfigurationUtil.getExistingLaunchConfiguration(configFile,
+ type, NodeConstants.ATTR_APP_PATH);
+ if (config != null) {
+ return config;
+ }
+
+ String configName = NodeConstants.EMPTY;
+ if(configFile!=null) {
+ configName = configFile.getFullPath().toString();
+ if (configName.startsWith("/")) {
+ configName = configName.substring(1, configName.length());
+ }
+ configName = configName.replaceAll("/", "_");
+ } else {
+ configName = file.getProject().getName();
+ }
+
+ IContainer container = null;
+ ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(container, configName);
+ workingCopy.setAttribute(NodeConstants.ATTR_APP_PATH, path);
+ workingCopy.setAttribute(NodeConstants.ATTR_APP_PROJECT, file.getProject().getLocation().toOSString());
+ return workingCopy.doSave();
+ }
+}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchArgumentsTab.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchArgumentsTab.java new file mode 100644 index 000000000..ee23e7658 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchArgumentsTab.java @@ -0,0 +1,233 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node.internal.launch.ui;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.debug.ui.StringVariableSelectionDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wst.jsdt.js.node.internal.NodeConstants;
+import org.eclipse.wst.jsdt.js.node.internal.ui.ImageResource;
+import org.eclipse.wst.jsdt.js.node.internal.Messages;
+
+/**
+ * Arguments tab for node application launch configuration
+ *
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class NodeLaunchArgumentsTab extends AbstractLaunchConfigurationTab {
+
+ protected Text nodeArgumentsText;
+ protected Text appArgumentsText;
+ protected Button nodeVariablesButton;
+ protected Button appVariablesButton;
+
+ NodeWorkingDirectoryBlock workingDirectoryBlock = new NodeWorkingDirectoryBlock(NodeConstants.ATTR_WORKING_DIRECTORY);
+
+ private ModifyListener modifyListener = new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateLaunchConfigurationDialog();
+ }
+ };
+
+ private SelectionListener nodeArgsSelectionListener = new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
+ dialog.open();
+ String variable = dialog.getVariableExpression();
+ if (variable != null) {
+ nodeArgumentsText.insert(variable);
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+ };
+
+ private SelectionListener appArgsSelectionListener = new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
+ dialog.open();
+ String variable = dialog.getVariableExpression();
+ if (variable != null) {
+ appArgumentsText.insert(variable);
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+ };
+
+ @Override
+ public void createControl(Composite parent) {
+ ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL);
+ scrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ Composite composite = new Composite(scrolledComposite, SWT.NULL);
+ scrolledComposite.setContent(composite);
+
+ Point minSize = composite.computeSize(0, 350);
+ composite.setSize(minSize);
+ if (composite.getParent() instanceof ScrolledComposite) {
+ ScrolledComposite sc1 = (ScrolledComposite)composite.getParent();
+ sc1.setMinSize(minSize);
+ sc1.setExpandHorizontal(true);
+ sc1.setExpandVertical(true);
+ }
+
+ GridLayout layout = new GridLayout();
+ layout.horizontalSpacing = 5;
+ layout.verticalSpacing = 5;
+ layout.numColumns = 1;
+ composite.setLayout(layout);
+
+ createNodeArgumentsGroup(composite);
+ createAppArgumentsGroup(composite);
+ createWorkingDirectoryGroup(composite);
+
+ setControl(scrolledComposite);
+ }
+
+ private void createNodeArgumentsGroup(Composite parent) {
+ Group nodeJSOptionsGroup = new Group(parent, SWT.NONE);
+ nodeJSOptionsGroup.setText(Messages.LAUNCH_CONFIGURATION_ARGUMENTS_TAB_NODE_ARGUMENTS_TEXT);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ nodeJSOptionsGroup.setLayoutData(gd);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ nodeJSOptionsGroup.setLayout(layout);
+ nodeJSOptionsGroup.setFont(parent.getFont());
+
+ nodeArgumentsText = new Text(nodeJSOptionsGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
+ gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 40;
+ gd.widthHint = 100;
+ nodeArgumentsText.setLayoutData(gd);
+ nodeArgumentsText.addModifyListener(modifyListener);
+
+ nodeVariablesButton = createPushButton(nodeJSOptionsGroup, Messages.LAUNCH_CONFIGURATION_ARGUMENTS_TAB_VARIABLES_TEXT, null);
+ nodeVariablesButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
+ nodeVariablesButton.addSelectionListener(nodeArgsSelectionListener);
+ }
+
+ private void createAppArgumentsGroup(Composite parent) {
+ Group scriptOptionsGroup = new Group(parent, SWT.NONE);
+ scriptOptionsGroup.setText(Messages.LAUNCH_CONFIGURATION_ARGUMENTS_TAB_APP_ARGUMENTS_TEXT);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ scriptOptionsGroup.setLayoutData(gd);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ scriptOptionsGroup.setLayout(layout);
+ scriptOptionsGroup.setFont(parent.getFont());
+
+ appArgumentsText = new Text(scriptOptionsGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
+ gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 40;
+ gd.widthHint = 100;
+ appArgumentsText.setLayoutData(gd);
+ appArgumentsText.addModifyListener(modifyListener);
+
+ appVariablesButton = createPushButton(scriptOptionsGroup, Messages.LAUNCH_CONFIGURATION_ARGUMENTS_TAB_VARIABLES_TEXT, null);
+ appVariablesButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
+ appVariablesButton.addSelectionListener(appArgsSelectionListener);
+ }
+
+ protected void createWorkingDirectoryGroup(Composite parent) {
+ workingDirectoryBlock.createControl(parent);
+ }
+
+ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
+ workingDirectoryBlock.setDefaults(configuration);
+ }
+
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ try {
+ nodeArgumentsText.setText(configuration.getAttribute(NodeConstants.ATTR_NODE_ARGUMENTS, NodeConstants.EMPTY));
+ appArgumentsText.setText(configuration.getAttribute(NodeConstants.ATTR_APP_ARGUMENTS, NodeConstants.EMPTY));
+ workingDirectoryBlock.initializeFrom(configuration);
+
+ } catch (CoreException e) {
+ setErrorMessage(e.getMessage());
+ }
+ }
+
+ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+ configuration.setAttribute(NodeConstants.ATTR_NODE_ARGUMENTS, nodeArgumentsText.getText().trim());
+ configuration.setAttribute(NodeConstants.ATTR_APP_ARGUMENTS, appArgumentsText.getText().trim());
+ workingDirectoryBlock.performApply(configuration);
+ }
+
+ public boolean isValid(ILaunchConfiguration launchConfig) {
+ setErrorMessage(null);
+ setMessage(null);
+ return workingDirectoryBlock.isValid(launchConfig);
+ }
+
+ public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog){
+ super.setLaunchConfigurationDialog(dialog);
+ workingDirectoryBlock.setLaunchConfigurationDialog(dialog);
+ }
+
+ public String getErrorMessage() {
+ String m = super.getErrorMessage();
+ if (m == null) {
+ return workingDirectoryBlock.getErrorMessage();
+ }
+ return m;
+ }
+
+ public String getMessage() {
+ String m = super.getMessage();
+ if (m == null) {
+ return workingDirectoryBlock.getMessage();
+ }
+ return m;
+ }
+
+ public Composite createComposite(Composite parent, Font font, int columns, int hspan, int fill) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(columns, false));
+ composite.setFont(font);
+ GridData gridData = new GridData(fill);
+ gridData.horizontalSpan = hspan;
+ composite.setLayoutData(gridData);
+ return composite;
+ }
+
+ @Override
+ public Image getImage() {
+ return ImageResource.getImage(ImageResource.IMG_ARGUMENTS);
+ }
+
+ public String getName() {
+ return Messages.LAUNCH_CONFIGURATION_ARGUMENTS_TAB;
+ }
+
+}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchMainTab.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchMainTab.java new file mode 100644 index 000000000..c2f9d651d --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchMainTab.java @@ -0,0 +1,229 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node.internal.launch.ui;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.dialogs.ISelectionStatusValidator;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.wst.jsdt.js.node.internal.ui.ImageResource;
+import org.eclipse.wst.jsdt.js.node.NodePlugin;
+import org.eclipse.wst.jsdt.js.node.internal.NodeConstants;
+import org.eclipse.wst.jsdt.js.node.internal.Messages;
+
+/**
+ * Main tab for node application launch configuration
+ *
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
+
+ private Text scriptText;
+ private Button searchButton;
+ private boolean mainTabEntriesValid;
+
+ //Generic Modify Listener
+ private ModifyListener modifyListener = new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateLaunchConfigurationDialog();
+ }
+ };
+
+ @Override
+ public void createControl(Composite parent) {
+ ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL);
+ scrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ Composite composite = new Composite(scrolledComposite, SWT.NULL);
+ scrolledComposite.setContent(composite);
+
+ Point minSize = composite.computeSize(0, 350);
+ composite.setSize(minSize);
+ if (composite.getParent() instanceof ScrolledComposite) {
+ ScrolledComposite sc1 = (ScrolledComposite)composite.getParent();
+ sc1.setMinSize(minSize);
+ sc1.setExpandHorizontal(true);
+ sc1.setExpandVertical(true);
+ }
+
+ GridLayout layout = new GridLayout();
+ layout.horizontalSpacing = 5;
+ layout.verticalSpacing = 5;
+ layout.numColumns = 1;
+ composite.setLayout(layout);
+
+ createProgramGroup(composite);
+
+ setControl(scrolledComposite);
+ }
+
+ private void createProgramGroup(Composite parent) {
+ Group programGroup = new Group(parent, SWT.NONE);
+ programGroup.setText(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_MAIN_FILE_TEXT);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ programGroup.setLayoutData(gd);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ programGroup.setLayout(layout);
+ programGroup.setFont(parent.getFont());
+
+ //Script part
+ scriptText = new Text(programGroup, SWT.SINGLE | SWT.BORDER);
+ scriptText.setLayoutData(gd);
+ scriptText.setFont(parent.getFont());
+ scriptText.addModifyListener(modifyListener);
+ searchButton = createPushButton(programGroup, Messages.LAUNCH_CONFIGURATION_MAIN_TAB_WORKSPACE_BUTTON, null);
+ searchButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ String scriptFile = browseWorkspace(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_DESCRIPTION);
+ if (scriptFile != null && !scriptFile.equals(NodeConstants.EMPTY)) {
+ scriptText.setText(scriptFile);
+ updateLaunchConfigurationDialog();
+ }
+ }
+ });
+ }
+
+ protected String browseWorkspace(String description) {
+ ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getControl().getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
+ dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
+ dialog.setAllowMultiple(false);
+ dialog.addFilter(new ViewerFilter() {
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (element instanceof IProject || element instanceof IFolder) {
+ return true;
+ }
+ if(element instanceof IFile) {
+ return "js".equals(((IFile)element).getFileExtension());
+ }
+ return false;
+ }
+ });
+ dialog.setTitle(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_TITLE);
+ dialog.setMessage(description);
+ dialog.setValidator(new ISelectionStatusValidator() {
+ public IStatus validate(Object[] selection) {
+ if (selection != null && selection.length > 0 && selection[0] instanceof IFile){
+ return new Status(IStatus.OK, NodePlugin.PLUGIN_ID, IStatus.OK, NodeConstants.EMPTY, null);
+ }
+ return new Status(IStatus.ERROR, NodePlugin.PLUGIN_ID, IStatus.ERROR, NodeConstants.EMPTY, null);
+ }
+ });
+
+ if (dialog.open() == Window.OK) {
+ IFile file = (IFile)dialog.getFirstResult();
+ if(file != null){
+ String fullFileName = file.getLocation().toOSString();
+ return fullFileName;
+ }
+ }
+ return null;
+ }
+
+ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
+ }
+
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ try {
+ scriptText.setText(configuration.getAttribute(NodeConstants.ATTR_APP_PATH, NodeConstants.EMPTY));
+ } catch (CoreException e) {
+ setErrorMessage(e.getMessage());
+ }
+ }
+
+ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+ configuration.setAttribute(NodeConstants.ATTR_APP_PATH, scriptText.getText().trim());
+
+ //Set default working directory
+ if(!scriptText.getText().trim().equals(NodeConstants.EMPTY)) {
+ File file = new File(scriptText.getText().trim());
+ IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(Path.fromOSString(file.getAbsolutePath()));
+ if(iFile != null && iFile.exists()) {
+ String project = iFile.getProject().getLocation().toOSString();
+ configuration.setAttribute(NodeConstants.ATTR_APP_PROJECT, project);
+ }
+ }
+ }
+
+ public boolean isValid(ILaunchConfiguration launchConfig) {
+ validateEntries();
+ return mainTabEntriesValid;
+ }
+
+ protected void validateEntries(){
+ setErrorMessage(null);
+ mainTabEntriesValid = true;
+
+ String scriptFile = scriptText.getText();
+
+ if (mainTabEntriesValid && scriptFile.length() > 0) {
+ File file = new File(scriptFile);
+ if (!file.exists()) {
+ setErrorMessage(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_MAIN_FILE_DOES_NOT_EXIST);
+ mainTabEntriesValid = false;
+ }
+ } else if(mainTabEntriesValid && scriptFile.length() <= 0){
+ setErrorMessage(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_MAIN_FILE);
+ mainTabEntriesValid = false;
+ }
+ }
+
+ public Composite createComposite(Composite parent, Font font, int columns, int hspan, int fill) {
+ Composite g = new Composite(parent, SWT.NONE);
+ g.setLayout(new GridLayout(columns, false));
+ g.setFont(font);
+ GridData gd = new GridData(fill);
+ gd.horizontalSpan = hspan;
+ g.setLayoutData(gd);
+ return g;
+ }
+
+ @Override
+ public Image getImage() {
+ return ImageResource.getImage(ImageResource.IMG_NODEJS);
+ }
+
+ public String getName() {
+ return Messages.LAUNCH_CONFIGURATION_MAIN_TAB;
+ }
+}
\ No newline at end of file diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchTabGroup.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchTabGroup.java new file mode 100644 index 000000000..ccc659068 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchTabGroup.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.jsdt.js.node.internal.launch.ui; + +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; +import org.eclipse.debug.ui.CommonTab; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.debug.ui.ILaunchConfigurationTab; + +/** + * Node tab group for node application launch configuration + * + * @author "Adalberto Lopez Venegas (adalbert)" + */ +public class NodeLaunchTabGroup extends AbstractLaunchConfigurationTabGroup { + + @Override + public void createTabs(ILaunchConfigurationDialog dialog, String mode) { + ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { + new NodeLaunchMainTab(), + new NodeLaunchArgumentsTab(), + new CommonTab() }; + setTabs(tabs); + } + + @Override + public void initializeFrom(ILaunchConfiguration configuration) { + super.initializeFrom(configuration); + } + + + @Override + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { + super.setDefaults(configuration); + } + +} diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeWorkingDirectoryBlock.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeWorkingDirectoryBlock.java new file mode 100644 index 000000000..58f517073 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeWorkingDirectoryBlock.java @@ -0,0 +1,67 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node.internal.launch.ui;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.ui.WorkingDirectoryBlock;
+import org.eclipse.wst.jsdt.js.node.NodePlugin;
+import org.eclipse.wst.jsdt.js.node.internal.NodeConstants;
+
+
+/**
+ * Node working directory block for node application launch configuration
+ *
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class NodeWorkingDirectoryBlock extends WorkingDirectoryBlock {
+
+ public NodeWorkingDirectoryBlock(String workingDirectoryAttribteName) {
+ super(workingDirectoryAttribteName);
+ }
+
+ @Override
+ protected IProject getProject(ILaunchConfiguration launchConfiguration) throws CoreException {
+ String projectLocation = NodeConstants.EMPTY;
+ try {
+ projectLocation = launchConfiguration.getAttribute(NodeConstants.ATTR_APP_PROJECT,
+ NodeConstants.EMPTY);
+ } catch (CoreException e) {
+ NodePlugin.logError(e, e.getLocalizedMessage());
+ }
+ if (!projectLocation.equals(NodeConstants.EMPTY)) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(new File(projectLocation).getName());
+ if (project != null && project.isAccessible()) {
+ return project;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ setLaunchConfiguration(configuration);
+ try {
+ String wd = configuration.getAttribute(NodeConstants.ATTR_WORKING_DIRECTORY,
+ NodeConstants.EMPTY);
+ setDefaultWorkingDir();
+ if (!wd.equals(NodeConstants.EMPTY)) {
+ setOtherWorkingDirectoryText(wd);
+ }
+ } catch (CoreException e) {
+ NodePlugin.logError(e, e.getLocalizedMessage());
+ }
+ }
+}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/messages.properties b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/messages.properties new file mode 100644 index 000000000..5b349d394 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/messages.properties @@ -0,0 +1,23 @@ +###############################################################################
+# Copyright (c) 2016 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+#Launch node application configuration
+LAUNCH_CONFIGURATION_ARGUMENTS_TAB=Arguments
+LAUNCH_CONFIGURATION_MAIN_TAB=Main
+LAUNCH_CONFIGURATION_ARGUMENTS_TAB_NODE_ARGUMENTS_TEXT=Node arguments
+LAUNCH_CONFIGURATION_ARGUMENTS_TAB_APP_ARGUMENTS_TEXT=Application arguments
+LAUNCH_CONFIGURATION_ARGUMENTS_TAB_VARIABLES_TEXT=Variables
+LAUNCH_CONFIGURATION_MAIN_TAB_MAIN_FILE_TEXT=Main file
+LAUNCH_CONFIGURATION_MAIN_TAB_WORKSPACE_BUTTON=Workspace...
+LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_TITLE=Select Main file
+LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_DESCRIPTION=Select a Javascript Main file
+LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_MAIN_FILE_DOES_NOT_EXIST=Specified file does not exist
+LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_NOT_JAVASCRIPT_FILE=Main file must be a Javascript file
+LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_MAIN_FILE=Specify a main file
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/propertytesters/PackageJsonPropertyTester.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/propertytesters/PackageJsonPropertyTester.java new file mode 100644 index 000000000..d4b903676 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/propertytesters/PackageJsonPropertyTester.java @@ -0,0 +1,42 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node.internal.propertytesters; +
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.wst.jsdt.js.node.internal.NodeConstants;
+
+/**
+ * Property tester to verify project contains package.json file
+ *
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class PackageJsonPropertyTester extends PropertyTester {
+
+ @Override
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if ("hasPackageJson".equals(property)) { //$NON-NLS-1$
+ return hasPackageJson((IProject) receiver);
+ }
+ return false;
+ }
+
+ public static boolean hasPackageJson(IProject project){
+ IFile packageJsonFile = project.getFile(NodeConstants.PACKAGE_JSON);
+ if (packageJsonFile != null && packageJsonFile.isAccessible()) {
+ return true;
+ }
+ return false;
+ }
+
+}
+
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/ui/ImageResource.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/ui/ImageResource.java new file mode 100644 index 000000000..4e8c78b34 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/ui/ImageResource.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.jsdt.js.node.internal.ui; + +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; +import org.eclipse.wst.jsdt.js.node.NodePlugin; + +/** + * Utility class to handle image resources. + */ +public class ImageResource { + private static ImageRegistry imageRegistry; + private static Map<String, ImageDescriptor> imageDescriptors; + private static URL ICON_BASE_URL; + + public static final String IMG_NODEJS = "transparent.gif"; //$NON-NLS-1$ + public static final String IMG_ARGUMENTS = "variable_tab.gif"; //$NON-NLS-1$ + + static { + try { + String pathSuffix = "icons/"; //$NON-NLS-1$ + ICON_BASE_URL = NodePlugin.getDefault().getBundle() + .getEntry(pathSuffix); + } catch (Exception e) { + NodePlugin.logError(e , "Images error: " + e.getMessage()); //$NON-NLS-1$ + } + } + + /** + * Return the image with the given key. + * + * @param key + * java.lang.String + * @return org.eclipse.swt.graphics.Image + */ + public static Image getImage(String key) { + return getImage(key, null); + } + + /** + * Return the image with the given key. + * + * @param key + * java.lang.String + * @return org.eclipse.swt.graphics.Image + */ + public static Image getImage(String key, String keyIfImageNull) { + if (imageRegistry == null) + initializeImageRegistry(); + Image image = imageRegistry.get(key); + if (image == null) { + if (keyIfImageNull != null) { + return getImage(keyIfImageNull, null); + } + imageRegistry.put(key, ImageDescriptor.getMissingImageDescriptor()); + image = imageRegistry.get(key); + } + return image; + } + + /** + * Return the image descriptor with the given key. + * + * @param key + * java.lang.String + * @return org.eclipse.jface.resource.ImageDescriptor + */ + public static ImageDescriptor getImageDescriptor(String key) { + if (imageRegistry == null) + initializeImageRegistry(); + ImageDescriptor id = imageDescriptors.get(key); + if (id != null) + return id; + + return ImageDescriptor.getMissingImageDescriptor(); + } + + /** + * Initialize the image resources. + */ + protected static void initializeImageRegistry() { + imageRegistry = NodePlugin.getDefault().getImageRegistry(); + imageDescriptors = new HashMap<String, ImageDescriptor>(); + registerImage(IMG_NODEJS, IMG_NODEJS); + registerImage(IMG_ARGUMENTS, IMG_ARGUMENTS); + } + + /** + * Register an image with the registry. + * + * @param key + * java.lang.String + * @param partialURL + * java.lang.String + */ + public static void registerImage(String key, String partialURL) { + try { + ImageDescriptor id = ImageDescriptor.createFromURL(new URL( + ICON_BASE_URL, partialURL)); + registerImageDescriptor(key, id); + } catch (Exception e) { + NodePlugin.logError(e , "Error registering image" + e.getMessage()); //$NON-NLS-1$ + } + } + + public static void registerImageDescriptor(String key, ImageDescriptor id) { + if (imageRegistry == null) + initializeImageRegistry(); + imageRegistry.put(key, id); + imageDescriptors.put(key, id); + } + +}
\ No newline at end of file diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/util/LaunchConfigurationUtil.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/util/LaunchConfigurationUtil.java new file mode 100644 index 000000000..de90e9f81 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/util/LaunchConfigurationUtil.java @@ -0,0 +1,97 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node.internal.util;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.variables.IStringVariableManager;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.wst.jsdt.js.node.NodePlugin;
+import org.eclipse.wst.jsdt.js.node.internal.NodeConstants;
+
+/**
+ * Node application launch configuration utils
+ *
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class LaunchConfigurationUtil {
+
+ private static void validateVariables(String expression) throws CoreException {
+ IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
+ manager.validateStringVariables(expression);
+ }
+
+ public static String resolveValue(String expression) throws CoreException {
+ String expanded= null;
+ try {
+ expanded= getValue(expression);
+ } catch (CoreException e) { //possibly just a variable that needs to be resolved at runtime
+ validateVariables(expression);
+ return null;
+ }
+ return expanded;
+ }
+
+ private static String getValue(String expression) throws CoreException {
+ IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
+ return manager.performStringSubstitution(expression);
+ }
+
+ /**
+ * Get an existing Node.js launch configuration for a given file if it exists.
+ *
+ * @return the existing Node.js launch configuration if any, null otherwise.
+ */
+ public static ILaunchConfiguration getExistingLaunchConfiguration(IFile file, ILaunchConfigurationType launchConfigTypeId,
+ String attributeName) {
+ if (file == null) {
+ return null;
+ }
+
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+
+ try {
+ ILaunchConfiguration[] configurations = launchManager.getLaunchConfigurations(launchConfigTypeId);
+ for (ILaunchConfiguration config : configurations) {
+ boolean match = false;
+
+ IPath configPath = getIPathFromLaunchConfig(config, attributeName);
+ if (configPath != null) {
+ if (configPath.equals(file.getRawLocation())) {
+ match = true;
+ }
+ }
+
+ if (match) {
+ return config;
+ }
+ }
+ } catch (CoreException coreException) {
+ return null;
+ }
+ return null;
+ }
+
+ private static IPath getIPathFromLaunchConfig(ILaunchConfiguration config, String attributeName) {
+ IPath configPath = null;
+ try {
+ configPath = new org.eclipse.core.runtime.Path(config.getAttribute(attributeName, NodeConstants.EMPTY));
+ } catch (CoreException e) {
+ NodePlugin.logError(e.getLocalizedMessage());
+ }
+ return configPath;
+ }
+}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/runtime/NodeJSRuntimeProvider.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/runtime/NodeJSRuntimeProvider.java new file mode 100644 index 000000000..90d5f7efc --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/runtime/NodeJSRuntimeProvider.java @@ -0,0 +1,34 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node.runtime;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.wst.jsdt.core.runtime.IBaseJSRuntimeInstall;
+import org.eclipse.wst.jsdt.core.runtime.IJSRuntimeInstallProvider;
+
+/**
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class NodeJSRuntimeProvider implements IJSRuntimeInstallProvider {
+
+ public NodeJSRuntimeProvider() {
+ }
+
+ @Override
+ public Collection<IBaseJSRuntimeInstall> getJSRuntimeInstallContributions() {
+ ArrayList<IBaseJSRuntimeInstall> array = new ArrayList<IBaseJSRuntimeInstall>();
+ array.add(new NodeJsInstall());
+ return array;
+ }
+
+}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/runtime/NodeJsInstall.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/runtime/NodeJsInstall.java new file mode 100644 index 000000000..d169be682 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/runtime/NodeJsInstall.java @@ -0,0 +1,68 @@ +/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.js.node.runtime;
+
+import java.io.File;
+
+import org.eclipse.wst.jsdt.core.runtime.IBaseJSRuntimeInstall;
+import org.eclipse.wst.jsdt.core.runtime.IJSRunner;
+
+/**
+ * @author "Adalberto Lopez Venegas (adalbert)"
+ */
+public class NodeJsInstall implements IBaseJSRuntimeInstall{
+
+ private IJSRunner runner;
+
+ @Override
+ public String getId() {
+ return "nodejsGlobal";
+ }
+
+ @Override
+ public IJSRunner getJSRunner(String mode) {
+ if (runner == null) {
+ runner = new NodeJsRunner(this);
+ }
+ return runner;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public void setName(String name) {
+
+ }
+
+ @Override
+ public File getInstallLocation() {
+ return new File ("node");
+ }
+
+ @Override
+ public void setInstallLocation(File installLocation) {
+
+ }
+
+ @Override
+ public String[] getJSRuntimeArguments() {
+ return null;
+ }
+
+ @Override
+ public void setJSRuntimeArguments(String runtimeArgs) {
+
+ }
+
+}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/runtime/NodeJsRunner.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/runtime/NodeJsRunner.java new file mode 100644 index 000000000..e8daa9633 --- /dev/null +++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/runtime/NodeJsRunner.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.jsdt.js.node.runtime; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +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.model.IProcess; +import org.eclipse.wst.jsdt.core.runtime.IBaseJSRuntimeInstall; +import org.eclipse.wst.jsdt.core.runtime.IJSRunner; +import org.eclipse.wst.jsdt.core.runtime.JSRunnerConfiguration; + +/** + * @author "Adalberto Lopez Venegas (adalbert)" + */ +public class NodeJsRunner implements IJSRunner { + private IBaseJSRuntimeInstall jsRuntimeInstall; + + public NodeJsRunner(IBaseJSRuntimeInstall jsRuntimeInstall) { + this.jsRuntimeInstall = jsRuntimeInstall; + } + + public IProcess run(JSRunnerConfiguration configuration, ILaunch launch, IProgressMonitor monitor) throws CoreException { + List<String> cmdLine = new ArrayList<String>(); + cmdLine.add(jsRuntimeInstall.getInstallLocation().getPath()); + + String [] nodeRuntimeArguments = combineRuntimeArgs(configuration, jsRuntimeInstall); + if (nodeRuntimeArguments.length != 0) { + for (String argument : nodeRuntimeArguments) { + cmdLine.add(argument); + } + } + + String mainFile = configuration.getFileToLaunch(); + cmdLine.add(mainFile); + + String [] appArguments = configuration.getProgramArguments(); + if (appArguments.length != 0) { + for (String argument : appArguments) { + cmdLine.add(argument); + } + } + + File workingPath = null; + String workingDirectory = configuration.getWorkingDirectory(); + if (workingDirectory.length() > 0){ + workingPath = new File(workingDirectory); + } + + String[] cmds = {}; + cmds = cmdLine.toArray(cmds); + + ProcessBuilder builder = new ProcessBuilder(cmds); + builder.directory(workingPath); + try { + Process process = builder.start(); + builder.redirectErrorStream(true); + return DebugPlugin.newProcess(launch, process, "Node.js process"); //$NON-NLS-1$ + } catch (Exception ex) { + } + + return null; + } + + protected String[] combineRuntimeArgs(JSRunnerConfiguration configuration, IBaseJSRuntimeInstall jsRuntimeInstall2) { + String[] launchVMArgs= configuration.getJSRuntimeArguments(); + String[] vmVMArgs = jsRuntimeInstall2.getJSRuntimeArguments(); + if (vmVMArgs == null || vmVMArgs.length == 0) { + return launchVMArgs; + } + + String[] allVMArgs = new String[launchVMArgs.length + vmVMArgs.length]; + System.arraycopy(vmVMArgs, 0, allVMArgs, 0, vmVMArgs.length); + System.arraycopy(launchVMArgs, 0, allVMArgs, vmVMArgs.length, launchVMArgs.length); + return allVMArgs; + } +} diff --git a/nodejs/pom.xml b/nodejs/pom.xml index b9bb46b16..c0e0c76dc 100644 --- a/nodejs/pom.xml +++ b/nodejs/pom.xml @@ -29,6 +29,7 @@ <module>org.eclipse.wst.jsdt.js.npm</module> <module>org.eclipse.wst.jsdt.js.grunt</module> <module>org.eclipse.wst.jsdt.js.gulp</module> + <module>org.eclipse.wst.jsdt.js.node</module> <module>org.eclipse.wst.jsdt.js.node.common</module> </modules> </project> |