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.plugins.gosu.cobertura.CoberturaReportParser.java
private static void collectFileData(SMInputCursor clazz, ParsingResult parsingResult) throws XMLStreamException { SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); while (line.getNext() != null) { int lineId = Integer.parseInt(line.getAttrValue("number")); boolean validLine = parsingResult.isValidLine(lineId); if (!validLine && parsingResult.fileExists()) { LOG.info("Hit on invalid line for file " + parsingResult.filename + " (line: " + lineId + "/" + parsingResult.inputFile.lines() + ")"); }/* ww w .j av a2 s . co m*/ try { int hits = (int) parseNumber(line.getAttrValue("hits"), ENGLISH); if (validLine) { parsingResult.coverage = parsingResult.coverage.lineHits(lineId, hits); } } catch (ParseException e) { throw MessageException.of("Unable to parse Cobertura report.", e); } String isBranch = line.getAttrValue("branch"); String text = line.getAttrValue("condition-coverage"); if (validLine && StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(text)) { String[] conditions = StringUtils.split(StringUtils.substringBetween(text, "(", ")"), "/"); parsingResult.coverage = parsingResult.coverage.conditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0])); } } }
From source file:org.sonar.plugins.gosu.codenarc.apt.AptParser.java
private static String getRuleName(String line) { if (StringUtils.isBlank(line)) { return null; }//www . ja va 2s . c o m String result = null; if (line.startsWith("* {")) { result = StringUtils.substringBetween(line, "* {", "} Rule").trim(); } else { result = line.substring(2).trim(); } if (result.endsWith("Rule")) { result = result.substring(0, result.length() - 4); } if (StringUtils.isAllLowerCase(result) || !StringUtils.isAlphanumeric(result) || "References".equals(result)) { // false positive return null; } return result; }
From source file:org.sonar.plugins.groovy.cobertura.CoberturaReportParser.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")); try {//from w w w. j a va 2 s . c om 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.plugins.javascript.coverage.CoberturaParser.java
private void collectFileData(SMInputCursor clazz, JavaScriptFileCoverage fileCoverage) throws XMLStreamException { SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); while (line.getNext() != null) { int lineId = Integer.parseInt(line.getAttrValue("number")); fileCoverage.addLine(lineId, Integer.parseInt(line.getAttrValue("hits"))); 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, "(", ")"), "/"); fileCoverage.addConditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0])); }/*from w w w. j a v a 2 s. c o m*/ } }
From source file:org.sonar.plugins.lua.cobertura.CoberturaReportParser.java
private static void collectFileData(SMInputCursor clazz, NewCoverage newCoverage) throws XMLStreamException { SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line"); while (line.getNext() != null) { int lineId = Integer.parseInt(line.getAttrValue("number")); try {/*from w w w .j a v a2s. co m*/ newCoverage.lineHits(lineId, (int) ParsingUtils.parseNumber(line.getAttrValue("hits"), Locale.ENGLISH)); } catch (ParseException e) { throw new IllegalStateException(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, "(", ")"), "/"); newCoverage.conditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0])); } } newCoverage.save(); }
From source file:org.sonar.plugins.objectivec.coverage.CoberturaXMLStreamHandler.java
private void recordCoverageFor(final SMInputCursor line, final CoverageMeasuresBuilder builder) throws XMLStreamException { final int lineId = Integer.parseInt(line.getAttrValue("number")); final int noHits = (int) Math.min(Long.parseLong(line.getAttrValue("hits")), Integer.MAX_VALUE); final String isBranch = line.getAttrValue("branch"); final String conditionText = line.getAttrValue("condition-coverage"); builder.setHits(lineId, noHits);/* w w w . j av a 2 s .c om*/ if (StringUtils.equals(isBranch, "true") && StringUtils.isNotBlank(conditionText)) { final String[] conditions = StringUtils.split(StringUtils.substringBetween(conditionText, "(", ")"), "/"); builder.setConditions(lineId, Integer.parseInt(conditions[1]), Integer.parseInt(conditions[0])); } }
From source file:org.sonar.plugins.python.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")); builder.setHits(lineId, Integer.parseInt(line.getAttrValue("hits"))); 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])); }/* ww w.java2 s . co m*/ } }
From source file:org.sonar.plugins.switchoffviolations.pattern.PatternDecoder.java
public static void decodeRangeOfLines(Pattern pattern, String field) { if (StringUtils.equals(field, "*")) { pattern.setCheckLines(false);/*from w w w . j av a 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.plugins.switchoffviolations.PatternDecoder.java
void decodeRangeOfLines(Pattern pattern, String field) { if (StringUtils.equals(field, "*")) { pattern.setCheckLines(false);// w ww . j ava 2s .c o 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.scanner.issue.ignore.pattern.PatternDecoder.java
public static Set<LineRange> decodeRangeOfLines(String field) { if (StringUtils.equals(field, "*")) { return Collections.emptySet(); } else {//from www . j av a2 s . co m Set<LineRange> lineRanges = new HashSet<>(); 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, '-'); lineRanges.add(new LineRange(Integer.valueOf(range[0]), Integer.valueOf(range[1]))); } else { lineRanges.add(new LineRange(Integer.valueOf(part), Integer.valueOf(part))); } } return lineRanges; } }