Class: Bee::Task::BeeDependencyResolver

Inherits:
BaseDependencyResolver show all
Defined in:
lib/dependency_resolver.rb

Overview

Bee dependency resolver.

Constant Summary collapse

DEFAULT_REPOSITORY =

Default repository address.

'http://repo1.maven.org/maven2'
DEFAULT_CACHE =

Default cache location.

File.expand_path('~/.java/dependencies')

Instance Method Summary collapse

Methods inherited from BaseDependencyResolver

#classpath, #dependencies

Constructor Details

#initialize(file, scope, verbose = false) ⇒ BeeDependencyResolver

Constructor:

  • file: dependency file (should be maven.xml).

  • scope: the scope for dependencies (compile, runtime or test).

  • verbose: tells if we should be verbose.



252
253
254
255
# File 'lib/dependency_resolver.rb', line 252

def initialize(file, scope, verbose=false)
  super(file, scope, verbose)
  @cache = DEFAULT_CACHE
end

Instance Method Details

#build_path(root, dependency) ⇒ Object

Build a Maven path.

  • root: the path root (root directory for repository or cache).

  • dependency: dependency as a map.

Return: path as a string.



303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/dependency_resolver.rb', line 303

def build_path(root, dependency)
  groupid = dependency[:groupid].split('.').join('/')
  artifactid = dependency[:artifactid]
  version = dependency[:version]
  type = dependency[:type] || 'jar'
  classifier = dependency[:classifier]
  if classifier
    return "#{root}/#{groupid}/#{artifactid}/#{version}/#{artifactid}-#{version}-#{classifier}.#{type}"
  else
    return "#{root}/#{groupid}/#{artifactid}/#{version}/#{artifactid}-#{version}.#{type}"
  end        
end

#parse_dependencies(source) ⇒ Object

Extract dependencies from a file.

  • source: file source.

Return: dependencies as a list of maps with keys groupid, artifactid, version, type, optional.



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/dependency_resolver.rb', line 261

def parse_dependencies(source)
  dependencies = YAML::load(source)
  new_dependencies = []
  for dependency in dependencies
    if dependency['group']
      if Array(dependency['scope']).include?(@scope) or !dependency['scope']
        new_dependency = {}
        for key in dependency.keys
          if key != 'group' and key != 'artifact'
            new_dependency[key.to_sym] = dependency[key]
          elsif key == 'group'
            new_dependency[:groupid] = dependency['group']
          elsif key == 'artifact'
            new_dependency[:artifactid] = dependency['artifact']
          end
        end
        new_dependencies << new_dependency
      end
    end
  end
  return new_dependencies
end

#parse_repositoriesObject

Extract repository list from file. Return: repository list.



286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/dependency_resolver.rb', line 286

def parse_repositories
  repositories = YAML::load(File.read(@file))
  new_repositories = []
  for repository in repositories
    if repository['repository']
      new_repositories << repository['repository']
    elsif repository['repositories']
      new_repositories = new_repositories + repository['repositories']
    end
  end
  return new_repositories
end