Skip to content

Commit

Permalink
ghci launch: use cabal flags and packages, automation tab
Browse files Browse the repository at this point in the history
  • Loading branch information
JPMoresmau committed Oct 17, 2009
1 parent 6ae57fb commit 8eb569f
Show file tree
Hide file tree
Showing 23 changed files with 1,440 additions and 990 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ public void testGetSourceDirRelativeName() throws Exception {
IFile file = null;
try {
file = project.getFile( "A.hs" );
ResourceUtil.getSourceDirRelativeName( file, hp );
ResourceUtil.getSourceDirRelativeName( file );
fail();
} catch( final IllegalArgumentException illarex ) {
// expected

}
file = project.getFile( "src/A.hs" );
assertEquals( "A.hs", ResourceUtil.getSourceDirRelativeName( file, hp ) );
assertEquals( "A.hs", ResourceUtil.getSourceDirRelativeName( file).toPortableString() );

file = project.getFile( "src/Bla/A.hs" );
assertEquals( "Bla/A.hs",
ResourceUtil.getSourceDirRelativeName( file, hp ) );
ResourceUtil.getSourceDirRelativeName( file ).toPortableString() );

file = project.getFile( "src/Some/Long/Path/A.hs" );
assertEquals( "Some/Long/Path/A.hs",
ResourceUtil.getSourceDirRelativeName( file, hp ) );
ResourceUtil.getSourceDirRelativeName( file ).toPortableString() );

try {
file = project.getFile( "test/Some/Path/A.hs" );
ResourceUtil.getSourceDirRelativeName( file, hp );
ResourceUtil.getSourceDirRelativeName( file );
fail();
} catch( final IllegalArgumentException illarex ) {
// expected
Expand All @@ -50,6 +50,6 @@ public void testGetSourceDirRelativeName() throws Exception {
hp.addSourcePath( "test" );
file = project.getFile( "test/Path/A.hs" );
assertEquals( "Path/A.hs",
ResourceUtil.getSourceDirRelativeName( file, hp ) );
ResourceUtil.getSourceDirRelativeName( file ).toPortableString() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -214,7 +213,7 @@ public static boolean isSourceFolder( final IFolder folder ) {
}

} catch( CoreException ex ) {
HaskellCorePlugin.log( "isSourceFolder:", ex );
HaskellCorePlugin.log( "isSourceFolder:", ex ); //$NON-NLS-1$
}
return false;
}
Expand Down Expand Up @@ -345,8 +344,8 @@ public static IPath getSourceRelativePath( final IContainer sourceContainer,
IPath sourcePath = sourceContainer.getProjectRelativePath();
IPath resourcePath = resourceContainer.getProjectRelativePath();
if( sourcePath.isPrefixOf( resourcePath ) ) {
int count = sourcePath.segmentCount();
result = resourcePath.removeFirstSegments( count );
int count = sourcePath.segmentCount();
result = resourcePath.removeFirstSegments( count );
}
return result;
}
Expand All @@ -364,25 +363,25 @@ private static IContainer getContainer( final IResource resource ) {
* @param file a workspace file, must not be <code>null</code>
* @param hp a haskell project, must not be <code>null</code>
*/
public static String getSourceDirRelativeName( final IFile file,
final IHaskellProject hp ) {
if( file == null || hp == null ) {
public static IPath getSourceDirRelativeName( final IResource file ) {
if( file == null ) {
throw new IllegalArgumentException();
}
IPath projectRelPath = file.getProjectRelativePath();
String result = null;
Iterator<IPath> it = hp.getSourcePaths().iterator();
while( result == null && it.hasNext() ) {
IPath sourcePath = it.next();
if( sourcePath.isPrefixOf( projectRelPath ) ) {
int num = projectRelPath.matchingFirstSegments( sourcePath );
result = projectRelPath.removeFirstSegments( num ).toOSString();
}
}
IContainer sourceContainer = getSourceContainer( file );
IPath result = null;
if( sourceContainer != null ) {
IPath sourcePath = sourceContainer.getProjectRelativePath();
if( sourcePath.isPrefixOf( projectRelPath ) ) {
int count = sourcePath.segmentCount();
result = projectRelPath.removeFirstSegments( count );
}
}

if( result == null ) {
String msg = file.getFullPath()
+ " is in no source folder in project " //$NON-NLS-1$
+ hp.getResource().getName();
+ file.getProject().getName();
throw new IllegalArgumentException( msg );
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
package net.sf.eclipsefp.haskell.debug.core.internal;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;

/** <p>The main plugin class for the Haskell Debug Core.</p>
Expand Down Expand Up @@ -38,4 +40,10 @@ public void stop( final BundleContext context ) throws Exception {
plugin = null;
super.stop( context );
}

public static void log( final String message, final Throwable thr ) {
String id = getPluginId();
Status status = new Status( IStatus.ERROR, id, IStatus.OK, message, thr );
getDefault().getLog().log( status );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package net.sf.eclipsefp.haskell.debug.core.internal.launch;

import net.sf.eclipsefp.haskell.core.util.ResourceUtil;
import net.sf.eclipsefp.haskell.debug.core.internal.HaskellDebugCore;
import net.sf.eclipsefp.haskell.debug.core.internal.util.CoreTexts;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.model.IProcess;

/**
*
* @author JP Moresmau
*
*/
public class CommandOnChangeListener implements IResourceChangeListener {
private final IProcess p;
private final String[] commands;
private final String projectName;

public CommandOnChangeListener( final IProcess p, final String projectName, final String... command ) {
super();
this.p = p;
this.commands = command;
this.projectName=projectName;
}

public void resourceChanged( final IResourceChangeEvent event ) {
try {
event.getDelta().accept( new IResourceDeltaVisitor() {

public boolean visit( final IResourceDelta delta )
throws CoreException {
if (delta.getResource().getProject()==null || delta.getResource().getProject().getName().equals(projectName)){
if( delta.getKind() == IResourceDelta.REMOVED || (delta.getKind() == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.CONTENT)>0)) {
if( delta.getResource() instanceof IFile
&& ResourceUtil.hasHaskellExtension( delta.getResource() ) ) {
runCommand();
return false;
}
}
return true;
}
return false;

}

});
} catch( CoreException ex ) {
HaskellDebugCore.log(CoreTexts.commandonchange_failed, ex );
}
}

protected void runCommand() throws CoreException {
for (String s:commands){
HaskellLaunchDelegate.commandToProcess( p, s );
}
}
}
Loading

0 comments on commit 8eb569f

Please sign in to comment.