1 21 package proguard; 22 23 import proguard.classfile.ClassPool; 24 import proguard.classfile.util.WarningPrinter; 25 import proguard.classfile.visitor.*; 26 import proguard.io.*; 27 28 import java.io.IOException ; 29 30 35 public class InputReader 36 { 37 private Configuration configuration; 38 39 40 44 public InputReader(Configuration configuration) 45 { 46 this.configuration = configuration; 47 } 48 49 50 54 public void execute(ClassPool programClassPool, 55 ClassPool libraryClassPool) throws IOException  56 { 57 WarningPrinter warningPrinter = configuration.warn ? 58 new WarningPrinter(System.err) : 59 null; 60 61 WarningPrinter notePrinter = configuration.note ? 62 new WarningPrinter(System.out) : 63 null; 64 65 DuplicateClassPrinter duplicateClassPrinter = configuration.note ? 66 new DuplicateClassPrinter(notePrinter) : 67 null; 68 69 if (configuration.programJars == null) 71 { 72 throw new IOException ("The input is empty. You have to specify one or more '-injars' options"); 73 } 74 75 readInput("Reading program ", 80 configuration.programJars, 81 new ClassFilter( 82 new ClassReader(false, 83 configuration.skipNonPublicLibraryClasses, 84 configuration.skipNonPublicLibraryClassMembers, 85 warningPrinter, 86 new ClassPresenceFilter(programClassPool, duplicateClassPrinter, 87 new ClassPoolFiller(programClassPool))))); 88 89 if (programClassPool.size() == 0) 91 { 92 throw new IOException ("The input doesn't contain any classes. Did you specify the proper '-injars' options?"); 93 } 94 95 if (configuration.libraryJars != null) 97 { 98 readInput("Reading library ", 102 configuration.libraryJars, 103 new ClassFilter( 104 new ClassReader(true, 105 configuration.skipNonPublicLibraryClasses, 106 configuration.skipNonPublicLibraryClassMembers, 107 warningPrinter, 108 new ClassPresenceFilter(programClassPool, duplicateClassPrinter, 109 new ClassPresenceFilter(libraryClassPool, duplicateClassPrinter, 110 new ClassPoolFiller(libraryClassPool)))))); 111 } 112 113 if (configuration.note) 115 { 116 int noteCount = notePrinter.getWarningCount(); 117 if (noteCount > 0) 118 { 119 System.err.println("Note: there were " + noteCount + 120 " duplicate class definitions."); 121 } 122 } 123 124 if (configuration.warn) 126 { 127 int warningCount = warningPrinter.getWarningCount(); 128 if (warningCount > 0) 129 { 130 System.err.println("Warning: there were " + warningCount + 131 " classes in incorrectly named files."); 132 System.err.println(" You should make sure all file names correspond to their class names."); 133 System.err.println(" The directory hierarchies must correspond to the package hierarchies."); 134 135 if (!configuration.ignoreWarnings) 136 { 137 System.err.println(" If you don't mind the mentioned classes not being written out,"); 138 System.err.println(" you could try your luck using the '-ignorewarnings' option."); 139 throw new IOException ("Please correct the above warnings first."); 140 } 141 } 142 } 143 } 144 145 146 149 private void readInput(String messagePrefix, 150 ClassPath classPath, 151 DataEntryReader reader) throws IOException  152 { 153 readInput(messagePrefix, 154 classPath, 155 0, 156 classPath.size(), 157 reader); 158 } 159 160 161 164 public void readInput(String messagePrefix, 165 ClassPath classPath, 166 int fromIndex, 167 int toIndex, 168 DataEntryReader reader) throws IOException  169 { 170 for (int index = fromIndex; index < toIndex; index++) 171 { 172 ClassPathEntry entry = classPath.get(index); 173 if (!entry.isOutput()) 174 { 175 readInput(messagePrefix, entry, reader); 176 } 177 } 178 } 179 180 181 184 private void readInput(String messagePrefix, 185 ClassPathEntry classPathEntry, 186 DataEntryReader dataEntryReader) throws IOException  187 { 188 try 189 { 190 DataEntryReader reader = 192 DataEntryReaderFactory.createDataEntryReader(messagePrefix, 193 classPathEntry, 194 dataEntryReader); 195 196 DirectoryPump directoryPump = 198 new DirectoryPump(classPathEntry.getFile()); 199 200 directoryPump.pumpDataEntries(reader); 202 } 203 catch (IOException ex) 204 { 205 throw new IOException ("Can't read [" + classPathEntry + "] (" + ex.getMessage() + ")"); 206 } 207 } 208 } 209
| Popular Tags
|