1*90c8c64dSAndroid Build Coastguard Worker2009/04/20. 2*90c8c64dSAndroid Build Coastguard Worker 3*90c8c64dSAndroid Build Coastguard Worker------- 4*90c8c64dSAndroid Build Coastguard Worker1- Goal 5*90c8c64dSAndroid Build Coastguard Worker------- 6*90c8c64dSAndroid Build Coastguard Worker 7*90c8c64dSAndroid Build Coastguard WorkerMkStub is small tool that takes a given JAR and filters all the private stuff we don't want to 8*90c8c64dSAndroid Build Coastguard Workerexpose, e.g.: 9*90c8c64dSAndroid Build Coastguard Worker- remove all private members. 10*90c8c64dSAndroid Build Coastguard Worker- only include a subset of classes. 11*90c8c64dSAndroid Build Coastguard Worker- exclude specific classes, fields or methods. 12*90c8c64dSAndroid Build Coastguard Worker 13*90c8c64dSAndroid Build Coastguard WorkerEach method body is replaced by the bytecode for 'throw new RuntimeException("stub");'. 14*90c8c64dSAndroid Build Coastguard Worker 15*90c8c64dSAndroid Build Coastguard Worker 16*90c8c64dSAndroid Build Coastguard Worker-------- 17*90c8c64dSAndroid Build Coastguard Worker2- Usage 18*90c8c64dSAndroid Build Coastguard Worker-------- 19*90c8c64dSAndroid Build Coastguard Worker 20*90c8c64dSAndroid Build Coastguard WorkerTo control it, you give it patterns like this: 21*90c8c64dSAndroid Build Coastguard Worker 22*90c8c64dSAndroid Build Coastguard Worker +foo => accepts all items which signature is exactly "foo" 23*90c8c64dSAndroid Build Coastguard Worker +foo* => accepts all items which signature starts by "foo" 24*90c8c64dSAndroid Build Coastguard Worker -bar => rejects all items which signature is exactly "bar" 25*90c8c64dSAndroid Build Coastguard Worker -bar* => rejects all items which signature starts by "bar" 26*90c8c64dSAndroid Build Coastguard Worker 27*90c8c64dSAndroid Build Coastguard WorkerSignatures are defined by: 28*90c8c64dSAndroid Build Coastguard Worker- a package name, e.g. com.android.blah 29*90c8c64dSAndroid Build Coastguard Worker- a dot followed by a class name 30*90c8c64dSAndroid Build Coastguard Worker- a # followed by a field or method name 31*90c8c64dSAndroid Build Coastguard Worker- an internal "Java method signature" that define parameters types and return value. 32*90c8c64dSAndroid Build Coastguard Worker 33*90c8c64dSAndroid Build Coastguard WorkerExamples of signatures: 34*90c8c64dSAndroid Build Coastguard Worker com.android.blah 35*90c8c64dSAndroid Build Coastguard Worker com.android.blah.MyClass 36*90c8c64dSAndroid Build Coastguard Worker com.android.blah.MyClass$MyInnerClass 37*90c8c64dSAndroid Build Coastguard Worker com.android.blah.MyClass#mPrivateField 38*90c8c64dSAndroid Build Coastguard Worker com.android.blah.MyClass#getInternalStuff 39*90c8c64dSAndroid Build Coastguard Worker com.android.blah.MyClass#getInternalStuff(Ljava/lang/String;I)V 40*90c8c64dSAndroid Build Coastguard Worker 41*90c8c64dSAndroid Build Coastguard WorkerAn example of configuration file: 42*90c8c64dSAndroid Build Coastguard Worker +com.android.blah 43*90c8c64dSAndroid Build Coastguard Worker -com.android.blah.MyClass$MyInnerClass 44*90c8c64dSAndroid Build Coastguard Worker -com.android.blah.MyClass#mPrivateField 45*90c8c64dSAndroid Build Coastguard Worker -com.android.blah.MyClass#getInternalStuff(Ljava/lang/String;I)V 46*90c8c64dSAndroid Build Coastguard Worker 47*90c8c64dSAndroid Build Coastguard WorkerThis would include only the indicated package yet would totally exclude the inner class 48*90c8c64dSAndroid Build Coastguard Workerand the specific field and the method with the exact given signature. 49*90c8c64dSAndroid Build Coastguard Worker 50*90c8c64dSAndroid Build Coastguard Worker 51*90c8c64dSAndroid Build Coastguard Worker 52*90c8c64dSAndroid Build Coastguard WorkerTo invoke MkStub, the syntax is: 53*90c8c64dSAndroid Build Coastguard Worker 54*90c8c64dSAndroid Build Coastguard Worker $ java -jar mkstubs input.jar output.jar [@configfile -pattern +pattern ...] 55*90c8c64dSAndroid Build Coastguard Worker 56*90c8c64dSAndroid Build Coastguard Worker 57*90c8c64dSAndroid Build Coastguard Worker 58*90c8c64dSAndroid Build Coastguard Worker-------------------- 59*90c8c64dSAndroid Build Coastguard Worker3- Known Limitations 60*90c8c64dSAndroid Build Coastguard Worker-------------------- 61*90c8c64dSAndroid Build Coastguard Worker 62*90c8c64dSAndroid Build Coastguard WorkerMost of the following limitations exist solely because of the short development time and 63*90c8c64dSAndroid Build Coastguard Workerbecause the tool was designed to solve one task and not just to be super generic. That means 64*90c8c64dSAndroid Build Coastguard Workerany limitation here can be easily lifted. 65*90c8c64dSAndroid Build Coastguard Worker 66*90c8c64dSAndroid Build Coastguard Worker- The generated constructors are not proper. They do not invoke the matching super() 67*90c8c64dSAndroid Build Coastguard Worker before the generated throw exception. Any attempt to load such a class should trigger 68*90c8c64dSAndroid Build Coastguard Worker an error from the byte code verifier or the class loader. 69*90c8c64dSAndroid Build Coastguard Worker 70*90c8c64dSAndroid Build Coastguard Worker- We do not currently check whether a class or method uses only included types. 71*90c8c64dSAndroid Build Coastguard Worker Suggestion: if type x.y.z is excluded, then any field, annotation, generic type, 72*90c8c64dSAndroid Build Coastguard Worker method parameter or return value that uses that type should generate a fatal error. 73*90c8c64dSAndroid Build Coastguard Worker 74*90c8c64dSAndroid Build Coastguard Worker- We do not filter out private classes. Their .class will still be present in the 75*90c8c64dSAndroid Build Coastguard Worker output (and stubbed), unless they are explicitly excluded. 76*90c8c64dSAndroid Build Coastguard Worker This is not orthogonal to the fact that private fields and methods are automatically 77*90c8c64dSAndroid Build Coastguard Worker excluded. 78*90c8c64dSAndroid Build Coastguard Worker 79*90c8c64dSAndroid Build Coastguard Worker- Private fields and methods are automatically excluded. There is no command line 80*90c8c64dSAndroid Build Coastguard Worker switch to prevent that. 81*90c8c64dSAndroid Build Coastguard Worker 82*90c8c64dSAndroid Build Coastguard Worker- The stubbed source is always generated. For example if the output jar name is 83*90c8c64dSAndroid Build Coastguard Worker given as ~/somedir/myfinal.jar, there will be a directory created at 84*90c8c64dSAndroid Build Coastguard Worker ~/somedir/myfinal.jar_sources that will contain the equivalent Java sources. 85*90c8c64dSAndroid Build Coastguard Worker There is not command line switch to prevent that. 86*90c8c64dSAndroid Build Coastguard Worker 87*90c8c64dSAndroid Build Coastguard Worker- There is no attempt to match features or behavior with DroidDoc. 88*90c8c64dSAndroid Build Coastguard Worker 89*90c8c64dSAndroid Build Coastguard Worker-- 90*90c8c64dSAndroid Build Coastguard Workerend 91