asciidoctor / asciidoctor-ant

:ant: Ant task to render Asciidoc documentation
Apache License 2.0
9 stars 5 forks source link

asciidoctor-ant not working in some cases #54

Closed steven-xing closed 7 years ago

steven-xing commented 8 years ago

case 1: cygwin ant working directory: c:/a/_b/c/d task source path: e (this is a relative path of c:/a/_b/c/d/e) expect result: should work without any problem actual result: all file skipped.

case 2: linux ant working directory: /a/_b/c/d task source path: e (this is a relative path of /a/_b/c/d/e) expect result: should work without any problem actual result: all file skipped.

suspect problem: in AsciidoctorAntTask.java, in method scanSourceFiles(), in above cases, the following code will not work

272 // stop when we hit the source directory root 273 if (absoluteSourceDirectory.equals(f.getAbsolutePath())) { 274 break; 275 }

the reason: the "absoluteSourceDirectory" is the relative source path which is passed in as a parameter of ant task, it will never match f.getAbsolutePath(), so the scan will not stop when hit the source path, and keep scanning to its parent directories, and if there is a pararent directory name start with a "_"(underscore), the scan will skip all files(this is unexpected). Even worse in case 1, since in cygwin, the getAbsolutePath will restrun a path in windows format.

NOTE:

  1. the maven plugin did not have this problem, since it will covert the absoluteSourceDirectory to a File, then comapre the absolute path of the source directory File with the absolute path of a scaning file, this avoid above problem.
  2. even the variable name is "absoluteSourceDirectory", its value come from a parameter named "sourceDirectory".

That is why I think this is a bug, my suggetion is do the same thing as maven plugin did.

The workaround is using absolute path as task source directory parameter in above cases.

mojavelinux commented 8 years ago

if there is a pararent directory name start with a "_"(underscore), the scan will skip all files(this is unexpected).

The scanner should only skip a file or folder if the segment that begins with an underscore is inside the source directory. It should not consider segments of the path that are parents of the source directory.

FYI: In the Asciidoctor ecosystem, a leading underscore is consider a marker for a hidden file or folder (but, again, only if the segment is in the part of the path that is relative to the source directory).

mojavelinux commented 8 years ago

In general, I agree the Ant plugin should follow the same rules as the Maven & Gradle plugins for consistency.

steven-xing commented 8 years ago

Yes, I agree, Currently the problem is the "if" check for stop scanning into the parent directory of the source path did not work in some cases, such as relative path or Cygwin. I would suggest fix this by doing the same thing as Maven&Gradle plugins. Thanks for your quick response.

FYI: We are doing a work around currently in our ant build script, we detect and use "cygpath" if required to covert the path to a absolute windows path then set it into the soureDirectory parameter. This make our build script work in both cygwin and Linux. But, we still expect a fix in the asciidoctor-ant.

binout commented 7 years ago

Can you check if i can close the issue with this last commit ? cc @steven-xing

steven-xing commented 7 years ago

All looks good based on code reading. We have not tried use the 1.6 jar in our build env yet. I will do some test with the 1.6 jar this week in our load build env, and let you know the result.

Thanks,

steven-xing commented 7 years ago

I built the jar from latest 1.6.x source code, and tested in our load build environment, all good. I think you can close the issue.

binout commented 7 years ago

Ok nice ! thx