Class: Licensed::Sources::Gradle
- Inherits:
-
Source
- Object
- Source
- Licensed::Sources::Gradle
show all
- Defined in:
- lib/licensed/sources/gradle.rb
Defined Under Namespace
Classes: Dependency
Constant Summary
collapse
- DEFAULT_CONFIGURATIONS =
["runtime", "runtimeClasspath"].freeze
- GRADLE_LICENSES_PATH =
".gradle-licenses".freeze
Instance Attribute Summary
Attributes inherited from Source
#config
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Source
#dependencies, full_type, #ignored?, inherited, #initialize, register_source, type, type_and_version
Class Method Details
.add_gradle_license_report_plugins_block(gradle_build_file) ⇒ Object
125
126
127
128
129
130
131
132
133
|
# File 'lib/licensed/sources/gradle.rb', line 125
def self.add_gradle_license_report_plugins_block(gradle_build_file)
if gradle_build_file.include? "plugins"
gradle_build_file.gsub(/(?<=plugins)\s+{/, " { id 'com.github.jk1.dependency-license-report' version '1.16'")
else
gradle_build_file = " plugins { id 'com.github.jk1.dependency-license-report' version '1.16' }" + gradle_build_file
end
end
|
.gradle_command(*args, path:, executable:, configurations:) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/licensed/sources/gradle.rb', line 135
def self.gradle_command(*args, path:, executable:, configurations:)
gradle_build_file = File.read("build.gradle")
if !gradle_build_file.include? "dependency-license-report"
gradle_build_file = Licensed::Sources::Gradle.add_gradle_license_report_plugins_block(gradle_build_file)
end
Dir.chdir(path) do
Tempfile.create(["license-", ".gradle"], path) do |f|
f.write(gradle_build_file)
f.write gradle_file(configurations)
f.close
Licensed::Shell.execute(executable, "-q", "-b", f.path, *args)
end
end
end
|
.gradle_file(configurations) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/licensed/sources/gradle.rb', line 152
def self.gradle_file(configurations)
"\n import com.github.jk1.license.render.CsvReportRenderer\n import com.github.jk1.license.filter.LicenseBundleNormalizer\n\n final configs = \#{configurations.inspect}\n\n licenseReport {\n configurations = configs\n outputDir = \"$projectDir/\#{GRADLE_LICENSES_PATH}\"\n renderers = [new CsvReportRenderer()]\n filters = [new LicenseBundleNormalizer()]\n }\n\n task printDependencies {\n doLast {\n def dependencies = []\n configs.each {\n configurations[it].resolvedConfiguration.resolvedArtifacts.each { artifact ->\n def id = artifact.moduleVersion.id\n dependencies << \" { \\\\\"group\\\\\": \\\\\"${id.group}\\\\\", \\\\\"name\\\\\": \\\\\"${id.name}\\\\\", \\\\\"version\\\\\": \\\\\"${id.version}\\\\\" }\"\n }\n }\n println \"[\\\\n${dependencies.join(\", \")}\\\\n]\"\n }\n }\n EOF\nend\n"
|
Instance Method Details
#enabled? ⇒ Boolean
82
83
84
|
# File 'lib/licensed/sources/gradle.rb', line 82
def enabled?
!gradle_executable.to_s.empty? && File.exist?(config.pwd.join("build.gradle"))
end
|
#enumerate_dependencies ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/licensed/sources/gradle.rb', line 86
def enumerate_dependencies
JSON.parse(self.class.gradle_command("printDependencies", path: config.pwd, executable: gradle_executable, configurations: configurations)).map do |package|
name = "#{package["group"]}:#{package["name"]}"
Dependency.new(
name: name,
version: package["version"],
path: config.pwd,
executable: gradle_executable,
configurations: configurations,
metadata: {
"type" => Gradle.type
}
)
end
end
|