/*
 * Copyright 2008-2012 LinkedIn, Inc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package voldemort.utils;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * A utility class that abstract out fields from manifest file
 * 
 */
public class ManifestFileReader {

    protected static final Logger logger = Logger.getLogger(ManifestFileReader.class);

    private static String MANIFEST_FILE = "META-INF/MANIFEST.MF";
    private static String RELEASE_VERSION_KEY = "Implementation-Version";

    public static String getReleaseVersion() {
        String version = null;
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream(MANIFEST_FILE));
            version = properties.getProperty(RELEASE_VERSION_KEY);
        } catch(IOException e) {
            logger.warn("Unable to load voldemort release version due to the following error:", e);
        }
        return version;
    }
}

@@ -636,31 +636,48 @@
 java.io.
-FileInputStream
+IOException;%0Aimport java.net.URL
 ;%0Aimport
@@ -678,34 +678,36 @@
 import java.
-io.IOExcep
+util.Enumera
 tion;%0Aimport
@@ -717,26 +717,61 @@
 va.util.
-Properti
+jar.Attributes;%0Aimport java.util.jar.Manif
 es
+t
 ;%0A%0Aimpor
@@ -1061,16 +1061,97 @@
 EST.MF%22;
+%0A%0A    // this seems too generic we should have a voldemort-implmentation-version?
 %0A    pri
@@ -1265,24 +1265,25 @@
 ion() %7B%0A
+%0A
         
 String v
@@ -1278,29 +1278,190 @@
     
-S
 tr
-ing version = null
+y %7B%0A            Enumeration%3CURL%3E resources = ManifestFileReader.class.getClassLoader()%0A                                                                 .getResources(MANIFEST_FILE)
 ;%0A  
@@ -1470,48 +1470,136 @@
     
+ 
-Properties properti
+   while(resources.hasMoreElements()) %7B%0A%0A                Manifest manif
 es
+t
  = new 
-Properties
+Manifest(resources.nextElement().openStream
 ()
+)
 ;%0A  
@@ -1608,145 +1608,365 @@
     
+    
-try %7B%0A            properties.load(new FileInputStream(MANIFEST_FILE));%0A            version = properties.getProperty(RELEASE_VERSION_KEY);
+    // check that this is your manifest and do what you need or get%0A                // the next one%0A                Attributes mainAttribs = manifest.getMainAttributes();%0A                String version = mainAttribs.getValue(RELEASE_VERSION_KEY);%0A                if(version != null) %7B%0A                    return version;%0A                %7D%0A%0A            %7D
 %0A   
@@ -1990,17 +1990,19 @@
 ception 
-e
+IoE
 ) %7B%0A    
@@ -2093,17 +2093,19 @@
 rror:%22, 
-e
+IoE
 );%0A     
@@ -2101,32 +2101,33 @@
 IoE);%0A        %7D%0A
+%0A
         return v
@@ -2121,29 +2121,27 @@
      return 
-version;
+null;%0A
 %0A    %7D%0A%7D%0A

Use the resources supplied by the classloader to load the manifest file absolute / relative file sytem paths dont work anymore because when you run this in a servlet container everything is relative to its context hence we use the right method of loading resources we probably need a better key to the implmenetation version - because if there exists another manifest file with the same key in the same servlet container we are doomed as we return its implementation version