Skip to content

Commit fdf5d0e

Browse files
committed
Create System Properties bugreport section
1 parent 9280a07 commit fdf5d0e

File tree

11 files changed

+146
-15
lines changed

11 files changed

+146
-15
lines changed

src/main/java/com/tibagni/logviewer/ServiceLocator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ object ServiceLocator {
1717
BugReportRepositoryImpl(
1818
BugReportParserImpl(
1919
listOf(
20-
PropertiesSectionParser(),
20+
BugreportInfoSectionParser(),
21+
SystemPropertiesSectionParser(),
2122
ApplicationPackagesSectionParser(),
2223
SystemHiddenPackagesSectionParser(),
2324
CarrierConfigSectionParser(),

src/main/java/com/tibagni/logviewer/bugreport/parser/PropertiesSectionParser.kt renamed to src/main/java/com/tibagni/logviewer/bugreport/parser/BugreportInfoSectionParser.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.tibagni.logviewer.bugreport.parser
22

33
import com.tibagni.logviewer.bugreport.section.BugReportSection
4-
import com.tibagni.logviewer.bugreport.section.PropertiesSection
4+
import com.tibagni.logviewer.bugreport.section.BugreportInfoSection
55

6-
class PropertiesSectionParser : BugReportSectionParser {
6+
class BugreportInfoSectionParser : BugReportSectionParser {
77
override val name = "BugreportInfo"
88
companion object {
99
private const val NOT_FOUND = "Not Found"
@@ -16,7 +16,7 @@ class PropertiesSectionParser : BugReportSectionParser {
1616
val kernel = parseBRProperty(bugReportText, "Kernel: ")
1717
val uptime = parseBRProperty(bugReportText, "Uptime: ")
1818

19-
return PropertiesSection(build, buildFingerprint, bootloader, kernel, uptime)
19+
return BugreportInfoSection(build, buildFingerprint, bootloader, kernel, uptime)
2020
}
2121

2222
private fun parseBRProperty(text: String, prefix: String): String {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.tibagni.logviewer.bugreport.parser
2+
3+
import com.tibagni.logviewer.bugreport.section.BugReportSection
4+
import com.tibagni.logviewer.bugreport.section.SystemPropertiesSection
5+
import com.tibagni.logviewer.stringView
6+
7+
class SystemPropertiesSectionParser : BugReportSectionParser {
8+
9+
override val name = "SystemProperties"
10+
override fun parse(bugreportPath: String, bugReportText: String): BugReportSection? {
11+
12+
val sysPropSectionStart = "\\n-+ SYSTEM PROPERTIES.* -+\\n"
13+
val sysPropSectionEnd = "\\n-+ .*SYSTEM PROPERTIES.* -+\\n"
14+
val sysPropStartMatch = sysPropSectionStart.toRegex().find(bugReportText) ?: return null
15+
val sysPropEndMatch = sysPropSectionEnd.toRegex().find(bugReportText, sysPropStartMatch.range.last) ?: return null
16+
val sysPropSection = bugReportText.stringView(sysPropStartMatch.range.first + 1, sysPropEndMatch.range.last)
17+
18+
return SystemPropertiesSection(sysPropSection.lines()
19+
.filter { line -> line.matches(Regex("\\[.+]: ?\\[.+]")) }
20+
.associate { line ->
21+
val (key, value) = line.split(":").map { it.trim() }
22+
key to value
23+
})
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.tibagni.logviewer.bugreport.section
22

3-
data class PropertiesSection(
3+
data class BugreportInfoSection(
44
val build: String,
55
val fingerprint: String,
66
val bootloader: String,
77
val kernel: String,
88
val uptime: String
9-
) : BugReportSection(SectionNames.PROPERTIES)
9+
) : BugReportSection(SectionNames.BUGREPORT_INFO)

src/main/java/com/tibagni/logviewer/bugreport/section/SectionNames.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.tibagni.logviewer.bugreport.section
22

33
object SectionNames {
4-
const val PROPERTIES = "Properties"
4+
const val BUGREPORT_INFO = "Bugreport Info"
5+
const val SYSTEM_PROPERTIES = "System Properties"
56
const val PLAIN_TEXT = "Plain Text bugreport"
67
const val APPLICATION_PKG = "Application Packages"
78
const val SYSTEM_HIDDEN_PKG = "Hidden system packages"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.tibagni.logviewer.bugreport.section
2+
3+
data class SystemPropertiesSection(val configs: Map<String, String>) :
4+
BugReportSection(SectionNames.SYSTEM_PROPERTIES)

src/main/java/com/tibagni/logviewer/bugreport/section/ui/PropertiesSectionPanel.kt renamed to src/main/java/com/tibagni/logviewer/bugreport/section/ui/BugreportInfoSectionPanel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.tibagni.logviewer.bugreport.section.ui
22

3-
import com.tibagni.logviewer.bugreport.section.PropertiesSection
3+
import com.tibagni.logviewer.bugreport.section.BugreportInfoSection
44
import com.tibagni.logviewer.util.layout.GBConstraintsBuilder
55
import com.tibagni.logviewer.view.maxWidthOfColumn
66
import java.awt.GridBagConstraints
77
import javax.swing.JScrollPane
88
import javax.swing.JTable
99

10-
class PropertiesSectionPanel(private val section: PropertiesSection) : SectionPanel(section.sectionName) {
10+
class BugreportInfoSectionPanel(private val section: BugreportInfoSection) : SectionPanel(section.sectionName) {
1111
init {
1212
buildUi()
1313
}

src/main/java/com/tibagni/logviewer/bugreport/section/ui/SectionPanelFactory.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import com.tibagni.logviewer.bugreport.section.*
55
object SectionPanelFactory {
66
fun createPanelFor(sectionName: String, section: BugReportSection): SectionPanel {
77
return when (sectionName) {
8-
SectionNames.PROPERTIES -> PropertiesSectionPanel(section as PropertiesSection)
8+
SectionNames.BUGREPORT_INFO -> BugreportInfoSectionPanel(section as BugreportInfoSection)
99
SectionNames.PLAIN_TEXT -> PlainTextBugreportPanel(section as PlainTextSection)
1010
SectionNames.APPLICATION_PKG -> PackageSectionPanel(section as PackagesSection)
1111
SectionNames.SYSTEM_HIDDEN_PKG -> PackageSectionPanel(section as PackagesSection)
1212
SectionNames.CARRIER_CONFIG -> CarrierConfigSectionPanel(section as CarrierConfigSection)
1313
SectionNames.SUBSCRIPTIONS -> SubscriptionsSectionPanel(section as SubscriptionsSection)
14+
SectionNames.SYSTEM_PROPERTIES -> SystemPropertiesSectionPanel(section as SystemPropertiesSection)
1415
else -> object : SectionPanel("Invalid Section") {}// Should never reach here
1516
}
1617
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.tibagni.logviewer.bugreport.section.ui
2+
3+
import com.tibagni.logviewer.bugreport.section.SystemPropertiesSection
4+
import com.tibagni.logviewer.util.layout.GBConstraintsBuilder
5+
import java.awt.GridBagConstraints
6+
import javax.swing.*
7+
import javax.swing.table.DefaultTableModel
8+
9+
class SystemPropertiesSectionPanel(private val section: SystemPropertiesSection) : SectionPanel(section.sectionName, true) {
10+
private val headerTitles = arrayOf("Property", "Value")
11+
private lateinit var tableModel: SysPropTableModel
12+
13+
init {
14+
buildUi()
15+
}
16+
17+
override fun onSearch(searchText: String) {
18+
val filteredRows =
19+
section.configs.filterKeys { it.contains(searchText) }.map { arrayOf(it.key, it.value) }
20+
.toTypedArray()
21+
tableModel.setDataVector(filteredRows, arrayOf("Property", "Value"))
22+
}
23+
24+
private fun buildUi() {
25+
val container = JPanel()
26+
container.layout = BoxLayout(container, BoxLayout.Y_AXIS)
27+
28+
val rows = section.configs.entries.map { arrayOf(it.key, it.value) }.toTypedArray()
29+
30+
val table = JTable()
31+
tableModel = SysPropTableModel(rows, headerTitles)
32+
table.model = tableModel
33+
table.tableHeader.resizingAllowed = true
34+
35+
container.add(table)
36+
37+
add(
38+
JScrollPane(container).also { it.verticalScrollBar.unitIncrement = 16 },
39+
GBConstraintsBuilder()
40+
.withGridx(1)
41+
.withGridy(2)
42+
.withWeightx(1.0)
43+
.withWeighty(1.0)
44+
.withFill(GridBagConstraints.BOTH)
45+
.build()
46+
)
47+
}
48+
}
49+
50+
private class SysPropTableModel(data: Array<Array<String>>, cols: Array<String>) : DefaultTableModel(data, cols) {
51+
override fun isCellEditable(row: Int, column: Int) = false
52+
}

src/test/java/com/tibagni/logviewer/bugreport/parser/PropertiesSectionParserTests.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.tibagni.logviewer.bugreport.parser
22

3-
import com.tibagni.logviewer.bugreport.section.PropertiesSection
3+
import com.tibagni.logviewer.bugreport.section.BugreportInfoSection
44
import org.junit.Assert.*
55
import org.junit.Before
66
import org.junit.Test
77

88
class PropertiesSectionParserTests {
9-
private lateinit var propertiesSectionParser: PropertiesSectionParser
9+
private lateinit var propertiesSectionParser: BugreportInfoSectionParser
1010

1111
companion object {
1212
const val PROPERTIES = "========================================================\n" +
@@ -22,12 +22,12 @@ class PropertiesSectionParserTests {
2222

2323
@Before
2424
fun setUp() {
25-
propertiesSectionParser = PropertiesSectionParser()
25+
propertiesSectionParser = BugreportInfoSectionParser()
2626
}
2727

2828
@Test
2929
fun testParseProperties() {
30-
val section = propertiesSectionParser.parse("", PROPERTIES) as PropertiesSection
30+
val section = propertiesSectionParser.parse("", PROPERTIES) as BugreportInfoSection
3131

3232
assertEquals("blabla-userdebug 11 AAA11.111 57ca8 test-keys", section.build)
3333
assertEquals("'bla/blabla/bla:11/AAA11.111/57ca8:userdebug/intcfg,test-keys'", section.fingerprint)
@@ -38,7 +38,7 @@ class PropertiesSectionParserTests {
3838

3939
@Test
4040
fun testParsePropertiesMissingData() {
41-
val section = propertiesSectionParser.parse("", "INVALID") as PropertiesSection
41+
val section = propertiesSectionParser.parse("", "INVALID") as BugreportInfoSection
4242

4343
assertEquals("Not Found", section.build)
4444
assertEquals("Not Found", section.fingerprint)

0 commit comments

Comments
 (0)