private static void scanJar(File jarfile, File root, List<GenerationTarget> targets) { JarFile jar = null; try { jar = new JarFile(jarfile); } catch (IOException e1) { } if (jar == null) return; Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = (JarEntry) entries.nextElement(); if (jarEntry.isDirectory()) { continue; } // expand .vm also but do not create a target. They are needed during generation. if (jarEntry.getName().endsWith("templates.xml") || jarEntry.getName().endsWith(".vm")) { File tempfile = null; try { tempfile = JarUtil.createTemporaryFile(jar, jarEntry); } catch (IOException e) { } if (tempfile != null && jarEntry.getName().endsWith("templates.xml")) { GenerationTarget target = createTarget(tempfile, root); if (target != null) { targets.add(target); } } } } } // end scanJar
private File createTemporaryFile(FsFolder folderRef, ZipFile zipfile, ZipEntry entry) throws IOException { String prefix = entry.getName(); int len = prefix.length(); Enumeration<? extends ZipEntry> enu = zipfile.entries(); while (enu.hasMoreElements()) { ZipEntry e = enu.nextElement(); String name = e.getName(); if (!name.equals(prefix) && name.startsWith(prefix)) { String suffix = name.substring(len); File file = new File(folderRef.m_file, suffix); if (e.isDirectory()) { file.mkdirs(); } else { file.createNewFile(); InputStream input = zipfile.getInputStream(entry); unzipTo(input, file); } } } // end while List<FsEntry> elements = folderRef.getFolderElements(); String entryname = entry.getName(); String resourceURL = "jar:file:" + zipfile.getName() + "!/" + entryname; File tmlFile = JarUtil.createTemporaryFile(resourceURL); return tmlFile; }