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.

Bug 121936 - Cannot create Rails project on Ubuntu 7.10
Summary: Cannot create Rails project on Ubuntu 7.10
Status: VERIFIED FIXED
Alias: None
Product: ruby
Classification: Unclassified
Component: Rails (show other bugs)
Version: 6.x
Hardware: All Linux
: P1 blocker (vote)
Assignee: Torbjorn Norbye
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-14 19:40 UTC by Roman Strobl
Modified: 2007-11-19 12:04 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Screenshot with the error (82.20 KB, text/plain)
2007-11-14 19:42 UTC, Roman Strobl
Details
Screenshot - this time with correct mimetype (82.20 KB, image/png)
2007-11-14 20:04 UTC, Roman Strobl
Details
Merge trunk fix to release60 branch (2.32 KB, patch)
2007-11-14 20:52 UTC, Torbjorn Norbye
Details | Diff
Updated patch (7.83 KB, patch)
2007-11-16 00:07 UTC, Torbjorn Norbye
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Roman Strobl 2007-11-14 19:40:17 UTC
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.
Comment 1 Roman Strobl 2007-11-14 19:42:18 UTC
Created attachment 53003 [details]
Screenshot with the error
Comment 2 Roman Strobl 2007-11-14 20:04:30 UTC
Created attachment 53004 [details]
Screenshot - this time with correct mimetype
Comment 3 Torbjorn Norbye 2007-11-14 20:50:41 UTC
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
Comment 4 Torbjorn Norbye 2007-11-14 20:52:27 UTC
Created attachment 53009 [details]
Merge trunk fix to release60 branch
Comment 5 Martin Krauskopf 2007-11-15 09:29:35 UTC
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...
Comment 6 Roman Strobl 2007-11-15 10:50:10 UTC
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.
Comment 7 Jiri Skrivanek 2007-11-15 10:52:03 UTC
I agree this is a 6.0 fix candidate.
Comment 8 Torbjorn Norbye 2007-11-16 00:05:34 UTC
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.
Comment 9 Torbjorn Norbye 2007-11-16 00:07:00 UTC
Created attachment 53089 [details]
Updated patch
Comment 10 Torbjorn Norbye 2007-11-16 00:08:01 UTC
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.
Comment 11 Martin Krauskopf 2007-11-16 08:08:32 UTC
I'm OK with the last fix.
Comment 12 Martin Krauskopf 2007-11-16 09:28:34 UTC
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?
Comment 13 Jiri Skrivanek 2007-11-16 09:44:10 UTC
Yes, it works with older builds.
Comment 14 Torbjorn Norbye 2007-11-16 15:50:54 UTC
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
Comment 15 Torbjorn Norbye 2007-11-16 15:54:38 UTC
(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.)
Comment 16 Martin Krauskopf 2007-11-16 16:07:53 UTC
> 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.
Comment 17 Jiri Skrivanek 2007-11-16 18:34:55 UTC
Verified in trunk.
Comment 18 Jesse Glick 2007-11-16 20:47:21 UTC
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.
Comment 19 Torbjorn Norbye 2007-11-17 17:14:06 UTC
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
Comment 20 Jiri Skrivanek 2007-11-19 12:04:07 UTC
Verified in 6.0.