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

Suppport for EditorConfig files with names #61

Merged
merged 3 commits into from
Mar 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public final class Settings {

public static final String MIME_TYPE = "text/x-editorconfig"; // NOI18N
public static final String EXTENSION = "editorconfig"; // NOI18N
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines marked with #NOI18N or other applicable comments on line before a given message/label or group of them denotes what items not to translate for cases where it is not completely obvious that something should not be translated.`

I doubt that we need the NOI18N declaration in a settings file because there is no translation for a MIME type, Extension and / or resource path.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think of an automatic approach of translating text within sourcecode (or at least separating). I don't think theres something wrong with that comment since the guys from the JDK for example do it the same way. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always keep it simple. There is NO automatic text translation right now and it makes NO sense to translate a MIME type. The documentation says you should use NOI18N when it is not completely obvious that something should not be translated and in this case it is obvious. So it's pointless to use NOI18N here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public static final String RESOURCE_PATH = "com/welovecoding/nbeditorconfig"; // NOI18N

@StaticResource
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import org.openide.filesystems.FileRenameEvent;

/**
* http://bits.netbeans.org/dev/javadoc/
* This kind of listener is attached to editorconfig files within a project.
* When this listener is attached to an editorconfig a FileChangeListener will
* be attached to all files in the folder with the editorconfig and subsequent
* ones. http://bits.netbeans.org/dev/javadoc/
*/
public class EditorConfigChangeListener extends FileChangeAdapter {

Expand All @@ -20,40 +23,39 @@ public class EditorConfigChangeListener extends FileChangeAdapter {
private final FileObject editorConfigFileObject;
private final FileChangeListener subsequentFilesListener;

static {
LOG.setLevel(Level.INFO);
}

public EditorConfigChangeListener(Project project, FileObject editorConfigFileObject) {
this.project = project;
this.editorConfigFileObject = editorConfigFileObject;

LOG.log(Level.INFO, "Attached EditorConfigChangeListener to: {0}", editorConfigFileObject.getPath());
this.subsequentFilesListener = new FileChangeListener(project, editorConfigFileObject);
editorConfigFileObject.getParent().addRecursiveListener(subsequentFilesListener);
}

@Override
public void fileAttributeChanged(FileAttributeEvent event) {
super.fileAttributeChanged(event);
LOG.log(Level.INFO, "Attribute changed: {0}", event.getFile().getPath());
}

@Override
public void fileRenamed(FileRenameEvent event) {
super.fileRenamed(event);
LOG.log(Level.INFO, "Renamed file: {0}", event.getFile().getPath());
// immediately apply editorconfig
propagateChanges();
}

@Override
public void fileDeleted(FileEvent event) {
super.fileDeleted(event);
LOG.log(Level.INFO, "Deleted file: {0}", event.getFile().getPath());
//TODO processDeletedEditorConfig
//TODO processDeletedFolderWhichMayContainsFoldersWithListeners -> remove them
event.getFile().getParent().removeRecursiveListener(subsequentFilesListener);
event.getFile().removeFileChangeListener(this);
}

@Override
public void fileChanged(FileEvent event) {
super.fileChanged(event);
LOG.log(Level.INFO, "EditorConfigs content changed: {0}", event.getFile().getPath());

propagateChanges();
}

private void propagateChanges() {
for (FileObject fo : Collections.list(editorConfigFileObject.getParent().getChildren(true))) {
LOG.log(Level.INFO, "Updating subsequent file: {0}", fo.getPath());
subsequentFilesListener.fileChanged(new FileEvent(fo));
Expand All @@ -63,7 +65,7 @@ public void fileChanged(FileEvent event) {
@Override
public void fileFolderCreated(FileEvent event) {
super.fileFolderCreated(event);
LOG.log(Level.INFO, "Created folder: {0}", event.getFile().getPath());
LOG.log(Level.FINE, "Created folder: {0}", event.getFile().getPath());
//TODO search for editor-configs and attach listeners
}

Expand All @@ -76,7 +78,18 @@ public void fileFolderCreated(FileEvent event) {
@Override
public void fileDataCreated(FileEvent event) {
super.fileDataCreated(event);
LOG.log(Level.INFO, "fileDataCreated: {0}", event.getFile().getPath());
LOG.log(Level.FINE, "fileDataCreated: {0}", event.getFile().getPath());
}

@Override
public void fileAttributeChanged(FileAttributeEvent event) {
super.fileAttributeChanged(event);
LOG.log(Level.FINE, "Attribute changed: {0}", event.getFile().getPath());
}

@Override
public void fileRenamed(FileRenameEvent event) {
super.fileRenamed(event);
LOG.log(Level.FINE, "Renamed file: {0}", event.getFile().getPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,31 @@ public class FileChangeListener extends FileChangeAdapter {

private static final Logger LOG = Logger.getLogger(FileChangeListener.class.getSimpleName());
private final Project project;
private final FileObject editorConfigFileObject;

public FileChangeListener(Project project, FileObject editorConfigFileObject) {
this.project = project;
LOG.log(Level.INFO, "Attached FileChangeListener to: {0}", editorConfigFileObject.getParent().getPath());
static {
LOG.setLevel(Level.INFO);
}

@Override
public void fileAttributeChanged(FileAttributeEvent event) {
super.fileAttributeChanged(event);
LOG.log(Level.INFO, "Attribute changed: {0}", event.getFile().getPath());
}

@Override
public void fileRenamed(FileRenameEvent event) {
super.fileRenamed(event);
LOG.log(Level.INFO, "Renamed file: {0}", event.getFile().getPath());
public FileChangeListener(Project project, FileObject editorConfigFileObject) {
this.project = project;
this.editorConfigFileObject = editorConfigFileObject;
LOG.log(Level.INFO, "[EC for {0}] Attached FileChangeListener to: {1}", new Object[]{editorConfigFileObject.getPath(), editorConfigFileObject.getParent().getPath()});
}

@Override
public void fileDeleted(FileEvent event) {
super.fileDeleted(event);
LOG.log(Level.INFO, "Deleted file: {0}", event.getFile().getPath());
//TODO processDeletedEditorConfig
//TODO processDeletedFolderWhichMayContainsFoldersWithListeners -> remove them
LOG.log(Level.INFO, "[EC for {0}] Deleted file: {1}", new Object[]{editorConfigFileObject.getPath(), event.getFile().getPath()});
event.getFile().removeRecursiveListener(this);
}

@Override
public void fileChanged(FileEvent event) {
super.fileChanged(event);
String path = event.getFile().getPath();

LOG.log(Level.INFO, "File content changed: {0}", path);
LOG.log(Level.INFO, "[EC for {0}] File content changed: {1}", new Object[]{editorConfigFileObject.getPath(), path});

if (applyRulesToFile(event)) {
try {
Expand All @@ -63,7 +56,7 @@ public void fileChanged(FileEvent event) {
Exceptions.printStackTrace(ex);
}
} else {
LOG.log(Level.INFO, "Rules will not be applied to: {0}", path);
LOG.log(Level.INFO, "[EC for {0}] Rules will not be applied to: {1}", new Object[]{editorConfigFileObject.getPath(), path});
}
}

Expand All @@ -85,7 +78,7 @@ private boolean applyRulesToFile(FileEvent event) {
@Override
public void fileFolderCreated(FileEvent event) {
super.fileFolderCreated(event);
LOG.log(Level.INFO, "Created folder: {0}", event.getFile().getPath());
LOG.log(Level.FINE, "[EC for {0}] Created folder: {1}", new Object[]{editorConfigFileObject.getPath(), event.getFile().getPath()});
//TODO search for editor-configs and attach listeners
}

Expand All @@ -99,8 +92,19 @@ public void fileFolderCreated(FileEvent event) {
public void fileDataCreated(FileEvent event) {
super.fileDataCreated(event);
FileObject primaryFile = event.getFile();
LOG.log(Level.INFO, "Added new file to project: {0} (MIME type: {1})",
new Object[]{primaryFile.getPath(), primaryFile.getMIMEType()});
LOG.log(Level.FINE, "[EC for {0}] Added new file to project: {1} (MIME type: {2})",
new Object[]{editorConfigFileObject.getPath(), primaryFile.getPath(), primaryFile.getMIMEType()});
}

@Override
public void fileAttributeChanged(FileAttributeEvent event) {
super.fileAttributeChanged(event);
LOG.log(Level.FINE, "[EC for {0}] Attribute changed: {1}", new Object[]{editorConfigFileObject.getPath(), event.getFile().getPath()});
}

@Override
public void fileRenamed(FileRenameEvent event) {
super.fileRenamed(event);
LOG.log(Level.FINE, "[EC for {0}] Renamed file: {1}", new Object[]{editorConfigFileObject.getPath(), event.getFile().getPath()});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.welovecoding.nbeditorconfig.listener;

import com.welovecoding.nbeditorconfig.config.Settings;
import com.welovecoding.nbeditorconfig.processor.SmartSkip;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.project.Project;
import org.openide.filesystems.FileObject;

public class ListenerAttacher {

private static final Logger LOG = Logger.getLogger(ListenerAttacher.class.getSimpleName());

static {
LOG.setLevel(Level.INFO);
}

/**
* Recursively attach listeners to folders containing a .editorconfig file.
*
* @param file file or folder to attach listener
* @param project the project the file is related to
*/
public static void attachListeners(FileObject file, Project project) {
if (project.getProjectDirectory().equals(file)) {
file.addRecursiveListener(new ProjectChangeListener(project));
}

if (file.isFolder()) {
if (SmartSkip.skipDirectory(file)) {
LOG.log(Level.INFO, "\u00ac Skipped directory: {0}", file.getPath());
} else {
for (FileObject child : file.getChildren()) {
attachListeners(child, project);
}
}
} else {
if (file.getExt().equals(Settings.EXTENSION)) {
file.addFileChangeListener(new EditorConfigChangeListener(project, file));
LOG.log(Level.INFO, "\u00ac Found EditorConfig: {0}", file.getPath());
} else {
LOG.log(Level.FINE, "\u00ac No EditorConfig Found: {0}", file.getPath());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,55 @@ public class ProjectChangeListener extends FileChangeAdapter {
private final Project project;

static {
LOG.setLevel(Level.OFF);
LOG.setLevel(Level.INFO);
}

public ProjectChangeListener(Project project) {
this.project = project;
}

@Override
public void fileFolderCreated(FileEvent event) {
super.fileFolderCreated(event);
LOG.log(Level.INFO, "Created folder: {0}", event.getFile().getPath());
ListenerAttacher.attachListeners(event.getFile(), project);
}

/**
* Method is triggered when content has changed and it's possible to display
* content in NetBeans. Method is also triggered when project will be opened.
*
* @param event Event for listening on filesystem changes
*/
@Override
public void fileDataCreated(FileEvent event) {
super.fileDataCreated(event);
LOG.log(Level.INFO, "fileDataCreated: {0}", event.getFile().getPath());
ListenerAttacher.attachListeners(event.getFile(), project);
}

@Override
public void fileAttributeChanged(FileAttributeEvent event) {
super.fileAttributeChanged(event);
LOG.log(Level.INFO, "PROJECTLISTENER: Attribute changed: {0}", event.getFile().getPath());
LOG.log(Level.FINE, "Attribute changed: {0}", event.getFile().getPath());
}

@Override
public void fileRenamed(FileRenameEvent event) {
super.fileRenamed(event);
LOG.log(Level.INFO, "PROJECTLISTENER: Renamed file: {0}", event.getFile().getPath());
LOG.log(Level.FINE, "Renamed file: {0}", event.getFile().getPath());
}

@Override
public void fileDeleted(FileEvent event) {
super.fileDeleted(event);
LOG.log(Level.INFO, "PROJECTLISTENER: Deleted file: {0}", event.getFile().getPath());
LOG.log(Level.FINE, "Deleted file: {0}", event.getFile().getPath());
}

@Override
public void fileChanged(FileEvent event) {
super.fileChanged(event);
LOG.log(Level.INFO, "PROJECTLISTENER: File content changed: {0}", event.getFile().getPath());
}

@Override
public void fileFolderCreated(FileEvent event) {
super.fileFolderCreated(event);
LOG.log(Level.INFO, "PROJECTLISTENER: Created folder: {0}", event.getFile().getPath());
}

/**
* Method is triggered when content has changed and it's possible to display
* content in NetBeans. Method is also triggered when project will be opened.
*
* @param event Event for listening on filesystem changes
*/
@Override
public void fileDataCreated(FileEvent event) {
super.fileDataCreated(event);
LOG.log(Level.INFO, "PROJECTLISTENER: fileDataCreated: {0}", event.getFile().getPath());
LOG.log(Level.FINE, "File content changed: {0}", event.getFile().getPath());
}

}
Loading