예제 #1
0
 /**
  * Returns full summary.
  *
  * @return The test summary of all events
  */
 public String summary() {
   final List<String> msgs = new LinkedList<String>();
   for (final AuditEvent event : this.events) {
     msgs.add(String.format("%s:%s", event.getLine(), event.getMessage()));
   }
   return StringUtils.join(msgs, "; ");
 }
예제 #2
0
 /**
  * Do we have this message for this line?
  *
  * @param line The number of the line
  * @param msg The message we're looking for
  * @return This message was reported for the give line?
  */
 public boolean has(final Integer line, final String msg) {
   boolean has = false;
   for (final AuditEvent event : this.events) {
     if (event.getLine() == line && event.getMessage().equals(msg)) {
       has = true;
       break;
     }
   }
   return has;
 }
예제 #3
0
  /** {@inheritDoc} */
  public boolean accept(AuditEvent aEvent) {
    // file and check match?
    if ((aEvent.getFileName() == null)
        || !mFileRegexp.matcher(aEvent.getFileName()).find()
        || (aEvent.getLocalizedMessage() == null)
        || ((mModuleId != null) && !mModuleId.equals(aEvent.getModuleId()))
        || ((mCheckRegexp != null) && !mCheckRegexp.matcher(aEvent.getSourceName()).find())) {
      return true;
    }

    // reject if no line/column matching
    if ((mLineFilter == null) && (mColumnFilter == null)) {
      return false;
    }

    // reject if line matches a line CSV value.
    if (mLineFilter != null) {
      if (mLineFilter.accept(aEvent.getLine())) {
        return false;
      }
    }

    // reject if column matches a column CSV value.
    if (mColumnFilter != null) {
      if (mColumnFilter.accept(aEvent.getColumn())) {
        return false;
      }
    }
    return true;
  }
    /**
     * Determines whether the source of an audit event matches the text of this tag.
     *
     * @param event the {@code AuditEvent} to check.
     * @return true if the source of event matches the text of this tag.
     */
    public boolean isMatch(AuditEvent event) {
      final int line = event.getLine();
      boolean match = false;

      if (line >= firstLine && line <= lastLine) {
        final Matcher tagMatcher = tagCheckRegexp.matcher(event.getSourceName());

        if (tagMatcher.find()) {
          match = true;
        } else if (tagMessageRegexp == null) {
          if (event.getModuleId() != null) {
            final Matcher idMatcher = tagCheckRegexp.matcher(event.getModuleId());
            match = idMatcher.find();
          }
        } else {
          final Matcher messageMatcher = tagMessageRegexp.matcher(event.getMessage());
          match = messageMatcher.find();
        }
      }
      return match;
    }
예제 #5
0
 @Override
 public void addError(AuditEvent evt) {
   if (evt.getSeverityLevel() != SeverityLevel.IGNORE) {
     writer.print("<error" + " line=\"" + evt.getLine() + "\"");
     if (evt.getColumn() > 0) {
       writer.print(" column=\"" + evt.getColumn() + "\"");
     }
     writer.print(" severity=\"" + evt.getSeverityLevel().getName() + "\"");
     writer.print(" message=\"" + encode(evt.getMessage()) + "\"");
     writer.println(" source=\"" + encode(evt.getSourceName()) + "\"/>");
   }
 }
  @Override
  public boolean accept(AuditEvent event) {
    boolean accepted = true;

    if (event.getLocalizedMessage() != null) {
      // Lazy update. If the first event for the current file, update file
      // contents and tag suppressions
      final FileContents currentContents = FileContentsHolder.getContents();

      if (currentContents != null) {
        if (getFileContents() != currentContents) {
          setFileContents(currentContents);
          tagSuppressions();
        }
        if (matchesTag(event)) {
          accepted = false;
        }
      }
    }
    return accepted;
  }
예제 #7
0
 @Override
 public void fileStarted(AuditEvent evt) {
   writer.println("<file name=\"" + encode(evt.getFileName()) + "\">");
 }
 @Test
 public void testDecideDefault() {
   final AuditEvent ev = new AuditEvent(this, "Test.java");
   assertTrue(ev.getFileName(), filter.accept(ev));
 }