Commit 20c99d1 1 parent 497f24e commit 20c99d1 Copy full SHA for 20c99d1
File tree 2 files changed +38
-2
lines changed
2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change 1
1
package protocbridge
2
2
3
+ import java .nio .file .Files
3
4
import scala .io .Source
4
5
import scala .sys .process .Process
5
6
import scala .sys .process .ProcessLogger
@@ -74,4 +75,31 @@ object ProtocRunner {
74
75
extraEnv : _*
75
76
).!
76
77
}
78
+
79
+ // Transforms the given protoc runner to a new runner that writes the
80
+ // options into a temporary file and passes the file to `protoc` as an `@`
81
+ // parameter.
82
+ def withParametersAsFile [T ](underlying : ProtocRunner [T ]): ProtocRunner [T ] =
83
+ fromFunction { (args, extraEnv) =>
84
+ {
85
+ val argumentFile = Files .createTempFile(" protoc-args-" , " .txt" )
86
+ try {
87
+ val writer = Files .newBufferedWriter(argumentFile)
88
+
89
+ try {
90
+ args.foreach { arg =>
91
+ writer.write(arg)
92
+ writer.write('\n ' )
93
+ }
94
+ } finally {
95
+ writer.close()
96
+ }
97
+
98
+ val fileArgument = s " @ ${argumentFile.toString}"
99
+ underlying.run(Seq (fileArgument), extraEnv)
100
+ } finally {
101
+ Files .delete(argumentFile)
102
+ }
103
+ }
104
+ }
77
105
}
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ object TestUtils {
67
67
}
68
68
69
69
class ProtocIntegrationSpec extends AnyFlatSpec with Matchers {
70
- " ProtocBridge.run " should " invoke JVM and Java plugin properly " in {
70
+ def invokeProtocProperly ( runner : ProtocRunner [ Int ]) = {
71
71
val protoFile =
72
72
new File (getClass.getResource(" /test.proto" ).getFile).getAbsolutePath
73
73
val protoDir = new File (getClass.getResource(" /" ).getFile).getAbsolutePath
@@ -77,7 +77,7 @@ class ProtocIntegrationSpec extends AnyFlatSpec with Matchers {
77
77
(0 to 4 ).map(i => Files .createTempDirectory(s " testout $i" ).toFile())
78
78
79
79
ProtocBridge .execute(
80
- RunProtoc ,
80
+ runner ,
81
81
Seq (
82
82
protocbridge.gens.java(" 3.8.0" ) -> javaOutDir,
83
83
TestJvmPlugin -> testOutDirs(0 ),
@@ -111,6 +111,14 @@ class ProtocIntegrationSpec extends AnyFlatSpec with Matchers {
111
111
readLines(new File (testOutDirs(0 ), " parameters.txt" )) must be(Seq (" Empty" ))
112
112
}
113
113
114
+ " ProtocBridge.run" should " invoke JVM and Java plugin properly" in {
115
+ invokeProtocProperly(RunProtoc )
116
+ }
117
+
118
+ " ProtocBridge.run" should " invoke JVM and Java plugin properly with options file" in {
119
+ invokeProtocProperly(ProtocRunner .withParametersAsFile(RunProtoc ))
120
+ }
121
+
114
122
it should " not deadlock for highly concurrent invocations" in {
115
123
val availableProcessors = Runtime .getRuntime.availableProcessors
116
124
assert(
You can’t perform that action at this time.
0 commit comments