Skip to content

Commit

Permalink
Merge pull request #342 from wttech/bugfix/embedded-package-issue
Browse files Browse the repository at this point in the history
fix onInstall issue
  • Loading branch information
dprzybyl authored Apr 27, 2022
2 parents c4b3a04 + 5d9f91d commit 539d41d
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class ApmInstallHook : OsgiAwareInstallHook() {
val resolverFactory = getService(ResourceResolverFactory::class.java)

try {
context.options.listener?.onMessage(ProgressTrackerListener.Mode.TEXT, "Installing APM scripts...", "")
logger.info("Installing APM scripts...")
SlingHelper.operateTraced(resolverFactory) { resolver ->
executeScripts(context, currentEnvironment, currentHook, resolver)
}
Expand All @@ -71,7 +73,6 @@ class ApmInstallHook : OsgiAwareInstallHook() {
}

private fun executeScripts(context: InstallContext, currentEnvironment: LaunchEnvironment, currentHook: String, resolver: ResourceResolver) {
context.options.listener.onMessage(ProgressTrackerListener.Mode.TEXT, "Installing APM scripts...", "")
val scriptManager = getService(ScriptManager::class.java)
val scriptFinder = getService(ScriptFinder::class.java)
val modifiedScriptFinder = getService(ModifiedScriptFinder::class.java)
Expand All @@ -84,7 +85,8 @@ class ApmInstallHook : OsgiAwareInstallHook() {
val result: ExecutionResult = scriptManager.process(script, ExecutionMode.AUTOMATIC_RUN, resolver)
logStatus(context, script.path, result)
}
context.options.listener.onMessage(ProgressTrackerListener.Mode.TEXT, "APM scripts installed.", "")
context.options.listener?.onMessage(ProgressTrackerListener.Mode.TEXT, "APM scripts installed.", "")
logger.info("APM scripts installed.")
}

private fun getCurrentHook(context: InstallContext): String {
Expand All @@ -104,19 +106,20 @@ class ApmInstallHook : OsgiAwareInstallHook() {
}

private fun logStatus(context: InstallContext, scriptPath: String, result: ExecutionResult) {
context.options.listener.onMessage(ProgressTrackerListener.Mode.TEXT, "", scriptPath)
context.options.listener?.onMessage(ProgressTrackerListener.Mode.TEXT, "", scriptPath)
if (result.isSuccess) {
logger.info("Script successfully executed: $scriptPath")
} else {
val packageException = PackageException("Script cannot be executed properly: $scriptPath")
context.options.listener.onError(ProgressTrackerListener.Mode.TEXT, "", packageException)
context.options.listener?.onError(ProgressTrackerListener.Mode.TEXT, "", packageException)
logger.error("", packageException)
result.entries
.stream()
.filter { it.status == Status.ERROR }
.map { it.messages }
.flatMap { it.stream() }
.forEach { context.options.listener.onMessage(ProgressTrackerListener.Mode.TEXT, "E", it) }
context.options.listener.onMessage(ProgressTrackerListener.Mode.TEXT, "APM scripts installed (with errors, check logs!)", "")
.forEach { context.options.listener?.onMessage(ProgressTrackerListener.Mode.TEXT, "E", it) }
context.options.listener?.onMessage(ProgressTrackerListener.Mode.TEXT, "APM scripts installed (with errors, check logs!)", "")
throw packageException
}
}
Expand Down

0 comments on commit 539d41d

Please sign in to comment.