maven-tools 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ module Maven
2
+ module Tools
3
+ class GemfileLock < Hash
4
+
5
+ class Dependency
6
+ attr_accessor :name, :version, :dependencies
7
+ def initialize(line, deps = {})
8
+ @name = line.sub(/\ .*/,'')
9
+ @version = line.sub(/.*\(/, '').sub(/\).*/, '').sub(/-java$/, '')
10
+ @dependencies = deps
11
+ end
12
+
13
+ def add(line)
14
+ dependencies[line.sub(/\ .*/,'')] = line.sub(/.*\(/, '').sub(/\).*/, '')
15
+ end
16
+ end
17
+
18
+ def initialize(file)
19
+ super()
20
+ current = nil
21
+ f = file.is_a?(File) ? file.path: file
22
+ if File.exists? f
23
+ File.readlines(f).each do |line|
24
+ if line =~ /^ [^ ]/
25
+ line.strip!
26
+ current = Dependency.new(line)
27
+ self[current.name] = current
28
+ elsif line =~ /^ [^ ]/
29
+ line.strip!
30
+ current.add(line) if current
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ def recurse(result, dep)
37
+ result[dep] = self[dep].version if self[dep] && !result.key?(dep)
38
+ if d = self[dep]
39
+ d.dependencies.each do |name, version|
40
+ unless result.key? name
41
+ if name != 'bundler'
42
+ result[name] = self[name].nil?? version : self[name].version
43
+ recurse(result, name)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def dependency_hull(deps = [])
51
+ deps = deps.is_a?(Array) ? deps : [deps]
52
+ result = {}
53
+ deps.each do |dep|
54
+ recurse(result, dep)
55
+ end
56
+ result
57
+ end
58
+
59
+ def hull
60
+ dependency_hull(keys)
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ if $0 == __FILE__
67
+ lockfile = Maven::Tools::GemfileLock.new(File.new(ARGV[0] || 'Gemfile.lock'))
68
+ p lockfile
69
+ p lockfile.dependency_hull("rails")
70
+ end
@@ -0,0 +1,67 @@
1
+ module Maven
2
+ module Tools
3
+ class GemfileLock < Hash
4
+
5
+ class Dependency
6
+ attr_accessor :name, :version, :dependencies
7
+ def initialize(line, deps = {})
8
+ @name = line.sub(/\ .*/,'')
9
+ @version = line.sub(/.*\(/, '').sub(/\).*/, '').sub(/-java$/, '')
10
+ @dependencies = deps
11
+ end
12
+
13
+ def add(line)
14
+ dependencies[line.sub(/\ .*/,'')] = line.sub(/.*\(/, '').sub(/\).*/, '')
15
+ end
16
+ end
17
+
18
+ def initialize(file)
19
+ current = nil
20
+ f = file.is_a?(File) ? file.path: file
21
+ if File.exists? f
22
+ File.readlines(f).each do |line|
23
+ if line =~ /^ [^ ]/
24
+ line.strip!
25
+ current = Dependency.new(line)
26
+ self[current.name] = current
27
+ elsif line =~ /^ [^ ]/
28
+ line.strip!
29
+ current.add(line) if current
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def recurse(result, dep)
36
+ result[dep] = self[dep].version if self[dep] && !result.key?(dep)
37
+ if d = self[dep]
38
+ d.dependencies.each do |name, version|
39
+ unless result.key? name
40
+ result[name] = self[name].nil?? version : self[name].version
41
+ recurse(result, name)
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def dependency_hull(deps = [])
48
+ deps = deps.is_a?(Array) ? deps : [deps]
49
+ result = {}
50
+ deps.each do |dep|
51
+ recurse(result, dep)
52
+ end
53
+ result
54
+ end
55
+
56
+ def hull
57
+ dependency_hull(keys)
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ if $0 == __FILE__
64
+ lockfile = Maven::Tools::GemfileLock.new(File.new(ARGV[0] || 'Gemfile.lock'))
65
+ p lockfile
66
+ p lockfile.dependency_hull("rails")
67
+ end
@@ -0,0 +1,95 @@
1
+ require File.join(File.dirname(__FILE__), 'coordinate.rb')
2
+ module Maven
3
+ module Tools
4
+
5
+ class Jarfile
6
+ include Coordinate
7
+
8
+ def initialize(file = 'Jarfile')
9
+ @file = file
10
+ @lockfile = file + ".lock"
11
+ end
12
+
13
+ def mtime
14
+ File.mtime(@file)
15
+ end
16
+
17
+ def exists?
18
+ File.exists?(@file)
19
+ end
20
+
21
+ def mtime_lock
22
+ File.mtime(@lockfile)
23
+ end
24
+
25
+ def exists_lock?
26
+ File.exists?(@lockfile)
27
+ end
28
+
29
+ def load_lockfile
30
+ _locked = []
31
+ if exists_lock?
32
+ File.read(@lockfile).each_line do |line|
33
+ line.strip!
34
+ if line.size > 0 && !(line =~ /^\s*#/)
35
+ _locked << line
36
+ end
37
+ end
38
+ end
39
+ _locked
40
+ end
41
+
42
+ def locked
43
+ @locked ||= load_lockfile
44
+ end
45
+
46
+ def locked?(coordinate)
47
+ coord = coordinate.sub(/^([^:]+:[^:]+):.+/) { $1 }
48
+ locked.detect { |l| l.sub(/^([^:]+:[^:]+):.+/) { $1 } == coord } != nil
49
+ end
50
+
51
+ def populate_unlocked(container)
52
+ if File.exists?(@file)
53
+ File.read(@file).each_line do |line|
54
+ if coord = to_coordinate(line)
55
+ unless locked?(coord)
56
+ container.add_artifact(coord)
57
+ end
58
+ elsif line =~ /^\s*(repository|source)\s/
59
+ # allow `source :name, "http://url"`
60
+ # allow `source "name", "http://url"`
61
+ # allow `source "http://url"`
62
+ # also allow `repository` instead of `source`
63
+ name, url = line.sub(/.*(repository|source)\s+/, '').split(/,/)
64
+ url = name unless url
65
+ # remove whitespace and trailing/leading ' or "
66
+ name.strip!
67
+ name.gsub!(/^:/, '')
68
+ name.gsub!(/^['"]|['"]$/,'')
69
+ url.strip!
70
+ url.gsub!(/^['"]|['"]$/,'')
71
+ container.add_repository(name, url)
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def populate_locked(container)
78
+ locked.each { |l| container.add_artifact(l) }
79
+ end
80
+
81
+ def generate_lockfile(dependency_coordinates)
82
+ if dependency_coordinates.empty?
83
+ FileUtils.rm_f(@lockfile) if exists_lock?
84
+ else
85
+ File.open(@lockfile, 'w') do |f|
86
+ dependency_coordinates.each do |d|
87
+ f.puts d.to_s
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,79 @@
1
+ require 'maven/tools/coordinate'
2
+ module Maven
3
+ module Tools
4
+
5
+ class Jarfile
6
+ include Coordinate
7
+
8
+ def initialize(file = 'Jarfile')
9
+ @file = file
10
+ @lockfile = file + ".lock"
11
+ end
12
+
13
+ def mtime
14
+ File.mtime(@file)
15
+ end
16
+
17
+ def exists?
18
+ File.exists?(@file)
19
+ end
20
+
21
+ def mtime_lock
22
+ File.mtime(@lockfile)
23
+ end
24
+
25
+ def exists_lock?
26
+ File.exists?(@lockfile)
27
+ end
28
+
29
+ def load_lockfile
30
+ _locked = []
31
+ if exists_lock?
32
+ File.read(@lockfile).each_line do |line|
33
+ line.strip!
34
+ if line.size > 0 && !(line =~ /^\s*#/)
35
+ _locked << line
36
+ end
37
+ end
38
+ end
39
+ _locked
40
+ end
41
+
42
+ def locked
43
+ @locked ||= load_lockfile
44
+ end
45
+
46
+ def locked?(coordinate)
47
+ coord = coordinate.sub(/^([^:]+:[^:]+):.+/) { $1 }
48
+ locked.detect { |l| l.sub(/^([^:]+:[^:]+):.+/) { $1 } == coord } != nil
49
+ end
50
+
51
+ def populate_unlocked(aether)
52
+ File.read(@file).each_line do |line|
53
+ if coord = to_coordinate(line)
54
+ unless locked?(coord)
55
+ aether.add_artifact(coord)
56
+ end
57
+ elsif line =~ /^\s*(repository|source)\s/
58
+ name, url = line.sub(/.*(repository|source)\s+/, '').gsub(/['":]/,'').split(/,/)
59
+ url = name unless url
60
+ aether.add_repository(name, url)
61
+ end
62
+ end
63
+ end
64
+
65
+ def populate_locked(aether)
66
+ locked.each { |l| aether.add_artifact(l) }
67
+ end
68
+
69
+ def generate_lockfile(dependency_coordinates)
70
+ File.open(@lockfile, 'w') do |f|
71
+ dependency_coordinates.each do |d|
72
+ f.puts d.to_s
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,63 @@
1
+ require File.join(File.dirname(__FILE__), 'rails_project.rb')
2
+ module Maven
3
+ module Tools
4
+ class PomGenerator
5
+ def read_rails(filename, plugin_version = nil, jruby_version = nil)
6
+ proj = Maven::Tools::RailsProject.new
7
+ proj.load_gemfile(filename.to_s)
8
+ proj.load_jarfile(File.join(File.dirname(filename.to_s), 'Jarfile'))
9
+ proj.load_mavenfile(File.join(File.dirname(filename.to_s), 'Mavenfile'))
10
+ proj.add_defaults(versions(plugin_version, jruby_version))
11
+ proj.to_xml
12
+ end
13
+
14
+ # the dummy allows to have all three methods the same argument list
15
+ def read_gemfile(filename, plugin_version = nil, dummy = nil)
16
+ dir = File.dirname(filename)
17
+ proj =
18
+ if File.exists? File.join( dir, 'config', 'application.rb' )
19
+ Maven::Tools::RailsProject.new
20
+ else
21
+ Maven::Tools::GemProject.new
22
+ end
23
+ proj.load_gemfile(filename.to_s)
24
+ proj.load_jarfile(File.join(File.dirname(filename.to_s), 'Jarfile'))
25
+ proj.load_mavenfile(File.join(File.dirname(filename.to_s), 'Mavenfile'))
26
+ proj.add_defaults(versions(plugin_version, nil))
27
+ proj.to_xml
28
+ end
29
+
30
+ # the dummy allows to have all three methods the same argument list
31
+ def read_gemspec(filename, plugin_version = nil, dummy = nil)
32
+ proj = Maven::Tools::GemProject.new
33
+ proj.load_gemspec(filename.to_s)
34
+ proj.load_jarfile(File.join(File.dirname(filename.to_s), 'Jarfile'))
35
+ proj.load_mavenfile(File.join(File.dirname(filename.to_s), 'Mavenfile'))
36
+ proj.add_defaults(versions(plugin_version, nil))
37
+ proj.to_xml
38
+ end
39
+
40
+ private
41
+
42
+ def versions(plugin_version, jruby_version)
43
+ result = {}
44
+ result[:jruby_plugins] = plugin_version if plugin_version
45
+ result[:jruby_version] = jruby_version if jruby_version
46
+ result
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ generator = Maven::Tools::PomGenerator.new
53
+
54
+ case ARGV.size
55
+ when 2
56
+ puts generator.send("read_#{ARGV[0]}".to_sym, ARGV[1])
57
+ when 3
58
+ puts generator.send("read_#{ARGV[0]}".to_sym, ARGV[1], ARGV[2])
59
+ when 4
60
+ puts generator.send("read_#{ARGV[0]}".to_sym, ARGV[1], ARGV[2], ARGV[3])
61
+ else
62
+ generator
63
+ end
@@ -0,0 +1,183 @@
1
+ require File.join(File.dirname(__FILE__), 'gem_project.rb')
2
+ module Maven
3
+ module Tools
4
+ class RailsProject < GemProject
5
+ tags :dummy
6
+
7
+ def initialize(name = dir_name, &block)
8
+ super(name, &block)
9
+ group_id "rails"
10
+ packaging "war"
11
+ end
12
+
13
+ def has_gem?(gem)
14
+ assets = profile(:assets)
15
+ self.gem?(gem) || (assets && assets.gem?(gem))
16
+ end
17
+
18
+ def add_defaults(args = {})
19
+ self.name = "#{dir_name} - rails application" unless name
20
+
21
+ # setup bundler plugin
22
+ plugin(:bundler)
23
+
24
+ s_args = args.dup
25
+ s_args.delete(:jruby_plugins)
26
+ super(s_args)
27
+
28
+ versions = VERSIONS.merge(args)
29
+
30
+ rails_gem = dependencies.detect { |d| d.type.to_sym == :gem && d.artifact_id.to_s =~ /^rail.*s$/ } # allow rails or railties
31
+
32
+ if !jar?("org.jruby:jruby-complete") && !jar?("org.jruby:jruby-core") && versions[:jruby_version]
33
+ minor = versions[:jruby_version].sub(/[0-9]*\./, '').sub(/\..*/, '')
34
+
35
+ #TODO once jruby-core pom is working !!!
36
+ if minor.to_i > 55 #TODO fix minor minimum version
37
+ jar("org.jruby:jruby-core", versions[:jruby_version])
38
+ jar("org.jruby:jruby-stdlib", versions[:jruby_version])
39
+ # override deps which works
40
+ jar("jline:jline", '0.9.94') if versions[:jruby_version] =~ /1.6.[1-2]/
41
+ jar("org.jruby.extras:jffi", '1.0.8', 'native') if versions[:jruby_version] =~ /1.6.[0-2]/
42
+ jar("org.jruby.extras:jaffl", '0.5.10') if versions[:jruby_version] =~ /1.6.[0-2]/
43
+ else
44
+ jar("org.jruby:jruby-complete", "${jruby.version}")
45
+ end
46
+ end
47
+
48
+ jar("org.jruby.rack:jruby-rack", versions[:jruby_rack]) unless jar?("org.jruby.rack:jruby-rack")
49
+
50
+ self.properties = {
51
+ "jruby.version" => versions[:jruby_version],
52
+ "jetty.version" => versions[:jetty_plugin],
53
+ "rails.env" => "development",
54
+ "gem.includeRubygemsInTestResources" => false
55
+ }.merge(self.properties)
56
+
57
+ plugin(:rails3) do |rails|
58
+ rails.version = "${jruby.plugins.version}" unless rails.version
59
+ rails.in_phase(:validate).execute_goal(:initialize)#.goals << "initialize"
60
+ end
61
+
62
+ plugin(:war, versions[:war_plugin]) unless plugin?(:war)
63
+ plugin(:war) do |w|
64
+ options = {
65
+ :webResources => Maven::Model::NamedArray.new(:resource) do |l|
66
+ l << { :directory => "public" }
67
+ l << {
68
+ :directory => ".",
69
+ :targetPath => "WEB-INF",
70
+ :includes => ['app/**', 'config/**', 'lib/**', 'vendor/**', 'Gemfile']
71
+ }
72
+ l << {
73
+ :directory => '${gem.path}',
74
+ :targetPath => 'WEB-INF/gems',
75
+ :includes => ['gems/**', 'specifications/**']
76
+ }
77
+ if plugin(:bundler).dependencies.detect { |d| d.type.to_sym == :gem }
78
+ l << {
79
+ :directory => '${gem.path}-bundler-maven-plugin',
80
+ :targetPath => 'WEB-INF/gems',
81
+ :includes => ['specifications/**']
82
+ }
83
+ end
84
+ end
85
+ }
86
+ options[:webXml] = 'config/web.xml' if File.exists?('config/web.xml') || !File.exists?('src/main/webapp/WEB-INF/web.xml')
87
+ w.with options
88
+ end
89
+
90
+ profile(:assets).activation.by_default if profiles.key?(:assets)
91
+ profile(:development).activation.by_default
92
+ profile(:test).activation.by_default
93
+ profile(:test).activation.property("rails.env", "test")
94
+ profile(:production) do |prod|
95
+ prod.activation.property("rails.env", "production")
96
+ prod.properties = {
97
+ "gem.home" => "${project.build.directory}/rubygems-production",
98
+ "gem.path" => "${project.build.directory}/rubygems-production"
99
+ }.merge(prod.properties)
100
+ end
101
+
102
+ profile(:war).plugin("org.mortbay.jetty:jetty-maven-plugin",
103
+ "${jetty.version}")
104
+
105
+ profile(:run) do |run|
106
+ overrideDescriptor = '${project.build.directory}/jetty/override-${rails.env}-web.xml'
107
+ run.activation.by_default
108
+ run.plugin("org.mortbay.jetty:jetty-maven-plugin",
109
+ "${jetty.version}") do |jetty|
110
+ options = {
111
+ :webAppConfig => {
112
+ :overrideDescriptor => overrideDescriptor
113
+ },
114
+ :systemProperties => {
115
+ :systemProperty => {
116
+ :name => 'jbundle.skip',
117
+ :value => 'true'
118
+ }
119
+ },
120
+ :connectors => <<-XML
121
+
122
+ <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
123
+ <port>8080</port>
124
+ </connector>
125
+ <connector implementation="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
126
+ <port>8443</port>
127
+ <keystore>${project.basedir}/src/test/resources/server.keystore</keystore>
128
+ <keyPassword>123456</keyPassword>
129
+ <password>123456</password>
130
+ </connector>
131
+ XML
132
+ }
133
+ options[:webXml] = 'config/web.xml' if File.exists?('config/web.xml')
134
+ jetty.with options
135
+ end
136
+ end
137
+ profile(:warshell) do |exec|
138
+ exec.plugin_repository('kos').url = 'http://opensource.kantega.no/nexus/content/groups/public/'
139
+ exec.plugin('org.simplericity.jettyconsole:jetty-console-maven-plugin', '1.42').execution do |jetty|
140
+ jetty.execute_goal(:createconsole)
141
+ jetty.configuration.comment <<-TEXT
142
+ see http://simplericity.com/2009/11/10/1257880778509.html for more info
143
+ -->
144
+ <!--
145
+ <backgroundImage>${basedir}/src/main/jettyconsole/puffin.jpg</backgroundImage>
146
+ <additionalDependencies>
147
+ <additionalDependency>
148
+ <artifactId>jetty-console-winsrv-plugin</artifactId>
149
+ </additionalDependency>
150
+ <additionalDependency>
151
+ <artifactId>jetty-console-requestlog-plugin</artifactId>
152
+ </additionalDependency>
153
+ <additionalDependency>
154
+ <artifactId>jetty-console-log4j-plugin</artifactId>
155
+ </additionalDependency>
156
+ <additionalDependency>
157
+ <artifactId>jetty-console-jettyxml-plugin</artifactId>
158
+ </additionalDependency>
159
+ <additionalDependency>
160
+ <artifactId>jetty-console-ajp-plugin</artifactId>
161
+ </additionalDependency>
162
+ <additionalDependency>
163
+ <artifactId>jetty-console-gzip-plugin</artifactId>
164
+ </additionalDependency>
165
+ <additionalDependency>
166
+ <artifactId>jetty-console-startstop-plugin</artifactId>
167
+ </additionalDependency>
168
+ </additionalDependencies>
169
+ TEXT
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+
177
+ if $0 == __FILE__
178
+ proj = Maven::Tools::RailsProject.new
179
+ proj.load(ARGV[0] || 'Gemfile')
180
+ proj.load(ARGV[1] || 'Mavenfile')
181
+ proj.add_defaults
182
+ puts proj.to_xml
183
+ end