Archive for November, 2007

My excuses for not blogging often

After reading last entry on David’s James blog about reasons for not blogging enough I started to think about my own reasons for doing exactly the same thing.

User friendliness of the blog content management is important but I don’t think that is my excuse. What it is then?

I am not going to mention the natural human laziness (I’ve just done it). It could be this as well but in my case I can see two things on my way to have more often updated blog:

  • perfectionism (sic!)
  • type of the content I decided to write about

Perfectionism because it stops me from posting “quick and dirty” posts. Very often instead of writing maybe bit rough entry but actually writing it I wait for a bit of time when I can “do it properly”. And obviously it rarely happens.

Type of the content because I decided to post mainly solutions to common software development problems as a favour to other as I often find answers for my questions in other’s people blogs. But this type of content is pretty time consuming to create. I might to change it as I am not to be honest as excited about doing that.

So… That’s my list of excuses. What’s yours?

Popularity: 33% [?]

Comments (3)

Eclipse 3.3 leaks permgen space

EclipseSome of you who use Eclipse 3.3 with Sun JVM might notice that it crashes from time to time. Those who have many plugins certainly experienced this more often. Problem and solution for this bug is very trivial but worth mentioning: leaking permgen space. Comes back like November flu! Just to remind the permgen space is a memory for storing “data needed by the virtual machine to describe objects that do not have an equivalence at the Java language level. For example objects describing classes and methods are stored in the permanent generation“. More information about permgen can be found in an article about tuning garbage collection.

To fix the problem edit your eclipse.ini and add following lines:

-XX:PermSize=128M
-XX:MaxPermSize=256M

You might also try Eclipse 3.3.1.1 which includes a fix for the above problem.

Enjoy!

Popularity: 38% [?]

Comments (1)

Integrating AStyle into your Ant build

AntThis blog entry will introduce you how to integrate AStyle into your Ant build.

Short introduction: In my current project I work on software which generates SDKs for multiple languages consuming Web21C services . The SDKs are SOAP webservice clients for multiple languages as Java, Python, PHP or .Net (new are comming soon). XSLT transformations are extensively in use to achieve the goal of generating those SDKs.

The problem is that we are facing a trade off:

  • we have ugly formatted XSL to be able to generate correctly formatted output code
  • we can have pretty formatted and easy to maintain and read XSL but not correctly formatted output in particular language

Let’s assume that we are not crazy yet and we will not follow the first option. The second option looks better but is still not perfect. We need to plug a tool which will do the dirty job for us: correct indentation, format and beautify our output source. Artistic Style (AStyle) has been selected as the tool as it is small, simple, fast tool and supports both Java and C#.

However the AStyle has couple of downsides:

  • doesn’t have easy integration with Ant
  • accepts only list of files for transformation, there is no recursive mode

Let’s assume that all source files to be transformed are in folder generated, with multiple subfolders. As there is no integration with Ant we will have to use <exec/> task. Something like:

<property name="astyle.exe" location="${astyle.home}/astyle.exe"></property>
<exec executable="${astyle.exe}" dir="${basedir}">
    <arg value="--mode=java"></arg>
    <arg value="--style=java"></arg>
    <arg value="--suffix=none"></arg>
    <arg value="${sourcefile}"></arg>
</exec>

AStyle accepts following arguments:

astyle [options] SourceFile1.java SourceFile2.java SourceFile3.java [...]

Wouldn’t it be nice to have -R option?

Our first approach could be construction of a space separated list of paths to all files in folder generated and then using this as argument in exec task. We would quickly realize that we have a possible problem with maximum length of a command line executed via exec task which is just 256 characters. Better will be to execute astyle many times, for each file to be formatted. Core Ant task are not enough in this case. We have to use ant-contrib tasks. First copy ant-contrib jar to your ANT_HOME/lib and add in your build:

<taskdef resource="net/sf/antcontrib/antlib.xml" />

It will let you use <for/> task which should help us to solve our problem as it will allow us to iterate over list of paths and execute external command for each one. The final ant task could look like:

<target name="format">
    <for param="file">
        <path>
  	    <fileset dir="${generated}" includes="**/*.java"/>
  	</path>
  	<sequential>
  	    <property name="astyle.exe" location="${astyle.home}/astyle.exe" />
	    <exec executable="${astyle.exe}" dir="${basedir}">
	        <arg value="--mode=java"/>
	        <arg value="--style=java"/>
	        <arg value="--suffix=none"/>
	        <arg value="@{file}"/>
	    </exec>
  	</sequential>
    </for>
</target>

Fist we define a name of the parameter to pass the tokens or files to the sequential, let’s call it just file. Note that for makes use of ant’s macrodef task, so the @{} notation is used for parameter substitution. Next we define path including all java files in generated folder. The last step is to use <sequential/> block where the execution of astyle.exe will happen for each source file defined using @{file} parameter.

Popularity: 40% [?]

Comments

Close
E-mail It