#!/usr/bin/env ruby require 'maven/jetty/ruby_maven' require 'thor' class JettyCommand < Thor no_tasks do def mvn @mvn ||= Maven::Jetty::RubyMaven.new end def exec(*args) ARGV.clear # clean up in case another script gets executed mvn.exec(args) end end desc "[run]", "runs jetty with a rails filesystem layout" method_option :environment, :aliases => '-e', :type => :string, :required => false, :desc => 'rails environment' method_option :port, :type => :numeric, :default => 8080, :desc => 'http port' method_option :sslport, :type => :numeric, :default => 8443, :desc => 'https port' def server(*args) args = ARGV.dup args.delete('server') if i = args.index("--") maven_args = args[i..-1] end maven_args ||= [] maven_args << "-Drails.env=#{options[:environment]}" if options[:environment] maven_args << "-Djetty.port=#{options[:port]}" maven_args << "-Djetty.sslport=#{options[:sslport]}" exec(*(["jetty:run", "-Prun"] + maven_args)) end desc "war WARFILE", "runs jetty with a given warfile" method_option :port, :type => :numeric, :default => 8080, :desc => 'http port' method_option :sslport, :type => :numeric, :default => 8443, :desc => 'https port' def war(file, *args) args = ARGV.dup if i = args.index("--") maven_args = args[i..-1] end maven_args ||= [] maven_args << "-Djetty.war=#{file}" maven_args << "-Djetty.port=#{options[:port]}" maven_args << "-Djetty.sslport=#{options[:sslport]}" exec(*(["jetty:deploy-war", "-Pwar"] + maven_args)) end desc "pom", "dump the pom used into pom.xml" method_option :force, :type => :boolean, :default => false, :desc => 'force to overwrite pom.xml' def pom(*args) if File.exists?('pom.xml') && !options[:force] warn "abort. pom.xml already exist. use --force to overwrite" else mvn.dump_pom(options[:force]) end end def help(*args) super(*args) goal = case args[0] when 'server' 'run' when 'war' 'deploy-war' end # TODO not sure whether or not these options are needed/helpful # if goal # puts # puts "Maven Options: (from jetty maven plugin)" # exec ["jetty:help", "-Ddetail=true", "-Dgoal=#{goal}"] # end end end if i = ARGV.index('run') ARGV[i] = 'server' end #p ARGV.detect {|a| p a ;a =~ /^[a-z]/ } unless ARGV[0] =~ /^[a-z]/ ARGV.insert(0, 'server') end JettyCommand.start