/** * Repository's classloader * @return {@linkplain ClassLoader} used to load extensions from the repository */ final synchronized public ClassLoader getClassLoader() { if (cLoader == null) { cLoader = getClassLoader(pLoader); } return cLoader; }
/** * Creates a new instance of {@linkplain ExtensionsRepository} which is a result of composition of other repositories * @param location Desired execution {@linkplain ExtensionsRepository.Location} * @param reps The repositories to wrap in composite * @return Returns a new instance of {@linkplain ExtensionsRepository} */ public static ExtensionsRepository composite(ExtensionsRepository.Location location, ExtensionsRepository ... reps) { Set<String> paths = new HashSet<String>(); StringBuilder sb = new StringBuilder(); for(ExtensionsRepository rep : reps) { if (location == ExtensionsRepository.Location.BOTH || location == rep.getLocation()) { String ePath = rep.getExtensionsPath(); if (ePath != null) { paths.add(ePath); } } } for(String path : paths) { if (sb.length() > 0) { sb.append(File.pathSeparatorChar); } sb.append(path); } return fixed(location, sb.toString()); } }
private List<File> getExtensionFiles() { extensionJarsLock.readLock().lock(); List<File> jars = extensionJarsRef.get(); if (jars == null) { try { extensionJarsLock.readLock().unlock(); extensionJarsLock.writeLock().lock(); jars = extensionJarsRef.get(); if (jars == null) { jars = new ArrayList<File>(); String extPath = getExtensionsPath(); if (extPath != null) { StringTokenizer st = new StringTokenizer(extPath, File.pathSeparator); while (st.hasMoreTokens()) { collectJars(new File(st.nextToken()), jars); } } extensionJarsRef.set(jars); return jars; } } finally { extensionJarsLock.writeLock().unlock(); } } else { extensionJarsLock.readLock().unlock(); } return jars; }
private void setupBootClassPath(Server.Settings ss) { StringBuilder bpcpBuilder = new StringBuilder(ss.bootClassPath != null ? ss.bootClassPath : ""); bpcpBuilder.append(File.pathSeparator).append(repository.getClassPath()); String bootClassPath = bpcpBuilder.toString(); if (bootClassPath != null) { BTraceLogger.debugPrint("Bootstrap ClassPath: " + bootClassPath); StringTokenizer tokenizer = new StringTokenizer(bootClassPath, File.pathSeparator); try { while (tokenizer.hasMoreTokens()) { String path = tokenizer.nextToken(); instr.appendToBootstrapClassLoaderSearch(new JarFile(new File(path))); } } catch (IOException ex) { BTraceLogger.debugPrint("adding to boot classpath failed!"); BTraceLogger.debugPrint(ex); } } }
public Compiler(String includePath, boolean unsafe, ExtensionsRepository repository, JavaCompiler wrappedCompiler) { if (includePath != null) { includeDirs = new ArrayList<String>(); String[] paths = includePath.split(File.pathSeparator); includeDirs.addAll(Arrays.asList(paths)); } this.unsafe = unsafe; this.compiler = wrappedCompiler; this.stdManager = compiler.getStandardFileManager(null, null, null); this.repository = repository; this.dumpDir = System.getProperty("net.java.btrace.dumpDir", null); if (this.dumpDir == null) { try { File tmp = File.createTempFile("tmp", ".tst"); this.dumpDir = tmp.getParent(); } catch (IOException e) { BTraceLogger.debugPrint("*** unable to determina 'tmp' directory. dumps disabled."); } } if (BTraceLogger.isDebug()) { BTraceLogger.debugPrint("*** compiling with repository: " + repository.getExtensionsPath()); } }
if (files != null) { for(File f : files) { collectJars(f, jars); System.err.println("*** attempting to load an extension from unsigned jar: " + jf.getName() + " @" + extLocation.name()); Set<ExtensionPrivilege> requestedPrivileges = getRequestedPrivileges(attrs); if (privileges.containsAll(requestedPrivileges)) { jars.add(dir);
/** * Calculated class-path for the extension repository * @return Returns the classpath computed over the repository */ final public String getClassPath() { Collection<File> jars = getExtensionFiles(); StringBuilder sb = new StringBuilder(); for(File jar : jars) { sb.append(File.pathSeparator).append(jar.getAbsolutePath()); } return sb.toString(); }
/** * Repository's classloader with custom parent * @param parent The parent classloader * @return {@linkplain ClassLoader} used to load extensions from the repository */ final public ClassLoader getClassLoader(final ClassLoader parent) { final List<URL> locs = getExtensionURLs(); return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return new URLClassLoader(locs.toArray(new URL[locs.size()]), parent); } }); }
private void setupBootClassPath(Server.Settings ss) { StringBuilder bpcpBuilder = new StringBuilder(ss.bootClassPath != null ? ss.bootClassPath : ""); bpcpBuilder.append(File.pathSeparator).append(repository.getClassPath()); String bootClassPath = bpcpBuilder.toString(); if (bootClassPath != null) { BTraceLogger.debugPrint("Bootstrap ClassPath: " + bootClassPath); StringTokenizer tokenizer = new StringTokenizer(bootClassPath, File.pathSeparator); try { while (tokenizer.hasMoreTokens()) { String path = tokenizer.nextToken(); instr.appendToBootstrapClassLoaderSearch(new JarFile(new File(path))); } } catch (IOException ex) { BTraceLogger.debugPrint("adding to boot classpath failed!"); BTraceLogger.debugPrint(ex); } } }
public Compiler(String includePath, boolean unsafe, ExtensionsRepository repository, JavaCompiler wrappedCompiler) { if (includePath != null) { includeDirs = new ArrayList<String>(); String[] paths = includePath.split(File.pathSeparator); includeDirs.addAll(Arrays.asList(paths)); } this.unsafe = unsafe; this.compiler = wrappedCompiler; this.stdManager = compiler.getStandardFileManager(null, null, null); this.repository = repository; this.dumpDir = System.getProperty("net.java.btrace.dumpDir", null); if (this.dumpDir == null) { try { File tmp = File.createTempFile("tmp", ".tst"); this.dumpDir = tmp.getParent(); } catch (IOException e) { BTraceLogger.debugPrint("*** unable to determina 'tmp' directory. dumps disabled."); } } if (BTraceLogger.isDebug()) { BTraceLogger.debugPrint("*** compiling with repository: " + repository.getExtensionsPath()); } }
if (files != null) { for(File f : files) { collectJars(f, jars); BTraceLogger.debugPrint("*** attempting to load an extension from unsigned jar: " + jf.getName() + " @" + extLocation.name()); Set<ExtensionPrivilege> requestedPrivileges = getRequestedPrivileges(attrs); if (privileges.containsAll(requestedPrivileges)) { jars.add(dir);
/** * Calculated class-path for the extension repository * @return Returns the classpath computed over the repository */ final public String getClassPath() { Collection<File> jars = getExtensionFiles(); StringBuilder sb = new StringBuilder(); for(File jar : jars) { sb.append(File.pathSeparator).append(jar.getAbsolutePath()); } return sb.toString(); }
/** * Repository's classloader with custom parent * @param parent The parent classloader * @return {@linkplain ClassLoader} used to load extensions from the repository */ final public ClassLoader getClassLoader(final ClassLoader parent) { final List<URL> locs = getExtensionURLs(); return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return new URLClassLoader(locs.toArray(new URL[locs.size()]), parent); } }); }
/** * Repository's classloader * @return {@linkplain ClassLoader} used to load extensions from the repository */ final synchronized public ClassLoader getClassLoader() { if (cLoader == null) { cLoader = getClassLoader(pLoader); } return cLoader; }
StringBuilder cpBuilder = new StringBuilder(classPath); cpBuilder.append(File.pathSeparator).append(System.getProperty("java.class.path")); cpBuilder.append(File.pathSeparator).append(extRepository.getClassPath());
agentArgs += ",probeDescPath=" + probeDescPath; if (extRepository != DEFAULT_REPOSITORY) { agentArgs += ",extPath=" + extRepository.getExtensionsPath();
/** * Creates a new instance of {@linkplain ExtensionsRepository} which is a result of composition of other repositories * @param location Desired execution {@linkplain ExtensionsRepository.Location} * @param reps The repositories to wrap in composite * @return Returns a new instance of {@linkplain ExtensionsRepository} */ public static ExtensionsRepository composite(ExtensionsRepository.Location location, ExtensionsRepository ... reps) { Set<String> paths = new HashSet<String>(); StringBuilder sb = new StringBuilder(); for(ExtensionsRepository rep : reps) { if (location == ExtensionsRepository.Location.BOTH || location == rep.getLocation()) { String ePath = rep.getExtensionsPath(); if (ePath != null) { paths.add(ePath); } } } for(String path : paths) { if (sb.length() > 0) { sb.append(File.pathSeparatorChar); } sb.append(path); } return fixed(location, sb.toString()); } }
private List<File> getExtensionFiles() { extensionJarsLock.readLock().lock(); List<File> jars = extensionJarsRef.get(); if (jars == null) { try { extensionJarsLock.readLock().unlock(); extensionJarsLock.writeLock().lock(); jars = extensionJarsRef.get(); if (jars == null) { jars = new ArrayList<File>(); String extPath = getExtensionsPath(); if (extPath != null) { StringTokenizer st = new StringTokenizer(extPath, File.pathSeparator); while (st.hasMoreTokens()) { collectJars(new File(st.nextToken()), jars); } } extensionJarsRef.set(jars); return jars; } } finally { extensionJarsLock.writeLock().unlock(); } } else { extensionJarsLock.readLock().unlock(); } return jars; }
/** * Lists the URLs of all the extensions known to the repository * @return A URL list of all extensions in the repository */ final public List<URL> getExtensionURLs() { synchronized(extensionsLock) { if (extensions == null) { Collection<File> jars = getExtensionFiles(); extensions = new ArrayList<URL>(); for(File jar : jars) { try { extensions.add(jar.toURI().toURL()); } catch (MalformedURLException ex) { // Logger.getLogger(ExtensionsLocator.class.getName()).log(Level.SEVERE, null, ex); } } } } return extensions; }
/** * Loads an extension by name * @param className The extension class name * @return The class of a loaded extension or <b>NULL</b> */ final public Class loadExtension(String className) { try { return getClassLoader().loadClass(className.replace('/', '.')); } catch (ClassNotFoundException ex) { } return null; } /**