use of java.security.CodeSource in project hadoop by apache.
the class FindClass method loadedClass.
/**
* Log that a class has been loaded, and where from.
* @param name classname
* @param clazz class
*/
private void loadedClass(String name, Class clazz) {
out("Loaded %s as %s", name, clazz);
CodeSource source = clazz.getProtectionDomain().getCodeSource();
URL url = source.getLocation();
out("%s: %s", name, url);
}
use of java.security.CodeSource in project cachecloud by sohutv.
the class NMONFileFactory method init.
/**
* 初始化nmon文件
*/
private static void init() {
try {
String path = System.getProperty(NMON_DIR_PATH);
if (path == null) {
String classpath = null;
try {
CodeSource codeSource = NMONFileFactory.class.getProtectionDomain().getCodeSource();
classpath = codeSource.getLocation().getPath();
if (classpath.startsWith(FILE)) {
//like that: file:/opt/app/cachecloud/cachecloud-web-1.0-SNAPSHOT.war!/WEB-INF/classes!/
classpath = classpath.substring(FILE.length() + 1);
}
if (new File(classpath).isDirectory()) {
path = classpath + "../.." + NMON_PATH;
} else {
//like that: /opt/app/cachecloud/cachecloud-web-1.0-SNAPSHOT.war!/WEB-INF/classes!/
String[] tmp = classpath.split("!/", 2);
path = tmp[0].substring(0, tmp[0].lastIndexOf("/")) + NMON_PATH;
}
} catch (Exception e) {
logger.error(classpath, e);
}
}
File nmonDir = new File(path);
if (!nmonDir.exists()) {
logger.error("{} path not exist", nmonDir.getAbsolutePath());
return;
}
//获取操作系统目录
File[] osDirs = nmonDir.listFiles();
if (osDirs == null) {
logger.error("{} not contains OS folders", nmonDir.getAbsolutePath());
return;
}
for (File osDir : osDirs) {
//获取处理器架构目录
File[] archFiles = osDir.listFiles();
if (archFiles == null) {
logger.info("{} not contains architecture folders", osDir.getName());
continue;
}
for (File archDir : archFiles) {
//获取nmon文件目录
File[] nmonFiles = archDir.listFiles();
if (nmonFiles == null) {
logger.info("{} not contains nomon files", archDir.getName());
continue;
}
for (File nmonFile : nmonFiles) {
nmonFileMap.put(osDir.getName() + "_" + archDir.getName() + "_" + nmonFile.getName(), nmonFile);
}
logger.info("init {} {} nmon file size=" + nmonFiles.length, osDir.getName(), archDir.getName());
}
}
logger.info("init {} finished, os size={}", nmonDir.getAbsolutePath(), osDirs.length);
} catch (Exception e) {
logger.error("init nmon factory", e);
}
}
use of java.security.CodeSource in project neo4j by neo4j.
the class EmbeddedJarLoader method loadJarFromRelativePath.
/**
* Try to load jar from relative ../lib/ directory for cases when we do not have jars in a class path.
* @param jar - path to a jar file to load.
* @return loaded jar file
* @throws EmbeddedJarNotFoundException if jar not exist or file name can't be represented as URI.
*/
private File loadJarFromRelativePath(String jar) {
try {
CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
URI uri = codeSource.getLocation().toURI();
File jarFile = new File(new File(uri).getParent(), jar);
if (!jarFile.exists()) {
throw new EmbeddedJarNotFoundException("Jar file '" + jar + "' not found.");
}
return jarFile;
} catch (URISyntaxException e) {
throw new EmbeddedJarNotFoundException("Jar file '" + jar + "' not found.");
}
}
use of java.security.CodeSource in project pinpoint by naver.
the class AgentClassLoaderTest method getProjectLibDir.
private String getProjectLibDir() {
// not really necessary, but useful for testing protectionDomain
ProtectionDomain protectionDomain = AgentClassLoader.class.getProtectionDomain();
CodeSource codeSource = protectionDomain.getCodeSource();
URL location = codeSource.getLocation();
logger.debug("lib location:{}", location);
String path = location.getPath();
// file:/D:/nhn_source/pinpoint_project/pinpoint-tomcat-profiler/target/classes/
int dirPath = path.lastIndexOf("target/classes/");
if (dirPath == -1) {
throw new RuntimeException("target/classes/ not found");
}
String projectDir = path.substring(1, dirPath);
return projectDir + "src/test/lib";
}
use of java.security.CodeSource in project jaggery by wso2.
the class JaggerySecurityDomain method getCodeSource.
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
public CodeSource getCodeSource() throws ScriptException {
if (codeSource != null) {
return codeSource;
}
URL url = null;
try {
String contextPath = servletContext.getRealPath("/");
if (contextPath == null) {
url = servletContext.getResource(scriptPath);
} else {
if (!contextPath.endsWith(File.separator)) {
contextPath += File.separator;
}
url = new File(contextPath + scriptPath).getCanonicalFile().toURI().toURL();
}
codeSource = new CodeSource(url, (Certificate[]) null);
return codeSource;
} catch (IOException e) {
throw new ScriptException(e);
}
}
Aggregations