On 12/05/2011, at 1:53 AM, Rene Groeschke wrote:

> Hi,
> I got it basically working with your hint. I've already noticed that this is 
> not (yet) public api. FYI: Unfortunately, If I mark     "ExampleModel" as an 
> input property in my task i got an error:
> ---------------
> java.io.NotSerializableException: 
> org.gradle.api.internal.AsmBackedClassGenerator$MixInDynamicObject
> ---------------
> to bad. That's the price on skating on thin ice, I think.

Could you add a jira issue for this? A decorated object should be serializable 
if the undecorated object is.

When you use @Input on a property, the property value is serialized when the 
task is executed. Next time the task is executed, the value is deserialized and 
then compared against the new value using equals(). So, this means that your 
ExampleModel class will need to be serializable, and implement a useful 
equals() method.

An alternative, depending on what you're doing, is to use @Nested on your model 
property, rather than using @Input. This will allow you to use the Gradle 
annotation on the properties of the model object:

class ExampleTask {
    @Nested ExampleModel model
}

class ExampleModel {
    @Input String title
    @InputDirectory @SkipWhenEmpty File someDir
}

There are a few benefit with this: you can apply different constraints to 
different properties, Gradle will take care of the serialization and 
comparison, and you get a better info message telling you what's changed.



> 
> regards,
> René
> 
> 
> 
> 
> Am 11.05.11 16:48, schrieb Szczepan Faber:
>> 
>> Hey,
>> 
>> Bear in mind that this is not fully public api :)
>> 
>> def ExampleModel model = 
>> services.get(ClassGenerator).newInstance(ExampleModel)
>> 
>> Then you should be able to put convention properties, e.g:
>> 
>> model.conventionMapping.someProperty = { ... }
>> 
>> Cheers,
>> Szczepan
>> 
>> On Wed, May 11, 2011 at 10:31 AM, Rene Groeschke <[email protected]> wrote:
>> 
>> Hi there,
>> I have another question about convention mapping objects.
>> I have a task that has a custom class as model:
>> 
>> -------------
>> class ExampleTask implements ConventionTask{
>>    def ExampleModel model = new ExampleModel();
>> }
>> 
>> class ExampleModel {
>>    String title
>> }
>> -------------
>> 
>> now I would like to add a property called exampleTitle as a 
>> convention-property to my project.
>> 
>> In my ExamplePlugin I have the following line:
>> -------------
>>  siteTask.conventionMapping.model.title = { pluginConvention.exampleTitle }
>> -------------
>> 
>> when running my tests now, I get the following error:
>> > groovy.lang.MissingPropertyException: No such property: model for class: 
>> > org.gradle.api.internal.ConventionAwareHelper
>> 
>> 
>> Anybody an idea how to wire the title attribute to the "exampleTitle" 
>> attribute of my pluginConvention? I'm not sure if this is a gradle question 
>> or just the result of my lacking groovy knowledge.
>> 
>> regards,
>> René
>> 
>> -- 
>> -----------------------
>> regards René
>> 
>> rene groeschke
>> http://www.breskeby.com                 
>> @breskeby
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>> 
>>   http://xircles.codehaus.org/manage_email
>> 
>> 
>> 
> 
> 
> -- 
> -----------------------
> regards René
> 
> rene groeschke
> http://www.breskeby.com
> @breskeby


--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com

Reply via email to