Eclipse Acceleo M2T-将时间戳写入生成的文件

Eclipse Acceleo M2T-将时间戳写入生成的文件,eclipse,acceleo,ocl,ecore,Eclipse,Acceleo,Ocl,Ecore,我正在使用*.mtl文件中定义的不同Acceleo模板生成一些文件 在这些文件的顶部,我需要编写如下内容: #----------------------------------------------------------------------------- # Project automatically generated by XXX at (add timestamp here) #---------------------------------------------------

我正在使用*.mtl文件中定义的不同Acceleo模板生成一些文件

在这些文件的顶部,我需要编写如下内容:

#-----------------------------------------------------------------------------
# Project automatically generated by XXX at (add timestamp here)
#-----------------------------------------------------------------------------
如何在每次生成文件时动态生成此时间戳

谢谢

编辑:我解决了这个问题,如下所述

模块
声明之后,添加
查询
声明:

[module generate('platform:/resource/qt48_model/qt48_xmlschema.xsd') ]
[comment get timestamp/]
[query public getCurrentTime(c : OclAny) : String =
invoke('org.eclipse.acceleo.qt_test_api.generator.common.GenerationSupport', 'getCurrentTime()', Sequence{}) /]
然后,创建一个名为
GenerationSupport
的类,并添加一个名为
getCurrentTime()
的方法:


你必须使用所谓的“服务”。 它基本上只是类中的一个公共方法,它将以字符串形式返回日期,并按照您想要的格式进行格式化。
查看acceleo教程,了解如何使用服务,一切都在那里。

尝试以下内容:

[query public getCurrentTime(traceabilityContext : OclAny): 
    String = invoke('yourPackage.YourJavaClass', 'getCurrentTime()', Sequence{})
/]
在Java类中,声明一个具有以下功能的方法:

public String getCurrentTime(){
  return customDate;
}
其中“customDate”应为自定义格式的字符串: new Date().toString(),使用mm/dd/yyyy或任何您想要的格式

请不要忘记将包含此Java类的包添加到MANIFEST.MF中的导出包中


祝你好运

有人正在寻找快速解决方案:String=invoke('java.util.Date','toString()',Sequence{})
public String getCurrentTime(){
  return customDate;
}