Having an interesting situation I cannot understan...
# plugin-development
s
Having an interesting situation I cannot understand. As part of a plugin I register the following DSL extensions:
Copy code
public abstract class HibernateOrmSpec {
	...

	@Optional
	abstract public Property<EnhancementSpec> getEnhancement();

	public void enhancement(Action<EnhancementSpec> action) {
		EnhancementSpec spec = getObjectFactory().newInstance( EnhancementSpec.class );
		action.execute( spec );
		getEnhancement().set( spec );
	}
}

abstract public class EnhancementSpec {
	abstract public Property<Boolean> getEnableLazyInitialization();
	...
}
Later, I try to see if the user specified this "enhancement" extension :
if ( !getEnhancement().isPresent() ) ...
The odd part is this... This works as expected:
Copy code
hibernate {
    enhancement {
    }
}
However, this does not:
Copy code
hibernate {
    enhancement
}
Now I can easily accept that this second form is "not valid". But the problem I am having is actually being able to recognize this situation to properly handle it (whether that be treat it as the first form, throw an exception, etc.). The problem is that, as far as I can tell, Gradle just ignores it (it being the "enhancement" token). Its not added to ext properties or anything like that. Any idea what Gradle actually does with that?
o
I believe it should just be calling
getEnhancement()
, as both Kotlin and Groovy support calling getters via a property name. I think it's technically valid in both to just have that as a standalone statement, as weird as it is.
s
ok, so then there is just no way to determine this situation as calling getEhhancement() won't actually set any value. bummer
Thanks for the pointer