예제 #1
0
  /**
   * Check that regular error parser extension defined in plugin.xml is accessible.
   *
   * @throws Exception...
   */
  public void testExtension() throws Exception {
    // ErrorParserManager.getErrorParser
    {
      IErrorParserNamed errorParser = ErrorParserManager.getErrorParserCopy(REGEX_ERRORPARSER_ID);
      assertNotNull(errorParser);
      assertEquals(REGEX_ERRORPARSER_NAME, errorParser.getName());

      assertTrue(errorParser instanceof RegexErrorParser);
      RegexErrorParser regexErrorParser = (RegexErrorParser) errorParser;
      assertEquals(REGEX_ERRORPARSER_ID, regexErrorParser.getId());
      assertEquals(REGEX_ERRORPARSER_NAME, regexErrorParser.getName());

      RegexErrorPattern[] patterns = regexErrorParser.getPatterns();
      assertEquals(1, patterns.length);

      RegexErrorPattern pattern = patterns[0];
      assertEquals(IMarker.SEVERITY_ERROR, pattern.getSeverity());
      assertEquals(true, pattern.isEatProcessedLine());
      assertEquals("(.*):(.*):regex (.*)", pattern.getPattern());
      assertEquals("$1", pattern.getFileExpression());
      assertEquals("$2", pattern.getLineExpression());
      assertEquals("$3", pattern.getDescriptionExpression());
      assertEquals("", pattern.getVarNameExpression());
    }

    // ErrorParserManager.getErrorParsers
    {
      IErrorParser errorParser = ErrorParserManager.getErrorParserCopy(REGEX_ERRORPARSER_ID);
      assertTrue(errorParser instanceof RegexErrorParser);

      RegexErrorParser regexErrorParser = (RegexErrorParser) errorParser;
      assertEquals(REGEX_ERRORPARSER_ID, regexErrorParser.getId());
      assertEquals(REGEX_ERRORPARSER_NAME, regexErrorParser.getName());
    }
  }
예제 #2
0
  /**
   * Make sure extensions contributed through extension point are sorted by name unless deprecated
   * or contributed by test plugin.
   *
   * @throws Exception...
   */
  public void testExtensionsSorting() throws Exception {
    {
      String[] ids = ErrorParserManager.getErrorParserExtensionIds();
      String lastName = "";
      boolean lastIsDeprecated = false;
      boolean lastIsTestPlugin = false;
      // first regular error parsers
      // then deprecated ones
      // then contributed by test plugin
      for (String id : ids) {
        String name = ErrorParserManager.getErrorParserCopy(id).getName();
        boolean isDeprecated = name.contains("(Deprecated)");
        boolean isTestPlugin = id.startsWith(CTestPlugin.PLUGIN_ID);
        String message = "Parser [" + lastName + "] preceeds [" + name + "]";

        // inside the same category sorted by names
        if (lastIsDeprecated == isDeprecated && lastIsTestPlugin == isTestPlugin) {
          assertTrue(message, lastName.compareTo(name) <= 0);
        }
        // deprecated follow non-deprecated (unless parsers from test plugin show up)
        if (lastIsTestPlugin == isTestPlugin) {
          assertFalse(message, lastIsDeprecated == true && isDeprecated == false);
        }
        // error parsers from test plugin are the last
        assertFalse(message, lastIsTestPlugin == true && isTestPlugin == false);

        lastName = name;
        lastIsDeprecated = isDeprecated;
        lastIsTestPlugin = isTestPlugin;
      }
    }
  }
