You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Juan Manuel Diaz Lara <jm...@yahoo.com.INVALID> on 2020/01/18 00:47:01 UTC

Template path strip out home directory,

I am using Cayenn 4.1.RC and trying to user custom templates. I created a new template, an selected in preferences, when generating I choose Advance and selecte my new template, generations fails with "Unable to find resource ..." and the template path, but this path does not have my home directory, it shows as a relative path, but in preferencis it has an absolute path.
I revies my data map xml in a text editor and then template path is relative, without my home directory as prefix.
So, I run CayenneModeler from my home directory and the template is found correctly. This is strange, because en Preferences path are absolute, but when generating they are used as relative to my home directory.
I do not know if this is a bug o I am missing something.
Thanks.

Atte. Juan Manuel Díaz Lara

Re: Template path strip out home directory,

Posted by Andrus Adamchik <an...@objectstyle.org>.
Yes, that's the idea. Just put custom templates somewhere in your project source tree, and things should work.

But there's indeed an inconsistency in the Modeler. Custom templates are still modeled as absolute file paths in the Modeler preferences, and shared between projects. This approach is obsolete and is a leftover from the earlier versions of the Modeler. We should remove templates from preferences and let the user select them as relative paths per-project.

Andrus


> On Jan 20, 2020, at 8:18 PM, Juan Manuel Diaz Lara <jm...@yahoo.com.INVALID> wrote:
> 
> to summarize, currently templates to generate project classes must be realative to project. Thanks Angus.
> 
> Atte. Juan Manuel Díaz Lara 
> 
>    On Monday, January 20, 2020, 10:09:34 AM CST, Andrus Adamchik <an...@objectstyle.org> wrote:  
> 
> 
>> I recommend using a build task because you get consistency and you don't have to re-select the templates over and over.
> 
> 4.1 introduced storing cgen and dbimport preferences right in the DataMap XML file, so picking templates every time should no longer be required. I suspect the original issue is related to this fact - the templates need to be in the project and in version control. 
> 
> There may be still inconsistencies in the GUI in handling of custom templates. Need to investigate that, and will do my best to follow up.
> 
> (FWIW, the feature above plus interactive DB import made me like the Modeler again :) In the span of the last 2 years I went from no / occasional Modeler use to full use. I can now avoid context switching between modeling and build tools, and also don't need to write manual scripts.)
> 
> Andrus
> 
> 
>> On Jan 20, 2020, at 6:19 PM, John Huss <jo...@gmail.com> wrote:
>> 
>> I can't directly answer your question as I don't use modeler directly for
>> class generation, but use a build task instead. I recommend using a build
>> task because you get consistency and you don't have to re-select the
>> templates over and over. I use *ant* for this, but it can be done with
>> maven too:
>> 
>> <path id="cgen.classpath">
>> 
>> <fileset dir="lib" includes="cayenne-*.jar" />
>> 
>> <fileset dir="lib" includes="commons-*.jar" />
>> 
>> <fileset dir="lib" includes="velocity-*.jar" />
>> 
>> <fileset dir="lib" includes="log4j-*.jar" />
>> 
>> <fileset dir="lib" includes="slf4j-*.jar" />
>> 
>> </path>
>> 
>> 
>> <typedef resource="org/apache/cayenne/tools/antlib.xml">
>> 
>> <classpath refid="cgen.classpath"/>
>> 
>> </typedef>
>> 
>> 
>> <target name="generate_java">
>> 
>> <cgen map="src/YourDataMap.map.xml"
>> 
>> superpkg="com.yourpackage.auto"
>> 
>> createpropertynames="true"
>> 
>> supertemplate="${basedir}/cgen/superclass.vm"
>> 
>> template=${basedir}/cgen/subclass.vm"
>> 
>> destDir="src"
>> 
>> outputPattern="*.java"
>> 
>> encoding="UTF-8"
>> 
>> mode="all"
>> 
>> />
>> 
>> </target>
>> 
>> On Fri, Jan 17, 2020 at 6:47 PM Juan Manuel Diaz Lara
>> <jm...@yahoo.com.invalid> wrote:
>> 
>>> I am using Cayenn 4.1.RC and trying to user custom templates. I created a
>>> new template, an selected in preferences, when generating I choose Advance
>>> and selecte my new template, generations fails with "Unable to find
>>> resource ..." and the template path, but this path does not have my home
>>> directory, it shows
> 
>>> as a relative path, but in preferencis it has an
>>> absolute path.
>>> I revies my data map xml in a text editor and then template path is
>>> relative, without my home directory as prefix.
>>> So, I run CayenneModeler from my home directory and the template is found
>>> correctly. This is strange, because en Preferences path are absolute, but
>>> when generating they are used as relative to my home directory.
>>> I do not know if this is a bug o I am missing something.
>>> Thanks.
>>> 
>>> Atte. Juan Manuel Díaz Lara


Re: Template path strip out home directory,

Posted by Juan Manuel Diaz Lara <jm...@yahoo.com.INVALID>.
to summarize, currently templates to generate project classes must be realative to project. Thanks Angus.

Atte. Juan Manuel Díaz Lara 

    On Monday, January 20, 2020, 10:09:34 AM CST, Andrus Adamchik <an...@objectstyle.org> wrote:  
 
 
> I recommend using a build task because you get consistency and you don't have to re-select the templates over and over.

4.1 introduced storing cgen and dbimport preferences right in the DataMap XML file, so picking templates every time should no longer be required. I suspect the original issue is related to this fact - the templates need to be in the project and in version control. 

There may be still inconsistencies in the GUI in handling of custom templates. Need to investigate that, and will do my best to follow up.

(FWIW, the feature above plus interactive DB import made me like the Modeler again :) In the span of the last 2 years I went from no / occasional Modeler use to full use. I can now avoid context switching between modeling and build tools, and also don't need to write manual scripts.)

Andrus


> On Jan 20, 2020, at 6:19 PM, John Huss <jo...@gmail.com> wrote:
> 
> I can't directly answer your question as I don't use modeler directly for
> class generation, but use a build task instead. I recommend using a build
> task because you get consistency and you don't have to re-select the
> templates over and over. I use *ant* for this, but it can be done with
> maven too:
> 
> <path id="cgen.classpath">
> 
> <fileset dir="lib" includes="cayenne-*.jar" />
> 
> <fileset dir="lib" includes="commons-*.jar" />
> 
> <fileset dir="lib" includes="velocity-*.jar" />
> 
> <fileset dir="lib" includes="log4j-*.jar" />
> 
> <fileset dir="lib" includes="slf4j-*.jar" />
> 
> </path>
> 
> 
> <typedef resource="org/apache/cayenne/tools/antlib.xml">
> 
> <classpath refid="cgen.classpath"/>
> 
> </typedef>
> 
> 
> <target name="generate_java">
> 
> <cgen map="src/YourDataMap.map.xml"
> 
> superpkg="com.yourpackage.auto"
> 
> createpropertynames="true"
> 
> supertemplate="${basedir}/cgen/superclass.vm"
> 
> template=${basedir}/cgen/subclass.vm"
> 
> destDir="src"
> 
> outputPattern="*.java"
> 
> encoding="UTF-8"
> 
> mode="all"
> 
> />
> 
> </target>
> 
> On Fri, Jan 17, 2020 at 6:47 PM Juan Manuel Diaz Lara
> <jm...@yahoo.com.invalid> wrote:
> 
>> I am using Cayenn 4.1.RC and trying to user custom templates. I created a
>> new template, an selected in preferences, when generating I choose Advance
>> and selecte my new template, generations fails with "Unable to find
>> resource ..." and the template path, but this path does not have my home
>> directory, it shows

>> as a relative path, but in preferencis it has an
>> absolute path.
>> I revies my data map xml in a text editor and then template path is
>> relative, without my home directory as prefix.
>> So, I run CayenneModeler from my home directory and the template is found
>> correctly. This is strange, because en Preferences path are absolute, but
>> when generating they are used as relative to my home directory.
>> I do not know if this is a bug o I am missing something.
>> Thanks.
>> 
>> Atte. Juan Manuel Díaz Lara
  

Re: Template path strip out home directory,

Posted by Andrus Adamchik <an...@objectstyle.org>.
> I recommend using a build task because you get consistency and you don't have to re-select the templates over and over.

4.1 introduced storing cgen and dbimport preferences right in the DataMap XML file, so picking templates every time should no longer be required. I suspect the original issue is related to this fact - the templates need to be in the project and in version control. 

There may be still inconsistencies in the GUI in handling of custom templates. Need to investigate that, and will do my best to follow up.

(FWIW, the feature above plus interactive DB import made me like the Modeler again :) In the span of the last 2 years I went from no / occasional Modeler use to full use. I can now avoid context switching between modeling and build tools, and also don't need to write manual scripts.)

