Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

Commit

Permalink
Normalize line endings
Browse files Browse the repository at this point in the history
In commit 6ac0b2d not all steps were executed
  • Loading branch information
Shredder121 committed Jan 30, 2016
1 parent 4625dec commit e4c976e
Show file tree
Hide file tree
Showing 7 changed files with 574 additions and 574 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

A NetBeans IDE plugin supporting the [EditorConfig][] standard.

- Supports NetBeans 8 and above
- Requires Java 8

- Supports NetBeans 8 and above
- Requires Java 8

[![](https://travis-ci.org/welovecoding/editorconfig-netbeans.svg?branch=master)](https://travis-ci.org/welovecoding/editorconfig-netbeans)

[**DOWNLOAD**](https://github.com/welovecoding/editorconfig-netbeans/releases)
Expand All @@ -14,7 +14,7 @@ A NetBeans IDE plugin supporting the [EditorConfig][] standard.
![Plugin Screenshot](https://dl.dropboxusercontent.com/u/74217418/screenshots/github/editorconfig-plugin/screen-1.png)

- Reads EditorConfig files
- [Syntax highlighting](https://dl.dropboxusercontent.com/u/74217418/screenshots/github/editorconfig-plugin/syntax-highlighting.png)
- [Syntax highlighting](https://dl.dropboxusercontent.com/u/74217418/screenshots/github/editorconfig-plugin/syntax-highlighting.png)
- [Navigation in EditorConfig files](https://dl.dropboxusercontent.com/u/74217418/screenshots/github/editorconfig-plugin/navigator-with-go-to-source.png)

## EditorConfig Project
Expand Down Expand Up @@ -115,4 +115,4 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[**Benny Neugebauer**](http://www.bennyn.de/) | [**Michael Koppen**](http://beanbelt.blogspot.de/) | [**Junichi Yamamoto**](http://junichi11.com/)

### Special Credits
- [Geertjan Wielenga](https://blogs.oracle.com/geertjan) for his posts on [EditorConfig and NetBeans IDE](https://blogs.oracle.com/geertjan/entry/editorconfig_and_netbeans_ide)
- [Geertjan Wielenga](https://blogs.oracle.com/geertjan) for his posts on [EditorConfig and NetBeans IDE](https://blogs.oracle.com/geertjan/entry/editorconfig_and_netbeans_ide)
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package com.welovecoding.nbeditorconfig.io.reader;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import org.netbeans.api.queries.FileEncodingQuery;
import org.openide.filesystems.FileObject;
import org.openide.util.Exceptions;

public class FileObjectReader {

public static synchronized String read(FileObject fo) {
return FileObjectReader.read(fo, FileEncodingQuery.getEncoding(fo));
}

public static synchronized String read(FileObject fo, Charset cs) {
final StringBuilder sb = new StringBuilder();
final char[] buffer = new char[512];

try (Reader in = new InputStreamReader(fo.getInputStream(), cs)) {
int len;
while ((len = in.read(buffer)) > 0) {
sb.append(buffer, 0, len);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}

return sb.toString();
}

}
package com.welovecoding.nbeditorconfig.io.reader;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import org.netbeans.api.queries.FileEncodingQuery;
import org.openide.filesystems.FileObject;
import org.openide.util.Exceptions;

public class FileObjectReader {

public static synchronized String read(FileObject fo) {
return FileObjectReader.read(fo, FileEncodingQuery.getEncoding(fo));
}

public static synchronized String read(FileObject fo, Charset cs) {
final StringBuilder sb = new StringBuilder();
final char[] buffer = new char[512];

try (Reader in = new InputStreamReader(fo.getInputStream(), cs)) {
int len;
while ((len = in.read(buffer)) > 0) {
sb.append(buffer, 0, len);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}

return sb.toString();
}

}
Original file line number Diff line number Diff line change
@@ -1,104 +1,104 @@
package com.welovecoding.nbeditorconfig.io.writer;

import com.welovecoding.nbeditorconfig.io.exception.FileAccessException;
import com.welovecoding.nbeditorconfig.io.exception.FileObjectLockException;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.text.BadLocationException;
import javax.swing.text.StyledDocument;
import org.openide.cookies.EditorCookie;
import org.openide.cookies.OpenCookie;
import org.openide.filesystems.FileAlreadyLockedException;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.openide.text.NbDocument;
import org.openide.util.Exceptions;
import org.openide.util.UserQuestionException;

public class FileObjectWriter {

private static final Logger LOG = Logger.getLogger(FileObjectWriter.class.getName());

public static synchronized void writeWithAtomicAction(final DataObject dataObject, final Charset cs, final String content) {
try {
final FileObject fo = dataObject.getPrimaryFile();
final EditorCookie cookie = dataObject.getLookup().lookup(EditorCookie.class);
NbDocument.runAtomicAsUser(cookie.openDocument(), new Runnable() {
@Override
public void run() {
try (Writer out = new OutputStreamWriter(fo.getOutputStream(), cs)) {
LOG.log(Level.INFO, "\u00ac Writing file");
out.write(content);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
});
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException ex) {
System.out.println("Document cannot be opened.");
Exceptions.printStackTrace(ex);
}
}

public static synchronized void write(FileObject fo, Charset cs, String content) throws FileObjectLockException {
FileLock lock = FileLock.NONE;

try {
LOG.log(Level.INFO, "\u00ac Trying to lock file: \"{0}\"", fo.getPath());
lock = fo.lock();
} catch (FileAlreadyLockedException ex) {
throw new FileObjectLockException("File is already locked: " + ex.getMessage());
} catch (UserQuestionException ex2) {
throw new FileObjectLockException("Lock cannot be obtained now: " + ex2.getMessage());
} catch (IOException ex3) {
throw new FileObjectLockException("File cannot be locked: " + ex3.getMessage());
}

try (Writer out = new OutputStreamWriter(fo.getOutputStream(lock), cs)) {
LOG.log(Level.INFO, "\u00ac Writing file");
out.write(content);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
} finally {
LOG.log(Level.INFO, "\u00ac Released file lock");
lock.releaseLock();
}

}

public static synchronized void closeDocumentInEditor(DataObject dataObject) {
final OpenCookie oc = dataObject.getLookup().lookup(OpenCookie.class);
if (oc != null) {
EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
if (ec != null) {
ec.close();
}
}
}

public static synchronized void openDocumentInEditor(DataObject dataObject) {
final OpenCookie oc = dataObject.getLookup().lookup(OpenCookie.class);
if (oc != null) {
oc.open();
}
}

public static synchronized void reopenDocumentInEditor(DataObject dataObject) {
final OpenCookie oc = dataObject.getLookup().lookup(OpenCookie.class);
if (oc != null) {
EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
if (ec != null) {
ec.close();
}
oc.open();
}
}
}
package com.welovecoding.nbeditorconfig.io.writer;

import com.welovecoding.nbeditorconfig.io.exception.FileAccessException;
import com.welovecoding.nbeditorconfig.io.exception.FileObjectLockException;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.text.BadLocationException;
import javax.swing.text.StyledDocument;
import org.openide.cookies.EditorCookie;
import org.openide.cookies.OpenCookie;
import org.openide.filesystems.FileAlreadyLockedException;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.openide.text.NbDocument;
import org.openide.util.Exceptions;
import org.openide.util.UserQuestionException;

public class FileObjectWriter {

private static final Logger LOG = Logger.getLogger(FileObjectWriter.class.getName());

public static synchronized void writeWithAtomicAction(final DataObject dataObject, final Charset cs, final String content) {
try {
final FileObject fo = dataObject.getPrimaryFile();
final EditorCookie cookie = dataObject.getLookup().lookup(EditorCookie.class);
NbDocument.runAtomicAsUser(cookie.openDocument(), new Runnable() {
@Override
public void run() {
try (Writer out = new OutputStreamWriter(fo.getOutputStream(), cs)) {
LOG.log(Level.INFO, "\u00ac Writing file");
out.write(content);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
});
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException ex) {
System.out.println("Document cannot be opened.");
Exceptions.printStackTrace(ex);
}
}

public static synchronized void write(FileObject fo, Charset cs, String content) throws FileObjectLockException {
FileLock lock = FileLock.NONE;

try {
LOG.log(Level.INFO, "\u00ac Trying to lock file: \"{0}\"", fo.getPath());
lock = fo.lock();
} catch (FileAlreadyLockedException ex) {
throw new FileObjectLockException("File is already locked: " + ex.getMessage());
} catch (UserQuestionException ex2) {
throw new FileObjectLockException("Lock cannot be obtained now: " + ex2.getMessage());
} catch (IOException ex3) {
throw new FileObjectLockException("File cannot be locked: " + ex3.getMessage());
}

try (Writer out = new OutputStreamWriter(fo.getOutputStream(lock), cs)) {
LOG.log(Level.INFO, "\u00ac Writing file");
out.write(content);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
} finally {
LOG.log(Level.INFO, "\u00ac Released file lock");
lock.releaseLock();
}

}

public static synchronized void closeDocumentInEditor(DataObject dataObject) {
final OpenCookie oc = dataObject.getLookup().lookup(OpenCookie.class);
if (oc != null) {
EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
if (ec != null) {
ec.close();
}
}
}

public static synchronized void openDocumentInEditor(DataObject dataObject) {
final OpenCookie oc = dataObject.getLookup().lookup(OpenCookie.class);
if (oc != null) {
oc.open();
}
}

public static synchronized void reopenDocumentInEditor(DataObject dataObject) {
final OpenCookie oc = dataObject.getLookup().lookup(OpenCookie.class);
if (oc != null) {
EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
if (ec != null) {
ec.close();
}
oc.open();
}
}
}
Loading

0 comments on commit e4c976e

Please sign in to comment.