Class: Ivy4r

Inherits:
Object
  • Object
show all
Defined in:
lib/ivy4r.rb,
lib/ivy4r/version.rb,
lib/ivy4r_java_extensions.rb

Overview

Simple wrapper that maps the ant ivy targets one to one to ruby. See the Apache Ivy for more informations about the parameters for a call. All ivy ant targets have the equivalent name in this class.

The standard parameters are provided as Hash, i.e.:

<ivy:configure file="settings.xml" settingsId="my.id" />

is

ivy4r.configure :file => "settings.xml", :settingsId => 'my.id'

You can use nested options via the nested attribute:

<ivy:buildlist reference="testpath">
  <fileset dir="target/p1" includes="buildfile" />
</ivy:buildlist>

is

@ivy4r.buildlist :reference => 'testpath', :nested => {
  :fileset => {:dir => 'target/p1', :includes => 'buildfile'}
}

you can nest more than on element of the same type using an array:

<ivy:buildlist reference="testpath">
  <fileset dir="target/sub" includes="**/buildfile" />
  <fileset dir="target/p1" includes="buildfile" />
</ivy:buildlist>

is

@ivy4r.buildlist :reference => 'testpath', :nested => {
  :fileset => [
    {:dir => 'target/sub', :includes => '**/buildfile'},
    {:dir => 'target/p1', :includes => 'buildfile'}
  ]
}

Constant Summary collapse

VERSION =
"0.12.10"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ant_instance = nil, &block) ⇒ Ivy4r

Initalizes ivy4r with optional ant wrapper object. Sets ant home dir and ivy lib dir to default values from Ivy4rJars gem.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ivy4r.rb', line 66

def initialize(ant_instance = nil, &block)
  @ant_home = ::Ivy4rJars.ant_home_dir
  @lib_dir = ::Ivy4rJars.lib_dir
  @project_dir = @lib_dir
  @environment_property = 'env'
  @ant = ant_instance
  
  if block
    if block.arity > 1
      raise ArgumentError, "To many arguments expected=1 given=#{block.arity}"
    elsif block.arity == 1
      yield self
    else
      instance_eval(&block)
    end
  end
end

Instance Attribute Details

#antObject

Returns the __antwrap__ instance to use for all internal calls creates a default instance if no instance has been set before.



56
57
58
# File 'lib/ivy4r.rb', line 56

def ant
  @ant
end

#ant_homeObject

Set the ant home directory to load ant classes from if no custom __antwrap__ is provided and the default provided ant version 1.7.1 should not be used. Must be set before any call to method that uses the ivy is made.



42
43
44
# File 'lib/ivy4r.rb', line 42

def ant_home
  @ant_home
end

#cache_dirObject

Donates the base directory for the cached files, if nil no caching is enabled



62
63
64
# File 'lib/ivy4r.rb', line 62

def cache_dir
  @cache_dir
end

#environment_propertyObject

The ant property name to use for references to environment properties in ant and ivy, defaults to ‘env’



53
54
55
# File 'lib/ivy4r.rb', line 53

def environment_property
  @environment_property
end

#lib_dirObject

Defines the directory to load ivy libs and its dependencies from



45
46
47
# File 'lib/ivy4r.rb', line 45

def lib_dir
  @lib_dir
end

#project_dirObject

Optional ant variable ivy.project.dir to add to ant environment before loading ivy defaults to the lib_dir



49
50
51
# File 'lib/ivy4r.rb', line 49

def project_dir
  @project_dir
end

#settings_fileObject

Access to ivy settings set via configure or settings method.



59
60
61
# File 'lib/ivy4r.rb', line 59

def settings_file
  @settings_file
end

Instance Method Details

#ant_referencesObject

Returns the ant references, note that this are java objects.



27
28
29
# File 'lib/ivy4r_java_extensions.rb', line 27

def ant_references
  ant.project.references
end

#artifactproperty(*params) ⇒ Object

Calls the __artifactproperty__ ivy target with given parameters and returns map with all defined properties



159
160
161
# File 'lib/ivy4r.rb', line 159

def artifactproperty(*params)
  Ivy::Artifactproperty.new(ant, cache_dir).execute(*params)
end

#artifactreport(*params) ⇒ Object

Calls the __artifactreport__ ivy target with given parameters and returns the created xml.



171
172
173
# File 'lib/ivy4r.rb', line 171

def artifactreport(*params)
  Ivy::Artifactreport.new(ant, cache_dir).execute(*params)
end

#buildlist(*params) ⇒ Object

Calls the __buildlist__ ivy target with given parameters and returns the resulting buildlist



165
166
167
# File 'lib/ivy4r.rb', line 165

def buildlist(*params)
  Ivy::Buildlist.new(ant, cache_dir).execute(*params)
end

#buildnumber(*params) ⇒ Object

Calls the __buildnumber__ ivy target with given parameters and returns info as hash.



111
112
113
# File 'lib/ivy4r.rb', line 111

