-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c058b8
commit 0f3c4e9
Showing
8 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/se/bjurr/violations/lib/parsers/KotlinGradleParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package se.bjurr.violations.lib.parsers; | ||
|
||
import static java.lang.Integer.parseInt; | ||
import static se.bjurr.violations.lib.model.SEVERITY.ERROR; | ||
import static se.bjurr.violations.lib.model.SEVERITY.INFO; | ||
import static se.bjurr.violations.lib.model.SEVERITY.WARN; | ||
import static se.bjurr.violations.lib.model.Violation.violationBuilder; | ||
import static se.bjurr.violations.lib.reports.Parser.KOTLINGRADLE; | ||
import static se.bjurr.violations.lib.util.Utils.isNullOrEmpty; | ||
import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import se.bjurr.violations.lib.model.SEVERITY; | ||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
public class KotlinGradleParser implements ViolationsParser { | ||
@Override | ||
public List<Violation> parseReportOutput(final String string) throws Exception { | ||
List<Violation> violations = new ArrayList<>(); | ||
List<String> lines = getLines(string); | ||
for (String lineString : lines) { | ||
List<List<String>> partsPerLine = new ArrayList<>(); | ||
for (List<String> parts : partsPerLine) { | ||
String filename = parts.get(1).trim(); | ||
Integer line = parseInt(parts.get(2)); | ||
Integer column = parseInt(parts.get(3)); | ||
String severity = parts.get(4).trim(); | ||
String message = parts.get(5).trim(); | ||
String rule = null; | ||
if (!isNullOrEmpty(parts.get(7))) { | ||
rule = parts.get(7).trim(); | ||
} | ||
violations.add( // | ||
violationBuilder() // | ||
.setParser(KOTLINGRADLE) // | ||
.setStartLine(line) // | ||
.setColumn(column) // | ||
.setFile(filename) // | ||
.setSeverity(toSeverity(severity)) // | ||
.setMessage(message) // | ||
.setRule(rule) // | ||
.build() // | ||
); | ||
} | ||
} | ||
return violations; | ||
} | ||
|
||
public SEVERITY toSeverity(final String severity) { | ||
if (severity.equalsIgnoreCase("error")) { | ||
return ERROR; | ||
} | ||
if (severity.equalsIgnoreCase("warning")) { | ||
return WARN; | ||
} | ||
return INFO; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/se/bjurr/violations/lib/parsers/KotlinMavenParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package se.bjurr.violations.lib.parsers; | ||
|
||
import static java.lang.Integer.parseInt; | ||
import static se.bjurr.violations.lib.model.SEVERITY.ERROR; | ||
import static se.bjurr.violations.lib.model.SEVERITY.INFO; | ||
import static se.bjurr.violations.lib.model.SEVERITY.WARN; | ||
import static se.bjurr.violations.lib.model.Violation.violationBuilder; | ||
import static se.bjurr.violations.lib.reports.Parser.KOTLINMAVEN; | ||
import static se.bjurr.violations.lib.util.Utils.isNullOrEmpty; | ||
import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import se.bjurr.violations.lib.model.SEVERITY; | ||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
public class KotlinMavenParser implements ViolationsParser { | ||
@Override | ||
public List<Violation> parseReportOutput(final String string) throws Exception { | ||
List<Violation> violations = new ArrayList<>(); | ||
List<String> lines = getLines(string); | ||
for (String lineString : lines) { | ||
List<List<String>> partsPerLine = new ArrayList<>(); | ||
for (List<String> parts : partsPerLine) { | ||
String filename = parts.get(1).trim(); | ||
Integer line = parseInt(parts.get(2)); | ||
Integer column = parseInt(parts.get(3)); | ||
String severity = parts.get(4).trim(); | ||
String message = parts.get(5).trim(); | ||
String rule = null; | ||
if (!isNullOrEmpty(parts.get(7))) { | ||
rule = parts.get(7).trim(); | ||
} | ||
violations.add( // | ||
violationBuilder() // | ||
.setParser(KOTLINMAVEN) // | ||
.setStartLine(line) // | ||
.setColumn(column) // | ||
.setFile(filename) // | ||
.setSeverity(toSeverity(severity)) // | ||
.setMessage(message) // | ||
.setRule(rule) // | ||
.build() // | ||
); | ||
} | ||
} | ||
return violations; | ||
} | ||
|
||
public SEVERITY toSeverity(final String severity) { | ||
if (severity.equalsIgnoreCase("error")) { | ||
return ERROR; | ||
} | ||
if (severity.equalsIgnoreCase("warning")) { | ||
return WARN; | ||
} | ||
return INFO; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/test/java/se/bjurr/violations/lib/KotlinGradleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package se.bjurr.violations.lib; | ||
|
||
import static se.bjurr.violations.lib.TestUtils.getRootFolder; | ||
|
||
import org.junit.Test; | ||
|
||
public class KotlinGradleTest { | ||
|
||
@Test | ||
public void testThatViolationsCanBeParsedGradle() { | ||
final String rootFolder = getRootFolder(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/java/se/bjurr/violations/lib/KotlinMavenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package se.bjurr.violations.lib; | ||
|
||
import static se.bjurr.violations.lib.TestUtils.getRootFolder; | ||
|
||
import org.junit.Test; | ||
|
||
public class KotlinMavenTest { | ||
|
||
@Test | ||
public void testThatViolationsCanBeParsedGradle() { | ||
final String rootFolder = getRootFolder(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
w: /Users/scottkennedy/project/src/main/java/com/example/Test.kt: (13, 87): Elvis operator (?:) always returns the left operand of non-nullable type String | ||
w: /Users/wolfs/projects/gradle/build-tool-release/buildSrc/subprojects/configuration/src/main/kotlin/org/gradle/gradlebuild/dependencies/DependenciesMetadataRulesPlugin.kt: (75, 54): Unchecked cast: Any? to List<CapabilitySpec> | ||
w: /home/bjerre/workspace/yet-another-kotlin-vs-java-comparison/src/main/kotlin/basics/controliiiflow/p01assigniiifromiiiif/Example.kt: (17, 9): Variable 'hejsan' is never used |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/home/kocka/sources/kerub/src/test/kotlin/com/github/K0zka/kerub/host/ControllerManagerImplTest.kt | ||
Warning:(34, 9) Kotlin: Variable 'controllerDynamic' is never used | ||
/home/kocka/sources/kerub/src/test/kotlin/com/github/K0zka/kerub/host/HostCapabilitiesDiscovererTest.kt | ||
Warning:(98, 45) Kotlin: Elvis operator (?:) always returns the left operand of non-nullable type kotlin.Long | ||
Warning:(98, 53) Kotlin: Unnecessary safe call on a non-null receiver of type kotlin.String | ||
Warning:(98, 63) Kotlin: Unnecessary safe call on a non-null receiver of type kotlin.Int | ||
Warning:(153, 42) Kotlin: This syntax for lambda is deprecated. Use short lambda notation {a[: Int], b[: String] -> ...} or function expression instead. | ||
Warning:(175, 7) Kotlin: Variable 'host' is never used | ||
Warning:(181, 48) Kotlin: Unnecessary non-null assertion (!!) on a non-null receiver of type com.github.K0zka.kerub.host.HostCapabilitiesDiscoverer | ||
Warning:(183, 40) Kotlin: Unnecessary safe call on a non-null receiver of type com.github.K0zka.kerub.model.HostCapabilities | ||
Warning:(184, 45) Kotlin: Unnecessary safe call on a non-null receiver of type com.github.K0zka.kerub.model.HostCapabilities | ||
/home/kocka/sources/kerub/src/test/kotlin/com/github/K0zka/kerub/host/SshClientUtilsTest.kt | ||
Warning:(54, 37) Kotlin: This syntax for lambda is deprecated. Use short lambda notation {a[: Int], b[: String] -> ...} or function expression instead. | ||
Warning:(64, 33) Kotlin: This syntax for lambda is deprecated. Use short lambda notation {a[: Int], b[: String] -> ...} or function expression instead. | ||
/home/kocka/sources/kerub/src/test/kotlin/com/github/K0zka/kerub/hypervisor/kvm/UtilsTest.kt | ||
Warning:(25, 7) Kotlin: Variable 'dom' is never used | ||
/home/kocka/sources/kerub/src/test/kotlin/com/github/K0zka/kerub/utils/junix/dmi/DmiDecoderTest.kt | ||
Warning:(127, 7) Kotlin: Variable 'devices' is never used |