Skip to content

Commit

Permalink
Now, the plugin should not mess with the character encoding after it …
Browse files Browse the repository at this point in the history
…has been set for the project. Also, all files in the project directory share the same character encoding not just the files in the source directories.
kelemen committed Sep 22, 2012
1 parent 39903e5 commit 388b17c
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.netbeans.gradle.project.query;

import java.io.File;
import java.nio.charset.Charset;
import org.netbeans.gradle.project.NbGradleProject;
import org.netbeans.gradle.project.model.NbGradleModule;
import org.netbeans.gradle.project.model.NbSourceGroup;
import org.netbeans.gradle.project.properties.ProjectProperties;
import org.netbeans.spi.queries.FileEncodingQueryImplementation;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
@@ -19,15 +17,14 @@ public GradleSourceEncodingQuery(NbGradleProject project) {

@Override
public Charset getEncoding(FileObject file) {
NbGradleModule mainModule = project.getAvailableModel().getMainModule();
for (NbSourceGroup srcGroup: mainModule.getSources().values()) {
for (File srcDir: srcGroup.getPaths()) {
FileObject srcDirObj = FileUtil.toFileObject(srcDir);
if (srcDirObj != null && FileUtil.isParentOf(srcDirObj, file)) {
return project.getProperties().getSourceEncoding().getValue();
}
}
if (FileUtil.isParentOf(project.getProjectDirectory(), file)) {
ProjectProperties properties = project.tryGetLoadedProperties();
return properties != null
? properties.getSourceEncoding().getValue()
: null;
}
else {
return null;
}
return null;
}
}

0 comments on commit 388b17c

Please sign in to comment.