def buildnumber(*params)
  Ivy::Buildnumber.new(ant, cache_dir).execute(*params)
end

#cachepath(*params) ⇒ Object

Calls the __cachepath__ ivy target with given parameters and returns array containing absolute file paths to all artifacts contained in result



142
143
144
# File 'lib/ivy4r.rb', line 142

def cachepath(*params)
  Ivy::Cachepath.new(ant, cache_dir).execute(*params)
end

#cleancache(*params) ⇒ Object

Calls the __cleancache__ ivy target with given parameters.



85
86
87
# File 'lib/ivy4r.rb', line 85

def cleancache(*params)
  Ivy::Cleancache.new(ant, cache_dir).execute(*params)
end

#configure(*params) ⇒ Object

Calls the __configure__ ivy target with given parameters.



98
99
100
101
102
103
# File 'lib/ivy4r.rb', line 98

def configure(*params)
  configure_task = Ivy::Configure.new(ant, nil) # do not cache configure
  result = configure_task.execute(*params)
  @settings_file = configure_task.params[:file]
  result
end

#findrevision(*params) ⇒ Object

Calls the __findrevision__ ivy target with given parameters and returns array containing absolute file paths to all artifacts contained in result



148
149
150
# File 'lib/ivy4r.rb', line 148

def findrevision(*params)
  Ivy::Findrevision.new(ant, cache_dir).execute(*params)
end

#info(*params) ⇒ Object

Calls the __info__ ivy target with given parameters and returns info as hash.



106
107
108
# File 'lib/ivy4r.rb', line 106

def info(*params)
  Ivy::Info.new(ant, cache_dir).execute(*params)
end

#install(*params) ⇒ Object

Calls the __install__ ivy target with given parameters always returns nil



153
154
155
# File 'lib/ivy4r.rb', line 153

def install(*params)
  Ivy::Install.new(ant, cache_dir).execute(*params)
end

#ivy_instanceObject

Returns the ivy instance for underlying ant project with the current ivy settings.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ivy4r_java_extensions.rb', line 10

def ivy_instance
  unless @ivy_instance
    variable_container = Java::OrgApacheIvyAnt::IvyAntVariableContainer.new(ant.project)
    settings_file = find_settings_file(variable_container) unless settings_file
    raise "no settings file set and no default settings found, cannot create ivy instance" unless settings_file
    raise "settings file does not exist: #{settings_file}" unless File.exists? settings_file

    settings = Java::OrgApacheIvyCoreSettings::IvySettings.new(variable_container)
    settings.base_dir = ant.project.base_dir
    @ivy_instance = Java::OrgApacheIvy::Ivy.new_instance(settings)
    @ivy_instance.configure(Java::JavaIo::File.new(settings_file))
  end

  @ivy_instance
end

#listmodules(*params) ⇒ Object

Calls the __listmodules__ ivy target with given parameters and returns info as hash.



116
117
118
# File 'lib/ivy4r.rb', line 116

def listmodules(*params) #:nodoc:
  Ivy::Listmodules.new(ant, cache_dir).execute(*params)
end

#makepom(*params) ⇒ Object

Calls the __makepom__ ivy target with given parameters and returns pom content.



121
122
123
# File 'lib/ivy4r.rb', line 121

def makepom(*params)
  Ivy::Makepom.new(ant, cache_dir).execute(*params)
end

#propertyObject

Used to get or set ant properties.

set

property['name'] = value sets the ant property with name to given value no overwrite

get

property[matcher] gets property that is equal via case equality operator (===)



183
184
185
# File 'lib/ivy4r.rb', line 183

def property
  AntPropertyHelper.new(ant, ant_properties)
end

#publish(*params) ⇒ Object

Calls the __publish__ ivy target with given parameters.



136
137
138
# File 'lib/ivy4r.rb', line 136

def publish(*params)
  Ivy::Publish.new(ant, cache_dir).execute(*params)
end

#report(*params) ⇒ Object

Calls the __report__ ivy target with given parameters



176
177
178
# File 'lib/ivy4r.rb', line 176

def report(*params)
  Ivy::Report.new(ant, cache_dir).execute(*params)
end

#resolve(*params) ⇒ Object

Calls the __resolve__ ivy target with given parameters and returns info as hash.



126
127
128
# File 'lib/ivy4r.rb', line 126

def resolve(*params)
  Ivy::Resolve.new(ant, cache_dir).execute(*params)
end

#retrieve(*params) ⇒ Object

Calls the __retrieve__ ivy target with given parameters.



131
132
133
# File 'lib/ivy4r.rb', line 131

def retrieve(*params)
  Ivy::Retrieve.new(ant, cache_dir).execute(*params)
end

#settings(*params) ⇒ Object

Calls the __settings__ ivy target with given parameters.



90
91
92
93
94
95
# File 'lib/ivy4r.rb', line 90

def settings(*params)
  settings_task = Ivy::Settings.new(ant, nil) # do not cache settings
  result = settings_task.execute(*params)
  @settings_file = settings_task.params[:file]
  result
end