Class: Maven::Tools::Jarfile

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

Defined Under Namespace

Classes: DSL

Instance Method Summary collapse

Methods included from Coordinate

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

Constructor Details

#initialize(file = 'Jarfile') ⇒ Jarfile

Returns a new instance of Jarfile.



30
31
32
33
# File 'lib/maven/tools/jarfile.rb', line 30

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

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


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

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

#exists_lock?Boolean

Returns:

  • (Boolean)


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

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

#generate_lockfile(dependency_coordinates) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
# File 'lib/maven/tools/jarfile.rb', line 193

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



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/maven/tools/jarfile.rb', line 51

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



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

def locked
  @locked ||= load_lockfile
end

#locked?(coordinate) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#mtimeObject



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

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

#mtime_lockObject



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

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

#populate_locked(container) ⇒ Object



189
190
191
# File 'lib/maven/tools/jarfile.rb', line 189

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

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



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/maven/tools/jarfile.rb', line 155

def populate_unlocked( container = nil, &block )
  if ::File.exists?(@file)
    dsl = DSL.new
    dsl.eval_file( @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