Skip to content

Commit

Permalink
Make api linter working with windows (#45)
Browse files Browse the repository at this point in the history
* Make api linter work with windows

* Throw exception when api linter return non-zero value
  • Loading branch information
devkanro authored Jul 14, 2020
1 parent 9cf8b72 commit 8108fec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bybutter.sisyphus.apilinter

import java.io.BufferedReader
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
Expand All @@ -19,23 +20,31 @@ class ApiLinterRunner {
apiLinterCmd.add(arg)
}
println("api-linter executing: $apiLinterCmd")
val process = ProcessBuilder(apiLinterCmd).start()
val process = ProcessBuilder(apiLinterCmd).redirectErrorStream(true).start()
val result = process.text()
process.waitFor()
val exitCode = process.waitFor()
if (exitCode != 0) {
println("api-linter: $result")
throw IllegalStateException("Api linter return with non-zero value '$exitCode'.")
}
return result
}

private fun extractApiLinter(version: String): Path {
val osName = System.getProperties().getProperty("os.name").normalize()
val platform = detectPlatform(osName)
val srcFilePath = Paths.get(version, "api-linter-$version-$platform.exe").toString()
val srcFile = this.javaClass.classLoader.getResource(srcFilePath)
?: throw UnsupportedOperationException("Unsupported api linter version $version or platform $osName.")
val srcFile = this.javaClass.classLoader.getResource(srcFilePath.replace(File.separatorChar, '/'))
?: throw UnsupportedOperationException("Unsupported api linter version $version for platform $osName.")
val executable = createTempBinDir().resolve("apilinter.exe")
srcFile.openStream().use {
Files.copy(it, executable)
}
Files.setPosixFilePermissions(executable, setOf(PosixFilePermission.OWNER_EXECUTE))
when (platform) {
"darwin", "linux" -> {
Files.setPosixFilePermissions(executable, setOf(PosixFilePermission.OWNER_EXECUTE))
}
}
return executable.also {
it.toFile().deleteOnExit()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.bybutter.sisyphus.protobuf.gradle
import com.bybutter.sisyphus.io.toUnixPath
import com.bybutter.sisyphus.protobuf.compiler.ProtocRunner
import java.io.File
import java.net.URI
import java.nio.file.FileSystems
import java.nio.file.FileVisitResult
import java.nio.file.Files
Expand Down Expand Up @@ -88,7 +87,7 @@ open class ExtractProtoTask : SourceTask() {
if (source) {
val protoName = name.toUnixPath()
sourceProtos.add(protoName)
sourceFileMapping[protoName] = URI(file.toUri().toURL().path).path
sourceFileMapping[protoName] = file.toString()
}
val targetFile = protoPath.toPath().resolve(name)
Files.createDirectories(targetFile.parent)
Expand Down

0 comments on commit 8108fec

Please sign in to comment.