Skip to content

Commit

Permalink
add assembly plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavsr committed Mar 29, 2015
1 parent 17d1649 commit 7410b6b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.trueaccord.scalapb.compiler

object Main extends App {
val response = Process.runWithInputStream(System.in)
System.out.write(response.toByteArray)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.trueaccord.scalapb.compiler

import java.io.{StringWriter, PrintWriter}
import java.io.{InputStream, StringWriter, PrintWriter}
import java.nio.file.attribute.PosixFilePermission
import java.nio.file.{Files, Path}

Expand All @@ -22,24 +22,28 @@ object Process {
stringWriter.toString
}

def runWithInputStream(fsin: InputStream): CodeGeneratorResponse = {
val registry = ExtensionRegistry.newInstance()
Scalapb.registerAllExtensions(registry)

Try {
val request = CodeGeneratorRequest.parseFrom(fsin, registry)
ProtobufGenerator.handleCodeGeneratorRequest(request)
}.recover {
case throwable =>
CodeGeneratorResponse.newBuilder()
.setError(throwable.toString + "\n" + getStackTrace(throwable))
.build
}.get
}

def runProtocUsing[A](protocCommand: String, schemas: Seq[String] = Nil,
includePaths: Seq[String] = Nil, protocOptions: Seq[String] = Nil)(runner: Seq[String] => A): A = {
val pipe = createPipe()
val sh = createShellScript(pipe)
val registry = ExtensionRegistry.newInstance()
Scalapb.registerAllExtensions(registry)

Future {
val fsin = Files.newInputStream(pipe)
val response = Try {
val request = CodeGeneratorRequest.parseFrom(fsin, registry)
ProtobufGenerator.handleCodeGeneratorRequest(request)
}.recover {
case throwable =>
CodeGeneratorResponse.newBuilder()
.setError(throwable.toString + "\n" + getStackTrace(throwable))
.build
}.get
val response = runWithInputStream(fsin)
val fsout = Files.newOutputStream(pipe)
fsout.write(response.toByteArray)
fsout.close()
Expand Down
2 changes: 2 additions & 0 deletions project/assembly.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.13.0")

0 comments on commit 7410b6b

Please sign in to comment.