Class: Maven::Tools::DSL::Jarfile

Inherits:
Object
  • Object
show all
Extended by:
Options
Defined in:
lib/maven/tools/dsl/jarfile.rb

Defined Under Namespace

Classes: ParentWithLock

Instance Method Summary collapse

Methods included from Options

args_and_options, fill_options, help_block

Constructor Details

#initialize(parent, file = 'Jarfile', skip_lock = false) ⇒ Jarfile

Returns a new instance of Jarfile.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/maven/tools/dsl/jarfile.rb', line 74

def initialize( parent, file = 'Jarfile', skip_lock = false )
  warn "DEPRECATED to have nil as parent" unless parent
  lockfile = JarfileLock.new( skip_lock ? nil : file )

  # the dependencies are only add if they are not locked
  @parent = ParentWithLock.new( parent, lockfile )

  # parse jarfile DSL
  eval( File.read( file ) )

  # fill dependencies from lockfile
  lockfile.coordinates.each do |d|
    a = Maven::Tools::Artifact.from_coordinate( d )
    add( a ) unless a[:systemPath]
  end
  scope( :test ) do
    lockfile.coordinates( :test ).each do |d|
      a = Maven::Tools::Artifact.from_coordinate( d )
      add( a ) unless a[:systemPath]
    end
  end
end

Instance Method Details

#add(artifact) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/maven/tools/dsl/jarfile.rb', line 97

def add( artifact )
  dep = Dependency.new

  # use the fill_options to fill up the dependency
  self.class.fill_options( dep, artifact, :type )

  # adjust the scope
  dep.scope = @scope if @scope

  # use the original parent if present
  (@parent.parent || @parent ).dependencies << dep
end

#artifactsObject



59
60
61
62
# File 'lib/maven/tools/dsl/jarfile.rb', line 59

def artifacts
  # TODO remove this part
  @artifacts ||= []
end

#helpObject



110
111
112
113
# File 'lib/maven/tools/dsl/jarfile.rb', line 110

def help
  warn "\n# Jarfile DSL #\n"
  warn self.class.help_block( :local => "path-to-local-jar", :jar => nil, :pom => nil, :repository => nil, :snapshot_repository => nil, :scope => nil)[0..-2]
end

#jar(*args, &block) ⇒ Object



123
124
125
126
127
128
# File 'lib/maven/tools/dsl/jarfile.rb', line 123

def jar( *args, &block )
  a = DependencyDSL.create( @parent, :jar, @scope, *args, &block )
  # TODO remove this part
  artifacts << a
  a
end

#jruby(*args, &block) ⇒ Object



159
160
161
162
163
164
165
166
# File 'lib/maven/tools/dsl/jarfile.rb', line 159

def jruby( *args, &block )
  warn "DEPRECATED jruby declaration has no effect anymore"
  # if args.empty? && !block
  #   @jruby ? @jruby.legacy_version : nil
  # else
  #   @jruby = JRubyDSL.create( @parent, :provided, *args, &block )
  # end
end

#local(path) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/maven/tools/dsl/jarfile.rb', line 115

def local( path )
  a = Artifact.new_local( ::File.expand_path( path ), :jar )
  add( a )
  # TODO remove this part
  artifacts << a
  a
end

#pom(*args, &block) ⇒ Object



130
131
132
133
134
135
# File 'lib/maven/tools/dsl/jarfile.rb', line 130

def pom( *args, &block )
  a = DependencyDSL.create( @parent, :pom, @scope, *args, &block )
  # TODO remove this part
  artifacts << a
  a
end

#repositoriesObject



64
65
66
67
# File 'lib/maven/tools/dsl/jarfile.rb', line 64

def repositories
  # TODO remove this part
  @repositories ||= []
end

#repository(name, url = nil) ⇒ Object Also known as: source



144
145
146
147
148
149
# File 'lib/maven/tools/dsl/jarfile.rb', line 144

def repository( name, url = nil )
  if url.nil?
    url = name
  end
  repositories << { :name => name.to_s, :url => url }
end

#scope(scope) ⇒ Object



152
153
154
155
156
157
# File 'lib/maven/tools/dsl/jarfile.rb', line 152

def scope( scope )
  @scope = scope
  yield if block_given?
ensure
  @scope = nil
end

#snapshot_repositoriesObject



69
70
71
72
# File 'lib/maven/tools/dsl/jarfile.rb', line 69

def snapshot_repositories
  # TODO remove this part
  @snapshot_repositories ||= []
end

#snapshot_repository(name, url = nil) ⇒ Object



137
138
139
140
141
142
# File 'lib/maven/tools/dsl/jarfile.rb', line 137

def snapshot_repository( name, url = nil )
  if url.nil?
    url = name
  end
  snapshot_repositories << { :name => name.to_s, :url => url }
end