Wednesday, 9 May 2012

Java5 annotations support for Maven plugins

So finally or at least (depends on your POV :-)), I have pushed some code to support Java5 annotations support for Maven plugins.
The "specs" are here https://cwiki.apache.org/confluence/display/MAVEN/Java+5+Annotations+for+Plugins.
The code is available in the branch http://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189/.
Snapshot are deployed to: https://repository.apache.org/content/repositories/snapshot .
You can have a look at it tests to see some samples: http://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189/maven-plugin-plugin/src/it/annotation-with-inheritance/
Basically you need to setup your pom as it:
    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>3.0-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>


  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-plugin</artifactId>
        <version>3.0-SNAPSHOT</version>
        <configuration>
          <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
        </configuration>
        <executions>
          <execution>
            <id>mojo-descriptor</id>
            <phase>process-classes</phase>
            <goals>
              <goal>descriptor</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  
  <repositories>
    <repository>
      <id>apache.snapshots</id>
      <name>Apache Snapshot Repository</name>
      <url>http://repository.apache.org/snapshots</url>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>apache.snapshots</id>
      <name>Apache Snapshot Repository</name>
      <url>http://repository.apache.org/snapshots</url>
      <releases>
        <enabled>false</enabled>
      </releases>
    </pluginRepository>
  </pluginRepositories>

Annotations to use are:
@Mojo( name = "foo", 
       defaultPhase = LifecyclePhase.COMPILE, 
       threadSafe = true )
@Execute( goal = "compiler", 
          lifecycle = "my-lifecycle", 
          phase = LifecyclePhase.PACKAGE )

public class FooMojo extends AbstractMojo
{
    /**
     * the cool bar to go
     * @since 1.0
     */
    @Parameter( expression = "${thebar}", 
                required = true, 
                defaultValue = "coolbar" )
    protected String bar;

    /**
     * beer for non french folks
     * @deprecated wine is better
     */
    @Parameter( expression = "${thebeer}", 
                defaultValue = "coolbeer" )
    protected String beer;

    /**
     * Plexus compiler manager.
     */
    @Component
    protected CompilerManager compilerManager;

    /**
     *
     */
    @Component( role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", 
                roleHint = "maven" )
    protected ArtifactMetadataSource artifactMetadataSource;

    public void execute()
        throws MojoExecutionException, MojoFailureException
    {
        // nothing
    }
}
Note: the help generation doesn't work yet !!
A new feature is your parent annotated classes can come from reactor project and from your project dependencies.
And don't complain yet too much in case of issues, it's a work in progress :-)
12 May 2012 UPDATE: Help generation done and code merged in trunk YEAHH :-)
25 May 2012 UPDATE: Few annotations has changed have a look at documentation page: https://cwiki.apache.org/confluence/display/MAVEN/Java+5+Annotations+for+Plugins
31 May 2012 UPDATE: release 3.0 deployed and now available.
Have Fun!

Friday, 23 March 2012

Search and browse with Archiva new UI


If you follow me, you probably know I'm working on a new UI for Apache Archiva using plain html/javascript technologies (one page load app).
Here some screenshot about new Search and Browsing screens.

The new browsing



The new search


To test it just download:
  • zip with self contained jetty: http://s.apache.org/LAST_ARCHIVABUILD_ZIP
  • war to install in your favorite servlet container: http://s.apache.org/LAST_ARCHIVABUILD_WAR

So all comments are welcome :-)
And have Fun !

Wednesday, 15 February 2012

Apache Archiva UI rewrite progress (How it works ? )

Recently I proposed to rewrite the Apache Archiva UI. The goal was to have a new fresh/modern UI :-).
So as IANAD (D for designer) using Twitter Bootstrap was a good solution to help to start.
Regarding web framework buzz :-), I proposed to have a plain html/javascript (without any complicated Java web framework stack) maybe because it's "à la mode" :-).
At the end, it will be a one page load application with only javascript (data transfer with the server only tru REST call) and rendering with html/js template mechanism.
But here too there is some buzz around: which one to choose ? To have an easy UI automatic refresh, the data binding was something mandatory.
That's why http://knockoutjs.com/ was choosen !!
Furthermore it's a very active community, people are helping very quickly to help on mailing list and very documentation (something not usual on Open Source project :P ).
And definitely we didn't want waste time on philosophical discussions on various frameworks.
I promise I will write a blog entry soon on some tips to use this framework :-)

So the rewrite is in progress (see http://www.screencast.com/t/KX93fcKhHvE)
And some documentation on how it works has been started here
The top jira issue is here http://jira.codehaus.org/browse/MRM-1497.
Yes some job to do :-).
We are hiring :-) to complete all. So if you want to have fun with nice javascript framework. Do not hesitate to propose patches or pull requests tru https://github.com/apache/archiva.
Note: during the interview process, we won't ask complicated puzzle or scholar questions :-) you will be judged only on your patches proposal.

If you want to test the new UI, you can try the following steps :
svn co https://svn.apache.org/repos/asf/archiva/all/ archiva-all-sources
cd archiva-all-sources/archiva
mvn tomcat7:run -pl :archiva-webapp-js -Pjs -Pdev -am
Hit your browser : http://localhost:9091/archiva/index.html?request_lang=en

And after this UI rewrite, what's else ?
I'm thinking about plugins/extension points mechanism with UI part too. As the UI will be in full js, folks will have to write their plugins ui in js.
Maybe not only, Vaadin XS looks to be possible solution to study.
So stay tune for coming next news :-)

Saturday, 21 January 2012

Unit tests with embeded tomcat artifacts

In the 7.x releases of Apache Tomcat, some maven artifacts are now published which include a nice and fluent embeded api to run a Tomcat instance.

So it's a nice opportunity to use it writing units to test servlets, rest api etc..
But until 7.0.25 it was only possible to do it with using a barcoding port which can cause some issues on ci servers where you are not sure ports are not used by something else running.

I have personally sended a RFC to ITEF to have port allocation for only my personal use on my birthday year or zip code port but strangely this RFC was never approved :-).

Now you can use the java ServerSocket port 0 feature to use any free port available on the machine.
It has been fixed with the issue 52028.

So now you can write a unit test as it (here a test with a REST service provided by Apache CXF).



