Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storing asked parameters fail if value is GString #135

Closed
aalmiray opened this issue Nov 25, 2014 · 4 comments
Closed

Storing asked parameters fail if value is GString #135

aalmiray opened this issue Nov 25, 2014 · 4 comments
Labels
Milestone

Comments

@aalmiray
Copy link
Contributor

When using the built-in ask() method template developers have to explicitly convert any values from GString to String otherwise the following error appears on screen (using --stacktrace)

Post install script caused an exception, project might be corrupt: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String
The unpacked template will remain in place to help you diagnose the problem

java.lang.ClassCastException: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String
    at java.util.Properties.store0(Properties.java:828)
    at java.util.Properties.store(Properties.java:765)
    at java_util_Properties$store.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at uk.co.cacoethes.lazybones.commands.InstallationScriptExecuter$_persistParentParams_closure2.doCall(InstallationScriptExecuter.groovy:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
    at groovy.lang.Closure.call(Closure.java:423)
    at groovy.lang.Closure.call(Closure.java:439)
    at org.codehaus.groovy.runtime.IOGroovyMethods.withWriter(IOGroovyMethods.java:1134)
    at org.codehaus.groovy.runtime.ResourceGroovyMethods.withWriter(ResourceGroovyMethods.java:1806)
    at org.codehaus.groovy.runtime.dgm$883.invoke(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at uk.co.cacoethes.lazybones.commands.InstallationScriptExecuter.persistParentParams(InstallationScriptExecuter.groovy:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:207)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
    at uk.co.cacoethes.lazybones.commands.InstallationScriptExecuter.runPostInstallScript(InstallationScriptExecuter.groovy:69)
    at uk.co.cacoethes.lazybones.commands.InstallationScriptExecuter$runPostInstallScript$0.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:153)
    at uk.co.cacoethes.lazybones.commands.InstallationScriptExecuter.runPostInstallScriptWithArgs(InstallationScriptExecuter.groovy:47)
    at uk.co.cacoethes.lazybones.commands.InstallationScriptExecuter.runPostInstallScriptWithArgs(InstallationScriptExecuter.groovy)
    at uk.co.cacoethes.lazybones.commands.InstallationScriptExecuter$runPostInstallScriptWithArgs.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
    at uk.co.cacoethes.lazybones.commands.CreateCommand.doExecute(CreateCommand.groovy:102)
    at uk.co.cacoethes.lazybones.commands.AbstractCommand.execute(AbstractCommand.groovy:29)
    at uk.co.cacoethes.lazybones.LazybonesMain.main(LazybonesMain.groovy:90)

Problem is that parameters are stored as is using a Properties object. Workaround is to explicitly invoke .toString() on values such as

props.project_url = ask("Define value for 'url' [https://github.com/${username}/${props.project_name}]: ", "https://github.com/${username}/${props.project_name}".toString(), 'url')

It would be better if the Lazybones runtime performed this conversion internally.

@pledbrook
Copy link
Owner

Thanks for the report. Will look into it at some point.

@aalmiray
Copy link
Contributor Author

Hackergarten at GGX sounds like a good opportunity to me 😉

@pledbrook pledbrook added the bug label Dec 17, 2014
@pledbrook
Copy link
Owner

Hmmm...this is definitely a weak area. The ask() method doesn't assume that the default value is of any particular type, and yet it performs no conversion on the string that a user enters. Later on, the InstallationScriptExecuter persists the parameter values on the assumption that they are all strings.

So there are two options here:

  1. The ask() method requires the default value to be a string. It is then up to the post-install script to perform the necessary conversion. Since that conversion may be required anyway when the user provides an alternative value from the command line, we'll gain consistency without complicating the life of the template developer.
  2. See option 1. The alternative would be to incorporate the converters currently used for the config command and perform the conversion during the ask() method and when the variables are persisted to a properties file. I feel this complicates things without providing a great deal of value though. Simpler to allow template developers direct access to the converters if they wish.

Option 1 is a breaking change, but a necessary one I feel. I'll put it into version 0.9.

@pledbrook pledbrook added this to the 0.9 milestone Dec 18, 2014
pledbrook added a commit that referenced this issue Dec 22, 2014
Fixes issue #135. Both incoming values (from the user at the command line) and
outgoing values (in the saved parent parameters) are based on strings, so the
`ask()` method now requires its default values to be strings as well. This means
that the template developer needs to manage any necessary conversions to other
types.
@pledbrook
Copy link
Owner

Need to report this as a breaking change in the release notes as I want with option 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants