mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Added sketch launching. Clicking the run button with an open sketch or a sketch folder / file highlighted in the navigator runs an applet just like the PDE, without saving any config. If there are errors, the applet won't load, and errors are reported in the console and Problems view.
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1 @@
|
||||
APPL????
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
|
||||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>CFBundleName</key>
|
||||
<string>@@sketch@@</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleAllowMixedLocalizations</key>
|
||||
<string>true</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>JavaApplicationStub</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>sketch.icns</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>@@sketch@@</string>
|
||||
|
||||
<!-- http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Articles/PListKeys.html#//apple_ref/doc/uid/20001431-113616 -->
|
||||
<key>LSUIPresentationMode</key>
|
||||
<integer>@@lsuipresentationmode@@</integer>
|
||||
|
||||
<!-- make sure that applications open in 32-bit mode on Snow Leopard,
|
||||
otherwise video and most other native libraries will choke
|
||||
http://developer.apple.com/mac/library/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW1 -->
|
||||
<key>LSArchitecturePriority</key>
|
||||
<array>
|
||||
<string>i386</string>
|
||||
<string>ppc</string>
|
||||
</array>
|
||||
|
||||
<key>Java</key>
|
||||
<dict>
|
||||
<key>VMOptions</key>
|
||||
<string>@@vmoptions@@</string>
|
||||
<key>MainClass</key>
|
||||
<string>@@sketch@@</string>
|
||||
<key>JVMVersion</key>
|
||||
<string>1.5*</string>
|
||||
<key>JVMArchs</key>
|
||||
<array>
|
||||
<string>i386</string>
|
||||
<string>ppc</string>
|
||||
</array>
|
||||
<key>ClassPath</key>
|
||||
<string>@@classpath@@</string>
|
||||
|
||||
<!-- http://developer.apple.com/releasenotes/Java/java141/system_properties/chapter_4_section_1.html#//apple_ref/doc/uid/TP30000285 -->
|
||||
<key>Properties</key>
|
||||
<dict>
|
||||
<key>apple.laf.useScreenMenuBar</key>
|
||||
<string>true</string>
|
||||
<key>apple.awt.showGrowBox</key>
|
||||
<string>false</string>
|
||||
<key>com.apple.smallTabs</key>
|
||||
<string>true</string>
|
||||
<key>apple.awt.Antialiasing</key>
|
||||
<string>false</string>
|
||||
<key>apple.awt.TextAntialiasing</key>
|
||||
<string>true</string>
|
||||
<key>com.apple.hwaccel</key>
|
||||
<string>true</string>
|
||||
<key>apple.awt.use-file-dialog-packages</key>
|
||||
<string>false</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -45,7 +45,7 @@
|
||||
delegate="processing.plugin.core.launching.ProcessingSketchLaunchConfigurationDelegate"
|
||||
id="processing.plugin.core.launching.processingSketch"
|
||||
modes="run"
|
||||
name="Processing Sketch">
|
||||
name="Processing Sketch Applet">
|
||||
<!--sourcePathComputerId="org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer"
|
||||
sourceLocatorId="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector" -->
|
||||
</launchConfigurationType>
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
|
||||
import processing.plugin.core.builder.Utilities;
|
||||
@@ -75,19 +76,30 @@ public final class ProcessingCore extends Plugin {
|
||||
/* public void start(BundleContext context) throws Exception {} */
|
||||
/* public void stop(BundleContext context) throws Exception {} */
|
||||
|
||||
|
||||
/**
|
||||
* Gets a URL to a file or folder in the plug-in's Resources folder.
|
||||
* Returns null if something went wrong.
|
||||
* Returns null if the path results in a bad URL.
|
||||
*
|
||||
* @param path relative path from the Resources folder
|
||||
*/
|
||||
public URL getPluginResource(String fileName){
|
||||
public URL getPluginResource(String path){
|
||||
try{
|
||||
return new URL(this.getBundle().getEntry("/"), "Resources/" + fileName);
|
||||
return new URL(this.getBundle().getEntry("/"), "Resources/" + path);
|
||||
} catch (MalformedURLException e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URL to a file or folder in the plug-in's Resources folder.
|
||||
* Returns null if the path results in a bad URL.
|
||||
*
|
||||
* @param path relative from the Resources folder
|
||||
*/
|
||||
public URL getPluginResource(IPath path){
|
||||
return getPluginResource(path.toOSString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the plug-in resources folder to a File and returns it. This will include the
|
||||
* Processing libraries and the core libraries folder.
|
||||
@@ -95,7 +107,7 @@ public final class ProcessingCore extends Plugin {
|
||||
* @return File reference to the core resources
|
||||
*/
|
||||
public File getPluginResourceFolder(){
|
||||
URL fileLocation = ProcessingCore.getProcessingCore().getPluginResource("");
|
||||
URL fileLocation = getPluginResource("");
|
||||
try {
|
||||
File folder = new File(FileLocator.toFileURL(fileLocation).getPath());
|
||||
if (folder.exists())
|
||||
|
||||
+1
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.Preferences;
|
||||
* be done by preferences pages in processing.plugin.ui plug-in, but
|
||||
* may be programatically accessed in the case of headless operation.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ProcessingCorePreferences {
|
||||
|
||||
private static ProcessingCorePreferences current;
|
||||
|
||||
@@ -226,6 +226,45 @@ public class SketchBuilder extends IncrementalProjectBuilder{
|
||||
StringWriter stream = new StringWriter();
|
||||
|
||||
result = preproc.write(stream, bigCode.toString(), codeFolderPackages);
|
||||
|
||||
String scrubbed = Utilities.scrubComments(stream.toString());
|
||||
String[] matches = Utilities.match(scrubbed, Utilities.SIZE_REGEX);
|
||||
|
||||
if(matches != null){
|
||||
try {
|
||||
int wide = Integer.parseInt(matches[1]);
|
||||
int high = Integer.parseInt(matches[2]);
|
||||
|
||||
if (high > 0){
|
||||
SketchProject.sketch_height = high;
|
||||
} else {
|
||||
SketchProject.sketch_height = -1;
|
||||
}
|
||||
if( wide > 0) {
|
||||
SketchProject.sketch_width = wide;
|
||||
} else {
|
||||
SketchProject.sketch_width = -1;
|
||||
}
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
// found a reference to size, but it didn't
|
||||
// seem to contain numbers
|
||||
|
||||
// final String message =
|
||||
// "The size of this applet could not automatically be\n" +
|
||||
// "determined from your code. You'll have to edit the\n" +
|
||||
// "HTML file to set the size of the applet.\n" +
|
||||
// "Use only numeric values (not variables) for the size()\n" +
|
||||
// "command. See the size() reference for an explanation.";
|
||||
|
||||
// set these back to null
|
||||
SketchProject.sketch_height = -1;
|
||||
SketchProject.sketch_width = -1;
|
||||
|
||||
ProcessingLog.logInfo("Could not find applet size");
|
||||
}
|
||||
} // else no size() command found
|
||||
|
||||
ByteArrayInputStream inStream = new ByteArrayInputStream(stream.toString().getBytes());
|
||||
try{
|
||||
if (!output.exists()){
|
||||
|
||||
+24
-1
@@ -29,12 +29,19 @@ import processing.plugin.core.ProcessingLog;
|
||||
|
||||
public class SketchProject implements IProjectNature {
|
||||
|
||||
/** value: <code>"processing.plugin.core.processingnature"</code> */
|
||||
/** value: <code>"processing.plugin.core.sketchNature"</code> */
|
||||
public static final String NATURE_ID = ProcessingCore.PLUGIN_ID + ".sketchNature";
|
||||
|
||||
/** The basic project entry being managed */
|
||||
protected IProject project;
|
||||
|
||||
// TODO make these a preference
|
||||
public static final int DEFAULT_WIDTH = 100;
|
||||
public static final int DEFAULT_HEIGHT = 100;
|
||||
|
||||
// set every build
|
||||
protected static int sketch_width = -1;
|
||||
protected static int sketch_height = -1;
|
||||
|
||||
/**
|
||||
* Return the SketchProject associated with the given IProject, or null
|
||||
@@ -434,4 +441,20 @@ public class SketchProject implements IProjectNature {
|
||||
|
||||
JavaCore.setOptions(options);
|
||||
}
|
||||
|
||||
/** Return the sketch's height, or the default height if size() has not been specified */
|
||||
public int getHeight() {
|
||||
return (sketch_height == -1) ? DEFAULT_HEIGHT : sketch_height;
|
||||
}
|
||||
|
||||
/** Return the sketch's width, or the default width if size() has not been specified */
|
||||
public int getWidth(){
|
||||
return (sketch_width == -1) ? DEFAULT_WIDTH : sketch_width;
|
||||
}
|
||||
|
||||
/** Returns the name of the main type of the compiled sketch*/
|
||||
public String getMainType() {
|
||||
return project.getName();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import java.util.zip.ZipFile;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
import processing.plugin.core.ProcessingCore;
|
||||
import processing.plugin.core.ProcessingCorePreferences;
|
||||
import processing.plugin.core.ProcessingLog;
|
||||
@@ -37,7 +38,9 @@ import processing.plugin.core.ProcessingLog;
|
||||
public class Utilities {
|
||||
|
||||
public static final String PACKAGE_REGEX = "(?:^|\\s|;)package\\s+(\\S+)\\;";
|
||||
|
||||
public static final String SIZE_REGEX =
|
||||
"(?:^|\\s|;)size\\s*\\(\\s*(\\S+)\\s*,\\s*([^\\s,\\)]+),?\\s*([^\\)]*)\\s*\\)\\s*\\;";
|
||||
|
||||
/**
|
||||
* Read in a file and return it as a string
|
||||
*
|
||||
@@ -496,5 +499,53 @@ public class Utilities {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public String scrubComments(String what) {
|
||||
char p[] = what.toCharArray();
|
||||
|
||||
int index = 0;
|
||||
while (index < p.length) {
|
||||
// for any double slash comments, ignore until the end of the line
|
||||
if ((p[index] == '/') &&
|
||||
(index < p.length - 1) &&
|
||||
(p[index+1] == '/')) {
|
||||
p[index++] = ' ';
|
||||
p[index++] = ' ';
|
||||
while ((index < p.length) &&
|
||||
(p[index] != '\n')) {
|
||||
p[index++] = ' ';
|
||||
}
|
||||
|
||||
// check to see if this is the start of a new multiline comment.
|
||||
// if it is, then make sure it's actually terminated somewhere.
|
||||
} else if ((p[index] == '/') &&
|
||||
(index < p.length - 1) &&
|
||||
(p[index+1] == '*')) {
|
||||
p[index++] = ' ';
|
||||
p[index++] = ' ';
|
||||
boolean endOfRainbow = false;
|
||||
while (index < p.length - 1) {
|
||||
if ((p[index] == '*') && (p[index+1] == '/')) {
|
||||
p[index++] = ' ';
|
||||
p[index++] = ' ';
|
||||
endOfRainbow = true;
|
||||
break;
|
||||
|
||||
} else {
|
||||
// continue blanking this area
|
||||
p[index++] = ' ';
|
||||
}
|
||||
}
|
||||
if (!endOfRainbow) {
|
||||
throw new RuntimeException("Missing the */ from the end of a " +
|
||||
"/* comment */");
|
||||
}
|
||||
} else { // any old character, move along
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return new String(p);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package processing.plugin.core.launching;
|
||||
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
|
||||
import org.eclipse.jdt.launching.StandardClasspathProvider;
|
||||
|
||||
public class ProcessingClasspathProvider extends StandardClasspathProvider{
|
||||
|
||||
public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+176
-25
@@ -1,34 +1,65 @@
|
||||
/*******************************************************************************
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Common Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.opensource.org/licenses/cpl1.0.php
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Chris Lonnen - adaptation for Processing
|
||||
*******************************************************************************/
|
||||
package processing.plugin.core.launching;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.debug.core.IDebugEventSetListener;
|
||||
import org.eclipse.debug.core.ILaunch;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchManager;
|
||||
|
||||
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
|
||||
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
|
||||
import org.eclipse.jdt.launching.IVMInstall;
|
||||
import org.eclipse.jdt.launching.JavaLaunchDelegate;
|
||||
import org.eclipse.jdt.launching.JavaRuntime;
|
||||
|
||||
/**
|
||||
* The launch configuration delegate for Processing Sketches. It is really a customized Java
|
||||
* launch configuration delegate, as Processing Sketches are compiled down and ultimately run
|
||||
* as Java applications (shhh! dont tell anyone)
|
||||
* as Java applications (shhh! don't tell anyone).
|
||||
*/
|
||||
public class ProcessingSketchLaunchConfigurationDelegate extends JavaLaunchDelegate {
|
||||
|
||||
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
|
||||
String workingDirectory = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, "");
|
||||
launch.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, workingDirectory);
|
||||
super.launch(configuration, mode, launch, monitor);
|
||||
}
|
||||
public class ProcessingSketchLaunchConfigurationDelegate extends JavaLaunchDelegate implements IDebugEventSetListener {
|
||||
|
||||
/**
|
||||
* If this is being started in run mode return true, otherwise return false to indicate it shouldn't be run
|
||||
* Maps ILaunch objects to File objects that represent the .html file initiating the
|
||||
* applet launch. This is used to delete the .html file when the launch terminates.
|
||||
*/
|
||||
private static Map fgLaunchToFileMap = new HashMap();
|
||||
|
||||
/** Used to map temp file to launch object. */
|
||||
private ILaunch fLaunch;
|
||||
|
||||
/* (non-Javadoc) Makes sure to cleanup the leftovers if things break. */
|
||||
public synchronized void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
|
||||
try{
|
||||
fLaunch = launch;
|
||||
super.launch(configuration, mode, launch, monitor);
|
||||
} catch (CoreException e){
|
||||
cleanup(launch);
|
||||
throw e;
|
||||
}
|
||||
fLaunch = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called first in the launch sequence. Checks to make sure this launcher is being executed
|
||||
* in run mode, and returns true to indicate that things can proceed. If it is being executed
|
||||
* in debug mode or some other unsupported mode, return false to abort the launch.
|
||||
*/
|
||||
public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
|
||||
if(mode.equals(ILaunchManager.RUN_MODE)){
|
||||
@@ -36,21 +67,141 @@ public class ProcessingSketchLaunchConfigurationDelegate extends JavaLaunchDeleg
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Returns the default VMInstall object. */
|
||||
public IVMInstall getVMInstall(ILaunchConfiguration configuration) throws CoreException {
|
||||
return JavaRuntime.getDefaultVMInstall();
|
||||
|
||||
// public String getJavaPolicyFile() ??
|
||||
|
||||
/** Clean up the temp files and listeners after a launch */
|
||||
public void cleanup(ILaunch launch){
|
||||
File temp = (File) fgLaunchToFileMap.get(launch);
|
||||
if (temp != null){
|
||||
try {
|
||||
fgLaunchToFileMap.remove(launch);
|
||||
temp.delete();
|
||||
} finally {
|
||||
// unregister any listeners? there shouldn't be any
|
||||
// because we don't support debugging
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// URL fileLocation = ProcessingCore.getProcessingCore().getPluginResource("");
|
||||
// try {
|
||||
// File folder = new File(FileLocator.toFileURL(fileLocation).getPath());
|
||||
// if (folder.exists())
|
||||
// return folder;
|
||||
// } catch (Exception e) {
|
||||
// ProcessingLog.logError(e);
|
||||
// }
|
||||
|
||||
public File buildHTMLFile(ILaunchConfiguration configuration, File dir) {
|
||||
FileWriter writer = null;
|
||||
File tempFile = null;
|
||||
try {
|
||||
String name = getAppletMainTypeName(configuration);
|
||||
tempFile = new File(dir, name + System.currentTimeMillis() + ".html"); //$NON-NLS-1$
|
||||
writer = new FileWriter(tempFile);
|
||||
writer.write("<html>\n");
|
||||
writer.write("<body>\n");
|
||||
writer.write("<applet code=");
|
||||
writer.write(name);
|
||||
writer.write(".class ");
|
||||
String appletName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_NAME, "");
|
||||
if (appletName.length() != 0) {
|
||||
writer.write("NAME =\"" + appletName + "\" ");
|
||||
}
|
||||
writer.write("width=\"");
|
||||
writer.write(Integer.toString(configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_WIDTH, 200)));
|
||||
writer.write("\" height=\"");
|
||||
writer.write(Integer.toString(configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_HEIGHT, 200)));
|
||||
writer.write("\" >\n");
|
||||
Map parameters = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_PARAMETERS, new HashMap());
|
||||
if (parameters.size() != 0) {
|
||||
Iterator iterator= parameters.entrySet().iterator();
|
||||
while(iterator.hasNext()) {
|
||||
Map.Entry next = (Map.Entry) iterator.next();
|
||||
writer.write("<param name=");
|
||||
writer.write(getQuotedString((String)next.getKey()));
|
||||
writer.write(" value=");
|
||||
writer.write(getQuotedString((String)next.getValue()));
|
||||
writer.write(">\n");
|
||||
}
|
||||
}
|
||||
writer.write("</applet>\n");
|
||||
writer.write("</body>\n");
|
||||
writer.write("</html>\n");
|
||||
} catch(IOException e) {
|
||||
} catch(CoreException e) {
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch(IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
public Map getVMSpecificAttributesMap(ILaunchConfiguration configuration) throws CoreException{
|
||||
return null;
|
||||
public String getQuotedString(String string) {
|
||||
if (string.indexOf('"') == -1) {
|
||||
return '"' + string + '"';
|
||||
}
|
||||
return '\'' + string + '\'';
|
||||
}
|
||||
|
||||
public String[] getClassPath(ILaunchConfiguration configuration) throws CoreException{
|
||||
IRuntimeClasspathEntry[] entries = new ProcessingClasspathProvider().computeUnresolvedClasspath(configuration);
|
||||
//TODO pickup here http://www.eclipse.org/articles/Article-Launch-Framework/launch.html
|
||||
return null;
|
||||
|
||||
|
||||
/* @see org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate#getProgramArguments(org.eclipse.debug.core.ILaunchConfiguration) */
|
||||
public String getProgramArguments(ILaunchConfiguration configuration) throws CoreException{
|
||||
File workingDir = verifyWorkingDirectory(configuration);
|
||||
File htmlFile = buildHTMLFile(configuration, workingDir);
|
||||
if(htmlFile == null){
|
||||
abort("Could not build HTML for applet launch.", null, IJavaLaunchConfigurationConstants.ERR_COULD_NOT_BUILD_HTML);
|
||||
}
|
||||
// add a mapping of the launch to the html file
|
||||
fgLaunchToFileMap.put(fLaunch, htmlFile);
|
||||
return htmlFile.getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Uncomment if we end up using javaPolicyFile
|
||||
// public String getVMArguments(ILaunchConfiguration configuration) throws CoreException {
|
||||
// StringBuffer arguments = new StringBuffer(super.getVMArguments(configuration));
|
||||
// File workingDir = verifyWorkingDirectory(configuration);
|
||||
// String javaPolicyFile = getJavaPolicyFile(workingDir);
|
||||
// arguments.append(javaPolicyFile);
|
||||
// return arguments.toString();
|
||||
// }
|
||||
|
||||
|
||||
public String getMainTypeName(ILaunchConfiguration configuration) throws CoreException{
|
||||
return configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_APPLETVIEWER_CLASS, IJavaLaunchConfigurationConstants.DEFAULT_APPLETVIEWER_CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the applet's main type name.
|
||||
*
|
||||
* @param configuration
|
||||
* @throws CoreException
|
||||
*/
|
||||
public String getAppletMainTypeName(ILaunchConfiguration configuration) throws CoreException{
|
||||
return super.getMainTypeName(configuration);
|
||||
}
|
||||
|
||||
/* @see org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate#getDefaultWorkingDirectory(org.eclipse.debug.core.ILaunchConfiguration) */
|
||||
public File getDefaultWorkingDirectory(ILaunchConfiguration configuration) throws CoreException{
|
||||
// default working dir for applets is the project's output directory
|
||||
String outputDir = JavaRuntime.getProjectOutputDirectory(configuration);
|
||||
if (outputDir == null) {
|
||||
// if no project attribute, default to eclipse directory
|
||||
return new File(System.getProperty("user.dir"));
|
||||
}
|
||||
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(outputDir);
|
||||
if (resource == null || !resource.exists()) {
|
||||
//default to eclipse directory
|
||||
return new File(System.getProperty("user.dir"));
|
||||
}
|
||||
return resource.getLocation().toFile();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,8 +12,11 @@ Require-Bundle: org.eclipse.ui,
|
||||
org.eclipse.jface.text;bundle-version="3.6.0",
|
||||
org.eclipse.ui.editors;bundle-version="3.6.0",
|
||||
org.eclipse.core.resources;bundle-version="3.6.0",
|
||||
processing.plugin.core;bundle-version="0.1.0"
|
||||
|
||||
processing.plugin.core;bundle-version="0.1.0",
|
||||
org.eclipse.debug.ui,
|
||||
org.eclipse.jdt.launching;bundle-version="3.5.100",
|
||||
org.eclipse.ui.ide;bundle-version="3.6.0",
|
||||
org.eclipse.jdt.core;bundle-version="3.6.0"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Import-Package: org.eclipse.ui.actions
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 213 B |
@@ -43,5 +43,43 @@
|
||||
<extension
|
||||
point="org.eclipse.core.runtime.preferences">
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.ide.resourceFilters">
|
||||
<filter
|
||||
pattern = "generated"
|
||||
selected="true">
|
||||
<description>
|
||||
Hides the generated folder and its contents from the UI.
|
||||
</description>
|
||||
|
||||
</filter>
|
||||
</extension>
|
||||
<extension point="org.eclipse.debug.ui.launchShortcuts">
|
||||
<shortcut
|
||||
category="Processing"
|
||||
class="processing.plugin.ui.launching.RunSketchAsAppletShortcut"
|
||||
description="Runs the Sketch as an applet, equivalent to the PDE run button."
|
||||
icon="Resources/16x16_icon.gif"
|
||||
id="processing.plugin.ui.launching.runSketchAsApplet"
|
||||
label="Processing Sketch (Applet)"
|
||||
modes="run">
|
||||
<contextualLaunch>
|
||||
<enablement>
|
||||
<with variable="selection">
|
||||
<count value="1" />
|
||||
<iterate>
|
||||
<or>
|
||||
<test property="org.eclipse.jdt.launching.hasProjectNature" args="processing.plugin.core.sketchNature"/>
|
||||
<test property="org.eclipse.debug.ui.matchesPattern" value="*.pde"/>
|
||||
</or>
|
||||
</iterate>
|
||||
</with>
|
||||
</enablement>
|
||||
</contextualLaunch>
|
||||
</shortcut>
|
||||
</extension>
|
||||
|
||||
|
||||
|
||||
|
||||
</plugin>
|
||||
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
/*******************************************************************************
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Common Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.opensource.org/licenses/cpl1.0.php
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API
|
||||
* Chris Lonnen - implementation for Processing
|
||||
*******************************************************************************/
|
||||
package processing.plugin.ui.launching;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
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.jdt.launching.IJavaLaunchConfigurationConstants;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.ide.ResourceUtil;
|
||||
|
||||
import processing.plugin.core.builder.SketchProject;
|
||||
import processing.plugin.ui.ProcessingLog;
|
||||
|
||||
public class RunSketchAsAppletShortcut implements ILaunchShortcut {
|
||||
|
||||
protected ILaunchConfiguration createConfiguration(IProject project){
|
||||
if (project == null) return null;
|
||||
SketchProject sketch = SketchProject.forProject(project);
|
||||
ILaunchConfiguration config = null;
|
||||
try{
|
||||
ILaunchConfigurationType configType = getConfigurationType();
|
||||
ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, project.getName());
|
||||
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, sketch.getMainType());
|
||||
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName());
|
||||
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_WIDTH, sketch.getWidth());
|
||||
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_HEIGHT, sketch.getHeight());
|
||||
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_NAME, "Processing Sketch");
|
||||
wc.setMappedResources(new IResource[] { sketch.getJavaProject().getUnderlyingResource() });
|
||||
// config =wc.doSave();
|
||||
config = wc; // this prevents a run config from being saved and sticking around.
|
||||
} catch (CoreException ce) {
|
||||
ProcessingLog.logError(ce);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
protected ILaunchConfigurationType getConfigurationType(){
|
||||
ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
|
||||
return lm.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLET);
|
||||
}
|
||||
|
||||
public void launch(ISelection selection, String mode) {
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
Object element = ((IStructuredSelection)selection).getFirstElement();
|
||||
|
||||
if (element instanceof IResource){
|
||||
IProject proj = ((IResource)element).getProject();
|
||||
try{
|
||||
if (proj.hasNature("processing.plugin.core.sketchNature")){
|
||||
launch(createConfiguration(proj), mode);
|
||||
} else {
|
||||
ProcessingLog.logInfo("Sketch could not be launched. The selected project does not have the required Sketch nature.");
|
||||
}
|
||||
} catch (CoreException e){
|
||||
ProcessingLog.logError("Launch aborted.", e);
|
||||
}
|
||||
} else {
|
||||
ProcessingLog.logInfo("Sketch could not be launched. Launcher was provided with a non-resource selection.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// have to implement. log a warning.
|
||||
// there isn't a great way to launch this without a model
|
||||
public void launch(IEditorPart editor, String mode) {
|
||||
IFile file = ResourceUtil.getFile(editor.getEditorInput());
|
||||
if(file != null){
|
||||
IProject proj = file.getProject();
|
||||
try{
|
||||
if (proj.hasNature("processing.plugin.core.sketchNature")){
|
||||
launch(createConfiguration(proj), mode);
|
||||
} else {
|
||||
ProcessingLog.logInfo("Sketch could not be launched. The editor contains a file that is not part of a project with a Sketch nature.");
|
||||
}
|
||||
} catch (CoreException e){
|
||||
ProcessingLog.logError("Launch aborted.", e);
|
||||
}
|
||||
} else {
|
||||
ProcessingLog.logInfo("Launch aborted. Editor contents are not part of a Sketch Project in the workspace");
|
||||
}
|
||||
}
|
||||
|
||||
private void launch(ILaunchConfiguration config, String mode) {
|
||||
if (config != null)
|
||||
DebugUITools.launch(config, mode);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user