Wednesday, 19 September 2007

Buildr: Using ruby to build java.. hmmm...

http://blog.labnotes.org/2007/05/03/buildr-or-when-ruby-is-faster-than-java/

http://buildr.rubyforge.org/

I've just started getting comfortable with using Maven, and
appreciating all the goodies that cam be used from it, then this comes
along... I wonder how much traction they'll get though, considering
the number of people already using Maven. I guess Ant didn't
disappear when Maven came along, so Maven probably won't disappear
with the appearance of Buildr.

Tuesday, 18 September 2007

Pardon the splatter, I just had my mind blown again...



DJ Sara (8 yrs old) and DJ Ryusei (5 yrs old) tearing it up on the turntable. I wonder if there's a DMC Junior competition somewhere.

Friday, 14 September 2007

Converting a DOS text file into Unix format

I was working on a config file in Ubuntu that had those nasty ^M
carriage returns at the end, and dos2unix doesn't seem to be around
anymore. So came across this info in Wikipedia:

http://en.wikipedia.org/wiki/Newline


The same tasks can be performed with sed, or in Perl if the platform
has a Perl interpreter:

sed -e 's/$/\r/' inputfile > outputfile # UNIX to
DOS (adding CRs)

sed -e 's/\r$//' inputfile > outputfile # DOS to
UNIX (removing CRs)

perl -p -e 's/(\r\n|\n|\r)/\r\n/g' inputfile > outputfile # Convert to DOS

perl -p -e 's/(\r\n|\n|\r)/\n/g' inputfile > outputfile # Convert to UNIX

perl -p -e 's/(\r\n|\n|\r)/\r/g' inputfile > outputfile # Convert to old Mac


It's probably the first time I've used sed!

Fixed: Maven 2 plugin problems with Bamboo/ Hudson + Tomcat setup on Windows

I've been tasked with setting up a continuous integration system at
work, and I've been evaluating - or trying to at least run - these
packages:

- Continuum
- Hudson
- Bamboo


I've yet to try these out:

- Luntbuild
- Cruisecontrol

From the looks of things, I proably should have tried out other two
before the other ones, given the lack of success I've had so far. :(

After a few emails exchanged with Atlassian Support re: Bamboo, I've
fixed a problem I was having with Bamboo and Hudson on my PC. I was
running them under Tomcat, which was installed as a Windows service.
My Ant builds were working fine, but my Maven2 builds were failing,
and would constantly complain that the 'maven-clean-plugin' was
missing, with errors like this:

Bamboo:

12-Sep-2007 16:48:01 [INFO]
----------------------------------------------------------------------------
12-Sep-2007 16:48:01 [INFO] Building AppFuse Core Application
12-Sep-2007 16:48:01 [INFO] task-segment: [clean, test]
12-Sep-2007 16:48:01 [INFO]
----------------------------------------------------------------------------
12-Sep-2007 16:48:01 [INFO] artifact
org.apache.maven.plugins:maven-clean-plugin: checking for updates from
appfuse
12-Sep-2007 16:48:02 [WARNING] repository metadata for: 'artifact
org.apache.maven.plugins:maven-clean-plugin' could not be retrieved
from repository: appfuse due to an error: Error transferring file
12-Sep-2007 16:48:02 [INFO] Repository 'appfuse' will be blacklisted
12-Sep-2007 16:48:03 [INFO]
------------------------------------------------------------------------
12-Sep-2007 16:48:03 [ERROR] BUILD ERROR
12-Sep-2007 16:48:03 [INFO]
------------------------------------------------------------------------
12-Sep-2007 16:48:03 [INFO] The plugin
'org.apache.maven.plugins:maven-clean-plugin' does not exist or no
valid version could be found
12-Sep-2007 16:48:03 [INFO]
------------------------------------------------------------------------
12-Sep-2007 16:48:03 [INFO] For more information, run Maven with the -e switch
12-Sep-2007 16:48:03 [INFO]
------------------------------------------------------------------------
12-Sep-2007 16:48:03 [INFO] Total time: 1 second
12-Sep-2007 16:48:03 [INFO] Finished at: Wed Sep 12 16:48:03 EST 2007
12-Sep-2007 16:48:03 [INFO] Final Memory: 1M/?4M
12-Sep-2007 16:48:03 [INFO]
------------------------------------------------------------------------

HUDSON:

[struts2-starter] $ C:\javatools\maven-2.0.6\bin\mvn.bat package
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Struts 2 Starter
[INFO] task-segment: [package]
[INFO] ----------------------------------------------------------------------------
[INFO] artifact org.apache.maven.plugins:maven-resources-plugin:
checking for updates from central
[WARNING] repository metadata for: 'artifact
org.apache.maven.plugins:maven-resources-plugin' could not be
retrieved from repository: central due to an error: Error transferring
file
[INFO] Repository 'central' will be blacklisted
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] The plugin 'org.apache.maven.plugins:maven-resources-plugin'
does not exist or no valid version could be found


I had already come across an issue raised for Hudson concerning this,
but didn't completely figure out what it meant:

https://hudson.dev.java.net/issues/show_bug.cgi?id=470

"The current workaround is to have hudson run under a new user with
its own .m2 directory and have whichever profiles are necessary
activated by default. That way, the profiles are picked up as part of
the alignWithUserInstallation mechanism in the embedder."

