Skip to content
Permalink
Browse files

Support sbt-scalac

  • Loading branch information...
Trung Nguyen
Trung Nguyen committed Apr 10, 2017
1 parent 9a44d27 commit bc75205ca390a620897cab12e16cae52fb80cf2f
@@ -0,0 +1,48 @@
package se.bjurr.violations.lib.parsers;

import static java.lang.Integer.parseInt;
import static se.bjurr.violations.lib.model.SEVERITY.*;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getLines;
import static se.bjurr.violations.lib.reports.Reporter.SBTSCALAC;

import java.util.ArrayList;
import java.util.List;
import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;

public class SbtScalacParser implements ViolationsParser {

@Override
public List<Violation> parseReportOutput(String reportContent) throws Exception {
List<Violation> violations = new ArrayList<>();
List<List<String>> partsPerLine =
getLines(reportContent, "^\\[(warn|error)\\] (.*):(\\d+): (.*)$");
for (List<String> parts : partsPerLine) {
String severity = parts.get(1);
String fileName = parts.get(2);
Integer lineNumber = parseInt(parts.get(3));
String message = parts.get(4);
violations.add( //
violationBuilder() //
.setReporter(SBTSCALAC) //
.setStartLine(lineNumber) //
.setFile(fileName) //
.setSeverity(toSeverity(severity)) //
.setMessage(message) //
.build() //
);
}
return violations;
}

public SEVERITY toSeverity(String severity) {
if ("error".equals(severity)) {
return ERROR;
}
if ("warn".equals(severity)) {
return WARN;
}
return INFO;
}
}
@@ -32,6 +32,7 @@
import se.bjurr.violations.lib.parsers.PyDocStyleParser;
import se.bjurr.violations.lib.parsers.PyLintParser;
import se.bjurr.violations.lib.parsers.ResharperParser;
import se.bjurr.violations.lib.parsers.SbtScalacParser;
import se.bjurr.violations.lib.parsers.SimianParser;
import se.bjurr.violations.lib.parsers.StyleCopParser;
import se.bjurr.violations.lib.parsers.ViolationsParser;
@@ -64,6 +65,7 @@
PYDOCSTYLE(new PyDocStyleParser()), //
PYLINT(new PyLintParser()), //
RESHARPER(new ResharperParser()), //
SBTSCALAC(new SbtScalacParser()), //
SIMIAN(new SimianParser()), //
STYLECOP(new StyleCopParser()), //
XMLLINT(new XMLLintParser()), //
@@ -0,0 +1,67 @@
package se.bjurr.violations.lib;

import static org.assertj.core.api.Assertions.assertThat;
import static se.bjurr.violations.lib.TestUtils.getRootFolder;
import static se.bjurr.violations.lib.ViolationsReporterApi.violationsReporterApi;
import static se.bjurr.violations.lib.model.SEVERITY.*;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;
import static se.bjurr.violations.lib.reports.Reporter.SBTSCALAC;

import java.util.List;
import org.junit.Test;
import se.bjurr.violations.lib.model.Violation;

public class SbtScalacTest {

@Test
public void testThatViolationsCanBeParsed() {
String rootFolder = getRootFolder();

List<Violation> actual =
violationsReporterApi() //
.withPattern(".*/sbtscalac/sbtscalac\\.txt$") //
.inFolder(rootFolder) //
.findAll(SBTSCALAC) //
.violations();

assertThat(actual) //
.containsExactly( //
violationBuilder() //
.setReporter(SBTSCALAC) //
.setFile(
"/Users/johndoe/workspace/org/prj/prj-server/src/main/scala/org/prj/server/ProjectServerApp.scala") //
.setStartLine(19) //
.setMessage(
"object creation impossible, since value system in trait ProjectServers of type akka.actor.ActorSystem is not defined") //
.setSeverity(ERROR) //
.build(), //
violationBuilder() //
.setReporter(SBTSCALAC) //
.setFile(
"/Users/johndoe/workspace/org/prj/prj-server/src/main/scala/org/prj/server/authentication/AuthenticationServer.scala") //
.setStartLine(23) //
.setMessage(
"class AuthenticationServer needs to be abstract, since value scheduler in trait TokenAuthentication of type monix.execution.Scheduler is not defined") //
.setSeverity(ERROR) //
.build(), //
violationBuilder() //
.setReporter(SBTSCALAC) //
.setFile(
"/Users/johndoe/workspace/org/prj/prj-server/src/main/scala/org/prj/server/profile/UserProfileServer.scala") //
.setStartLine(28) //
.setMessage(
"class UserProfileServer needs to be abstract, since value scheduler in trait TokenAuthentication of type monix.execution.Scheduler is not defined") //
.setSeverity(ERROR) //
.build(), //
violationBuilder() //
.setReporter(SBTSCALAC) //
.setFile(
"/Users/johndoe/workspace/org/prj/prj-server/src/main/scala/org/prj/server/user/UserServer.scala") //
.setStartLine(29) //
.setMessage(
"class UserServer needs to be abstract, since value scheduler in trait TokenAuthentication of type monix.execution.Scheduler is not defined") //
.setSeverity(ERROR) //
.build() //
);
}
}
@@ -0,0 +1,19 @@
[info] Loading global plugins from /Users/johndoe/.sbt/0.13/plugins
[info] Loading project definition from /Users/johndoe/workspace/org/prj/prj
[info] Set current project to haru (in build file:/Users/johndoe/workspace/org/prj/)
[info] Compiling 8 Scala sources to /Users/johndoe/workspace/org/prj/prj-server/target/scala-2.12/classes...
[error] /Users/johndoe/workspace/org/prj/prj-server/src/main/scala/org/prj/server/ProjectServerApp.scala:19: object creation impossible, since value system in trait ProjectServers of type akka.actor.ActorSystem is not defined
[error] object ProjectServerApp extends App with ProjectServers {
[error] ^
[error] /Users/johndoe/workspace/org/prj/prj-server/src/main/scala/org/prj/server/authentication/AuthenticationServer.scala:23: class AuthenticationServer needs to be abstract, since value scheduler in trait TokenAuthentication of type monix.execution.Scheduler is not defined
[error] final class AuthenticationServer(
[error] ^
[error] /Users/johndoe/workspace/org/prj/prj-server/src/main/scala/org/prj/server/profile/UserProfileServer.scala:28: class UserProfileServer needs to be abstract, since value scheduler in trait TokenAuthentication of type monix.execution.Scheduler is not defined
[error] final class UserProfileServer(
[error] ^
[error] /Users/johndoe/workspace/org/prj/prj-server/src/main/scala/org/prj/server/user/UserServer.scala:29: class UserServer needs to be abstract, since value scheduler in trait TokenAuthentication of type monix.execution.Scheduler is not defined
[error] final class UserServer(
[error] ^
[error] four errors found
[error] (project-server/compile:compileIncremental) Compilation failed
[error] Total time: 5 s, completed Apr 10, 2017 1:30:34 PM

0 comments on commit bc75205

Please sign in to comment.
You can’t perform that action at this time.