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(); }
/// <summary>Unpack matching files from a jar.</summary> /// <remarks> /// Unpack matching files from a jar. Entries inside the jar that do /// not match the given pattern will be skipped. /// </remarks> /// <param name="jarFile">the .jar file to unpack</param> /// <param name="toDir">the destination directory into which to unpack the jar</param> /// <param name="unpackRegex">the pattern to match jar entries against</param> /// <exception cref="System.IO.IOException"/> public static void UnJar(FilePath jarFile, FilePath toDir, Pattern unpackRegex ) { JarFile jar = new JarFile(jarFile); try { Enumeration <JarEntry> entries = ((Enumeration <JarEntry>)jar.Entries()); while (entries.MoveNext()) { JarEntry entry = entries.Current; if (!entry.IsDirectory() && unpackRegex.Matcher(entry.GetName()).Matches()) { InputStream @in = jar.GetInputStream(entry); try { FilePath file = new FilePath(toDir, entry.GetName()); EnsureDirectory(file.GetParentFile()); OutputStream @out = new FileOutputStream(file); try { IOUtils.CopyBytes(@in, @out, 8192); } finally { @out.Close(); } } finally { @in.Close(); } } } } finally { jar.Close(); } }
private static Type[] GetVisibleClasses() { //--Variables IList <Type> classes = new List <Type>(); // (get classpath) string pathSep = Runtime.GetProperty("path.separator"); string[] cp = Runtime.GetProperties().GetProperty("java.class.path", null).Split(pathSep); // --Fill Options // (get classes) foreach (string entry in cp) { Redwood.Util.Log("Checking cp " + entry); //(should skip?) if (entry.Equals(".") || entry.Trim().IsEmpty()) { continue; } //(no, don't skip) File f = new File(entry); if (f.IsDirectory()) { // --Case: Files try { using (IDirectoryStream <IPath> stream = Files.NewDirectoryStream(f.ToPath(), "*.class")) { foreach (IPath p in stream) { //(get the associated class) Type clazz = FilePathToClass(entry, p.ToString()); if (clazz != null) { //(add the class if it's valid) classes.Add(clazz); } } } } catch (IOException ioe) { Redwood.Util.Error(ioe); } } else { //noinspection StatementWithEmptyBody if (!IsIgnored(entry)) { // --Case: Jar try { using (JarFile jar = new JarFile(f)) { IEnumeration <JarEntry> e = ((IEnumeration <JarEntry>)jar.Entries()); while (e.MoveNext()) { //(for each jar file element) JarEntry jarEntry = e.Current; string clazz = jarEntry.GetName(); if (clazz.Matches(".*class$")) { //(if it's a class) clazz = Sharpen.Runtime.Substring(clazz, 0, clazz.Length - 6).ReplaceAll("/", "."); //(add it) try { classes.Add(Sharpen.Runtime.GetType(clazz, false, ClassLoader.GetSystemClassLoader())); } catch (TypeLoadException) { Redwood.Util.Warn("Could not load class in jar: " + f + " at path: " + clazz); } catch (NoClassDefFoundError) { Redwood.Util.Debug("Could not scan class: " + clazz + " (in jar: " + f + ')'); } } } } } catch (IOException) { Redwood.Util.Warn("Could not open jar file: " + f + "(are you sure the file exists?)"); } } } } //case: ignored jar return(Sharpen.Collections.ToArray(classes, new Type[classes.Count])); }