FroMage / jax-doclets

Set of JavaDoc doclets for modern Java annotations APIs
http://www.lunatech-labs.com/open-source/jax-doclets
GNU Lesser General Public License v3.0
26 stars 23 forks source link

Path regexp support: unable to create directory #25

Closed ilyavolk closed 12 years ago

ilyavolk commented 12 years ago

Duplicate with Issue 26 from code.google.com tracker.

When I use resource with a Path with regexp like .+,.+, doclet cannot create directory. It seems doclet removes several regexp expressions from path, but not all of them.

What steps will reproduce the problem? 1.Create a resource with a Path annotation with a regex. Example: @Path("contact/{contactIds : .+,.+}")

  1. Run the jax doclet against the project.
  2. You will get a stack trace about not being able to create the directory from the doclet. See below.

What version of the product are you using? 0.8.0 0.9.0 0.10.0

On what operating system? Windows 7

Call stack: Embedded error: Error rendering Maven report: Exit code: 1 - javadoc: error - Unable to create directory D:/target/site/jaxrsdocs\v1.0\account{accountId}\address-book\contact{contactIds : .+,.+} javadoc: error - In doclet class com.lunatech.doclets.jax.jaxrs.JAXRSDoclet, method start has thrown an exception java.lang.reflect.InvocationTargetException com.sun.tools.doclets.internal.toolkit.util.DocletAbortException at com.sun.tools.doclets.internal.toolkit.util.DirectoryManager.createDirectory(DirectoryManager.java:263) at com.sun.tools.doclets.internal.toolkit.util.Util.genWriter(Util.java:576) at com.sun.tools.doclets.formats.html.markup.HtmlWriter.(HtmlWriter.java:61) at com.sun.tools.doclets.formats.html.markup.HtmlDocWriter.(HtmlDocWriter.java:47) at com.sun.tools.doclets.formats.html.HtmlDocletWriter.(HtmlDocletWriter.java:95) at com.lunatech.doclets.jax.jaxrs.writers.ResourceWriter.getWriter(ResourceWriter.java:43) at com.lunatech.doclets.jax.jaxrs.writers.ResourceWriter.(ResourceWriter.java:37) at com.lunatech.doclets.jax.jaxrs.model.Resource.write(Resource.java:165) at com.lunatech.doclets.jax.jaxrs.model.Resource.write(Resource.java:169) at com.lunatech.doclets.jax.jaxrs.model.Resource.write(Resource.java:169) at com.lunatech.doclets.jax.jaxrs.model.Resource.write(Resource.java:169) at com.lunatech.doclets.jax.jaxrs.model.Resource.write(Resource.java:169) at com.lunatech.doclets.jax.jaxrs.model.Resource.write(Resource.java:169) at com.lunatech.doclets.jax.jaxrs.model.Resource.write(Resource.java:169) at com.lunatech.doclets.jax.jaxrs.JAXRSDoclet.start(JAXRSDoclet.java:106) at com.lunatech.doclets.jax.jaxrs.JAXRSDoclet.start(JAXRSDoclet.java:78) 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)

ilyavolk commented 12 years ago

To fix this issue, you need to patch Utils.java, function removeFragmentRegexes. At the first line regexp pattern must be replaced to

Pattern regexPattern = Pattern.compile("\\{(\\w[\\w\\.-]*)[ ]*:");

Unit test for this issue (sorry, I didn't find an ability to attach files):

package com.lunatech.doclets.jax.test;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.junit.Before;
import org.junit.Test;

import com.lunatech.doclets.jax.Utils;

public class UtilsTest {

    private Map testFragment = new HashMap();

    @Before
    public void setUp() {
        testFragment.put("/", "/");

        testFragment.put("/{resource}", "/{resource}"); 
        testFragment.put("/resource1/resource2", "/resource1/resource2");

        testFragment.put("{id}", "{id}");
        testFragment.put("~/id", "~/id");
        testFragment.put("resource/{id : \\S+}", "resource/{id}");
        testFragment.put("resource/{ids : .+,.+}", "resource/{ids}");

        testFragment.put("{id : \\d+}/resource", "{id}/resource");
        testFragment.put("{id}/resource", "{id}/resource");
        testFragment.put("{id : \\S+}", "{id}");
        testFragment.put("resource1/{id : \\d+}", "resource1/{id}");
        testFragment.put("resource1/{id}/resource2/{ids}", "resource1/{id}/resource2/{ids}");
        testFragment.put("resource1/{id}/resource2/{id : \\d+}", "resource1/{id}/resource2/{id}");
    }

    @Test
    public void testRemoveFragmentRegexes() {
        Map regexFragments = new HashMap();
        for(Entry entry : testFragment.entrySet()) {
            String newFragment = Utils.removeFragmentRegexes(entry.getKey(), regexFragments);
            assertEquals(entry.getValue(), newFragment);
        }
    }
}
FroMage commented 12 years ago

Aha, it's a whitespace issue! OK. Fix committed, thanks a lot :)