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.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/maven/tools/dsl/jarfile.rb', line 79

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



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/maven/tools/dsl/jarfile.rb', line 102

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



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

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

#helpObject



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

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



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

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

#jruby(*args, &block) ⇒ Object



166
167
168
169
170
171
172
173
# File 'lib/maven/tools/dsl/jarfile.rb', line 166

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



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

def local( path )
  jar_path = ::File.expand_path( path )
  jar_path.sub!( /#{@parent.basedir}/, '${basedir}' )
  a = Artifact.new_local( jar_path, :jar )
  add( a )
  # TODO remove this part
  artifacts << a
  a
end

#pom(*args, &block) ⇒ Object



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

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

#repositoriesObject



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

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

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



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

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

#scope(scope) ⇒ Object



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

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

#snapshot_repositoriesObject



74
75
76
77
# File 'lib/maven/tools/dsl/jarfile.rb', line 74

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

#snapshot_repository(name, url = nil) ⇒ Object



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

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