package com.nirima.jenkins.plugins.docker.ws;

import com.google.common.base.Strings;
import com.nirima.jenkins.plugins.docker.action.DockerBuildAction;
import hudson.Extension;
import hudson.FilePath;
import hudson.model.Job;
import hudson.model.WorkspaceBrowser;
import java.io.File;
import java.util.logging.Logger;


@Extension
public class MappedFsWorkspaceBrowser extends WorkspaceBrowser  {

    private static final Logger LOGGER = Logger.getLogger(MappedFsWorkspaceBrowser.class.getName());

    public MappedFsWorkspaceBrowser() {
        LOGGER.info(this.getClass().getName() + " initializing.");
    }

    @Override
    public FilePath getWorkspace(Job job) {

        DockerBuildAction a = (DockerBuildAction) job.getLastBuild().getAction(DockerBuildAction.class);

        if (a!= null) {
            if (! Strings.isNullOrEmpty(a.remoteFsMapping)) {
                File mappedRemoteWorkspace = new File(a.remoteFsMapping);
                mappedRemoteWorkspace = new File(mappedRemoteWorkspace, "workspace");
                mappedRemoteWorkspace = new File(mappedRemoteWorkspace, job.getName());
                return new FilePath(mappedRemoteWorkspace);
            }
        }
        return null;

    }
}

@@ -220,16 +220,41 @@
 el.Job;%0A
+import hudson.model.Run;%0A
 import h
@@ -691,25 +691,24 @@
  job) %7B%0A
-%0A
         
 DockerBu
@@ -703,31 +703,90 @@
     
-DockerBuildAction a = (
+Run lastBuild = job.getLastBuild();%0A%0A        if (lastBuild != null) %7B%0A            
 Dock
@@ -802,26 +802,22 @@
 tion
-) job.getL
+ a = l
 astBuild
 ().g
@@ -812,18 +812,16 @@
 astBuild
-()
 .getActi
@@ -862,42 +862,30 @@
     
+    
 if (a
+ 
 != null
-) %7B%0A            if (! 
+ && !
 Stri
@@ -1248,32 +1248,33 @@
     %7D%0A        %7D%0A
+%0A
         return n

fix possible NPE in getWorkspace for job with no last build