-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4ce338
commit 773e416
Showing
4 changed files
with
57 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 54 additions & 53 deletions
107
net.sf.eclipsefp.haskell.hlint/src/net/sf/eclipsefp/haskell/hlint/HLintRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,53 +1,54 @@ | |||
/** | /** | ||
* (c) 2011, Alejandro Serrano | * (c) 2011, Alejandro Serrano | ||
* Released under the terms of the EPL. | * Released under the terms of the EPL. | ||
*/ | */ | ||
package net.sf.eclipsefp.haskell.hlint; | package net.sf.eclipsefp.haskell.hlint; | ||
|
|
||
import java.io.StringReader; | import java.io.StringReader; | ||
import java.io.StringWriter; | import java.io.StringWriter; | ||
import java.util.ArrayList; | import java.util.ArrayList; | ||
import java.util.List; | import java.util.List; | ||
|
|
||
import net.sf.eclipsefp.haskell.hlint.parser.OutputParser; | import net.sf.eclipsefp.haskell.hlint.parser.OutputParser; | ||
import net.sf.eclipsefp.haskell.hlint.util.HLintText; | import net.sf.eclipsefp.haskell.hlint.util.HLintText; | ||
import net.sf.eclipsefp.haskell.util.ProcessRunner; | import net.sf.eclipsefp.haskell.util.ProcessRunner; | ||
|
|
||
import org.eclipse.core.runtime.IPath; | import org.eclipse.core.runtime.IPath; | ||
import org.eclipse.osgi.util.NLS; | import org.eclipse.osgi.util.NLS; | ||
|
|
||
/** | /** | ||
* Class the encapsulates the logic of calling hlint and | * Class the encapsulates the logic of calling hlint and | ||
* sending the output to the parser to generate a list | * sending the output to the parser to generate a list | ||
* of suggestions. | * of suggestions. | ||
* | * | ||
* @author Alejandro Serrano | * @author Alejandro Serrano | ||
* @author JP Moresmau | * @author JP Moresmau | ||
* | * | ||
*/ | */ | ||
public class HLintRunner { | public class HLintRunner { | ||
|
|
||
public List<Suggestion> run(IPath path) { | public List<Suggestion> run(IPath path) { | ||
StringWriter err=new StringWriter(); | StringWriter err=new StringWriter(); | ||
StringWriter out=new StringWriter(); | StringWriter out=new StringWriter(); | ||
try { | try { | ||
String exe=HLintPlugin.getHlintPath(); | String exe=HLintPlugin.getHlintPath(); | ||
if (exe==null || exe.length()==0){ | if (exe==null || exe.length()==0){ | ||
exe="hlint"; // hope it's in the path | exe="hlint"; // hope it's in the path | ||
} | } | ||
new ProcessRunner().executeBlocking(path.toFile().getParentFile(), out, err, exe, path.toOSString()); | int code=new ProcessRunner().executeBlocking(path.toFile().getParentFile(), out, err, exe, path.toOSString()); | ||
|
if (code==0){ | ||
OutputParser parser = new OutputParser(new StringReader(out.toString())); | OutputParser parser = new OutputParser(new StringReader(out.toString())); | ||
return parser.suggestions(); | return parser.suggestions(); | ||
} catch (Throwable ex) { | } | ||
String msg=err.toString().length()>0?err.toString():out.toString(); | } catch (Throwable ex) { | ||
HLintPlugin.logError(NLS.bind(HLintText.error_run,msg), ex); | String msg=err.toString().length()>0?err.toString():out.toString(); | ||
} | HLintPlugin.logError(NLS.bind(HLintText.error_run,msg), ex); | ||
return new ArrayList<Suggestion>(); | } | ||
} | return new ArrayList<Suggestion>(); | ||
|
} | ||
public static List<Suggestion> runHLintOn(IPath path) { |
|
||
HLintRunner runner = new HLintRunner(); | public static List<Suggestion> runHLintOn(IPath path) { | ||
return runner.run(path); | HLintRunner runner = new HLintRunner(); | ||
} | return runner.run(path); | ||
} | } | ||
} |