@Test public void testOptionalHeader() throws Exception { HeaderCheck check = new HeaderCheck("test-optionaljava-header.regex"); File testSrcDir = MavenTestingUtils.getProjectDir("src/test/java"); String path = HeaderCheckTest.class.getName().replace('.', '/') + ".java"; File srcFile = PathAssert.assertFileExists(testSrcDir, path); JunitReport report = new JunitReport(); check.check(report, srcFile); Assert.assertEquals("entry.count", 1, report.getEntryCount()); JunitReport.FileEntry entry = report.getEntry(srcFile); Assert.assertNotNull("Should have found entry", entry); System.out.println(entry); Assert.assertEquals("Entry.type", "none", entry.type); }
public void check(Report report, File file) { try { String fileHeader[] = readFileHeader(file); int maxLines = Math.min(header.length, fileHeader.length); for (int fileIdx = 0, regexIdx = 0; regexIdx < maxLines; fileIdx++, regexIdx++) { while (!fileHeader[fileIdx].matches(header[regexIdx]) && optional[regexIdx]) { regexIdx++; if (regexIdx >= maxLines) { report.pass(file); return; } } if (!fileHeader[fileIdx].matches(header[regexIdx])) { report.violation(file, "header", fileIdx, "Header line #%d \"%s\" does not match regex \"%s\"", fileIdx, fileHeader[fileIdx], header[regexIdx]); return; } } report.pass(file); } catch (IOException e) { report.failure(file, e); } }
HeaderCheck { public void check(Report report, File file) { try { String fileHeader[] = readFileHeader(file); int maxLines = Math.min(header.length, fileHeader.length); for (int fileIdx = 0, regexIdx = 0; regexIdx < maxLines; fileIdx++, regexIdx++) { while (!fileHeader[fileIdx].matches(header[regexIdx]) && optional[regexIdx]) { regexIdx++; if (regexIdx >= maxLines) { report.pass(file); return; } } if (!fileHeader[fileIdx].matches(header[regexIdx])) { report.violation(file, "header", fileIdx, "Header line #%d \"%s\" does not match regex \"%s\"", fileIdx, fileHeader[fileIdx], header[regexIdx]); return; } } report.pass(file); } catch (IOException e) { report.failure(file, e); } } }
HeaderCheck { public void check(Report report, File file) { try { String fileHeader[] = readFileHeader(file); int maxLines = Math.min(header.length, fileHeader.length); for (int fileIdx = 0, regexIdx = 0; regexIdx < maxLines; fileIdx++, regexIdx++) { while (!fileHeader[fileIdx].matches(header[regexIdx]) && optional[regexIdx]) { regexIdx++; if (regexIdx >= maxLines) { report.pass(file); return; } } if (!fileHeader[fileIdx].matches(header[regexIdx])) { report.violation(file, "header", fileIdx, "Header line #%d \"%s\" does not match regex \"%s\"", fileIdx, fileHeader[fileIdx], header[regexIdx]); return; } } report.pass(file); } catch (IOException e) { report.failure(file, e); } } HeaderCheck(String regexId); }
HeaderCheck { public void check(Report report, File file) { try { String fileHeader[] = readFileHeader(file); int maxLines = Math.min(header.length, fileHeader.length); for (int fileIdx = 0, regexIdx = 0; regexIdx < maxLines; fileIdx++, regexIdx++) { while (!fileHeader[fileIdx].matches(header[regexIdx]) && optional[regexIdx]) { regexIdx++; if (regexIdx >= maxLines) { report.pass(file); return; } } if (!fileHeader[fileIdx].matches(header[regexIdx])) { report.violation(file, "header", fileIdx, "Header line #%d \"%s\" does not match regex \"%s\"", fileIdx, fileHeader[fileIdx], header[regexIdx]); return; } } report.pass(file); } catch (IOException e) { report.failure(file, e); } } HeaderCheck(String regexId); void check(Report report, File file); }
HeaderCheck { public void check(Report report, File file) { try { String fileHeader[] = readFileHeader(file); int maxLines = Math.min(header.length, fileHeader.length); for (int fileIdx = 0, regexIdx = 0; regexIdx < maxLines; fileIdx++, regexIdx++) { while (!fileHeader[fileIdx].matches(header[regexIdx]) && optional[regexIdx]) { regexIdx++; if (regexIdx >= maxLines) { report.pass(file); return; } } if (!fileHeader[fileIdx].matches(header[regexIdx])) { report.violation(file, "header", fileIdx, "Header line #%d \"%s\" does not match regex \"%s\"", fileIdx, fileHeader[fileIdx], header[regexIdx]); return; } } report.pass(file); } catch (IOException e) { report.failure(file, e); } } HeaderCheck(String regexId); void check(Report report, File file);  }