Created
July 30, 2015 18:03
-
-
Save flandr/bb2a9ceed64b3dac324e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Map; | |
import java.nio.file.Paths; | |
/** Caplet to include runtime classpath. */ | |
public class RuntimeClasspathCaplet extends Capsule { | |
private static final String PROP_RUNTIME_CP = "caplet.runtime.classpath"; | |
/** Composition constructor. */ | |
public RuntimeClasspathCaplet(final Capsule prev) { | |
super(prev); | |
} | |
// Regrettably we can't use any external libraries in this method (e.g. | |
// Guava) that are not used by the core Capsule jar because this method is | |
// invoked prior to the capsule being expanded. | |
@Override | |
@SuppressWarnings("unchecked") | |
protected <T> T attribute(Map.Entry<String, T> attr) { | |
if (attr != ATTR_APP_CLASS_PATH) { | |
return super.attribute(attr); | |
} | |
String classpath = System.getProperty(PROP_RUNTIME_CP); | |
if (classpath == null || classpath.isEmpty()) { | |
return super.attribute(attr); | |
} | |
List<Object> cplist = new ArrayList<>( | |
(List<Object>) super.attribute(attr)); | |
for (String component : classpath.split(":")) { | |
cplist.add(Paths.get(component).toAbsolutePath().normalize() | |
.toString()); | |
} | |
return (T) cplist; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment