Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get to run on windows #78

Closed
chanibal opened this issue Sep 10, 2015 · 13 comments
Closed

Can't get to run on windows #78

chanibal opened this issue Sep 10, 2015 · 13 comments

Comments

@chanibal
Copy link
Contributor

Just tried to install on windows+cygwin, but can't get it to work. I'm not sure if this is my instalation problem or i have found a bug.

My instalation procedure (from cygwin prompt):

$ apt-cyg install graphviz
$ apt-cyg install rubygems
$ gem install ascii-doctor-diagram
$ cd my-project-dir
$ asciidoctor -r asciidoctor-diagram Test.adoc
Error: Could not find or load main class org.asciidoctor.diagram.CommandServer
asciidoctor-diagram: ERROR: Failed to generate image: end of file reached
$ cd ~/.gem/ruby/gems/asciidoctor-diagram-1.3.0/examples
$ asciidoctor -r asciidoctor-diagram -I ../lib design.adoc
Error: Could not find or load main class org.asciidoctor.diagram.CommandServer
asciidoctor-diagram: ERROR: Failed to generate image: end of file reached
Error: Could not find or load main class org.asciidoctor.diagram.CommandServer
asciidoctor-diagram: ERROR: Failed to generate image: end of file reached

My version is:

$ gem list

*** LOCAL GEMS ***

asciidoctor (1.5.2)
asciidoctor-diagram (1.3.0)
json (1.8.2)
minitest (5.4.3)
power_assert (0.2.2)
rake (10.4.2)
rdoc (4.2.0)
test-unit (3.0.8)
@mojavelinux
Copy link
Member

Seems like it isn't finding the bundled Asciidoctor Diagram jar file that provides the server.

Could you show the output of the following command?

gem which asciidoctor-diagram

The tests do pass on Windows (see https://ci.appveyor.com/project/asciidoctor/asciidoctor-diagram). I wonder if this scenario is not covered, though.

@chanibal
Copy link
Contributor Author

$ gem which asciidoctor-diagram 
/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/asciidoctor-diagram.rb

Maybe this is because of my not so standard setup? This is windows 10 + cygwin (current stable). Most things seem to work, though.

@chanibal
Copy link
Contributor Author

Can't run this on cmd at this moment (did not install bats in %USERDIR%/bin, just bash).

@mojavelinux
Copy link
Member

Can't run this on cmd at this moment (did not install bats in %USERDIR%/bin, just bash).

That could very well be the problem. Most issues with running Ruby programs tends to be that the OS doesn't setup the binstubs or PATH correctly. (One of Ruby's biggest downfalls is that OS vendors totally screw up the environment by default, which is why I always, always, always use RVM...which does work on Cygwin btw).

@pepijnve
Copy link
Member

@chanibal if you could try out some patches it might be easier to get to the bottom of this. asciidoctor-diagram locates its jar files, but doesn't really validate if they exist or not. See https://github.com/asciidoctor/asciidoctor-diagram/blob/master/lib/asciidoctor-diagram/util/java.rb#L6 for an example. Most likely an incorrect path is being constructed and being passed to the JVM.

Could you insert puts args at https://github.com/asciidoctor/asciidoctor-diagram/blob/master/lib/asciidoctor-diagram/util/java_socket.rb#L18 locally on your machine? The output of that should already give an idea of why/how the classpath is incorrect.

@chanibal
Copy link
Contributor Author

Output with args:

ARGS:
-Djava.awt.headless=true
-cp
/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/asciidoctor-diagram-java-1.3.4.jar:/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/ditaamini-0.10.jar:/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/plantuml.jar
org.asciidoctor.diagram.CommandServer
Error: Could not find or load main class org.asciidoctor.diagram.CommandServer
asciidoctor-diagram: ERROR: Failed to generate image: end of file reached

Files mentioned exist

$ file /home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/asciidoctor-diagram-java-1.3.4.jar
/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/asciidoctor-diagram-java-1.3.4.jar: Zip archive data, at least v1.0 to extract

