Class: Maven::Tools::Jarfile

Inherits:
Object
  • Object
show all
Includes:
Coordinate
Defined in:
lib/maven/tools/jarfile.rb

Defined Under Namespace

Classes: DSL, LockedParent

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Coordinate

#gav, #group_artifact, #to_coordinate, #to_split_coordinate, #to_split_coordinate_with_scope, #to_version

Constructor Details

#initialize(file = 'Jarfile') ⇒ Jarfile

Returns a new instance of Jarfile.



32
33
34
35
# File 'lib/maven/tools/jarfile.rb', line 32

def initialize(file = 'Jarfile')
  @file = file
  @lockfile = file + ".lock"
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



36
37
38
# File 'lib/maven/tools/jarfile.rb', line 36

def file
  @file
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/maven/tools/jarfile.rb', line 42

def exists?
  ::File.exists?(@file)
end

#exists_lock?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/maven/tools/jarfile.rb', line 50

def exists_lock?
  ::File.exists?(@lockfile)
end

#generate_lockfile(dependency_coordinates) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
# File 'lib/maven/tools/jarfile.rb', line 217

def generate_lockfile(dependency_coordinates)
  if dependency_coordinates.empty?
    FileUtils.rm_f(@lockfile) if exists_lock?
  else
    ::File.open(@lockfile, 'w') do |f|
      dependency_coordinates.each do |d|
        f.puts d.to_s unless d.to_s =~ /^ruby.bundler:/
      end
    end
  end
end

#load_lockfileObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/maven/tools/jarfile.rb', line 54

def load_lockfile
  _locked = []
  if exists_lock?
    ::File.read(@lockfile).each_line do |line|
      line.strip!
      if line.size > 0 && !(line =~ /^\s*#/)
        _locked << line
      end
    end
  end
  _locked
end

#lockedObject



67
68
69
# File 'lib/maven/tools/jarfile.rb', line 67

def locked
  @locked ||= load_lockfile
end

#locked?(coordinate) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/maven/tools/jarfile.rb', line 71

def locked?(coordinate)
  coord = coordinate.sub(/^([^:]+:[^:]+):.+/) { $1 }
  locked.detect { |l| l.sub(/^([^:]+:[^:]+):.+/) { $1 } == coord } != nil
end

#mtimeObject



38
39
40
# File 'lib/maven/tools/jarfile.rb', line 38

def mtime
  ::File.mtime(@file)
end

#mtime_lockObject



46
47
48
# File 'lib/maven/tools/jarfile.rb', line 46

def mtime_lock
  ::File.mtime(@lockfile)
end

#populate_locked(container) ⇒ Object



213
214
215
# File 'lib/maven/tools/jarfile.rb', line 213

def populate_locked(container)
  locked.each { |l| container.add_artifact(l) }
end

#populate_unlocked(container = nil, &block) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/maven/tools/jarfile.rb', line 179

def populate_unlocked( container = nil, &block )
  warn 'DEPRECATED use Maven::Tools::DSL::Jarfile instead'
  if ::File.exists?(@file)
    dsl = Maven::Tools::DSL::Jarfile.new( nil, @file )

    if block
      block.call( dsl )
    end
    # TODO all that container stuff needs to go into jbundler !!!
    if container
      dsl.artifacts.each do |a|
        if path = a[ :system_path ]
          container.add_local_jar( path )
        elsif not locked?( coord = a.to_coordinate )
          if exclusions = a.exclusions
            container.add_artifact_with_exclusions( coord,
                                                    exclusions )
          else
            container.add_artifact( coord )
          end
        end
      end
      dsl.repositories.each do |repo|
        container.add_repository( repo[ :name ] || repo[ 'name' ],
                                  repo[ :url ] || repo[ 'url' ] )
      end
      dsl.snapshot_repositories.each do |repo|
        container.add_snapshot_repository( repo[ :name ] || repo[ 'name' ],
                                           repo[ :url ] || repo[ 'url' ] )
      end
    end
  end
end

#setup_locked(parent) ⇒ Object



174
175
176
177
# File 'lib/maven/tools/jarfile.rb', line 174

def setup_locked( parent )
  warn 'DEPRECATED use Maven::Tools::DSL::Jarfile instead'
  Maven::Tools::DSL::Jarfile.new( LockedParent.new( parent ), @file )
end

#setup_unlocked(parent) ⇒ Object



169
170
171
172
# File 'lib/maven/tools/jarfile.rb', line 169

def setup_unlocked( parent )
  warn 'DEPRECATED use Maven::Tools::DSL::Jarfile instead'
  Maven::Tools::DSL::Jarfile.new( parent, @file )
end