Skip to content

Commit

Permalink
feat: Add a default "plugins" dir in the distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed Jun 29, 2024
1 parent 7d654b1 commit 8afd371
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
16 changes: 6 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ application {
mainClass.set("br.com.felipezorzo.zpa.cli.MainKt")
}

val copyDependencies = tasks.create<Sync>("copyDependencies") {
from(configurations.runtimeClasspath)
into(layout.buildDirectory.dir("dependencies/flat"))
}
tasks["assemble"].dependsOn(copyDependencies)

publishing {
repositories {
maven {
Expand Down Expand Up @@ -190,11 +184,13 @@ jreleaser {

path.set(file(jdkPath))
}
mainJar {
path.set(file("build/libs/zpa-cli-{{projectVersion}}.jar"))
javaArchive {
path = "build/distributions/zpa-cli-{{projectVersion}}.tar"
}
jars {
pattern.set("build/dependencies/flat/*.jar")
fileSet {
input = "src/dist/plugins"
output = "plugins"
includes = listOf("*")
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/dist/plugins/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Put your custom plugins in this directory.

Follow the instructions at https://github.com/felipebz/zpa/wiki/Create-a-plugin-with-custom-rules to create a custom plugin with additional rules.
13 changes: 12 additions & 1 deletion src/main/kotlin/br/com/felipezorzo/zpa/cli/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ import org.sonar.plugins.plsqlopen.api.PlSqlFile
import org.sonar.plugins.plsqlopen.api.checks.PlSqlVisitor
import java.io.File
import java.nio.charset.StandardCharsets
import java.nio.file.Path
import java.util.*
import java.util.concurrent.TimeUnit
import java.util.logging.LogManager
import java.util.stream.Collectors
import kotlin.io.path.absolute
import kotlin.io.path.extension
import kotlin.io.path.name
import kotlin.system.measureTimeMillis
import br.com.felipezorzo.zpa.cli.sqissue.Issue as GenericIssue

Expand All @@ -40,7 +44,14 @@ class Main(private val args: Arguments) {
LogManager.getLogManager().readConfiguration(it)
}

val pluginManager = PluginManager()
val codePath = Path.of(Main::class.java.protectionDomain.codeSource.location.path).absolute()
val appHome = if (codePath.extension == "jar" && (codePath.parent.name == "lib" || codePath.parent.name == "jars")) {
codePath.parent.parent.name
} else {
"."
}

val pluginManager = PluginManager(Path.of(appHome, "plugins"))
pluginManager.loadPlugins()
pluginManager.startPlugins()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package br.com.felipezorzo.zpa.cli.plugin

import org.pf4j.DefaultPluginManager
import org.pf4j.PluginDescriptorFinder
import java.nio.file.Path

class PluginManager: DefaultPluginManager() {
class PluginManager(pluginRoot: Path): DefaultPluginManager(pluginRoot) {

override fun createPluginDescriptorFinder(): PluginDescriptorFinder {
return ZpaPluginDescriptorFinder()
Expand Down

0 comments on commit 8afd371

Please sign in to comment.