RSS

Monthly Archives: September 2009

Weird Error While Executing LessCSS

>This is really odd: I got the following output while running lessc on some .less files from an Apache Ant task:

-lesscss:
[003:221] MagicCam 0: Current process: java, Flash is loaded: no
[003:221] Error(magiccammac.cc:276): MagicCam 0: MagicCamOpen: Not an allowed process!
[000:002] MagicCam 0: Current process: java, Flash is loaded: no
[000:002] Error(magiccammac.cc:276): MagicCam 0: MagicCamOpen: Not an allowed process!
[000:001] MagicCam 1: Current process: java, Flash is loaded: no
[000:001] Error(magiccammac.cc:276): MagicCam 1: MagicCamOpen: Not an allowed process!
[000:002] MagicCam 1: Current process: java, Flash is loaded: no
[000:002] Error(magiccammac.cc:276): MagicCam 1: MagicCamOpen: Not an allowed process!
[lesscss] 0 file(s) transformed in 4 ms; 7 unmodified file(s) skipped.

Now I had it at a different point in the build process:

do-generate-headings:
Warning: Reference saxon.classpath has not been set at runtime, but was found during
build file parsing, attempting to resolve. Future versions of Ant may support
referencing ids defined in non-executed targets.
[xslt] Processing /Users/ernst/albizia/build/contentdb/pfizer/content/PreprocessedSite.xml to /Users/ernst/albizia/build/contentdb/pfizer/content/PageHeadings.ErigeronStrings.xml
[xslt] Loading stylesheet /Users/ernst/albizia/src/build-xslt/GeneratePageHeadings.xslt
[xmlvalidate2] 1 file(s) have been successfully validated.
[000:224] MagicCam 0: Current process: java, Flash is loaded: no
[000:224] Error(magiccammac.cc:276): MagicCam 0: MagicCamOpen: Not an allowed process!
[000:003] MagicCam 0: Current process: java, Flash is loaded: no
[000:003] Error(magiccammac.cc:276): MagicCam 0: MagicCamOpen: Not an allowed process!
[000:000] MagicCam 1: Current process: java, Flash is loaded: no
[000:001] Error(magiccammac.cc:276): MagicCam 1: MagicCamOpen: Not an allowed process!
[000:002] MagicCam 1: Current process: java, Flash is loaded: no
[000:002] Error(magiccammac.cc:276): MagicCam 1: MagicCamOpen: Not an allowed process!

There is a tiny bit of information here:

 
1 Comment

Posted by on 22 September 2009 in ant, flash, google talk, googletalk, java, lesscss, magiccam, magiccamopen

 

OptiPNG Ant Task

>OptiPNG is a tool for optimizing PNG images. And now, there’s an Ant task for executing it from an Ant build file:

Mini-HOWTO for Linux/UNIX/Mac OS X systems, assuming you already have Apache Ant installed:

  1. download OptiPNG source code from SourceForge (TAR GZ file)
  2. execute: ./configure
  3. execute: make
  4. execute: sudo make install
    (enter your password if required); the command optipng is now installed in /usr/local/bin/
  5. download the optipng-ant-task source code from http://github.com/znerd/optipng-ant-task/downloads – take the latest version available (you can choose between a ZIP and a TAR GZ file)
  6. unpack the download file, this will create a new directory with an odd name like: znerd-optipng-ant-task-604de975b4cc4a1a2766e385c91b749318af038e (you may want to rename it to optipng-ant-task or so)
  7. in that directory, execute: ant
    this will compile the classes, run the available unit test and build the JAR file

Then you can use the Ant task from your own build file, for example as follows:

<taskdef name="optipng" classname="com.pensioenpage.jynx.optipng.OptiPNGTask" classpath="lib/optipng-ant-task.jar" />
<optipng dir="src/htdocs" todir="build/htdocs" />

 
Leave a comment

Posted by on 8 September 2009 in ant, optipng, png, task, taskdef

 

Java Language: Referencing Current Class From Static Context

>Currently, in Java SE 6, to reference the current class from a static context the name of the class is needed. For example:

public class Foo {
public static final valueOf(String s) {
if (s == null) {
return null;
} else if (s.startsWith(Foo.class.getName() + ':')) {
...
} else {
...
}
}
}

However, if this code would be copied to another class, or if the class is renamed, then that code will cause issues, possibly even causing hard-to-find bugs.

Instead it would be nice if the enclosing class could be referenced without using the name. A possible syntax that does not introduce new language keywords could just be:

