package com.highway2urhell;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

public class VersionUtils {

	public static final String UNKNOWN_VERSION = "UNKNOWN";
	public static final String NO_FRAMEWORK = "NO_FRAMEWORK";

	private VersionUtils() {
	}

	public static String getVersion(String clazzName, String groupId,
			String artifactId) {
		//check 
		Class<?> clazz;
		try {
			clazz = Class.forName(clazzName);
		} catch (ClassNotFoundException e1) {
			return NO_FRAMEWORK;
		}
		String version = null;
		
		// try to load from maven properties first
		Properties p = new Properties();
		InputStream is = null;

		try {
			is = clazz.getResourceAsStream("/META-INF/maven/" + groupId + "/"
					+ artifactId + "/pom.properties");
			if (is != null) {
				p.load(is);
				version = p.getProperty("version", "");
			}
		} catch (Exception e) {
			// ignore
		} finally {
			if (is != null) {
				try {
					is.close();
				} catch (IOException e) {
					// ignore
				}
			}
		}

		// try to load from manifest
		try {
			is = clazz.getResourceAsStream("/META-INF/MANIFEST.MF");
			if (is != null) {
				Manifest manifest = new Manifest(is);
				Attributes attr = manifest.getMainAttributes();
				version = attr.getValue("Implementation-Version");
			}
		} catch (Exception e) {
			// ignore
		} finally {
			if (is != null) {
				try {
					is.close();
				} catch (IOException e) {
					// ignore
				}
			}
		}



		// fallback to using Java API
		if (version == null) {
			Package aPackage = clazz.getPackage();
			if (aPackage != null) {
				version = aPackage.getImplementationVersion();
				if (version == null) {
					version = aPackage.getSpecificationVersion();
				}
			}
		}
		if (version == null) {
			// we could not compute the version so use a blank
			version = UNKNOWN_VERSION;
		}

		return version;
	}

}

@@ -78,16 +78,71 @@
 Stream;%0A
+import java.net.JarURLConnection;%0Aimport java.net.URL;%0A
 import j
@@ -1166,32 +1166,467 @@
 anifest%0A%09%09try %7B%0A
+%09%09%09URL clazzRes = clazz.getResource('/' + clazz.getName().replace('.', '/') + %22.class%22);%0A%09%09%09String classResPath = clazzRes.getPath();%0A%09%09%09Manifest manifest = null;%0A%09%09%09if (classResPath.contains(%22!%22)) %7B%0A%09%09%09%09classResPath = classResPath.split(%22!%22)%5B0%5D;%0A%09%09%09%09URL url = new URL(%22jar:%22 + classResPath + %22!/%22);%0A%09%09%09%09JarURLConnection jarConnection = (JarURLConnection) url.openConnection();%0A%09%09%09%09manifest = jarConnection.getManifest();%0A%09%09%09%7D else %7B%0A%09
 %09%09%09is = clazz.ge
@@ -1635,33 +1635,49 @@
 esourceAsStream(
-%22
+classResPath + %22!
 /META-INF/MANIFE
@@ -1684,24 +1684,25 @@
 ST.MF%22);%0A%09%09%09
+%09
 if (is != nu
@@ -1708,24 +1708,14 @@
 ull)
- %7B
 %0A%09%09%09%09
-Manifest 
+%09
 mani
@@ -1734,24 +1734,60 @@
 anifest(is);
+%0A%0A%09%09%09%7D%0A%09%09%09if (manifest != null)%0A%09%09%09%7B
 %0A%09%09%09%09Attribu

fix get version from manifest of jar