1
/* $Id: DataEntryReaderFactory.java,v 1.2 2004/08/15 12:39:30 eric Exp $
3
* ProGuard -- shrinking, optimization, and obfuscation of Java class files.
5
* Copyright (c) 2002-2004 Eric Lafortune (eric@graphics.cornell.edu)
7
* This program is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License as published by the Free
9
* Software Foundation; either version 2 of the License, or (at your option)
12
* This program is distributed in the hope that it will be useful, but WITHOUT
13
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17
* You should have received a copy of the GNU General Public License along
18
* with this program; if not, write to the Free Software Foundation, Inc.,
19
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
import proguard.util.*;
28
* This class can create DataEntryReader instances based on class path entries.
29
* The readers will unwrap the input data entries from any jars, wars, ears,
30
* and zips, before passing them to a given reader.
32
* @author Eric Lafortune
34
public class DataEntryReaderFactory
37
* Creates a DataEntryReader that can read the given class path entry.
39
* @param messagePrefix a prefix for messages that are printed out.
40
* @param classPathEntry the input class path entry.
41
* @param reader a data entry reader to which the reading of actual
42
* class files and resource files can be delegated.
43
* @return a DataEntryReader for reading the given class path entry.
45
public static DataEntryReader createDataEntryReader(String messagePrefix,
46
ClassPathEntry classPathEntry,
47
DataEntryReader reader)
49
String entryName = classPathEntry.getName();
50
boolean isJar = entryName.endsWith(".jar");
51
boolean isWar = entryName.endsWith(".war");
52
boolean isEar = entryName.endsWith(".ear");
53
boolean isZip = entryName.endsWith(".zip");
55
String filter = classPathEntry.getFilter();
56
String jarFilter = classPathEntry.getJarFilter();
57
String warFilter = classPathEntry.getWarFilter();
58
String earFilter = classPathEntry.getEarFilter();
59
String zipFilter = classPathEntry.getZipFilter();
61
System.out.println(messagePrefix +
67
" [" + classPathEntry.getName() + "]" +
72
zipFilter != null ? " (filtered)" : ""));
74
// Add a filter, if specified.
77
reader = new FilteredDataEntryReader(new DataEntryNameFilter(new FileNameListMatcher(filter)),
81
// Unzip any jars, if necessary.
82
reader = wrapInJarReader(reader, isJar, jarFilter, ".jar");
85
// Unzip any wars, if necessary.
86
reader = wrapInJarReader(reader, isWar, warFilter, ".war");
89
// Unzip any ears, if necessary.
90
reader = wrapInJarReader(reader, isEar, earFilter, ".ear");
93
// Unzip any zips, if necessary.
94
reader = wrapInJarReader(reader, isZip, zipFilter, ".zip");
104
* Wraps the given DataEntryReader in a JarReader, filtering it if necessary.
106
private static DataEntryReader wrapInJarReader(DataEntryReader reader,
111
// Unzip any jars, if necessary.
112
DataEntryReader jarReader = new JarReader(reader);
121
// Add a filter, if specified.
122
if (jarFilter != null)
124
jarReader = new FilteredDataEntryReader(
125
new DataEntryNameFilter(
126
new FileNameListMatcher(jarFilter)),
130
// Only unzip the right type of jars.
131
return new FilteredDataEntryReader(
132
new DataEntryNameFilter(
133
new ExtensionMatcher(jarExtension)),