package com.github.ulisesbocchio.jar.resources;

import org.springframework.core.env.Environment;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

import java.util.Optional;

/**
 * @author Ulises Bocchio
 */
public class JarResourceLoader implements ResourceLoader {

    private ResourceLoader delegate = new DefaultResourceLoader();
    private String extractPath;
    private Environment environment;
    private String propertyName;

    public JarResourceLoader(String extractPath) {
        this.extractPath = extractPath;
    }

    public JarResourceLoader() {
    }

    public JarResourceLoader(Environment environment, String propertyName) {
        this.environment = environment;
        this.propertyName = propertyName;
    }

    @Override
    public Resource getResource(String location) {
        Resource resource = delegate.getResource(location);
        String resolvedExtractPath = resolveExtractPath();
        return new JarResource(resource, resolvedExtractPath);
    }

    private String resolveExtractPath() {
        return Optional.ofNullable(environment)
                .map(env -> environment.getProperty(propertyName))
                .orElse(extractPath);
    }

    @Override
    public ClassLoader getClassLoader() {
        return delegate.getClassLoader();
    }

    public void setDelegate(ResourceLoader delegate) {
        this.delegate = delegate;
    }
}

@@ -42,16 +42,87 @@
 urces;%0A%0A
+import com.google.common.io.Files;%0A%0Aimport lombok.extern.slf4j.Slf4j;%0A%0A
 import o
@@ -379,16 +379,23 @@
 hio%0A */%0A
+@Slf4j%0A
 public c
@@ -541,24 +541,64 @@
 xtractPath;%0A
+    private String resolvedExtractPath;%0A
     private 
@@ -1122,23 +1122,27 @@
 tPath = 
-r
+getR
 esolve
+d
 ExtractP
@@ -1237,23 +1237,27 @@
  String 
-r
+getR
 esolve
+d
 ExtractP
@@ -1272,22 +1272,83 @@
         
-return
+if(resolvedExtractPath == null) %7B%0A            resolvedExtractPath =
  Optiona
@@ -1470,32 +1470,361 @@
 e(extractPath);%0A
+            if (extractPath == null) %7B%0A                extractPath = Files.createTempDir().getAbsolutePath();%0A                log.debug(%22TEMP EXTRACT DIR CREATED %7B%7D%22, extractPath);%0A            %7D%0A            log.debug(%22Resolved JarResource extract path to: %7B%7D%22, resolvedExtractPath);%0A        %7D%0A        return resolvedExtractPath;%0A
     %7D%0A%0A    @Over

Update JarResourceLoader.java