Reputation: 1436
I'm using git plugin for Eclipse, as do my daily build, it becomes difficult to track which version of the build from the git is been tested. Unless there is way to auto fetch the branch and commit id from the git plugin and generate a static String version information in the code during each build. Is it possible ?
I prefer not to use a git java API from my code, like say i can fetch the git information with JGit API, if i point it to a local repos, however, that is not how it should be done, as it will create issues with application deployment. Rather should be Eclipse plugin that will generate a string during the build.
Upvotes: 1
Views: 822
Reputation: 48893
Eclipse creates directory .externalToolBuilders
to keep tools settings.
Example of git-version.launch
:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/projX/.externalToolBuilders/git-version.bat}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/projX}"/>
</launchConfiguration>
and git-version.bat
:
@echo off
set VFILE=META-INF/git.properties
git rev-parse --short HEAD >%VFILE%
if ERRORLEVEL 1 (
set hasgit=no
) else (
set hasgit=yes
)
rem Git revision.
if %hasgit% == yes (
set /p rev= <%VFILE%
) else (
set rev=unknown
)
echo git.rev=%rev% >%VFILE%
rem Are sources has local changes?
if %hasgit% == yes (
git diff-index --quiet HEAD
if ERRORLEVEL 1 (
echo git.clean=no >>%VFILE%
) else (
echo git.clean=yes >>%VFILE%
)
)
Build command is registered in .project
:
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value><project>/.externalToolBuilders/git-version.launch</value>
</dictionary>
</arguments>
</buildCommand>
Upvotes: 0
Reputation: 1436
I have made a tool to do what i wanted, inspired from the above pointers by @VonC
Upvotes: 1
Reputation: 1328152
The Eclipse git plugin isn't responsible for the build.
But you can customize your Java builder and add a pre-build event which will modify one of your java files with the right version string in it.
Upvotes: 2