예제 #3
0
  /**
   * Make sure special characters are serialized properly.
   *
   * @throws Exception...
   */
  public void testSerializeRegexErrorParserSpecialCharacters() throws Exception {

    final String TESTING_ID = "org.eclipse.cdt.core.test.regexerrorparser";
    final String TESTING_NAME = "<>\"'\\& Error Parser";
    final String TESTING_REGEX = "Pattern-<>\"'\\&";
    final String ALL_IDS =
        ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
    {
      // Create error parser with the same id as in eclipse registry
      RegexErrorParser regexErrorParser = new RegexErrorParser(TESTING_ID, TESTING_NAME);
      regexErrorParser.addPattern(
          new RegexErrorPattern(
              TESTING_REGEX,
              "line-<>\"'\\&",
              "file-<>\"'\\&",
              "description-<>\"'\\&",
              null,
              IMarkerGenerator.SEVERITY_WARNING,
              false));

      // Add to available parsers
      ErrorParserExtensionManager.setUserDefinedErrorParsersInternal(
          new IErrorParserNamed[] {regexErrorParser});
      assertNotNull(ErrorParserManager.getErrorParserCopy(TESTING_ID));
      // And serialize in persistent storage
      ErrorParserExtensionManager.serializeUserDefinedErrorParsers();
    }

    {
      // Re-load from persistent storage and check it out
      ErrorParserExtensionManager.loadUserDefinedErrorParsers();
      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      assertTrue(all.contains(TESTING_ID));

      IErrorParser errorParser = ErrorParserManager.getErrorParserCopy(TESTING_ID);
      assertNotNull(errorParser);
      assertTrue(errorParser instanceof RegexErrorParser);
      RegexErrorParser regexErrorParser = (RegexErrorParser) errorParser;
      assertEquals(TESTING_ID, regexErrorParser.getId());
      assertEquals(TESTING_NAME, regexErrorParser.getName());

      RegexErrorPattern[] errorPatterns = regexErrorParser.getPatterns();
      assertEquals(1, errorPatterns.length);
      assertEquals(TESTING_REGEX, errorPatterns[0].getPattern());
    }
  }
예제 #4
0
  /**
   * Test retrieval of error parser, clone() and equals().
   *
   * @throws Exception...
   */
  public void testGetErrorParserCopy() throws Exception {
    {
      IErrorParserNamed clone1 = ErrorParserManager.getErrorParserCopy(REGEX_ERRORPARSER_ID);
      IErrorParserNamed clone2 = ErrorParserManager.getErrorParserCopy(REGEX_ERRORPARSER_ID);
      assertEquals(clone1, clone2);
      assertNotSame(clone1, clone2);
    }
    {
      IErrorParserNamed clone1 = ErrorParserManager.getErrorParserCopy(NOTREGEX_ERRORPARSER_ID);
      IErrorParserNamed clone2 = ErrorParserManager.getErrorParserCopy(NOTREGEX_ERRORPARSER_ID);
      assertEquals(clone1, clone2);
      assertNotSame(clone1, clone2);

      assertTrue(clone1 instanceof ErrorParserNamedWrapper);
      assertTrue(clone2 instanceof ErrorParserNamedWrapper);
      IErrorParser gccClone1 = ((ErrorParserNamedWrapper) clone1).getErrorParser();
      IErrorParser gccClone2 = ((ErrorParserNamedWrapper) clone2).getErrorParser();
      assertNotSame(clone1, clone2);
    }
  }
예제 #5
0
  /**
   * Test serialization of user defined error parsers.
   *
   * @throws Exception...
   */
  public void testSerializeErrorParser() throws Exception {
    final String TESTING_ID = "org.eclipse.cdt.core.test.errorparser";
    final String TESTING_NAME = "An error parser";

    {
      // Create error parser
      IErrorParser errorParser = new GASErrorParser();
      // Add to available parsers
      ErrorParserExtensionManager.setUserDefinedErrorParsersInternal(
          new IErrorParserNamed[] {
            new ErrorParserNamedWrapper(TESTING_ID, TESTING_NAME, errorParser)
          });
      assertNotNull(ErrorParserManager.getErrorParserCopy(TESTING_ID));
      assertEquals(TESTING_NAME, ErrorParserManager.getErrorParserCopy(TESTING_ID).getName());
      // Serialize in persistent storage
      ErrorParserExtensionManager.serializeUserDefinedErrorParsers();
    }
    {
      // Remove from available parsers
      ErrorParserExtensionManager.setUserDefinedErrorParsersInternal(null);
      assertNull(ErrorParserManager.getErrorParserCopy(TESTING_ID));
    }

    {
      // Re-load from persistent storage and check it out
      ErrorParserExtensionManager.loadUserDefinedErrorParsers();
      IErrorParserNamed errorParser = ErrorParserManager.getErrorParserCopy(TESTING_ID);
      assertNotNull(errorParser);
      assertEquals(TESTING_NAME, errorParser.getName());
      assertTrue(errorParser instanceof ErrorParserNamedWrapper);
      assertTrue(
          ((ErrorParserNamedWrapper) errorParser).getErrorParser() instanceof GASErrorParser);
    }
    {
      // Remove from available parsers as clean-up
      ErrorParserExtensionManager.setUserDefinedErrorParsersInternal(null);
      assertNull(ErrorParserManager.getErrorParserCopy(TESTING_ID));
    }
  }
