×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Porting Mobile Java

    GUMP, an aspect-oriented Java post-processor, is now available in Alpha as open source.

    Built on four years' experience of using byte-code engineering to solve the problems of porting to hundreds of devices, GUMP provides a more elegant alternative to source code pre-processors.

    By injecting fixes directly into the byte-code (the compiled .class files), the Java source code can be kept clean and simple. You no longer need to litter the source code with device specific variations.

    Once a problem-specific fix has been developed (using GUMP's pluggable framework), it is encapsulated as a re-usable gumplet that can be applied to any build to inject the same fix.

    Gumplets can also be used to inject debugging code, or to optimize performance.

    GUMP's resource manipulation framework makes it possible to develop gumplets that work on resources instead of code. For example, gumplets can insert manifest entries, or optmize and fix PNGs to suit a specific device.

    Current status as time of writing:

    • The project is considered "alpha", and should be treated as such.
    • The distribution contains a selection of sample gumplets - see the Gumplet Directory. It is hoped this will grow over time, and that other developers will contribute to this in the spirit of open source.
    • Documentation will be scant until I get the wiki is up and running. (NEWS!!: 20th June, 2009: Wiki is now running!)


    GUMP is built on the open source library Javassist, and an understanding of Javassist is necessary for gumplet development.

    With hope that you find this of use,
    Graham.
    Last edited by grahamhughes; 2009-06-20 at 19:52.

  2. #2
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Porting Mobile Java

    thanks Graham for sharing this with us !
    I hope it will grow out to be a succesfull project and that many "grumplets" will be developed by the community and obviously shared
    I wish you the best of luck !

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Porting Mobile Java

    Thanks Tiger69!!

    I should have added, GUMP runs inside Ant, so can integrate with your existing build process (assuming you use Ant!!). As such, it mixes easily with other porting techniques (including the use of pre-processors, though it largely makes them redundant).

    An example fix: replacing calls to Canvas.getHeight() with a constant, for devices that return the wrong value.

    PHP Code:
    replaceCalls(allClasses(),
        
    // this is the signature for the calls we want to replace
        
    "javax.microedition.lcdui.Canvas.getHeight()I",
        
    // this represents the code we're going to inject to replace each method call
        
    "{ $_ = 160; }"
    ); 
    "$_" is a placeholder for the return value from the method-call we're replacing. This code goes in a gumplet, so no source code in you MIDlet is modified. The fix will be applied directly to the byte code (.class files). If we wrap this in a gumplet called lcdui.ScreenHeightFix (a gumplet is just a class, to this is its class name), then the Ant script looks like:

    Code:
    <gumplet name="lcdui.ScreenHeightFix"/>
    Gumplets can be parameterized, so you can make that fix more general:

    PHP Code:
    replaceCalls(allClasses(),
        
    "javax.microedition.lcdui.Canvas.getHeight()I",
        
    "{ $_ = " screenHeight "; }"
    ); 
    The code in the Ant script then looks like:

    Code:
    <gumplet name="lcdui.ScreenHeightFix">
        <param name="screenHeight" value="${device.screenheight}"/>
    </gumplet>
    "device.screenheight" might come from existing device-properties files you already have (one for each device). Likewise, you can create separate xml files for each device (containing the gumplet tags relevant to that device).

    The complete gumplet class would be:

    PHP Code:
    package net.sourceforge.mobileporting.gump.gumplet.lcdui;

    import net.sourceforge.mobileporting.gump.gumplet.CodeModifier;
    import javassist.CannotCompileException;

    /**
     * Replaces calls to Canvas.getHeight() with a constant value, for devices
     * that return the wrong value in FullScreenMode.
     * <p>
     * <pre>
     * &lt;gumplet name="lcdui.ScreenHeightFix"/&gt;
     * </pre>
     * @author Graham Hughes
     */

    public class ScreenHeightFix extends CodeModifier {
        private 
    int screenHeight 160;

        @
    Override
        
    protected void process() throws CannotCompileException {
            
    replaceCalls(allClasses(),
                    
    "javax.microedition.lcdui.Canvas.getHeight()I",
                    
    "{ $_ = " screenHeight "; }"
            
    );
        }

        
    /**
         * @gumpletparameter
         * @param height full screen height of device (defaults to 160)
         */
        
    public void setScreenHeight(int height) {
            
    screenHeight h;
        }

    Once this is compiled, it becomes a permanent part of your library of fixes. Once you add it to you device-specific script, you never have to worry about this issue again.

    Share or don't share... it's up to you. If you need to keep company secrets secret, or you just don't want competitors benefiting from your hard work, that's fine.

    Cheers,
    Graham.

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Porting Mobile Java

    Last edited by grahamhughes; 2009-06-27 at 12:18.

  5. #5
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Porting Mobile Java

    UPDATE!! I've been informed that the link I posted is only accessible to me! I've now posted the correct, public link!

  6. #6
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Porting Mobile Java

    nice work graham ! good to see it's getting documented :P
    for simple minds like myself that helps out a lot

Similar Threads

  1. [moved] Mobile Porting Solutions
    By ninnythomas in forum News and Announcements
    Replies: 3
    Last Post: 2008-11-03, 10:10
  2. Mobile learning server / environment published
    By mikaset in forum News and Announcements
    Replies: 0
    Last Post: 2008-03-25, 20:50
  3. Execute Java applications at the phone from the mobile
    By JasonN in forum Mobile Java General
    Replies: 4
    Last Post: 2006-10-03, 13:36
  4. Java Mobile Phone Specification - Question for Nokia
    By schadha in forum Mobile Java General
    Replies: 0
    Last Post: 2002-09-04, 11:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •