1 21 package proguard.wtk; 22 23 import com.sun.kvem.environment.*; 24 import proguard.*; 25 import proguard.classfile.*; 26 27 import java.io.*; 28 import java.util.*; 29 30 31 48 public class ProGuardObfuscator implements Obfuscator 49 { 50 private static final String DEFAULT_CONFIGURATION = "default.pro"; 51 52 53 55 public void createScriptFile(File jadFile, 56 File projectDir) 57 { 58 } 61 62 63 public void run(File obfuscatedJarFile, 64 String wtkBinDir, 65 String wtkLibDir, 66 String jarFileName, 67 String projectDirName, 68 String classPath, 69 String emptyAPI) 70 throws IOException 71 { 72 Configuration configuration = new Configuration(); 74 75 ConfigurationParser parser = new ConfigurationParser(this.getClass().getResource(DEFAULT_CONFIGURATION)); 77 78 try 79 { 80 parser.parse(configuration); 81 82 configuration.libraryJars = classPath(classPath); 84 85 configuration.programJars = new ClassPath(); 87 configuration.programJars.add(new ClassPathEntry(new File(jarFileName), false)); 88 configuration.programJars.add(new ClassPathEntry(obfuscatedJarFile, true)); 89 90 configuration.useMixedCaseClassNames = 93 !System.getProperty("os.name").regionMatches(true, 0, "windows", 0, 7); 94 95 ProGuard proGuard = new ProGuard(configuration); 97 proGuard.execute(); 98 99 } 100 catch (ParseException ex) 101 { 102 throw new IOException(ex.getMessage()); 103 } 104 finally 105 { 106 parser.close(); 107 } 108 } 109 110 111 114 private ClassPath classPath(String classPathString) 115 { 116 ClassPath classPath = new ClassPath(); 117 118 String separator = System.getProperty("path.separator"); 119 120 int index = 0; 121 while (index < classPathString.length()) 122 { 123 int next_index = classPathString.indexOf(separator, index); 125 if (next_index < 0) 126 { 127 next_index = classPathString.length(); 128 } 129 130 ClassPathEntry classPathEntry = 132 new ClassPathEntry(new File(classPathString.substring(index, next_index)), 133 false); 134 135 classPath.add(classPathEntry); 136 137 index = next_index + 1; 139 } 140 141 return classPath; 142 } 143 } 144 | Popular Tags |