KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > Targeter


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This library 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)
10  * any later version.
11  *
12  * This library 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 Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard;
22
23 import proguard.classfile.ClassPool;
24 import proguard.classfile.util.ClassUtil;
25 import proguard.classfile.visitor.ClassVersionSetter;
26
27 import java.io.IOException JavaDoc;
28 import java.util.*;
29
30 /**
31  * This class sets the target version on program classes.
32  *
33  * @author Eric Lafortune
34  */

35 public class Targeter
36 {
37     private Configuration configuration;
38
39
40     /**
41      * Creates a new Targeter to set the target version on program classes
42      * according to the given configuration.
43      */

44     public Targeter(Configuration configuration)
45     {
46         this.configuration = configuration;
47     }
48
49
50     /**
51      * Sets the target version on classes in the given program class pool.
52      */

53     public void execute(ClassPool programClassPool) throws IOException JavaDoc
54     {
55         Set newerClassVersions = configuration.warn ? new HashSet() : null;
56
57         programClassPool.classesAccept(new ClassVersionSetter(configuration.targetClassVersion,
58                                                               newerClassVersions));
59
60         if (newerClassVersions != null &&
61             newerClassVersions.size() > 0)
62         {
63             System.err.print("Warning: some classes have more recent versions (");
64
65             Iterator iterator = newerClassVersions.iterator();
66             while (iterator.hasNext())
67             {
68                 Integer JavaDoc classVersion = (Integer JavaDoc)iterator.next();
69                 System.err.print(ClassUtil.externalClassVersion(classVersion.intValue()));
70
71                 if (iterator.hasNext())
72                 {
73                     System.err.print(",");
74                 }
75             }
76
77             System.err.println(")");
78             System.err.println(" than the target version ("+ClassUtil.externalClassVersion(configuration.targetClassVersion)+").");
79
80             if (!configuration.ignoreWarnings)
81             {
82                 System.err.println(" If you are sure this is not a problem,");
83                 System.err.println(" you could try your luck using the '-ignorewarnings' option.");
84                 throw new IOException JavaDoc("Please correct the above warnings first.");
85             }
86         }
87     }
88 }
89
Popular Tags