package org.apache.hadoop.fs.glusterfs;

import java.io.IOException;

import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Versioning stuff for the shim.  This class is not tested since there is no 
 * deterministic behaviour (i.e. it might not work if not building from binary), 
 * and the effects are pure side effects.
 */
public class Version extends Properties{
    static final Logger LOG = LoggerFactory.getLogger(Version.class);
    public Version() {
        super();
        try{
            load(this.getClass().getClassLoader().getResourceAsStream("git.properties"));
        }
        catch(Throwable t){
            LOG.warn("Couldn't find GIT properties for version info " + 
            t.getMessage()+".  This jar may have been built OUTSIDE a GIT repo.");
        }
    }
    public String getTag(){
        return this.getProperty("git.commit.id.describe").split("-")[0];
    }
    
    /**
     * For use with terminal version checking. 
       
       Example, run with an argument to get single property:
             java -cp /home/Development/hadoop-glusterfs/glusterfs-2.0-SNAPSHOT.jar \
                 org.apache.hadoop.fs.glusterfs.Version git.commit.id.describe | cut -d'-' -f 1     

       Or just run (no args, prints all properties)
             java -cp /home/Development/hadoop-glusterfs/glusterfs-2.0-SNAPSHOT.jar \
    */
    public static void main(String[] args){
        Version v = new Version();
        //Dump the whole version info if no arg
        if(args.length==0){
            System.out.println(v);
        }
        //if specific arg given, print just that.
        else{
            String prop = v.get(args[0])+"";
            System.out.println(
                    prop!=null?
                        prop
                        :"Couldnt find property "+prop);
        }
    }
}

@@ -866,14 +866,23 @@
     
-return
+String commit =
  thi
@@ -920,16 +920,182 @@
 scribe%22)
+; %0A        String tag = commit != null ? %0A                commit.split(%22-%22)%5B0%5D:%0A               %22no version info available. check log warnings.%22;%0A        return commit
 .split(%22

add simple unit test to confirm version works w/o git.properties in classpath