Netcentric / vault-upgrade-hook

Jackrabbit FileVault Install Hook to perform additional actions during package installation
Eclipse Public License 1.0
19 stars 13 forks source link

resourceResolver through Groovy script #35

Closed adolfodepazvela closed 6 years ago

adolfodepazvela commented 6 years ago

Hi, I'am unable to access the resourceResolver through the groovy script? Looks like the vault-upgrade-hook use the com.icfolson.aem.groovy.console.GroovyConsoleService, when it parses the script, I think is supposed to find the service.

Any advice how I can use the resourceResolver?

Thanks

otarsko commented 6 years ago

@adolfodepazvela , it should be possible. Can you post your AEM version, branch/version (develop?) you are using, and it also would be nice if you provide example script which is not working + upgrade action configuration. Then I can take a look and try to find the problem.

adolfodepazvela commented 6 years ago

@otarsko, Hi, I use AEM 6.2, I compiled the develop branch of the hook. Here is part of my code, it is executed on the groovy script console but not with this tool, even if it uses the same API. Looks like the bindings are not available when executing the code from this tool. I will check from my side into the code, to see if we can use the bindings.

I get: no such property: resourceResolver for class

import groovy.transform.Field
import com.day.cq.tagging.Tag
import org.apache.sling.api.resource.ResourceResolver
import org.apache.sling.api.resource.ResourceResolverFactory
import com.day.cq.tagging.TagManager

@Field tagManager = resourceResolver.adaptTo(com.day.cq.tagging.TagManager)
@Field tagManager2 = slingRequest.getResourceResolver().adaptTo(com.day.cq.tagging.TagManager)

Thanks

Adolfo

otarsko commented 6 years ago

@adolfodepazvela, I've put your code into the /vault-upgrade-hook/samples/groovy-package/src/main/upgrader/always/#35-test.groovy from develop branch, added print(tagManager) at the end, built this sample package, installed and got in the logs:

02.03.2018 18:07:53.216 *INFO* [qtp42940176-3234] biz.netcentric.vlt.upgrade.UpgradeProcessor executing [biz.netcentric.vlt.upgrade.UpgradeInfo@27b0e74c [node=Node[NodeDelegate{tree=/etc/packages/vault-upgrade-hook-samples/sample-groovy-package-1.0.1-SNAPSHOT.zip/jcr:content/vlt:definition/upgrader/always: { jcr:primaryType = sling:Folder, jcr:createdBy = admin, jcr:created = 2018-03-02T18:07:29.660+01:00, handler = groovyconsole, runMode = always, always.groovy = { ... }, #35-test.groovy = { ... }}}], status=biz.netcentric.vlt.upgrade.UpgradeStatus@68dc978a [node=Node[NodeDelegate{tree=/var/upgrade/vault-upgrade-hook-samples/sample-groovy-package: { jcr:primaryType = nt:unstructured}}], version=null], installationMode=ON_CHANGE, defaultPhase=PREPARE, handler=biz.netcentric.vlt.upgrade.handler.groovy.GroovyConsoleHandler@7b49aabc, actions={PREPARE=[biz.netcentric.vlt.upgrade.handler.groovy.GroovyScript@c0865901, biz.netcentric.vlt.upgrade.handler.groovy.GroovyScript@5ad638ec], PREPARE_FAILED=[], INSTALLED=[], INSTALL_FAILED=[], END=[]}]]: [[biz.netcentric.vlt.upgrade.handler.groovy.GroovyScript@c0865901, biz.netcentric.vlt.upgrade.handler.groovy.GroovyScript@5ad638ec]]
02.03.2018 18:07:53.295 *INFO* [qtp42940176-3234] biz.netcentric.vlt.upgrade.handler.groovy.GroovyScript Executed [#35-test.groovy]: [00:00:00.001]
com.day.cq.tagging.impl.JcrTagManagerImpl@71a5fb26
---

02.03.2018 18:07:53.298 *INFO* [qtp42940176-3234] biz.netcentric.vlt.upgrade.UpgradeProcessor executed GroovyScript[#35-test.groovy, 81ms] - /etc/packages/vault-upgrade-hook-samples/sample-groovy-package-1.0.1-SNAPSHOT.zip/jcr:content/vlt:definition/upgrader/always/#35-test.groovy

So it works fine for me. So far, I would assume that in your upgrade action definition (in my case it was /vault-upgrade-hook/samples/groovy-package/src/main/upgrader/always) you have handler="script"(or it's not defined at all) instead of handler="groovyconsole".

Can you please check your definition one more time?

otarsko commented 6 years ago

@adolfodepazvela is there any update regarding your issue? Was it solved?

adolfodepazvela commented 6 years ago

Sorry for the late response! Finally, it is solved now!

Thanks

Adolfo

adolfodepazvela commented 6 years ago

Do you know if there is a way to print the output in the package manager console? Thanks

nc-andreashaller commented 6 years ago

Hi @adolfodepazvela, the output of your GroovyConsole script (everything written out with println) is automatically added to the package manager output. Though the formatting can be a bit off because the console does not support line breaks. Best, Andreas