public Object run() { return source.getProtectionDomain(); } });
public ProtectionDomain run() { return ClassDefinitionUtils.class.getProtectionDomain(); } });
@Override public ClassLoadingStrategy<ClassLoader> resolveStrategy(Class<?> mockedType, ClassLoader classLoader, boolean localMock) { return ClassLoadingStrategy.Default.INJECTION.with(localMock ? mockedType.getProtectionDomain() : InjectionBase.class.getProtectionDomain()); } }
public static String getCodeBase(Class<?> cls) { if (cls == null) { return null; } ProtectionDomain domain = cls.getProtectionDomain(); if (domain == null) { return null; } CodeSource source = domain.getCodeSource(); if (source == null) { return null; } URL location = source.getLocation(); if (location == null) { return null; } return location.getFile(); }
public static String getCodeBase(Class<?> cls) { if (cls == null) { return null; } ProtectionDomain domain = cls.getProtectionDomain(); if (domain == null) { return null; } CodeSource source = domain.getCodeSource(); if (source == null) { return null; } URL location = source.getLocation(); if (location == null) { return null; } return location.getFile(); }
/** * Returns location of the class. If class is not in a jar, it's classpath * is returned; otherwise the jar location. */ public static String classLocation(Class clazz) { return clazz.getProtectionDomain().getCodeSource().getLocation().getPath(); }
protected ProtectionDomain getDomain() { Class clazz; if (superClass != null && !superClass.getName().equals("java.lang.Object")) clazz = superClass; else if (interfaces != null && interfaces.length > 0) clazz = interfaces[0]; else clazz = this.getClass(); return clazz.getProtectionDomain(); }
return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
/** * 获得参数clazz所在的Jar文件的绝对路径 */ public static String getJarPath(Class<?> clazz) { return clazz.getProtectionDomain().getCodeSource().getLocation().getFile(); } }
private static void setRunningLocation(CliMain m) { mRunningLocation = m.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); try { mRunningLocation = URLDecoder.decode(mRunningLocation, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } if (mRunningLocation.endsWith(".jar")) { mRunningLocation = mRunningLocation.substring(0, mRunningLocation.lastIndexOf(File.separator) + 1); } File f = new File(mRunningLocation); mRunningLocation = f.getAbsolutePath(); }
/** * Get the code source file or class path of the Class passed in. * * @param clazz * @return Jar file name or class path. */ public static String getCodeSource(Class<?> clazz) { ProtectionDomain protectionDomain = clazz.getProtectionDomain(); if (protectionDomain == null || protectionDomain.getCodeSource() == null) { return null; } CodeSource codeSource = clazz.getProtectionDomain().getCodeSource(); URL location = codeSource.getLocation(); if (location == null) { return null; } String path = codeSource.getLocation().toExternalForm(); if (path.endsWith(".jar") && path.contains("/")) { return path.substring(path.lastIndexOf('/') + 1); } return path; }
static String getEagleEyeLocation() { try { URL resource = EagleEye.class.getProtectionDomain().getCodeSource().getLocation(); if (resource != null) { return resource.toString(); } } catch (Throwable t) { // ignore } return "unknown location"; }
/** * Get the code source file or class path of the Class passed in. * * @param clazz * @return Jar file name or class path. */ public static String getCodeSource(Class<?> clazz) { ProtectionDomain protectionDomain = clazz.getProtectionDomain(); if (protectionDomain == null || protectionDomain.getCodeSource() == null) { return null; } CodeSource codeSource = clazz.getProtectionDomain().getCodeSource(); URL location = codeSource.getLocation(); if (location == null) { return null; } String path = codeSource.getLocation().toExternalForm(); if (path.endsWith(".jar") && path.contains("/")) { return path.substring(path.lastIndexOf('/') + 1); } return path; }
@Override public String toString() { final URL location = klass.getProtectionDomain().getCodeSource().getLocation(); try { final String jar = new File(location.toURI()).getName(); if (jar.endsWith(".jar")) { return jar; } return "project.jar"; } catch (Exception ignored) { return "project.jar"; } } }
static File currentJarFile() { try { return new File(Boot.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
@SuppressWarnings("unchecked") private Class<T> defineClass(String specializedClassName, byte[] specializedClassBytecode) { return (Class<T>) UNSAFE.defineClass( specializedClassName, specializedClassBytecode, 0, specializedClassBytecode.length, prototypeClass.getClassLoader(), prototypeClass.getProtectionDomain() ); }
public Path getConfigInPluginDir() { return PathUtils .get(new File(AnalysisIkPlugin.class.getProtectionDomain().getCodeSource().getLocation().getPath()) .getParent(), "config") .toAbsolutePath(); }
public Class<?> toClass() { return toClass(ClassHelper.getClassLoader(ClassGenerator.class), getClass().getProtectionDomain()); }
public Class<?> toClass() { return toClass(ClassHelper.getClassLoader(ClassGenerator.class), getClass().getProtectionDomain()); }
@SneakyThrows protected static Map<String, SQLCase> loadSQLCases(final String path) { File file = new File(SQLCasesLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath()); return file.isFile() ? loadSQLCasesFromJar(path, file) : loadSQLCasesFromTargetDirectory(path); }