[go: nahoru, domu]

Skip to content

Commit

Permalink
Update Kotlin to 1.16.21, remove Launch4j task, use argument for inpu…
Browse files Browse the repository at this point in the history
…t and output instead of option, add exclude option
  • Loading branch information
valaphee committed Apr 29, 2022
1 parent 8821fd2 commit 2519068
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 35 deletions.
12 changes: 1 addition & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {
id("com.github.johnrengelman.shadow") version "7.0.0"
id("com.palantir.git-version") version "0.12.3"
id("edu.sc.seis.launch4j") version "2.5.0"
kotlin("jvm") version "1.6.20"
kotlin("jvm") version "1.6.21"
signing
}

Expand Down Expand Up @@ -56,14 +56,4 @@ tasks {

application { mainClass.set("com.valaphee.protod.MainKt") }

launch4j {
jarTask = tasks.shadowJar.get()
icon = "${projectDir}/app.ico"
copyright = "Copyright (c) 2021-2022, Valaphee"
companyName = "Valaphee"
fileDescription = "Protocol Buffers Decompiler extracts Protocol Buffers descriptors from any file"
productName = "Protod"
copyConfigurable = emptyArray<Any>()
}

signing { useGpgCmd() }
25 changes: 6 additions & 19 deletions src/main/kotlin/com/valaphee/protod/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import com.google.protobuf.DescriptorProtos
import com.valaphee.protod.util.occurrencesOf
import kotlinx.cli.ArgParser
import kotlinx.cli.ArgType
import kotlinx.cli.required
import kotlinx.cli.default
import kotlinx.cli.multiple
import java.io.File

fun main(arguments: Array<String>) {
val argumentParser = ArgParser("protod")
val input by argumentParser.option(ArgType.String, "input", "i", "Input file").required()
val output by argumentParser.option(ArgType.String, "output", "o", "Output path").required()
val input by argumentParser.argument(ArgType.String, "input", "i", "Input file")
val output by argumentParser.argument(ArgType.String, "output", "o", "Output path")
val exclude by argumentParser.option(ArgType.String, "exclude", null, "Exclude files").multiple().default(listOf("google/protobuf/compiler/plugin.proto", "google/protobuf/any.proto", "google/protobuf/api.proto", "google/protobuf/descriptor.proto", "google/protobuf/duration.proto", "google/protobuf/empty.proto", "google/protobuf/field_mask.proto", "google/protobuf/source_context.proto", "google/protobuf/struct.proto", "google/protobuf/timestamp.proto", "google/protobuf/type.proto", "google/protobuf/wrappers.proto"))
argumentParser.parse(arguments)

val inputFile = File(input)
Expand Down Expand Up @@ -85,7 +87,7 @@ fun main(arguments: Array<String>) {
println("Generating ${files.size} Protocol Buffers definitions")
val outputPath = File(output)
files.forEach { file ->
if (!included.contains(file.name)) {
if (!exclude.contains(file.name)) {
val outputFile = File(outputPath, file.name)
outputFile.parentFile.mkdirs()
outputFile.printWriter().use { printWriter ->
Expand All @@ -101,18 +103,3 @@ fun main(arguments: Array<String>) {
}
}
}

private val included = setOf(
"google/protobuf/compiler/plugin.proto",
"google/protobuf/any.proto",
"google/protobuf/api.proto",
"google/protobuf/descriptor.proto",
"google/protobuf/duration.proto",
"google/protobuf/empty.proto",
"google/protobuf/field_mask.proto",
"google/protobuf/source_context.proto",
"google/protobuf/struct.proto",
"google/protobuf/timestamp.proto",
"google/protobuf/type.proto",
"google/protobuf/wrappers.proto",
)
10 changes: 5 additions & 5 deletions src/main/kotlin/com/valaphee/protod/util/KnuthMorrisPratt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ fun ByteArray.occurrencesOf(pattern: ByteArray): Sequence<Int> {
}

var i = 0
var matches0 = 0
var _matches = 0
return generateSequence {
while (i < size) {
while (matches0 > 0 && pattern[matches0] != this[i]) matches0 = resultTable[matches0 - 1]
if (pattern[matches0] == this[i]) matches0++
if (matches0 == pattern.size) {
matches0 = resultTable[matches0 - 1]
while (_matches > 0 && pattern[_matches] != this[i]) _matches = resultTable[_matches - 1]
if (pattern[_matches] == this[i]) _matches++
if (_matches == pattern.size) {
_matches = resultTable[_matches - 1]
i++
return@generateSequence i - pattern.size
}
Expand Down

0 comments on commit 2519068

Please sign in to comment.