vendredi 4 décembre 2009

How to - Android and Eclipse

Introduction


It was a long time I didn't post anything on the blog, mainly because I worked a lot on an internal project and because I haven't been working with a new technology for a while.

Another reason is that I'm looking for a job as Architect or Product Owner in Switzerland (Geneva or Lausanne), if you have any in your procket don't hesitate to contact me at jeanphiv@gmail.com:)

Stop speaking about me, my new playground is the Android platform (linked to the google AppEngine of course) and this tutorial will explain how to install the sdk and manage all what you need to build a whole project.

Tool version








Tool Version Download Install directory
eclipse 3.5.0, 20090621-0832 http://www.eclipse.org/downloads/ T:/eclipse/3.5.0
Android 2.0 http://developer.android.com/sdk/index.html T:/android/2.0
Eclipse Android plugin (ATD) 0.9.4 https://dl-ssl.google.com/android/eclipse/


Install the SDK


  • Download the sdk on http://developer.android.com/sdk/index.html
  • Unzip the file to the suitable directory (T:/android/2.0 in my case)
  • Create an ANDROID_HOME variable and add it to the path




  • Start the setup
  • If you use a proxy, you have to cancel the automatic download and set the proxy first.


  • Go back to Installed Packages and click on update all. If the connection fails, try to check the checkbox about https.


    Accept all download and wait.....

    Install the Android Development Tools (ADT) Plugin

    Go to the Help/Install new software menu and add the following plugin url provider
    https://dl-ssl.google.com/android/eclipse/



    When simply accept all licences and start downloading the features. It could take a long time before the sdk was fully updated.

    And restart Eclipse

    Configure the Eclipse plugin


    Once the plugin has been installed, you have to configure it:

    Go to the window/preferences menu, select Android and set the suitable path to the SDK



    Create an AVD (Android Virtual Device)


    Once the plugin has been configured, you can define your first AVD (Android Virtual Device). This is the phone model to which you want to develop. This feature is provided by clicking on the phone button of the toolbar.



    Create a new project


    Go to new project, select Other... then Android

    Modify the code of the main activity with the following code...



    ...and run the project, you should almost have the nicest interface in the world as show below:)


    Enjoy
    The End
  • jeudi 17 septembre 2009

    Grails with Eclipse

    Introduction

    As I've already said, I prefer Eclipse to Netbeans mainly for speed reasons. For now, Netbeans provides clearly a more accomplished management of Grails. Nevertheless, using this plugin is very frustrating (this is my advice) mainly because of its slowness. That's why I would like to test if Eclipse is able to manage a Grails project.

    This article describes how to manage a Grails project with Eclipse and what the Groovy plugin proposes.

    Tools version


    Tool Version Download Install directory
    eclipse 3.5.0, 20090621-0832 http://www.eclipse.org/downloads/ T:/eclipse/3.5.0
    plugin groovy V2 alpha http://groovy.codehaus.org/Eclipse+Plugin
    groovy 1.6.4 http://groovy.codehaus.org/Download T:/groovy/1.6.4/
    grails 1.1.1 http://grails.org/ T:/grails/1.1.1

    Create a new Grails project

    First create a new project with the following command: grails create-app eclipse-test1

    Configure eclipse

    Install the Groovy V2 alpha plugin

    Go to the Help/Install new software menu and add the following plugin url provider http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.5/

    When simply install the plugin






    Set GROOVY_HOME variable

    The plugin needs to know where your Groovy has been installed







    Prevent the groovy plugin from generation any class file

    The Grails documentation asks for preventing the Groovy plugin from generation any class files.







    This option seems to not be available any more in the new version of the groovy plugin.
    I think (and hope) we can consider that this step is no more needed

    Import the project in eclipse

    This is the standard way to import the Eclipse project generating by the Grails create-app command.

    Add groovy nature

    Right click on the project and add a groovy nature

    Remove the display of external library

    By default, all grails libraries are added to the project path and displayed in the project exporer. You can prevent Eclipse from displaying these jar by cliking on the Customize view of the explorer top left menu and set Library from external.

    Run project

    The project runs as java application calling the GrailsMain class.

    Think about adding your run configuration to the run and debug menu. Thus this action can be use faster from the java eclipse perspective.

    The project can be stopped correctly (without any instance of server remaining inlive)

    Groovy management

    The groovy nature has to be added to the project, unlike Netbeans, where is no grails specific issues. Eclipse manages groovy files, not domain, controller ...

    Error detection

    The first thing to check is how error are managed. I always think that a good IDE for a dynamic language should warn about 'strange code' and allow the user to decide which warning is pertinent. Maybe I will have a look on how it can be done in eclipse.

    • detect unknown class name: OK
    • detect unknown member: No
    • detect unknown constructor parameter: No
    • detect unknown method: No
    Completion
    completion is rather pleasant to use. It works fast and be able to add the needed import at the top of the class.
    • Class member: OK
    • Class method: OK
    • Import class package: OK
    • Find package: OK
    • Set constructor params: No
    • Ctrl click to reach another class: OK

    Refactoring

    The refactoring works fine. It's a great functionality especially for a dynamic language.

    You can move a class from a package to another one and eclipse change the impacted code for you.

    Debug

    The debug works fine. You can easily add beakpoint, watch your variable and so on....

    Conclusion

    My first feeling is rather good, Eclipse processes Groovy files significantly faster than Netbeans does. On the other side, there is no specific items dedicated to Grails.
    Nevertheless, I meet some strange behavior. In particularly because sometime Eclipse seems having some trouble to find an existing class and display an error.
    I will continue to explore deeply the couple Grails/Eclipse and focus on how improving the test speed
    In my advice this is a key point to improve the productivity of the Grails technology, but it will be the opportunity for another article.

    jeudi 6 août 2009

    Choisir c'est renoncer

    Choisir un framework ou un outil (quelque soit sa finalité) est rarement évident.
    Actuellement je continue mon exploration à temps (très) partiel du couple Django/Google App engine et j'essaie d'identifier les éléments qui influent mes décisions. Il faut bien avouer que si certains éléments sont très objectifs et quantifiables, d'autres sont beaucoup plus évanescents et procèdent plus de l'intuition que de la mesure physique.

    Le fait est que si vous voulez démarrer une application sans passer 6 mois à évaluer tous les frameworks de la terre, il faut être capable de faire un choix avec beaucoup d'inconnues. Le dilème étant toujours le même:
    Est ce que les avantages d'une technologie dépassent le temps d'apprentissage et les risques associés.

    Si vous avez la chance (mais la chance se provoque) de choisir le 'bon' framework que vous allez utiliser pendant plusieurs années, les avantages sont évidents. Par contre, dans tous les autres cas, la discussion est ouverte.

    A titre personnel j'ai souvent eu à faire ces choix. Certains choix se sont révélés excellents (hibernate/Spring plutot que JDO ou les EJB), conteneur léger plutot que conteneur lourd, enterprise Architect (pour l'UML). Certains bons choix etaient des renoncements (OpenLazlo).
    D'autres enfin me laissent encore des doutes (Grails).

    Au final, je pense que les critères les plus pertinents sont les suivants:

    L'Open source
    Je ne crois absolument pas aux frameworks maison, la version 1 marche bien, la 1.1 c'est ok mais on arrive rarement à la 2.0 faute de combattants, de ressources, de volonté....
    L'Open Source permet aussi de qualifier la vitalité de la communauté qui porte le projet sans les filtres commerciaux

    La fiabilité des premiers tests
    C'est pas forcement un indicateur logique mais il faut avouer que la première impression compte énormément. Si chaque tutoriel nécessite plusieurs jours d'effort pour le faire fonctionner, ce n'est pas très bon signe

    Les applications/entreprises utilisant ce framework

    Il s'agit de savoir qui d'autre que moi va se retrouver dans la même galère une fois les premiers tutoriaux élémentaires passés. Savoir aussi qui a réussi à aller au delà que Hello World sans consommer toute la mémoire du serveur. Par contre, attention au phénomène village gaulois, il faut être honnête sur ce critère et ne pas chercher à se rassurer sur le thème 'je ne suis pas tout seul'.

    Qualité des outils - Rapidité des cycles codage/test
    Un des points qui m'interroge le plus actuellement c'est l'influence de la qualité de l'environnement de développement sur les performances d'une technologie. C'est un des points qui me pose le plus de problème sur le choix de Grails par exemple.

    Grails permet de créer très vite une application web en utilisant des technologies Java éprouvées.
    Par contre, il est basé sur Groovy, et de ce fait ne dispose pas d'intégration aussi puissante que celle de Java dans Eclipse ou Netbeans. Le plugin Netbeans est puissant en fonctionalités mais reste lent. Le plugin Eclipse est plus que limité. Comme les outils ne sont pas très efficaces, la phase d'apprentissage est plus longue. Certes, le code est plus réduit mais chaque ligne est plus couteuse à coder.

    Je suppose que les cycles de productivité s'inverse à un moment (mais c'est juste une intuition). Une mise en place java/Spring/ hibernate est plus longue au démarrage mais sera plus productive sur le long terme et ce grâce aux outils.

    Cout du renoncement

    Savoir renoncer à un framework sur lequel des travaux sont déja engagés est le point le plus délicat.
    Les psychologues appellent piège abscon le fait de rester sur un mauvais choix parce qu'on y a déjà beaucoup investi. Pour éviter ce piège, il faut que le coûtd'abandon de la technologie nous apparaissent moins important que continuer à avancer malgré tout.
    Continuons avec l'exemple Grails, vous pouvez le choisir sans souci pour démarrer une application et avoir des résultats rapides. En effet, si vous revenez à du java classique, votre investissement ne sera pas perdu. Les deux technologies peuvent fonctionner l'une à coté de l'autre et vous aurez malgrè tout été au contact de nombreuses bonnes idées et pratiques.
    Si vous aviez choisi Ruby On Rails par exemple, le retour est bien moins évident car le décalage avec les technologies les plus répandues est bien plus grand.

    jeudi 30 juillet 2009

    Google App Engine vs App Engine Patch?

    I'm beginning to understand what's Python, what's Django, what's webapp and I already have a great decision to take.
    Which framework to choose in order to manage the presentation layer ( The story of the computer science is endless.)? I thought it was simple but it's not:)

    The Django version provided with the google appengine is the 0.96 and many features (Internationalization, Forms) I need seem to be present only in the full 1.0 Django Version.

    On the other side, the App Engine Patch site says that Django could be slow at starting if where are no enought requests to maintain it alive.

    After reading the following discussion http://www.mail-archive.com/google-appengine@googlegroups.com/msg06044.html. I will try the patch and see what happens

    jeudi 23 juillet 2009

    Python - AppEngine - Let's Go

    Today, I would like try to use Python/Django to make some tests with Google App Angine. Unlike Java and grails, I don't know anything about Python.
    If I succeed to do something, it would means that product is great, otherwise It should be because of me:)

    First good news, we can use Eclipse instead of Netbeans with the plugin pydev. I configure it by following this tutorial.

    First bad news, the menu item run google app engine doesn't appear in the menu:(. I try with the simple eclipse sdk and with a previous version but this run menu remains not present)

    I solve my first mistake!!! The menu appears only if you right-click on the src folder. It's not present at the project level. A great example about loosing stupid time because of ergonomy details.

    Again a time consuming action, setting the proxy configuration because a connection timeout occurs. I don't know why but it never works as expected:)

    In my case, setting the proxy allows the command to go to the step where it asks for the mail and password. The connection error occurs afterward.
    If I set a wrong proxy value, this step is not reached.

    I said that because I think it means my proxy configuration is OK and I have a problem elsewhere.
    After many tests, I didn't succeed in downloading my application. I don't want to spend more time on that subject. I will do the uploading from my personal computer.

    I already had the same problem with the stax platform and never succeed in downloading an application.

    Nevertheless, I succeed in starting some examples without any problem. The framework makes me a strong impression. The server starts fast, runs fast. The management of Python by eclipse is also really pleasant. Maybe I will be convinced?

    Of course this is a first impression. When I started with Grails, my problem come later in term of complexity.

    Now I have to learn how the triptich Python/Django/GAE manages all things needed by a project in the real life like testing, managing internationalization, how presentation framework works ....

    But it will be another story....

    Grails - App engine - the search is not over

    In fact I'm very disappointed by the way grails managing app-engine.
    For now I begin thinking that the cost to be hosted by the appengine is two hight and we are far from an industrial technology.

    I gladly admit that I don't have many time to try solving all problems I met. But this is the real life and I have to make choice:)

    Anyway i will do some test with Python and django in order to see if the solution is stronger.

    For now I didn't succeed in using JPA so all items described hereafter are linked to JDO.
    • The whole model of persitency have changed, say goodbye to the save() method, say goodbye to all generated findBy.... methods.
    • The code you're writing looks like using Spring with Java by having a persistency manager. The problem is that you're writing in Groovy and of course the completion done by the IDE isn't as fine as if you were in Java. Without the implicit job done by Grails, writing this code is painfully.
    • Most of your code is linked to google, the "import com.google.appengine.api.datastore.*" is everywhere. Don't expect a fast come back to a more traditionnal hosting by changing a config file.
    • I don't succeed to create integration test (I guess it's possible by making some spring call during the setup()). So don't expect that your exiting tests will run.
    • Forget the validation() method and thus forget the smart contraint management provided by Grails
    To end, these problems come only after trying to create two objects without any relationship or complex pocessus.
    For now, my personal feeling is that this is not a stable solution for a real application. Nevertheless, I of course continue to follow the developement.
    Another problem is that nowhere on the official sites, these limitations are detailled. All tutorials are very simple and work only if you do exactly that's written (for exemaple don't try to create a domain class without any package).

    mercredi 22 juillet 2009

    Grails - App Engine - No validation available

    Well, With the couple Grails/GAE, I move from one problem to another:(

    The today issue came in two steps:

    First I add some constraints to my object and notice that they are not managed. All objects violating these constraints are created.

    I look at the generated controller code and note that the validate() method is not called before saving the object. I of course add it and everything works fine.

    def save = {
    def instance= new Item(params)
    instance.validate()
    if(!instance.hasErrors() ) {
    try{
    persistenceManager.makePersistent(instance)
    } finally{
    flash.message = "instance ${instance.id} created"
    redirect(action:show,id:instance.id)
    }
    }

    render(view:'create',model:[instance:instance])

    }

    Now I upgrade my inline application and note that it doesn't work anymore. There is the following server error if a constraint is broken (the case where there is no error works fine):

    Error: Server Error

    The server encountered an error and could not complete your request.

    If the problem persists, please report your problem and mention this error message and the query that caused it.

    If you want to check that behavior simply go to http://petclinic-grails.appspot.com/owner/add and try to create a owner with all fields empty.

    It seems that the validate() is done by the hibernate plugin which is replaced by the appengine plugin.

    Moreover I saw that flash messages don't have the expected behavior. They stay more than one page reload. I don' t have time to see why.