Bug 42616 - fop bash script still broken under cygwin when current dir has spaces
Summary: fop bash script still broken under cygwin when current dir has spaces
Status: CLOSED WONTFIX
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: general (show other bugs)
Version: 0.94
Hardware: Other other
: P2 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
: 43704 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-06-08 05:18 UTC by Richard Wheeldon
Modified: 2012-04-30 00:17 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Wheeldon 2007-06-08 05:18:16 UTC
e.g :

richard@birkenhead /cygdrive/c/Documents and Settings/richard/IdeaProjects/Apach
e FOP $ ./fop -awt examples/fo/basic/readme.fo

produces the following:

cygpath: error converting "FOP/lib/*.jar:Settings/richard/IdeaProjects/Apache:an
d:/cygdrive/c/Documents:/cygdrive/c/Documents and Settings/richard/IdeaProjects/
Apache FOP/build/fop.jar:/cygdrive/c/Documents and Settings/richard/IdeaProjects
/Apache FOP/build/fop-sandbox.jar:/cygdrive/c/Documents and Settings/richard/Ide
aProjects/Apache FOP/build/fop-hyph.jar:/cygdrive/f/geolog/trunk/geolog/src" - U
nknown error 4294967295
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/fop/cli/Ma
in

This affects the current trunk.

Related bugs are:
40583     Under Cygwin, fop bash script CLASSPATH problem 
  http://issues.apache.org/bugzilla/show_bug.cgi?id=40583
21070     ClassPath with spaces cause undefined class errors
  http://issues.apache.org/bugzilla/show_bug.cgi?id=21070
Comment 1 Simon Pepping 2007-06-11 11:16:01 UTC
The problem may be due to this part:

