/*
 * The MIT License
 *
 * Copyright (c) 2014, Arne M. Størksen
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package org.jenkinsci.plugins.SemanticVersioning.parsing;

import hudson.model.AbstractBuild;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import net.sf.json.JSONObject;

import org.apache.commons.io.FileUtils;
import org.jenkinsci.plugins.SemanticVersioning.AppVersion;
import org.jenkinsci.plugins.SemanticVersioning.InvalidBuildFileFormatException;

public abstract class JsonVersionParser extends AbstractBuildDefinitionParser {
    
    private final String filepath;
    private final String jsonpathVersion;
    
    protected JsonVersionParser(String filepath, String jsonpathVersion) {
        this.filepath = filepath;
        this.jsonpathVersion = jsonpathVersion;
    }

    public AppVersion extractAppVersion(AbstractBuild<?, ?> build) throws IOException, InvalidBuildFileFormatException {
        
        File file = new File(filepath);
        
        System.err.println(file.getAbsolutePath());
        
        if(file.exists()) {

        	System.err.println("file exists: "+file.getAbsolutePath());

            String content = FileUtils.readFileToString(file);
            
            if(content == null || content.isEmpty()) {

            	throw new InvalidBuildFileFormatException("'" + filepath + "' is not a valid file.");

            } else {

            	JSONObject jsonObject = JSONObject.fromObject( content );
            	JSONObject out = jsonObject;
            	String version = null;
            	for(String s : jsonpathVersion.split("\\.")) {
            		Object o = out.get(s);
                    System.err.println(" ===> "+s+" / "+o);
            		version = o.toString();
            		if(o!=null && o instanceof JSONObject) {
            			out = (JSONObject)o;
            		} else {
            			break;
            		}
            	}
            	return AppVersion.parse(version);
            }
        } else {
            throw new FileNotFoundException("'" + filepath + "' was not found.");
        }
	}
    
    
    

}

@@ -1197,16 +1197,40 @@
 rsing;%0A%0A
+import hudson.FilePath;%0A
 import h
@@ -2011,16 +2011,21 @@
 ption %7B%0A
+    %09
         
@@ -2054,16 +2054,53 @@
 ew File(
+build.getWorkspace().getRemote()+%22/%22+
 filepath

check for the file in the project's workspace