.seedstack-maven-plugin.2.4.1.source-code.SeedStackCaplet Maven / Gradle / Ivy
/**
* Copyright (c) 2013-2016, The SeedStack authors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import java.io.File;
import java.net.URLDecoder;
import java.nio.file.Path;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
public class SeedStackCaplet extends Capsule {
private static final Map.Entry> RAW_ATTR_APP_CLASS_PATH = ATTRIBUTE("App-Class-Path", T_LIST(T_STRING()), null, true, "A list of entries that are added to the classpath on runtime");
private static final String CLASSPATH = "capsule.classpath";
private final String homePath = getHomePath();
private final String startupPath = getStartupPath();
public SeedStackCaplet(Capsule prev) {
super(prev);
}
public SeedStackCaplet(Path jarFile) {
super(jarFile);
}
private String getHomePath() {
try {
return new File(System.getProperty("user.home")).getAbsoluteFile().getCanonicalPath();
} catch (Exception e) {
log(LOG_QUIET, "Unable to resolve home path: " + e.getMessage());
}
return null;
}
private String getStartupPath() {
try {
CodeSource codeSource = SeedStackCaplet.class.getProtectionDomain().getCodeSource();
if (codeSource != null) {
File file = new File(URLDecoder.decode(codeSource.getLocation().getPath(), "UTF-8"));
if (file.isFile()) {
file = file.getParentFile();
}
return file.getAbsoluteFile().getCanonicalPath();
}
} catch (Exception e) {
log(LOG_QUIET, "Unable to resolve startup path: " + e.getMessage());
}
return null;
}
@Override
@SuppressWarnings("unchecked")
protected T attribute(Map.Entry attr) {
if (attr.getKey().equals(RAW_ATTR_APP_CLASS_PATH.getKey())) {
final List rawClasspath = new ArrayList<>(super.attribute(RAW_ATTR_APP_CLASS_PATH));
final Set
© 2015 - 2024 Weber Informatics LLC | Privacy Policy