class

The previous example would then become:

public class Foo {
public static final valueOf(String s) {
if (s == null) {
return null;
} else if (s.startsWith(class.getName() + ':')) {
...
} else {
...
}
}
}

Of course, this construct should also be allowed in non-static code.

One open question is how to deal with inner classes and referencing a certain outer class. I would not mind keeping that out of scope, so the feature only allows referencing the direct enclosing class.

Another issue is subclassing. Would the class statement reference the current class (in case of a non-static context) or the one the method is defined in?

 
Leave a comment

Posted by on 3 September 2009 in class, extension, java, language, this

 

Improving Ant Output

>Ant is a very popular build tool in Java environments. Numerous tasks have been developed for it that allow integration with various services and products quite easy.

One area Ant could improve in is output. Running a typical build file produces a lot of output that is not really relevant to the user. Also, when an error occurs, it would be nice to have a stack trace giving more information, but then you need to rerun Ant with the -verbose option, which enables verbose output for all tasks, not just the failing one.

And note that there may be situations in which rerunning the task is suboptimal:

  • the error does not occur again (but it may come back to hunt you later on)
  • executing the build takes a lot of time

Here are some guidelines I propose for improving Ant output:

  1. keep output to stdout very limited;
  2. after completion of the build run, provide access to more output, including the stacktrace, without rerunning the task

Here’s an example of some Ant output:

-init-properties:

-init-site-properties:

check-questions:

transform-questions-xml:
[xmlvalidate2] 10 file(s) have been successfully validated.
[xslt] Transforming into /Users/ernst/albizia/build/contentdbsrc/xsite/content
[xslt] Processing /Users/ernst/albizia/build/contentdbsrc/xsite/content/AOW.QuestionsCategory.xml to /Users/ernst/albizia/build/contentdbsrc/xsite/content/Vragen_AOW.SourcePage.xml
[xslt] Loading stylesheet /Users/ernst/albizia/src/build-xslt/PreprocessQuestions.xslt
[xslt] Processing /Users/ernst/albizia/build/contentdbsrc/xsite/content/Berekenen.QuestionsCategory.xml to /Users/ernst/albizia/build/contentdbsrc/xsite/content/Vragen_Berekenen.SourcePage.xml

The output from the xmlvalidate2 task is very brief. That’s nice. In fact the question is whether the output should be shown at all. The output from the xslt task, however, is quite verbose. Instead of listing all files being processed, it could just give a summary of what it did. When -verbose is passed, it could output what is currently output.

Here are some possible options for achieving the goals I stated above:

  1. When a certain Ant option is enabled (which could at some point be enabled by default), send all verbose output to a file on the file system, for example build.log or .build.log. This file can be examined by the user after the build is finished (or cancelled).
  2. When using the default output mode for stdout, do not output the names of tasks that are not actually run (depending on the if and unless attributes).
  3. By default make all tasks just output a single line with a summary of what it did.
  4. Do not put an empty line between each executed task.
  5. When using this mode, use fixed-width output for the target names, and put the task output behind that. Target and task names may have to be cropped for that. For example:
    -init-prope.:
    -init-site-.:
    check-quest.:
    transform-q.:xmlvali.: 10 file(s) validated.
       xslt: 15 file(s) processed, 0 unmodified file(s) skipped.

Note that the output Ant 1.7.1 currently produces when running Ant with the -verbose option is always available after the build run, so the reduction of initial output is not limiting the investigation options for the user, but is in fact extending those.

What do you think of this? Do you consider the current Ant output too verbose or just fine? Have you every had issues examining why an Ant build failed and you wish you would have passed -verbose in the first place? And what do you think of the suggested changes?

 
4 Comments

Posted by on 3 September 2009 in ant, apache ant, output, stdout, verbose, verbosity

 

Converting ODS to CSV

>Recently I’ve released an ODS (OpenDocument Spreadsheet) to CSV (Comma-Separated Values) converter. It’s available from GitHub:

The current version (0.1) is not perfect, I’ve documented some issues, mainly related to empty fields/records being output. After releasing version 0.1 I created some unit tests; once they pass, these issues should be resolved.

During development, it turned out it’s really easy to parse an ODS file, since it’s just a ZIP file with the contents contained in simple XML file inside it.

The converter uses SAX to parse the XML inside it, to minimize memory usage. It comes with a Java library, a command line program and an Apache Ant task. And there are no external dependencies other than a Java runtime environment (version 1.5 or up).