Atlassian support was able to replicate the error I was getting by
running the Bamboo standalone running under the SYSTEM directory, and
asked me to check if Tomcat was running as SYSTEM, which it was, as I
that is the default when you install Tomcat as a Windows service.
Ah, of course! <lightbulb moment>

When these packages do their continous integration, Bamboo and Hudson
are calling outside the web application to an external batch file. So
when Maven gets run by Bamboo or Hudson, Maven will run as *that*
user, which in this case is the SYSTEM user. I guess SYSTEM user will
try to get its settings from C:\Documents and Settings\Default User\
and not my own user account with the correct maven settings.

So the solution was to go into Services, look for "Apache Tomcat" then
in the "Log On As" column, get it to run as a user with the correct
Maven settings.

Now I don't know if I would have gotten this problem if I was running
under Linux. I think I would still have, because if Tomcat was running
under the user "tomcat", but my maven settings were under a
"autobuild" directory, it would be the same scenario, and the fix
would be to run Tomcat - or whatever app server you're using - under
the "autobuild" account.

Sunday, 9 September 2007

Why's Poignant Guide to Ruby - annoying, irritating, slow

I've known about Ruby for a while, and picked up on the hype, mostly because of the Ruby on Rails framework. I started learning Ruby just a few weeks ago at work, courtesy of our architect looking to stretch the development team's repertoire. It wasn't hard to learn, and the fact that the built-in libraries are clearly not as extensive as in Java (of course) - it wasn't really much of a hurdle, as most programmers probably use only a fraction of what's in the JDK. The fact that it has multiple method names for doing the same thing (Array has size() and length() - WTF?) also wasn't that much of a deterrent. In contrast, I've been planning to learn Python for the past few years, but never seem to have gotten over the completely useless self parameter in its constructors. I like what I've seen so far in Ruby, the integration of regular expressions in the language, meta-programming and the whole "domain specific languages" aspect, and Ruby gems - almost all good so far. At one point I was wondering why I didn't give it a go much earlier.

Then I remembered the biggest thing that turned me off: "Why's Poignant Guide to Ruby". I have never seen a more self-indulgent, verbose, time-wasting programming language tutorial. The first time I came across it I was completely put off by the cutesy cartoons, the "trying hard but not good enough" humour, and the irritating and annoying asides and stories. I think I got through a chapter or two and gave up in exasperation. I was clearly not the audience this dude was writing for. He was possibly writing for children - "oh yes, the array is like a biiiig caterpillar, and the commas are its legs!", or teens with ADHD who needed frequent distractions to keep them reading the text (yes, I don't know how that's supposed to work).

I'm going through it again, this time as someone who doesn't actually have to learn from his text, and while I appreciate some of the things he seems to be reaching for, the abstractions he's trying to convey, I still think it takes up too much time to get to the point. It just smells too much of condescending "edutainment". If you ever wanted to read a document that treats you like an idiot - waay more than those "For Dummies" or "Idiot's Guide" books - this is it.

And yes, I know there are a lot of other excellent Ruby tutorials out there, but at the time I first encountered the Poignant Guide, I didn't actually have any use for Ruby at my then-workplace, so my exploration never went any further.

Friday, 7 September 2007

Unable to mount .dmg files in OS X - "Device not configured" error. How to fix it.

I had downloaded some DMG files to install some software and kept
getting these error messages:

Unable to attach "Foo.dmg" - Device not configured.

It was happening for more than one .dmg file, and I'm sure the
download was not corrupted.

At first, I tried using the Disk Utility, thinking it was related to
disk permissions, but the option wasn't present when I selected the
DMG. Clicking on "Verify disk" didn't help either, and resulted in the
same error "Device not configured".

Tried the instructions below and they worked.

1. Go into terminal

2. type

su [username that has admin rights]

you will be asked for your admin password.

3. Then run these commands. (I don't know what they do but they worked)

sudo kextunload -c com.apple.AppleDiskImageController

sudo kextload -b com.apple.AppleDiskImageController

4. Now try to mount those .dmg files.

Addendum: It's still not fixed. Now I'm just getting a new error message - "no mountable file systems". Oh great.

Do I believe in Free Markets? Why Sure I do!

http://www.theonion.com/content/news/u_s_to_give_every_iraqi_3_544_91

Tuesday, 4 September 2007

Set up Tomcat to redirect HTTP requests to HTTPS

We had JIRA installed and using the built-in Tomcat app server,
accepting both HTTP and HTTPS requests. We wanted to restrict it so
that all JIRA access was only via SSL. The config changes were pretty
simple.
1. Change Tomcat's server.xml.
Edit the non-SSL <Connector> entry listening on port 80 and add or
edit the redirectPort atribute to point to the port on which the SSL
<Connector> is listening. By default, the redirectPort was pointing
to port 443.
Was:
<Connector port="80"
enableLookups="false" redirectPort="8443"
maxThreads="100" minSpareThreads="100" maxSpareThreads="100"/>

Changed to:
<Connector port="80"
enableLookups="false" redirectPort="443"
maxThreads="100" minSpareThreads="100" maxSpareThreads="100"/>
Because the SSL entry was:


2. In the Tomcat web.xml file the following <security-constraint> has
to be added within the <web-app> element. This new element must be
added after the <servlet-mapping> element:

<!-- SSL settings. only allow HTTPS access to JIRA -->
<security-constraint>
<web-resource-collection>
<web-resource-name>Entire Application</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>