I’m trying to write a simple Maven plugin for my team that will call
compass and convert out sass to css in our automated build. I’ve spent
several days going through many of the articles and help requests, but I
still haven’t been able to get things working.
I used Nick Seiger’s article to build a JRuby (1.5.6.1) with compass and
all dependencies:
http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar
$ java -jar jruby-complete-1.6.5.1.jar -S gem install -i ./compass
compass
$ jar uf jruby-complete-1.6.5.1.jar -C compass.
$ mv jruby-complete-1.6.5.1.jar compass-0.12.alpha.4.jar
$ java -jar compass-0.12.alpha.4.jar -S compass compile
$ jruby: No such file or directory – compass (LoadError)
The first problem is that the command line doesn’t even work. I get the
following error:
$ jruby: No such file or directory – compass (LoadError)
The second problem is that I eventually got the scripts to run from
within
my Java program, but I get errors that I don’t see when run compass on
the
command line (I have Ruby installed). Here is basically all of the code
for the Maven Mojo:
String myPath =
CompassMavenMojo.class.getProtectionDomain().getCodeSource().getLocation().toExternalForm();
System.out.println(“Path: " + myPath);
String command = String.format(”%s!/bin/start.rb", myPath);
System.out.println("Command: " + command);
org.jruby.Main.main(new String[]{command,“compile”, configLocation});
The start.rb script is in the Mojo project and gets distributed with the
jar. The configLocation variable is a Mojo parameter and is passed in.
It’s the directory where the config.rb file resides. I have a
dependency
on the JRuby complete compass-0.12.alpha.4.jar that I build, so all of
the
JRuby files and the gems reside in that JAR. Here are the contents of
start.rb:
begin
ENV[‘GEM_HOME’] ||= File.expand_path(‘…/gems’, FILE)
require ‘rubygems’
$LOAD_PATH.unshift FILE.sub(/!.*/,
‘!/gems/compass-0.12.alpha.4/lib’)
load ‘gems/compass-0.12.alpha.4/bin/compass’
0
rescue SystemExit => e
e.status
end
It’s actually a file that was generated by Warbler (something else I
tried
that didn’t work), but modified by me. When I install my maven plugin
and
then run a build from the project that uses the plugin I get errors like
this:
Path:
file:/C:/Users/Tony/.m2/repository/com/codeworkslp/compass-maven-plugin/1.0/compass-maven-plugin-1.0.jar
Command:
file:/C:/Users/Tony/.m2/repository/com/codeworkslp/compass-maven-plugin/1.0/compass-maven-plugin-1.0.jar!/bin/start.rb
{:sass=>{:load_paths=>[#<Sass::Importers::Filesystem:0x5fe1153a
@root=“C:/Users/Tony/workspaces/ADT/SelfService/self-service/src/main/webapp/sass”>,
#<Sass::Importers::Filesystem:0x465863 @root=“file:
C:/Users/Tony/.m2/repository/org/jruby/compass/0.12.alpha.4/compass-0.12.alpha.4.jar!/gems/compass-0.12.alpha.4/frameworks/blueprint/stylesheets”>,
#<Sass::Importers::Filesystem:0xa54cbb9 @root=“file:
C:/Users/Tony/.m2/repository/org/jruby/compass/0.12.alpha.4/compass-0.12.alpha.4.jar!/gems/compass-0.12.alpha.4/frameworks/compass/stylesheets”>,
Compass::SpriteImporter], :style=>:compact, :line_comm
ents=>true, :cache=>true,
:cache_location=>“C:\Users\Tony\workspaces\ADT\SelfService\self-service\src\main\webapp/.sass-cache”},
:project_name=>“C:\Users\Tony\workspaces\ADT\SelfService
\self-service\src\main\webapp”, :sass_files=>nil,
:cache_location=>“C:\Users\Tony\workspaces\ADT\SelfService\self-service\src\main\webapp/.sass-cache”}
error src/main/webapp/sass/alarm_contacts.sass (Line 1: File to
import not found or unreadable: compass.
Load paths:
C:/Users/Tony/workspaces/ADT/SelfService/self-service/src/main/webapp/sass
file:C:/Users/Tony/.m2/repository/org/jruby/compass/0.12.alpha.4/compass-0.12.alpha.4.jar!/gems/compass-0.12.alpha.4/frameworks/blueprint/stylesheets
file:C:/Users/Tony/.m2/repository/org/jruby/compass/0.12.alpha.4/compass-0.12.alpha.4.jar!/gems/compass-0.12.alpha.4/frameworks/compass/stylesheets
Compass::SpriteImporter)
overwrite alarm_contacts.css
error src/main/webapp/sass/alarm_dashboard.sass (Line 1: File to
import not found or unreadable: compass.
…and so on, repeating from “Load Paths” for each SASS file processed.
I
realize I’m using an alpha build, but I had this exact problem with
0.11.7,
so that’s not the issue. Also, when I run compass from the command line
(Ruby, not JRuby), it works brilliantly. Like I said, I’ve tried
everything I could find on how to do this including using
ScriptContainer.java, but I end up with the same error. Also, when I
used
Warbler to build an executable jar it also gives me the same output.
I’m
not a Ruby developer, so I don’t know what I’m doing wrong. Any help
would
be appreciated.
Thanks,
Tony