Example usage for org.apache.commons.lang StringUtils remove

List of usage examples for org.apache.commons.lang StringUtils remove

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils remove.

Prototype

public static String remove(String str, char remove) 

Source Link

Document

Removes all occurrences of a character from within the source string.

Usage

From source file:org.sonar.plugins.checkstyle.CheckstyleProfileExporterTest.java

private static String sanitizeForTests(String xml) {
    // remove the doctype declaration, else the unit test fails when executed offline
    return StringUtils.remove(xml, CheckstyleProfileExporter.DOCTYPE_DECLARATION);
}

From source file:org.sonar.plugins.core.issue.notification.IssueChangesEmailTemplateTest.java

@Test
public void test_email_with_changes() {
    Notification notification = new Notification("issue-changes").setFieldValue("projectName", "Struts")
            .setFieldValue("projectKey", "org.apache:struts")
            .setFieldValue("componentName", "org.apache.struts.Action").setFieldValue("key", "ABCDE")
            .setFieldValue("ruleName", "Avoid Cycles").setFieldValue("message", "Has 3 cycles")
            .setFieldValue("comment", "How to fix it?").setFieldValue("old.assignee", "simon")
            .setFieldValue("new.assignee", "louis").setFieldValue("new.resolution", "FALSE-POSITIVE")
            .setFieldValue("new.status", "RESOLVED");

    EmailMessage email = template.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");

    String message = email.getMessage();
    String expectedMessage = TestUtils.getResourceContent(
            "/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_changes.txt");
    expectedMessage = StringUtils.remove(expectedMessage, '\r');
    assertThat(message).isEqualTo(expectedMessage);
    assertThat(email.getFrom()).isNull();
}

From source file:org.sonar.plugins.csharp.gallio.results.execution.model.TestCaseDetail.java

public String getFormatedErrorMessage() {
    return StringEscapeUtils.escapeXml(StringUtils.remove(errorMessage, "\n\t"));
}

From source file:org.sonar.plugins.flex.cpd.FlexCpdMavenSensor.java

String removeCDataNodes(String xml) {
    String result = xml;//from w w  w. j a v  a2 s .com
    String startNode = "<codefragment>";
    String endNode = "</codefragment>";
    String[] subs = StringUtils.substringsBetween(xml, startNode, endNode);
    if (subs != null) {
        for (String sub : subs) {
            result = StringUtils.remove(result, startNode + sub + endNode);
        }
    }
    return result;
}

From source file:org.sonar.plugins.groovy.codenarc.Converter.java

private void rule(Class<? extends AbstractRule> ruleClass, String since) throws Exception {
    if (duplications.contains(ruleClass)) {
        System.out.println("Duplicated rule " + ruleClass.getName());
    } else {/*from   w  ww.j  a  v a  2 s  .c  o  m*/
        duplications.add(ruleClass);
    }
    AbstractRule rule = ruleClass.newInstance();
    String key = ruleClass.getCanonicalName();
    String configKey = StringUtils.removeEnd(ruleClass.getSimpleName(), "Rule");
    String name = StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(configKey), ' ');
    String priorityStr = priority(rule.getPriority());
    String description = props.getProperty(configKey + ".description.html");

    SortedSet<String> params = new TreeSet<String>();

    // extract params
    String[] params1 = StringUtils.substringsBetween(description, "${", "}");
    if (params1 != null) {
        for (String param : params1) {
            description = StringUtils.remove(description, " (${" + param + "})");
            param = StringUtils.removeStart(param, "rule.");
            params.add(param);
        }
    }

    String[] params2 = StringUtils.substringsBetween(description, "<em>", "</em> property");
    if (params2 != null) {
        params.addAll(Arrays.asList(params2));
    }

    String[] params3 = StringUtils.substringsBetween(description, "configured in <em>", "</em>");
    if (params3 != null) {
        params.addAll(Arrays.asList(params3));
    }

    if (StringUtils.contains(description, "length property")) {
        params.add("length");
    }
    if (StringUtils.contains(description, "sameLine property")) {
        params.add("sameLine");
    }

    // output
    if (since != null) {
        out.println("  <!-- since " + since + " -->");
    }
    out.println("  <rule key=\"" + key + "\"" + " priority=\"" + priorityStr + "\">");
    out.println("    <name><![CDATA[" + name + "]]></name>");
    out.println("    <configKey><![CDATA[" + configKey + "]]></configKey>");
    out.println("    <description><![CDATA[" + description + "]]></description>");

    if (params != null) {
        for (String param : params) {
            out.println("    <param key=\"" + param + "\"/>");
        }
    }

    out.println("  </rule>");
    out.println();
    count++;
}

From source file:org.sonar.plugins.php.codesniffer.PhpCodeSnifferProfileExporterTest.java

@Test
public void testExportComplexProfile() throws IOException, SAXException {
    ServerFileSystem fileSystem = mock(ServerFileSystem.class);
    PhpCodeSnifferRuleRepository repository = new PhpCodeSnifferRuleRepository(fileSystem, new XMLRuleParser());
    List<Rule> rules = repository.createRules();

    RuleFinder ruleFinder = new MockPhpCodeSnifferRuleFinder(rules);
    PhpCodeSnifferProfileImporter importer = new PhpCodeSnifferProfileImporter(ruleFinder, mapper);
    Reader reader = new StringReader(
            TestUtils.getResourceContent("/org/sonar/plugins/php/codesniffer/complex-ruleset.xml"));
    RulesProfile rulesProfile = importer.importProfile(reader, ValidationMessages.create());

    StringWriter xmlOutput = new StringWriter();
    exporter.exportProfile(rulesProfile, xmlOutput);
    String expected = StringUtils.remove(
            TestUtils.getResourceContent("/org/sonar/plugins/php/codesniffer/complex-export.xml"), '\r');
    String filteredOuput = StringUtils.remove(xmlOutput.toString(), '\r');
    assertThat(filteredOuput).isEqualTo(expected);
}

