asciidoctor / asciidoctor-ant

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

Unexpected result from using baseDir #72

Open dballardgh opened 6 years ago

dballardgh commented 6 years ago

Environment

I've set up a directory structure as:

build.xml
lib\asciidoctor-ant.jar
src\asciidoc\hello.ad
src\asciidoc\examples\myexample.ad
target

Scenario 1:

My hello.ad has include::src/asciidoc/examples/myexample.ad[].

My build.xml convert statement is:

<asciidoctor:convert sourceDirectory="src/asciidoc" sourceDocumentName="hello.ad" outputDirectory="target" backend="html5"/>

Running the convert:

F:\sandbox\asciidoctor-test>ant doc
Buildfile: F:\sandbox\asciidoctor-test\build.xml

doc:
[asciidoctor:convert] Render hello.ad from src/asciidoc to target with backend=html5

This works as expected and results in target/hello.html with included content.

Scenario 2:

My hello.ad has include::examples/myexample.ad[].

Same convert configuration:

<asciidoctor:convert sourceDirectory="src/asciidoc" sourceDocumentName="hello.ad" outputDirectory="target" backend="html5"/>
F:\sandbox\asciidoctor-test>ant doc
Buildfile: F:\sandbox\asciidoctor-test\build.xml

doc:
[asciidoctor:convert] Render hello.ad from src/asciidoc to target with backend=html5
asciidoctor: WARNING: hello.ad: line 16: include file not found: F:/sandbox/asciidoctor-test/examples/myexample.ad

This logs a WARNING as expected, and creates target/hello.html with missing include.

Scenario 3 (PROBLEM):

To allow the include to be found, I add baseDir to my convert statement:

<asciidoctor:convert sourceDirectory="src/asciidoc" sourceDocumentName="hello.ad" outputDirectory="target" backend="html5" baseDir="src/asciidoc"/>
F:\sandbox\asciidoctor-test>ant doc
Buildfile: F:\sandbox\asciidoctor-test\build.xml

doc:
[asciidoctor:convert] Render hello.ad from src/asciidoc to target with backend=html5

This appears to work as expected, with no WARNING. However the target directory is empty and the hello.html output file was created in the src directory as:

F:\sandbox\asciidoctor-test\src\asciidoc\sandbox\asciidoctor-test\target\hello.html

It does contain the expected include content. So it would appear that the actual output directory is the fully resolved baseDir plus the fully resolved outputDirectory. I would expect baseDir not to affect the output directory.

asciidoctor-ant test cases

I cloned the current https://github.com/asciidoctor/asciidoctor-ant.git and ran a mvn test. All 12 of the tests failed, some of which had the same target path problems as described above. So this may be a problem specific to running the convert on windows.

Please let me know if I can provide additional information.

abelsromero commented 6 years ago

Hi,

Just to provide more insights, I run on Windows 10 and only 1 test failed for me, and it is indeed the one related to basedir.

Results :

Failed tests:   should_manage_relativebasedir(org.asciidoctor.ant.AsciidoctorAntTaskTest): (..)

Tests run: 12, Failures: 1, Errors: 0, Skipped: 0
dballardgh commented 6 years ago

Just a quick followup. When I clone to drive c: and run the tests, I recreate @abelsromero's results with 12 run, 1 failure.

When I clone to drive f: and run the tests, all 12 tests fail. In all cases, the test case cannot find the output files. The reason is that the tests are looking for the output files relative to junit's TemporaryFolder (which looks like is based on window's TEMP variable) on drive c::

C:\Users\dballard\AppData\Local\Temp\junit4654498160491557855\asciidoctor-twitter\twitter.html

However, asciidoctor is putting the output on current drive f::

F:\Users\dballard\AppData\Local\Temp\junit4654498160491557855\asciidoctor-twitter\twitter.html

I think this has something to do with asciidoctor's SAFE mode. I haven't quite figured out the semantics of SAFE mode yet. I did go into the ANT task and changed the safe mode to UNSAFE as a test, and the problem disappears. The files are created on c: as expected. Also as a test, changing TemporaryFolder() to TemporaryFolder(new File("f:/tmp")) corrected this problem, leaving only the originally reported baseDir issue.

binout commented 5 years ago

Can you try again ? I think it's fixed with 1.5.8 release 🤞

dballardgh commented 5 years ago

Hi @binout,

Currently on Win 10. I cloned the current tree and ran "mvn test". The compile is successful, but all of the tests fail with safe-mode problems such as:

SEVERE: (SecurityError) to_dir C:\Users\david\AppData\Local\Temp\junit3183025117078637188\asciidoctor is outside of jail: C:/ (disallowed in safe mode)

Perhaps this test output could be written to "target" rather than $TEMP?

Regards, Dave