01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: JarUtils.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.tools;
09:
10: import java.io.File;
11: import java.util.ArrayList;
12: import java.util.Collection;
13:
14: public abstract class JarUtils {
15: public static Collection<String> getFileList(File file) {
16: return getFileList(file, true);
17: }
18:
19: private static ArrayList<String> getFileList(File file, boolean root) {
20: ArrayList<String> filelist = new ArrayList<String>();
21: if (file.isDirectory()) {
22: String[] list = file.list();
23: for (String filename : list) {
24: File next_file = new File(file.getAbsolutePath()
25: + File.separator + filename);
26: ArrayList<String> dir = getFileList(next_file, false);
27:
28: for (String file_name : dir) {
29: if (!root) {
30: file_name = file.getName() + File.separator
31: + file_name;
32: }
33:
34: int filelist_size = filelist.size();
35: for (int j = 0; j < filelist_size; j++) {
36: if ((filelist.get(j)).compareTo(file_name) > 0) {
37: filelist.add(j, file_name);
38: break;
39: }
40: }
41: if (filelist_size == filelist.size()) {
42: filelist.add(file_name);
43: }
44: }
45: }
46: } else if (file.isFile()) {
47: filelist.add(file.getName());
48: }
49:
50: return filelist;
51: }
52: }
|