$ file /home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/ditaamini-0.10.jar
/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/ditaamini-0.10.jar: Zip archive data, at least v1.0 to extract

$ file /home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/plantuml.jar
/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/plantuml.jar: Java archive data (JAR)

@pepijnve
Copy link
Member

@chanibal thanks for that. So the ditaa jar is missing for some reason. That's why you're getting the Could not find or load main class org.asciidoctor.diagram.CommandServer error. The CommandServer class indirectly has dependencies on classes in the ditaa jar and if that's not present then CommandServer won't be loadable.

There are two things that can be done here:

  • Make the CommandServer class a bit more modular and load the plantuml and ditaa source code using reflection. That way error reporting will be more precies (e.g. something like 'Ditaa missing') and it will be possible to degrade more gracefully.
  • Figure out why the ditaa jar wasn't installed on your system. Honestly I have no idea how this could happen. I downloaded the gem file from rubygems.org and extracted it to check the contents. ditaamini-0.10.jar is in there as it should be. Perhaps you could try doing a reinstall of the gem?

@pepijnve
Copy link
Member

Double checked the metadata in the gem file as well. lib/ditaamini-0.10.jar is listed in there as well so there's really no reason why it shouldn't be present after installing. Bizarre...

@mojavelinux have you ever seen something like this happen?

@chanibal
Copy link
Contributor Author

@pepijnve, I do have dittamini, look at my comment again. I have made a copy-paste error before and edited my comment to fix this within a minute of posting, but you were faster to read it, I guess.

@pepijnve
Copy link
Member

Yep when I read your comment it said no such file for ditaa :)
Looking at the output again it dawned on me what's wrong. You're running on windows with the windows version of the JVM which expects ; as path separator in the -cp argument but since Ruby is running under Cygwin the File::PATH_SEPARATOR is set to : and the asciidoctor-diagram code is constructing the -cp argument value with that.
The code probably needs a special case for Cygwin to handle this. You might be able to override the path separator using an environment variable (but I'm not sure if you can). That might end up causing problems elsewhere of course.

@pepijnve
Copy link
Member

@chanibal if you have some more time to test this, could you try replacing File::PATH_SEPARATOR with ';'at https://github.com/asciidoctor/asciidoctor-diagram/blob/master/lib/asciidoctor-diagram/util/java_socket.rb#L16. If that works, then my hunch is confirmed and I'll add the special cygwin case and make a 1.3.1 build asap.

chanibal added a commit to chanibal/asciidoctor-diagram that referenced this issue Sep 16, 2015
@chanibal
Copy link
Contributor Author

Changed File::PATH_SEPARATOR to ";":

$ asciidoctor -r asciidoctor-diagram Test.adoc
ARGS:
-Djava.awt.headless=true
-cp
/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/asciidoctor-diagram-java-1.3.4.jar;/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/ditaamini-0.10.jar;/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/plantuml.jar
org.asciidoctor.diagram.CommandServer
Error: Could not find or load main class org.asciidoctor.diagram.CommandServer
asciidoctor-diagram: ERROR: Failed to generate image: end of file reached

Just to be sure, from the command line nothing changes:

$ java -Djava.awt.headless=true -cp /home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/asciidoctor-diagram-java-1.3.4.jar:/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/ditaamini-0.10.jar:/home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/plantuml.jar org.asciidoctor.diagram.CommandServer
Error: Could not find or load main class org.asciidoctor.diagram.CommandServer

But this thing works:

 java -Djava.awt.headless=true -cp "$(cygpath -w /home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/asciidoctor-diagram-java-1.3.4.jar);$(cygpath -w /home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/ditaamini-0.10.jar);$(cygpath -w /home/chanibal/.gem/ruby/gems/asciidoctor-diagram-1.3.0/lib/plantuml.jar)" org.asciidoctor.diagram.CommandServer
50136

Adding pull request. Please review it, my first ever code in ruby so it might have problems

chanibal added a commit to chanibal/asciidoctor-diagram that referenced this issue Sep 16, 2015
@mojavelinux
Copy link
Member

👍

pepijnve added a commit that referenced this issue Sep 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants