List of usage examples for org.apache.commons.lang StringUtils substringBetween
public static String substringBetween(String str, String open, String close)
Gets the String that is nested in between two Strings.
From source file:org.sonar.api.server.rule.RuleParamType.java
public static RuleParamType parse(String s) { // deprecated formats if ("i".equals(s) || "i{}".equals(s)) { return INTEGER; }/* w w w . j a v a 2s .com*/ if ("s".equals(s) || "s{}".equals(s) || "r".equals(s) || "REGULAR_EXPRESSION".equals(s)) { return STRING; } if ("b".equals(s)) { return BOOLEAN; } if (s.startsWith("s[")) { String values = StringUtils.substringBetween(s, "[", "]"); return multipleListOfValues(StringUtils.split(values, ',')); } // standard format String format = StringUtils.substringBefore(s, OPTION_SEPARATOR); String values = null; boolean multiple = false; String[] options = s.split(CSV_SPLIT_REGEX); for (String option : options) { String opt = StringEscapeUtils.unescapeCsv(option); if (opt.startsWith(VALUES_PARAM + PARAMETER_SEPARATOR)) { values = StringEscapeUtils .unescapeCsv(StringUtils.substringAfter(opt, VALUES_PARAM + PARAMETER_SEPARATOR)); } else if (opt.startsWith(MULTIPLE_PARAM + PARAMETER_SEPARATOR)) { multiple = Boolean .parseBoolean(StringUtils.substringAfter(opt, MULTIPLE_PARAM + PARAMETER_SEPARATOR)); } } if (values == null || StringUtils.isBlank(values)) { return new RuleParamType(format); } return new RuleParamType(format, multiple, values.split(CSV_SPLIT_REGEX)); }
From source file:org.sonar.api.utils.CoberturaReportParserUtils.java
private static void collectFileData(SMInputCursor clazz, CoverageMeasuresBuilder builder) throws XMLStreamException { SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); while (line.getNext() != null) { int lineId = Integer.parseInt(line.getAttrValue("number")); try {/*from ww w . j av a 2s . c o m*/ builder.setHits(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH)); } catch (ParseException e) { throw new XmlParserException(e); } String isBranch = line.getAttrValue("branch"); String text = line.getAttrValue("condition-coverage"); if (StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) { String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/"); builder.setConditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0])); } } }
From source file:org.sonar.batch.issue.ignore.pattern.PatternDecoder.java
public static void decodeRangeOfLines(IssuePattern pattern, String field) { if (StringUtils.equals(field, "*")) { pattern.setCheckLines(false);//from w w w . ja va 2 s. co m } else { pattern.setCheckLines(true); String s = StringUtils.substringBetween(StringUtils.trim(field), "[", "]"); String[] parts = StringUtils.split(s, ','); for (String part : parts) { if (StringUtils.contains(part, '-')) { String[] range = StringUtils.split(part, '-'); pattern.addLineRange(Integer.valueOf(range[0]), Integer.valueOf(range[1])); } else { pattern.addLine(Integer.valueOf(part)); } } } }
From source file:org.sonar.core.i18n.RuleI18nManager.java
static RuleKey extractRuleKey(String propertyKey) { String s = StringUtils.substringBetween(propertyKey, RULE_PREFIX, NAME_SUFFIX); String ruleKey = StringUtils.substringAfter(s, "."); String repository = StringUtils.substringBefore(s, "."); return new RuleKey(repository, ruleKey); }
From source file:org.sonar.java.checks.verifier.CheckVerifier.java
protected void collectExpectedIssues(String comment, int line) { String expectedStart = getExpectedIssueTrigger(); if (comment.startsWith(expectedStart)) { String cleanedComment = StringUtils.remove(comment, expectedStart); EnumMap<IssueAttribute, String> attr = new EnumMap<>(IssueAttribute.class); String expectedMessage = StringUtils.substringBetween(cleanedComment, "{{", "}}"); if (StringUtils.isNotEmpty(expectedMessage)) { attr.put(IssueAttribute.MESSAGE, expectedMessage); }//from w w w . j a v a2s.c om int expectedLine = line; String attributesSubstr = extractAttributes(comment, attr); cleanedComment = StringUtils .stripEnd(StringUtils.remove(StringUtils.remove(cleanedComment, "[[" + attributesSubstr + "]]"), "{{" + expectedMessage + "}}"), " \t"); if (StringUtils.startsWith(cleanedComment, "@")) { final int lineAdjustment; final char firstChar = cleanedComment.charAt(1); final int endIndex = cleanedComment.indexOf(' '); if (endIndex == -1) { lineAdjustment = Integer.parseInt(cleanedComment.substring(2)); } else { lineAdjustment = Integer.parseInt(cleanedComment.substring(2, endIndex)); } if (firstChar == '+') { expectedLine += lineAdjustment; } else if (firstChar == '-') { expectedLine -= lineAdjustment; } else { Fail.fail("Use only '@+N' or '@-N' to shifts messages."); } } updateEndLine(expectedLine, attr); expected.put(expectedLine, attr); } }
From source file:org.sonar.java.checks.verifier.CheckVerifier.java
private static String extractAttributes(String comment, Map<IssueAttribute, String> attr) { String attributesSubstr = StringUtils.substringBetween(comment, "[[", "]]"); if (!StringUtils.isEmpty(attributesSubstr)) { Iterable<String> attributes = Splitter.on(";").split(attributesSubstr); for (String attribute : attributes) { String[] split = StringUtils.split(attribute, '='); if (split.length == 2 && CheckVerifier.ATTRIBUTE_MAP.containsKey(split[0])) { attr.put(CheckVerifier.ATTRIBUTE_MAP.get(split[0]), split[1]); } else { Fail.fail("// Noncompliant attributes not valid: " + attributesSubstr); }/* ww w . j a v a 2s .c o m*/ } } return attributesSubstr; }
From source file:org.sonar.plsqlopen.checks.verifier.PlSqlCheckVerifier.java
private static String extractAttributes(String comment, Map<IssueAttribute, String> attr) { String attributesSubstr = StringUtils.substringBetween(comment, "[[", "]]"); if (!StringUtils.isEmpty(attributesSubstr)) { Iterable<String> attributes = Splitter.on(";").split(attributesSubstr); for (String attribute : attributes) { String[] split = StringUtils.split(attribute, '='); if (split.length == 2 && PlSqlCheckVerifier.ATTRIBUTE_MAP.containsKey(split[0])) { attr.put(PlSqlCheckVerifier.ATTRIBUTE_MAP.get(split[0]), split[1]); } else { Fail.fail("// Noncompliant attributes not valid: " + attributesSubstr); }//from w w w . j ava 2 s . com } } return attributesSubstr; }
From source file:org.sonar.plugins.cobertura.api.AbstractCoberturaParser.java
private void collectFileData(SMInputCursor clazz, FileData data) throws ParseException, XMLStreamException { SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); while (line.getNext() != null) { String lineId = line.getAttrValue("number"); data.addLine(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH)); String isBranch = line.getAttrValue("branch"); String text = line.getAttrValue("condition-coverage"); if (StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) { String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/"); data.addConditionLine(lineId, Integer.parseInt(conditions[0]), Integer.parseInt(conditions[1]), StringUtils.substringBefore(text, " ")); }/* w ww .ja v a 2 s . com*/ } }
From source file:org.sonar.plugins.cxx.coverage.CoberturaParser.java
private void collectFileData(SMInputCursor clazz, CoverageMeasuresBuilder builder) throws XMLStreamException { SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); while (line.getNext() != null) { int lineId = Integer.parseInt(line.getAttrValue("number")); long noHits = Long.parseLong(line.getAttrValue("hits")); if (noHits > Integer.MAX_VALUE) { CxxUtils.LOG.warn(/* w w w . j ava2 s . c o m*/ "Truncating the actual number of hits ({}) to the maximum number supported by Sonar ({})", noHits, Integer.MAX_VALUE); noHits = Integer.MAX_VALUE; } builder.setHits(lineId, (int) noHits); String isBranch = line.getAttrValue("branch"); String text = line.getAttrValue("condition-coverage"); if (StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) { String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/"); builder.setConditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0])); } } }
From source file:org.sonar.plugins.cxx.gcovr.CxxGcovrSensor.java
private void collectFileData(SMInputCursor clazz, FileData data) throws ParseException, XMLStreamException { logger.debug("collectFileData"); SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); while (line.getNext() != null) { String lineId = line.getAttrValue("number"); data.addLine(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH)); String isBranch = line.getAttrValue("branch"); String text = line.getAttrValue("condition-coverage"); if (StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) { String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/"); data.addConditionLine(lineId, Integer.parseInt(conditions[0]), Integer.parseInt(conditions[1]), StringUtils.substringBefore(text, " ")); }//from w w w . j a v a 2 s .com } }