Andrus


> On Jan 20, 2020, at 6:19 PM, John Huss <jo...@gmail.com> wrote:
> 
> I can't directly answer your question as I don't use modeler directly for
> class generation, but use a build task instead. I recommend using a build
> task because you get consistency and you don't have to re-select the
> templates over and over. I use *ant* for this, but it can be done with
> maven too:
> 
> <path id="cgen.classpath">
> 
> <fileset dir="lib" includes="cayenne-*.jar" />
> 
> <fileset dir="lib" includes="commons-*.jar" />
> 
> <fileset dir="lib" includes="velocity-*.jar" />
> 
> <fileset dir="lib" includes="log4j-*.jar" />
> 
> <fileset dir="lib" includes="slf4j-*.jar" />
> 
> </path>
> 
> 
> <typedef resource="org/apache/cayenne/tools/antlib.xml">
> 
> <classpath refid="cgen.classpath"/>
> 
> </typedef>
> 
> 
> <target name="generate_java">
> 
> <cgen map="src/YourDataMap.map.xml"
> 
> superpkg="com.yourpackage.auto"
> 
> createpropertynames="true"
> 
> supertemplate="${basedir}/cgen/superclass.vm"
> 
> template=${basedir}/cgen/subclass.vm"
> 
> destDir="src"
> 
> outputPattern="*.java"
> 
> encoding="UTF-8"
> 
> mode="all"
> 
> />
> 
> </target>
> 
> On Fri, Jan 17, 2020 at 6:47 PM Juan Manuel Diaz Lara
> <jm...@yahoo.com.invalid> wrote:
> 
>> I am using Cayenn 4.1.RC and trying to user custom templates. I created a
>> new template, an selected in preferences, when generating I choose Advance
>> and selecte my new template, generations fails with "Unable to find
>> resource ..." and the template path, but this path does not have my home
>> directory, it shows

>> as a relative path, but in preferencis it has an
>> absolute path.
>> I revies my data map xml in a text editor and then template path is
>> relative, without my home directory as prefix.
>> So, I run CayenneModeler from my home directory and the template is found
>> correctly. This is strange, because en Preferences path are absolute, but
>> when generating they are used as relative to my home directory.
>> I do not know if this is a bug o I am missing something.
>> Thanks.
>> 
>> Atte. Juan Manuel Díaz Lara


Re: Template path strip out home directory,

Posted by John Huss <jo...@gmail.com>.
I can't directly answer your question as I don't use modeler directly for
class generation, but use a build task instead. I recommend using a build
task because you get consistency and you don't have to re-select the
templates over and over. I use *ant* for this, but it can be done with
maven too:

<path id="cgen.classpath">

<fileset dir="lib" includes="cayenne-*.jar" />

<fileset dir="lib" includes="commons-*.jar" />

<fileset dir="lib" includes="velocity-*.jar" />

<fileset dir="lib" includes="log4j-*.jar" />

<fileset dir="lib" includes="slf4j-*.jar" />

</path>


<typedef resource="org/apache/cayenne/tools/antlib.xml">

<classpath refid="cgen.classpath"/>

</typedef>


<target name="generate_java">

<cgen map="src/YourDataMap.map.xml"

superpkg="com.yourpackage.auto"

createpropertynames="true"

supertemplate="${basedir}/cgen/superclass.vm"

template=${basedir}/cgen/subclass.vm"

destDir="src"

outputPattern="*.java"

encoding="UTF-8"

mode="all"

/>

</target>

On Fri, Jan 17, 2020 at 6:47 PM Juan Manuel Diaz Lara
<jm...@yahoo.com.invalid> wrote:

> I am using Cayenn 4.1.RC and trying to user custom templates. I created a
> new template, an selected in preferences, when generating I choose Advance
> and selecte my new template, generations fails with "Unable to find
> resource ..." and the template path, but this path does not have my home
> directory, it shows as a relative path, but in preferencis it has an
> absolute path.
> I revies my data map xml in a text editor and then template path is
> relative, without my home directory as prefix.
> So, I run CayenneModeler from my home directory and the template is found
> correctly. This is strange, because en Preferences path are absolute, but
> when generating they are used as relative to my home directory.
> I do not know if this is a bug o I am missing something.
> Thanks.
>
> Atte. Juan Manuel Díaz Lara