From source file:org.sonar.plugins.php.codesniffer.PhpCodeSnifferProfileExporterTest.java

@Test
public void testExportProfile() throws IOException, SAXException {
    ServerFileSystem fileSystem = mock(ServerFileSystem.class);
    PhpCodeSnifferRuleRepository repository = new PhpCodeSnifferRuleRepository(fileSystem, new XMLRuleParser());
    List<Rule> rules = repository.createRules();

    RuleFinder ruleFinder = new MockPhpCodeSnifferRuleFinder(rules);
    PhpCodeSnifferProfileImporter importer = new PhpCodeSnifferProfileImporter(ruleFinder, mapper);
    Reader reader = new StringReader(
            TestUtils.getResourceContent("/org/sonar/plugins/php/codesniffer/simple-ruleset.xml"));
    RulesProfile rulesProfile = importer.importProfile(reader, ValidationMessages.create());

    StringWriter xmlOutput = new StringWriter();
    exporter.exportProfile(rulesProfile, xmlOutput);
    String expected = StringUtils
            .remove(TestUtils.getResourceContent("/org/sonar/plugins/php/codesniffer/simple-export.xml"), '\r');
    String filteredOuput = StringUtils.remove(xmlOutput.toString(), '\r');
    assertThat(filteredOuput).isEqualTo(expected);
}

From source file:org.sonar.plugins.php.pmd.PhpmdProfileExporterTest.java

@Test
public void testExportProfileWithParam() throws IOException, SAXException {
    ServerFileSystem fileSystem = mock(ServerFileSystem.class);
    PhpmdRuleRepository repository = new PhpmdRuleRepository(fileSystem, new XMLRuleParser());
    List<Rule> rules = repository.createRules();

    RuleFinder ruleFinder = new PhpmdRuleFinder(rules);
    PhpmdProfileImporter importer = new PhpmdProfileImporter(ruleFinder);
    String path = "/org/sonar/plugins/php/pmd/simple-ruleset-with-param.xml";
    Reader reader = new StringReader(TestUtils.getResourceContent(path));
    ValidationMessages messages = ValidationMessages.create();
    RulesProfile rulesProfile = importer.importProfile(reader, messages);
    assertThat(messages).isNotNull();// w  w w  .  j  av a 2 s  .c  o  m
    assertThat(messages.hasErrors()).isFalse();
    assertThat(messages.hasWarnings()).isFalse();
    assertThat(messages.hasWarnings()).isFalse();

    StringWriter xmlOutput = new StringWriter();
    exporter.exportProfile(rulesProfile, xmlOutput);
    String exptected = TestUtils.getResourceContent("/org/sonar/plugins/php/pmd/simple-export-with-param.xml");
    assertEquals(StringUtils.remove(exptected, '\r'), StringUtils.remove(xmlOutput.toString(), '\r'));

}

From source file:org.sonar.plugins.php.pmd.PhpmdProfileExporterTest.java

@Test
public void testExportProfile() throws IOException, SAXException {
    ServerFileSystem fileSystem = mock(ServerFileSystem.class);
    PhpmdRuleRepository repository = new PhpmdRuleRepository(fileSystem, new XMLRuleParser());
    List<Rule> rules = repository.createRules();

    RuleFinder ruleFinder = new PhpmdRuleFinder(rules);
    PhpmdProfileImporter importer = new PhpmdProfileImporter(ruleFinder);
    Reader reader = new StringReader(
            TestUtils.getResourceContent("/org/sonar/plugins/php/pmd/simple-ruleset.xml"));
    ValidationMessages messages = ValidationMessages.create();
    RulesProfile rulesProfile = importer.importProfile(reader, messages);
    assertThat(messages).isNotNull();/* w w w. j a v a2 s.  com*/
    assertThat(messages.hasErrors()).isFalse();
    assertThat(messages.hasWarnings()).isTrue();
    assertThat(messages.hasInfos()).isFalse();

    StringWriter xmlOutput = new StringWriter();
    exporter.exportProfile(rulesProfile, xmlOutput);
    String exptected = TestUtils.getResourceContent("/org/sonar/plugins/php/pmd/simple-export.xml");
    assertEquals(StringUtils.remove(exptected, '\r'), StringUtils.remove(xmlOutput.toString(), '\r'));

}

From source file:org.sonar.plugins.pmd.PmdProfileExporterTest.java

@Test
public void testExportProfile() throws IOException, SAXException {
    ServerFileSystem fileSystem = mock(ServerFileSystem.class);
    PmdRuleRepository repository = new PmdRuleRepository(fileSystem, new XMLRuleParser());
    List<Rule> rules = repository.createRules();

    RuleFinder ruleFinder = new FakeRuleFinder(rules);
    PmdProfileImporter importer = new PmdProfileImporter(ruleFinder);
    Reader reader = new StringReader(TestUtils.getResourceContent("/org/sonar/plugins/pmd/simple.xml"));
    RulesProfile rulesProfile = importer.importProfile(reader, ValidationMessages.create());

    StringWriter xmlOutput = new StringWriter();
    exporter.exportProfile(rulesProfile, xmlOutput);
    assertEquals(TestUtils.getResourceContent("/org/sonar/plugins/pmd/export_simple.xml"),
            StringUtils.remove(xmlOutput.toString(), '\r'));
}