Index: oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/OakVersion.java =================================================================== --- oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/OakVersion.java (revision 1809026) +++ oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/OakVersion.java (working copy) @@ -14,10 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.jackrabbit.oak; +package org.apache.jackrabbit.oak.commons; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; import javax.annotation.Nonnull; @@ -27,34 +29,33 @@ */ public final class OakVersion { - private static String version = null; - private OakVersion() { } /** - * Returns the version of oak-core. + * Returns the version of an Oak module. * + * @param moduleName the name of the module + * @param clazz a class of the module * @return the version (or "SNAPSHOT" when unknown) */ @Nonnull - public synchronized static String getVersion() { - if (version == null) { - version = "SNAPSHOT"; // fallback - InputStream stream = OakVersion.class - .getResourceAsStream("/META-INF/maven/org.apache.jackrabbit/oak-core/pom.properties"); - if (stream != null) { + public static String getVersion(String moduleName, Class clazz) { + String version = "SNAPSHOT"; // fallback + InputStream stream = clazz.getResourceAsStream( + "/META-INF/maven/org.apache.jackrabbit/" + + moduleName + "/pom.properties"); + if (stream != null) { + try { try { - try { - Properties properties = new Properties(); - properties.load(stream); - version = properties.getProperty("version"); - } finally { - stream.close(); - } - } catch (IOException e) { - // ignore + Properties properties = new Properties(); + properties.load(stream); + version = properties.getProperty("version", version); + } finally { + stream.close(); } + } catch (IOException e) { + // ignore } } return version; Index: oak-core/src/main/java/org/apache/jackrabbit/oak/OakVersion.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/OakVersion.java (revision 1809037) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/OakVersion.java (working copy) @@ -16,10 +16,6 @@ */ package org.apache.jackrabbit.oak; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - import javax.annotation.Nonnull; /** @@ -40,22 +36,8 @@ @Nonnull public synchronized static String getVersion() { if (version == null) { - version = "SNAPSHOT"; // fallback - InputStream stream = OakVersion.class - .getResourceAsStream("/META-INF/maven/org.apache.jackrabbit/oak-core/pom.properties"); - if (stream != null) { - try { - try { - Properties properties = new Properties(); - properties.load(stream); - version = properties.getProperty("version"); - } finally { - stream.close(); - } - } catch (IOException e) { - // ignore - } - } + version = org.apache.jackrabbit.oak.commons.OakVersion.getVersion( + "oak-core", OakVersion.class); } return version; }