-
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 59daadf
Showing
9 changed files
with
249 additions
and
8 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
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
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.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<List<String>> partsPerLine = | ||
getLines(string, "([^:])+?:([^:]*)[^\\d]+?(\\d+?)[^\\d]+?(\\d+?)[^:]+?:(.*)"); | ||
for (List<String> parts : partsPerLine) { | ||
String severity = parts.get(1).trim(); | ||
String filename = parts.get(2).trim(); | ||
Integer line = parseInt(parts.get(3)); | ||
Integer column = parseInt(parts.get(4)); | ||
String message = parts.get(5).trim(); | ||
violations.add( // | ||
violationBuilder() // | ||
.setParser(KOTLINGRADLE) // | ||
.setStartLine(line) // | ||
.setColumn(column) // | ||
.setFile(filename) // | ||
.setSeverity(toSeverity(severity)) // | ||
.setMessage(message) // | ||
.build() // | ||
); | ||
} | ||
return violations; | ||
} | ||
|
||
public SEVERITY toSeverity(final String severity) { | ||
if (severity.equalsIgnoreCase("e")) { | ||
return ERROR; | ||
} | ||
if (severity.equalsIgnoreCase("w")) { | ||
return WARN; | ||
} | ||
return INFO; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
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.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<List<String>> partsPerLine = | ||
getLines(string, "\\[([^\\]]+?)\\]([^:]*)[^\\d]+?(\\d+?)[^\\d]+?(\\d+?)[^\\)]+?\\)(.*)"); | ||
for (List<String> parts : partsPerLine) { | ||
String severity = parts.get(1).trim(); | ||
String filename = parts.get(2).trim(); | ||
Integer line = parseInt(parts.get(3)); | ||
Integer column = parseInt(parts.get(4)); | ||
String message = parts.get(5).trim(); | ||
violations.add( // | ||
violationBuilder() // | ||
.setParser(KOTLINMAVEN) // | ||
.setStartLine(line) // | ||
.setColumn(column) // | ||
.setFile(filename) // | ||
.setSeverity(toSeverity(severity)) // | ||
.setMessage(message) // | ||
.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
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
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
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.ViolationsApi.violationsApi; | ||
import static se.bjurr.violations.lib.model.SEVERITY.WARN; | ||
import static se.bjurr.violations.lib.reports.Parser.KOTLINGRADLE; | ||
|
||
import java.util.List; | ||
import org.junit.Test; | ||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
public class KotlinGradleTest { | ||
|
||
@Test | ||
public void testThatViolationsCanBeParsed() { | ||
final String rootFolder = getRootFolder(); | ||
|
||
final List<Violation> actual = | ||
violationsApi() // | ||
.withPattern(".*/kotlingradle/.*\\.txt") // | ||
.inFolder(rootFolder) // | ||
.findAll(KOTLINGRADLE) // | ||
.violations(); | ||
|
||
assertThat(actual) // | ||
.hasSize(3); | ||
|
||
final Violation violation0 = actual.get(0); | ||
assertThat(violation0.getMessage()) // | ||
.isEqualTo( | ||
"Elvis operator (?:) always returns the left operand of non-nullable type String"); | ||
assertThat(violation0.getFile()) // | ||
.isEqualTo("/Users/scottkennedy/project/src/main/java/com/example/Test.kt"); | ||
assertThat(violation0.getSeverity()) // | ||
.isEqualTo(WARN); | ||
assertThat(violation0.getRule()) // | ||
.isEqualTo(""); | ||
assertThat(violation0.getParser()) // | ||
.isEqualTo(KOTLINGRADLE); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
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.ViolationsApi.violationsApi; | ||
import static se.bjurr.violations.lib.model.SEVERITY.WARN; | ||
import static se.bjurr.violations.lib.reports.Parser.KOTLINMAVEN; | ||
|
||
import java.util.List; | ||
import org.junit.Test; | ||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
public class KotlinMavenTest { | ||
|
||
@Test | ||
public void testThatViolationsCanBeParsed() { | ||
final String rootFolder = getRootFolder(); | ||
|
||
final List<Violation> actual = | ||
violationsApi() // | ||
.withPattern(".*/kotlinmaven/.*\\.txt") // | ||
.inFolder(rootFolder) // | ||
.findAll(KOTLINMAVEN) // | ||
.violations(); | ||
|
||
assertThat(actual) // | ||
.hasSize(29); | ||
|
||
final Violation violation0 = actual.get(0); | ||
assertThat(violation0.getMessage()) // | ||
.isEqualTo("Unchecked cast: AssetDao<*> to DaoOperations.Read<T, UUID>"); | ||
assertThat(violation0.getFile()) // | ||
.isEqualTo( | ||
"/home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/data/hub/AnyAssetDaoImpl.kt"); | ||
assertThat(violation0.getSeverity()) // | ||
.isEqualTo(WARN); | ||
assertThat(violation0.getRule()) // | ||
.isEqualTo(""); | ||
assertThat(violation0.getParser()) // | ||
.isEqualTo(KOTLINMAVEN); | ||
} | ||
} |
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,39 @@ | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/data/hub/AnyAssetDaoImpl.kt: (44, 63) Unchecked cast: AssetDao<*> to DaoOperations.Read<T, UUID> | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/data/hub/AnyEntityDaoImpl.kt: (18, 27) Unchecked cast: KClass<out Entity<*>> to KClass<out Asset> | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/data/hub/AnyEntityDaoImpl.kt: (25, 30) Unchecked cast: KClass<out Entity<*>> to KClass<out Asset> | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/planner/Plan.kt: (14, 12) Parameter 'step' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/planner/Plan.kt: (14, 44) Parameter 'plan' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/planner/PlanComparator.kt: (50, 8) Name shadowed: first | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/planner/PlanComparator.kt: (50, 8) Variable 'first' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/planner/PlanComparator.kt: (51, 8) Name shadowed: second | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/planner/PlanComparator.kt: (51, 8) Variable 'second' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/planner/execution/PlanExecutorImpl.kt: (152, 14) Unchecked cast: StepExecutor<*>? to StepExecutor<AbstractOperationalStep> | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/planner/steps/base/AbstractUnAllocateFactory.kt: (17, 21) Unchecked cast: VirtualStorageAllocation to S | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/planner/steps/vstorage/migrate/live/libvirt/LibvirtMigrateVirtualStorageDeviceExecutor.kt: (13, 10) Unreachable code | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/services/impl/AbstractAssetService.kt: (92, 50) Unchecked cast: List<Asset> to List<T> | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/services/impl/VirtualStorageDeviceServiceImpl.kt: (49, 42) 'allocation: VirtualStorageAllocation' is deprecated. Use allocations | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/services/impl/VirtualStorageDeviceServiceImpl.kt: (51, 43) 'allocation: VirtualStorageAllocation' is deprecated. Use allocations | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/services/socket/InternalMessageListenerImpl.kt: (41, 36) The corresponding parameter in the supertype 'InternalMessageListener' is named 'sessionId'. This may cause problems when calling this function with named arguments. | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/services/socket/SpringSocketClientConnection.kt: (60, 48) Unchecked cast: KClass<Entity<*>> to KClass<out Entity<out Any>> | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/AnyUtils.kt: (7, 1) Expected performance impact of inlining 'public inline fun NOP(): Unit defined in com.github.kerubistan.kerub.utils in file AnyUtils.kt' is insignificant. Inlining works best for functions with parameters of functional types | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/AnyUtils.kt: (9, 1) Expected performance impact of inlining 'public inline fun NOP(comment: String): Unit defined in com.github.kerubistan.kerub.utils in file AnyUtils.kt' is insignificant. Inlining works best for functions with parameters of functional types | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/AnyUtils.kt: (9, 16) Parameter 'comment' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/artemis/MqInit.kt: (20, 10) 'deployQueue(SimpleString!, SimpleString!, SimpleString!, Boolean, Boolean): Queue!' is deprecated. Deprecated in Java | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/ipmi/IOUtils.kt: (8, 24) Parameter 'timeout' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/ipmi/IpmiClient.kt: (49, 18) Parameter 'address' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/ipmi/IpmiClient.kt: (49, 35) Parameter 'onSession' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/ispn/InfinispanJsonExternalizer.kt: (19, 33) Unchecked cast: Class<out Any> to Class<out Entity<*>> | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/fw/ipfw/Ipfw.kt: (6, 11) Parameter 'session' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/fw/ipfw/Ipfw.kt: (6, 35) Parameter 'port' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/fw/ipfw/Ipfw.kt: (6, 46) Parameter 'proto' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/fw/ipfw/Ipfw.kt: (10, 12) Parameter 'session' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/fw/ipfw/Ipfw.kt: (10, 36) Parameter 'port' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/fw/ipfw/Ipfw.kt: (10, 47) Parameter 'proto' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/mount/FSTab.kt: (10, 11) Parameter 'session' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/storagemanager/lvm/LvmLv.kt: (137, 42) Parameter 'vgName' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/sysctl/BsdSysCtl.kt: (13, 7) Variable 'props' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/virt/vbox/VBoxManage.kt: (50, 9) Variable 'device' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/virt/vbox/VBoxManage.kt: (147, 25) 'allocation: VirtualStorageAllocation' is deprecated. Use allocations | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/virt/vbox/VBoxManage.kt: (187, 8) Parameter 'listener' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/virt/vbox/VBoxManage.kt: (190, 57) Parameter 'size' is never used | ||
[WARNING] /home/bjerre/workspace/kerub/src/main/kotlin/com/github/kerubistan/kerub/utils/junix/zfs/Zfs.kt: (16, 3) Unreachable code |