change svn commit comment

Thursday, September 10, 2009

It happens sometimes, committing something in svn then realising the comment was wrongly for something completely different, or the main thing was missed out. Here's how to change it.

If you don't have the repo configured to allow post-commit changes (as per; it is off by default), then you can easily do it on the server as admin with no config changes:

sudo svnadmin setlog --bypass-hooks /path/to/repo /path/to/text-file-with-new-comment.txt -r ##

This command is documented in svn versions 1.4 to 1.6.


Trac
If Trac is being used on the project, then prompt it to re-read the repo and pick up the change by:
trac-admin /path/to/trac-project resync ##

where ## is the revision number to resync. If it is left out then all revisions will be resynchronised.

netbeans - matisse - fix invalid components

Saturday, May 23, 2009

Netbeans' Matisse Swing editor is a great tool. Keeping it running is the challenge. That is, carefully ensuring that .form files are kept in sync with the .java files, and no external editing gets too trigger-happy. The other challenge, it turns out, can be when migrating to a different dev box / dev environment.
I was getting an error when trying to open forms that had opened fine in my previous environment, and I knew they were committed to my version control.

The error:

Error in loading component xxxx... no such property exists.

And then if you carry on to view the form, in navigator you get [invalid component] instead of classnames next to those components.

Infuriating when you know it should work. But I've found it to be only caused by one of 2 reasons:

  1. Compile the class! Ensure that every one of the beans that the form is trying to load is currently compiled (do 'clean and build' on the whole project if in doubt).
  2. Netbeans' JRE incompatible For example, my current project is in Java 6, and the projects were configured fine in Netbeans to use Java 6. However, Netbeans itself was launching in Java 5, which is fine, except that you then get the above error. It would be so easy for the Netbeans team to add this compatbility check one would think, but oh well. So, if Netbeans' JRE (tools> Java Platforms) is lower than your project JRE, change Netbeans' default runtime by either (as of NB 6.5):
    • running the IDE with the --jdkhome switch on the command line
    • or by entering the path to the JDK in the netbeans_jdkhome property of your INSTALLATION_DIRECTORY/etc/netbeans.conf file.


If these don't help, check out [user directory]/var/log/messages.log (eg. for OSX, user dir is '~/.netbeans/[version]/'), and your answer should lie in an exception thrown in there.

netbeans - matisse - convert panel to form

Friday, April 17, 2009

The Swing GUI editor in NetBeans is great. It has a number of samples to build from as well, one of which is the Master/Detail template. That's an example of one that generates a JPanel, and I wanted to convert to a JFrame. Here are the steps, assuming a form named NewForm (with NetBeans 6.5):

  1. In NewForm.java:
    1. Change extends JPanel to extends JFrame.
    2. Change the static void main.. method content to be:
      java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
      new NewForm().setVisible(true);
      }
      });

  2. In NewForm.form (may need to edit this outside of NetBeans):
    1. Change the type attribute of Form (near the top) from type="org.netbeans.modules.form.forminfo.JPanelFormInfo" to type="org.netbeans.modules.form.forminfo.JFrameFormInfo".


  3. In the graphical editor, select the Frame and choose the Code tab. Under Form Size Policy, change to Generate pack().


That should be it, good to go. May need to recompile, and/or open close the form to get NetBeans to recognise the changes.

checkpoint secureclient for mac

Thursday, April 09, 2009

It's great that CheckPoint has a SecureClient for the Mac. It works really well. What doesn't work, is making it stop.

There is no way to prevent it booting at startup. Oh, there are ways referred to by CheckPoint's docs, but as they say in the fine print, that just stops the gui from starting - any security policies (read: complete firewall lockdown) will still be in place. And if you do have the gui up and choose 'Stop VPN-1 SecureClient', again it's only the gui that goes, and you go mad like me having lost your svn, http, etc server, not knowing why. There are ways to control it via the command line which you could script, but your admins have to have allowed it to allow that via some centralised settings at their end.

So, if you do need SC, always launch the gui. If you need access to services on that box, then always choose 'Tools>Disable Security Policy' in SC. And if you don't need it anymore, then say goodbye to it, like I'm about to do.

use eclipse to autowrap an object

Tuesday, April 07, 2009

I'm sure there's a better design methodology to do this, but I have an issue in Java where the PostgreSQL JDBC driver can't execute createBlob() (in JDBC3 spec), so I want to overwrite its Connection. I can't subclass it, as it's returned from the call DriverManager.getConnection(...). So what I need to do is use the Wrapper design pattern, aka Decorator, aka Delegator. Oh wouldn't it be great to use via? But alas, until my cry is heard, or someone corrects me, the solution is to:

  1. Create a new class that also implements Connection.
  2. Use this class to wrap the obtained PostgreSQLConnection
  3. Painstakingly implement each and every method in Connection to pass through to the wrapped connection, except for the methods I want to meddle with.
  4. Pass out of my Connection-obtainer class, not the raw Connection, but my new wrapper.
  5. Accept resignedly that when the Connection interface changes, my Connection wrapper will now not fulfil the new interface and will break. Really good reason for via.
