This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
When I switch to native Ruby which comes with Ubuntu, I can't create a Rails project. The error I get is: /bin/bash: -/: invalid option Usage: /bin/bash [GNU long option] [option] ... /bin/bash [GNU long option] [option] script-file ... GNU long options: --debug --debugger --dump-po-strings --dump-strings --help --init-file --login --noediting --noprofile --norc --posix --protected --rcfile --restricted --verbose --version --wordexp Shell options: -irsD or -c command or -O shopt_option (invocation only) -abefhkmnptuvxBCHP or -o option The problem is that /usr/bin/rails on Ubuntu is a bash script, not a Ruby script. Thus the Rails project cannot be created. I installed Ruby and Rails using apt-get. This happens with NetBeans 6.0 RC1, with versions: $ ruby -v ruby 1.8.6 (2007-06-07 patchlevel 36) [i486-linux] $ bash -version GNU bash, version 3.2.25(1)-release (i486-pc-linux-gnu) rails version 1.2.5. Tor suggested that this is probably a P1, so I file it as a P1. Attaching screenshot with the error.
Created attachment 53003 [details] Screenshot with the error
Created attachment 53004 [details] Screenshot - this time with correct mimetype
Fixed in trunk. I think this should be backported to 6.0. Martin, can you review the diffs? Jiri, do you agree to this as a 6.0 fix candidate? The root problem is that on Debian, they've hacked the "rails" script such that it's no longer a Ruby program (which it is everywhere else). For various reasons, we always want to run ruby programs like rake, spec and rails through the ruby interpreter (to for example fix I/O flushing), but this doesn't work when the program isn't actually a Ruby program! I had some logic in there to handle this before; it would look to see if you had a "gem" installation of Rails, and if not it would assume that you're running in a hacked Rails installation. That worked until recently when we started "finding" gems in nonstandard places on Ubuntu (like /var/lib/gems/1.8). The proper fix is not to look for a Rails gem, but to actually check the mime type of the Rails file! Our MIME resolver is capable of determining whether a script with no extension is a Ruby file - it scans the header. In my diff I also bump up the header size read, since that's necessary to recognize Ruby in "long" paths like this: #!/Users/tor/dev/ruby/install/ruby-1.8.5/bin/ruby\n (Diff against release60 attached as a separate patch) IDE:------------------------------------------------- IDE: [11/14/07 12:45 PM] Committing started Checking in editing/test/unit/src/org/netbeans/modules/ruby/RubyMimeResolverTest.java; /cvs/ruby/editing/test/unit/src/org/netbeans/modules/ruby/RubyMimeResolverTest.java,v <-- RubyMimeResolverTest.java new revision: 1.5; previous revision: 1.4 done Checking in railsprojects/src/org/netbeans/modules/ruby/railsprojects/RailsProjectGenerator.java; /cvs/ruby/railsprojects/src/org/netbeans/modules/ruby/railsprojects/RailsProjectGenerator.java,v <-- RailsProjectGenerator.java new revision: 1.16; previous revision: 1.15 done Checking in editing/src/org/netbeans/modules/ruby/RubyMimeResolver.java; /cvs/ruby/editing/src/org/netbeans/modules/ruby/RubyMimeResolver.java,v <-- RubyMimeResolver.java new revision: 1.3; previous revision: 1.2 done IDE: [11/14/07 12:45 PM] Committing finished
Created attachment 53009 [details] Merge trunk fix to release60 branch
This seems to brake cases where shebang line looks like: #!/space/ruby/ruby-1.8.6-p110/bin/ruby1.8.6-p110 RubyMimeResolver.isRubyHeader is quiet uneasy piece to read ;) But seems to be tested well. Would not suffice to have rather one or more regexps (for next 6.1+)? Or it is because of speed? Curious...
I verified the fix in http://deadlock.netbeans.org/hudson/job/ruby/5242. The fix still needs to be verified in 60 branch after commit.
I agree this is a 6.0 fix candidate.
Hi Martin, I've updated the Ruby mime resolver to be much more flexible (and simple). I used to only accept certain patterns - /usr/bin/env ruby, C:\program files\foo\ruby.exe, etc. I've now changed it such that it considers any file with a shebang line containing "ruby" as a Ruby file (provided the reference to Ruby is not followed by a / or a \ before the next space, e.g. #! /home/mynameisruby/bin/sh will not be considered a ruby file, but #!/foo/bar/foo-ruby1.8 will be. I will attach an updated patch. Since the header recognizer is completely different I added it in a different place in the file such that the diff simply shows the old method getting deleted and the new method getting added.
Created attachment 53089 [details] Updated patch
By the way, I've checked in the new version in the trunk so it can be tested there. I thought it was important to fix this aspect of the Ruby file recognizer since we're relying on it more for the Rails command now.
I'm OK with the last fix.
Seems that following shebang line does not pass: #!D:/Development/Ruby/ruby-1.8.6-dist/bin/ruby Jirka pointed to it, using Windows. Not sure if this worked before. Probably it did. Jirko?
Yes, it works with older builds.
I added that testcase to the unit tests. The problem was that the number of bytes read from the file header was too small (40) to be able to see the "ruby" command at the end of it. I doubled it. By the way, this scenario was also broken with the old ruby mime resolver - files with that shebang line would not get recognized as Ruby files. Of course, what's new here is that we now need the correct result for the "rails" script. However, note that it's not a catastrophe if the rails command is not recognized as a Ruby program; what will happen then is that the command will not be run through the ruby interpreter, so output flushing will not work - nothing will be printed in the output window until the command is done. That's a fatal problem when running user programs (which may be waiting for input without printing the prompt), but not fatal problem for a noninteractive short program like the rails command (which just creates the project structure and then exits). Martin, the only change to the diff is this: - static final int HEADER_LENGTH = 40; + static final int HEADER_LENGTH = 80; Fixed in trunk: IDE:------------------------------------------------- IDE: [11/16/07 7:37 AM] Committing started Checking in test/unit/src/org/netbeans/modules/ruby/RubyMimeResolverTest.java; /cvs/ruby/editing/test/unit/src/org/netbeans/modules/ruby/RubyMimeResolverTest.java,v <-- RubyMimeResolverTest.java new revision: 1.8; previous revision: 1.7 done Checking in src/org/netbeans/modules/ruby/RubyMimeResolver.java; /cvs/ruby/editing/src/org/netbeans/modules/ruby/RubyMimeResolver.java,v <-- RubyMimeResolver.java new revision: 1.5; previous revision: 1.4 done IDE: [11/16/07 7:37 AM] Committing finished
(You can test what happens in the case where the Rails command is not recognized as ruby by renaming your Ruby interpreter "rubee" and updating the Rails script to point to it.)
> Martin, the only change to the diff is this: > > - static final int HEADER_LENGTH = 40; > + static final int HEADER_LENGTH = 80; Which waits for the more or less the same issue to be filed. Why not to do something like (pseudo-code): if (readTwoFirstChars is not '#!') not shebang else read gradually e.g. first 500 chars, until giving up Current algorithm reads always all HEADER_LENGHT chars but 80 seems to me still on the edge. We can't (or do not want to) change it to e.g. 500 due to performance reasons if I understand it correctly. So changing the algorithm to above would solve it. Would be quicker then the current and more bullet-proof. I agree, that for 6.0 current one is sufficient.
Verified in trunk.
Be sure to ask pnejedly for advice on best writing MIMEResolver impls which scan file contents, as this is a subject he knows most about.
Merged to release60. Checking in railsprojects/src/org/netbeans/modules/ruby/railsprojects/RailsProjectGenerator.java; /cvs/ruby/railsprojects/src/org/netbeans/modules/ruby/railsprojects/RailsProjectGenerator.java,v <-- RailsProjectGenerator.java new revision: 1.14.2.1; previous revision: 1.14 done Checking in editing/src/org/netbeans/modules/ruby/RubyMimeResolver.java; /cvs/ruby/editing/src/org/netbeans/modules/ruby/RubyMimeResolver.java,v <-- RubyMimeResolver.java new revision: 1.2.4.1; previous revision: 1.2 done Checking in editing/test/unit/src/org/netbeans/modules/ruby/RubyMimeResolverTest.java; /cvs/ruby/editing/test/unit/src/org/netbeans/modules/ruby/RubyMimeResolverTest.java,v <-- RubyMimeResolverTest.java new revision: 1.4.4.1; previous revision: 1.4 done
Verified in 6.0.