Create a simple portlet with JBoss Forge!

Following is a simple way to create a portlet with the JBossForge Tool:

1) Start the forge


_____
|  ___|__  _ __ __ _  ___
| |_ / _ \| `__/ _` |/ _ \  \\
|  _| (_) | | | (_| |  __/  //
|_|  \___/|_|  \__, |\___|
|___/

[no project] portlet-demo $

2) Install portlet-plugin

The Portlet plugin is not yet listed in the Forge plugin repository. You need to use the git url to install it. In Forge type:

forge git-plugin git://github.com/jerr/plugin-portlet.git

That’s it! The plugin will be downloaded and installed.

3) Setting up a portlet project

From the forge prompt, create a new project and install the PortletFacet. This sets up your pom.xml.

new-project --named HelloForge  --topLevelPackage org.demo
portlet setup

4) Generating a simple portlet

Once the Facet is installed, you can create new portlet.

portlet new-portlet --named HelloPortlet

5) Building the war archive

Using maven we compile and package the web archive

mvn install

5) Deploy it

If you used GateIn, add the new archive in the  deployment directory. Via the admin page, import the portlet and add it in a page.

Here is the result.

Tags: ,

Multi-module code coverage with JaCoCo and Sonar!

I would like to share my first experiment of test coverage for a multi-module maven project with sonar and JaCoCo.

Prerequisites :

  • sonar 2.3
  • sonar JaCoCo plugin 0.2
  • maven 2
  • Sample project :

    I have a multi-module project with the following structure:

    mySeamApp
       mySeamApp-ear
       mySeamApp-ejb
       mySeamApp-tests
       mySeamApp-util
       mySeamApp-war

    This example was generated from seam-ear-archetype ( http://code.google.com/p/open-archetypes/ )

    Setps of experiment :

    1) Unzip the sample project : multimodulecoverage.zip
    2) Download the jacoco agent from ${your_sonarserver_url}/deploy/plugins/jacoco/agent-all-0.4.0.20100604151516.jar
    3) Compile and test projects:

    mvn clean  test -DargLine="-Dsun.lang.ClassLoader.allowArraySyntax=true -Xms512m -Xmx512m -javaagent:D:\Users\jer\agent-all-0.4.0.20100604151516.jar=destfile=../target/itjacoco.exec,append=true,includes=org.printstacktrace.*,excludes=*_javassist_*"

    4) Generate the sonar information without test:

    mvn sonar:sonar -Dsonar.core.codeCoveragePlugin=jacoco -Dsonar.jacoco.itReportPath=..\target\itjacoco.exec -Dmaven.test.skip

    5) Inspect the sonar server pages:

    It works!

    Conclusions :

  • Thanks to the sonar team for this plugin.
  • The data is in section it covergae tab, because we use « itReportPath » to merge the informations.
  • We must manually download and configure the agent.
  • So, waiting for the next version of the JaCoCo sonar plugin.
  • sonar4eclipse demo!

    This video shows how to bind a sonar site with Eclipse using the sonar4eclipse plugin.

    Installing Prerequisites :

  • eclipse 3.5
  • sonar4eclipse 0.1.1
  • Demo :

  • step 1 : add sonar navigator view
  • step 2 : add new server (ex nemo.sonarsource.org)
  • step 3 : browse projects in navigator
  • step 4 : Show local java files with sonar remote markers
  • Other plugin : « sonar-ide »

    Good news, this month, the sonar team has just started a new plugin « sonar-ide ». If the part about eclipse is going well, I’ll stop this one.

    Tags: ,

    Demo of m2eclipse with waroverlay

    This video shows the creation of an application with two web modules. (MNGECLIPSE-599)

    Installing Prerequisites :

    Demo :

    This presentation creates three projects. A main application myapp and two modules, module1 and module2.

    It uses the concept of waroverlay to integrate the two modules.



    Todo :

    • Allow to use warpath (MNGECLIPSE-405)
    • Use more maven-war-plugin configuration.
    • Integrate this stuff to the official m2eclipse plugin ;)

    Tags: , , ,

    Maven, PMD et Sonar!

    Voici un exemple d’utilisation des règles PMD définies dans un fichier pom.xml par sonar.
    La synchronisation n’est pas automatique mais peut se faire simplement. On doit décrire les nouvelles règles façon sonar, et déployer le tout sur le serveur.

    Petites explications :

    Maven permet de configurer des règles pmd spécifiques.

          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-pmd-plugin</artifactId>
          <configuration>
            <rulesets>
              <ruleset>${project.build.outputDirectory}/rulesets/org-printstacktrace-pmd.xml</ruleset>
            </rulesets>
          </configuration>

    Dans le monde réel, vous pouvez utiliser une configuration posée sur un serveur :

      <ruleset>http://myserveur/rulesets/org-printstacktrace-pmd.xml</ruleset>

    Configuration d’une règle PMD dans le ficher org-printstacktrace-pmd.xml

    <ruleset name="Try-finally PMD ruleset">
        <rule name="PrintStackTracePackageName" message="Package name must start with org.printstacktrace"
    class="net.sourceforge.pmd.rules.XPathRule">
            <description>
            Package name must start with org.printstacktrace.
            </description>
                <properties>
                    <property name="xpath">
                        <value>
                            //PackageDeclaration/Name[not
    (starts-with(@Image,'org.printstacktrace.') )]
                        </value>
                    </property>
                </properties>
            <priority>3</priority>
        </rule>
    </ruleset>

    Décrire la règle pour sonar dans le fichier yourdsonarhome\extensions\rules\pmd\pmd-sonar.xml

    <rules>
      <rule key="PrintStackTracePackageName">
        <name>Package name must start with org.printstacktrace.</name>
        <configKey>org-printstacktrace-pmd.xml/PrintStackTracePackageName</configKey>
        <category name="Reliability"/>
        <description><![CDATA[Package name must start with org.printstacktrace.]]></description>
      </rule>
    </rules>

    Tester en 2 minutes …

  • télécharger la dernière version de sonar : http://sonar.codehaus.org/
  • installer sonar (dé-zipper l’archive)
  • dé-zipper le fichier extensions.zip dans le répertoire de sonar (installation des nouvelles règles).
  • lancer sonar
  • activer la nouvelle règle dans le profil sonar.
  • décompresser l’archive :sonar-pmd.zip
  • exécuter  « mvn install sonar:sonar »
  • vérifier le résultat sur http://localhost:9000/
  • A ajouter à ma ‘Todo List’

  • Rechercher un plugin sonar de synchronisation des configurations maven de checkstyle, pmd, findbug, …
  • Trouver un plugin sonar de synchronisation des profils de check sonar avec la configuration maven.
  • Réaliser les plugins si dessus, si ils n’existent pas.

    Liens utiles :

    http://markmail.org/message/m7lwwnzy67i5ll3g
    http://old.nabble.com/PMD-custom-rule-problem-td20304856.html
    http://sonar.codehaus.org/what-makes-checkstyle-pmd-findbugs-and-macker-complementary/
    http://www.developpez.net/forums/d848532/general-developpement/conception/outils/integration-continue/sonar-pmd-customs-rules/

    Tags: , ,