FroMage/jax-doclets — Issue #20: 0.9.1-SNAPSHOT build fails under Windows
Author: stanio
Created: 2011-12-23 05:31:28+00:00
State: open

The build of the current development version 0.9.1-SNAPSHOT fails under Windows:

[INFO] [javadoc:test-javadoc {execution: jaxrs}]
[INFO]
Loading source files for package com.lunatech.doclets.jax.jaxb...
Loading source files for package com.lunatech.doclets.jax.jaxb.testcase...
Loading source files for package com.lunatech.doclets.jax.test...
Loading source files for package com.lunatech.doclets.jax.test.demo.doc...
Loading source files for package com.lunatech.doclets.jax.test.demo.nodoc...
Loading source files for package com.lunatech.doclets.jax.test.demo...
Loading source files for package com.lunatech.doclets.jax.test.interfaces...
Loading source files for package com.lunatech.doclets.jax.test.jpa...
Constructing Javadoc information...
Generating .../jax-doclets/doclets/target/jaxrsdocs\index.html...
Generating .../jax-doclets/doclets/target/jaxrsdocs\doc-method-order\index.html...
1 error
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An error has occurred in Test JavaDocs report generation:
Exit code: 1 - javadoc: error - In doclet class com.lunatech.doclets.jax.jaxrs.JAXRSDoclet, method start has thrown an exception java.lang.reflect.InvocationTargetException
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(String.java:686)
at java.util.regex.Matcher.appendReplacement(Matcher.java:703)
at java.util.regex.Matcher.replaceAll(Matcher.java:813)
at java.lang.String.replaceAll(String.java:2189)
at com.lunatech.doclets.jax.Utils.urlToSystemPath(Utils.java:348)
at com.lunatech.doclets.jax.jaxrs.writers.ResourceWriter.getWriter(ResourceWriter.java:42)
at com.lunatech.doclets.jax.jaxrs.writers.ResourceWriter.<init>(ResourceWriter.java:38)
at com.lunatech.doclets.jax.jaxrs.model.Resource.write(Resource.java:161)
at com.lunatech.doclets.jax.jaxrs.model.Resource.write(Resource.java:165)
at com.lunatech.doclets.jax.jaxrs.model.Resource.write(Resource.java:165)
at com.lunatech.doclets.jax.jaxrs.JAXRSDoclet.start(JAXRSDoclet.java:95)
at com.lunatech.doclets.jax.jaxrs.JAXRSDoclet.start(JAXRSDoclet.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:269)
at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:143)
at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:340)
at com.sun.tools.javadoc.Start.begin(Start.java:128)
at com.sun.tools.javadoc.Main.execute(Main.java:41)
at com.sun.tools.javadoc.Main.main(Main.java:31)

Command line was: C:\java\jdk1.6.0_x64\jre\..\bin\javadoc.exe @options @packages

Refer to the generated Javadoc files in '...\jax-doclets\doclets\target\jaxrsdocs' dir.

The problem appears the following line in com.lunatech.doclets.jax.Utils.urlToSystemPath():

return name.replaceAll("/", File.separator);

This fails because under Windows the File.separator happens to match the regex escape character. So it should either get escaped properly:

diff --git a/doclets/src/main/java/com/lunatech/doclets/jax/Utils.java b/doclets/src/main/java/com/lunatech/doclets/jax/Utils.java
--- a/doclets/src/main/java/com/lunatech/doclets/jax/Utils.java
+++ b/doclets/src/main/java/com/lunatech/doclets/jax/Utils.java
@@ -343,11 +343,11 @@

public static String urlToSystemPath(Resource resource) {
String name = resource.getAbsolutePath();
if (name.startsWith("/"))
name = name.substring(1);
- return name.replaceAll("/", File.separator);
+ return name.replaceAll("/", Matcher.quoteReplacement(File.separator));
}

public static String urlToClass(JAXBClass from, JAXBClass to) {
return classToRoot(from) + classToPath(to) + "/" + to.getShortClassName() + ".html";
}

Or use the simpler and probably faster String.replace(char, char):

diff --git a/doclets/src/main/java/com/lunatech/doclets/jax/Utils.java b/doclets/src/main/java/com/lunatech/doclets/jax/Utils.java
--- a/doclets/src/main/java/com/lunatech/doclets/jax/Utils.java
+++ b/doclets/src/main/java/com/lunatech/doclets/jax/Utils.java
@@ -343,11 +343,11 @@

public static String urlToSystemPath(Resource resource) {
String name = resource.getAbsolutePath();
if (name.startsWith("/"))
name = name.substring(1);
- return name.replaceAll("/", File.separator);
+ return name.replace('/', File.separatorChar);
}

public static String urlToClass(JAXBClass from, JAXBClass to) {
return classToRoot(from) + classToPath(to) + "/" + to.getShortClassName() + ".html";
}