package liquibase.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;

public class LiquibaseUtil {
    public static String getBuildVersion() {
        String buildVersion = "UNKNOWN";
        Properties buildInfo = new Properties();
        ClassLoader classLoader = LiquibaseUtil.class.getClassLoader();

        URL buildInfoFile = classLoader.getResource("buildinfo.properties");
        InputStream in = null;
        try {
            if (buildInfoFile != null) {
            	URLConnection connection = buildInfoFile.openConnection();
            	connection.setUseCaches(false);
                in = connection.getInputStream();
                buildInfo.load(in);
                String o = (String) buildInfo.get("build.version");

                if (o != null) {
                    buildVersion = o;
                }
            }
        } catch (IOException e) {
            // This is not a fatal exception.
            // Build info will be returned as 'UNKNOWN'        }
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    // TODO Log this error and remove the RuntimeException.
                    throw new RuntimeException("Failed to close InputStream in LiquibaseUtil.", e);
                }
            }
        }

        return buildVersion;
    }
}

@@ -18,16 +18,133 @@
 .util;%0A%0A
+import liquibase.exception.UnexpectedLiquibaseException;%0Aimport liquibase.integration.commandline.CommandLineUtils;%0A%0A
 import j
@@ -159,24 +159,24 @@
 OException;%0A
-
 import java.
@@ -271,16 +271,80 @@
 perties;
+%0Aimport java.util.jar.Attributes;%0Aimport java.util.jar.Manifest;
 %0A%0Apublic
@@ -366,16 +366,17 @@
 eUtil %7B%0A
+%0A
     publ
@@ -750,17 +750,20 @@
         
-%09
+    
 URLConne
@@ -829,9 +829,12 @@
     
-%09
+    
 conn
@@ -1097,32 +1097,32 @@
               %7D%0A
-
             %7D%0A  
@@ -1110,32 +1110,954 @@
  %7D%0A            %7D
+ else %7B%0A                Class clazz = LiquibaseUtil.class;%0A                String className = clazz.getSimpleName() + %22.class%22;%0A                String classPath = clazz.getResource(className).toString();%0A                if (classPath.startsWith(%22jar%22)) %7B%0A                    String manifestPath = classPath.substring(0, classPath.lastIndexOf(%22!%22) + 1) +%0A                            %22/META-INF/MANIFEST.MF%22;%0A                    Manifest manifest = null;%0A                    try %7B%0A                        manifest = new Manifest(new URL(manifestPath).openStream());%0A                    %7D catch (IOException e) %7B%0A                        throw new UnexpectedLiquibaseException(%22Cannot open a URL to the manifest of our own JAR file.%22);%0A                    %7D%0A                    Attributes attr = manifest.getMainAttributes();%0A                    buildVersion = attr.getValue(%22Bundle-Version%22);%0A                %7D%0A            %7D%0A
 %0A        %7D catch

add fallback method of getting build version from manifest