public static String generateInheritanceTree(String cp) throws IOException { LoggingUtils.getEvoLogger().info("* Analyzing classpath (generating inheritance tree)"); List<String> cpList = Arrays.asList(cp.split(File.pathSeparator)); // Clear current inheritance file to make sure a new one is generated Properties.INHERITANCE_FILE = ""; InheritanceTree tree = InheritanceTreeGenerator.createFromClassPath(cpList); File outputFile = File.createTempFile("ES_inheritancetree", ".xml.gz"); outputFile.deleteOnExit(); InheritanceTreeGenerator.writeInheritanceTree(tree, outputFile); return outputFile.getAbsolutePath(); }
private static void analyzeDirectory(InheritanceTree inheritanceTree, File directory) { for (File file : directory.listFiles()) { analyze(inheritanceTree, file); } }
/** * */ private static void analyze(InheritanceTree inheritanceTree, File file) { if (!file.canRead()) { return; } if (file.getName().endsWith(".jar")) { // handle jar file analyzeJarFile(inheritanceTree, file); } else if (file.getName().endsWith(".class")) { // handle individual class analyzeClassFile(inheritanceTree, file); } else if (file.isDirectory()) { // handle directory analyzeDirectory(inheritanceTree, file); } else { // Invalid entry? } }
private static void initInheritanceTree(List<String> classPath) { logger.debug("Calculate inheritance hierarchy"); inheritanceTree = InheritanceTreeGenerator.createFromClassPath(classPath); TestClusterGenerator clusterGenerator = new TestClusterGenerator(inheritanceTree); TestGenerationContext.getInstance().setTestClusterGenerator(clusterGenerator); InheritanceTreeGenerator.gatherStatistics(inheritanceTree); }
if (!Properties.INSTRUMENT_CONTEXT && !Properties.INHERITANCE_FILE.isEmpty()) { try { InheritanceTree tree = readInheritanceTree(Properties.INHERITANCE_FILE); LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Inheritance tree loaded from {}", Properties.INHERITANCE_FILE); InheritanceTree inheritanceTree = readJDKData(); if(inheritanceTree==null){ inheritanceTree = new InheritanceTree(); TestGenerationContext.getInstance().getClassLoaderForSUT()).getAllClasses(classPathEntry, "", true, false)) { analyzeClassStream(inheritanceTree, ResourceList.getInstance( TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(className), false);
Collection<String> list = getAllResources(); InheritanceTree inheritanceTree = new InheritanceTree(); List<InheritanceTree> others = new ArrayList<>(); logger.info("Trying to load {}", filterFile); try { InheritanceTree tree = readUncompressedInheritanceTree(filterFile); others.add(tree); } catch (IOException e) { logger.warn("Cannot open/find "+name); } else { analyzeClassStream(inheritanceTree, stream, true); counter++;
@Test public void canFindJDKData(){ InheritanceTree it = InheritanceTreeGenerator.readJDKData(); Assert.assertNotNull(it); }
private static void analyzeClassFile(InheritanceTree inheritanceTree, File classFile) { try { analyzeClassStream(inheritanceTree, new FileInputStream(classFile), false); } catch (FileNotFoundException e) { logger.error("", e); } }
/** * Main constructor * * @param data */ public ProjectGraph(ProjectStaticData data) { this.data = data; inheritanceTree = InheritanceTreeGenerator.createFromClassList(data.getClassNames()); castInformation = new HashMap<String, Set<String>>(); if(logger.isDebugEnabled()){ logger.debug("Classes in inheritance tree: " + inheritanceTree.getAllClasses()); } }
private static void analyzeClassStream(InheritanceTree inheritanceTree, InputStream inputStream, boolean onlyPublic) { try { ClassReader reader = new ClassReader(inputStream); inputStream.close(); ClassNode cn = new ClassNode(); reader.accept(cn, ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE); analyzeClassNode(inheritanceTree, cn, onlyPublic); } catch (IOException e) { logger.error("", e); } catch(java.lang.ArrayIndexOutOfBoundsException e) { logger.error("ASM Error while reading class ("+e.getMessage()+")"); } }
/** * Create inheritance tree only for the classes passed as parameter * * <p> * Private classes will be ignored * * @param classNames * @return */ public static InheritanceTree createFromClassList(Collection<String> classNames) throws IllegalArgumentException { if (classNames == null || classNames.isEmpty()) { throw new IllegalArgumentException("No class name defined"); } InheritanceTree inheritanceTree = new InheritanceTree(); for (String className : classNames) { if (className == null) { throw new IllegalArgumentException("Null class name"); } analyzeClassName(inheritanceTree, className); } // Remove all classes not in the parameter list, otherwise we get the superclasses from outside the list Set<String> classes = new HashSet<>(inheritanceTree.getAllClasses()); for (String className : classes) { if (!classNames.contains(className)) inheritanceTree.removeClass(className); } return inheritanceTree; }
analyzeClassStream(inheritanceTree, zf.getInputStream(ze), false); } catch (IOException e1) {
private static void analyzeClassName(InheritanceTree inheritanceTree, String className) { InputStream stream = ResourceList.getInstance( TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(className); if(stream==null){ throw new IllegalArgumentException("Failed to locate/load class: "+className); } logger.debug("Going to analyze: {}", className); analyzeClassStream(inheritanceTree, stream, false); }