Skip to content

Commit

Permalink
Do not limit to just 'dylib', we also need 'so' and 'dll'
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvisser committed Sep 11, 2023
1 parent 560c4b0 commit 298213c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import kotlin.io.path.walk
@ApplicationScoped
class PluginExtensionLoader {

companion object {
const val PLUGIN_EXTENSION = "plugin"
}

@OptIn(ExperimentalPathApi::class)
@Produces
@ApplicationScoped
Expand All @@ -27,9 +23,15 @@ class PluginExtensionLoader {
.map(Path::toFile)
.filter { it.extension == PLUGIN_EXTENSION }
.map { objectMapper.readValue<PluginDefinition>(it.readText()) }
.map { Plugin(it, pluginPath.resolve(it.dylibFile())) }
.map { Plugin(it, pluginPath.resolve(it.filename(osUtils))) }
.toList()
}

private fun PluginDefinition.dylibFile() = libName.takeIf { it.endsWith(".dylib") } ?: "$libName.dylib"
private fun PluginDefinition.filename(osUtils: OsUtils) =
libName.takeIf { fileExtensionPattern.matches(it) } ?: "$libName.${osUtils.getPluginFileExtension()}"

private companion object {
private const val PLUGIN_EXTENSION = "plugin"
private val fileExtensionPattern = ".+\\.(dylib|so|dll)".toRegex()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ class VersionProperties {
private fun loadGitProperties() {
VersionProperties::class.java.classLoader.getResourceAsStream(GIT_PROPERTIES)
?.run { properties.load(this) }
?: Log.debug("No Git information available: cannot load git.properties file.")
?: Log.info("No Git information available: cannot load git.properties file.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ class PluginConfigureCommand(
private fun storePluginConfiguration(pluginName: String) {
var hasPluginSpecificConfig = false
val pluginConfigFile = config.pluginConfigDirectory().resolve("$pluginName.json").toFile()
val pluginConfig = if (pluginConfigFile.exists()) objectMapper.readValue<Map<String, String>>(pluginConfigFile) else emptyMap()
val pluginConfig = if (pluginConfigFile.exists()) objectMapper.readValue<Map<String, Any?>>(pluginConfigFile) else emptyMap()

val answers = mutableMapOf<String, Any>()

config.configure {
hasPluginSpecificConfig = true
val message = it.toMessage()
val currentValue = pluginConfig[it.key]
val currentValue = (pluginConfig[it.key] as String?).orEmpty()
var input = retConsole.prompt(message, currentValue)

while (it.required && input.ifEmpty { currentValue.orEmpty() }.isEmpty()) {
while (it.required && input.ifEmpty { currentValue }.isEmpty()) {
retConsole.out("Please fill in an answer")
input = retConsole.prompt(message, currentValue)
}

answers[it.key] = input.ifEmpty { currentValue.orEmpty() }
answers[it.key] = input.ifEmpty { currentValue }
}

if (hasPluginSpecificConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import kotlin.io.path.createDirectories
class PluginInitializeCommand(
private val retConsole: RetConsole,
private val objectMapper: ObjectMapper,
osUtils: OsUtils,
private val osUtils: OsUtils,
) : Runnable {
@Spec
lateinit var commandSpec: CommandSpec
Expand All @@ -49,23 +49,23 @@ class PluginInitializeCommand(
retConsole.out("Initializing plugin '$pluginName'")
val pluginNameWithFallbackToParent = if (this::pluginPath.isInitialized) pluginPath else pluginName
val plugin = File(pluginNameWithFallbackToParent)
val dylib = pluginDirectory.resolve("$pluginName.dylib").toFile()
val pluginFile = pluginDirectory.resolve("$pluginName.${osUtils.getPluginFileExtension()}").toFile()

if (plugin.isAbsolute) {
if (dylib.exists() && plugin != dylib) {
if (pluginFile.exists() && plugin != pluginFile) {
val overwrite = retConsole.prompt("The plugin is already installed, overwrite [Yn]?", "Y")
if (overwrite.isBlank() || overwrite.lowercase() == "y") {
plugin.copyTo(dylib, true)
Log.info("Dynamic library overwritten for '$pluginName'")
plugin.copyTo(pluginFile, true)
Log.info("Plugin file overwritten for '$pluginName'")
}
} else {
plugin.copyTo(dylib, true)
Log.info("Copied dynamic library for '$pluginName'")
plugin.copyTo(pluginFile, true)
Log.info("Copied plugin file for '$pluginName'")
}
}

if (!dylib.exists()) {
throw FileNotFoundException("$dylib does not exist")
if (!pluginFile.exists()) {
throw FileNotFoundException("$pluginFile does not exist")
}

Log.info("Generating/updating plugin file for '$pluginName'")
Expand Down

0 comments on commit 298213c

Please sign in to comment.