Module: BuildrDependencyExtensions::TransitiveDependencies

Includes:
Extension
Defined in:
lib/buildr-dependency-extensions/transitive-buildr.rb

Class Method Summary collapse

Class Method Details

.add_dependency(project, new_dependencies, dependency, scopes, depth = 0) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/buildr-dependency-extensions/transitive-buildr.rb', line 93

def add_dependency project, new_dependencies, dependency, scopes, depth = 0
  scopes.each do |scope|
    if (!@dependency_pom_cache[dependency])
      @dependency_pom_cache[dependency] = POM.load(dependency.pom)
    end
    @dependency_pom_cache[dependency].declared_dependencies([scope]).each do |dep|
      artifact = project.artifact(dep)
      excludes = dependency.instance_variable_get(:@excludes) || []
      matching_dependency = excludes.select do |excluded_dep|
        excluded_dep.to_hash[:id] == artifact.to_hash[:id] &&
          excluded_dep.to_hash[:group] == artifact.to_hash[:group]
      end
      add_dependency project, new_dependencies, artifact, scopes, (depth + 1) if matching_dependency.empty?
    end
  end
  class << dependency
    attr_accessor :depth
  end
  dependency.depth = depth
  new_dependencies << dependency
end

.extended(base) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/buildr-dependency-extensions/transitive-buildr.rb', line 11

def self.extended(base)
  class << base

    attr_accessor :transitive_scopes
    attr_accessor :cache_dependencies

    def conflict_resolver
      # @conflict_resolver ||= HighestVersionConflictResolver.new
      @conflict_resolver ||= MavenVersionConflictResolver.new
    end
  end
  super
end

.resolve_compile_dependencies(project) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/buildr-dependency-extensions/transitive-buildr.rb', line 58

def resolve_compile_dependencies project
  original_file_tasks   = project.compile.dependencies.reject {|dep| HelperFunctions.is_artifact? dep }
  original_dependencies = project.compile.dependencies.select {|dep| HelperFunctions.is_artifact? dep }
  new_dependencies = []
  original_dependencies.each do |dependency|
    add_dependency project, new_dependencies, dependency, [nil, "compile"]
  end
  new_dependencies = resolve_conflicts(project, new_dependencies.uniq)
  project.compile.dependencies = new_dependencies + original_file_tasks
end

.resolve_conflicts(project, dependencies) ⇒ Object



115
116
117
118
119
120
121
122
123
# File 'lib/buildr-dependency-extensions/transitive-buildr.rb', line 115

def resolve_conflicts project, dependencies
  unique_transitive_artifacts = HelperFunctions.get_unique_group_artifact(dependencies)
  new_scope_artifacts = unique_transitive_artifacts.map do |artifact|
    artifact_hash = Artifact.to_hash(artifact)
    artifact_hash[:version] = project.conflict_resolver.resolve(artifact, dependencies)
    project.artifact(Artifact.to_spec(artifact_hash))
  end
  new_scope_artifacts
end

.resolve_runtime_dependencies(project) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/buildr-dependency-extensions/transitive-buildr.rb', line 69

def resolve_runtime_dependencies project
  original_file_tasks   = project.run.classpath.reject {|dep| HelperFunctions.is_artifact? dep }
  original_dependencies = project.run.classpath.select {|dep| HelperFunctions.is_artifact? dep }
  new_dependencies = []
  original_dependencies.each do |dependency|
    add_dependency project, new_dependencies, dependency, [nil, "compile", "runtime"]
  end
  new_dependencies = resolve_conflicts(project, new_dependencies.uniq)
  project.run.classpath = new_dependencies + original_file_tasks
end

.resolve_test_dependencies(project) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/buildr-dependency-extensions/transitive-buildr.rb', line 80

def resolve_test_dependencies project
  original_file_tasks   = project.test.dependencies.reject {|dep| HelperFunctions.is_artifact? dep }
  original_test_compile_file_tasks = project.test.compile.dependencies.reject {|dep| HelperFunctions.is_artifact? dep }
  original_dependencies = project.test.dependencies.select {|dep| HelperFunctions.is_artifact? dep }
  new_dependencies = []
  original_dependencies.each do |dependency|
    add_dependency project, new_dependencies, dependency, [nil, "compile", "runtime"]
  end
  new_dependencies = resolve_conflicts(project, new_dependencies.uniq)
  project.test.dependencies = new_dependencies + original_file_tasks
  project.test.compile.dependencies = new_dependencies + original_test_compile_file_tasks
end