~ubuntu-branches/ubuntu/maverick/proguard/maverick

« back to all changes in this revision

Viewing changes to src/proguard/InputReader.java

  • Committer: Bazaar Package Importer
  • Author(s): Sam Clegg, Onkar Shinde, Sam Clegg
  • Date: 2009-10-09 16:17:49 UTC
  • mfrom: (1.2.3 upstream) (3.1.6 karmic)
  • Revision ID: james.westby@ubuntu.com-20091009161749-qjk059y5r792co7c
Tags: 4.4-1
[ Onkar Shinde ]
* Merge from Ubuntu. (Closes: #534029, #548810)

[ Sam Clegg ]
* Thanks Onkar for the above fixes!
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3
3
 *             of Java bytecode.
4
4
 *
5
 
 * Copyright (c) 2002-2008 Eric Lafortune (eric@graphics.cornell.edu)
 
5
 * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu)
6
6
 *
7
7
 * This program is free software; you can redistribute it and/or modify it
8
8
 * under the terms of the GNU General Public License as published by the Free
54
54
    public void execute(ClassPool programClassPool,
55
55
                        ClassPool libraryClassPool) throws IOException
56
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
57
        // Check if we have at least some input classes.
70
58
        if (configuration.programJars == null)
71
59
        {
72
60
            throw new IOException("The input is empty. You have to specify one or more '-injars' options");
73
61
        }
74
62
 
 
63
        // Perform some sanity checks on the class paths.
 
64
        checkInputOutput(configuration.libraryJars,
 
65
                         configuration.programJars);
 
66
        checkInputOutput(configuration.programJars,
 
67
                         configuration.programJars);
 
68
 
 
69
        WarningPrinter warningPrinter = new WarningPrinter(System.err, configuration.warn);
 
70
        WarningPrinter notePrinter    = new WarningPrinter(System.out, configuration.note);
 
71
 
 
72
        DuplicateClassPrinter duplicateClassPrinter = new DuplicateClassPrinter(notePrinter);
 
73
 
75
74
        // Read the program class files.
76
75
        // Prepare a data entry reader to filter all classes,
77
76
        // which are then decoded to classes by a class reader,
111
110
        }
112
111
 
113
112
        // Print out a summary of the notes, if necessary.
114
 
        if (notePrinter != null)
 
113
        int noteCount = notePrinter.getWarningCount();
 
114
        if (noteCount > 0)
115
115
        {
116
 
            int noteCount = notePrinter.getWarningCount();
117
 
            if (noteCount > 0)
118
 
            {
119
 
                System.err.println("Note: there were " + noteCount +
120
 
                                   " duplicate class definitions.");
121
 
            }
 
116
            System.err.println("Note: there were " + noteCount +
 
117
                               " duplicate class definitions.");
122
118
        }
123
119
 
124
120
        // Print out a summary of the warnings, if necessary.
125
 
        if (warningPrinter != null)
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)
 
121
        int warningCount = warningPrinter.getWarningCount();
 
122
        if (warningCount > 0)
 
123
        {
 
124
            System.err.println("Warning: there were " + warningCount +
 
125
                               " classes in incorrectly named files.");
 
126
            System.err.println("         You should make sure all file names correspond to their class names.");
 
127
            System.err.println("         The directory hierarchies must correspond to the package hierarchies.");
 
128
 
 
129
            if (!configuration.ignoreWarnings)
 
130
            {
 
131
                System.err.println("         If you don't mind the mentioned classes not being written out,");
 
132
                System.err.println("         you could try your luck using the '-ignorewarnings' option.");
 
133
                throw new IOException("Please correct the above warnings first.");
 
134
            }
 
135
        }
 
136
    }
 
137
 
 
138
 
 
139
    /**
 
140
     * Performs some sanity checks on the class paths.
 
141
     */
 
142
    private void checkInputOutput(ClassPath inputClassPath,
 
143
                                  ClassPath outputClassPath)
 
144
    throws IOException
 
145
    {
 
146
        if (inputClassPath == null ||
 
147
            outputClassPath == null)
 
148
        {
 
149
            return;
 
150
        }
 
151
 
 
152
        for (int index1 = 0; index1 < inputClassPath.size(); index1++)
 
153
        {
 
154
            ClassPathEntry entry1 = inputClassPath.get(index1);
 
155
            if (!entry1.isOutput())
 
156
            {
 
157
                for (int index2 = 0; index2 < outputClassPath.size(); index2++)
136
158
                {
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.");
 
159
                    ClassPathEntry entry2 = outputClassPath.get(index2);
 
160
                    if (entry2.isOutput() &&
 
161
                        entry2.getName().equals(entry1.getName()))
 
162
                    {
 
163
                        throw new IOException("Input jars and output jars must be different ["+entry1.getName()+"]");
 
164
                    }
140
165
                }
141
166
            }
142
167
        }