Пример #1
0
 @Test
 public void testInCache() throws IOException {
   Configuration config = new DefaultConfiguration("myname");
   final String filePath = temporaryFolder.newFile().getPath();
   PropertyCacheFile cache = new PropertyCacheFile(config, filePath);
   cache.put("myFile", 1);
   assertTrue(cache.inCache("myFile", 1));
   assertFalse(cache.inCache("myFile", 2));
   assertFalse(cache.inCache("myFile1", 1));
 }
Пример #2
0
  @Override
  protected void processFiltered(File file, List<String> lines) {
    // check if already checked and passed the file
    final String fileName = file.getPath();
    final long timestamp = file.lastModified();
    if (cache != null
        && (cache.inCache(fileName, timestamp)
            || !Utils.fileExtensionMatches(file, getFileExtensions()))) {
      return;
    }

    final String msg = "%s occurred during the analysis of file %s.";

    try {
      final FileText text = FileText.fromLines(file, lines);
      final FileContents contents = new FileContents(text);
      final DetailAST rootAST = parse(contents);

      getMessageCollector().reset();

      walk(rootAST, contents, AstState.ORDINARY);

      final DetailAST astWithComments = appendHiddenCommentNodes(rootAST);

      walk(astWithComments, contents, AstState.WITH_COMMENTS);
    } catch (final TokenStreamRecognitionException tre) {
      final String exceptionMsg = String.format(msg, "TokenStreamRecognitionException", fileName);
      LOG.error(exceptionMsg);
      final RecognitionException re = tre.recog;
      final String message = re.getMessage();
      getMessageCollector().add(createLocalizedMessage(message));
    }
    // RecognitionException and any other (need to check if needed)
    catch (Throwable ex) {
      final String exceptionMsg = String.format(msg, ex.getClass().getSimpleName(), fileName);
      LOG.error(exceptionMsg, ex);
      getMessageCollector().add(createLocalizedMessage(ex.getMessage()));
    }

    if (cache != null && getMessageCollector().size() == 0) {
      cache.put(fileName, timestamp);
    }
  }