DIRLIBS=${FOP_HOME}/lib/*.jar
for i in ${DIRLIBS}

I have no idea how to solve it, even on Linux. ${FOP_HOME}/lib/*.jar simply is
not expanded when it contains one or more spaces, even when quoted or when the
spaces are escaped. The for loop is even worse. Even if DIRLIBS would be
properly set, it seems impossible to obtain a correct word splitting in the for
loop when each separate path element contains spaces.

Bug 40583 is not really related. It addresses another problem, one which is
specific for Cygwin.

Comment 2 Arno Peters 2007-06-12 00:19:53 UTC
To avoid splitting arguments on spaces, set IFS to newline at the beginning of
the script like so:

  export IFS=$'\n'

Please try this and report your findings.
Comment 3 Richard Wheeldon 2007-06-28 08:26:46 UTC
Spaces are not the whole of the problem:

The following works:

richard@birkenhead /cygdrive/f/dir with spaces/fop-head/xml-fop
$ ./fop -awt ./examples/fo/basic/simple.fo > foo 2>&1


The following doesn't:

richard@birkenhead /cygdrive/f/dir with spaces/fop-head/xml-fop
$ cd ../

richard@birkenhead /cygdrive/f/dir with spaces/fop-head
$ mv xml-fop xml\ fop

richard@birkenhead /cygdrive/f/dir with spaces/fop-head
$ cd xml\ fop/

richard@birkenhead /cygdrive/f/dir with spaces/fop-head/xml fop
$ !./f
./fop -awt ./examples/fo/basic/simple.fo > foo 2>&1

richard@birkenhead /cygdrive/f/dir with spaces/fop-head/xml fop
$ cat ./foo
cygpath: error converting "fop/lib/*.jar:spaces/fop-head/xml:with:/cygdrive/f/di
r:/cygdrive/f/dir with spaces/fop-head/xml fop/build/fop.jar:/cygdrive/f/dir wit
h spaces/fop-head/xml fop/build/fop-sandbox.jar:/cygdrive/f/dir with spaces/fop-
head/xml fop/build/fop-hyph.jar:/cygdrive/f/geolog/trunk/geolog/src" - Unknown e
rror 4294967295
java.lang.NoClassDefFoundError: org/apache/fop/cli/Main
Exception in thread "main"
richard@birkenhead /cygdrive/f/dir with spaces/fop-head/xml fop
$
Comment 4 Richard Wheeldon 2007-06-28 08:28:15 UTC
export IFS=$'\n'

Adding this just after the opening comments fixes the problem under Linux and 
Cygwin.
Comment 5 Simon Pepping 2007-06-29 10:41:02 UTC
Applied the fix in the form:

export IFS="
"

because I feared that $'\n' is specific for bash. Thanks for the suggestion and
the testing. See revision 551972.
Comment 6 Alfred Nathaniel 2007-10-22 07:36:47 UTC
http://svn.apache.org/viewvc?view=rev&revision=551972 breaks the 0.94 fop 
script on Solaris where /bin/sh is a plain-vanilla Bourne shell.

The assigment should be written as:

IFS="
"
export IFS
Comment 7 Simon Pepping 2007-10-22 12:11:56 UTC
Fixed in revision 587204. I removed the export statement because it is not needed.
Comment 8 Alfred Nathaniel 2007-10-29 07:41:04 UTC
*** Bug 43704 has been marked as a duplicate of this bug. ***
Comment 9 Alfred Nathaniel 2007-10-29 07:48:31 UTC
The IFS assignment has to be removed altogether.  In Bourne shell it means that

fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf

is interpreted as

fop "-xml foo.xml -xsl foo.xsl -pdf foo.pdf"

which produces for basically all commandlines:

java.lang.IllegalArgumentException: Error creating InputHandler object.
        at org.apache.fop.cli.CommandLineOptions.createInputHandler
(CommandLineOptions.java:818)
        at org.apache.fop.cli.CommandLineOptions.parse
(CommandLineOptions.java:165)
        at org.apache.fop.cli.Main.startFOP(Main.java:154)
        at org.apache.fop.cli.Main.main(Main.java:197)

Workaround (provided bash is installed): invoke fop script explicitly as bash 
script instead of implicit #!/bin/sh

$ bash fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf
Comment 10 Simon Pepping 2007-10-29 12:23:59 UTC
(In reply to comment #9)
> The IFS assignment has to be removed altogether.  In Bourne shell it means that
> 
> fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf
> 
> is interpreted as
> 
> fop "-xml foo.xml -xsl foo.xsl -pdf foo.pdf"

Can you explain? I do not see such a thing happen:
$ /fop/fop --execdebug -xml foo.xml -xsl foo.xsl -pdf foo.pdf
exec "/usr/lib/jvm/java-1.5.0-sun/bin/java" -classpath
"/fop/lib/xmlgraphics-commons-1.3svn.jar:/fop/lib/xml-apis-1.3.02.jar:/fop/lib/xercesImpl-2.7.1.jar:/fop/lib/xalan-2.7.0.jar:/fop/lib/servlet-2.2.jar:/fop/lib/serializer-2.7.0.jar:/fop/lib/fop-hyph.jar:/fop/lib/commons-logging-1.0.4.jar:/fop/lib/commons-io-1.3.1.jar:/fop/lib/batik-all-1.6.jar:/fop/lib/avalon-framework-4.2.0.jar:/fop/build/fop.jar:/fop/build/fop-sandbox.jar:/fop/build/fop-hyph.jar"
org.apache.fop.cli.Main "-xml" "foo.xml" "-xsl" "foo.xsl" "-pdf" "foo.pdf"
Comment 11 Peter West 2007-10-29 18:40:57 UTC
Try

OLD_IFS=$IFS
IFS="
"
find ${FOP}/lib -name -name '*.jar'|while read jarfile
do
      if [ -z "$LOCALCLASSPATH" ] ; then
        LOCALCLASSPATH="$jarfile"
      else
        LOCALCLASSPATH="$jarfile"${pathSepChar}$LOCALCLASSPATH
      fi
done
IFS=$OLD_IFS


I don't know how the CLASSPATH reacts to spaces. If there's a problem, the
assignments to LOCALCALSSPATH will have to have the spaces escaped.
Comment 12 Simon Pepping 2007-10-30 13:32:33 UTC
(In reply to comment #11)
> Try
> 
> OLD_IFS=$IFS
> IFS="
> "
> find ${FOP}/lib -name -name '*.jar'|while read jarfile
> do
>       if [ -z "$LOCALCLASSPATH" ] ; then
>         LOCALCLASSPATH="$jarfile"
>       else
>         LOCALCLASSPATH="$jarfile"${pathSepChar}$LOCALCLASSPATH
>       fi
> done
> IFS=$OLD_IFS
> 
find "${FOP}/lib" -name '*.jar'|while read jarfile
do
      if [ -z "$LOCALCLASSPATH" ] ; then
        LOCALCLASSPATH=$jarfile
      else
        LOCALCLASSPATH=$jarfile${pathSepChar}$LOCALCLASSPATH
      fi
done

would be almost perfect, and avoid the need for the change of IFS, except that
the call to find places the whole while loop in a subshell, and updates of
LOCALCLASSPATH are lost when it returns.

Comment 13 Peter West 2007-10-30 22:05:17 UTC
I forgot that everything in the line would be assigned to the variable, and I
forgot that the pipeline would be executed in a subshell.

So how about

JARPATH=$(SEP="";find ${FOP}/lib -name '*.jar'|\
while read jarfile;do echo -n $SEP"$jarfile"; SEP=${pathSepChar}; done)

if [ -z "$LOCALCLASSPATH" ] ; then
    LOCALCLASSPATH="$JARPATH"
else
    LOCALCLASSPATH="$JARPATH"${pathSepChar}$LOCALCLASSPATH
fi
Comment 14 Simon Pepping 2007-10-31 13:07:09 UTC
(In reply to comment #13)
> So how about
> 
> JARPATH=$(SEP="";find ${FOP}/lib -name '*.jar'|\
> while read jarfile;do echo -n $SEP"$jarfile"; SEP=${pathSepChar}; done)
> 
> if [ -z "$LOCALCLASSPATH" ] ; then
>     LOCALCLASSPATH="$JARPATH"
> else
>     LOCALCLASSPATH="$JARPATH"${pathSepChar}$LOCALCLASSPATH
> fi
> 
Excellent. But keep it simple and use =`...` instead of =$(...) (is this a
bashism?). Then the following should replace the libs section in the fop script:

# add in the dependency .jar files, which reside in $FOP_HOME/lib
if [ -z "$LOCALCLASSPATH" ] ; then
  SEP=""
else
  SEP="${pathSepChar}"
fi
LOCALCLASSPATH=${LOCALCLASSPATH}`find "${FOP_HOME}/lib" -name '*.jar' \
  | while read jarfile
do
  echo -n "$SEP$jarfile"
  SEP="${pathSepChar}"
done`

Note, however, that the complaint with which this bug was reopened, has never
been validated; see comments #9 and #10. So one may argue that this solution is
not sufficiently better to warrant being committed. I think it is, because it
removes the fiddling with IFS and the parsing of a list of libs.
Comment 15 Peter West 2007-10-31 22:56:00 UTC
$(...) is posix-preferred, I believe.
Comment 16 Glenn Adams 2012-04-01 19:21:52 UTC
if this problem still exists in current trunk (FOP1.0 or later), then submit a new bug
Comment 17 Glenn Adams 2012-04-30 00:14:39 UTC
batch transition resolved+wontfix to closed+wontfix
Comment 18 Glenn Adams 2012-04-30 00:17:08 UTC
batch transition resolved+wontfix to closed+wontfix; if you believe this remains a bug and can demonstrate it with appropriate input FO file and output PDF file (as applicable), then you may reopen