-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add basic support to custom plugins
To be compatible with zpa-cli, the plugins should have a META-INF/extensions.idx file with the fully-qualified name of a CustomPlSqlRulesDefinition subclass
- Loading branch information
Showing
6 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/br/com/felipezorzo/zpa/cli/plugin/PluginManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package br.com.felipezorzo.zpa.cli.plugin | ||
|
||
import org.pf4j.DefaultPluginManager | ||
import org.pf4j.PluginDescriptorFinder | ||
|
||
class PluginManager: DefaultPluginManager() { | ||
|
||
override fun createPluginDescriptorFinder(): PluginDescriptorFinder { | ||
return ZpaPluginDescriptorFinder() | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/br/com/felipezorzo/zpa/cli/plugin/ZpaPluginDescriptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package br.com.felipezorzo.zpa.cli.plugin | ||
|
||
import org.pf4j.DefaultPluginDescriptor | ||
|
||
class ZpaPluginDescriptor : DefaultPluginDescriptor() { | ||
|
||
public override fun setPluginId(pluginId: String): DefaultPluginDescriptor { | ||
return super.setPluginId(pluginId) | ||
} | ||
|
||
fun setVersion(version: String): DefaultPluginDescriptor { | ||
return super.setPluginVersion(version) | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/br/com/felipezorzo/zpa/cli/plugin/ZpaPluginDescriptorFinder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package br.com.felipezorzo.zpa.cli.plugin | ||
|
||
import org.pf4j.PluginDescriptor | ||
import org.pf4j.PluginDescriptorFinder | ||
import org.pf4j.PluginRuntimeException | ||
import org.pf4j.util.FileUtils | ||
import java.io.IOException | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.util.jar.JarFile | ||
import java.util.jar.Manifest | ||
|
||
class ZpaPluginDescriptorFinder : PluginDescriptorFinder { | ||
|
||
override fun isApplicable(pluginPath: Path): Boolean { | ||
return Files.exists(pluginPath) && FileUtils.isJarFile(pluginPath) | ||
} | ||
|
||
override fun find(pluginPath: Path): PluginDescriptor { | ||
val manifest = readManifest(pluginPath) | ||
return createPluginDescriptor(manifest) | ||
} | ||
|
||
private fun readManifest(pluginPath: Path): Manifest { | ||
try { | ||
return JarFile(pluginPath.toFile()).use { it.manifest } | ||
} catch (e: IOException) { | ||
throw PluginRuntimeException(e, "Cannot read manifest from {}", pluginPath) | ||
} | ||
} | ||
|
||
private fun createPluginDescriptor(manifest: Manifest): PluginDescriptor { | ||
val pluginDescriptor = ZpaPluginDescriptor() | ||
val attributes = manifest.mainAttributes | ||
|
||
val id = attributes.getValue(PLUGIN_ID) | ||
pluginDescriptor.pluginId = id | ||
|
||
val version = attributes.getValue(PLUGIN_VERSION) | ||
if (version.isNotEmpty()) { | ||
pluginDescriptor.version = version | ||
} | ||
|
||
return pluginDescriptor | ||
} | ||
|
||
companion object { | ||
const val PLUGIN_ID = "Plugin-Key" | ||
const val PLUGIN_VERSION = "Plugin-Version" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters