'. '

ObfuscatePerLibrary

From APIDesign

(Difference between revisions)
Jump to: navigation, search
(Design)
Line 33: Line 33:
</source>
</source>
 +
 +
Need to generate [[JavaScript]] which can be loaded into [[Bck2Brwsr]] [[VM]]. E.g. the actual '''vm''' object is already created and need to be passed to the generated script (investigate [http://requirejs.org/ requirejs.org]). The script assumes existence of method ''registerLibrary'' in the calling context:
 +
 +
<source lang="javascript">
 +
registerLibrary(/*['dep','anotherDep','moreDep']*/, function (vm) {
 +
// when invoked register all methods into the vm object
 +
});
 +
</source>
 +
 +
As soon as one does var vm = bck2brwsr(...) all the provided libraries will be loaded.
=== TODO ===
=== TODO ===
[[Category:Bck2Brwsr]]
[[Category:Bck2Brwsr]]

Revision as of 13:51, 3 April 2013

Bck2Brwsr supports static obfuscation mode when whole application is converted into a gigantic static JavaScript. This is not much different to what GWT does. However that looses the dynamic nature of Java and thus I'd like to achieve a state when we will do obfuscation per library - e.g. JAR file. Only some package (possibly individual classes) could be exported. By default everything would be hidden (obviously all private and package private methods).

I hope this could give us the benefits of deep obfuscation (most of the classes obfuscated) with ability to link individual libraries in an incremental fashion. Moreover we would not need enormous gigs of memory to compile modestly large applications.

Alternative Deployment

Browsers are optimized for consuming JavaScript (compressed by GZip). We tried to use ZIP, but it is not the most effective solution. That is why let's modify our maven archetype to generate alternative .js.gzip file for per JAR file. If the JavaScript file is found, let bck2brwsr use it. If not, let [bck2brwsr]] download and use the JAR file.

Design

Define @Exported annotation to put on packages, classes, methods. This exported elements need to stick to fixed identifier.

Do as much calls as possible inside a library with obfuscated names. Private, package private methods should be obfuscated (unless @Exported). Classes in non-exported packages can have everything obfuscated (unless implement exported symbol). Exported classes should generate something like this:

function org_nb_test_Clazz() {
 
}
vm['org/nb/test/Clazz'] = org_nb_test_Clazz;

public or protected non-final methods need to be exported in an overridable style:

function org_nb_test_Clazz() {
  var p = ...;
 
  org_nb_test_Clazz.impl_myFunction_V = function () { ... };
 
  p['myFunction_V'] = org_nb_test_Clazz.impl_myFunction_V;
  p.callMyFunction_V = function() { return this['myFunction_V'](); }
}

Need to generate JavaScript which can be loaded into Bck2Brwsr VM. E.g. the actual vm object is already created and need to be passed to the generated script (investigate requirejs.org). The script assumes existence of method registerLibrary in the calling context:

registerLibrary(/*['dep','anotherDep','moreDep']*/, function (vm) {
  // when invoked register all methods into the vm object
});

As soon as one does var vm = bck2brwsr(...) all the provided libraries will be loaded.

TODO

Personal tools
buy