Module: MiniAether::Helper

Included in:
Bootstrap, Resolver
Defined in:
lib/mini_aether/helper.rb

Constant Summary collapse

System =
Java::JavaLang::System

Instance Method Summary collapse

Instance Method Details

#interpolate(str) ⇒ Object

Interpolate variables like ${user.home} and ${env.HOME} from system properties and environment variables respectively.



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
# File 'lib/mini_aether/helper.rb', line 25

def interpolate(str)
  ret = ''

  s = StringScanner.new(str)
  pos = s.pos

  while s.scan_until(/\$\{[^\s}]+\}/) # match ${stuff}
    # add the pre_match, but only starting from previous position
    ret << str.slice(pos, (s.pos - pos - s.matched.size))

    # interpolate
    var = s.matched.slice(2..-2)
    ret << case var
           when /^env\.(.*)/
             ENV[$1] || ''
           else
             System.getProperty(var) || ''
           end

    pos = s.pos
  end
  ret << s.rest
  
  ret
end

#jar_path(dep) ⇒ String

Build a m2 repository path fragment for dep. For example, coordinates of com.example:project:1.0.1 would result in com/example/project/1.0.1/project-1.0.1.jar.

Parameters:

  • dep (Hash)

    a hash with keys :group_id, :artifact_id, and :version

Returns:

  • (String)

    a path fragment to this artifact in m2 repository format



57
58
59
60
61
62
63
64
65
# File 'lib/mini_aether/helper.rb', line 57

def jar_path(dep)
  group_id = dep[:group_id]
  group_path = group_id.gsub('.', '/')
  artifact_id = dep[:artifact_id]
  version = dep[:version]

  file_name = "#{artifact_id}-#{version}.jar"
  "#{group_path}/#{artifact_id}/#{version}/#{file_name}"
end

#local_repository_pathObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mini_aether/helper.rb', line 5

def local_repository_path
  default_local_repo_path =
    File.join(System.getProperty('user.home'), '.m2', 'repository')

  if File.exists? M2_SETTINGS
    xml = File.read M2_SETTINGS
    begin
      parser = XmlParser.new(xml)
      parser.pull_to_path(:settings, :localRepository)
      interpolate(parser.pull_text_until_end.strip)
    rescue XmlParser::NotFoundError
      default_local_repo_path
    end
  else
    default_local_repo_path
  end
end