Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactorng to follow ruby-maven and allow extension
- Loading branch information
Showing
16 changed files
with
334 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.pom.xml | ||
target | ||
*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#-*- mode: ruby -*- | ||
|
||
jar("org.jruby.rack:jruby-rack", '1.1.13.1') | ||
jar("org.jruby:jruby-core", "${jruby.version}") | ||
|
||
# lock down versions | ||
properties['jruby.version'] = '1.7.2' | ||
properties['jruby.plugins.version'] = '0.29.3' | ||
properties['jetty.version'] = '8.1.9.v20130131' | ||
|
||
# vim: syntax=Ruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'maven/ruby/cli' | ||
require 'maven/jetty/pom_magic' | ||
|
||
module Maven | ||
module Jetty | ||
class Cli < Maven::Ruby::Cli | ||
|
||
def magic_pom( dir = '.', *args ) | ||
PomMagic.new.generate_pom( File.expand_path( dir ), *args ) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
require 'maven/tools/gem_project' | ||
|
||
module Maven | ||
module Jetty | ||
class JettyProject < Maven::Tools::GemProject | ||
|
||
tags :dummy | ||
|
||
private | ||
|
||
CONNECTOR_XML = <<-XML | ||
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> | ||
<port>${jetty.port}</port> | ||
</connector> | ||
<connector implementation="org.eclipse.jetty.server.ssl.SslSelectChannelConnector"> | ||
<port>${jetty.sslport}</port> | ||
<keystore>${project.build.directory}/jetty/server.keystore</keystore> | ||
<keyPassword>123456</keyPassword> | ||
<password>123456</password> | ||
</connector> | ||
XML | ||
|
||
public | ||
|
||
def rails?( dir = '.' ) | ||
File.exists? File.join( dir, 'config', 'application.rb' ) | ||
end | ||
|
||
def connector_xml | ||
if File.exists?( 'src/test/resources/server.keystore' ) | ||
CONNECTOR_XML.sub( /..project.build.directory..jetty/, '${project.basedir}/src/test/resources' ) | ||
else | ||
CONNECTOR_XML | ||
end | ||
end | ||
|
||
def web_xml | ||
if File.exists?( File.join( 'config', 'web.xml' ) ) | ||
File.join( 'config', 'web.xml' ) | ||
elsif File.exists?('web.xml') | ||
'web.xml' | ||
end | ||
end | ||
|
||
def add_defaults | ||
super | ||
self.properties.merge!({ | ||
"jetty.war" => "${project.build.directory}/${project.build.finalName}.war", | ||
"jetty.port" => '8080', | ||
"jetty.sslport" => '8443' | ||
}) | ||
|
||
self.properties[ 'rails.env' ] = 'development' if rails? | ||
|
||
profile(:war).plugin("org.mortbay.jetty:jetty-maven-plugin", | ||
"${jetty.version}")do |jetty| | ||
options = { | ||
:war => "${jetty.war}", | ||
:connectors => connector_xml | ||
} | ||
jetty.with options | ||
end | ||
|
||
profile(:run) do |run| | ||
overrideDescriptor = rails? ? '${project.build.directory}/jetty/override-rails-${rails.env}-web.xml' : '${project.build.directory}/jetty/override-rack-web.xml' | ||
run.activation.by_default | ||
run.plugin("org.mortbay.jetty:jetty-maven-plugin", | ||
"${jetty.version}") do |jetty| | ||
options = { | ||
:webAppConfig => { | ||
:overrideDescriptor => overrideDescriptor | ||
}, | ||
:systemProperties => { | ||
:systemProperty => { | ||
:name => 'jbundle.skip', | ||
:value => 'true' | ||
} | ||
}, | ||
:connectors => connector_xml, | ||
:webXml => web_xml, | ||
:webAppSourceDirectory => "." | ||
} | ||
jetty.with options | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<web-app> | ||
<context-param> | ||
<!-- must match the place where the gems are located --> | ||
<param-name>gem.path</param-name> | ||
<param-value>./target/rubygems:./target/rubygems-bundler-maven-plugin</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>jruby.rack.logging</param-name> | ||
<param-value>stdout</param-value> | ||
</context-param> | ||
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<web-app> | ||
<context-param> | ||
<!-- must match the place where the gems are located --> | ||
<param-name>gem.path</param-name> | ||
<param-value>./target/rubygems:./target/rubygems-bundler-maven-plugin</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>rails.env</param-name> | ||
<param-value>development</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>jruby.rack.logging</param-name> | ||
<param-value>stdout</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>jruby.rack.layout_class</param-name> | ||
<param-value>JRuby::Rack::RailsFilesystemLayout</param-value> | ||
</context-param> | ||
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<web-app> | ||
<context-param> | ||
<!-- must match the place where the gems are located --> | ||
<param-name>gem.path</param-name> | ||
<param-value>./target/rubygems:./target/rubygems-bundler-maven-plugin</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>rails.env</param-name> | ||
<param-value>production</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>jruby.rack.logging</param-name> | ||
<param-value>stdout</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>jruby.rack.layout_class</param-name> | ||
<param-value>JRuby::Rack::RailsFilesystemLayout</param-value> | ||
</context-param> | ||
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
require 'maven/ruby/pom_magic' | ||
require 'maven/jetty/jetty_project' | ||
require 'fileutils' | ||
|
||
module Maven | ||
module Jetty | ||
class PomMagic < Maven::Ruby::PomMagic | ||
|
||
def generate_pom( dir = '.', *args ) | ||
|
||
proj = JettyProject.new | ||
|
||
ensure_web_xml( dir, proj ) | ||
ensure_mavenfile( dir ) | ||
ensure_keystore( dir ) | ||
ensure_overlays( dir ) | ||
|
||
load_standard_files( dir, proj ) | ||
|
||
pom_xml( dir, proj, args ) | ||
end | ||
|
||
def ensure_overlays( dir ) | ||
target = target_dir( dir ) | ||
Dir[ File.join( File.dirname( __FILE__ ), "override-*-web.xml" ) ].each do |f| | ||
FileUtils.cp( f, target ) | ||
end | ||
end | ||
|
||
def ensure_web_xml( dir, proj, source = File.dirname( __FILE__ ), target = nil ) | ||
target ||= File.join( config_dir( dir ), 'web.xml' ) | ||
if !File.exists?( target ) && !File.exists?( File.join( dir, 'src', 'main', 'webapp', 'WEB-INF', 'web.xml' ) ) | ||
flavour = rails?( dir ) ? "rails" : "rack" | ||
web_xml = File.join( source, "#{flavour}-web.xml" ) | ||
FileUtils.cp( web_xml, target ) | ||
warn "created #{target.sub( /#{dir}\/?/, './' )}" | ||
end | ||
end | ||
|
||
def rails?( dir ) | ||
File.exists? File.join( dir, 'config', 'application.rb' ) | ||
end | ||
|
||
def config_dir( dir ) | ||
if File.exists?( File.join( dir, 'config' ) ) | ||
File.join( dir, 'config' ) | ||
else | ||
dir | ||
end | ||
end | ||
|
||
def target_dir( dir ) | ||
target = File.join( dir, 'target', 'jetty' ) | ||
unless File.exists?( target ) | ||
FileUtils.mkdir_p target | ||
end | ||
target | ||
end | ||
|
||
def ensure_keystore( dir ) | ||
target = File.join( target_dir( dir ), 'server.keystore' ) | ||
if !File.exists?( target ) && !File.exists?( File.join( dir, 'src', 'test', 'resources', 'server.keystore' ) ) | ||
store = File.join( File.dirname( __FILE__ ), "server.keystore" ) | ||
FileUtils.cp( store, target ) | ||
end | ||
end | ||
|
||
# def first_gemspec( dir = '.' ) | ||
# gemspecs = Dir[ File.join( dir, "*.gemspec" ) ] | ||
# if gemspecs.size > 0 | ||
# File.expand_path( gemspecs[ 0 ] ) | ||
# end | ||
# end | ||
|
||
# def file( name, dir = '.' ) | ||
# File.expand_path( File.join( dir, name ) ) | ||
# end | ||
|
||
# def pom_xml( dir = '.', proj, args ) | ||
# index = args.index( '-f' ) || args.index( '--file' ) | ||
# name = args[ index + 1 ] if index | ||
# pom = File.join( dir, name || '.pom.xml' ) | ||
# File.open(pom, 'w') do |f| | ||
# f.puts proj.to_xml | ||
# end | ||
# args += ['-f', pom] unless name | ||
# args | ||
# end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.