如何自动将时间戳字段添加到标记提交日期的 java class
How can I automatically add a datestamp field to a java class marking a commit date
I can't figure out a nice, succinct title for this question, so bear with me!
My overall goal is to have a variable in my source code which give the date, time, (and possibly commit id) of a class so that when exceptions get caught, I could output the error along with that said variable so I can easily track the source code version giving me the grief.
I'd like to accomplish one of two things. When I edit a java file such that mercurial or git picks up a change, I'd like for the class which got modified to get a new field:
public static final String commitTime = "yyyymmdd - hhmmss - <commitid>";
Or if inner class is too much, something appended to the bottom of the file such as:
public lass failname_stamp {
public static final String commitTime = "yyyymmdd - hhmmss - <commitid>";
}
Or something to that effect.
This doesn't have to be specific to mercurial or git, however it would be a feature that ties in with them. So when a commit happens on a file, a process will 运行 add such data to the file itself.
I imagine such a tool would need to integrate with my IDE (eclipse and intelliJ) if not a 3rd party plugin for my mercurial or git instance.
I know I have seen source code files with comment fields at the top such as:
/**
* @since 1.2
*/
But I'd like something more thorough and specific and not relying on a human to manually update comments.
源本身无法知道正在签入的版本,除非您手动添加某种版本字符串 - 但这既乏味又容易失败。
但是,我相信您不希望在 source 代码中使用此信息,而是希望在构建时生成此信息(例如,不同的构建环境也可能导致不同的结果),您可能会在其中生成随目标代码一起提供的 属性 文件。
我不会说 Java,但我为我的 python 项目解决了这个问题:
- 当它是运行来自版本库时,查询并使用代码版本,例如错误/崩溃报告 Querying hg for the checked-out version
- 当 运行 在存储库之外时,程序会查找生成的版本文件。我确实将我的代码包与此类预生成的版本文件一起发布;它是自动生成的,并与我的编译场中使用的构建脚本中其他未触及的代码捆绑在一起。 Checking for presence of pre-generated version info, if code executed outside repository
我强烈建议在您的代码中采用类似的机制:它既灵活又易于使用。查询存储库属性并回退使用您随代码包一起提供的 属性 文件(如果两者都不存在,则报告 'unknown version')
I can't figure out a nice, succinct title for this question, so bear with me!
My overall goal is to have a variable in my source code which give the date, time, (and possibly commit id) of a class so that when exceptions get caught, I could output the error along with that said variable so I can easily track the source code version giving me the grief.
I'd like to accomplish one of two things. When I edit a java file such that mercurial or git picks up a change, I'd like for the class which got modified to get a new field:
public static final String commitTime = "yyyymmdd - hhmmss - <commitid>";
Or if inner class is too much, something appended to the bottom of the file such as:
public lass failname_stamp {
public static final String commitTime = "yyyymmdd - hhmmss - <commitid>";
}
Or something to that effect.
This doesn't have to be specific to mercurial or git, however it would be a feature that ties in with them. So when a commit happens on a file, a process will 运行 add such data to the file itself.
I imagine such a tool would need to integrate with my IDE (eclipse and intelliJ) if not a 3rd party plugin for my mercurial or git instance.
I know I have seen source code files with comment fields at the top such as:
/**
* @since 1.2
*/
But I'd like something more thorough and specific and not relying on a human to manually update comments.
源本身无法知道正在签入的版本,除非您手动添加某种版本字符串 - 但这既乏味又容易失败。
但是,我相信您不希望在 source 代码中使用此信息,而是希望在构建时生成此信息(例如,不同的构建环境也可能导致不同的结果),您可能会在其中生成随目标代码一起提供的 属性 文件。
我不会说 Java,但我为我的 python 项目解决了这个问题:
- 当它是运行来自版本库时,查询并使用代码版本,例如错误/崩溃报告 Querying hg for the checked-out version
- 当 运行 在存储库之外时,程序会查找生成的版本文件。我确实将我的代码包与此类预生成的版本文件一起发布;它是自动生成的,并与我的编译场中使用的构建脚本中其他未触及的代码捆绑在一起。 Checking for presence of pre-generated version info, if code executed outside repository
我强烈建议在您的代码中采用类似的机制:它既灵活又易于使用。查询存储库属性并回退使用您随代码包一起提供的 属性 文件(如果两者都不存在,则报告 'unknown version')