diff --git a/pmd-netbeans/CHANGES.txt b/pmd-netbeans/CHANGES.txt
index 0461c7e748..7d08c33b53 100644
--- a/pmd-netbeans/CHANGES.txt
+++ b/pmd-netbeans/CHANGES.txt
@@ -1,3 +1,5 @@
+- ignore R/O files in scanner (http://www.netbeans.org/issues/show_bug.cgi?id=72197)
+
Version 1.6
- Updated pmd to version 3.6
diff --git a/pmd-netbeans/build.xml b/pmd-netbeans/build.xml
index 26157a96ac..22ccd01b17 100644
--- a/pmd-netbeans/build.xml
+++ b/pmd-netbeans/build.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/pmd-netbeans/manifest.mf b/pmd-netbeans/manifest.mf
index e7bf0ed9ad..1577ba26ad 100644
--- a/pmd-netbeans/manifest.mf
+++ b/pmd-netbeans/manifest.mf
@@ -1,5 +1,5 @@
Manifest-Version: 1.0
-OpenIDE-Module-Specification-Version: 1.6
+OpenIDE-Module-Specification-Version: 1.6.0.1
Created-By: Ole-Martin Mørk and Gunnlaugur Þór Briem and Radim Kubacki
OpenIDE-Module: pmd
OpenIDE-Module-Layer: pmd/mf-layer.xml
diff --git a/pmd-netbeans/src/pmd/RunPMDAction.java b/pmd-netbeans/src/pmd/RunPMDAction.java
index 3d2a20e79b..9e86b0dedf 100644
--- a/pmd-netbeans/src/pmd/RunPMDAction.java
+++ b/pmd-netbeans/src/pmd/RunPMDAction.java
@@ -181,7 +181,7 @@ public class RunPMDAction extends CookieAction {
String name = cp.getResourceName( fobj, '.', false );
//The file is not a java file
- if( !dataobject.getPrimaryFile().hasExt( "java" ) || dataobject.getCookie( LineCookie.class ) == null ) {
+ if (!shouldCheck(dataobject)) {
continue;
}
@@ -244,6 +244,15 @@ public class RunPMDAction extends CookieAction {
Collections.sort( list );
return list;
}
+
+ // package private for testing purposes
+ static boolean shouldCheck(DataObject dobj) {
+ if (!dobj.getPrimaryFile().hasExt( "java" )
+ || dobj.getCookie( LineCookie.class ) == null) {
+ return false;
+ }
+ return true;
+ }
/**
diff --git a/pmd-netbeans/src/pmd/scan/Scanner.java b/pmd-netbeans/src/pmd/scan/Scanner.java
index d92366d1ec..f8d8704e29 100644
--- a/pmd-netbeans/src/pmd/scan/Scanner.java
+++ b/pmd-netbeans/src/pmd/scan/Scanner.java
@@ -101,13 +101,17 @@ public class Scanner implements Runnable, DocumentListener {
if (foo != null)
tabSize = foo.intValue();
- DataObject object = NbEditorUtilities.getDataObject(doc);
- if (object == null) {
+ DataObject dobj = NbEditorUtilities.getDataObject(doc);
+ if (dobj == null) {
return;
}
- LineCookie cookie = ( LineCookie )object.getCookie( LineCookie.class );
+ if (!dobj.getPrimaryFile().canWrite()) {
+ return;
+ }
+
+ LineCookie cookie = ( LineCookie )dobj.getCookie( LineCookie.class );
Line.Set lineset = cookie.getLineSet();
- List list = Collections.singletonList(object);
+ List list = Collections.singletonList(dobj);
List faults = RunPMDAction.performScan(list );
PMDScanAnnotation.clearAll();
for( int i = 0; i < faults.size(); i++ ) {
diff --git a/pmd-netbeans/test/unit/src/pmd/RunPMDActionTest.java b/pmd-netbeans/test/unit/src/pmd/RunPMDActionTest.java
index 2f944262bd..e9adad93b6 100644
--- a/pmd-netbeans/test/unit/src/pmd/RunPMDActionTest.java
+++ b/pmd-netbeans/test/unit/src/pmd/RunPMDActionTest.java
@@ -33,7 +33,9 @@ import java.util.List;
import org.netbeans.junit.NbTestCase;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileSystem;
import org.openide.filesystems.FileUtil;
+import org.openide.filesystems.XMLFileSystem;
import org.openide.loaders.DataObject;
/**
@@ -110,6 +112,41 @@ public class RunPMDActionTest extends NbTestCase {
assertEquals("There should be no error for PMDSample.java file", 0, result.size());
}
+
+ public void testShouldCheck() throws Exception {
+ clearWorkDir();
+
+ FileObject dir = FileUtil.toFileObject(getWorkDir());
+ assertNotNull("Cannot find FileObject for work dir", dir);
+ FileObject f1;
+ f1 = dir.createData("MANIFEST.MF");
+ assertNotNull("Cannot create file in work dir", f1);
+ DataObject d1 = DataObject.find(f1);
+ assertNotNull("Cannot find a data object", d1);
+ assertFalse("MANIFEST.MF file should not be checked", RunPMDAction.shouldCheck(d1));
+
+ f1 = dir.createData("PMDSample.java");
+ assertNotNull("Cannot create file in work dir", f1);
+ FileLock l = null;
+ try {
+ l = f1.lock();
+ PrintStream ps = new PrintStream (f1.getOutputStream(l));
+ ps.print("public class PMDSample { PMDSample () {} }");
+ ps.close();
+ }
+ finally {
+ if (l != null) {
+ l.releaseLock();
+ }
+ }
+ d1 = DataObject.find(f1);
+ assertTrue("Java file should be checked", RunPMDAction.shouldCheck(d1));
+ FileSystem fs = new XMLFileSystem(RunPMDActionTest.class.getResource("testfs.xml"));
+ f1 = fs.findResource("pkg/Sample.java");
+ assertFalse("expecting R/O file on XMLFileSystem", f1.canWrite());
+ d1 = DataObject.find(f1);
+ assertTrue("read only Java file "+d1+" should be checked too", RunPMDAction.shouldCheck(d1));
+ }
/**
* Test of asynchronous method, of class pmd.RunPMDAction.
diff --git a/pmd-netbeans/test/unit/src/pmd/testfs.xml b/pmd-netbeans/test/unit/src/pmd/testfs.xml
new file mode 100644
index 0000000000..789a7d3f71
--- /dev/null
+++ b/pmd-netbeans/test/unit/src/pmd/testfs.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+