@Before
public void startTomcat()
throws Exception
{
tomcat = new Tomcat();
tomcat.setBaseDir( System.getProperty( "java.io.tmpdir" ) );
tomcat.setPort( 0 );

Context context = tomcat.addContext( "", System.getProperty( "java.io.tmpdir" ) );

A context param in your web.xml:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring-context.xml</param-value>
</context-param>

In the code

ApplicationParameter applicationParameter = new ApplicationParameter();
applicationParameter.setName( "contextConfigLocation" );
applicationParameter.setValue( "classpath*:META-INF/spring-context.xml" );
context.addApplicationParameter( applicationParameter );

A listener class in your web.xml:

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

In the code

context.addApplicationListener( ContextLoaderListener.class.getName() );

CXF servlet declaration in your web.xml:

<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/restServices/*</url-pattern>
</servlet-mapping>

In the code:

tomcat.addServlet( context, "cxf", new CXFServlet() );
context.addServletMapping( "/restServices/*", "cxf" );

tomcat.start();

port = tomcat.getConnector().getLocalPort();

System.out.println("Tomcat started on port:"+port);
}



So now you can test/consume you REST services on localhost with the port.

Don't miss to shutdown the tomcat instance on tearDown or @After

@After
public void stopTomcat()
throws Exception
{
tomcat.stop();
}


If you use Maven you need the following dependencies:

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<scope>test</scope>
<version>7.0.25</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<scope>test</scope>
<version>7.0.25</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<scope>test</scope>
<version>7.0.25</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<scope>test</scope>
<version>7.0.25</version>
</dependency>


As samples talks more than long docs ("Code talks, bullshit walks" :-) ).
The tomcat maven archetype has been improved with a sample. (see previous post)

Have Fun!

Friday, 13 January 2012

Tomcat Maven plugin archetype. Sample talks more than long documentation :-)

As code sample talks more than long and borying documentation (or maybe because I don't like to write too long documentation :-) ), I have writen an archetype for the Apache Tomcat Maven Plugin.

Some features describe in this post are now implemented.

As it's not yet released but soon !, just use :

mvn archetype:generate \
-DarchetypeGroupId=org.apache.tomcat.maven \
-DarchetypeArtifactId=tomcat-maven-archetype \
-DarchetypeVersion=2.0-SNAPSHOT \
-DarchetypeRepository=https://repository.apache.org/content/repositories/snapshots/
....
[INFO] Using property: groupId = org.apache.tomcat.maven
Define value for property 'artifactId': : tomcat-sample (project will be created in ./tomcat-sample )
...
cd tomcat-sample


You can run your webapp with: mvn tomcat6:run or mvn tomcat7:run (depends on tomcat version you want)
And hit your browser to http://localhost:9090 and you will use a very complicated hello world webapp sample :-)

Now you can try: mvn clean install .
You will see a selenium test running (by default firefox), use -Pchrome for using chrome should work too with -Piexplore (not tested :-) ).

Note you have now an executable war.
Try it !

cd basic-webapp-exec/target/
java -jar basic-webapp-exec-1.0-SNAPSHOT-war-exec.jar -httpPort 9191


And hit your browser to http://localhost:9191.
So you have a tomcat7 running our fabulous application and without installing nothing !

More details on the project



This archetype build a simple project with some maven modules. IMHO it's nice layout to use.

basic-api (service interface)
basic-api-impl (service default impl)
basic-webapp (our webapp module)
basic-webapp-exec (module to generated executable war)
basic-webapp-it (module to run selenium tests with generated war)


The application is exposing a REST service called HelloService (in basic-api module)


@Path( "HelloService" )
public interface HelloService
{
@Path( "sayHello/{who}" )
@GET
@Produces( { MediaType.TEXT_PLAIN } )
String sayHello( @PathParam( "who" ) String who );
}


The implementation is in the module basic-api-impl.
Note we use Apache Cxf to provide REST services (for more details have a look at the various spring files).

The webapp is a simple page based on jquery and twitter bootstrap.

So have fun !

Saturday, 26 November 2011

From a pull request to a jira issue

After the generate a patch and attach it to a jira issue, it's now the time to have a tool to create an issue from a patch request (the current implementation works only for github pull request).

So the Patch Tracker plugin has now a new goal called to-issue. This goal will read a github pull request and create an issue in your issue tracker (currently only supported for jira).

It's simple :-).
As sample see pull request : https://github.com/jenkinsci/jenkins/pull/320 and the created issue in jira: https://issues.jenkins-ci.org/browse/JENKINS-11883
I have just used the cli:

mvn patch-tracker:to-issue -Dpatch.request.id=320 -B

For easy configuration see the properties in the jenkins pom.

<project.patchManagement.system>github</project.patchManagement.system>
<patch.request.organisation>jenkinsci</patch.request.organisation>
<patch.request.repository>jenkins</patch.request.repository>
<project.patchManagement.url>https://api.github.com</project.patchManagement.url>

<patch.tracker.serverId>jenkins-jira</patch.tracker.serverId>


entry in settings:

<server>
<id>jenkins-jira</id>
<username>uid</username>
<password>password</password>
</server>


And that's it :-).

BTW if you need more features, patch (or pull requests) are welcome.

This maven plugin is in the maven sandbox @asf and not released, so if you want to try it you must have asf maven snapshot repo in your settings or buid it manually.
Sources are here:

  • https://github.com/apache/maven-sandbox (path plugins/maven-patch-tracker-plugin) yup no sparse checkout with git :P

  • http://svn.apache.org/repos/asf/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/



Some docs has been started here http://maven.apache.org/plugins/maven-patch-tracker-plugin (maybe not yet in sync so wait a bit)

Have fun !

Monday, 21 November 2011

Life is too short to waste time uploading a patch or Maven Patch Tracker plugin

Life is too short and you don't want to waste time contributing to a project (creating a patch, a entry in the jira issue tracker then upload the patch).
So the Maven Patch Tracker plugin is for you !



You will be able with a maven plugin to do all of this in one command line !
Without any configuration you have to write :

mvn patch-tracker:create
-Dpatch.summary="foo summary"
-Dpatch.serverUrl=http://localhost:8080/browse/MNG -B
-Dpatch.user=uid -Dpatch.password=pwd


If you find that boring or too long no problem, there is a solution for that (yes good developer are lasy developers they use tool to automate tasks :-) ).
So configure you pom, with the issue tracker id

<issueManagement>
<system>jira</system>
<url>http://host:ip/browse/projectKey</url>
</issueManagement>


Add a server entry in you settings.xml


<server>
<id>jira-maven</id>
<username>olamy</username>
<password>very complicated password for paranoiac security folks</password>
</server>


Reference this jira server in your pom:


<properties>
....
<patch.tracker.serverId>jira-maven</patch.tracker.serverId>
....
</properties>


Et voilà, just run and save fingers:

mvn patch-tracker:create -Dpatch.summary="foo summary" -B


NOTE: without -B the plugin will use a prompt mode to ask you confirmation on the values

An other mojo called update can add/update an issue with an other patch:

mvn patch-tracker:update -Dpatch.description="update of the issue with an other patch" -Dpatch.patchId=MNG-5203 -B

This command will update the issue MNG-5203 with an other patch.

NOTE: currently only jira is supported

The plugin will use the configured scm client configured tru your scm url to generate the patch/diff file.
So your project is configured with svn but for some reasons you use git svn.
No problem add the parameter: -Dscm.providerType=git

Other improvement I think: load the patch to review board.

Something else ?
Ideas and patches are welcome :-)

You can test it using the snapshot repo: https://repository.apache.org/content/groups/snapshots-group/ or build it yourself: http://svn.apache.org/repos/asf/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/

Have Fun and good hacking!