Index: build.xml =================================================================== --- build.xml (revision 18359) +++ build.xml (working copy) @@ -467,8 +467,25 @@ + + + + + + + + + + + + + + + + Index: src/main/groovy/lang/GroovySystem.java =================================================================== --- src/main/groovy/lang/GroovySystem.java (revision 18359) +++ src/main/groovy/lang/GroovySystem.java (working copy) @@ -17,6 +17,7 @@ import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; import org.codehaus.groovy.util.ReferenceBundle; +import org.codehaus.groovy.util.ReleaseInfo; public final class GroovySystem { // @@ -78,4 +79,8 @@ ReferenceBundle.getSoftBundle().getManager().stopThread(); ReferenceBundle.getWeakBundle().getManager().stopThread(); } + + public static String getVersion() { + return ReleaseInfo.getVersion(); + } } Index: src/main/META-INF/release-info.properties =================================================================== --- src/main/META-INF/release-info.properties (revision 0) +++ src/main/META-INF/release-info.properties (revision 0) @@ -0,0 +1,4 @@ +ImplementationVersion=##ImplementationVersion## +BundleVersion=##BundleVersion## +BuildDate=##BuildDate## +BuildTime=##BuildTime## \ No newline at end of file Index: src/main/org/codehaus/groovy/runtime/InvokerHelper.java =================================================================== --- src/main/org/codehaus/groovy/runtime/InvokerHelper.java (revision 18359) +++ src/main/org/codehaus/groovy/runtime/InvokerHelper.java (working copy) @@ -22,6 +22,7 @@ import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; import org.codehaus.groovy.runtime.wrappers.PojoWrapper; import org.codehaus.groovy.transform.powerassert.PowerAssertionError; +import org.codehaus.groovy.util.ReleaseInfo; import org.w3c.dom.Element; import java.beans.Introspector; @@ -446,17 +447,9 @@ } public static String getVersion() { - String version = null; - Package p = Package.getPackage("groovy.lang"); - if (p != null) { - version = p.getImplementationVersion(); - } - if (version == null) { - version = ""; - } - return version; + return ReleaseInfo.getVersion(); } - + /** * Writes the given object to the given stream */ Index: src/main/org/codehaus/groovy/util/ReleaseInfo.java =================================================================== --- src/main/org/codehaus/groovy/util/ReleaseInfo.java (revision 0) +++ src/main/org/codehaus/groovy/util/ReleaseInfo.java (revision 0) @@ -0,0 +1,49 @@ +package org.codehaus.groovy.util; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * Exposes the Groovy release information + * + * @author Roshan Dawrani + */ +public class ReleaseInfo { + private static Properties releaseInfo = new Properties(); + private static String RELEASE_INFO_FILE = "META-INF/release-info.properties"; + private static String KEY_IMPLEMENTATION_VERSION = "ImplementationVersion"; + private static String KEY_BUNDLE_VERSION = "BundleVersion"; + private static String KEY_BUILD_DATE = "BuildDate"; + private static String KEY_BUILD_TIME = "BuildTime"; + private static boolean loaded = false; + + public static String getVersion() { + return get(KEY_IMPLEMENTATION_VERSION); + } + + public static Properties getAllProperties() { + loadInfo(); + return releaseInfo; + } + + private static String get(String propName) { + loadInfo(); + String propValue = releaseInfo.getProperty(propName); + return (propValue == null ? "" : propValue); + } + + private static void loadInfo() { + if(!loaded) { + InputStream is = ReleaseInfo.class.getClassLoader().getResourceAsStream(RELEASE_INFO_FILE); + if(is != null) { + try { + releaseInfo.load(is); + } catch(IOException ioex) { + // ignore. In case of some exception, release info is not available + } + } + loaded = true; + } + } +} Index: src/test/groovy/lang/GroovySystemTest.groovy =================================================================== --- src/test/groovy/lang/GroovySystemTest.groovy (revision 18359) +++ src/test/groovy/lang/GroovySystemTest.groovy (working copy) @@ -6,6 +6,7 @@ * Tests for the GroovySystem class * * @author Graeme Rocher + * @author Roshan Dawrani **/ class GroovySystemTest extends GroovyTestCase { @@ -14,4 +15,8 @@ assert GroovySystem.metaClassRegistry assert GroovySystem.getMetaClassRegistry() } + + void testGroovyVersion() { + assert GroovySystem.getVersion() + } } \ No newline at end of file