private static ImmutableSet <string> getEntries(File jarFile, string rootPath) { ImmutableSet.Builder <string> builder = ImmutableSet.builder(); try { using (JarFile jar = new JarFile(jarFile)) { IEnumerator <JarEntry> jarEntries = jar.entries(); while (jarEntries.MoveNext()) { JarEntry entry = jarEntries.Current; string entryName = entry.Name; if (entryName.StartsWith(rootPath, StringComparison.Ordinal) && !entryName.Equals(rootPath)) { string relativeEntryPath = entryName.Substring(rootPath.Length + 1); if (relativeEntryPath.Trim().Length > 0) { builder.add(relativeEntryPath); } } } } } catch (Exception e) { throw new System.ArgumentException(Messages.format("Error scanning entries in JAR file: {}", jarFile), e); } return(builder.build()); }
public static List <String> getAllClassNames(String jarFilename) { try { var classes = new ArrayList <String>(); var pathToJar = jarFilename; var jarFile = new JarFile(pathToJar); foreach (var je in jarFile.entries().ToIterable()) { if (je.IsDirectory || !je.Name.endsWith(".class")) { continue; } String className = je.Name.substring(0, je.Name.length() - ".class".Length); className = className.replace('/', '.'); classes.add(className); } jarFile.close(); return(classes); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
void build() { List<String> lst = new ArrayList<String>(); //collect unit tests Console.WriteLine("Collecting unit tests from " + _testDir); collectTests(_testDir, _testDir, lst, ".+?\\.Test.+?\\.class$"); TestSuite suite = new TestSuite(); for (String arg : lst) { //ignore inner classes defined in tests if (arg.IndexOf('$') != -1) continue; String cls = arg.Replace(".class", ""); try { Class test = Class.forName(cls); suite.AddTestSuite(test); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } //run tests TestRunner.Run(suite); //see what classes from the ooxml-schemas.jar are loaded Console.WriteLine("Copying classes to " + _destDest); Map<String, Class<?>> classes = GetLoadedClasses(_ooxmlJar.getName()); for (Class<?> cls : classes.values()) { String className = cls.GetName(); String classRef = className.Replace('.', '/') + ".class"; File destFile = new File(_destDest, classRef); copyFile(cls.GetResourceAsStream('/' + classRef), destFile); if(cls.isInterface()){ /** * Copy classes and interfaces declared as members of this class */ for(Class fc : cls.GetDeclaredClasses()){ className = fc.GetName(); classRef = className.Replace('.', '/') + ".class"; destFile = new File(_destDest, classRef); copyFile(fc.GetResourceAsStream('/' + classRef), destFile); } } } //finally copy the compiled .xsb files Console.WriteLine("Copying .xsb resources"); JarFile jar = new JarFile(_ooxmlJar); for(Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements(); ){ JarEntry je = e.nextElement(); if(je.GetName().matches("schemaorg_apache_xmlbeans/system/\\w+/\\w+\\.xsb")) { File destFile = new File(_destDest, je.GetName()); copyFile(jar.GetInputStream(je), destFile); } } jar.close(); }