So enough whinging. In Eclipse, it is just a matter of creating a new class, and implementing Connection. If the methods didn't appear then the class name will have an error; Ctrl+1 on this gives the option 'Add unimplemented methods'. And there they will be, all 50 of them (rough count), ready to type this.connection.blah() in each. But hey, Eclipse can do multiline regex finds, and we can use regular expressions in the find and replace, so....

To fix all wrapped method calls that return a value:
In the new class, Ctrl-F to bring up the find/replace dialog. Make sure 'Wrap search' and 'Regular expression' are ticked, and 'Scope' is 'All', then copy and paste into Find:
(?s)[^\n]*(public (?!class)[^\n]* (\S*\([^\)]*\))[^\{]*\{)[^\}]*return[^\}]*}

This searches for any lines having the word public, not followed by class, and having a return statement.
Hit Find a few times to validate it's matching correctly.

Now, in Replace:
\1\nreturn this.myWrappedFieldName.\2;\n}

Takes the first match (\1) and appends the method call (\2) to the field name.

Click 'Replace All' to see it happen.

To fix the remaining method calls with no return value (ie void)
In Find:
(?m).*(public void (\S*\([^\n]*\)).*\{)[^\}]*}

Now, in Replace:
\1\nthis.myWrappedFieldName.\2;\n}

And 'Replace All' again.

As yet the above regex statements don't remove parameter types from the calling statements, so you will have to go through and remove them, but that should be relatively little work.

SQuirreL SQL

Thursday, March 19, 2009

For a long time I have been looking for an open source database management tool that would be able to access any JDBC compliant database. I've used the great Oracle product, SQLDeveloper, for a long time and found it great for SQL Server management (usually performing quicker than using Microsoft's own Management Studio!). But now I've started using Derby (aka JavaDB aka Cloudscape) and SQLDeveloper is limited to Oracle, SQL Server, and MySQL.

Step in SQuirreL SQL. It has a pretty smooth interface, with great features like SQL syntax highlighting and even code completion. Released under the LGPL license, it is open source and contributions are welcomed, particularly for plugins. The plugins are important as JDBC is obviously a restricted subset of a database's functionality - a number of the existing plugins enable extra features for specific database types (eg. Derby's triggers).

Another very notable plugin is called graph which enables production of simple entity relationship diagrams (ERD) from a database connection. While it doesn't display multiplicity indicators, and some of the image exporting is a bit clunky, it is great to have this functionality in an open source product. (I now use NetBeans' UML Modeling which is great for the common UML diagrams, but lacking ERDs).

secure svn server on osx tiger

Sunday, February 08, 2009

My notes to help remember the processes to get a secure svn server using Apache 2 on OS X Tiger. I know these are documented in lots of places, but it seemed that parts of various HowTos were required in order to do it with current Apache (2.2) and with Tiger. For anyone with Leopard onwards, you can skip the installation of Apache2 as this is now standard from Leopard on (Tiger and earlier used Apache 1.3 and earlier) and here is probably your best bet.

Edit: I drafted this a year ago and never finished (or published) it. Now the server has reverted back to apache1.3 after an update and my ssl cert had expired - time to revive the post! Unfortunately I didn't capture all the steps, especially the setting up of mods-enabled etc, but I'll just use my install as reference. Ask if you need those bits. Meantime, this link may be helpful. Brad.
Edit 2 (16/4/2009): It did it again. If svn access starts to fail, log in to a directory-displaying page or any page that gives the apache http server version - if it says 1.3 then it's reverted back from 2.0 (alternatively, if ls -l /usr/sbin/apachectl shows a single file rather than a symlink to /sw/sbin directory, that also is an indicator it's reverted). Easy fix is (after stopping 'Personal Web Sharing' in System Prefs): sudo ln -sf /sw/sbin/apache2ctl /usr/sbin/apachectl as below. Then start web sharing again; should now be 2.0 running.

Installing Apache httpd 2
1. Apache2 Installation

The bulk of this guide comes from Tim Fanelli's great howto (just the Fink, Apache2, Subversion, and WebDav steps for now). If you don't have XCode Tools installed prior to this, you can get them here (requires free registration). Extra notes to the sections in Tim's guide follow:

  • Apache2: At the end of this section you can start up Apache2. Be sure to shut down the 1.3 WebServer first via the Sharing panel of SysPrefs, if it is running. You should then be able to view the Apache2 welcome screen by browsing to http://localhost. You probably won't be able to access this from another machine yet though (even within LAN) as the Mac's firewall won't be allowing it. We'll get to that later.
  • Subversion: If you will be carrying this on to use svn, you might as well do this and the WebDAV steps now. You'll need svn-ssl, but may not require svn-client-ssl. I didn't install it.
That's all we need from that blog for setting up the Apache2 server

2. Apache2 Configuration
Next we'll configure Apache2 to be handled by the Sharing panel of SysPrefs, instead of old 1.3.

  • cd /usr/sbin
  • mv apachectl apachectl1.3 {–> This renames default apache1.3/apachectl command}
  • ln -s /sw/sbin/apache2ctl apachectl {–> This creates symlink for Apache2/apachectl command}

