View Javadoc
1 /***
2 * PackageListReader.java
3 * Project: Dependency Tool
4 *
5 * Copyright 2003 ELCA Informatique SA
6 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland
7 * www.elca.ch
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 */
24
25 package dptool.config;
26
27 import java.io.File;
28 import java.util.Enumeration;
29 import java.util.Iterator;
30 import java.util.TreeSet;
31 import java.util.jar.JarEntry;
32 import java.util.jar.JarFile;
33
34 import javax.swing.JFileChooser;
35 import javax.swing.filechooser.FileFilter;
36
37 /***
38 * Describe class <code>PackageListReader</code> here.
39 *
40 * @author Peter Moosmann
41 * @version 0.1-alpha
42 * @version $Id$
43 */
44 public class PackageListReader
45 {
46
47 public File[] getJarFileList()
48 {
49
50 JFileChooser chooser = new JFileChooser();
51 chooser.setFileFilter(new JarFileFilter());
52 chooser.setMultiSelectionEnabled(true);
53 chooser.showOpenDialog(null);
54
55 return chooser.getSelectedFiles();
56 }
57
58 public String[] getPackagesFromJarFiles(File[] files) throws Exception
59 {
60 TreeSet packages = new TreeSet();
61
62 for (int i = 0; i < files.length; i++)
63 {
64
65 JarFile jar = new JarFile(files[i]);
66
67 Enumeration jarEntries = jar.entries();
68
69 while (jarEntries.hasMoreElements())
70 {
71 JarEntry entry = (JarEntry)jarEntries.nextElement();
72
73 if (entry.isDirectory()) {
74
75 String packageName = entry.getName();
76 packageName = packageName.replace('/', '.');
77
78 packageName = packageName.substring(0, packageName.length() -1);
79
80 packages.add(packageName);
81
82 }
83 }
84 }
85 return (String[])packages.toArray(new String[packages.size()]);
86 }
87
88 public class JarFileFilter extends FileFilter
89 {
90 public JarFileFilter() {}
91
92 public boolean accept(File file)
93 {
94 return (file.isDirectory() || file.getName().endsWith(".jar"));
95 }
96
97 public String getDescription()
98 {
99 return "Java Archive *.jar";
100 }
101 }
102 }
This page was automatically generated by Maven