@Test public void testRealPathMatchWithRegexpAndProject() throws Exception { bug.addClass("SourceMatcherTest", null); ClassAnnotation primaryClass = bug.getPrimaryClass(); primaryClass.setSourceLines(SourceLineAnnotation.createUnknown("SourceMatcherTest", "SourceMatcherTest.java")); Project testProject = new Project(); String sourceDir = "src/test/java/edu/umd/cs/findbugs/filter"; testProject.addSourceDirs(Collections.singletonList(sourceDir)); SourceLineAnnotation.generateRelativeSource(new File(sourceDir), testProject); SourceMatcher sm = new SourceMatcher("~.*findbugs.*.java"); assertTrue("The regex matches the source directory of the given java file", sm.match(bug)); sm = new SourceMatcher("~.*notfound.*.java"); assertFalse("The regex does not match the source directory of the given java file", sm.match(bug)); }
@Override public boolean match(BugInstance bugInstance) { ClassAnnotation primaryClassAnnotation = bugInstance.getPrimaryClass(); if (primaryClassAnnotation == null) { return false; } boolean result = false; String bugFileName = primaryClassAnnotation.getSourceFileName(); if (bugFileName != null && !bugFileName.isEmpty()) { result = fileName.match(bugFileName); if (!result && bugInstance.getPrimarySourceLineAnnotation().isSourceFileKnown()) { bugFileName = bugInstance.getPrimarySourceLineAnnotation().getRealSourcePath(); result = fileName.match(bugFileName); } } LOG.debug("Matching {} with {}, result = {}", bugFileName, fileName, result); return result; }
SourceMatcher implements Matcher { @Override public boolean match(BugInstance bugInstance) { ClassAnnotation primaryClassAnnotation = bugInstance.getPrimaryClass(); if (primaryClassAnnotation == null) { return false; } boolean result = false; String bugFileName = primaryClassAnnotation.getSourceFileName(); if (bugFileName != null && !bugFileName.isEmpty()) { result = fileName.match(bugFileName); if (!result && bugInstance.getPrimarySourceLineAnnotation().isSourceFileKnown()) { bugFileName = bugInstance.getPrimarySourceLineAnnotation().getRealSourcePath(); result = fileName.match(bugFileName); } } LOG.debug("Matching {} with {}, result = {}", bugFileName, fileName, result); return result; } }
SourceMatcher implements Matcher { @Override public boolean match(BugInstance bugInstance) { ClassAnnotation primaryClassAnnotation = bugInstance.getPrimaryClass(); if (primaryClassAnnotation == null) { return false; } boolean result = false; String bugFileName = primaryClassAnnotation.getSourceFileName(); if (bugFileName != null && !bugFileName.isEmpty()) { result = fileName.match(bugFileName); if (!result && bugInstance.getPrimarySourceLineAnnotation().isSourceFileKnown()) { bugFileName = bugInstance.getPrimarySourceLineAnnotation().getRealSourcePath(); result = fileName.match(bugFileName); } } LOG.debug("Matching {} with {}, result = {}", bugFileName, fileName, result); return result; } SourceMatcher(String fileName); }
SourceMatcher implements Matcher { @Override public boolean match(BugInstance bugInstance) { ClassAnnotation primaryClassAnnotation = bugInstance.getPrimaryClass(); if (primaryClassAnnotation == null) { return false; } boolean result = false; String bugFileName = primaryClassAnnotation.getSourceFileName(); if (bugFileName != null && !bugFileName.isEmpty()) { result = fileName.match(bugFileName); if (!result && bugInstance.getPrimarySourceLineAnnotation().isSourceFileKnown()) { bugFileName = bugInstance.getPrimarySourceLineAnnotation().getRealSourcePath(); result = fileName.match(bugFileName); } } LOG.debug("Matching {} with {}, result = {}", bugFileName, fileName, result); return result; } SourceMatcher(String fileName); @Override String toString(); @Override boolean match(BugInstance bugInstance); @Override void writeXML(XMLOutput xmlOutput, boolean disabled); }
SourceMatcher implements Matcher { @Override public boolean match(BugInstance bugInstance) { ClassAnnotation primaryClassAnnotation = bugInstance.getPrimaryClass(); if (primaryClassAnnotation == null) { return false; } boolean result = false; String bugFileName = primaryClassAnnotation.getSourceFileName(); if (bugFileName != null && !bugFileName.isEmpty()) { result = fileName.match(bugFileName); if (!result && bugInstance.getPrimarySourceLineAnnotation().isSourceFileKnown()) { bugFileName = bugInstance.getPrimarySourceLineAnnotation().getRealSourcePath(); result = fileName.match(bugFileName); } } LOG.debug("Matching {} with {}, result = {}", bugFileName, fileName, result); return result; } SourceMatcher(String fileName); @Override String toString(); @Override boolean match(BugInstance bugInstance); @Override void writeXML(XMLOutput xmlOutput, boolean disabled);  }