- add obfuscation support to jMP via ProGuard

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@6987 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 14 years ago
parent 3fe5911b66
commit 927721259a
  1. 8
      sdk/jme3-obfuscate/build.xml
  2. 6
      sdk/jme3-obfuscate/manifest.mf
  3. 45
      sdk/jme3-obfuscate/nbproject/build-impl.xml
  4. 8
      sdk/jme3-obfuscate/nbproject/genfiles.properties
  5. 6
      sdk/jme3-obfuscate/nbproject/project.properties
  6. 73
      sdk/jme3-obfuscate/nbproject/project.xml
  7. 1
      sdk/jme3-obfuscate/nbproject/suite.properties
  8. BIN
      sdk/jme3-obfuscate/release/libs/proguard.jar
  9. BIN
      sdk/jme3-obfuscate/release/libs/retrace.jar
  10. 8
      sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/Bundle.properties
  11. 107
      sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCompositeProvider.java
  12. 45
      sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCustomizerPanel.form
  13. 88
      sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/ObfuscateCustomizerPanel.java
  14. 9
      sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/layer.xml
  15. 36
      sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/pro-guard-targets.xml
  16. 22
      sdk/jme3-obfuscate/src/com/jme3/gde/obfuscate/pro-guard.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="com.jme3.gde.obfuscate" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project com.jme3.gde.obfuscate.</description>
<import file="nbproject/build-impl.xml"/>
</project>

@ -0,0 +1,6 @@
Manifest-Version: 1.0
OpenIDE-Module: com.jme3.gde.obfuscate
OpenIDE-Module-Implementation-Version: 0
OpenIDE-Module-Layer: com/jme3/gde/obfuscate/layer.xml
OpenIDE-Module-Localizing-Bundle: com/jme3/gde/obfuscate/Bundle.properties

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*** GENERATED FROM project.xml - DO NOT EDIT ***
*** EDIT ../build.xml INSTEAD ***
-->
<project name="com.jme3.gde.obfuscate-impl" basedir="..">
<fail message="Please build using Ant 1.7.1 or higher.">
<condition>
<not>
<antversion atleast="1.7.1"/>
</not>
</condition>
</fail>
<property file="nbproject/private/suite-private.properties"/>
<property file="nbproject/suite.properties"/>
<fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
<property file="${suite.dir}/nbproject/private/platform-private.properties"/>
<property file="${suite.dir}/nbproject/platform.properties"/>
<macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="${@{value}}"/>
</sequential>
</macrodef>
<macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="property"/>
<attribute name="value"/>
<sequential>
<property name="@{property}" value="@{value}"/>
</sequential>
</macrodef>
<property file="${user.properties.file}"/>
<nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
<condition>
<not>
<contains string="${cluster.path.evaluated}" substring="platform"/>
</not>
</condition>
</fail>
<import file="${harness.dir}/build.xml"/>
</project>

@ -0,0 +1,8 @@
build.xml.data.CRC32=db46de11
build.xml.script.CRC32=69663b9b
build.xml.stylesheet.CRC32=a56c6a5b@1.42.2
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=db46de11
nbproject/build-impl.xml.script.CRC32=c9f3ae73
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.42.2

@ -0,0 +1,6 @@
javac.source=1.5
javac.compilerargs=-Xlint -Xlint:-serial
nbm.homepage=http://proguard.sourceforge.net/
nbm.module.author=Normen Hansen
nbm.needs.restart=true
spec.version.base=0.8.0

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.apisupport.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>com.jme3.gde.obfuscate</code-name-base>
<suite-component/>
<module-dependencies>
<dependency>
<code-name-base>com.jme3.gde.core</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>0.12</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.project.ant</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.40</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.projectapi</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.35</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.50.0.8</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.filesystems</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.46</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>8.14</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util.lookup</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>8.6</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
<public-packages/>
</data>
</configuration>
</project>

@ -0,0 +1,8 @@
OpenIDE-Module-Display-Category=jMonkeyPlatform
OpenIDE-Module-Long-Description=\
Support for obfuscating distributions using ProGuard
OpenIDE-Module-Name=Obfuscation Support
OpenIDE-Module-Short-Description=Support for obfuscating distributions
ObfuscateCustomizerPanel.jCheckBox1.text=Obfuscate Build
ProGuard=ProGuard
LBL_Category_Obfuscate=Obfuscation

@ -0,0 +1,107 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.jme3.gde.obfuscate;
import com.jme3.gde.core.j2seproject.ProjectExtensionManager;
import com.jme3.gde.core.j2seproject.ProjectExtensionProperties;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JComponent;
import org.netbeans.api.project.Project;
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
/**
*
* @author normenhansen
*/
@ProjectCustomizer.CompositeCategoryProvider.Registration(projectType = "org-netbeans-modules-java-j2seproject", category = "Application", position = 510)
public class ObfuscateCompositeProvider implements ProjectCustomizer.CompositeCategoryProvider {
private static final String CAT_OBFUSCATION = "Obfuscation"; // NOI18N
private static ProjectExtensionProperties jwsProps = null;
private String[] keyList = new String[]{
"obfuscate"
};
public ObfuscateCompositeProvider() {
}
@Override
public ProjectCustomizer.Category createCategory(Lookup context) {
return ProjectCustomizer.Category.create(CAT_OBFUSCATION,
NbBundle.getMessage(ObfuscateCompositeProvider.class, "LBL_Category_Obfuscate"), null);
}
@Override
public JComponent createComponent(ProjectCustomizer.Category category, Lookup context) {
jwsProps = new ProjectExtensionProperties(context.lookup(Project.class), keyList);
ObfuscateCustomizerPanel panel = new ObfuscateCustomizerPanel(jwsProps);
category.setStoreListener(new SavePropsListener(jwsProps, context.lookup(Project.class)));
category.setOkButtonListener(panel);
return panel;
}
private class SavePropsListener implements ActionListener {
private String extensionName = "obfuscate";
private String extensionVersion = "v0.9";
private String[] extensionDependencies = new String[]{"-post-jar", "-obfuscate"};
private ProjectExtensionManager manager = new ProjectExtensionManager(extensionName, extensionVersion, extensionDependencies);
private ProjectExtensionProperties properties;
private Project project;
public SavePropsListener(ProjectExtensionProperties props, Project project) {
this.properties = props;
this.project = project;
manager.setAntTaskLibrary("pro-guard");
}
public void actionPerformed(ActionEvent e) {
if ("true".equals(properties.getProperty("obfuscate"))) {
manager.loadTargets("nbres:/com/jme3/gde/obfuscate/pro-guard-targets.xml");
manager.checkExtension(project);
} else {
manager.removeExtension(project);
}
try {
properties.store();
} catch (IOException ioe) {
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();
// }
// }
}
}

@ -0,0 +1,45 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jCheckBox1" pref="328" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jCheckBox1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="241" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JCheckBox" name="jCheckBox1">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/obfuscate/Bundle.properties" key="ObfuscateCustomizerPanel.jCheckBox1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Form>

@ -0,0 +1,88 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* LwjglAppletCustomizerPanel.java
*
* Created on 11.11.2010, 16:56:53
*/
package com.jme3.gde.obfuscate;
import com.jme3.gde.core.j2seproject.ProjectExtensionProperties;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.openide.util.HelpCtx;
/**
*
* @author normenhansen
*/
public class ObfuscateCustomizerPanel extends javax.swing.JPanel implements ActionListener {
private ProjectExtensionProperties properties;
/** Creates new form LwjglAppletCustomizerPanel */
public ObfuscateCustomizerPanel(ProjectExtensionProperties properties) {
this.properties = properties;
initComponents();
loadProperties();
HelpCtx.setHelpIDString(this, "sdk.application_deployment");
}
private void loadProperties() {
String str = properties.getProperty("obfuscate");
if ("true".equals(str)) {
jCheckBox1.setSelected(true);
} else {
jCheckBox1.setSelected(false);
}
}
private void saveProperties() {
if (jCheckBox1.isSelected()) {
properties.setProperty("obfuscate", "true");
} else {
properties.setProperty("obfuscate", "");
}
}
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jCheckBox1 = new javax.swing.JCheckBox();
jCheckBox1.setText(org.openide.util.NbBundle.getMessage(ObfuscateCustomizerPanel.class, "ObfuscateCustomizerPanel.jCheckBox1.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)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jCheckBox1)
.addContainerGap(241, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox jCheckBox1;
// End of variables declaration//GEN-END:variables
}

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
<folder name="org-netbeans-api-project-libraries">
<folder name="Libraries">
<file name="pro-guard.xml" url="pro-guard.xml"/>
</folder>
</folder>
</filesystem>

@ -0,0 +1,36 @@
<target name="-obfuscate" depends="-test-obfuscate-enabled,-create-library-property" if="is.obfuscate.enabled">
<taskdef resource="proguard/ant/task.properties"
classpath="${libs.pro-guard.classpath}" />
<proguard>
-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
</proguard>
<delete file="${dist.jar}"/>
<move file="${dist.jar}.obfuscated.jar" tofile="${dist.jar}"/>
</target>
<target name="-test-obfuscate-enabled">
<condition property="is.obfuscate.enabled">
<istrue value="${obfuscate}"/>
</condition>
</target>
<target name="-create-library-property" depends="-create-mac-library-property">
<property name="proguard.library.path" value="${java.home}/lib/rt.jar${path.separator}${run.classpath}"/>
</target>
<target name="-create-mac-library-property" depends="-test-mac" if="is.macos">
<property name="proguard.library.path" value="/System/Library/Frameworks/JavaVM.framework/Classes/classes.jar:${run.classpath}"/>
</target>
<target name="-test-mac">
<condition property="is.macos">
<os family="mac"/>
</condition>
</target>

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE library PUBLIC "-//NetBeans//DTD Library Declaration 1.0//EN" "http://www.netbeans.org/dtds/library-declaration-1_0.dtd">
<library version="1.0">
<name>pro-guard</name>
<type>j2se</type>
<localizing-bundle>com.jme3.gde.obfuscate.Bundle</localizing-bundle>
<volume>
<type>classpath</type>
<resource>jar:nbinst://com.jme3.gde.obfuscate/libs/proguard.jar!/</resource>
<resource>jar:nbinst://com.jme3.gde.obfuscate/libs/retrace.jar!/</resource>
</volume>
<volume>
<type>src</type>
</volume>
<volume>
<type>javadoc</type>
</volume>
</library>
Loading…
Cancel
Save