git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4342 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Radim Kubacki
2006-04-14 15:25:41 +00:00
parent 2773f03749
commit c502aab3bb
7 changed files with 66 additions and 7 deletions

View File

@ -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

View File

@ -4,7 +4,7 @@
<property name="pmd.jar" value="pmd-3.6.jar"/>
<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"/>

View File

@ -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

View File

@ -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;
}
/**

View File

@ -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++ ) {

View File

@ -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.

View 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>