From f309d89222b3a0033b1bced96ee1766f41a0f27f Mon Sep 17 00:00:00 2001 From: Georgios Gousios Date: Wed, 27 Jun 2012 18:35:02 +0200 Subject: [PATCH] Do not autogenerate Version class on every compile. Instead, use a properties template file and Maven filtering to set the correct version while building the output jar. At runtime, load the properties file from the classpath and statically initialize the version parameter. --- pom.xml | 6 ++++ .../java/org/umlgraph/doclet/Version.java | 29 +++++++++++++++++++ src/main/resources/version.properties | 1 + 3 files changed, 36 insertions(+) create mode 100644 src/main/java/org/umlgraph/doclet/Version.java diff --git a/pom.xml b/pom.xml index 3a0489e..d6dab5a 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,12 @@ + + + src/main/resources + true + + org.apache.maven.plugins diff --git a/src/main/java/org/umlgraph/doclet/Version.java b/src/main/java/org/umlgraph/doclet/Version.java new file mode 100644 index 0000000..3db05df --- /dev/null +++ b/src/main/java/org/umlgraph/doclet/Version.java @@ -0,0 +1,29 @@ +package org.umlgraph.doclet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +class Version { + private final static String filename = "version.properties"; + private final static String key = "umlgraph.version"; + public static String VERSION; + + static { + Properties props = new Properties(); + InputStream in = Version.class.getClassLoader().getResourceAsStream(filename); + try { + props.load(in); + if (props.get(key) == null) { + System.err.println("Could not find version property"); + VERSION = "0"; + } else { + VERSION = props.get(key).toString(); + } + + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties index e69de29..3d3ff90 100644 --- a/src/main/resources/version.properties +++ b/src/main/resources/version.properties @@ -0,0 +1 @@ +umlgraph.version=${pom.version} \ No newline at end of file