Skip to content

Commit 790063a

Browse files
authored
Merge pull request #28 from Bible-Translation-Tools/jbs-plugin-paths
Jbs plugin paths
2 parents ee11fdd + 6e72bb3 commit 790063a

File tree

5 files changed

+86
-41
lines changed

5 files changed

+86
-41
lines changed

assets/src/main/resources/plugins/ocenaudio.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
canEdit: true
55
canRecord: true
66
executable:
7-
macos: /Applications/ocenaudio.app/Contents/MacOS/ocenaudio
8-
linux: /usr/bin/ocenaudio
9-
windows: C:\Program Files (x86)\ocenaudio\ocenaudio.exe
7+
macos:
8+
- /Applications/ocenaudio.app/Contents/MacOS/ocenaudio
9+
linux:
10+
- /usr/bin/ocenaudio
11+
windows:
12+
- C:\Program Files (x86)\ocenaudio\ocenaudio.exe
13+
- C:\Program Files\ocenaudio\ocenaudio.exe
14+
- C:\Users\${user.name}\AppData\Local\ocenaudio\ocenaudio.exe
15+
- C:\Users\${user.name}\AppData\Roaming\ocenaudio\ocenaudio.exe
1016
args: []

jvm/workbookapp/src/main/kotlin/org/wycliffeassociates/otter/jvm/workbookapp/audioplugin/parser/ParsedAudioPluginDataMapper.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ class ParsedAudioPluginDataMapper(osName: String? = null) {
1414
*/
1515
fun mapToAudioPluginData(parsedAudioPlugin: ParsedAudioPluginData, sourceFile: File): AudioPluginData {
1616
// Get the executable for the system we are running on
17-
val executable = when {
18-
osName.contains("WIN") -> parsedAudioPlugin.executable.windows
19-
osName.contains("MAC") -> parsedAudioPlugin.executable.macos
20-
else -> parsedAudioPlugin.executable.linux
21-
}
17+
val executable = selectExecutable(parsedAudioPlugin)
2218

2319
return AudioPluginData(
2420
0,
@@ -31,4 +27,27 @@ class ParsedAudioPluginDataMapper(osName: String? = null) {
3127
sourceFile
3228
)
3329
}
30+
31+
private fun selectExecutable(parsedAudioPlugin: ParsedAudioPluginData): String? {
32+
val options = when {
33+
osName.contains("WIN") -> parsedAudioPlugin.executable.windows
34+
osName.contains("MAC") -> parsedAudioPlugin.executable.macos
35+
else -> parsedAudioPlugin.executable.linux
36+
}?.map {
37+
insertArguments(it)
38+
}
39+
return options?.let {
40+
selectValid(it)
41+
}
42+
}
43+
44+
private fun insertArguments(filename: String): String {
45+
return filename.replace("\${user.name}", System.getProperty("user.name"))
46+
}
47+
48+
private fun selectValid(paths: List<String>): String? {
49+
return paths.map { File(it) }.firstOrNull {
50+
it.exists() && it.canExecute()
51+
}?.absolutePath
52+
}
3453
}

jvm/workbookapp/src/main/kotlin/org/wycliffeassociates/otter/jvm/workbookapp/audioplugin/parser/ParsedExecutable.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package org.wycliffeassociates.otter.jvm.workbookapp.audioplugin.parser
22

33
data class ParsedExecutable(
44
// nullable since executable might not exist for a platform
5-
var macos: String?,
6-
var windows: String?,
7-
var linux: String?
5+
var macos: List<String>?,
6+
var windows: List<String>?,
7+
var linux: List<String>?
88
)

jvm/workbookapp/src/test/kotlin/org/wycliffeassociates/otter/jvm/workbookapp/audioplugin/AudioPluginTest.kt

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,31 @@ import org.wycliffeassociates.otter.common.data.config.AudioPluginData
66
import java.io.File
77

88
class AudioPluginTest {
9+
10+
var exe = File.createTempFile("test", ".exe").apply {
11+
setExecutable(true)
12+
deleteOnExit()
13+
}
14+
915
var inputAudioPluginData = AudioPluginData(
10-
0,
11-
"Beethoven",
12-
"3.4.2",
13-
true,
14-
false,
15-
"bash",
16-
listOf("-c", "echo hello"),
17-
File("some/fake/file/path.yaml")
16+
0,
17+
"Beethoven",
18+
"3.4.2",
19+
true,
20+
false,
21+
"bash",
22+
listOf("-c", "echo hello"),
23+
exe
1824
)
1925
var missingExecutablePlugin = AudioPluginData(
20-
0,
21-
"Beethoven",
22-
"3.4.2",
23-
true,
24-
false,
25-
"./my-missing-executable",
26-
listOf("hello"),
27-
File("some/fake/file/path.yaml")
26+
0,
27+
"Beethoven",
28+
"3.4.2",
29+
true,
30+
false,
31+
"./my-missing-executable",
32+
listOf("hello"),
33+
File("some/fake/file/path.yaml")
2834
)
2935
val inputFile = File("somefile.wav")
3036

@@ -33,8 +39,8 @@ class AudioPluginTest {
3339
// Create the plugin
3440
val audioPlugin = AudioPlugin(inputAudioPluginData)
3541
audioPlugin
36-
.launch(inputFile)
37-
.blockingAwait()
42+
.launch(inputFile)
43+
.blockingAwait()
3844
// Test only finishes if completable finishes
3945
}
4046

@@ -44,8 +50,8 @@ class AudioPluginTest {
4450
val audioPlugin = AudioPlugin(missingExecutablePlugin)
4551
try {
4652
audioPlugin
47-
.launch(inputFile)
48-
.blockingAwait()
53+
.launch(inputFile)
54+
.blockingAwait()
4955
Assert.fail()
5056
} catch (e: RuntimeException) {
5157
// IOException thrown as RuntimeException

jvm/workbookapp/src/test/kotlin/org/wycliffeassociates/otter/jvm/workbookapp/audioplugin/parser/ParsedAudioPluginDataMapperTest.kt

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,32 @@ import org.wycliffeassociates.otter.common.data.config.AudioPluginData
66
import java.io.File
77

88
class ParsedAudioPluginDataMapperTest {
9+
10+
var win = File.createTempFile("windows", ".exe").apply {
11+
setExecutable(true)
12+
deleteOnExit()
13+
}
14+
var linux = File.createTempFile("linux", ".exe").apply {
15+
setExecutable(true)
16+
deleteOnExit()
17+
}
18+
var mac = File.createTempFile("mac", ".exe").apply {
19+
setExecutable(true)
20+
deleteOnExit()
21+
}
22+
923
val PLUGIN_PLATFORM_TABLE = listOf(
1024
mapOf(
1125
"os.name" to "Mac OS X",
12-
"expectedExecutable" to "/Applications/Audacity.workbookapp/Contents/MacOS/Audacity"
26+
"expectedExecutable" to mac.absolutePath
1327
),
1428
mapOf(
1529
"os.name" to "Windows 10",
16-
"expectedExecutable" to "C:\\Program Files (x86)\\Audacity\\audacity.exe"
30+
"expectedExecutable" to win.absolutePath
1731
),
1832
mapOf(
1933
"os.name" to "Linux",
20-
"expectedExecutable" to "audacity"
34+
"expectedExecutable" to linux.absolutePath
2135
)
2236
)
2337

@@ -31,9 +45,9 @@ class ParsedAudioPluginDataMapperTest {
3145
true,
3246
false,
3347
ParsedExecutable(
34-
"/Applications/Audacity.workbookapp/Contents/MacOS/Audacity",
35-
"C:\\Program Files (x86)\\Audacity\\audacity.exe",
36-
"audacity"
48+
listOf(mac.absolutePath),
49+
listOf(win.absolutePath),
50+
listOf(linux.absolutePath)
3751
),
3852
listOf("-t value")
3953
)
@@ -107,9 +121,9 @@ class ParsedAudioPluginDataMapperTest {
107121
true,
108122
false,
109123
ParsedExecutable(
110-
"/Applications/Audacity.workbookapp/Contents/MacOS/Audacity",
111-
"C:\\Program Files (x86)\\Audacity\\audacity.exe",
112-
"audacity"
124+
listOf(mac.absolutePath),
125+
listOf(win.absolutePath),
126+
listOf(linux.absolutePath)
113127
),
114128
listOf("-t value")
115129
)
@@ -124,7 +138,7 @@ class ParsedAudioPluginDataMapperTest {
124138
inputPluginData.version,
125139
inputPluginData.canEdit,
126140
inputPluginData.canRecord,
127-
"audacity",
141+
linux.absolutePath,
128142
inputPluginData.args,
129143
inputPluginFile
130144
)

0 commit comments

Comments
 (0)