/
HaskellLaunchDelegate.java
143 lines (110 loc) · 5.13 KB
/
HaskellLaunchDelegate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright (c) 2003-2008 by Leif Frenzel. All rights reserved.
// This code is made available under the terms of the Eclipse Public License,
// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
package net.sf.eclipsefp.haskell.debug.core.internal.launch;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.sf.eclipsefp.haskell.debug.core.internal.HaskellDebugCore;
import net.sf.eclipsefp.haskell.debug.core.internal.debug.HaskellDebugTarget;
import net.sf.eclipsefp.haskell.debug.core.internal.util.CoreTexts;
import net.sf.eclipsefp.haskell.util.PlatformUtil;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchesListener2;
import org.eclipse.debug.core.model.IProcess;
/** <p>Implements the launching functionality for Haskell launch interactive (GHCi, Hugs)
* configurations.</p>
*
* @author Leif Frenzel
*/
public class HaskellLaunchDelegate extends AbstractHaskellLaunchDelegate {
// static final String DEBUG_PROCESS_TYPE = "net.sf.eclipsefp.haskell.debug.ui.internal.launch.ghci.GhciProcessType"; //$NON-NLS-1$
@Override
protected void preProcessCreation( final ILaunchConfiguration configuration,
final String mode, final ILaunch launch, final Map<String, String> processAttribs ) {
// NOOP
}
@Override
protected void postProcessCreation( final ILaunchConfiguration configuration,
final String mode, final ILaunch launch, final IProcess process ) throws CoreException{
process.setAttribute( HaskellDebugCore.PROCESS_COMMAND_HISTORY, Boolean.TRUE.toString() );
List<String> fileNames=configuration.getAttribute( ILaunchAttributes.FILES, new ArrayList<String>() );
if (mode.equals( ILaunchManager.DEBUG_MODE )){
HaskellDebugTarget hdt=new HaskellDebugTarget( launch, process,fileNames );
launch.addDebugTarget(hdt);
hdt.start();
}
registerReloadListener(configuration,launch,process);
}
@Override
protected void preProcessDefinitionCreation(
final ILaunchConfiguration configuration, final String mode, final ILaunch launch ) {
// NOOP
}
@Override
protected void postProcessFinished(final ILaunchConfiguration configuration) {
// NOOP
}
public static void commandToProcess(final IProcess p,final String command) throws CoreException{
try {
if (command!=null && command.length()>0){
p.getStreamsProxy().write( command );
p.getStreamsProxy().write( PlatformUtil.NL );
}
} catch (IOException ioe){
Status status = new Status(IStatus.ERROR, HaskellDebugCore.getPluginId(),CoreTexts.console_command_failed, ioe);
throw new CoreException(status);
}
}
private void registerReloadListener(final ILaunchConfiguration configuration,final ILaunch launch,final IProcess process) throws CoreException{
final String command= configuration.getAttribute( ILaunchAttributes.COMMAND, (String)null );
commandToProcess( process, command );
String reloadCommand=configuration.getAttribute( ILaunchAttributes.RELOAD_COMMAND, (String)null );
IInteractiveLaunchOperationDelegate del=getDelegate( configuration );
if (del!=null && del.getReloadCommand()!=null){
reloadCommand=del.getReloadCommand();
}
final String project=configuration.getAttribute( ILaunchAttributes.PROJECT_NAME, (String)null );
if (reloadCommand!=null && configuration.getAttribute( ILaunchAttributes.RELOAD, false )){
final boolean commandOnReload= configuration.getAttribute( ILaunchAttributes.COMMAND_ON_RELOAD, false );
final CommandOnChangeListener cocl=new CommandOnChangeListener(process,project,
reloadCommand,
commandOnReload?command:null);
ResourcesPlugin.getWorkspace().addResourceChangeListener(
cocl, IResourceChangeEvent.PRE_BUILD );
ILaunchesListener2 ll=new ILaunchesListener2() {
@Override
public void launchesRemoved( final ILaunch[] launches ) {
// NOOP
}
@Override
public void launchesChanged( final ILaunch[] launches ) {
// NOOP
}
@Override
public void launchesAdded( final ILaunch[] launches ) {
// NOOP
}
@Override
public void launchesTerminated( final ILaunch[] launches ) {
for (ILaunch l:launches){
if (launch.equals( l )){
ResourcesPlugin.getWorkspace().removeResourceChangeListener( cocl );
DebugPlugin.getDefault().getLaunchManager().removeLaunchListener( this );
}
}
}
};
DebugPlugin.getDefault().getLaunchManager().addLaunchListener( ll );
}
}
}