List of usage examples for java.lang Class getProtectionDomain
public java.security.ProtectionDomain getProtectionDomain()
From source file:Main.java
public static void main(String[] args) throws Exception { Class cls = Class.forName("Main"); // returns the name of the class System.out.println("Class = " + cls.getName()); // returns the ProtectionDomain of this class. ProtectionDomain p = cls.getProtectionDomain(); System.out.println(p);/* w ww . java2 s . co m*/ }
From source file:com.heliosdecompiler.helios.bootloader.Bootloader.java
public static void main(String[] args) { try {//from w w w.j a v a 2 s .c om if (!Constants.DATA_DIR.exists() && !Constants.DATA_DIR.mkdirs()) throw new RuntimeException("Could not create data directory"); if (!Constants.ADDONS_DIR.exists() && !Constants.ADDONS_DIR.mkdirs()) throw new RuntimeException("Could not create addons directory"); if (!Constants.SETTINGS_FILE.exists() && !Constants.SETTINGS_FILE.createNewFile()) throw new RuntimeException("Could not create settings file"); if (Constants.DATA_DIR.isFile()) throw new RuntimeException("Data directory is file"); if (Constants.ADDONS_DIR.isFile()) throw new RuntimeException("Addons directory is file"); if (Constants.SETTINGS_FILE.isDirectory()) throw new RuntimeException("Settings file is directory"); try { Class<?> clazz = Class.forName("org.eclipse.swt.widgets.Event"); Object location = clazz.getProtectionDomain() != null && clazz.getProtectionDomain().getCodeSource() != null ? clazz.getProtectionDomain().getCodeSource().getLocation() : ""; throw new RuntimeException("SWT should not be loaded. Instead, it was loaded from " + location); } catch (ClassNotFoundException ignored) { loadSWTLibrary(); } DisplayPumper displayPumper = new DisplayPumper(); if (System.getProperty("os.name").toLowerCase().contains("mac")) { System.out.println("Attemting to force main thread"); Executor executor; try { Class<?> dispatchClass = Class.forName("com.apple.concurrent.Dispatch"); Object dispatchInstance = dispatchClass.getMethod("getInstance").invoke(null); executor = (Executor) dispatchClass.getMethod("getNonBlockingMainQueueExecutor") .invoke(dispatchInstance); } catch (Throwable throwable) { throw new RuntimeException("Could not reflectively access Dispatch", throwable); } if (executor != null) { executor.execute(displayPumper); } else { throw new RuntimeException("Could not load executor"); } } else { Thread pumpThread = new Thread(displayPumper); pumpThread.setName("Display Pumper"); pumpThread.start(); } while (!displayPumper.isReady()) ; Display display = displayPumper.getDisplay(); Shell shell = displayPumper.getShell(); Splash splashScreen = new Splash(display); splashScreen.updateState(BootSequence.CHECKING_LIBRARIES); checkPackagedLibrary(splashScreen, "enjarify", Constants.ENJARIFY_VERSION, BootSequence.CHECKING_ENJARIFY, BootSequence.CLEANING_ENJARIFY, BootSequence.MOVING_ENJARIFY); checkPackagedLibrary(splashScreen, "Krakatau", Constants.KRAKATAU_VERSION, BootSequence.CHECKING_KRAKATAU, BootSequence.CLEANING_KRAKATAU, BootSequence.MOVING_KRAKATAU); try { if (!System.getProperty("os.name").toLowerCase().contains("linux")) { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } catch (Exception exception) { //Not important. No point notifying the user } Helios.main(args, shell, splashScreen); synchronized (displayPumper.getSynchronizer()) { displayPumper.getSynchronizer().wait(); } System.exit(0); } catch (Throwable t) { displayError(t); System.exit(1); } }
From source file:Main.java
private static String getJaxpImplementationInfo(String componentName, Class componentClass) { CodeSource source = componentClass.getProtectionDomain().getCodeSource(); return MessageFormat.format("{0} implementation: {1} loaded from: {2}", componentName, componentClass.getName(), source == null ? "Java Runtime" : source.getLocation()); }
From source file:Main.java
public static File findPom(Class clazz) { try {//from w w w . ja v a 2 s . c o m URL location = clazz.getProtectionDomain().getCodeSource().getLocation(); File classFile = new File(location.toURI()); File root = findPomRoot(classFile); return root != null ? new File(root, "pom.xml") : null; } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:org.icgc.dcc.release.client.config.SparkConfig.java
private static String getPath(Class<?> type) { return type.getProtectionDomain().getCodeSource().getLocation().getPath(); }
From source file:Main.java
/** * Returns the folder that contains a jar that contains the class * * @param aclass a class to find a jar/*from w w w . j a v a 2 s . c o m*/ * @return */ public static String getJarContainingFolderPath(Class aclass) throws Exception { CodeSource codeSource = aclass.getProtectionDomain().getCodeSource(); File jarFile; if (codeSource.getLocation() != null) { jarFile = new File(codeSource.getLocation().toURI()); } else { String path = aclass.getResource(aclass.getSimpleName() + ".class").getPath(); int startIndex = path.indexOf(":") + 1; int endIndex = path.indexOf("!"); if (startIndex == -1 || endIndex == -1) { throw new IllegalStateException( "Class " + aclass.getSimpleName() + " is located not within a jar: " + path); } String jarFilePath = path.substring(startIndex, endIndex); jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8"); jarFile = new File(jarFilePath); } return jarFile.getParentFile().getAbsolutePath(); }
From source file:zipkin.sparkstreaming.job.ZipkinSparkStreamingConfiguration.java
static String pathToJar(Class<?> type) { URL jarFile = type.getProtectionDomain().getCodeSource().getLocation(); try {/* w w w. ja v a2 s. c o m*/ return URLDecoder.decode(jarFile.getPath(), "UTF-8"); } catch (UnsupportedEncodingException e) { return null; } }
From source file:com.github.aliakhtar.annoTest.util.Compiler.java
private static String classPathFor(Class<?> clazz) { return clazz.getProtectionDomain().getCodeSource().getLocation().getFile(); }
From source file:com.googlecode.flyway.core.util.ClassUtils.java
/** * Retrieves the physical location on disk of this class. * * @param aClass The class to get the location for. * @return The absolute path of the .class file. */// w w w . j a v a2s . c om public static String getLocationOnDisk(Class<?> aClass) { try { String url = aClass.getProtectionDomain().getCodeSource().getLocation().getPath(); return URLDecoder.decode(url, "UTF-8"); } catch (UnsupportedEncodingException e) { //Can never happen. return null; } }
From source file:com.firewallid.util.FIFile.java
public static File getWorkingDirectory(Class clazz) throws URISyntaxException { return new File(clazz.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()) .getParentFile();// ww w . j ava2 s . c o m }