Monthly Archives: July 2011

Java BigDecimal comparison

Why BigDecimal?, wasn’t it enough with all the previous numeric types to represent all the possible values?

No. When it comes to manage currency values, BigDecimal is the only class accurate enough to deal with them.

Anyway, this post is about its comparison, which may be very tricky. We’re used to the .equals method, so we may be tempted to use it to compare BigDecimal objects. Well, don’t. It does not work.

So what do we do to compare BigDecimal values a and b?, we must use the .compareTo() and .signum() methods.

 a.compareTo(b);  // returns (-1 if a < b), (0 if a == b), (1 if a > b)
 a.signum(); // returns (-1 if a < 0), (0 if a == 0), (1 if a > 0)

There you go 😉

How to allow the change of a commit comment in SVN

Sometimes you commit something and you forget to write a comment… big mistake, if you ask me. Maybe you did write a comment, but it was wrong. Don’t panic: you can edit it.

What will you need to do so? Two things:

1.- Admin access to the svn server installation.

2.- Tortoise SVN client or svn console. I’ll use Tortoise SVN here.

By default, SVN servers don’t have this option activated, let’s say… so they will not allow you change any comment on any revision, even if you committed the stuff in the first place.

In order to activate it, you have to (assuming that you’re using a unix based server) go to your repo hooks directory. Listing the files in there, you will find a file called pre-revprop-change.tmpl. You will need to remove the extension and do it executable, with the next commands:

mv pre-revprop-change.tmpl pre-revprop-change
chmod 777 pre-revprop-change

No restart is necessary. Now if you do “Show log” on any resource through your Tortoise SVN client, you will be able to do right click on a revision like this:

Right click on Revision

And choose the option “Edit log message”:

Editing Log Message

Ok. Done. We’re happy. We’re good. BUT… what if we only want the people who initially committed the resource to do the change on the comment?, because with the current configuration, anyone will be able to change the revision comment… suddenly this does not seem such a good idea any more, right?

Don’t worry and stay here. This is what you need to do: edit the mentioned pre-revprop-change file updating the next lines:

REPOS="$1"
REV="$2"
USER="$3"
PROPNAME="$4"
ACTION="$5"

if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" -a `/usr/local/subversion/bin/svnlook author -r "$REV" "$REPOS"` = "$USER" ]; then exit 0; fi

echo "Changing revision properties other than svn:log is prohibited... and if you were changing svn:log... did you commit this revision at first place?" >&2
exit 1

No restart is necessary after this either.

Obviously /usr/local/subversion/bin/svnlook will have to point to your svnlook path.

With this we’re done. Enjoy it.

How to enable Cron for non-root users

If you try to edit a user’s crontab and get this error:

”crontab: you are not authorized to use cron.  Sorry.”

You need to log in as root and edit a config file to add the user that you want to access Cron too:

# vi /usr/lib/cron/cron.allow

We add the user:

root
user1
user2

We save & close.

Now we log in with the user and we are able to access its crontab:

$ crontab -e

[Seen: Nekan]

Disabling security on Jenkins

One may “accidentally” set up security realm / authorization in such a way that you may no longer able to reconfigure Jenkins.
When this happens, you can fix this by the following steps:

  1. Stop Jenkins (the easiest way to do this is to kill the servlet container.)
  2. Go to $JENKINS_HOME in the file system and find config.xml file.
  3. Open this file in the editor.
  4. Look for the <useSecurity>true</useSecurity> element in this file.
  5. Replace true with false
  6. Start Jenkins

When Jenkins comes back, it’s in the unsecured mode where everyone gets full access to the system.

So useful.

[Seen: Jenkins wiki]