Skip to content
This repository has been archived by the owner on Nov 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #18 from dscho/resource-leak
Browse files Browse the repository at this point in the history
Fix resource leak warning, generics warning and remove DOS line endings.
  • Loading branch information
fornwall committed Jul 11, 2013
2 parents 84141db + 0512317 commit 6e46777
Show file tree
Hide file tree
Showing 20 changed files with 1,656 additions and 1,652 deletions.
32 changes: 16 additions & 16 deletions plugin.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
commandCategoryName = EclipseScript
commandCategoryDescription = Commands for using the EclipseScript plug-in
commandRunLastName = EclipseScript: Run Last
commandRunLastDescription = Run the last EclipseScript that has been executed
commandRunCurrentName = EclipseScript: Run Current
commandRunCurrentDescription = Run the currently edited EclipseScript
commandRunScriptParameterName = Script
commandOpenScriptDialogName = EclipseScript: Open Script Dialog
commandOpenScriptDialogDescription = Search and select available scripts

markerName=EclipseScript Problem
pluginName=EclipseScript
bundleVendor=eclipsescript.org
commandRunLastSequence = Ctrl+R
commandRunCurrentSequence = Alt+R
commandOpenScriptDialogSequence = M1+4
commandCategoryName = EclipseScript
commandCategoryDescription = Commands for using the EclipseScript plug-in
commandRunLastName = EclipseScript: Run Last
commandRunLastDescription = Run the last EclipseScript that has been executed
commandRunCurrentName = EclipseScript: Run Current
commandRunCurrentDescription = Run the currently edited EclipseScript
commandRunScriptParameterName = Script
commandOpenScriptDialogName = EclipseScript: Open Script Dialog
commandOpenScriptDialogDescription = Search and select available scripts

markerName=EclipseScript Problem
pluginName=EclipseScript
bundleVendor=eclipsescript.org
commandRunLastSequence = Ctrl+R
commandRunCurrentSequence = Alt+R
commandOpenScriptDialogSequence = M1+4
2 changes: 1 addition & 1 deletion src/org/eclipsescript/core/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void start(BundleContext bundleContext) throws Exception {
// ServiceReference<PlatformAdmin> platformAdminServiceRef = context.getServiceReference(PlatformAdmin.class);
// PlatformAdmin platformAdminService = context.getService(platformAdminServiceRef);
// Eclipse 3.6 api:
ServiceReference platformAdminServiceRef = context.getServiceReference(PlatformAdmin.class.getName());
ServiceReference<?> platformAdminServiceRef = context.getServiceReference(PlatformAdmin.class.getName());
PlatformAdmin platformAdminService = (PlatformAdmin) context.getService(platformAdminServiceRef);

resolver = platformAdminService.createResolver();
Expand Down
70 changes: 35 additions & 35 deletions src/org/eclipsescript/core/RunCurrentHandler.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package org.eclipsescript.core;


import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipsescript.messages.Messages;
import org.eclipsescript.scripts.ScriptLanguageHandler;
import org.eclipsescript.scripts.ScriptMetadata;
import org.eclipsescript.scripts.ScriptStore;
import org.eclipsescript.ui.ErrorHandlingHandler;
import org.eclipsescript.util.EclipseUtils;

public class RunCurrentHandler extends ErrorHandlingHandler {

@Override
protected void doExecute(ExecutionEvent event) throws Exception {
IEditorInput editorInput = EclipseUtils.getCurrentEditorInput();
if (editorInput instanceof FileEditorInput) {
FileEditorInput fileInput = (FileEditorInput) editorInput;
IFile editedFile = fileInput.getFile();
boolean isScriptFile = ScriptLanguageHandler.isEclipseScriptFile(editedFile);
if (isScriptFile) {
ScriptMetadata m = new ScriptMetadata(fileInput.getFile());
ScriptStore.executeScript(m);
return;
}
}
MessageDialog.openInformation(EclipseUtils.getWindowShell(), Messages.cannotRunCurrentScriptTitle,
Messages.cannotRunCurrentScriptText);
}

}
package org.eclipsescript.core;


import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipsescript.messages.Messages;
import org.eclipsescript.scripts.ScriptLanguageHandler;
import org.eclipsescript.scripts.ScriptMetadata;
import org.eclipsescript.scripts.ScriptStore;
import org.eclipsescript.ui.ErrorHandlingHandler;
import org.eclipsescript.util.EclipseUtils;

public class RunCurrentHandler extends ErrorHandlingHandler {

@Override
protected void doExecute(ExecutionEvent event) throws Exception {
IEditorInput editorInput = EclipseUtils.getCurrentEditorInput();
if (editorInput instanceof FileEditorInput) {
FileEditorInput fileInput = (FileEditorInput) editorInput;
IFile editedFile = fileInput.getFile();
boolean isScriptFile = ScriptLanguageHandler.isEclipseScriptFile(editedFile);
if (isScriptFile) {
ScriptMetadata m = new ScriptMetadata(fileInput.getFile());
ScriptStore.executeScript(m);
return;
}
}
MessageDialog.openInformation(EclipseUtils.getWindowShell(), Messages.cannotRunCurrentScriptTitle,
Messages.cannotRunCurrentScriptText);
}

}
52 changes: 26 additions & 26 deletions src/org/eclipsescript/core/RunLastHandler.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package org.eclipsescript.core;


import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipsescript.messages.Messages;
import org.eclipsescript.scripts.ScriptMetadata;
import org.eclipsescript.scripts.ScriptStore;
import org.eclipsescript.ui.ErrorHandlingHandler;
import org.eclipsescript.util.EclipseUtils;

public class RunLastHandler extends ErrorHandlingHandler {

public static ScriptMetadata lastRun = null;

@Override
public void doExecute(ExecutionEvent event) throws ExecutionException {
if (lastRun == null) {
MessageDialog.openWarning(EclipseUtils.activeWindow().getShell(), "No script to run", //$NON-NLS-1$
Messages.runScriptBeforeRunningLast);
} else {
ScriptStore.executeScript(lastRun);
}
}
}
package org.eclipsescript.core;


import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipsescript.messages.Messages;
import org.eclipsescript.scripts.ScriptMetadata;
import org.eclipsescript.scripts.ScriptStore;
import org.eclipsescript.ui.ErrorHandlingHandler;
import org.eclipsescript.util.EclipseUtils;

public class RunLastHandler extends ErrorHandlingHandler {

public static ScriptMetadata lastRun = null;

@Override
public void doExecute(ExecutionEvent event) throws ExecutionException {
if (lastRun == null) {
MessageDialog.openWarning(EclipseUtils.activeWindow().getShell(), "No script to run", //$NON-NLS-1$
Messages.runScriptBeforeRunningLast);
} else {
ScriptStore.executeScript(lastRun);
}
}
}
80 changes: 40 additions & 40 deletions src/org/eclipsescript/javascript/JavaScriptLanguageSupport.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
package org.eclipsescript.javascript;

import org.eclipsescript.javascript.CustomContextFactory.CustomContext;
import org.eclipsescript.rhino.javascript.Context;
import org.eclipsescript.rhino.javascript.ContextAction;
import org.eclipsescript.rhino.javascript.ImporterTopLevel;
import org.eclipsescript.rhino.javascript.ScriptableObject;
import org.eclipsescript.scriptobjects.Eclipse;
import org.eclipsescript.scripts.IScriptLanguageSupport;
import org.eclipsescript.scripts.ScriptMetadata;

public class JavaScriptLanguageSupport implements IScriptLanguageSupport {

private final CustomContextFactory contextFactory = new CustomContextFactory();

@Override
public void executeScript(final ScriptMetadata script) {
contextFactory.call(new ContextAction() {
@Override
public Object run(Context _context) {
if (!(_context instanceof CustomContext))
throw new IllegalArgumentException("Wrong context class: " + _context.getClass()); //$NON-NLS-1$
CustomContext context = (CustomContext) _context;
ScriptableObject scope = new ImporterTopLevel(context);
JavascriptRuntime jsRuntime = new JavascriptRuntime(context, scope, script);

Eclipse eclipseJavaObject = new Eclipse(jsRuntime);
Object eclipseJsObject = Context.javaToJS(eclipseJavaObject, scope);
ScriptableObject.putConstProperty(scope, Eclipse.VARIABLE_NAME, eclipseJsObject);

try {
jsRuntime.evaluate(script.getFile(), false);
} catch (Throwable e) {
jsRuntime.handleExceptionFromScriptRuntime(e);
}
return null;
}
});
}
}
package org.eclipsescript.javascript;

import org.eclipsescript.javascript.CustomContextFactory.CustomContext;
import org.eclipsescript.rhino.javascript.Context;
import org.eclipsescript.rhino.javascript.ContextAction;
import org.eclipsescript.rhino.javascript.ImporterTopLevel;
import org.eclipsescript.rhino.javascript.ScriptableObject;
import org.eclipsescript.scriptobjects.Eclipse;
import org.eclipsescript.scripts.IScriptLanguageSupport;
import org.eclipsescript.scripts.ScriptMetadata;

public class JavaScriptLanguageSupport implements IScriptLanguageSupport {

private final CustomContextFactory contextFactory = new CustomContextFactory();

@Override
public void executeScript(final ScriptMetadata script) {
contextFactory.call(new ContextAction() {
@Override
public Object run(Context _context) {
if (!(_context instanceof CustomContext))
throw new IllegalArgumentException("Wrong context class: " + _context.getClass()); //$NON-NLS-1$
CustomContext context = (CustomContext) _context;
ScriptableObject scope = new ImporterTopLevel(context);
JavascriptRuntime jsRuntime = new JavascriptRuntime(context, scope, script);

Eclipse eclipseJavaObject = new Eclipse(jsRuntime);
Object eclipseJsObject = Context.javaToJS(eclipseJavaObject, scope);
ScriptableObject.putConstProperty(scope, Eclipse.VARIABLE_NAME, eclipseJsObject);

try {
jsRuntime.evaluate(script.getFile(), false);
} catch (Throwable e) {
jsRuntime.handleExceptionFromScriptRuntime(e);
}
return null;
}
});
}
}
88 changes: 44 additions & 44 deletions src/org/eclipsescript/messages/Messages.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
package org.eclipsescript.messages;

import org.eclipse.osgi.util.NLS;

/**
* Localization messages using the {@link NLS} system. The static initializer block will initialize the fields of this
* class with values loaded from the messages properties file.
*/
public class Messages extends NLS {

private static final String BUNDLE_NAME = Messages.class.getPackage().getName() + ".messages"; //$NON-NLS-1$

public static String cannotRunCurrentScriptText;
public static String cannotRunCurrentScriptTitle;
public static String clearMarkersJobName;
public static String fileToIncludeDoesNotExist;
public static String fileToReadDoesNotExist;
public static String internalErrorDialogDetails;
public static String internalErrorDialogText;
public static String internalErrorDialogTitle;
public static String noDocumentSelected;
public static String noSelectionSelected;
public static String noTextEditorSelected;
public static String notPossibleToScheduleObject;
public static String removeAllTerminatedConsoles;
public static String Resources_cannotReadFromObject;
public static String runScriptBeforeRunningLast;
public static String scriptAlertDialogTitle;
public static String scriptBackgroundJobName;
public static String scriptConfirmDialogTitle;
public static String scriptConsoleName;
public static String scriptErrorWhenRunningScriptDialogText;
public static String scriptErrorWhenRunningScriptDialogTitle;
public static String scriptErrorWhenRunningScriptJumpToScriptButton;
public static String scriptErrorWhenRunningScriptOkButton;
public static String scriptPromptDialogTitle;
public static String scriptTimeout;
public static String windowOpenArgumentNull;

static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

}
package org.eclipsescript.messages;

import org.eclipse.osgi.util.NLS;

/**
* Localization messages using the {@link NLS} system. The static initializer block will initialize the fields of this
* class with values loaded from the messages properties file.
*/
public class Messages extends NLS {

private static final String BUNDLE_NAME = Messages.class.getPackage().getName() + ".messages"; //$NON-NLS-1$

public static String cannotRunCurrentScriptText;
public static String cannotRunCurrentScriptTitle;
public static String clearMarkersJobName;
public static String fileToIncludeDoesNotExist;
public static String fileToReadDoesNotExist;
public static String internalErrorDialogDetails;
public static String internalErrorDialogText;
public static String internalErrorDialogTitle;
public static String noDocumentSelected;
public static String noSelectionSelected;
public static String noTextEditorSelected;
public static String notPossibleToScheduleObject;
public static String removeAllTerminatedConsoles;
public static String Resources_cannotReadFromObject;
public static String runScriptBeforeRunningLast;
public static String scriptAlertDialogTitle;
public static String scriptBackgroundJobName;
public static String scriptConfirmDialogTitle;
public static String scriptConsoleName;
public static String scriptErrorWhenRunningScriptDialogText;
public static String scriptErrorWhenRunningScriptDialogTitle;
public static String scriptErrorWhenRunningScriptJumpToScriptButton;
public static String scriptErrorWhenRunningScriptOkButton;
public static String scriptPromptDialogTitle;
public static String scriptTimeout;
public static String windowOpenArgumentNull;

static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

}
50 changes: 25 additions & 25 deletions src/org/eclipsescript/messages/messages.properties
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
internalErrorDialogTitle=EclipseScript Internal Error
internalErrorDialogText=The error has been logged. See below for details.
internalErrorDialogDetails=Plug-in name: {0}\nPlug-in ID: {1}\nVersion: {2}\n\n{3}
runScriptBeforeRunningLast=No EclipseScript script has been run\!
scriptAlertDialogTitle=EclipseScript Alert
scriptConfirmDialogTitle=EclipseScript Prompt
scriptConsoleName=EclipseScript: {0}
scriptErrorWhenRunningScriptDialogTitle=EclipseScript Error
scriptErrorWhenRunningScriptDialogText=Execution of the script "{0}" failed at line {2} with the following message:\n\n{1}
scriptErrorWhenRunningScriptJumpToScriptButton=&Go to script
scriptErrorWhenRunningScriptOkButton=&Ok
scriptTimeout = Script timeout after {0} seconds.\n\nTry using the eclipse.runtime.schedule(runnable) function for long-running background tasks.
scriptBackgroundJobName=EclipseScript: {0}
scriptPromptDialogTitle=EclipseScript Prompt
cannotRunCurrentScriptText=Cannot run the currently edited script
cannotRunCurrentScriptTitle=Cannot run
clearMarkersJobName=Clear script markers
fileToIncludeDoesNotExist=File does not exist:
fileToReadDoesNotExist=File to read does not exist:
noDocumentSelected=No document selected\!
noSelectionSelected=No selection selected\!
noTextEditorSelected=No text editor selected\!
notPossibleToScheduleObject=Not possible to schedule object:
Resources_cannotReadFromObject=Cannot read from object:
windowOpenArgumentNull=The urlString argument to open(urlString) was null
internalErrorDialogTitle=EclipseScript Internal Error
internalErrorDialogText=The error has been logged. See below for details.
internalErrorDialogDetails=Plug-in name: {0}\nPlug-in ID: {1}\nVersion: {2}\n\n{3}
runScriptBeforeRunningLast=No EclipseScript script has been run\!
scriptAlertDialogTitle=EclipseScript Alert
scriptConfirmDialogTitle=EclipseScript Prompt
scriptConsoleName=EclipseScript: {0}
scriptErrorWhenRunningScriptDialogTitle=EclipseScript Error
scriptErrorWhenRunningScriptDialogText=Execution of the script "{0}" failed at line {2} with the following message:\n\n{1}
scriptErrorWhenRunningScriptJumpToScriptButton=&Go to script
scriptErrorWhenRunningScriptOkButton=&Ok
scriptTimeout = Script timeout after {0} seconds.\n\nTry using the eclipse.runtime.schedule(runnable) function for long-running background tasks.
scriptBackgroundJobName=EclipseScript: {0}
scriptPromptDialogTitle=EclipseScript Prompt
cannotRunCurrentScriptText=Cannot run the currently edited script
cannotRunCurrentScriptTitle=Cannot run
clearMarkersJobName=Clear script markers
fileToIncludeDoesNotExist=File does not exist:
fileToReadDoesNotExist=File to read does not exist:
noDocumentSelected=No document selected\!
noSelectionSelected=No selection selected\!
noTextEditorSelected=No text editor selected\!
notPossibleToScheduleObject=Not possible to schedule object:
Resources_cannotReadFromObject=Cannot read from object:
windowOpenArgumentNull=The urlString argument to open(urlString) was null
removeAllTerminatedConsoles=Remove All EclipseScript Consoles
Loading

0 comments on commit 6e46777

Please sign in to comment.