Ancient Programming

What I encounter in my software part of life is in danger of being commented upon here

Archive for June, 2008

Automatically reconnect to NAS under Mac OS X

Posted by Jacob von Eyben on 27th June 2008

Mac OS X doesn’t remount network drives when booted. You have to do this yourselves.

You can easily automate this by creating an application using the automator and add it to your login items.

Automator - create application

You automator script should contain two items:

  • Get Specified Servers
  • Connect to Servers

Save the script as an application and put it into login items for your user account. This will execute your small application each time you login and you should be reconnected to your NAS on startup.

Posted in how to, mac | No Comments »

Fixedformat4j 1.2.0 released

Posted by Jacob von Eyben on 12th June 2008

This evening I released a new version of fixedformat4j containing improved error reporting when failing to parse data using the FixedFormatManager.

The lack of good error reporting was a bit of a pain. It was not easy to see where in the parsing failed and it was not possible to get a complete list of format instructions.

A new ParseException is now thrown which contains the nessesary information.

See example of the new and improved stacktrace:

com.ancientprogramming.fixedformat4j.format.ParseException: failed to parse 'barfooba' at offset 16 as java.util.Date from 'foobarfoobarfoobarfoobar'. Got format instructions from com.ancientprogramming.fixedformat4j.format.impl.MyRecord.getDateData. See details{FormatContext{offset=16, dataType=java.util.Date, formatter=com.ancientprogramming.fixedformat4j.format.impl.ByTypeFormatter}, FormatInstructions{length=8, alignment=LEFT, paddingChar=' ', fixedFormatPatternData=FixedFormatPatternData{pattern='yyyyMMdd'}, fixedFormatBooleanData=FixedFormatBooleanData{trueValue='T', falseValue='F'}, fixedFormatNumberData=FixedFormatNumberData{signing=NOSIGN, positiveSign='+', negativeSign='-'}, fixedFormatDecimalData=FixedFormatDecimalData{decimals=2, useDecimalDelimiter=false, decimalDelimiter='.'}}}
 at com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl.readDataAccordingFieldAnnotation(FixedFormatManagerImpl.java:179)
 at com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl.load(FixedFormatManagerImpl.java:70)

Feel free to download the latest version and take a look at the changelist.

Posted in java | No Comments »

How to create macros for maven-site-plugin

Posted by Jacob von Eyben on 5th June 2008

Many maven projects uses the maven site plugin to generate there documentation.

The maven-site-plugin uses the doxia to let authors write xdoc, apt and fml documents as the source for there project documentation. These written documents is processed by doxia to generate html and merged into the complete project site by the maven-site-plugin.

I found doxia and especially the apt language somehow lacking in functionality. I would like to use the syntaxhighlighter to be able to highlight code examples on the fixedformat4j project.

Doxia comes out-of-the-box with a small bunch of macros and you have the ability to write custom macros as well.

Custom macro


I wrote a simple macro based on the core snippet macro:

pom.xml:



    org.apache.maven.doxia
    doxia-modules
    1.0-alpha-11
  
  4.0.0
  com.ancientprogramming.maven.doxia
  doxia-module-syntaxhighlighter
  1.0-alpha-11
  Doxia :: syntaxhighlighter
  


        org.codehaus.plexus
        plexus-maven-plugin
        
          
            
              descriptor
            
          
        
      
    
  

Changes to the snippet plugin:

...
  public void execute(Sink sink, MacroRequest request)
      throws MacroExecutionException {
    System.out.println("ancientprogramming - running execute");
    String id = (String) request.getParameter("id");

    required(id, "id");

    String urlParam = (String) request.getParameter("url");

    String fileParam = (String) request.getParameter("file");

    String codeParam = (String) request.getParameter("code");

    required(codeParam, "code");

    URL url;

    if (!StringUtils.isEmpty(urlParam)) {
      try {
        url = new URL(urlParam);
      }
      catch (MalformedURLException e) {
        throw new IllegalArgumentException(urlParam + " is a malformed URL");
      }
    } else if (!StringUtils.isEmpty(fileParam)) {
      File f = new File(fileParam);

      if (!f.isAbsolute()) {
        f = new File(request.getBasedir(), fileParam);
      }

      try {
        url = f.toURL();
      }
      catch (MalformedURLException e) {
        throw new IllegalArgumentException(urlParam + " is a malformed URL");
      }
    } else {
      throw new IllegalArgumentException("Either the 'url' or the 'file' param has to be given.");
    }

    StringBuffer snippet;

    try {
      snippet = getSnippet(url, id);
    }
    catch (IOException e) {
      throw new MacroExecutionException("Error reading snippet", e);
    }

   sink.rawText("... syntaxhighlighter prefix ...");
   sink.rawText(snippet.toString());
   sink.rawText("... syntaxhighlighter postfix ...");
}
...

Note: wordpress obfuscates the above code where I wrote the syntax hightlighter pre and post fix. You can see what you actually should write at the syntaxhighligther project.

Use custom macro
To be able to use the macro you have to add your macro as dependency to the maven-site-plugin:


  org.apache.maven.plugins
   maven-site-plugin
   
     ${basedir}/src/site
     src/site/fixedformat4j-template.vm
   
   
    
      com.ancientprogramming.maven.doxia
      doxia-module-syntaxhighlighter
      1.0-alpha-11
    
  


Now you can use the macro by writing the following in your apt files:

%{code-snippet|id=basicusage|code=java|file=../../BasicUsageRecord.java}

Change your site template
Before the the source can be highlighted in your documentation you should add the syntaxhighlighter javascript and stylesheets to your template.
See how to change your template here.

Posted in how to, java, maven | 1 Comment »

Fixedformat4j scores well on sonar

Posted by Jacob von Eyben on 5th June 2008

Today I found fixedformat4j was obtained at sonarsoftware and it was exciting to see that it scored pretty well compared to some other very well known opensource projects like the commons series, some of the spring module and even the Apache Maven project.

I didn’t know sonar before today. They describe them as:

Sonar is an entreprise quality control tool, distributed under the terms of the GNU LGPL. Its basic purpose is to join existing continuous integration tools to place Java development projects under quality control.

Even though the metrics at sonar doesn’t draw the complete picture on how good or mature a project is, it still gives a hint.

Posted in fixedformat4j, java | No Comments »