View Javadoc
1 package jface.jarfind;
2
3 import java.io.File;
4 import java.util.Collection;
5 import java.util.Iterator;
6 import java.util.jar.JarEntry;
7
8 import org.apache.log4j.Category;
9 import org.apache.tools.ant.DirectoryScanner;
10
11 /***
12 * This is the main class for the jarfind tool. For more information about
13 * the command line arguments see the {@link #main(String[])} method.
14 *
15 * @author <a href="mailto:powerpete@users.sf.net">Moritz Petersen</a>
16 * @version $Id: Main.java,v 1.2 2003/03/30 11:38:51 powerpete Exp $
17 */
18 public class Main
19 {
20 private static Category log4j = Category.getInstance(Main.class);
21
22 /***
23 * This method is used to start the jarfind tool. It has the following
24 * functions:
25 * <ul>
26 * <li> Parsing the command line arguments.
27 * <li> Initializing the {@link DirectoryScanner} with the baseDir and
28 * the file pattern.
29 * <li> Using {@link JarFileFind} to find matching files and print the
30 * results.
31 * </ul>
32 *
33 * @param args The command line arguments. Expected is:
34 * <ul>
35 * <li> The basedir where the search will start.
36 * <li> The filename pattern for the .jar files (Ant like
37 * pattern).
38 * <li> The pattern for the entry names.
39 * </ul>
40 */
41 public static void main(String[] args)
42 {
43 try
44 {
45 //
46 // Load the command line arguments
47 //
48 String baseDir = args[0];
49 if (!baseDir.endsWith(File.separator))
50 {
51 baseDir += File.separator;
52 }
53 String filePattern = args[1];
54 String entryPattern = args[2];
55 log4j.debug("entryPattern = " + entryPattern);
56
57 //
58 // Scan the directories for the files.
59 //
60 DirectoryScanner scanner = new DirectoryScanner();
61 scanner.setBasedir(baseDir);
62 scanner.setIncludes(new String[] { filePattern });
63 scanner.scan();
64
65 //
66 // Find in each file.
67 //
68 String[] filenames = scanner.getIncludedFiles();
69 for (int i = 0; i < filenames.length; i++)
70 {
71 String filename = baseDir + filenames[i];
72 log4j.debug("filename = " + filename);
73
74 JarFileFind find = new JarFileFind(filename);
75 Collection entries = find.findEntries(entryPattern);
76
77 if (!entries.isEmpty())
78 {
79 System.out.println("\n" + filename + " >>");
80 for (Iterator it = entries.iterator(); it.hasNext();)
81 {
82 JarEntry entry = (JarEntry) it.next();
83 System.out.println(entry.getName());
84 }
85 }
86 }
87 }
88 catch (Exception e)
89 {
90 log4j.error("An error occured: " + e);
91 if (e.getMessage() != null)
92 {
93 System.err.println(
94 "Error: " + e.getMessage() + "\n" +
95 "\n");
96 }
97 System.err.println(
98 "Usage: jarfind basedir filepattern entrypattern\n" +
99 "\n" +
100 " Scans all .jar or .zip files, that match the given\n" +
101 " file name pattern (filepattern), and lists all entries\n" +
102 " with a name matching the entry name pattern\n" +
103 " (entrypattern).\n" +
104 "\n" +
105 " basedir - The directory where the file scan starts.\n" +
106 " filepattern - The Ant like pattern for the files.\n" +
107 " entrypattern - The pattern for the entry names.\n" +
108 " * means any character in any number.\n" +
109 " ? means any single character.\n" +
110 "\n" +
111 "\n" +
112 " (c) 2003 by Moritz Petersen");
113 }
114 }
115 }
116
This page was automatically generated by Maven