Edit /sw/etc/apache2/apache2.conf:
  1. Change the pidfile location to:

    /private/var/run/httpd.pid

  2. In order to easily view logs from Console, and to get free log rotation, change the ErrorLog parameter to:

    /var/log/httpd/error_log

  3. And add a new entry:

    CustomLog /var/log/httpd/access_log common


3. SSL Certificate
Go back to Tim's post and the SSL step. You'll want to follow the link and generate the certificate Important: Ensure you create a CommonName attribute in the certificate. If it is missing then many svn clients will fail to access the site. After doing that though, a couple of the commands given back in the main howto are wrong. Change sudo cp ~/server.key /sw/etc/apache2/ssl.key/ to sudo cp ~/sslcert/server.key /sw/etc/apache2/ssl.key/ and the same for .crt.


Edit (13/5/2009): Looks like Tim's blog is having some technical issues. Here are the ssl certificate creation and installation steps:
  1. cd /tmp
  2. openssl genrsa -des3 -out server.key {generates the key}
  3. openssl req -new -key server.key -out server.csr {generates a certificate-signing request (CSR; holds the information about the certificate) using the created key}
  4. openssl x509 -req [-days 365] server.csr -signkey server.key -out server.crt {generates the certificate, with information in the CSR, using our key. The bit in the square brackets is optional, and is if you want the certificate to expire.}
  5. sudo mv server.key /sw/etc/apache2/ssl.key/
  6. sudo mv server.crt /sw/etc/apache2/ssl.crt/
  7. sudo chmod 0400 /sw/etc/apache2/ssl.key/ {if server won't start later, try also: sudo chmod u+xw on this path}
  8. sudo chmod 0400 /sw/etc/apache2/ssl.crt/



For better security, don't do the decryption suggested. However, for
pragmatism and to be able to control the server via the SysPrefs, just
do it :)

mysql quick reference

Sunday, January 25, 2009

Launch mysqld (server) on Linux (if not already running):
sudo /etc/init.d/mysql start

Connect to server [specific database]:
mysql [-h host] -u user -p [dbname to use]

Use the SHOW statement to find out what databases currently exist on the server:
mysql> SHOW DATABASES;

Pick one:
mysql> USE dbname

Create new one:
mysql> CREATE DATABASE dbname;

List tables:
mysql> SHOW TABLES;

Create table:
mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
-> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);

List tables columns:
mysql> DESCRIBE tablename;

Generate schema:
mysql> SHOW CREATE TABLE tablename;

use jndi with spring to access external properties file

Tuesday, January 13, 2009

On the surface, external configuration files in a JEE environment provide a simple mechanism to store environment-specific data, but they can be a pain to access. How to access it when file system access isn't allowed? Since it's outside the classpath, where is the file in each environment? If I'm using Spring, how do I access this movable file?

The best solution I've found is to use jndi resources. The following is a solution using Websphere (6) and Spring (2.01).

Step 1: Configure the jndi reference for Websphere
This step was based on information from IBM's page "Using URL resources to manage J2EE property files in IBM WebSphere Application Server V5", steps A and B. Websphere Studio isn't required, however, so briefly:
a) Navigate to Resources > URL > URLs and create a new URL. Make up a JNDI name starting with "url/". In 'specification', enter the path to the properties file as a URI, eg. "file:///E:/project.properties". So now Websphere has a URL Resource pointing to the properties file for this environment.
b) In the code, edit web.xml. Configure a new resource-ref as shown in IBM's figure 6. 'res-ref-name' is the jndi name we set up in a). Then in ibm-web-bnd.xmi, add a new resRefBindings as shown in IBM's figure 7.
That completes the configuration of Websphere and the jndi configuration in the code.

Step 2: Next Spring needs to be able to load the properties file by looking up the jndi location.
c) I'll assume that you want the properties file to be set as a property on a class 'pkg.MyClass'. To do this, we use a PropertyFactoryBean to convert from properties file to Properties class. The PropertyFactoryBean takes a Resource as location property, so we create a UrlResource bean for this, with the java.net.Url as constructor argument. This java.net.Url is the result of using a JndiObjectFactoryBean to look up the jndi name and return the Url object. The following bean config shows these conversions:


<bean class="myclass">
 <property name="props">
  <!-- Load from the .properties file-->
  <bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
   <property name="location">
    <!-- Generate a UrlResource from the java.net.Url -->
    <bean class="org.springframework.core.io.UrlResource">
     <constructor-arg>
      <!-- use jndi to look up the location of the parameters.properties file -->
      <bean class="org.springframework.jndi.JndiObjectFactoryBean">
       <property name="jndiName" value="java:comp/env/url/analysisParametersURL" />
      </bean>
     </constructor-arg>
    </bean>
   </property>
  </bean>
 </property>
</bean>


And that's it. In summary, Spring looks up a jndi URL reference to a properties file, configured in the JEE server. Spring beans are created that convert the URL to a URLResource to a Properties object, available for injection into your custom class.