Sha256: d0064a8f55e08f6674bbc41b07ca7738ff6c4987bf43d4afab8550f89fa205ad

Contents?: true

Size: 1.73 KB

Versions: 6

Compression:

Stored size: 1.73 KB

Contents

require 'maven/tools/coordinate'
module Maven
  module Tools

    class Jarfile
      include Coordinate

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

      def mtime
        File.mtime(@file)
      end

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

      def mtime_lock
        File.mtime(@lockfile)
      end

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

      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

      def locked
        @locked ||= load_lockfile
      end

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

      def populate_unlocked(aether)
        File.read(@file).each_line do |line| 
          if coord = to_coordinate(line)
            unless locked?(coord)
              aether.add_artifact(coord)
            end
          elsif line =~ /^\s*(repository|source)\s/
            name, url = line.sub(/.*(repository|source)\s+/, '').gsub(/['":]/,'').split(/,/)
            url = name unless url
            aether.add_repository(name, url)
          end
        end
      end

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

      def generate_lockfile(dependency_coordinates)
        File.open(@lockfile, 'w') do |f|
          dependency_coordinates.each do |d|
            f.puts d.to_s
          end
        end
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
maven-tools-0.31.0 lib/maven/tools/jarfile.rb~
maven-tools-0.30.0 lib/maven/tools/jarfile.rb~
maven-tools-0.29.3 lib/maven/tools/jarfile.rb~
maven-tools-0.29.2 lib/maven/tools/jarfile.rb~
maven-tools-0.29.1 lib/maven/tools/jarfile.rb~
maven-tools-0.29.0 lib/maven/tools/jarfile.rb~