Skip to content

Commit 2af2181

Browse files
committed
Dangerfile: handle maven-enforcer-plugin output.
1 parent ad2ec67 commit 2af2181

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Dangerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,58 @@ else
234234
print_errors_summary 'rflint', errors_count, 'https://github.com/php-coder/mystamps/wiki/rflint'
235235
end
236236

237+
# Handle `mvn enforcer:enforce` results
238+
#
239+
# Example:
240+
# [INFO] --- maven-enforcer-plugin:1.4.1:enforce (default-cli) @ mystamps ---
241+
# [WARNING] Rule 0: org.apache.maven.plugins.enforcer.BannedDependencies failed with message:
242+
# Found Banned Dependency: junit:junit:jar:4.12
243+
# Use 'mvn dependency:tree' to locate the source of the banned dependencies.
244+
# [INFO] ------------------------------------------------------------------------
245+
# [INFO] BUILD FAILURE
246+
# [INFO] ------------------------------------------------------------------------
247+
#
248+
enforcer_output = 'enforcer.log'
249+
unless File.file?(enforcer_output)
250+
warn("Couldn't find #{enforcer_output}. maven-enforcer-plugin result is unknown")
251+
else
252+
errors = []
253+
plugin_output_started = false
254+
File.readlines(enforcer_output).each do |line|
255+
# We're interesting in everything between
256+
# [INFO] --- maven-enforcer-plugin:1.4.1:enforce (default-cli) @ mystamps ---
257+
# and
258+
# [INFO] ------------------------------------------------------------------------
259+
# lines
260+
261+
if line.start_with? '[INFO] --- maven-enforcer-plugin:'
262+
plugin_output_started = true
263+
next
264+
end
265+
266+
unless plugin_output_started
267+
next
268+
end
269+
270+
if line.start_with? '[INFO] -----'
271+
break
272+
end
273+
274+
if line.start_with? '[INFO] Download'
275+
next
276+
end
277+
278+
line.sub!('[WARNING] ', '')
279+
errors << line.rstrip
280+
end
281+
282+
unless errors.empty?
283+
error_msgs = errors.join("\n")
284+
fail("maven-enforcer-plugin reported about errors. Please, fix them. "\
285+
"Here is its output:\n```\n#{error_msgs}\n```")
286+
end
287+
end
288+
237289
# Handle `mvn findbugs:check` results
238290
#
239291
# Example:

0 commit comments

Comments
 (0)