Exemplo n.º 1
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;
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Register the error in {@link ErrorParserManager}.
   *
   * @param matcher - matcher to parse the input line.
   * @param eoParser - {@link ErrorParserManager}.
   * @return {@code true} indicating that error was found.
   */
  protected boolean recordError(Matcher matcher, ErrorParserManager eoParser) {
    int severity = getSeverity(matcher);
    if (severity == -1)
      // Skip
      return true;

    String fileName = getFileName(matcher);
    int lineNum = getLineNum(matcher);
    String desc = getDesc(matcher);
    String varName = getVarName(matcher);
    IPath externalPath = null;

    IResource file = null;
    if (fileName != null) {
      file = eoParser.findFileName(fileName);

      if (file == null) {
        // If the file is not found in the workspace we attach the problem to the project
        // and add the external path to the file.
        file = eoParser.getProject();
        externalPath = getLocation(fileName);
      }
    }

    eoParser.generateExternalMarker(file, lineNum, desc, severity, varName, externalPath);
    return true;
  }
Exemplo n.º 3
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());
    }
  }
Exemplo n.º 4
0
 /**
  * Convenience method to let {@link ErrorParserManager} parse one line of output. This method goes
  * through the whole working cycle every time creating new {@link ErrorParserManager}.
  *
  * @param project - for which project to parse output.
  * @param buildDir - location of build for {@link ErrorParserManager}.
  * @param errorParsers - error parsers used.
  * @param line - one line of output.
  * @throws Exception
  */
 private void parseOutput(IProject project, IPath buildDir, String[] errorParsers, String line)
     throws Exception {
   ErrorParserManager epManager =
       new ErrorParserManager(project, buildDir, markerGenerator, errorParsers);
   line = line + '\n';
   epManager.write(line.getBytes(), 0, line.length());
   epManager.close();
   epManager.getOutputStream().close();
 }
Exemplo n.º 5
0
  @Override
  protected void tearDown() throws Exception {
    ResourceHelper.cleanUp();
    fProject = null;

    ErrorParserManager.setUserDefinedErrorParsers(null);
  }
Exemplo n.º 6
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);
    }
  }
Exemplo n.º 7
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));
    }
  }
Exemplo n.º 8
0
  /**
   * Checks if compatibility with CCorePlugin methods from CDT 6.0 was not violated.
   *
   * @throws Exception...
   */
  public void testCompatibility() throws Exception {
    final CCorePlugin cCorePlugin = CCorePlugin.getDefault();

    // CCorePlugin.getAllErrorParsersIDs()
    String all = ErrorParserManager.toDelimitedString(cCorePlugin.getAllErrorParsersIDs());
    assertTrue(all.contains(NOTREGEX_ERRORPARSER_ID));

    // CCorePlugin.getErrorParser(id)
    IErrorParser[] gccErrorParserArray = cCorePlugin.getErrorParser(NOTREGEX_ERRORPARSER_ID);
    assertNotNull(gccErrorParserArray);
    assertEquals(1, gccErrorParserArray.length);
    assertTrue(gccErrorParserArray[0] instanceof GASErrorParser);
  }
Exemplo n.º 9
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());
    }
  }
