Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

line endings, or something

  • Loading branch information...
commit 58544f73b6829c1f0168a5853087a5613d509345 1 parent 22d6fb3
@JPMoresmau authored
View
142 net.sf.eclipsefp.haskell.util/src/net/sf/eclipsefp/haskell/util/BinaryStreamRedirect.java
@@ -1,71 +1,71 @@
-/**
- * Copyright (c) 2012 by JP Moresmau
- * 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.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * @author JP Moresmau
- *
- */
-public class BinaryStreamRedirect extends Thread {
-
- private static final int BUFFER_SIZE = 2048;
-
- private final InputStream fInput;
-
- private OutputStream output;
-
- public BinaryStreamRedirect( final String name, final InputStream in,
- final OutputStream out ) {
- super( name );
- fInput = in;
- output = out;
- setPriority( Thread.MAX_PRIORITY - 1 );
- }
-
- public BinaryStreamRedirect( final InputStream in, final OutputStream out ) {
- this( "Stream redirect thread", in, out ); //$NON-NLS-1$
- }
-
- // interface methods of java.lang.Thread
- // //////////////////////////////////////
-
- @Override
- public void run() {
- byte[] cbuf = new byte[ BUFFER_SIZE ];
- int count;
- try {
- while( ( count = fInput.read( cbuf, 0, BUFFER_SIZE ) ) >= 0 ) {
- output.write( cbuf, 0, count );
- output.flush(); // flush straight away
- }
-
- output.close();
- } catch( IOException ex ) {
- // reading error, abort multiplexing
- }
- }
-
- public OutputStream getOutput() {
- return output;
- }
-
- public void setOutput(OutputStream output) {
- if (this.output!=null){
- try {
- this.output.flush();
- this.output.close();
- } catch( IOException ignore ) {
- // noop
- }
- }
- this.output = output;
- }
-
-}
+/**
+ * Copyright (c) 2012 by JP Moresmau
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * @author JP Moresmau
+ *
+ */
+public class BinaryStreamRedirect extends Thread {
+
+ private static final int BUFFER_SIZE = 2048;
+
+ private final InputStream fInput;
+
+ private OutputStream output;
+
+ public BinaryStreamRedirect( final String name, final InputStream in,
+ final OutputStream out ) {
+ super( name );
+ fInput = in;
+ output = out;
+ setPriority( Thread.MAX_PRIORITY - 1 );
+ }
+
+ public BinaryStreamRedirect( final InputStream in, final OutputStream out ) {
+ this( "Stream redirect thread", in, out ); //$NON-NLS-1$
+ }
+
+ // interface methods of java.lang.Thread
+ // //////////////////////////////////////
+
+ @Override
+ public void run() {
+ byte[] cbuf = new byte[ BUFFER_SIZE ];
+ int count;
+ try {
+ while( ( count = fInput.read( cbuf, 0, BUFFER_SIZE ) ) >= 0 ) {
+ output.write( cbuf, 0, count );
+ output.flush(); // flush straight away
+ }
+
+ output.close();
+ } catch( IOException ex ) {
+ // reading error, abort multiplexing
+ }
+ }
+
+ public OutputStream getOutput() {
+ return output;
+ }
+
+ public void setOutput(OutputStream output) {
+ if (this.output!=null){
+ try {
+ this.output.flush();
+ this.output.close();
+ } catch( IOException ignore ) {
+ // noop
+ }
+ }
+ this.output = output;
+ }
+
+}
View
670 net.sf.eclipsefp.haskell.util/src/net/sf/eclipsefp/haskell/util/FileUtil.java
@@ -1,335 +1,335 @@
-package net.sf.eclipsefp.haskell.util;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Locale;
-import java.util.Set;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * Cross-platform file utilities and container for commonly used file and folder
- * names.
- *
- * @author Thomas ten Cate (original)
- * @author Scott Michel (bscottm@ieee.org, modifications)
- */
-public class FileUtil {
- /** Normal Haskell source extension. */
- public static final String EXTENSION_HS = "hs"; //$NON-NLS-1$
- /** Literate Haskell (embedded TeX) source extension. */
- public static final String EXTENSION_LHS = "lhs"; //$NON-NLS-1$
- /** Haskell for C bindings source extension. */
- public static final String EXTENSION_HSC = "hsc"; //$NON-NLS-1$
- /**
- * "Common Architecture for Building Applications and Libraries" (cabal)
- * project file source extension.
- */
- public static final String EXTENSION_CABAL = "cabal"; //$NON-NLS-1$
-
- /** Default project source directory */
- public static final String DEFAULT_FOLDER_SRC = "src";
- /** Default project documentation directory */
- public static final String DEFAULT_FOLDER_DOC = "doc";
-
- /** Haskell for Alex lexers. */
- public static final String EXTENSION_ALEX = "x"; //$NON-NLS-1$
- /** Haskell for Happy parsers. */
- public static final String EXTENSION_HAPPY = "y"; //$NON-NLS-1$
- /** Haskell for UU Attribute Grammars. */
- public static final String EXTENSION_UUAGC = "ag"; //$NON-NLS-1$
-
- /** Candidate locations to search for files on a path */
- static final ArrayList<File> candidateLocations = new ArrayList<File>(32);
-
-
- public static Set<String> haskellExtensions=new HashSet<String>();
-
- static {
- // Initialize the candidate file locations list, since this doesn't
- // change during runtime.
- // add all directories from the PATH environment variable
- String path = System.getenv("PATH"); //$NON-NLS-1$
- for (String dir : path.split(File.pathSeparator)) {
- File f=new File(dir);
- candidateLocations.add(f);
- // the haskell platform doesn't always put these extra dirs in the path
- if (f.getParentFile()!=null && dir.contains("Haskell Platform")){
- candidateLocations.add(new File(f.getParentFile(),"lib/extralibs/bin"));
- candidateLocations.add(new File(f.getParentFile(),"mingw/bin"));
- }
- }
-
- // add common bin directories from the user's home directory
- ArrayList<String> homes = new ArrayList<String>();
- final String envHome = System.getenv("HOME"); //$NON-NLS-1$
-
- homes.add(envHome);
-
- final String userHome = System.getProperty("user.home"); //$NON-NLS-1$
- if (!userHome.equals(envHome))
- homes.add(userHome);
-
- String[] userBins = new String[] { ".cabal/bin", //$NON-NLS-1$
- "usr/bin", //$NON-NLS-1$
- "bin", //$NON-NLS-1$
- "AppData/Roaming/cabal/bin", // Windows 7 //$NON-NLS-1$
- "Application Data/cabal/bin" // Windows XP
- };
-
- for (String home : homes) {
- for (String userBin : userBins) {
- candidateLocations.add(new File(home, userBin));
- }
- }
-
- haskellExtensions.add(EXTENSION_HS);
- haskellExtensions.add(EXTENSION_LHS);
- haskellExtensions.add(EXTENSION_HSC);
- }
-
- private FileUtil() {
- // do not instantiate
- }
-
- /**
- * Makes the given base name into a valid executable file name. On Unix, this
- * returns the base name itself. On Windows, it appends ".exe".
- */
- public static String makeExecutableName(final String baseName) {
- if (PlatformUtil.runningOnWindows() && !baseName.endsWith("." + PlatformUtil.WINDOWS_EXTENSION_EXE)) { //$NON-NLS-1$
- return baseName + "." + PlatformUtil.WINDOWS_EXTENSION_EXE; //$NON-NLS-1$
- }
- return baseName;
- }
-
- /** Makes the given Path into a valid executable name, which is effectively a NOP on Unix, but ensures
- * that ".exe" is appended on Windows.
- */
- public static IPath makeExecutableName(final IPath exePath) {
- if (PlatformUtil.runningOnWindows()) {
- String ext = exePath.getFileExtension();
- if (ext == null || !ext.equals(PlatformUtil.WINDOWS_EXTENSION_EXE)) {
- return exePath.addFileExtension(PlatformUtil.WINDOWS_EXTENSION_EXE);
- }
- }
-
- return exePath;
- }
-
- /**
- * Returns true if the given file is executable. On Unix, this checks the file
- * permission bits. On Windows, it checks whether the file extension is that
- * of an executable file.
- */
- public static boolean isExecutable(final File file) {
- if (PlatformUtil.runningOnWindows()) {
- return isExecutableWindows(file);
- }
-
- // Assume a UNIX flavor.
- return isExecutableUnix(file);
- }
-
- private static boolean isExecutableUnix(final File file) {
- // Until Java 7, there is no way to check the executable bit of a file.
- // Apart from writing a JNI function (hassle), this is the best we can
- // do...
- try {
- Process process = Runtime.getRuntime().exec(new String[] { "test", "-x", file.getAbsolutePath() }); //$NON-NLS-1$ //$NON-NLS-2$
- int exitValue = process.waitFor();
- if (exitValue != 0) {
- return false;
- }
- } catch (IOException ex) {
- // pretend it succeeded
- } catch (InterruptedException ex) {
- // pretend it succeeded
- }
- return true;
- }
-
- private static boolean isExecutableWindows(final File file) {
- String fileExt = new Path(file.getPath()).getFileExtension();
- for (String ext : PlatformUtil.WINDOWS_EXECUTABLE_EXTENSIONS) {
- if (fileExt.equals(ext)) {
- return true;
- }
- }
- return false;
- }
-
- public static File findExecutableInPath(final String shortFileName) {
- return findInPath(makeExecutableName(shortFileName), new FileFilter() {
-
- public boolean accept(final File pathname) {
- return FileUtil.isExecutable(pathname);
- }
- });
- }
-
- public static File findInPath(final String shortFileName, final FileFilter ff) {
- // Shallow copy is sufficient in this case
- ArrayList<File> candidates = new ArrayList<File>(candidateLocations);
-
- // Add the current working directory, since it might change.
- String pwd = System.getProperty("user.dir"); //$NON-NLS-1$
- candidates.add(new File(pwd));
-
- for (File candidate : candidates) {
- File file = new File(candidate, shortFileName);
- if (file.exists() && (ff == null || ff.accept(file))) {
- return file;
- }
- }
- return null;
- }
-
-
- /**
- * Delete all contents including directories
- */
- static public boolean deleteRecursively(final File file) {
- if (file == null || !file.exists()) {
- return true;
- }
-
- // If file is a file, delete it
- if (file.isFile()) {
- boolean del = file.delete();
- return del;
- }
- // The file is a directory
- File[] files = file.listFiles();
- for (File f : files) {
- deleteRecursively(f);
- }
- boolean del = file.delete();
- return del;
- }
-
- /**
- * <p>
- * returns whether the passed resource is a literate Haskell source file, as
- * recognized by the file extension '.lhs'.
- * </p>
- */
- public static boolean hasLiterateExtension(final IResource resource) {
- return has(resource, EXTENSION_LHS);
- }
-
- /**
- * Predicate that determines whether the resource is a Cabal project file.
- *
- * @param resource
- * The resource
- * @return true if the resource is a Cabal project file.
- */
- public static boolean hasCabalExtension(final IResource resource) {
- return has(resource, EXTENSION_CABAL);
- }
-
- /**
- * <p>
- * returns whether the passed resource is a Haskell source file, as recognized
- * by the file extensions '.hs' and '.lhs'.
- * </p>
- */
- public static boolean hasHaskellExtension(final IResource resource) {
- return has(resource, EXTENSION_HS) || has(resource, EXTENSION_LHS) || has(resource, EXTENSION_HSC);
- }
-
- public static boolean hasAnySourceExtension(final IResource resource) {
- return hasHaskellExtension(resource) || hasCabalExtension(resource)
- || has(resource,EXTENSION_ALEX)
- || has(resource,EXTENSION_HAPPY)
- || has(resource,EXTENSION_UUAGC);
- }
-
-
- private static boolean has(final IResource resource, final String extension) {
- if (resource != null) {
- String resExt = resource.getFileExtension();
- return resExt != null && resExt.equalsIgnoreCase(extension);
- }
-
- return false;
- }
-
- /** Return the list of candidate locations in which we search for various executables
- */
- public static final ArrayList<File> getCandidateLocations() {
- return candidateLocations;
- }
-
- public static String getContents(IFile f) throws Exception{
- StringBuilder sb=new StringBuilder();
- if (f.exists()){
- ByteArrayOutputStream baos=new ByteArrayOutputStream();
- InputStream is=f.getContents(true);
- byte[] buf=new byte[4096];
- int r=is.read(buf);
- while (r>-1){
- baos.write(buf,0,r);
- r=is.read(buf);
- }
- is.close();
- sb.append(new String(baos.toByteArray(),f.getCharset()));
- }
- return sb.toString();
- }
-
- public static String getContents(File f,String charSet) throws IOException{
- StringBuilder sb=new StringBuilder();
- if (f.exists()){
- ByteArrayOutputStream baos=new ByteArrayOutputStream();
- InputStream is=new BufferedInputStream(new FileInputStream(f));
- byte[] buf=new byte[4096];
- int r=is.read(buf);
- while (r>-1){
- baos.write(buf,0,r);
- r=is.read(buf);
- }
- is.close();
- sb.append(new String(baos.toByteArray(),charSet));
- }
- return sb.toString();
- }
-
-
- public static void writeSharedFile(File tgt,String contents,int tries) throws IOException{
- try {
- Writer w=new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(tgt)),"UTF8");
- w.write(contents);
- w.close();
- } catch (FileNotFoundException e){
- if (tries>1 && e.getMessage().toLowerCase(Locale.ENGLISH).contains("another process")){
- try {
- Thread.sleep(200);
- } catch (InterruptedException ie){
- // NOOP
- }
- writeSharedFile(tgt,contents,tries-1);
- return;
- }
- throw e;
- } catch (IOException e){
- throw e;
- }
- }
-}
+package net.sf.eclipsefp.haskell.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * Cross-platform file utilities and container for commonly used file and folder
+ * names.
+ *
+ * @author Thomas ten Cate (original)
+ * @author Scott Michel (bscottm@ieee.org, modifications)
+ */
+public class FileUtil {
+ /** Normal Haskell source extension. */
+ public static final String EXTENSION_HS = "hs"; //$NON-NLS-1$
+ /** Literate Haskell (embedded TeX) source extension. */
+ public static final String EXTENSION_LHS = "lhs"; //$NON-NLS-1$
+ /** Haskell for C bindings source extension. */
+ public static final String EXTENSION_HSC = "hsc"; //$NON-NLS-1$
+ /**
+ * "Common Architecture for Building Applications and Libraries" (cabal)
+ * project file source extension.
+ */
+ public static final String EXTENSION_CABAL = "cabal"; //$NON-NLS-1$
+
+ /** Default project source directory */
+ public static final String DEFAULT_FOLDER_SRC = "src";
+ /** Default project documentation directory */
+ public static final String DEFAULT_FOLDER_DOC = "doc";
+
+ /** Haskell for Alex lexers. */
+ public static final String EXTENSION_ALEX = "x"; //$NON-NLS-1$
+ /** Haskell for Happy parsers. */
+ public static final String EXTENSION_HAPPY = "y"; //$NON-NLS-1$
+ /** Haskell for UU Attribute Grammars. */
+ public static final String EXTENSION_UUAGC = "ag"; //$NON-NLS-1$
+
+ /** Candidate locations to search for files on a path */
+ static final ArrayList<File> candidateLocations = new ArrayList<File>(32);
+
+
+ public static Set<String> haskellExtensions=new HashSet<String>();
+
+ static {
+ // Initialize the candidate file locations list, since this doesn't
+ // change during runtime.
+ // add all directories from the PATH environment variable
+ String path = System.getenv("PATH"); //$NON-NLS-1$
+ for (String dir : path.split(File.pathSeparator)) {
+ File f=new File(dir);
+ candidateLocations.add(f);
+ // the haskell platform doesn't always put these extra dirs in the path
+ if (f.getParentFile()!=null && dir.contains("Haskell Platform")){
+ candidateLocations.add(new File(f.getParentFile(),"lib/extralibs/bin"));
+ candidateLocations.add(new File(f.getParentFile(),"mingw/bin"));
+ }
+ }
+
+ // add common bin directories from the user's home directory
+ ArrayList<String> homes = new ArrayList<String>();
+ final String envHome = System.getenv("HOME"); //$NON-NLS-1$
+
+ homes.add(envHome);
+
+ final String userHome = System.getProperty("user.home"); //$NON-NLS-1$
+ if (!userHome.equals(envHome))
+ homes.add(userHome);
+
+ String[] userBins = new String[] { ".cabal/bin", //$NON-NLS-1$
+ "usr/bin", //$NON-NLS-1$
+ "bin", //$NON-NLS-1$
+ "AppData/Roaming/cabal/bin", // Windows 7 //$NON-NLS-1$
+ "Application Data/cabal/bin" // Windows XP
+ };
+
+ for (String home : homes) {
+ for (String userBin : userBins) {
+ candidateLocations.add(new File(home, userBin));
+ }
+ }
+
+ haskellExtensions.add(EXTENSION_HS);
+ haskellExtensions.add(EXTENSION_LHS);
+ haskellExtensions.add(EXTENSION_HSC);
+ }
+
+ private FileUtil() {
+ // do not instantiate
+ }
+
+ /**
+ * Makes the given base name into a valid executable file name. On Unix, this
+ * returns the base name itself. On Windows, it appends ".exe".
+ */
+ public static String makeExecutableName(final String baseName) {
+ if (PlatformUtil.runningOnWindows() && !baseName.endsWith("." + PlatformUtil.WINDOWS_EXTENSION_EXE)) { //$NON-NLS-1$
+ return baseName + "." + PlatformUtil.WINDOWS_EXTENSION_EXE; //$NON-NLS-1$
+ }
+ return baseName;
+ }
+
+ /** Makes the given Path into a valid executable name, which is effectively a NOP on Unix, but ensures
+ * that ".exe" is appended on Windows.
+ */
+ public static IPath makeExecutableName(final IPath exePath) {
+ if (PlatformUtil.runningOnWindows()) {
+ String ext = exePath.getFileExtension();
+ if (ext == null || !ext.equals(PlatformUtil.WINDOWS_EXTENSION_EXE)) {
+ return exePath.addFileExtension(PlatformUtil.WINDOWS_EXTENSION_EXE);
+ }
+ }
+
+ return exePath;
+ }
+
+ /**
+ * Returns true if the given file is executable. On Unix, this checks the file
+ * permission bits. On Windows, it checks whether the file extension is that
+ * of an executable file.
+ */
+ public static boolean isExecutable(final File file) {
+ if (PlatformUtil.runningOnWindows()) {
+ return isExecutableWindows(file);
+ }
+
+ // Assume a UNIX flavor.
+ return isExecutableUnix(file);
+ }
+
+ private static boolean isExecutableUnix(final File file) {
+ // Until Java 7, there is no way to check the executable bit of a file.
+ // Apart from writing a JNI function (hassle), this is the best we can
+ // do...
+ try {
+ Process process = Runtime.getRuntime().exec(new String[] { "test", "-x", file.getAbsolutePath() }); //$NON-NLS-1$ //$NON-NLS-2$
+ int exitValue = process.waitFor();
+ if (exitValue != 0) {
+ return false;
+ }
+ } catch (IOException ex) {
+ // pretend it succeeded
+ } catch (InterruptedException ex) {
+ // pretend it succeeded
+ }
+ return true;
+ }
+
+ private static boolean isExecutableWindows(final File file) {
+ String fileExt = new Path(file.getPath()).getFileExtension();
+ for (String ext : PlatformUtil.WINDOWS_EXECUTABLE_EXTENSIONS) {
+ if (fileExt.equals(ext)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static File findExecutableInPath(final String shortFileName) {
+ return findInPath(makeExecutableName(shortFileName), new FileFilter() {
+
+ public boolean accept(final File pathname) {
+ return FileUtil.isExecutable(pathname);
+ }
+ });
+ }
+
+ public static File findInPath(final String shortFileName, final FileFilter ff) {
+ // Shallow copy is sufficient in this case
+ ArrayList<File> candidates = new ArrayList<File>(candidateLocations);
+
+ // Add the current working directory, since it might change.
+ String pwd = System.getProperty("user.dir"); //$NON-NLS-1$
+ candidates.add(new File(pwd));
+
+ for (File candidate : candidates) {
+ File file = new File(candidate, shortFileName);
+ if (file.exists() && (ff == null || ff.accept(file))) {
+ return file;
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * Delete all contents including directories
+ */
+ static public boolean deleteRecursively(final File file) {
+ if (file == null || !file.exists()) {
+ return true;
+ }
+
+ // If file is a file, delete it
+ if (file.isFile()) {
+ boolean del = file.delete();
+ return del;
+ }
+ // The file is a directory
+ File[] files = file.listFiles();
+ for (File f : files) {
+ deleteRecursively(f);
+ }
+ boolean del = file.delete();
+ return del;
+ }
+
+ /**
+ * <p>
+ * returns whether the passed resource is a literate Haskell source file, as
+ * recognized by the file extension '.lhs'.
+ * </p>
+ */
+ public static boolean hasLiterateExtension(final IResource resource) {
+ return has(resource, EXTENSION_LHS);
+ }
+
+ /**
+ * Predicate that determines whether the resource is a Cabal project file.
+ *
+ * @param resource
+ * The resource
+ * @return true if the resource is a Cabal project file.
+ */
+ public static boolean hasCabalExtension(final IResource resource) {
+ return has(resource, EXTENSION_CABAL);
+ }
+
+ /**
+ * <p>
+ * returns whether the passed resource is a Haskell source file, as recognized
+ * by the file extensions '.hs' and '.lhs'.
+ * </p>
+ */
+ public static boolean hasHaskellExtension(final IResource resource) {
+ return has(resource, EXTENSION_HS) || has(resource, EXTENSION_LHS) || has(resource, EXTENSION_HSC);
+ }
+
+ public static boolean hasAnySourceExtension(final IResource resource) {
+ return hasHaskellExtension(resource) || hasCabalExtension(resource)
+ || has(resource,EXTENSION_ALEX)
+ || has(resource,EXTENSION_HAPPY)
+ || has(resource,EXTENSION_UUAGC);
+ }
+
+
+ private static boolean has(final IResource resource, final String extension) {
+ if (resource != null) {
+ String resExt = resource.getFileExtension();
+ return resExt != null && resExt.equalsIgnoreCase(extension);
+ }
+
+ return false;
+ }
+
+ /** Return the list of candidate locations in which we search for various executables
+ */
+ public static final ArrayList<File> getCandidateLocations() {
+ return candidateLocations;
+ }
+
+ public static String getContents(IFile f) throws Exception{
+ StringBuilder sb=new StringBuilder();
+ if (f.exists()){
+ ByteArrayOutputStream baos=new ByteArrayOutputStream();
+ InputStream is=f.getContents(true);
+ byte[] buf=new byte[4096];
+ int r=is.read(buf);
+ while (r>-1){
+ baos.write(buf,0,r);
+ r=is.read(buf);
+ }
+ is.close();
+ sb.append(new String(baos.toByteArray(),f.getCharset()));
+ }
+ return sb.toString();
+ }
+
+ public static String getContents(File f,String charSet) throws IOException{
+ StringBuilder sb=new StringBuilder();
+ if (f.exists()){
+ ByteArrayOutputStream baos=new ByteArrayOutputStream();
+ InputStream is=new BufferedInputStream(new FileInputStream(f));
+ byte[] buf=new byte[4096];
+ int r=is.read(buf);
+ while (r>-1){
+ baos.write(buf,0,r);
+ r=is.read(buf);
+ }
+ is.close();
+ sb.append(new String(baos.toByteArray(),charSet));
+ }
+ return sb.toString();
+ }
+
+
+ public static void writeSharedFile(File tgt,String contents,int tries) throws IOException{
+ try {
+ Writer w=new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(tgt)),"UTF8");
+ w.write(contents);
+ w.close();
+ } catch (FileNotFoundException e){
+ if (tries>1 && e.getMessage().toLowerCase(Locale.ENGLISH).contains("another process")){
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException ie){
+ // NOOP
+ }
+ writeSharedFile(tgt,contents,tries-1);
+ return;
+ }
+ throw e;
+ } catch (IOException e){
+ throw e;
+ }
+ }
+}
View
88 net.sf.eclipsefp.haskell.util/src/net/sf/eclipsefp/haskell/util/LangUtil.java
@@ -1,44 +1,44 @@
-/**
- * Copyright (c) 2012 by JP Moresmau
- * 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.util;
-
-import java.util.Collection;
-
-/**
- * Small utility methods, usually to do with Strings or Collections
- * @author JP Moresmau
- *
- */
-public class LangUtil {
-
- public static <T> String join (Collection<T> cols,String sep){
- if (cols==null || cols.size()==0){
- return "";
- }
- String s="";
- StringBuilder ret=new StringBuilder();
- for (T o:cols){
- ret.append(s);
- s=sep;
- ret.append(String.valueOf(o));
- }
- return ret.toString();
- }
-
- /**
- * remove double quotes around a string
- * @param s
- * @return
- */
- public static String unquote(String s){
- if (s!=null && s.length()>1){
- if (s.charAt(0)=='\"' && s.charAt(s.length()-1)=='\"'){
- s=s.substring(1,s.length()-1);
- }
- }
- return s;
- }
-}
+/**
+ * Copyright (c) 2012 by JP Moresmau
+ * 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.util;
+
+import java.util.Collection;
+
+/**
+ * Small utility methods, usually to do with Strings or Collections
+ * @author JP Moresmau
+ *
+ */
+public class LangUtil {
+
+ public static <T> String join (Collection<T> cols,String sep){
+ if (cols==null || cols.size()==0){
+ return "";
+ }
+ String s="";
+ StringBuilder ret=new StringBuilder();
+ for (T o:cols){
+ ret.append(s);
+ s=sep;
+ ret.append(String.valueOf(o));
+ }
+ return ret.toString();
+ }
+
+ /**
+ * remove double quotes around a string
+ * @param s
+ * @return
+ */
+ public static String unquote(String s){
+ if (s!=null && s.length()>1){
+ if (s.charAt(0)=='\"' && s.charAt(s.length()-1)=='\"'){
+ s=s.substring(1,s.length()-1);
+ }
+ }
+ return s;
+ }
+}
View
48 tests/Autocomplete.csv
@@ -1,24 +1,24 @@
-1;Autocomplete same module;In Main.hs, create new function
-;;In main function, check autocomplete gives new function before even saving
-;;Save
-;;Check autocomplete still gives new function
-2;Autocomplete another module name;Create a new module M1 with a function f1
-;;Save
-;;Back to Main.hs
-;;Import <ctrl-space> should offer the new module
-;;Add import
-3;Autocomplete another module name from unreferenced package;Import <ctrl-space> should offer the System.Random
-;;Add import
-;;Dependency to random added in cabal file
-4;Autocomplete another module function;In Main.hs, f1 should be part of autocomplete
-5;Autocomplete another module function not imported;Remove import of M1
-;;Save
-;;In Main.hs, f1 should be part of autocomplete (not imported context)
-;;Adding f1 should add import to M1
-6;Autcomplete another function package referenced module not referenced;Search autocomplete for catMaybes in not referenced
-;;Adding catMaybes should import Data.Maybe
-7;Autocomplete for unreferenced package;Search autocomplete for getStdRandom in all packages
-;;Adding getStdRandom should add import to System.Random
-;;Dependency to random added in cabal file
-8;Autocomplete constructor;Search autocomplete for Node
-;;Check Data.Tree (Tree(..)) added in imports
+1;Autocomplete same module;In Main.hs, create new function
+;;In main function, check autocomplete gives new function before even saving
+;;Save
+;;Check autocomplete still gives new function
+2;Autocomplete another module name;Create a new module M1 with a function f1
+;;Save
+;;Back to Main.hs
+;;Import <ctrl-space> should offer the new module
+;;Add import
+3;Autocomplete another module name from unreferenced package;Import <ctrl-space> should offer the System.Random
+;;Add import
+;;Dependency to random added in cabal file
+4;Autocomplete another module function;In Main.hs, f1 should be part of autocomplete
+5;Autocomplete another module function not imported;Remove import of M1
+;;Save
+;;In Main.hs, f1 should be part of autocomplete (not imported context)
+;;Adding f1 should add import to M1
+6;Autcomplete another function package referenced module not referenced;Search autocomplete for catMaybes in not referenced
+;;Adding catMaybes should import Data.Maybe
+7;Autocomplete for unreferenced package;Search autocomplete for getStdRandom in all packages
+;;Adding getStdRandom should add import to System.Random
+;;Dependency to random added in cabal file
+8;Autocomplete constructor;Search autocomplete for Node
+;;Check Data.Tree (Tree(..)) added in imports
View
70 tests/Basic.csv
@@ -1,35 +1,35 @@
-1;Simple exe project;Create executable haskell project
-;;Open Main.hs
-;;Check syntax highlighting works
-;;Create new function
-;;Check outline works
-;;Fill in code
-;;Save
-;;Expand Cabal -> executable
-;;Right click Run
-;;Check console shows output
-;;Right click on project Run
-;;Check console shows output
-2;GHCi support;Right click Main.hs -> GHCi
-;;Check loads ok
-;;Check function runs
-;;Check :main runs
-;;Modify file and save
-;;Check reloaded
-;;Close GHCi
-3;Library project;Create library project
-;;Check no module created
-;;Create module
-;;Check syntax highlighting works
-;;Check outline works
-;;Check build works
-;;Check GHCi works
-4;Existing project;Put existing cabal project with Setup.hs in workspace folder
-;;Create project
-;;Check cabal file, Main.hs are not overwritten
-;;Check Setup.hs not overwritten
-5;Existing project with Setup.lhs;Put existing cabal project with Setup.lhs in workspace folder
-;;Create project
-;;Check cabal file, Main.hs are not overwritten
-;;Check Setup.lhs not overwritten
-;;Check Setup.hs not created
+1;Simple exe project;Create executable haskell project
+;;Open Main.hs
+;;Check syntax highlighting works
+;;Create new function
+;;Check outline works
+;;Fill in code
+;;Save
+;;Expand Cabal -> executable
+;;Right click Run
+;;Check console shows output
+;;Right click on project Run
+;;Check console shows output
+2;GHCi support;Right click Main.hs -> GHCi
+;;Check loads ok
+;;Check function runs
+;;Check :main runs
+;;Modify file and save
+;;Check reloaded
+;;Close GHCi
+3;Library project;Create library project
+;;Check no module created
+;;Create module
+;;Check syntax highlighting works
+;;Check outline works
+;;Check build works
+;;Check GHCi works
+4;Existing project;Put existing cabal project with Setup.hs in workspace folder
+;;Create project
+;;Check cabal file, Main.hs are not overwritten
+;;Check Setup.hs not overwritten
+5;Existing project with Setup.lhs;Put existing cabal project with Setup.lhs in workspace folder
+;;Create project
+;;Check cabal file, Main.hs are not overwritten
+;;Check Setup.lhs not overwritten
+;;Check Setup.hs not created
View
16 tests/CabalPackages.csv
@@ -1,8 +1,8 @@
-1;Cabal update;Cabal update in cabal package view
-;;Check no errors in console
-2;List of installed packages;Check list is present
-;;Check versions for package
-;;Check info is showing for selected version/package
-3;List of all packages;Check list and info appear
-4;Install package;Install something inocuous like AC-Angle
-;;Check no errors in console
+1;Cabal update;Cabal update in cabal package view
+;;Check no errors in console
+2;List of installed packages;Check list is present
+;;Check versions for package
+;;Check info is showing for selected version/package
+3;List of all packages;Check list and info appear
+4;Install package;Install something inocuous like AC-Angle
+;;Check no errors in console
View
42 tests/GoToDeclaration.csv
@@ -1,21 +1,21 @@
-1;Go to declaration same project;Create a new module M1 with a function f1
-;;Save, Close
-;;Back to Main.hs
-;;Import M1
-;;Use f1 in code
-;;Open definition on f1
-;;Check opens M1 on proper line
-2;Go to declaration local doc;Import System.Random
-;;Use getStdGen
-;;Open definition on getStdRandom
-;;Open local HTML page
-3;Go to declaration hackage;Import haskell-src-exts
-;;Use Language.Haskell.Exts.Annotated (parseFile)
-;;Open definition on parseFile
-;;Open Hackage HTML file
-4;Go to operator declaration;import Database.Persist.Query
-;;import Database.Persist
-;;import Database.Persist.Query.Internal (Update)
-;;let op=(=.) :: EntityField String String -> String -> Update String
-;;Open definition on op
-;;Open HTML file at proper anchor
+1;Go to declaration same project;Create a new module M1 with a function f1
+;;Save, Close
+;;Back to Main.hs
+;;Import M1
+;;Use f1 in code
+;;Open definition on f1
+;;Check opens M1 on proper line
+2;Go to declaration local doc;Import System.Random
+;;Use getStdGen
+;;Open definition on getStdRandom
+;;Open local HTML page
+3;Go to declaration hackage;Import haskell-src-exts
+;;Use Language.Haskell.Exts.Annotated (parseFile)
+;;Open definition on parseFile
+;;Open Hackage HTML file
+4;Go to operator declaration;import Database.Persist.Query
+;;import Database.Persist
+;;import Database.Persist.Query.Internal (Update)
+;;let op=(=.) :: EntityField String String -> String -> Update String
+;;Open definition on op
+;;Open HTML file at proper anchor
View
50 tests/Install.csv
@@ -1,25 +1,25 @@
-1;Clean install;Install current Haskell Platform
-;;Run cabal update
-;;Install current version of Eclipse for Java developers
-;;Start Eclipse, new workspace
-;;Install eclipsefp from updates site
-;;Restart Eclipse
-;;GHC should be detected from path
-;;Cabal should be detected from path
-;;Should prompt for buildwrapper and scion-browser installs
-;;Install both
-;;Create executable project
-;;Open Main.hs
-;;Check syntax highlighting works
-;;Check outline works
-;;Check browser works
-2;Upgrade install;Install previous version
-;;Update eclipsefp from updates site
-;;Restart Eclipse
-;;Should prompt for buildwrapper and scion-browser installs
-;;Install both
-;;Create executable project
-;;Open Main.hs
-;;Check syntax highlighting works
-;;Check outline works
-;;Check browser works
+1;Clean install;Install current Haskell Platform
+;;Run cabal update
+;;Install current version of Eclipse for Java developers
+;;Start Eclipse, new workspace
+;;Install eclipsefp from updates site
+;;Restart Eclipse
+;;GHC should be detected from path
+;;Cabal should be detected from path
+;;Should prompt for buildwrapper and scion-browser installs
+;;Install both
+;;Create executable project
+;;Open Main.hs
+;;Check syntax highlighting works
+;;Check outline works
+;;Check browser works
+2;Upgrade install;Install previous version
+;;Update eclipsefp from updates site
+;;Restart Eclipse
+;;Should prompt for buildwrapper and scion-browser installs
+;;Install both
+;;Create executable project
+;;Open Main.hs
+;;Check syntax highlighting works
+;;Check outline works
+;;Check browser works
View
132 todo.txt
@@ -1,67 +1,67 @@
-- quick fix on missing package
- -> install package
- -> event when installing packages
- -> parse package name
- -> clean and rebuild projects that are broken because of this missing package
-
-- global action to remove all useless imports
-- global action to clean all imports: only import what's needed
-
-- format using haskell-src-exts
- - doesn't support comments
-- format using scan
- - very limited
-- format using stylish-haskell
-
-- show packages in error in Cabal Packages view (error overlay on icon) + errors + enable install button
- - list of packages in error
-
-- achievements!
-
-- "visual programming"
- - define expressions
- - the expressions get revaluated every time the file is changed
- - expressions could be assigned with "viewers"
- -> show images, play sound, etc
-
-- clean up preferences
- - no option for GHC/GHCi: we need to know what options to ignore for GHCi, since these options are going to appear in the Cabal file
- - GHC options on each project as well
-
-- GHC 6.12 -dynamic option (http://mostlycode.wordpress.com/2010/01/26/ghc-6-12-1-dynamic-executables-fun/)
-
-- code manipulation: should be pluggable into scion without recompiling???
- - broken refactorings (point free, etc...)
-
-- files not haskell in source folders could go into data-files automatically
-
-
-
-
-- run Ghci with proper flags done partially
- - ask which cabal component to take
- - what about conditional in cabal (like scion: if ghc impl...)
- - remove inproper options
- - ignore .ghci file option? (http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-dot-files.html -ignore-dot-ghci)
-
-.ghci file parsing/editor?? (http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-dot-files.html http://neilmitchell.blogspot.com/2010/01/using-ghci-files-to-run-projects.html http://neilmitchell.blogspot.com/2010/01/better-ghci-files.html)
-
-- integrate analysis tools like hpc, HaskaBelle
-- integrate runtime tools like criterion
-- integrate HaRe for refactoring?
-
-- debugging
- - column on breakpoint??
- - try to use :hist to display full stack (can we intercept write to add :trace in front?)
- - better system to force evaluation? Done with custom value setter calling :force what about calling seq ... ()?
- - reloading modules when stopped seems to cause breakpoints to disappear in GHCi, to check
-
-- add Haskell nature + related files to existing project
-
-- import management (order import, only import what's needed, add proper import for function?)
-
-- project rename
-- module rename (rename file + module name + imports ) (in cabal already done)
-
-- CAPRI http://www.haskell.org/haskellwiki/Capri to install scion
+- quick fix on missing package
+ -> install package
+ -> event when installing packages
+ -> parse package name
+ -> clean and rebuild projects that are broken because of this missing package
+
+- global action to remove all useless imports
+- global action to clean all imports: only import what's needed
+
+- format using haskell-src-exts
+ - doesn't support comments
+- format using scan
+ - very limited
+- format using stylish-haskell
+
+- show packages in error in Cabal Packages view (error overlay on icon) + errors + enable install button
+ - list of packages in error
+
+- achievements!
+
+- "visual programming"
+ - define expressions
+ - the expressions get revaluated every time the file is changed
+ - expressions could be assigned with "viewers"
+ -> show images, play sound, etc
+
+- clean up preferences
+ - no option for GHC/GHCi: we need to know what options to ignore for GHCi, since these options are going to appear in the Cabal file
+ - GHC options on each project as well
+
+- GHC 6.12 -dynamic option (http://mostlycode.wordpress.com/2010/01/26/ghc-6-12-1-dynamic-executables-fun/)
+
+- code manipulation: should be pluggable into scion without recompiling???
+ - broken refactorings (point free, etc...)
+
+- files not haskell in source folders could go into data-files automatically
+
+
+
+
+- run Ghci with proper flags done partially
+ - ask which cabal component to take
+ - what about conditional in cabal (like scion: if ghc impl...)
+ - remove inproper options
+ - ignore .ghci file option? (http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-dot-files.html -ignore-dot-ghci)
+
+.ghci file parsing/editor?? (http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-dot-files.html http://neilmitchell.blogspot.com/2010/01/using-ghci-files-to-run-projects.html http://neilmitchell.blogspot.com/2010/01/better-ghci-files.html)
+
+- integrate analysis tools like hpc, HaskaBelle
+- integrate runtime tools like criterion
+- integrate HaRe for refactoring?
+
+- debugging
+ - column on breakpoint??
+ - try to use :hist to display full stack (can we intercept write to add :trace in front?)
+ - better system to force evaluation? Done with custom value setter calling :force what about calling seq ... ()?
+ - reloading modules when stopped seems to cause breakpoints to disappear in GHCi, to check
+
+- add Haskell nature + related files to existing project
+
+- import management (order import, only import what's needed, add proper import for function?)
+
+- project rename
+- module rename (rename file + module name + imports ) (in cabal already done)
+
+- CAPRI http://www.haskell.org/haskellwiki/Capri to install scion
- built-in -> install global/local/project
Please sign in to comment.
Something went wrong with that request. Please try again.