Class: Warbler::WebServer::Artifact

Inherits:
Struct
  • Object
show all
Defined in:
lib/warbler/web_server.rb

Constant Summary collapse

@@local_repository =
nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#artifact_idObject

Returns the value of attribute artifact_id

Returns:

  • (Object)

    the current value of artifact_id



3
4
5
# File 'lib/warbler/web_server.rb', line 3

def artifact_id
  @artifact_id
end

#group_idObject

Returns the value of attribute group_id

Returns:

  • (Object)

    the current value of group_id



3
4
5
# File 'lib/warbler/web_server.rb', line 3

def group_id
  @group_id
end

#repoObject

Returns the value of attribute repo

Returns:

  • (Object)

    the current value of repo



3
4
5
# File 'lib/warbler/web_server.rb', line 3

def repo
  @repo
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



3
4
5
# File 'lib/warbler/web_server.rb', line 3

def version
  @version
end

Instance Method Details

#cached_pathObject



9
10
11
# File 'lib/warbler/web_server.rb', line 9

def cached_path
  @cached_path ||= File.join(local_repository, path_fragment)
end

#download_urlObject



13
14
15
# File 'lib/warbler/web_server.rb', line 13

def download_url
  @download_url ||= "#{repo}/#{path_fragment}" #:nocov:
end

#local_pathObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/warbler/web_server.rb', line 17

def local_path
  unless File.exist?(cached_path)
    puts "Downloading #{artifact_id}-#{version}.jar" #:nocov:
    FileUtils.mkdir_p File.dirname(cached_path) #:nocov:
    require 'open-uri'                    #:nocov:
    begin
      open(download_url) do |stream|        #:nocov:
        File.open(cached_path, "wb") do |f| #:nocov:
          while buf = stream.read(4096) #:nocov:
            f << buf                    #:nocov:
          end                           #:nocov:
        end                             #:nocov:
      end                               #:nocov:
    rescue => e
      e.message.concat " - #{download_url}"
      raise e
    end
  end
  cached_path
end

#local_repositoryObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/warbler/web_server.rb', line 40

def local_repository
  @@local_repository ||= begin
    m2_home = File.join(user_home, '.m2')
    if File.exist?(settings = File.join(m2_home, 'settings.xml'))
      local_repo = detect_local_repository(settings)
    end
    if local_repo.nil? && mvn_home = ENV['M2_HOME'] || ENV['MAVEN_HOME']
      if File.exist?(settings = File.join(mvn_home, 'conf/settings.xml'))
        local_repo = detect_local_repository(settings)
      end
    end
    local_repo || File.join(m2_home, 'repository')
  end
end

#path_fragmentObject



5
6
7
# File 'lib/warbler/web_server.rb', line 5

def path_fragment
  @path_fragment ||= "#{group_id.gsub('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}.jar"
end