1 22 package proguard; 23 24 import java.io.*; 25 import java.util.*; 26 27 32 public class GPL 33 { 34 38 public static void check() 39 { 40 ByteArrayOutputStream out = new ByteArrayOutputStream(); 41 new Exception ().printStackTrace(new PrintStream(out)); 42 LineNumberReader reader = new LineNumberReader( 43 new InputStreamReader( 44 new ByteArrayInputStream(out.toByteArray()))); 45 46 Set unknownPackageNames = unknownPackageNames(reader); 47 48 if (unknownPackageNames.size() > 0) 49 { 50 String uniquePackageNames = uniquePackageNames(unknownPackageNames); 51 52 System.out.println("ProGuard is released under the GNU General Public License. The authors of all"); 53 System.out.println("programs or plugins that link to it ("+uniquePackageNames+"...) therefore"); 54 System.out.println("must ensure that these programs carry the GNU General Public License as well."); 55 } 56 } 57 58 59 62 private static Set unknownPackageNames(LineNumberReader reader) 63 { 64 Set packageNames = new HashSet(); 65 66 try 67 { 68 while (true) 69 { 70 String line = reader.readLine(); 71 if (line == null) 72 { 73 break; 74 } 75 76 line = line.trim(); 77 if (line.startsWith("at ")) 78 { 79 line = line.substring(2).trim(); 80 line = trimSuffix(line, '('); 81 line = trimSuffix(line, '.'); 82 line = trimSuffix(line, '.'); 83 84 if (line.length() > 0 && !isKnown(line)) 85 { 86 packageNames.add(line); 87 } 88 } 89 } 90 } 91 catch (IOException ex) 92 { 93 } 94 95 return packageNames; 96 } 97 98 99 103 private static String uniquePackageNames(Set packageNames) 104 { 105 StringBuffer buffer = new StringBuffer (); 106 107 Iterator iterator = packageNames.iterator(); 108 while (iterator.hasNext()) 109 { 110 String packageName = (String )iterator.next(); 111 if (!containsPrefix(packageNames, packageName)) 112 { 113 buffer.append(packageName).append(", "); 114 } 115 } 116 117 return buffer.toString(); 118 } 119 120 121 125 private static String trimSuffix(String string, char separator) 126 { 127 int index = string.lastIndexOf(separator); 128 return index < 0 ? "" : string.substring(0, index); 129 } 130 131 132 135 private static boolean containsPrefix(Set set, String name) 136 { 137 int index = 0; 138 139 while (!set.contains(name.substring(0, index))) 140 { 141 index = name.indexOf('.', index + 1); 142 if (index < 0) 143 { 144 return false; 145 } 146 } 147 148 return true; 149 } 150 151 152 159 private static boolean isKnown(String packageName) 160 { 161 return packageName.startsWith("java") || 162 packageName.startsWith("sun.reflect") || 163 packageName.startsWith("proguard") || 164 packageName.startsWith("org.apache.tools.ant") || 165 packageName.startsWith("org.apache.tools.maven") || 166 packageName.startsWith("org.eclipse") || 167 packageName.startsWith("org.netbeans") || 168 packageName.startsWith("com.sun.kvem") || 169 packageName.startsWith("jg.j2me") || 170 packageName.startsWith("jg.common") || 171 packageName.startsWith("jg.buildengine"); 172 } 173 174 175 public static void main(String [] args) 176 { 177 LineNumberReader reader = new LineNumberReader( 178 new InputStreamReader(System.in)); 179 180 Set unknownPackageNames = unknownPackageNames(reader); 181 182 if (unknownPackageNames.size() > 0) 183 { 184 String uniquePackageNames = uniquePackageNames(unknownPackageNames); 185 186 System.out.println(uniquePackageNames); 187 } 188 } 189 } 190 | Popular Tags |