Exemplo n.º 10
0
  /**
   * Check that default parser IDs are stored properly.
   *
   * @throws Exception...
   */
  public void testSerializeDefaultErrorParserIds() throws Exception {
    final String[] testingDefaultErrorParserIds = {
      "org.eclipse.cdt.core.test.errorparser0",
      "org.eclipse.cdt.core.test.errorparser1",
      "org.eclipse.cdt.core.test.errorparser2",
    };
    final String TESTING_IDS = ErrorParserManager.toDelimitedString(testingDefaultErrorParserIds);
    final String DEFAULT_IDS =
        ErrorParserManager.toDelimitedString(ErrorParserManager.getDefaultErrorParserIds());

    {
      // setDefaultErrorParserIds
      ErrorParserExtensionManager.setDefaultErrorParserIdsInternal(testingDefaultErrorParserIds);

      String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds();
      assertNotNull(defaultErrorParserIds);
      assertEquals(TESTING_IDS, ErrorParserManager.toDelimitedString(defaultErrorParserIds));

      // serialize them
      ErrorParserExtensionManager.serializeDefaultErrorParserIds();
    }

    {
      // Remove from internal list
      ErrorParserExtensionManager.setDefaultErrorParserIdsInternal(null);
      assertEquals(
          DEFAULT_IDS,
          ErrorParserManager.toDelimitedString(ErrorParserManager.getDefaultErrorParserIds()));
    }

    {
      // Re-load from persistent storage and check it out
      ErrorParserExtensionManager.loadDefaultErrorParserIds();

      String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds();
      assertNotNull(defaultErrorParserIds);
      assertEquals(TESTING_IDS, ErrorParserManager.toDelimitedString(defaultErrorParserIds));
    }

    {
      // Reset IDs and serialize
      ErrorParserExtensionManager.setDefaultErrorParserIdsInternal(null);
      ErrorParserExtensionManager.serializeDefaultErrorParserIds();

      // Check that default IDs are loaded
      ErrorParserExtensionManager.loadDefaultErrorParserIds();
      String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds();
      assertNotNull(defaultErrorParserIds);
      assertEquals(DEFAULT_IDS, ErrorParserManager.toDelimitedString(defaultErrorParserIds));
    }
  }
Exemplo n.º 11
0
  /**
   * Test setting/retrieval of default error parser IDs preferences.
   *
   * @throws Exception...
   */
  public void testDefaultErrorParserIds() throws Exception {
    final String[] availableParserIds = ErrorParserManager.getErrorParserAvailableIds();
    assertNotNull(availableParserIds);
    final String[] initialDefaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds();

    // preconditions
    {
      String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds();
      assertNotNull(defaultErrorParserIds);
      assertEquals(
          ErrorParserManager.toDelimitedString(availableParserIds),
          ErrorParserManager.toDelimitedString(defaultErrorParserIds));
    }
    // setDefaultErrorParserIds
    {
      String[] newDefaultErrorParserIds = {
        "org.eclipse.cdt.core.test.errorparser0",
        "org.eclipse.cdt.core.test.errorparser1",
        "org.eclipse.cdt.core.test.errorparser2",
      };
      ErrorParserManager.setDefaultErrorParserIds(newDefaultErrorParserIds);
      String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds();
      assertNotNull(defaultErrorParserIds);
      assertEquals(
          ErrorParserManager.toDelimitedString(newDefaultErrorParserIds),
          ErrorParserManager.toDelimitedString(defaultErrorParserIds));
    }

    // reset
    {
      ErrorParserManager.setDefaultErrorParserIds(null);
      String[] defaultErrorParserIds = ErrorParserManager.getDefaultErrorParserIds();
      assertNotNull(defaultErrorParserIds);
      assertEquals(
          ErrorParserManager.toDelimitedString(availableParserIds),
          ErrorParserManager.toDelimitedString(defaultErrorParserIds));
    }
  }
Exemplo n.º 12
0
  /**
   * Test setting/retrieval of user defined error parsers.
   *
   * @throws Exception...
   */
  public void testUserDefinedErrorParsers() throws Exception {
    final String TESTING_ID = "org.eclipse.cdt.core.test.errorparser";
    final String TESTING_NAME = "An error parser";
    // reset parsers
    {
      ErrorParserManager.setUserDefinedErrorParsers(null);
      String[] userDefinedIds = ErrorParserManager.getUserDefinedErrorParserIds();
      assertNull(userDefinedIds);

      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      String extensions =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserExtensionIds());
      assertEquals(all, extensions);
    }
    {
      ErrorParserManager.setUserDefinedErrorParsers(
          new IErrorParserNamed[] {
            new ErrorParserNamedWrapper(TESTING_ID, TESTING_NAME, new DummyErrorParser()),
          });
      String userDefinedIds =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getUserDefinedErrorParserIds());
      assertEquals(TESTING_ID, userDefinedIds);

      String all =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserAvailableIds());
      String extensions =
          ErrorParserManager.toDelimitedString(ErrorParserManager.getErrorParserExtensionIds());
      assertFalse(all.equals(extensions));
    }
  }
Exemplo n.º 13
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);
    }
  }