jetty-run 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,127 @@
1
+ #
2
+ # Copyright (C) 2013 Christian Meier
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'maven/tools/gem_project'
22
+
23
+ module Maven
24
+ module Jetty
25
+ class JettyProject < Maven::Tools::GemProject
26
+
27
+ tags :dummy
28
+
29
+ private
30
+
31
+ CONNECTOR_XML = <<-XML
32
+
33
+ <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
34
+ <port>${jetty.port}</port>
35
+ </connector>
36
+ <connector implementation="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
37
+ <port>${jetty.sslport}</port>
38
+ <keystore>${project.build.directory}/jetty/server.keystore</keystore>
39
+ <keyPassword>123456</keyPassword>
40
+ <password>123456</password>
41
+ </connector>
42
+ XML
43
+
44
+ public
45
+
46
+ def initialize( dir = '.')
47
+ @dir = dir
48
+ super *[]
49
+ end
50
+
51
+ def rails?( dir = '.' )
52
+ File.exists? File.join( dir, 'config', 'application.rb' )
53
+ end
54
+
55
+ def connector_xml
56
+ if File.exists?( File.join( @dir, 'src', 'test','resources','server.keystore' ) )
57
+ CONNECTOR_XML.sub( /..project.build.directory..jetty/, '${project.basedir}/src/test/resources' )
58
+ else
59
+ CONNECTOR_XML
60
+ end
61
+ end
62
+
63
+ def web_xml
64
+ if File.exists?( File.join( @dir, 'config', 'web.xml' ) )
65
+ File.join( @dir, 'config', 'web.xml' )
66
+ elsif File.exists?( File.join( @dir, 'web.xml' ) )
67
+ 'web.xml'
68
+ end
69
+ end
70
+
71
+ def load_gemfile(file)
72
+ super
73
+ file = file.path if file.is_a?(File)
74
+ if File.exists? file
75
+ gem 'bundler'
76
+ #plugin( :bundler, "${jruby.plugins.version}" ).execute_goal( :install )
77
+ end
78
+ super
79
+ end
80
+
81
+ def add_defaults
82
+ super
83
+ self.properties.merge!({
84
+ "jetty.war" => "${project.build.directory}/${project.build.finalName}.war",
85
+ "jetty.port" => '8080',
86
+ "jetty.sslport" => '8443'
87
+ })
88
+
89
+ self.properties[ 'rails.env' ] = 'development' if rails?( @dir )
90
+
91
+ plugin( :gem, "${jruby.plugins.version}" ).execute_goal( :initialize )
92
+
93
+ profile(:war).plugin("org.mortbay.jetty:jetty-maven-plugin",
94
+ "${jetty.version}")do |jetty|
95
+ options = {
96
+ :war => "${jetty.war}",
97
+ :connectors => connector_xml
98
+ }
99
+ jetty.with options
100
+ end
101
+
102
+ profile(:run) do |run|
103
+ overrideDescriptor = rails?( @dir ) ? '${project.build.directory}/jetty/override-rails-${rails.env}-web.xml' : '${project.build.directory}/jetty/override-rack-web.xml'
104
+ run.activation.by_default
105
+ run.plugin("org.mortbay.jetty:jetty-maven-plugin",
106
+ "${jetty.version}") do |jetty|
107
+ options = {
108
+ :webAppConfig => {
109
+ :overrideDescriptor => overrideDescriptor
110
+ },
111
+ :systemProperties => {
112
+ :systemProperty => {
113
+ :name => 'jbundle.skip',
114
+ :value => 'true'
115
+ }
116
+ },
117
+ :connectors => connector_xml,
118
+ :webXml => web_xml,
119
+ :webAppSourceDirectory => "."
120
+ }
121
+ jetty.with options
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,69 @@
1
+ require 'maven/tools/rails_project'
2
+
3
+ module Maven
4
+ module Jetty
5
+ class RackProject < Maven::Tools::GemProject
6
+
7
+ tags :dummy
8
+
9
+ private
10
+
11
+ CONNECTOR_XML = <<-XML
12
+
13
+ <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
14
+ <port>${jetty.port}</port>
15
+ </connector>
16
+ <connector implementation="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
17
+ <port>${jetty.sslport}</port>
18
+ <keystore>${project.basedir}/src/test/resources/server.keystore</keystore>
19
+ <keyPassword>123456</keyPassword>
20
+ <password>123456</password>
21
+ </connector>
22
+ XML
23
+
24
+ public
25
+
26
+
27
+ def add_defaults
28
+ super
29
+ self.properties.merge!({
30
+ "jetty.version" => '7.6.4.v20120524',
31
+ "jetty.war" => "${project.build.directory}/${project.build.finalName}.war",
32
+ "jetty.port" => '8080',
33
+ "jetty.sslport" => '8443'
34
+ })
35
+
36
+ profile(:war).plugin("org.mortbay.jetty:jetty-maven-plugin",
37
+ "${jetty.version}")do |jetty|
38
+ options = {
39
+ :war => "${jetty.war}",
40
+ :connectors => CONNECTOR_XML
41
+ }
42
+ jetty.with options
43
+ end
44
+
45
+ profile(:run) do |run|
46
+ overrideDescriptor = '${project.build.directory}/jetty/override-${rails.env}-web.xml'
47
+ run.activation.by_default
48
+ run.plugin("org.mortbay.jetty:jetty-maven-plugin",
49
+ "${jetty.version}") do |jetty|
50
+ options = {
51
+ :webAppConfig => {
52
+ :overrideDescriptor => overrideDescriptor
53
+ },
54
+ :systemProperties => {
55
+ :systemProperty => {
56
+ :name => 'jbundle.skip',
57
+ :value => 'true'
58
+ }
59
+ },
60
+ :connectors => CONNECTOR_XML
61
+ }
62
+ options[:webXml] = 'config/web.xml' if File.exists?('config/web.xml')
63
+ jetty.with options
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,31 @@
1
+ <!--
2
+ Copyright (C) 2013 Christian Meier
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ the Software, and to permit persons to whom the Software is furnished to do so,
9
+ subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ -->
21
+ <web-app>
22
+ <context-param>
23
+ <!-- must match the place where the gems are located -->
24
+ <param-name>gem.path</param-name>
25
+ <param-value>./target/rubygems:./target/rubygems-bundler-maven-plugin</param-value>
26
+ </context-param>
27
+ <context-param>
28
+ <param-name>jruby.rack.logging</param-name>
29
+ <param-value>stdout</param-value>
30
+ </context-param>
31
+ </web-app>
@@ -0,0 +1,19 @@
1
+ <web-app>
2
+ <context-param>
3
+ <!-- must match the place where the gems are located -->
4
+ <param-name>gem.path</param-name>
5
+ <param-value>./target/rubygems:./target/rubygems-bundler-maven-plugin</param-value>
6
+ </context-param>
7
+ <context-param>
8
+ <param-name>rails.env</param-name>
9
+ <param-value>production</param-value>
10
+ </context-param>
11
+ <context-param>
12
+ <param-name>jruby.rack.logging</param-name>
13
+ <param-value>stdout</param-value>
14
+ </context-param>
15
+ <context-param>
16
+ <param-name>jruby.rack.layout_class</param-name>
17
+ <param-value>JRuby::Rack::RailsFilesystemLayout</param-value>
18
+ </context-param>
19
+ </web-app>
@@ -0,0 +1,19 @@
1
+ <web-app>
2
+ <context-param>
3
+ <!-- must match the place where the gems are located -->
4
+ <param-name>gem.path</param-name>
5
+ <param-value>./target/rubygems</param-value>
6
+ </context-param>
7
+ <context-param>
8
+ <param-name>rails.env</param-name>
9
+ <param-value>development</param-value>
10
+ </context-param>
11
+ <context-param>
12
+ <param-name>jruby.rack.logging</param-name>
13
+ <param-value>stdout</param-value>
14
+ </context-param>
15
+ <context-param>
16
+ <param-name>jruby.rack.layout_class</param-name>
17
+ <param-value>JRuby::Rack::RailsFilesystemLayout</param-value>
18
+ </context-param>
19
+ </web-app>
@@ -0,0 +1,39 @@
1
+ <!--
2
+ Copyright (C) 2013 Christian Meier
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ the Software, and to permit persons to whom the Software is furnished to do so,
9
+ subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ -->
21
+ <web-app>
22
+ <context-param>
23
+ <!-- must match the place where the gems are located -->
24
+ <param-name>gem.path</param-name>
25
+ <param-value>./target/rubygems:./target/rubygems-bundler-maven-plugin</param-value>
26
+ </context-param>
27
+ <context-param>
28
+ <param-name>rails.env</param-name>
29
+ <param-value>development</param-value>
30
+ </context-param>
31
+ <context-param>
32
+ <param-name>jruby.rack.logging</param-name>
33
+ <param-value>stdout</param-value>
34
+ </context-param>
35
+ <context-param>
36
+ <param-name>jruby.rack.layout_class</param-name>
37
+ <param-value>JRuby::Rack::RailsFilesystemLayout</param-value>
38
+ </context-param>
39
+ </web-app>
@@ -0,0 +1,39 @@
1
+ <!--
2
+ Copyright (C) 2013 Christian Meier
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ the Software, and to permit persons to whom the Software is furnished to do so,
9
+ subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ -->
21
+ <web-app>
22
+ <context-param>
23
+ <!-- must match the place where the gems are located -->
24
+ <param-name>gem.path</param-name>
25
+ <param-value>./target/rubygems:./target/rubygems-bundler-maven-plugin</param-value>
26
+ </context-param>
27
+ <context-param>
28
+ <param-name>rails.env</param-name>
29
+ <param-value>production</param-value>
30
+ </context-param>
31
+ <context-param>
32
+ <param-name>jruby.rack.logging</param-name>
33
+ <param-value>stdout</param-value>
34
+ </context-param>
35
+ <context-param>
36
+ <param-name>jruby.rack.layout_class</param-name>
37
+ <param-value>JRuby::Rack::RailsFilesystemLayout</param-value>
38
+ </context-param>
39
+ </web-app>
@@ -0,0 +1,19 @@
1
+ <web-app>
2
+ <context-param>
3
+ <!-- must match the place where the gems are located -->
4
+ <param-name>gem.path</param-name>
5
+ <param-value>./target/rubygems:./target/rubygems-bundler-maven-plugin</param-value>
6
+ </context-param>
7
+ <context-param>
8
+ <param-name>rails.env</param-name>
9
+ <param-value>development</param-value>
10
+ </context-param>
11
+ <context-param>
12
+ <param-name>jruby.rack.logging</param-name>
13
+ <param-value>stdout</param-value>
14
+ </context-param>
15
+ <context-param>
16
+ <param-name>jruby.rack.layout_class</param-name>
17
+ <param-value>JRuby::Rack::RailsFilesystemLayout</param-value>
18
+ </context-param>
19
+ </web-app>
@@ -0,0 +1,89 @@
1
+ #
2
+ # Copyright (C) 2013 Christian Meier
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'maven/ruby/pom_magic'
22
+ require 'maven/jetty/jetty_project'
23
+ require 'fileutils'
24
+
25
+ module Maven
26
+ module Jetty
27
+ class PomMagic < Maven::Ruby::PomMagic
28
+
29
+ def generate_pom( dir = '.', *args )
30
+ proj = JettyProject.new( dir )
31
+
32
+ ensure_web_xml( dir, proj )
33
+ ensure_mavenfile( dir, File.dirname( __FILE__ ) )
34
+ ensure_keystore( dir )
35
+ ensure_overlays( dir )
36
+
37
+ load_standard_files( dir, proj )
38
+
39
+ pom_xml( dir, proj, args )
40
+ end
41
+
42
+ def ensure_overlays( dir )
43
+ target = target_dir( dir )
44
+ Dir[ File.join( File.dirname( __FILE__ ), "override-*-web.xml" ) ].each do |f|
45
+ FileUtils.cp( f, target )
46
+ end
47
+ end
48
+
49
+ def ensure_web_xml( dir, proj, source = File.dirname( __FILE__ ), target = nil )
50
+ target ||= File.join( config_dir( dir ), 'web.xml' )
51
+ if !File.exists?( target ) && !File.exists?( File.join( dir, 'src', 'main', 'webapp', 'WEB-INF', 'web.xml' ) )
52
+ flavour = rails?( dir ) ? "rails" : "rack"
53
+ web_xml = File.join( source, "#{flavour}-web.xml" )
54
+ FileUtils.cp( web_xml, target )
55
+ warn "created #{target.sub( /#{dir}\/?/, './' )}"
56
+ end
57
+ end
58
+
59
+ def rails?( dir )
60
+ File.exists? File.join( dir, 'config', 'application.rb' )
61
+ end
62
+
63
+ def config_dir( dir )
64
+ if File.exists?( File.join( dir, 'config' ) )
65
+ File.join( dir, 'config' )
66
+ else
67
+ dir
68
+ end
69
+ end
70
+
71
+ def target_dir( dir )
72
+ target = File.join( dir, 'target', 'jetty' )
73
+ unless File.exists?( target )
74
+ FileUtils.mkdir_p target
75
+ end
76
+ target
77
+ end
78
+
79
+ def ensure_keystore( dir )
80
+ target = File.join( target_dir( dir ), 'server.keystore' )
81
+ if !File.exists?( target ) && !File.exists?( File.join( dir, 'src', 'test', 'resources', 'server.keystore' ) )
82
+ store = File.join( File.dirname( __FILE__ ), "server.keystore" )
83
+ FileUtils.cp( store, target )
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+ end