From 2f73363107965c8488088e96b1c55debf3be126a Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Tue, 30 Oct 2012 16:15:11 +0000 Subject: [PATCH] SDK: - improve obfuscation option - make obfuscation option obfuscate whole application incl libraries - add way to add options to obfuscation git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9920 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/gde/obfuscate/Bundle.properties | 1 + .../obfuscate/ObfuscateCompositeProvider.java | 42 +++++++------------ .../obfuscate/ObfuscateCustomizerPanel.form | 41 ++++++++++++++++-- .../obfuscate/ObfuscateCustomizerPanel.java | 40 ++++++++++++++---- .../jme3/gde/obfuscate/pro-guard-targets.xml | 26 +++++++----- 5 files changed, 100 insertions(+), 50 deletions(-) diff --git a/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/Bundle.properties b/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/Bundle.properties index 4e90126cc..92045b854 100644 --- a/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/Bundle.properties +++ b/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/Bundle.properties @@ -6,3 +6,4 @@ OpenIDE-Module-Short-Description=Support for obfuscating distributions ObfuscateCustomizerPanel.jCheckBox1.text=Obfuscate Build ProGuard=ProGuard LBL_Category_Obfuscate=Obfuscation +ObfuscateCustomizerPanel.jLabel1.text=Obfuscation option additions: diff --git a/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCompositeProvider.java b/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCompositeProvider.java index 3103ed5a7..151e8702f 100644 --- a/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCompositeProvider.java +++ b/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCompositeProvider.java @@ -28,8 +28,17 @@ public class ObfuscateCompositeProvider implements ProjectCustomizer.CompositeCa private static final String CAT_OBFUSCATION = "Obfuscation"; // NOI18N private static ProjectExtensionProperties jwsProps = null; private String[] keyList = new String[]{ - "obfuscate" + "obfuscate", + "obfuscate.options" }; + private static String defaultOpts = "-keep public class * extends com.jme3.app.Application{public *;}\n" + + "-keep public class * extends com.jme3.system.JmeSystemDelegate{public *;}\n" + + "-keep public class * implements com.jme3.renderer.Renderer{public *;}\n" + + "-keep public class * implements com.jme3.asset.AssetLoader{public *;}\n" + + "-keep public class * implements com.jme3.asset.AssetLocator{public *;}\n" + + "-keep public class * implements de.lessvoid.nifty.screen.ScreenController{public *;}\n" + + "-dontwarn\n" + + "-dontnote\n"; public ObfuscateCompositeProvider() { } @@ -43,6 +52,9 @@ public class ObfuscateCompositeProvider implements ProjectCustomizer.CompositeCa @Override public JComponent createComponent(ProjectCustomizer.Category category, Lookup context) { jwsProps = new ProjectExtensionProperties(context.lookup(Project.class), keyList); + if(jwsProps.getProperty("obfuscate.options")==null){ + jwsProps.setProperty("obfuscate.options", defaultOpts); + } ObfuscateCustomizerPanel panel = new ObfuscateCustomizerPanel(jwsProps); category.setStoreListener(new SavePropsListener(jwsProps, context.lookup(Project.class))); category.setOkButtonListener(panel); @@ -52,7 +64,7 @@ public class ObfuscateCompositeProvider implements ProjectCustomizer.CompositeCa private class SavePropsListener implements ActionListener { private String extensionName = "obfuscate"; - private String extensionVersion = "v0.9"; + private String extensionVersion = "v0.10"; private String[] extensionDependencies = new String[]{"-post-jar", "-obfuscate"}; private ProjectExtensionManager manager = new ProjectExtensionManager(extensionName, extensionVersion, extensionDependencies); private ProjectExtensionProperties properties; @@ -77,31 +89,5 @@ public class ObfuscateCompositeProvider implements ProjectCustomizer.CompositeCa Exceptions.printStackTrace(ioe); } } - -// private void unZipFile(InputStream source, FileObject projectRoot) throws IOException { -// try { -// ZipInputStream str = new ZipInputStream(source); -// ZipEntry entry; -// while ((entry = str.getNextEntry()) != null) { -// if (entry.isDirectory()) { -// FileUtil.createFolder(projectRoot, entry.getName()); -// } else { -// FileObject fo = FileUtil.createData(projectRoot, entry.getName()); -// writeFile(str, fo); -// } -// } -// } finally { -// source.close(); -// } -// } -// -// private void writeFile(ZipInputStream str, FileObject fo) throws IOException { -// OutputStream out = fo.getOutputStream(); -// try { -// FileUtil.copy(str, out); -// } finally { -// out.close(); -// } -// } } } diff --git a/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCustomizerPanel.form b/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCustomizerPanel.form index 23cb97c48..863707e15 100644 --- a/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCustomizerPanel.form +++ b/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCustomizerPanel.form @@ -1,4 +1,4 @@ - +
@@ -16,9 +16,16 @@ - + - + + + + + + + + @@ -28,7 +35,11 @@ - + + + + + @@ -41,5 +52,27 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCustomizerPanel.java b/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCustomizerPanel.java index feaba966a..a7ba7ffd9 100644 --- a/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCustomizerPanel.java +++ b/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCustomizerPanel.java @@ -23,7 +23,9 @@ public class ObfuscateCustomizerPanel extends javax.swing.JPanel implements Acti private ProjectExtensionProperties properties; - /** Creates new form LwjglAppletCustomizerPanel */ + /** + * Creates new form LwjglAppletCustomizerPanel + */ public ObfuscateCustomizerPanel(ProjectExtensionProperties properties) { this.properties = properties; initComponents(); @@ -38,6 +40,8 @@ public class ObfuscateCustomizerPanel extends javax.swing.JPanel implements Acti } else { jCheckBox1.setSelected(false); } + String props = properties.getProperty("obfuscate.options"); + jTextArea1.setText(props); } private void saveProperties() { @@ -46,32 +50,47 @@ public class ObfuscateCustomizerPanel extends javax.swing.JPanel implements Acti } else { properties.setProperty("obfuscate", ""); } + properties.setProperty("obfuscate.options", jTextArea1.getText()); } public void actionPerformed(ActionEvent e) { saveProperties(); } - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { jCheckBox1 = new javax.swing.JCheckBox(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jLabel1 = new javax.swing.JLabel(); jCheckBox1.setText(org.openide.util.NbBundle.getMessage(ObfuscateCustomizerPanel.class, "ObfuscateCustomizerPanel.jCheckBox1.text")); // NOI18N + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jScrollPane1.setViewportView(jTextArea1); + + jLabel1.setText(org.openide.util.NbBundle.getMessage(ObfuscateCustomizerPanel.class, "ObfuscateCustomizerPanel.jLabel1.text")); // NOI18N + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(jCheckBox1, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE) + .addComponent(jCheckBox1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( @@ -79,10 +98,17 @@ public class ObfuscateCustomizerPanel extends javax.swing.JPanel implements Acti .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jCheckBox1) - .addContainerGap(241, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE) + .addContainerGap()) ); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox jCheckBox1; + private javax.swing.JLabel jLabel1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea jTextArea1; // End of variables declaration//GEN-END:variables } diff --git a/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/pro-guard-targets.xml b/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/pro-guard-targets.xml index e1b9435ba..12b911bfe 100644 --- a/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/pro-guard-targets.xml +++ b/sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/pro-guard-targets.xml @@ -2,17 +2,20 @@ - -libraryjars ${proguard.library.path} - -injars ${dist.jar} - -outjars ${dist.jar}.obfuscated.jar - -keepclasseswithmembers public class * { - public static void main(java.lang.String[]); - } - -keep public class * implements de.lessvoid.nifty.screen.ScreenController - -keep public class * extends com.jme3.app.Application + -libraryjars ${proguard.library.path} + -injars ${dist.dir}/lib(!META-INF/MANIFEST.MF) + -injars ${dist.jar} + -outjars ${dist.jar}.obfuscated.jar + -keepclasseswithmembers public class * { + public static void main(java.lang.String[]); + } + ${obfuscate.options} + + + @@ -22,15 +25,16 @@ - + - + - \ No newline at end of file + + \ No newline at end of file