Skip to content

Commit

Permalink
Fixes #57 - Option to terminate REPL after execution.
Browse files Browse the repository at this point in the history
Added an option in the launch configuration for installing a REPL or not. True by default.
  • Loading branch information
laurentpetit committed Jul 13, 2009
1 parent 76744d7 commit 6e07f3f
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 35 deletions.
4 changes: 2 additions & 2 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Require-Bundle: org.eclipse.ui,
org.antlr.runtime;bundle-version="3.0.0",
org.eclipse.ui.views,
org.eclipse.core.filesystem,
clojure;bundle-version="0.0.0",
clojurecontrib;bundle-version="0.0.0",
org.eclipse.core.expressions,
org.eclipse.ui.forms
org.eclipse.ui.forms,
clojure;bundle-version="0.0.0"
Export-Package: clojuredev,
clojuredev.launching
Bundle-ClassPath: .,
Expand Down
30 changes: 18 additions & 12 deletions src/clojuredev/launching/ClojureLaunchDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,25 @@ public String getVMArguments(ILaunchConfiguration configuration) throws CoreExce
public String getProgramArguments(ILaunchConfiguration configuration) throws CoreException {
String userProgramArguments = super.getProgramArguments(configuration);

String filesToLaunchArguments = LaunchUtils.getFilesToLaunchAsCommandLineList(configuration);

// Add serverrepl as a file to launch to install a remote server
try {
URL serverReplBundleUrl = ClojuredevPlugin.getDefault().getBundle().getResource("clojuredev/debug/serverrepl.clj");
URL serverReplFileUrl = FileLocator.toFileURL(serverReplBundleUrl);
String serverRepl = serverReplFileUrl.getFile();
filesToLaunchArguments = "-i " + '\"' + serverRepl + "\" " + filesToLaunchArguments;
} catch (IOException e) {
e.printStackTrace();
if (configuration.getAttribute(LaunchUtils.ATTR_CLOJURE_INSTALL_REPL, true)) {
String filesToLaunchArguments = LaunchUtils.getFilesToLaunchAsCommandLineList(configuration, false);

// Add serverrepl as a file to launch to install a remote server
try {
URL serverReplBundleUrl = ClojuredevPlugin.getDefault().getBundle().getResource("clojuredev/debug/serverrepl.clj");
URL serverReplFileUrl = FileLocator.toFileURL(serverReplBundleUrl);
String serverRepl = serverReplFileUrl.getFile();
filesToLaunchArguments = "-i " + '\"' + serverRepl + "\" " + filesToLaunchArguments;
} catch (IOException e) {
e.printStackTrace();
}

return filesToLaunchArguments + " --repl " + userProgramArguments;
} else {
String filesToLaunchArguments = LaunchUtils.getFilesToLaunchAsCommandLineList(configuration, true);

return filesToLaunchArguments + userProgramArguments;
}

return filesToLaunchArguments + " --repl " + userProgramArguments;
}

}
4 changes: 2 additions & 2 deletions src/clojuredev/launching/ClojureLaunchShortcut.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private ILaunchConfiguration findLaunchConfiguration(IProject project, IFile[] f
ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(type);
candidateConfigs = new ArrayList(configs.length);
for (ILaunchConfiguration config: configs) {
if (config.getAttribute(ATTR_MAIN_TYPE_NAME, "").equals(LaunchUtils.MAIN_CLASSNAME)
if (config.getAttribute(ATTR_MAIN_TYPE_NAME, "").startsWith("clojure.")
&& config.getAttribute(ATTR_PROJECT_NAME, "").equals(project.getName())
&& LaunchUtils.getFilesToLaunchList(config).equals(Arrays.asList(files))) {
candidateConfigs.add(config);
Expand Down Expand Up @@ -140,7 +140,7 @@ protected ILaunchConfiguration createConfiguration(IProject project, IFile[] fil

wc.setAttribute(ATTR_PROGRAM_ARGUMENTS, "");

wc.setAttribute(ATTR_MAIN_TYPE_NAME, LaunchUtils.MAIN_CLASSNAME);
wc.setAttribute(ATTR_MAIN_TYPE_NAME, LaunchUtils.MAIN_CLASSNAME_FOR_REPL);

wc.setAttribute(ATTR_PROJECT_NAME, project.getName());

Expand Down
38 changes: 32 additions & 6 deletions src/clojuredev/launching/ClojureMainTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
Expand Down Expand Up @@ -65,6 +66,7 @@ public class ClojureMainTab extends AbstractJavaMainTab implements IJavaLaunchCo

protected TableViewer sourceFilesViewer;

private Button installREPLChoice;
private Text serverPort;

public String getName() {
Expand Down Expand Up @@ -137,12 +139,27 @@ public void widgetSelected(SelectionEvent e) {
}

private void createReplServerControl(final Composite parent) {
Group section = SWTFactory.createGroup(parent, "Repl remote control settings",
Group section = SWTFactory.createGroup(parent, "Repl settings",
2, 1, 0);

installREPLChoice = SWTFactory.createCheckButton(
section, "Install a REPL (see tooltip for detail)", null, true, 2);
installREPLChoice.setToolTipText("If checked, the main class will be clojure.contrib.repl_ln, all files listed will be loaded"
+ " with the -i option.\n If unchecked, the main class will be clojure.main, all files listed but the last will be loaded"
+ " with the -i option, and the last file will be loaded as a script.");

SWTFactory.createLabel(section, "Remote server must listen on port: ", 1);
serverPort = SWTFactory.createSingleText(section, 0);

installREPLChoice.addSelectionListener( new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {}

public void widgetSelected(SelectionEvent e) {
serverPort.setEnabled(installREPLChoice.getSelection());
updateLaunchConfigurationDialog();
}
});

serverPort.addModifyListener( new ModifyListener() {
public void modifyText(ModifyEvent e) {
updateLaunchConfigurationDialog();
Expand All @@ -160,9 +177,9 @@ public void setDefaults(ILaunchConfigurationWorkingCopy config) {

try {
if (config.getAttribute(ATTR_MAIN_TYPE_NAME, (String) null) == null) {
config.setAttribute(ATTR_MAIN_TYPE_NAME, LaunchUtils.MAIN_CLASSNAME);
config.setAttribute(ATTR_MAIN_TYPE_NAME, LaunchUtils.MAIN_CLASSNAME_FOR_REPL);
}

config.setAttribute(LaunchUtils.ATTR_CLOJURE_INSTALL_REPL, true);
config.setAttribute(LaunchUtils.ATTR_CLOJURE_SERVER_LISTEN, LaunchUtils.DEFAULT_SERVER_PORT);

config.doSave();
Expand All @@ -183,9 +200,14 @@ public void initializeFrom(ILaunchConfiguration config) {
}

try {
installREPLChoice.setSelection(config.getAttribute(
LaunchUtils.ATTR_CLOJURE_INSTALL_REPL, true));
serverPort.setText(Integer.toString(config.getAttribute(LaunchUtils.ATTR_CLOJURE_SERVER_LISTEN, LaunchUtils.DEFAULT_SERVER_PORT)));
serverPort.setEnabled(installREPLChoice.getSelection());
} catch (CoreException e) {
ClojuredevPlugin.logError("error while initializing serverPort", e);
installREPLChoice.setSelection(true);
serverPort.setEnabled(true);
serverPort.setText("");
}
try {
Expand All @@ -202,11 +224,15 @@ public void performApply(ILaunchConfigurationWorkingCopy config) {
config.setAttribute(ATTR_PROJECT_NAME, fProjText.getText().trim());

LaunchUtils.setFilesToLaunchString(config, (List<IFile>) sourceFilesViewer.getInput());


config.setAttribute(ATTR_MAIN_TYPE_NAME,
installREPLChoice.getSelection()
? LaunchUtils.MAIN_CLASSNAME_FOR_REPL
: LaunchUtils.MAIN_CLASSNAME);

config.setAttribute(LaunchUtils.ATTR_CLOJURE_INSTALL_REPL, installREPLChoice.getSelection());
config.setAttribute(LaunchUtils.ATTR_CLOJURE_SERVER_LISTEN, Integer.valueOf(serverPort.getText()));

mapResources(config);
}


}
40 changes: 27 additions & 13 deletions src/clojuredev/launching/LaunchUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ private LaunchUtils(){}

static public final String LAUNCH_ID = "clojuredev.launching.clojure";

// static public final String MAIN_CLASSNAME = "clojure.lang.Repl";
static public final String MAIN_CLASSNAME = "clojure.contrib.repl_ln";
// static public final String MAIN_CLASSNAME = "clojure.lang.Repl";
static public final String MAIN_CLASSNAME = "clojure.main";
static public final String MAIN_CLASSNAME_FOR_REPL = "clojure.contrib.repl_ln";

static public final int DEFAULT_SERVER_PORT = -1;

Expand All @@ -52,19 +51,34 @@ private LaunchUtils(){}

public static final String SERVER_FILE_PORT_SUFFFIX = ".port";

static public String getProgramArguments(IFile[] files) {
public static final String ATTR_CLOJURE_INSTALL_REPL = "CLOJUREDEV_ATTR_CLOJURE_INSTALL_REPL";

/**
* @param files
* @param lastFileAsScript if true, does not install the last arg as a resource to load, but as
* a script to launch
* @return
*/
static public String getProgramArguments(IFile[] files, boolean lastFileAsScript) {
StringBuilder args = new StringBuilder();
for (IFile srcFile : files) {
if (args.length() > 0) {
args.append(" ");
}
args.append("-i \"" + srcFile.getLocation().toString() + "\"");

int lastIndex = lastFileAsScript ? files.length - 1 : files.length;

for (int i = 0; i < lastIndex; i++) {
args.append(" -i" + fileArg(files[i]));
}
if (lastFileAsScript) {
args.append(fileArg(files[lastIndex]));
}
return args.toString();
}

static public String getProgramArguments(List<IFile> files) {
return getProgramArguments(files.toArray(new IFile[]{}));
private static String fileArg(IFile file) {
return " \"" + file.getLocation().toString() + "\"";
}

static public String getProgramArguments(List<IFile> files, boolean lastFileAsScript) {
return getProgramArguments(files.toArray(new IFile[]{}), lastFileAsScript);
}

static public List<IFile> getFilesToLaunchList(ILaunchConfiguration config) throws CoreException {
Expand All @@ -78,9 +92,9 @@ static public List<IFile> getFilesToLaunchList(ILaunchConfiguration config) thro
return selectedFiles;
}

static public String getFilesToLaunchAsCommandLineList(ILaunchConfiguration config) throws CoreException {
static public String getFilesToLaunchAsCommandLineList(ILaunchConfiguration config, boolean lastFileAsScript) throws CoreException {
List<IFile> filesToLaunch = LaunchUtils.getFilesToLaunchList(config);
return LaunchUtils.getProgramArguments(filesToLaunch);
return LaunchUtils.getProgramArguments(filesToLaunch, lastFileAsScript);

}

Expand Down

0 comments on commit 6e07f3f

Please sign in to comment.