[Qt-jambi-interest] [RFC PATCH 0/5] Goodbye Version.java
Raymond Martin
laseray at gmail.com
Sun Dec 27 19:38:58 CET 2009
On December 27, 2009 12:44:57 pm Francis Galiegue wrote:
> This patch series applies cleanly on top of the community-port-to-4_6
> repository, and it solves a longstanding problem: the qt-jambi version was
> hardcoded into Java code. With these patches applied, this is no longer the
> case.
>
> Apart from the obvious advantage of getting rid of the hardcoded version,
> this will also allow us to check, for instance, whether the Qt version we
> try to build against is the same than the declared qt-jambi version (this
> is NOT implemented in this patch series).
Getting rid of the hardcoded version for a .properties file is not necessarily
the best way to go. Whether you have a .java or .properties file with the
version stuff in it almost amounts to the same thing.
Did you consider putting the version information into the Ant build.xml as
properties and having them inserted into the manifest as attributes?
Then you can use the java jar utilities to read the attributes directly and
you do not need another file laying around.
For instance, a little excerpt of a build.xml:
<property name="devel" value="false" />
<property name="build" value="${build.date}" />
<property name="major" value="1.0" />
<property name="minor" value="M3" />
<property name="update" value="1" />
<property name="version" value="${major}.${minor}" />
<property name="version.update" value="${version}.${update}" />
<property name="version.build" value="${version.update}-${build}" />
<property name="applicationjar" value="omegatplus.jar" />
<!-- automatically build/update the manifest file -->
<target name="manifest" description="Create manifest">
<manifest file="MANIFEST.MF" mode="update">
<attribute name="Built-By" value="${user.name}" />
<attribute name="Version" value="${version}" />
<attribute name="Update" value="${update}" />
<attribute name="Build" value="${build}" />
<attribute name="ApplicationJar" value="${applicationjar}" />
<attribute name="Devel" value="${devel}" />
<attribute name="Main-Class" value="omegatplus.OmegaTPlus" />
<attribute name="Class-Path" value="lib/liquidlnf.jar images/" />
<attribute name="License" value="GPL"/>
</manifest>
</target>
With some associated utility code:
/**
* Name of the OmegaT+ Jar file
* Used to calculate the installation directory, etc.
*/
final public static String APPLICATIONJAR = "omegatplus.jar";
final public static File APPLICATIONJARPATH =
new File( installDir() + File.separator + APPLICATIONJAR );
public static Attributes readManifest()
{
Manifest manifest = null;
try
{
JarFile jar = new JarFile( APPLICATIONJARPATH );
manifest = jar.getManifest();
}
catch( IOException e )
{
log.error( "Cannot read jar-file manifest: " + e.getMessage(), e );
}
if( manifest == null ) return( null );
return( manifest.getMainAttributes() );
}
final public static Attributes attribs = readManifest();
final public static String attrBuiltBy = attribs.getValue( "Built-By" );
final public static String attrVersion = attribs.getValue( "Version" );
final public static String attrBuild = attribs.getValue( "Build" );
final public static String attrUpdate = attribs.getValue( "Update" );
final public static String attrDevel = attribs.getValue( "Devel" );
final public static String attrMain = attribs.getValue( "Main-Class" );
final public static String attrClassPath = attribs.getValue( "Class-Path" );
final public static String attrLicense = attribs.getValue( "License" );
Cheers,
Raymond
More information about the Qt-jambi-interest
mailing list