예제 #6
0
  /**
   * Test setting/retrieval of error parsers and their IDs.
   *
   * @throws Exception...
   */
  public void testAvailableErrorParsers() throws Exception {
    final String TESTING_ID = "org.eclipse.cdt.core.test.errorparser";
    final String TESTING_NAME = "An error parser";

    final String[] availableParserIds = ErrorParserManager.getErrorParserAvailableIds();
    assertNotNull(availableParserIds);
    assertTrue(availableParserIds.length > 0);
    final String firstId = ErrorParserManager.getErrorParserAvailableIds()[0];
    final IErrorParserNamed firstErrorParser = ErrorParserManager.getErrorParserCopy(firstId);
    assertNotNull(firstErrorParser);
    assertEquals(firstId, firstErrorParser.getId());
    final String firstName = firstErrorParser.getName();
    // Preconditions
    {
      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      assertEquals(false, all.contains(TESTING_ID));
      assertEquals(true, all.contains(firstId));

      assertNull(ErrorParserManager.getErrorParserCopy(TESTING_ID));

      IErrorParserNamed retrieved2 = ErrorParserManager.getErrorParserCopy(firstId);
      assertNotNull(retrieved2);
      assertEquals(firstErrorParser, retrieved2);
    }

    // set available parsers
    {
      IErrorParser dummy1 = new DummyErrorParser();
      IErrorParser dummy2 = new DummyErrorParser();
      ErrorParserManager.setUserDefinedErrorParsers(
          new IErrorParserNamed[] {
            // add brand new one
            new ErrorParserNamedWrapper(TESTING_ID, TESTING_NAME, dummy1),
            // override extension with another one
            new ErrorParserNamedWrapper(firstId, firstName, dummy2),
          });
      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      assertEquals(true, all.contains(TESTING_ID));
      assertEquals(true, all.contains(firstId));

      IErrorParserNamed retrieved1 = ErrorParserManager.getErrorParserCopy(TESTING_ID);
      assertNotNull(retrieved1);
      assertEquals(TESTING_NAME, retrieved1.getName());
      assertTrue(retrieved1 instanceof ErrorParserNamedWrapper);
      assertEquals(dummy1, ((ErrorParserNamedWrapper) retrieved1).getErrorParser());

      IErrorParserNamed retrieved2 = ErrorParserManager.getErrorParserCopy(firstId);
      assertNotNull(retrieved2);
      assertEquals(firstName, retrieved2.getName());
      assertTrue(retrieved2 instanceof ErrorParserNamedWrapper);
      assertEquals(dummy2, ((ErrorParserNamedWrapper) retrieved2).getErrorParser());

      IErrorParserNamed retrieved2_ext = ErrorParserManager.getErrorParserExtensionCopy(firstId);
      assertNotNull(retrieved2_ext);
      assertEquals(firstName, retrieved2_ext.getName());
      assertEquals(firstErrorParser, retrieved2_ext);
    }
    // reset available parsers
    {
      ErrorParserManager.setUserDefinedErrorParsers(null);
      String[] userDefinedIds = ErrorParserManager.getUserDefinedErrorParserIds();
      assertNull(userDefinedIds);

      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      assertEquals(false, all.contains(TESTING_ID));
      assertEquals(true, all.contains(firstId));

      assertNull(ErrorParserManager.getErrorParserCopy(TESTING_ID));

      IErrorParserNamed retrieved2 = ErrorParserManager.getErrorParserCopy(firstId);
      assertNotNull(retrieved2);
      assertEquals(firstErrorParser, retrieved2);
    }
  }