📄 proguardgui.java
字号:
} /** * Returns the ProGuard configuration that reflects the current GUI settings. */ private Configuration getProGuardConfiguration() { Configuration configuration = new Configuration(); // Get the input and output jars and directories. configuration.programJars = programPanel.getClassPath(); configuration.libraryJars = libraryPanel.getClassPath(); // Collect the boilerplate keep options. List keep = new ArrayList(); for (int index = 0; index < boilerplateKeep.length; index++) { if (boilerplateKeepCheckBoxes[index].isSelected()) { addClassSpecifications(keep, boilerplateKeep[index], boilerplateKeepTextFields[index].getText()); } } // Collect the additional keep options. List additionalKeep = additionalKeepPanel.getClassSpecifications(); if (additionalKeep != null) { keep.addAll(additionalKeep); } // Put the list of keep options in the configuration. if (keep.size() > 0) { configuration.keep = keep; } // Collect the boilerplate keep names options. List keepNames = new ArrayList(); for (int index = 0; index < boilerplateKeepNames.length; index++) { if (boilerplateKeepNamesCheckBoxes[index].isSelected()) { addClassSpecifications(keepNames, boilerplateKeepNames[index], boilerplateKeepNamesTextFields[index].getText()); } } // Collect the additional keep names options. List additionalKeepNames = additionalKeepNamesPanel.getClassSpecifications(); if (additionalKeepNames != null) { keepNames.addAll(additionalKeepNames); } // Put the list of keep names options in the configuration. if (keepNames.size() > 0) { configuration.keepNames = keepNames; } // Collect the boilerplate "no side effect methods" options. List noSideEffectMethods = new ArrayList(); for (int index = 0; index < boilerplateNoSideEffectMethods.length; index++) { if (boilerplateNoSideEffectMethodCheckBoxes[index].isSelected()) { noSideEffectMethods.add(boilerplateNoSideEffectMethods[index]); } } // Collect the additional "no side effect methods" options. List additionalNoSideEffectOptions = additionalNoSideEffectsPanel.getClassSpecifications(); if (additionalNoSideEffectOptions != null) { noSideEffectMethods.addAll(additionalNoSideEffectOptions); } // Put the list of "no side effect methods" options in the configuration. if (noSideEffectMethods.size() > 0) { configuration.assumeNoSideEffects = noSideEffectMethods; } // Get the other options. configuration.shrink = shrinkCheckBox .isSelected(); configuration.printUsage = printUsageCheckBox .isSelected() ? printUsageTextField .getText() : null; configuration.optimize = optimizeCheckBox .isSelected(); configuration.allowAccessModification = allowAccessModificationCheckBox .isSelected(); configuration.obfuscate = obfuscateCheckBox .isSelected(); configuration.printMapping = printMappingCheckBox .isSelected() ? printMappingTextField .getText() : null; configuration.applyMapping = applyMappingCheckBox .isSelected() ? applyMappingTextField .getText() : null; configuration.obfuscationDictionary = obfuscationDictionaryCheckBox .isSelected() ? obfuscationDictionaryTextField .getText() : null; configuration.overloadAggressively = overloadAggressivelyCheckBox .isSelected(); configuration.defaultPackage = defaultPackageCheckBox .isSelected() ? defaultPackageTextField .getText() : null; configuration.useMixedCaseClassNames = useMixedCaseClassNamesCheckBox .isSelected(); configuration.keepAttributes = keepAttributesCheckBox .isSelected() ? ListUtil.commaSeparatedList(keepAttributesTextField.getText()) : null; configuration.newSourceFileAttribute = newSourceFileAttributeCheckBox .isSelected() ? newSourceFileAttributeTextField .getText() : null; configuration.printSeeds = printSeedsCheckBox .isSelected() ? printSeedsTextField .getText() : null; configuration.verbose = verboseCheckBox .isSelected(); configuration.note = noteCheckBox .isSelected(); configuration.warn = warnCheckBox .isSelected(); configuration.ignoreWarnings = ignoreWarningsCheckBox .isSelected(); configuration.skipNonPublicLibraryClasses = skipNonPublicLibraryClassesCheckBox .isSelected(); configuration.skipNonPublicLibraryClassMembers = skipNonPublicLibraryClassMembersCheckBox.isSelected(); return configuration; } /** * Looks in the given list for a ProGuard option that is identical to the * given template. Returns true if it found, and removes the matching option * as a side effect. */ private boolean findClassSpecification(ClassSpecification classSpecificationTemplate, List classSpecifications) { if (classSpecifications == null) { return false; } for (int index = 0; index < classSpecifications.size(); index++) { if (classSpecificationTemplate.equals(classSpecifications.get(index))) { // Remove the matching option as a side effect. classSpecifications.remove(index); return true; } } return false; } /** * Looks in the given list for ProGuard options that match the given template. * Returns a comma-separated string of class file names from matching options, * and removes the matching options as a side effect. */ private String findMatchingClassSpecifications(ClassSpecification classSpecificationTemplate, List classSpecifications) { if (classSpecifications == null) { return null; } StringBuffer buffer = null; for (int index = 0; index < classSpecifications.size(); index++) { ClassSpecification listedClassSpecification = (ClassSpecification)classSpecifications.get(index); String className = listedClassSpecification.className; classSpecificationTemplate.className = className; if (classSpecificationTemplate.equals(listedClassSpecification)) { if (buffer == null) { buffer = new StringBuffer(); } else { buffer.append(','); } buffer.append(className == null ? "*" : ClassUtil.externalClassName(className)); // Remove the matching option as a side effect. classSpecifications.remove(index--); } } return buffer == null ? null : buffer.toString(); } /** * Adds ProGuard options to the given list, based on the given option * template and the comma-separated list of class names to be filled in. */ private void addClassSpecifications(List classSpecifications, ClassSpecification classSpecificationTemplate, String classNamesString) { List classNames = ListUtil.commaSeparatedList(classNamesString); for (int index = 0; index < classNames.size(); index++) { String className = (String)classNames.get(index); // Create a copy of the template. ClassSpecification classSpecification = (ClassSpecification)classSpecificationTemplate.clone(); // Set the class name in the copy. classSpecification.className = className.equals("") || className.equals("*") ? null : ClassUtil.internalClassName(className); // Add the copy to the list. classSpecifications.add(classSpecification); } } // Methods and internal classes related to actions. /** * Loads the given ProGuard configuration into the GUI. */ private void loadConfiguration(String fileName) { try { // Parse the configuration file. ConfigurationParser parser = new ConfigurationParser(fileName); Configuration configuration = new Configuration(); parser.parse(configuration); // Let the GUI reflect the configuration. setProGuardConfiguration(configuration); } catch (IOException ex) { JOptionPane.showMessageDialog(getContentPane(), msg("cantOpenConfigurationFile", fileName), msg("warning"), JOptionPane.ERROR_MESSAGE); } catch (ParseException ex) { JOptionPane.showMessageDialog(getContentPane(), msg("cantParseConfigurationFile", fileName), msg("warning"), JOptionPane.ERROR_MESSAGE); } } /** * Loads the given ProGuard configuration into the GUI. */ private void loadConfiguration(URL url) { try { // Parse the configuration file. ConfigurationParser parser = new ConfigurationParser(url); Configuration configuration = new Configuration(); parser.parse(configuration); // Let the GUI reflect the configuration. setProGuardConfiguration(configuration); } catch (IOException ex) { JOptionPane.showMessageDialog(getContentPane(), msg("cantOpenConfigurationFile", url), msg("warning"), JOptionPane.ERROR_MESSAGE); } catch (ParseException ex) { JOptionPane.showMessageDialog(getContentPane(), msg("cantParseConfigurationFile", url), msg("warning"), JOptionPane.ERROR_MESSAGE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -