@Override public String toString() { StringBuilder result = new StringBuilder(); for (ClassLoaderReference loader : loadersByName.values()) { result.append(loader.getName()); result.append('\n'); for (Module m : getModules(loader)) { result.append(' '); result.append(m); result.append('\n'); } } result.append(getExclusionString()); result.append('\n'); return result.toString(); }
@Override public String toString() { StringBuilder result = new StringBuilder(); for (ClassLoaderReference loader : loadersByName.values()) { result.append(loader.getName()); result.append('\n'); for (Module m : getModules(loader)) { result.append(' '); result.append(m); result.append('\n'); } } result.append(getExclusionString()); result.append('\n'); return result.toString(); }
/** * Add all modules from another scope */ public void addToScope(AnalysisScope other) { if (other == null) { throw new IllegalArgumentException("null other"); } for (ClassLoaderReference loader : other.getLoaders()) { for (Module m : other.getModules(loader)) { addToScope(loader, m); } } }
/** * Add all modules from another scope */ public void addToScope(AnalysisScope other) { if (other == null) { throw new IllegalArgumentException("null other"); } for (ClassLoaderReference loader : other.getLoaders()) { for (Module m : other.getModules(loader)) { addToScope(loader, m); } } }
/** * Enhance an {@link AnalysisScope} to include in a particular loader, elements from a set of Eclipse projects * * @param loader the class loader in which new {@link Module}s will live * @param projectPaths Eclipse project paths to add to the analysis scope * @param scope the {@link AnalysisScope} under construction. This will be mutated. * @param seen set of {@link Module}s which have already been seen, and should not be added to the analysis scope */ private static void buildScope(ClassLoaderReference loader, Collection<EclipseProjectPath<?, ?>> projectPaths, AnalysisScope scope, Collection<Module> seen) throws IOException { for (EclipseProjectPath<?, ?> path : projectPaths) { AnalysisScope pScope = path.toAnalysisScope((File) null); for (Module m : pScope.getModules(loader)) { if (!seen.contains(m)) { seen.add(m); scope.addToScope(loader, m); } } } }
private static void computeClassPath(AnalysisScope scope) { StringBuilder buf = new StringBuilder(); ClassLoaderReference cl = scope.getApplicationLoader(); while (cl != null) { List<Module> modules = scope.getModules(cl); for (Module m : modules) { if (buf.length() > 0) buf.append(File.pathSeparator); if (m instanceof JarFileModule) { JarFileModule jarFileModule = (JarFileModule) m; buf.append(jarFileModule.getAbsolutePath()); } else if (m instanceof DirectoryTreeModule) { DirectoryTreeModule directoryTreeModule = (DirectoryTreeModule) m; buf.append(directoryTreeModule.getPath()); } else Assertions.UNREACHABLE("Module entry is neither jar file nor directory"); } cl = cl.getParent(); } }
List<Module> modules = scope.getModules(cl);
@Override protected IClassLoader makeNewClassLoader(ClassLoaderReference classLoaderReference, IClassHierarchy cha, IClassLoader parent, AnalysisScope scope) throws IOException { if (classLoaderReference.equals(JavaSourceAnalysisScope.SOURCE)) { ClassLoaderImpl cl = makeSourceLoader(classLoaderReference, cha, parent); cl.init(scope.getModules(classLoaderReference)); return cl; } else { return super.makeNewClassLoader(classLoaderReference, cha, parent, scope); } }
@Override protected IClassLoader makeNewClassLoader(ClassLoaderReference classLoaderReference, IClassHierarchy cha, IClassLoader parent, AnalysisScope scope) throws IOException { if (classLoaderReference.equals(JavaSourceAnalysisScope.SOURCE)) { ClassLoaderImpl cl = makeSourceLoader(classLoaderReference, cha, parent); cl.init(scope.getModules(classLoaderReference)); return cl; } else { return super.makeNewClassLoader(classLoaderReference, cha, parent, scope); } }
/** * @return the rt.jar (1.4) or core.jar (1.5) file, or null if not found. */ private JarFile getRtJar() { return RtJar.getRtJar( new MapIterator<Module,JarFile>( new FilterIterator<>(getModules(getPrimordialLoader()).iterator(), JarFileModule.class::isInstance), M -> ((JarFileModule) M).getJarFile())); }
/** * @return the rt.jar (1.4) or core.jar (1.5) file, or null if not found. */ private JarFile getRtJar() { return RtJar.getRtJar( new MapIterator<Module,JarFile>( new FilterIterator<>(getModules(getPrimordialLoader()).iterator(), JarFileModule.class::isInstance), M -> ((JarFileModule) M).getJarFile())); }
cl.init(scope.getModules(classLoaderReference)); return cl;
cl.init(scope.getModules(classLoaderReference)); return cl;
public static String getJavaJar(AnalysisScope javaScope) throws IOException { Module javaJar = javaScope.getModules(javaScope.getApplicationLoader()).iterator().next(); if (javaJar instanceof JarFileModule) { String javaJarPath = ((JarFileModule)javaJar).getAbsolutePath(); return javaJarPath; } else { assert javaJar instanceof NestedJarFileModule : javaJar; File F = File.createTempFile("android", ".jar"); //F.deleteOnExit(); System.err.println(F.getAbsolutePath()); TemporaryFile.streamToFile(F, ((NestedJarFileModule)javaJar).getNestedContents()); return F.getAbsolutePath(); } }
public static Set<ModuleEntry> getJavaScriptCodeFromProject(String project) throws IOException, CoreException { IJavaScriptProject p = JavaScriptHeadlessUtil.getJavaScriptProjectFromWorkspace(project); JSCallGraphUtil.setTranslatorFactory(new CAstRhinoTranslatorFactory()); AnalysisScope s = JavaScriptEclipseProjectPath.make(p, Collections.<Pair<String,Plugin>>emptySet()).toAnalysisScope(new CAstAnalysisScope(JSCallGraphUtil.makeLoaders(), Collections.singleton(JavaScriptLoader.JS))); List<Module> modules = s.getModules(JavaScriptTypes.jsLoader); Set<ModuleEntry> mes = HashSetFactory.make(); for(Module m : modules) { for(ModuleEntry entry : Iterator2Iterable.make(m.getEntries())) { mes.add(entry); } } return mes; }
@Override protected IClassLoader makeNewClassLoader(ClassLoaderReference classLoaderReference, IClassHierarchy cha, IClassLoader parent, AnalysisScope scope) throws IOException { if (classLoaderReference.equals(JavaScriptTypes.jsLoader)) { JavaScriptLoader L = new JavaScriptLoader(cha, jsTranslatorFactory); L.init(scope.getModules(classLoaderReference)); return L; } else { return super.makeNewClassLoader(classLoaderReference, cha, parent, scope); } }
@Test public void testProjectScope() throws IOException, CoreException { IJavaScriptProject p = JavaScriptHeadlessUtil.getJavaScriptProjectFromWorkspace(project.projectName); JSCallGraphUtil.setTranslatorFactory(new CAstRhinoTranslatorFactory()); AnalysisScope s = makeProjectPath(p).toAnalysisScope(new CAstAnalysisScope(JSCallGraphUtil.makeLoaders(), Collections.singleton(JavaScriptLoader.JS))); System.err.println(s); Assert.assertTrue("cannot make scope", s != null); Assert.assertFalse("cannot find files", s.getModules(JavaScriptTypes.jsLoader).isEmpty()); }
@Override public IClassLoader getLoader(ClassLoaderReference classLoaderReference, IClassHierarchy cha, AnalysisScope scope) { if (THE_LOADER == null) { THE_LOADER = makeTheLoader(cha); try { THE_LOADER.init(scope.getModules(getTheReference())); } catch (java.io.IOException e) { Assertions.UNREACHABLE(); } } if (classLoaderReference.equals(scope.getSyntheticLoader())) { syntheticLoader = new BypassSyntheticClassLoader(scope.getSyntheticLoader(), THE_LOADER, scope.getExclusions(), cha); return syntheticLoader; } else { assert classLoaderReference.equals(getTheReference()); return THE_LOADER; } }
@Override public IClassLoader getLoader(ClassLoaderReference classLoaderReference, IClassHierarchy cha, AnalysisScope scope) { if (THE_LOADER == null) { THE_LOADER = makeTheLoader(cha); try { THE_LOADER.init(scope.getModules(getTheReference())); } catch (java.io.IOException e) { Assertions.UNREACHABLE(); } } if (classLoaderReference.equals(scope.getSyntheticLoader())) { syntheticLoader = new BypassSyntheticClassLoader(scope.getSyntheticLoader(), THE_LOADER, scope.getExclusions(), cha); return syntheticLoader; } else { assert classLoaderReference.equals(getTheReference()); return THE_LOADER; } }