Unfortunately I'm not a maven user, so I can't really help here. But hopefully someone else could chime in.
On Sun, May 3, 2020 at 11:39 AM Faizel Dakri <[email protected]> wrote: > Hi John, > > Thank you for the pointers. I didn’t see any way to easily get the > metadata into my templates via a custom tool, however I thought it would be > a good exercise to figure out how to do it anyway. I’ve tried to follow > your advice (as well as looking at the cayenne source), but I’m having > difficulty getting my properties file loaded via the > org.apache.velocity.tools property. > > I’m running cgen via my maven build and I can confirm the cgen goal is > running (I can see that it is picking up my custom templates), however I’ve > been unsuccessful in getting it to pick up my custom properties file where > my tool is specified. Is there a sanctioned way of telling the cgen goal > about this property? I’ve tried using both the maven properties plugin and > passing on the command line, but I have yet to succeed in loading my file. > At least it appears unsuccessful. When I debug my maven build, I see that > there is an unresolved reference for my tool when velocity is processing my > templates. > > Assuming I’m eventually successful in loading my properties, I have one > more question. You mention that any custom velocity tool (and properties > files) must be on the class path. I’m assuming that this is the class path > in effect while the cgen goal is running. How does one go about altering > the class path for a maven plugin? Or does the plugin pickup the project > dependencies? (Apologies if this is a basic question, I’m not yet a Maven > expert). > > Thanks again for your help, > > F > > > > On Apr 29, 2020, at 02:14 PM, John Huss <[email protected]> wrote: > > > > I haven't used the metadata / comments yet, so I can't help with that > > specifically. > > > > For the using a custom tool with cgen you need to define a > > "tools.properties" file in your class path (I would just put it at the > > root) with contents like this: > > > > > > tools.toolbox = application > > > > tools.application.*myUtils* = com.something.tools.MyCgenUtils > > > > > > The referenced class (and the properties file) needs to be on the class > > path when you invoke cgen. The class should contain public instance (not > > static) methods in bean-style that work on parts of the DataMap, like an > > ObjEntity or a ObjAttribute (or their properties). For example: > > > > > > *public* *boolean* hasReverse(ObjRelationship rel) {} > > > > Then when you invoke cgen you need to set a system property to point to > the > > location of your tools.properties file, like this if it is in the class > > path root: > > > > -Dorg.apache.velocity.tools=/tools.properties > > > > > > Your template can reference an instance of your util class using the > short > > name defined for it in the tools.properties file: > > > > > > ${*myUtils*.getGwtType($attr.Type)} > > > > > > This process has multiple points of failure, so it can be hard to > > setup correctly, but hopefully you can get it working. > > > > On Wed, Apr 29, 2020 at 11:29 AM Faizel Dakri <[email protected]> wrote: > > > >> Hello all, > >> > >> Being fairly new to Cayenne, this may be an obvious question. I would > like > >> to know how I can access the metadata stored on an > >> attribute/relationship/entity in the datamap from within my velocity > >> templates (I think in CayenneModeler, this is how the comment field is > >> stored for a datamap item). I think this is the metadata stored via the > >> newish InfoExtension facility. > >> > >> I see that the DataChannelMetaData can be injected into a DataDomain > (and > >> I’m doing that at runtime in my server app), however I cannot see how to > >> get to this metadata from an attribute or relationship or entity in the > >> context of a velocity template. Is this possible? I would think it is > since > >> Modeler is able to read/write those comments, but I am having a hard > time > >> doing so in a template. > >> > >> I did see that there is a hook to provide my own tool into the cgen > tool. > >> Would this be a potential path to look into if the metadata is not > >> accessible directly in the templates as is? If so, any pointers on > where to > >> start? > >> > >> Thanks for any advice. > >> > >> F > >> > >> -- > >> Faizel Dakri > >> [email protected] > >> > >> > >> > >> > >
