Thursday, 17 April 2014

Review of "Version Control with Git" by Jon Loeliger and Matthew McCullough, O'Reilly


This book claims to "explain how Git works and teach mastery" of Git. And it does. If you read this book carefully (SCM systems are not necessarily easy to grasp), you most probably will be able to learn everything you ever wanted to know about Git.

Maybe even more ;)

On the other hand, as a curious SVN user trying to check out new stuff and competing technologies, you might be a bit overwhelmed by the amount of details you are confronted with.

Contents and structure of the book

After a general part about version control systems and some essential concepts of Git, the authors  guide you through all the nuts and bolts of a single, local repository. You should not be afraid to even look inside the folders and files beneath that hidden .git directory. That's a very technical approach,  but it's worth it if you really want to understand how Git works.

It's not until Chapter 12 (of 21) that you will deal with remote repositories; most books I know take an opposite approach and start with remote repositories right away. "Version Control with Git" takes one step after the other and makes sure you understand the simpler stuff first, and even if that means you have to be patient, it's most probably the better approach.
 
The last part of the book provides some advanced examples and interesting tips, tricks and techniques that I am sure not too many Git  users know about, plus a detailed introduction to github.

Summary


The answer to the question of how much you will like this book simply depends of what you expect.

If you want to know everything there is to know about Git, get this book. If you want a reference about git concepts and detailed explanations, get this book. If you ever had problems understanding why Git behaved somehow strange under certain circumstances, well, get this book.

Otherwise, for example if you are a SVN user who wants a somehow painless transition path to Git, there might be better suited books for you. But, as this kind of reader, if you keep using Git, most probably, you will buy "Version Control with Git" nevertheless (just a bit later).

Saturday, 4 January 2014

Findbugs as eclipse plugin in a bndtools project

This post is just a little write-up about how to use findbugs in a bndtools project. Specifically it is about how to suppress findbugs warnings you don't think to be accurate in some context.

Prerequisites:

I assume you have installed bndtools and findbugs (e.g. via the eclipse marketplace). Further you should have created a bndtools project, and, preferably for this little tutorial, you should get a findbugs warning in your code when running findbugs on your bndtools project.

An Example:

    private static volatile ConfigurationProvider configurationProvider;

    @Reference
    public void setConfigurationProvider(ConfigurationProvider provider) {
        configurationProvider = provider;
    }

This kind of code will give me a findbugs warning like "Write to static field" in the assignment. I do not want to discuss if this is appropriate here, just now I want to get rid of this warning.

The library to the rescue:

Fortunately for us, when searching maven.org for "com.google.code.findbugs", you will find an "annotations" jar (currently in version 2.0.3); this little library provides a couple of annotations to give findbugs some hints about your needs.

The code change needed:

Checking some examples, I conclude that what I need is this:

    @Reference
    @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
    public void setConfigurationProvider(ConfigurationProvider provider) {
        configurationProvider = provider;
    }


Dependencies management:

But I have to add the annotations jar to the build path of my project (I will not need the dependency when running the bundle though!). In the context of a bndtools workspace there is a convenient way to add the library in in non-obstructive way:


  • Drag the downloaded annotations-2.0.3.jar onto the "Build" repository in the bndtools Repositories view
  • you might have to check the ext/repositories.bnd file (see below)
  • Refresh the bndtools repositories (in the Bndtools menu)
  • Your code should compile now, and the findbugs warning should be gone.
Troubleshooting:

There is one thing which might prevent you from succeeding: If you check your cnf/ext/repositories.bnd file, the definition of the Build repository might look like

aQute.lib.deployer.FileRepo;name=Build;location=${workspace}/cnf/buildrepo

I think this is the default when installing bndtools. What you need to do to make the above work is to change that line to 

aQute.bnd.deployer.repository.LocalIndexedRepo;name=Build;local=${workspace}/cnf/buildrepo;pretty=true

This will make the Build repo a LocalOBR which should not change its behaviour otherwise (see that google groups entry).

Hope that this is useful for somebody ;)