[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Re: add copyright information in EMF generated Java

Dave Steinberg wrote:

Hi Liangzhao,

There are no options in EMF 2.2 that will do this directly. You'll need to use dynamic templates with a custom Header.javajetinc that includes your copyright information.

You can do this by importing the templates/Header.javajetinc file from the org.eclipse.emf.codegen.ecore plug-in into your own project. Then, in your GenModel, under Templates & Merge, enable "Dynamic Templates" and set "Template Directory" with a workspace path (for example, "/MyProject/templates"). That should cause it to pick up the Header.javajetinc file when you generate the code, compiling the resulting templates on the fly. So, you can add whatever copyright information you want to have there. You can also copy in and modify Header.jetinc, Header.propertiesjetinc and Header.xmljetinc if you're concerned about other, non-Java artifacts.

Note that none of these changes will be merged into existing artifacts, so if you've already generated code, you'll need to delete it before regenerating and, where you've made changes manually, merge in the new headers.

Cheers,
Dave


If this is any help i do this on a per class basis by using annotations on my ecore. Here is a header template from project-name/jet-templates/Header.javajetinc

where my dynamic template directory is set to /project-name/jet-templates



------------8<------------8<------------8<------------8<------------8<------------8<

<%
String xxxx_fileComment = "comment missing!!";
final GenBase xxxx_genBase = argument instanceof GenBase ? (GenBase) argument : (GenBase)((Object[])argument)[0];
org.eclipse.emf.ecore.EAnnotation xxxx_EcoreClassAnnotation = xxxx_genBase.getEcoreModelElement().getEAnnotation("http://www.leeds.ac.uk/xxxx/yyyy";);
if (xxxx_EcoreClassAnnotation != null) {
org.eclipse.emf.common.util.EMap xxxx_details = xxxx_EcoreClassAnnotation.getDetails();
if (xxxx_details.containsKey("file comment")) {
xxxx_fileComment = (String)xxxx_details.get("file comment");
}
}
%>
<% for (String xxxx_line : xxxx_fileComment.split("\n")){ %>
* <%=xxxx_line%>
<%}%>
*/


------------8<------------8<------------8<------------8<------------8<------------8<

and here is a sample segment of ecore model

------------8<------------8<------------8<------------8<------------8<------------8<

<eClassifiers xsi:type="ecore:EClass" name="Wibble" eSuperTypes="#//wobble/object">
<eAnnotations source="http://www.leeds.ac.uk/xxxx-ecore-1.0/xxxx_genmodel";>
<details key="file comment" value="whatever copyright code you need"/>
</eAnnotations>



------------8<------------8<------------8<------------8<------------8<------------8<

hope this helps
regards
gary


liangzhao zeng wrote:
Hi, Dave

thanks a lot for the info. However, I use the EMF 2.2 that come with the RSA 7.0. any suggestions? I notice that there are property about the templates&merge, but not sure how to use them.

Cheers,

Liangzhao