klaas1979-ivy4r 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ require 'ivy/target'
2
+
3
+ module Ivy
4
+ class Listmodules < Ivy::Target
5
+ def parameter
6
+ [
7
+ Parameter.new(:organisation, true),
8
+ Parameter.new(:module, true),
9
+ Parameter.new(:branch, false),
10
+ Parameter.new(:revision, true),
11
+ Parameter.new(:matcher, false),
12
+ Parameter.new(:property, true),
13
+ Parameter.new(:value, true),
14
+ Parameter.new(:settingsRef, false),
15
+ ]
16
+ end
17
+
18
+ protected
19
+ def before_hook
20
+ @cached_property_names = ant_properties.map {|key, value| key }
21
+ end
22
+
23
+ def after_hook
24
+ @cached_property_names = nil
25
+ end
26
+
27
+ def execute_ivy
28
+ call_nested :ivy_listmodules => params
29
+ end
30
+
31
+ def create_return_values
32
+ ant_properties.reject { |key, value| @cached_property_names.member? key }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ require 'ivy/target'
2
+
3
+ module Ivy
4
+ class Makepom < Ivy::Target
5
+ def parameter
6
+ [
7
+ Parameter.new(:ivyfile, true),
8
+ Parameter.new(:pomfile, true),
9
+ Parameter.new(:nested, true),
10
+ Parameter.new(:settingsRef, false)
11
+ ]
12
+ end
13
+
14
+ protected
15
+ def execute_ivy
16
+ call_nested :ivy_makepom => params
17
+ end
18
+
19
+ def create_return_values
20
+ IO.read(params[:pomfile])
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ require 'ivy/target'
2
+
3
+ module Ivy
4
+ class Publish < Ivy::Target
5
+ def parameter
6
+ [
7
+ Parameter.new(:artifactspattern, false),
8
+ Parameter.new(:resolver, true),
9
+ Parameter.new(:pubrevision, false),
10
+ Parameter.new(:pubbranch, false),
11
+ Parameter.new(:forcedeliver, false),
12
+ Parameter.new(:update, false),
13
+ Parameter.new(:validate, false),
14
+ Parameter.new(:replacedynamicrev, false),
15
+ Parameter.new(:publishivy, false),
16
+ Parameter.new(:conf, false),
17
+ Parameter.new(:overwrite, false),
18
+ Parameter.new(:warnonmissing, false),
19
+ Parameter.new(:srcivypattern, false),
20
+ Parameter.new(:srcivypattern, false),
21
+ Parameter.new(:pubdate, false),
22
+ Parameter.new(:status, false),
23
+ Parameter.new(:delivertarget, false),
24
+ Parameter.new(:settingsRef, false)
25
+ ]
26
+ end
27
+
28
+ protected
29
+ def execute_ivy
30
+ call_nested :ivy_publish => params
31
+ end
32
+
33
+ def create_return_values
34
+ nil
35
+ end
36
+ end
37
+ end
data/lib/ivy/report.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'ivy/target'
2
+
3
+ module Ivy
4
+ class Report < Ivy::Target
5
+ def parameter
6
+ [
7
+ Parameter.new(:todir, false),
8
+ Parameter.new(:nested, false),
9
+ Parameter.new(:outputpattern, false),
10
+ Parameter.new(:xsl, false),
11
+ Parameter.new(:xml, false),
12
+ Parameter.new(:graph, false),
13
+ Parameter.new(:dot, false),
14
+ Parameter.new(:conf, false),
15
+ Parameter.new(:organisation, false),
16
+ Parameter.new(:module, false),
17
+ Parameter.new(:validate, false),
18
+ Parameter.new(:xslfile, false),
19
+ Parameter.new(:settingsRef, false),
20
+ Parameter.new(:resolveId, false)
21
+ ]
22
+ end
23
+
24
+ protected
25
+ def execute_ivy
26
+ call_nested :ivy_report => params
27
+ end
28
+
29
+ def create_return_values
30
+ nil
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,44 @@
1
+ require 'ivy/target'
2
+
3
+ module Ivy
4
+ class Resolve < Ivy::Target
5
+ def parameter
6
+ [
7
+ Parameter.new(:file, false),
8
+ Parameter.new(:conf, false),
9
+ Parameter.new(:refresh, false),
10
+ Parameter.new(:resolveMode, false),
11
+ Parameter.new(:inline, false),
12
+ Parameter.new(:keep, false),
13
+ Parameter.new(:organisation, false),
14
+ Parameter.new(:module, false),
15
+ Parameter.new(:revision, false),
16
+ Parameter.new(:branch, false),
17
+ Parameter.new(:type, false),
18
+ Parameter.new(:haltonfailure, false),
19
+ Parameter.new(:failureproperty, false),
20
+ Parameter.new(:transitive, false),
21
+ Parameter.new(:showprogress, false),
22
+ Parameter.new(:validate, false),
23
+ Parameter.new(:settingsRef, false),
24
+ Parameter.new(:resolveId, false),
25
+ Parameter.new(:log, false)
26
+ ]
27
+ end
28
+
29
+ def result_property_values
30
+ property = params[:resolveId] ? ".#{params[:resolveId]}" : ''
31
+ [
32
+ ResultValue.new("ivy.organisation#{property}", nil),
33
+ ResultValue.new("ivy.module#{property}", nil),
34
+ ResultValue.new("ivy.revision#{property}", nil),
35
+ ResultValue.new("ivy.resolved.configurations#{property}", Ivy::COMMA_SPLITTER)
36
+ ]
37
+ end
38
+
39
+ protected
40
+ def execute_ivy
41
+ call_nested :ivy_resolve => params
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ require 'ivy/target'
2
+
3
+ module Ivy
4
+ class Retrieve < Ivy::Target
5
+ def parameter
6
+ [
7
+ Parameter.new(:pattern, false),
8
+ Parameter.new(:ivypattern, false),
9
+ Parameter.new(:conf, false),
10
+ Parameter.new(:sync, false),
11
+ Parameter.new(:type, false),
12
+ Parameter.new(:symlink, false),
13
+ Parameter.new(:settingsRef, false),
14
+ Parameter.new(:log, false)
15
+ ]
16
+ end
17
+
18
+ protected
19
+ def execute_ivy
20
+ call_nested :ivy_retrieve => params
21
+ end
22
+
23
+ def create_return_values
24
+ nil
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ require 'ivy/configure'
2
+
3
+ module Ivy
4
+ class Settings < Ivy::Configure
5
+
6
+ def create_return_values
7
+ nil
8
+ end
9
+
10
+ protected
11
+ def execute_ivy
12
+ call_nested :ivy_settings => params
13
+ end
14
+ end
15
+ end
data/lib/ivy/target.rb ADDED
@@ -0,0 +1,122 @@
1
+ require 'facets'
2
+
3
+ module Ivy
4
+
5
+ COMMA_SPLITTER = Proc.new {|value| value.to_s.split(',').map(&:strip)}
6
+
7
+ Parameter = Struct.new(:symbol, :mandatory) do
8
+ def mandatory?
9
+ mandatory
10
+ end
11
+ end
12
+
13
+ ResultValue = Struct.new(:matcher, :parser) do
14
+ def parse(value)
15
+ parser ? parser.call(value) : value
16
+ end
17
+ end
18
+ class Target
19
+ attr_reader :params
20
+
21
+ def initialize(ant)
22
+ @ant = ant
23
+ end
24
+
25
+ # Executes this ivy target with given parameters returning a result where appropriate
26
+ def execute(*params)
27
+ @params = {}
28
+ params.pop.each { |key, value| @params[key] = value } if Hash === params.last
29
+ params.each { |key| @params[key] = true }
30
+
31
+ validate
32
+ before_hook
33
+ execute_ivy
34
+ create_return_values
35
+ ensure
36
+ after_hook
37
+ end
38
+
39
+ protected
40
+
41
+ # Validates provided hash of parameters, raises an exception if any mandatory parameter is
42
+ # missing or an unknown parameter has been provided.
43
+ def validate
44
+ unknown = params.keys - symbols(parameter)
45
+ raise ArgumentError, "Unknown parameters '#{unknown.join(', ')}' for #{self.class}" unless unknown.empty?
46
+ missing = symbols(mandatory_parameter).find_all { |p| params.keys.member?(p) == false }
47
+ raise ArgumentError, "Missing mandatory parameters '#{missing.join(', ')}' for #{self.class}" unless missing.empty?
48
+ end
49
+
50
+ # Hook method called after validation but before #execute_ivy
51
+ # overwrite for special actions needed
52
+ def before_hook
53
+ end
54
+
55
+ # After hook is always called for #execute within +ensure+ block
56
+ # overwrite for special clean up
57
+ def after_hook
58
+ end
59
+
60
+ # Helper to call the nested ant targets recursively if nessecary. Must be called within +do+ +end+
61
+ # block of ant target to work.
62
+ def call_nested(nested)
63
+ if nested
64
+ nested.each do |method, paramlist|
65
+ [paramlist].flatten.each do |params|
66
+ if params.member? :nested
67
+ p = params.dup
68
+ nest = p.delete(:nested)
69
+ @ant.send(method, p, &lambda {call_nested(nest)})
70
+ else
71
+ @ant.send(method, params)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ # Creates the result for the execution by default it iterates of the ant properties and fetches
79
+ # all properties that match the result properties for target as a hash. Overwrite to provide
80
+ # a different result
81
+ def create_return_values
82
+ result_properties
83
+ end
84
+
85
+ # Fetches all result properties for called target and returns them as hash
86
+ def result_properties
87
+ result = ant_properties.map do |p|
88
+ rp = result_property_values.find { |rp| rp.matcher === p[0] }
89
+ rp ? [p[0], rp.parse(p[1])].flatten : nil
90
+ end.compact.to_h(:multi)
91
+ result.update_values do |v|
92
+ case v.size
93
+ when 0
94
+ nil
95
+ when 1
96
+ v[0]
97
+ else
98
+ v
99
+ end
100
+ end
101
+
102
+ result
103
+ end
104
+
105
+ def mandatory_parameter
106
+ parameter.find_all {|p| p.mandatory? }
107
+ end
108
+
109
+ def symbols(params)
110
+ params.map{|p| p.symbol}
111
+ end
112
+
113
+ def ant_properties
114
+ @ant.project.properties
115
+ end
116
+
117
+ def ant_references
118
+ @ant.project.references
119
+ end
120
+ end
121
+
122
+ end
@@ -0,0 +1,49 @@
1
+ require 'ivy/target'
2
+ require 'ivy/info'
3
+ require 'ivy/settings'
4
+ require 'ivy/configure'
5
+ require 'ivy/cleancache'
6
+ require 'ivy/resolve'
7
+ require 'ivy/makepom'
8
+ require 'ivy/cachepath'
9
+ #require 'ivy/listmodules'
10
+ require 'ivy/artifactproperty'
11
+ require 'ivy/artifactreport'
12
+ require 'ivy/findrevision'
13
+ require 'ivy/buildnumber'
14
+ require 'ivy/retrieve'
15
+ require 'ivy/publish'
16
+ require 'ivy/report'
17
+ require 'ivy/buildlist'
18
+
19
+ =begin
20
+ finished
21
+ * info
22
+ * settings
23
+ * configure
24
+ * cleancache
25
+ * buildnumber
26
+ * findrevision
27
+ * cachepath
28
+ * artifactreport
29
+ * resolve
30
+ * makepom
31
+ * retrieve
32
+ * publish
33
+ * artifactproperty
34
+ * report
35
+ o Using yEd to layout report graphs
36
+ * buildlist
37
+
38
+ TODO
39
+ * deliver
40
+ * install
41
+ * repreport
42
+
43
+ not working:
44
+ * listmodules
45
+
46
+ makes no sense:
47
+ * cachefileset
48
+ * var
49
+ =end
data/lib/ivy4r.rb ADDED
@@ -0,0 +1,176 @@
1
+ require 'antwrap'
2
+ require 'ivy/targets'
3
+
4
+ class Ivy4r
5
+ VERSION = '0.1.0'
6
+
7
+ # Set the ant home directory to load ant classes from if no custom __antwrap__ is provided
8
+ attr_accessor :ant_home
9
+
10
+ # Defines the directory to load ivy libs and its dependencies from
11
+ attr_accessor :lib_dir
12
+
13
+ attr_accessor :project_dir
14
+
15
+ # To provide a custom __antwrap__ to use instead of default one
16
+ attr_writer :ant
17
+
18
+ def initialize(*opts)
19
+ @ant = opts[0] if opts.size == 1
20
+ raise "To many parameters to create Ivy4r use none, or 1 to set ANT!" if opts.size > 1
21
+ end
22
+
23
+ # Calls the __cleancache__ ivy target with given parameters.
24
+ def cleancache(*params)
25
+ Ivy::Cleancache.new(ant).execute(*params)
26
+ end
27
+
28
+ # Calls the __settings__ ivy target with given parameters.
29
+ def settings(*params)
30
+ Ivy::Settings.new(ant).execute(*params)
31
+ end
32
+
33
+ # Calls the __configure__ ivy target with given parameters.
34
+ def configure(*params)
35
+ Ivy::Configure.new(ant).execute(*params)
36
+ end
37
+
38
+ # Calls the __info__ ivy target with given parameters and returns info as hash.
39
+ def info(*params)
40
+ Ivy::Info.new(ant).execute(*params)
41
+ end
42
+
43
+ # Calls the __buildnumber__ ivy target with given parameters and returns info as hash.
44
+ def buildnumber(*params)
45
+ Ivy::Buildnumber.new(ant).execute(*params)
46
+ end
47
+
48
+ # Calls the __listmodules__ ivy target with given parameters and returns info as hash.
49
+ def listmodules(*params) #:nodoc:
50
+ Ivy::Listmodules.new(ant).execute(*params)
51
+ end
52
+
53
+ # Calls the __makepom__ ivy target with given parameters and returns pom content.
54
+ def makepom(*params)
55
+ Ivy::Makepom.new(ant).execute(*params)
56
+ end
57
+
58
+ # Calls the __resolve__ ivy target with given parameters and returns info as hash.
59
+ def resolve(*params)
60
+ Ivy::Resolve.new(ant).execute(*params)
61
+ end
62
+
63
+ # Calls the __retrieve__ ivy target with given parameters.
64
+ def retrieve(*params)
65
+ Ivy::Retrieve.new(ant).execute(*params)
66
+ end
67
+
68
+ # Calls the __publish__ ivy target with given parameters.
69
+ def publish(*params)
70
+ Ivy::Publish.new(ant).execute(*params)
71
+ end
72
+
73
+ # Calls the __cachepath__ ivy target with given parameters and returns
74
+ # array containing absolute file paths to all artifacts contained in result
75
+ def cachepath(*params)
76
+ Ivy::Cachepath.new(ant).execute(*params)
77
+ end
78
+
79
+ # Calls the __findrevision__ ivy target with given parameters and returns
80
+ # array containing absolute file paths to all artifacts contained in result
81
+ def findrevision(*params)
82
+ Ivy::Findrevision.new(ant).execute(*params)
83
+ end
84
+
85
+ # Calls the __artifactproperty__ ivy target with given parameters and returns
86
+ # map with all defined properties
87
+ def artifactproperty(*params)
88
+ Ivy::Artifactproperty.new(ant).execute(*params)
89
+ end
90
+
91
+ # Calls the __buildlist__ ivy target with given parameters and returns
92
+ # the resulting buildlist
93
+ def buildlist(*params)
94
+ Ivy::Buildlist.new(ant).execute(*params)
95
+ end
96
+
97
+ # Calls the __artifactreport__ ivy target with given parameters and returns
98
+ # the created xml.
99
+ def artifactreport(*params)
100
+ Ivy::Artifactreport.new(ant).execute(*params)
101
+ end
102
+
103
+ # Calls the __report__ ivy target with given parameters
104
+ def report(*params)
105
+ Ivy::Report.new(ant).execute(*params)
106
+ end
107
+
108
+ # Used to get or set an ant properties
109
+ # [set] <tt>property['name'] = value</tt> sets the ant property with name to given value no overwrite
110
+ # [get] <tt>property[matcher]/tt> gets property that is equal via case equality operator (+===+)
111
+ def property
112
+ AntPropertyHelper.new(ant_properties)
113
+ end
114
+
115
+ # Returns the __antwrap__ instance to use for all internal calls creates a default
116
+ # instance if no instance has been set before.
117
+ def ant
118
+ @ant ||= ::Antwrap::AntProject.new(:ant_home => ant_home, :name => "ivy-ant",
119
+ :basedir => Dir.pwd, :declarative => true)
120
+ init(@ant) if should_init?
121
+ @ant
122
+ end
123
+
124
+ private
125
+ def should_init?
126
+ @init_done.nil? || @init_done == false
127
+ end
128
+
129
+ def init(ant)
130
+ @init_done = true
131
+ ant.property :name => 'ivy.project.dir', :value => project_dir
132
+ ant.path :id => 'ivy.lib.path' do
133
+ ant.fileset :dir => lib_dir, :includes => '*.jar'
134
+ end
135
+
136
+ ant.typedef :name => "ivy_settings", :classname => "org.apache.ivy.ant.IvyAntSettings", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader', :loaderRef => 'ivy.lib.path.loader'
137
+ ant.taskdef :name => "ivy_configure", :classname => "org.apache.ivy.ant.IvyConfigure", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
138
+ ant.taskdef :name => "ivy_resolve", :classname => "org.apache.ivy.ant.IvyResolve", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
139
+ ant.taskdef :name => "ivy_retrieve", :classname => "org.apache.ivy.ant.IvyRetrieve", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
140
+ ant.taskdef :name => "ivy_deliver", :classname => "org.apache.ivy.ant.IvyDeliver", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
141
+ ant.taskdef :name => "ivy_publish", :classname => "org.apache.ivy.ant.IvyPublish", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
142
+ ant.taskdef :name => "ivy_extract", :classname => "org.apache.ivy.ant.IvyExtractFromSources", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
143
+ ant.taskdef :name => "ivy_cachepath", :classname => "org.apache.ivy.ant.IvyCachePath", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
144
+ ant.taskdef :name => "ivy_cachefileset", :classname => "org.apache.ivy.ant.IvyCacheFileset", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
145
+ ant.taskdef :name => "ivy_report", :classname => "org.apache.ivy.ant.IvyReport", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
146
+ ant.taskdef :name => "ivy_repreport", :classname => "org.apache.ivy.ant.IvyRepositoryReport", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
147
+ ant.taskdef :name => "ivy_var", :classname => "org.apache.ivy.ant.IvyVar", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
148
+ ant.taskdef :name => "ivy_check", :classname => "org.apache.ivy.ant.IvyCheck", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
149
+ ant.taskdef :name => "ivy_artifactproperty", :classname => "org.apache.ivy.ant.IvyArtifactProperty", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
150
+ ant.taskdef :name => "ivy_buildlist", :classname => "org.apache.ivy.ant.IvyBuildList", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
151
+ ant.taskdef :name => "ivy_install", :classname => "org.apache.ivy.ant.IvyInstall", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
152
+ ant.taskdef :name => "ivy_convertpom", :classname => "org.apache.ivy.ant.IvyConvertPom", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
153
+ ant.taskdef :name => "ivy_makepom", :classname => "org.apache.ivy.ant.IvyMakePom", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
154
+ ant.taskdef :name => "ivy_artifactreport", :classname => "org.apache.ivy.ant.IvyArtifactReport", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
155
+ ant.taskdef :name => "ivy_info", :classname => "org.apache.ivy.ant.IvyInfo", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
156
+ ant.taskdef :name => "ivy_addpath", :classname => "org.apache.ivy.ant.AddPathTask", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
157
+ ant.taskdef :name => "ivy_listmodules", :classname => "org.apache.ivy.ant.IvyListModules", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
158
+ ant.taskdef :name => "ivy_findrevision", :classname => "org.apache.ivy.ant.IvyFindRevision", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
159
+ ant.taskdef :name => "ivy_buildnumber", :classname => "org.apache.ivy.ant.IvyBuildNumber", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
160
+ ant.taskdef :name => "ivy_cleancache", :classname => "org.apache.ivy.ant.IvyCleanCache", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
161
+ end
162
+
163
+ def ant_properties
164
+ ant.project.properties
165
+ end
166
+ end
167
+
168
+ AntPropertyHelper = Struct.new(:ant_properties) do #:nodoc:
169
+ def []=(name, value) #:nodoc:
170
+ ant_properties[name] = value
171
+ end
172
+
173
+ def [](matcher) #:nodoc:
174
+ ant_properties.find {|p| matcher === p[0] }[1]
175
+ end
176
+ end