Skip to content

Commit

Permalink
Remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
miklein committed Jan 14, 2015
1 parent eb70a3c commit cd99412
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
/*
* SonarQube Cobertura Plugin
*/
package org.sonar.plugins.scala.cobertura;

import static java.util.Locale.ENGLISH;
Expand All @@ -28,7 +31,6 @@

import javax.xml.stream.XMLStreamException;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.codehaus.staxmate.in.SMHierarchicCursor;
import org.codehaus.staxmate.in.SMInputCursor;
Expand All @@ -47,7 +49,7 @@

public class ScalaCoberturaReportParser {

private static final Logger LOG = LoggerFactory.getLogger(ScalaCoberturaReportParser.class);
private static final Logger LOG = LoggerFactory.getLogger(ScalaCoberturaReportParser.class);
private final SensorContext context;
private FileSystem fileSystem;

Expand All @@ -58,7 +60,7 @@ private ScalaCoberturaReportParser(SensorContext context, FileSystem fileSystem)

/**
* Parse a Cobertura xml report and create measures accordingly
* @param fileSystem
* @param fileSystem
*/
public static void parseReport(File xmlFile, SensorContext context, FileSystem fileSystem) {
new ScalaCoberturaReportParser(context, fileSystem).parse(xmlFile);
Expand All @@ -84,11 +86,8 @@ private void collectPackageMeasures(SMInputCursor pack) throws XMLStreamExceptio
Map<String, CoverageMeasuresBuilder> builderByFilename = Maps.newHashMap();
collectFileMeasures(pack.descendantElementCursor("class"), builderByFilename);
for (Map.Entry<String, CoverageMeasuresBuilder> entry : builderByFilename.entrySet()) {
String className = sanitizeFilename(entry.getKey());
String filename = className.replace('.', '/') + ".scala";
FilePredicates filePredicates = fileSystem.predicates();

InputFile resource = fileSystem.inputFile(filePredicates.matchesPathPattern("**/*" + filename));
InputFile resource = fileSystem.inputFile(filePredicates.matchesPathPattern("**/*" + entry.getKey()));
if (resource != null){
for (Measure measure : entry.getValue().createMeasures()) {
context.saveMeasure(resource, measure);
Expand Down Expand Up @@ -131,10 +130,4 @@ private void collectFileData(SMInputCursor clazz, CoverageMeasuresBuilder builde
}
}

private static String sanitizeFilename(String s) {
String fileName = FilenameUtils.removeExtension(s);
fileName = fileName.replace('/', '.').replace('\\', '.');
return fileName;
}

}

0 comments on commit cd99412

Please sign in to comment.