File: lock.rb

package info (click to toggle)
ruby-jar-dependencies 0.3.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 232 kB
  • sloc: ruby: 1,325; xml: 14; makefile: 9
file content (76 lines) | stat: -rw-r--r-- 1,586 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'jars/maven_exec'

module Jars
  class JarDetails < Array

    def scope
      self[ -2 ].to_sym
    end

    def file
      file = self[ -1 ].strip
      file.empty? ? path : file
    end

    def group_id
      self[ 0 ]
    end

    def artifact_id
      self[ 1 ]
    end

    def version
      self[ -3 ]
    end

    def classifier
      size == 5 ? nil : self[ 2 ]
    end

    def gacv
      classifier ? self[ 0..3 ] : self[ 0..2 ]
    end

    def path
      if scope == :system
        # replace maven like system properties embedded into the string
        self[ -1 ].gsub( /\$\{[a-zA-Z.]+\}/ ) do |a|
          ENV_JAVA[ a[2..-2] ] || a
        end
      else
        File.join( Jars.home, group_id.gsub(/[.]/, '/'), artifact_id, version, gacv[ 1..-1 ].join( '-' ) + '.jar' )
      end
    end
  end

  class Lock

    def initialize( file )
      @file = file
    end

    def process( scope )
      scope ||= :runtime
      File.read( @file ).each_line do |line|
        next if not line =~ /:.+:/
        jar = JarDetails.new( line.strip.sub( /:jar:/, ':' ).sub( /:$/, ': ' ).split( /:/ ) )
        case scope
        when :all
          yield jar
        when :compile
          # jar.scope is maven scope
          yield jar if jar.scope != :test
        when :provided
          # jar.scope is maven scope
          yield jar if jar.scope == :provided
        when :runtime
          # jar.scope is maven scope
          yield jar if jar.scope != :test and jar.scope != :provided
        when :test
          yield jar
        end
      end
    end
  end
end