1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
/*
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
* Copyright (c) 2002-2011 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package proguard.ant;
import org.apache.tools.ant.BuildException;
import proguard.*;
import proguard.classfile.util.ClassUtil;
import java.io.*;
import java.util.ArrayList;
/**
* This Task allows to configure and run ProGuard from Ant.
*
* @author Eric Lafortune
*/
public class ProGuardTask extends ConfigurationTask
{
// Ant task attributes.
public void setConfiguration(File configurationFile) throws BuildException
{
try
{
ConfigurationParser parser = new ConfigurationParser(configurationFile);
try
{
parser.parse(configuration);
}
catch (ParseException ex)
{
throw new BuildException(ex.getMessage());
}
finally
{
parser.close();
}
}
catch (IOException ex)
{
throw new BuildException(ex.getMessage());
}
}
/**
* @deprecated Use the nested outjar element instead.
*/
public void setOutjar(String parameters)
{
throw new BuildException("Use the <outjar> nested element instead of the 'outjar' attribute");
}
public void setSkipnonpubliclibraryclasses(boolean skipNonPublicLibraryClasses)
{
configuration.skipNonPublicLibraryClasses = skipNonPublicLibraryClasses;
}
public void setSkipnonpubliclibraryclassmembers(boolean skipNonPublicLibraryClassMembers)
{
configuration.skipNonPublicLibraryClassMembers = skipNonPublicLibraryClassMembers;
}
public void setTarget(String target)
{
configuration.targetClassVersion = ClassUtil.internalClassVersion(target);
if (configuration.targetClassVersion == 0)
{
throw new BuildException("Unsupported target '"+target+"'");
}
}
public void setForceprocessing(boolean forceProcessing)
{
configuration.lastModified = forceProcessing ? Long.MAX_VALUE : 0;
}
public void setPrintseeds(File printSeeds)
{
configuration.printSeeds = optionalFile(printSeeds);
}
public void setShrink(boolean shrink)
{
configuration.shrink = shrink;
}
public void setPrintusage(File printUsage)
{
configuration.printUsage = optionalFile(printUsage);
}
public void setOptimize(boolean optimize)
{
configuration.optimize = optimize;
}
public void setOptimizationpasses(int optimizationPasses)
{
configuration.optimizationPasses = optimizationPasses;
}
public void setAllowaccessmodification(boolean allowAccessModification)
{
configuration.allowAccessModification = allowAccessModification;
}
public void setMergeinterfacesaggressively(boolean mergeinterfacesaggressively)
{
configuration.mergeInterfacesAggressively = mergeinterfacesaggressively;
}
public void setObfuscate(boolean obfuscate)
{
configuration.obfuscate = obfuscate;
}
public void setPrintmapping(File printMapping)
{
configuration.printMapping = optionalFile(printMapping);
}
public void setApplymapping(File applyMapping)
{
configuration.applyMapping = resolvedFile(applyMapping);
}
public void setObfuscationdictionary(File obfuscationDictionary)
{
configuration.obfuscationDictionary = resolvedFile(obfuscationDictionary);
}
public void setClassobfuscationdictionary(File classObfuscationDictionary)
{
configuration.classObfuscationDictionary = resolvedFile(classObfuscationDictionary);
}
public void setPackageobfuscationdictionary(File packageObfuscationDictionary)
{
configuration.packageObfuscationDictionary = resolvedFile(packageObfuscationDictionary);
}
public void setOverloadaggressively(boolean overloadAggressively)
{
configuration.overloadAggressively = overloadAggressively;
}
public void setUseuniqueclassmembernames(boolean useUniqueClassMemberNames)
{
configuration.useUniqueClassMemberNames = useUniqueClassMemberNames;
}
public void setUsemixedcaseclassnames(boolean useMixedCaseClassNames)
{
configuration.useMixedCaseClassNames = useMixedCaseClassNames;
}
public void setFlattenpackagehierarchy(String flattenPackageHierarchy)
{
configuration.flattenPackageHierarchy = ClassUtil.internalClassName(flattenPackageHierarchy);
}
public void setRepackageclasses(String repackageClasses)
{
configuration.repackageClasses = ClassUtil.internalClassName(repackageClasses);
}
/**
* @deprecated Use the repackageclasses attribute instead.
*/
public void setDefaultpackage(String defaultPackage)
{
configuration.repackageClasses = ClassUtil.internalClassName(defaultPackage);
}
public void setKeepparameternames(boolean keepParameterNames)
{
configuration.keepParameterNames = keepParameterNames;
}
public void setRenamesourcefileattribute(String newSourceFileAttribute)
{
configuration.newSourceFileAttribute = newSourceFileAttribute;
}
public void setPreverify(boolean preverify)
{
configuration.preverify = preverify;
}
public void setMicroedition(boolean microEdition)
{
configuration.microEdition = microEdition;
}
public void setVerbose(boolean verbose)
{
configuration.verbose = verbose;
}
public void setNote(boolean note)
{
if (note)
{
// Switch on notes if they were completely disabled.
if (configuration.note != null &&
configuration.note.isEmpty())
{
configuration.note = null;
}
}
else
{
// Switch off notes.
configuration.note = new ArrayList();
}
}
public void setWarn(boolean warn)
{
if (warn)
{
// Switch on warnings if they were completely disabled.
if (configuration.warn != null &&
configuration.warn.isEmpty())
{
configuration.warn = null;
}
}
else
{
// Switch off warnings.
configuration.warn = new ArrayList();
}
}
public void setIgnorewarnings(boolean ignoreWarnings)
{
configuration.ignoreWarnings = ignoreWarnings;
}
public void setPrintconfiguration(File printConfiguration)
{
configuration.printConfiguration = optionalFile(printConfiguration);
}
public void setDump(File dump)
{
configuration.dump = optionalFile(dump);
}
// Implementations for Task.
public void execute() throws BuildException
{
try
{
ProGuard proGuard = new ProGuard(configuration);
proGuard.execute();
}
catch (IOException ex)
{
throw new BuildException(ex.getMessage());
}
}
// Small utility methods.
/**
* Returns a file that is properly resolved with respect to the project
* directory, or <code>null</code> or empty if its name is actually a
* boolean flag.
*/
private File optionalFile(File file)
{
String fileName = file.getName();
return
fileName.equalsIgnoreCase("false") ||
fileName.equalsIgnoreCase("no") ||
fileName.equalsIgnoreCase("off") ? null :
fileName.equalsIgnoreCase("true") ||
fileName.equalsIgnoreCase("yes") ||
fileName.equalsIgnoreCase("on") ? new File("") :
resolvedFile(file);
}
/**
* Returns a file that is properly resolved with respect to the project
* directory.
*/
private File resolvedFile(File file)
{
return file.isAbsolute() ? file :
new File(getProject().getBaseDir(),
file.getName());
}
}
|