Thursday, July 24, 2014

How to ban a given class...

This week I came across an odd situation.  I need to make sure nobody was using 'javax.ws.rs.Path' class.

So how can I ban a give class from my project?

It looked like a job for maven enforcer plugin!  Nop, that was no good.  Enforcer has no rule for this. May be extra enforcer rules?  No rule there for that too.

After searching a little bit more I found a plugin to do that!

Restrict-maven-plugin allowed me to do so.


<plugin>
  <groupId>com.yamanyar</groupId>
  <artifactId>restrict-maven-plugin</artifactId>
  <version>0.6</version>
  <executions>
    <execution>
      <phase>process-classes</phase>
      <goals>
        <goal>restrict</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <continueOnError>false</continueOnError>
    <restrictions>
      <restriction>com.contaazul.* to javax.ws.rs.Path</restriction>
    </restrictions>
  </configuration>
</plugin>

Easy no?

Now if someone add this by mistake maven will let us know:
[error] Restricted access from:(com.contaazul.MyClass.class) com.contaazul.MyClass to: javax.ws.rs.Path due to rule [1-1]
[error] Build is broken due to 1 restriction policies!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 45.133 s (Wall Clock)
[INFO] Finished at: 2014-07-24T10:20:44-03:00
[INFO] Final Memory: 60M/1247M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.yamanyar:restrict-maven-plugin:0.4:restrict (default) on project contaazul-app-business: There are 1 access exceptions! -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Way better then catching a bug latter, no?

Wednesday, June 25, 2014

Maven formatter plugin now supports Java 8

Just release maven-formatter-plugin 1.4.0.

This new version uses Eclipse Luna formatter, which mean Java 8 / Lambdas support.

Here a usage example:

<plugin>
  <groupId>com.marvinformatics.formatter</groupId>
  <artifactId>formatter-maven-plugin</artifactId>
  <version>1.4.0</version>
  <executions>
    <execution>
      <goals>
        <goal>validate</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <excludes>
      <exclude>**/target/**</exclude>
    </excludes>
    <aggregator>true</aggregator>
    <lineEnding>LF</lineEnding>
  </configuration>
</plugin>


Go for it!

Eclipse Luna + AJDT

You may or may not know, but Eclipse Luna is already out on the mirrors.

Still, if you are using AspectJ and wanna add Java 8 / lambdas to the mix there is no public update site for AJDT version compatible with Eclipse Luna.

Poking around I found the dev update site:
http://download.eclipse.org/tools/ajdt/44/dev/update/

Hope it helps!

Saturday, May 24, 2014

Google Could Platform is meant to script...

Impressive!

No, really impressive!


I have being using AWS for 2 years, and still google managed to impress me.

gcutil is really nice, no need to worry with ssh keys, auth details...  gutil just give you a url, just copy it, paste on browser, allow access and enter the authorization key back to command line.  Very similar to Google Authentication 2nd step.

$ gcloud auth login
Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?XXXX


Enter verification code: ***

You are now logged in as [m***@gmail.com].
Your current project is [None].  You can change this setting by running:
  $ gcloud config set project <project>

Easy right?

After that, I wanna install cassandra....  and the script to do so is straight forward (available at: https://github.com/GoogleCloudPlatform/compute-cassandra-python)


Also, $500 bucks starter kick is really nice!

Tuesday, April 1, 2014

Who is dragging my build!

We are a java shop and we use maven to manage our project build, tests, deploy...

But a couple days ago one of our modules build time jump to the roof with no apparent reason.

I knew which module was problematic.
But why?
Where is the problem?

Maven profiler to the rescue: https://github.com/takari/maven-profiler


Once I located the problem I was able to isolate some code on a new module and all was good again.

Cheers!

Thursday, March 27, 2014

Points estimation with beers

This week I made a quick presentation where I work to make us rethink point estimation.



Original presentation in portuguese:

Wednesday, March 26, 2014

maven-formatter-plugin got faster

A week ago (give or take) I post about my maven-formatter-plugin fork here.

Back then, I was trying to get it faster and if possible get it using all power my computer have.

Well, it is faster now!

The eclipse luna M6 contains a formatter way faster, so I decided to make a new release and include it!

I tried it on a big project (about 3K files and 100K lines).

The format validation time drop from 24s to 16s.... 30% faster.

<plugin> <groupId>com.marvinformatics.formatter</groupId> <artifactId>formatter-maven-plugin</artifactId> <version>1.4.0.M6</version> <executions> <execution> <goals> <goal>validate</goal> </goals> </execution> </executions></plugin>

Not bad, not bad at all.

Monday, March 17, 2014

One Formatter to rule them all!

Here we use pull request every day, every time.  All work is pull request oriented (thank you so much github).

But, a multicultural environment (multi-OSes, meaning multiple encoding + multiple line endings) can be a sore sight for eyes.

Here is a example:
https://github.com/velo/querydsl/pull/3

Someone though it was a nice idea to change the code format for a class.


691 lines of code changed.  How many meaningful? ZERO! I know it is ZERO cause I made it that way, but sometimes there is a single line changed and other 690 of pure chaos!

To help, some guys came up with a maven-formatter-plugin... It works, maven build breaks if you start doing funky changes.

That helped, a lot, but we had to open console and launch maven, it wasn't good enough.  Better then nothing, but still far from reasonable.

I looked and the project felt abandoned.  And I needed it. Was time to act.  Was time to create a fork.
https://github.com/velo/maven-formatter-plugin

The forked version presents some advantages:

  1. support javascript formatting (as well java inherited from the original code)
  2. contains an m2e configurator
  3. uses eclipse kepler formmater (getting ready for luna soon)
  4. uses N threads in order to get things done faster
At this point is necessary to install the m2e configurator by hand, but still, it helps, A LOT!
Update site: http://velo.github.io/maven-formatter-plugin/p2/1.3.0

Once installed, the plugin will set eclipse formatter to the same used on maven.

We now are free from pull requests with meaningless changes.  All business now.

Enjoy!

Saturday, March 8, 2014

Getting pull request and sonar playing toghetter

One thing I really dislike is duplicate efforts!

I wanna do things once, well done and to last as long it should.

For instance, when I go to the market, I buy whatever I need for the next 2 days but not more then I would need for a week.  This way I can carry it all in a single trip, I have fresh products and don't need to get into market 3 times a day =D

Back to this post.  At my company we are ADDICTED to pull requests!  All work goes to review before it goes to production.  That has N+1 advantages that I won't explore on this post. Anyway we do it, a lot!

But then, we decided to use Sonar to point out obvious problems.
After we bought a shine new EC2 machine, we setup Sonar, set our CI to run reports once a day and then.... well, then nothing!

We kept falling into same issues sonar was supposed to help us to flush out.

But why?  The sonar report was there, to everyone to see!  Nobody saw it =/
But why?  Cause sonar was some other place people don't go!

If there was a way to make sonar report to be written at github, on our pull requests.

Googling lead me to nothing.
Was time to get my hands dirty.
And so it begun!

https://github.com/velo/sonar-pull-request-integration

After 2 weekends working on it I was ready to show to my co-workers.
Live at https://github.com/velo/querydsl/pull/1/

Everybody got really excited with this.  So I decided to try this on some really pull request we did on our every day work.  Well, was kinda failure, lots of bugs on my tool.  But after a few hours fixing then SUCCESS!!!

We now adopted this feature under the company organization and are maintaining it since.
https://github.com/ContaAzul/sonar-pull-request-integration

To execute this plugin use the following command:
$ mvn com.contaazul.sonarpullrequestintegration:sonar-github-pull-request-maven-plugin:publish -Dsonar.branch=hazelcast -Dgithub.pullRequestId=1 -Dgithub.repositoryOwner=velo -Dgithub.repositoryName=querydsl -Dgithub.oauth2=**********

Hope it is useful to others.