http://www.netbeans.org/issues/show_bug.cgi?id=72197 - ignore R/O files in periodic scan
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4342 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
- ignore R/O files in scanner (http://www.netbeans.org/issues/show_bug.cgi?id=72197)
|
||||||
|
|
||||||
Version 1.6
|
Version 1.6
|
||||||
- Updated pmd to version 3.6
|
- Updated pmd to version 3.6
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<property name="pmd.jar" value="pmd-3.6.jar"/>
|
<property name="pmd.jar" value="pmd-3.6.jar"/>
|
||||||
<property name="nb.version" value="netbeans50"/>
|
<property name="nb.version" value="netbeans50"/>
|
||||||
<property name="VERSION" value="1.6"/>
|
<property name="VERSION" value="1.6.0.1"/>
|
||||||
|
|
||||||
<property file="build.ant.properties"/>
|
<property file="build.ant.properties"/>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Manifest-Version: 1.0
|
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
|
Created-By: Ole-Martin Mørk and Gunnlaugur Þór Briem and Radim Kubacki
|
||||||
OpenIDE-Module: pmd
|
OpenIDE-Module: pmd
|
||||||
OpenIDE-Module-Layer: pmd/mf-layer.xml
|
OpenIDE-Module-Layer: pmd/mf-layer.xml
|
||||||
|
@ -181,7 +181,7 @@ public class RunPMDAction extends CookieAction {
|
|||||||
String name = cp.getResourceName( fobj, '.', false );
|
String name = cp.getResourceName( fobj, '.', false );
|
||||||
|
|
||||||
//The file is not a java file
|
//The file is not a java file
|
||||||
if( !dataobject.getPrimaryFile().hasExt( "java" ) || dataobject.getCookie( LineCookie.class ) == null ) {
|
if (!shouldCheck(dataobject)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,6 +245,15 @@ public class RunPMDAction extends CookieAction {
|
|||||||
return 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the action this action is set up to do on the specified nodes
|
* Performs the action this action is set up to do on the specified nodes
|
||||||
|
@ -101,13 +101,17 @@ public class Scanner implements Runnable, DocumentListener {
|
|||||||
if (foo != null)
|
if (foo != null)
|
||||||
tabSize = foo.intValue();
|
tabSize = foo.intValue();
|
||||||
|
|
||||||
DataObject object = NbEditorUtilities.getDataObject(doc);
|
DataObject dobj = NbEditorUtilities.getDataObject(doc);
|
||||||
if (object == null) {
|
if (dobj == null) {
|
||||||
return;
|
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();
|
Line.Set lineset = cookie.getLineSet();
|
||||||
List list = Collections.singletonList(object);
|
List list = Collections.singletonList(dobj);
|
||||||
List faults = RunPMDAction.performScan(list );
|
List faults = RunPMDAction.performScan(list );
|
||||||
PMDScanAnnotation.clearAll();
|
PMDScanAnnotation.clearAll();
|
||||||
for( int i = 0; i < faults.size(); i++ ) {
|
for( int i = 0; i < faults.size(); i++ ) {
|
||||||
|
@ -33,7 +33,9 @@ import java.util.List;
|
|||||||
import org.netbeans.junit.NbTestCase;
|
import org.netbeans.junit.NbTestCase;
|
||||||
import org.openide.filesystems.FileLock;
|
import org.openide.filesystems.FileLock;
|
||||||
import org.openide.filesystems.FileObject;
|
import org.openide.filesystems.FileObject;
|
||||||
|
import org.openide.filesystems.FileSystem;
|
||||||
import org.openide.filesystems.FileUtil;
|
import org.openide.filesystems.FileUtil;
|
||||||
|
import org.openide.filesystems.XMLFileSystem;
|
||||||
import org.openide.loaders.DataObject;
|
import org.openide.loaders.DataObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,6 +113,41 @@ public class RunPMDActionTest extends NbTestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
* Test of asynchronous method, of class pmd.RunPMDAction.
|
||||||
*/
|
*/
|
||||||
|
7
pmd-netbeans/test/unit/src/pmd/testfs.xml
Normal file
7
pmd-netbeans/test/unit/src/pmd/testfs.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
|
||||||
|
<filesystem>
|
||||||
|
<folder name="pkg">
|
||||||
|
<file name="Sample.java"/>
|
||||||
|
</folder>
|
||||||
|
</filesystem>
|
Reference in New Issue
Block a user