Skip to content

Commit

Permalink
Merge pull request #6 from sportngin/fix_cpd_output_for_dry_plugin
Browse files Browse the repository at this point in the history
Make friendly with DRY jenkins plugin
  • Loading branch information
marklarr committed Nov 5, 2013
2 parents 8f3361e + 1d3bb12 commit 34acbea
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ end

The CI server of choice is Jenkins -- install the plugins for the metrics you plan on using.

* lint: https://wiki.jenkins-ci.org/display/JENKINS/PMD+Plugin
* lines_of_code: https://wiki.jenkins-ci.org/display/JENKINS/SLOCCount+Plugin
* duplicate_code_detection: https://wiki.jenkins-ci.org/display/JENKINS/Violations (This could technically be used for lint also, but PMD has friendlier sorting on the front-end)
* test_suite: JUNIT reporting is built into Jenkins.
* `lint`: https://wiki.jenkins-ci.org/display/JENKINS/PMD+Plugin
* `lines_of_code`: https://wiki.jenkins-ci.org/display/JENKINS/SLOCCount+Plugin
* `duplicate_code_detection`: https://wiki.jenkins-ci.org/display/JENKINS/DRY+Plugin
* `test_suite`: JUnit reporting is built into Jenkins.

In Jenkins, call the rake task and load in the generated files

![Jenkins Screenshot](/docs/jenkins-setup.jpg)
![Jenkins Screenshot - Violations](/docs/jenkins-setup-violations.png)

Triggering a build should now show the metrics in the build.

Expand Down
Binary file removed docs/jenkins-setup-violations.png
Binary file not shown.
Binary file modified docs/jenkins-setup.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 18 additions & 9 deletions lib/objective_ci/ci_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def duplicate_code_detection(opts={})
"| LC_CTYPE=C LANG=C sed 's/\\/\\.\\//\\//' > #{DUPLICATION_DESTINATION}",
opts)
pmd_exclude
pmd_patch
end

private
def exclusion_options_list(option_flag)
if exclusions.empty?
''
Expand All @@ -83,13 +83,13 @@ def exclusion_options_list(option_flag)
"#{option_flag} #{wrapped_exclusions.join(" #{option_flag} ")}"
end
end
private :exclusion_options_list

private
def using_pods?
File.exists?("Podfile")
File.exists?("Podfile") || File.exists?("podfile")
end
private :using_pods?

private
def call_binary(binary, cl_options, tail, opts={})
extra_options = opts["#{binary}_options".to_sym]
override_options = opts["#{binary}_override".to_sym]
Expand All @@ -99,22 +99,22 @@ def call_binary(binary, cl_options, tail, opts={})
puts command
puts `#{command}`
end
private :call_binary

private
def requires_options(opts, *keys)
keys.each do |k|
raise "option #{k} is required." unless opts.has_key?(k)
end
end
private :requires_options

private
def requires_at_least_one_option(opts, *keys)
if (opts.keys && keys).empty?
raise "at least one of the options #{keys.join(", ")} is required"
end
end
private :requires_at_least_one_option

private
def pmd_exclude
# Unfortunately, pmd doesn't seem to provide any nice out-of-the-box way for excluding files from the results.
absolute_exclusions = exclusions.map { |e| "#{Dir.pwd}/#{e}/" }
Expand All @@ -127,16 +127,25 @@ def pmd_exclude
end
File.open(DUPLICATION_DESTINATION, 'w') { |file| file.write(output.to_s) }
end
private :pmd_exclude

def pmd_patch
# Make sure encoding is UTF-8, or else Jenkins DRY plugin will fail to parse.
new_xml = Nokogiri::XML.parse(File.open(DUPLICATION_DESTINATION).read, nil, "UTF-8")
File.open(DUPLICATION_DESTINATION, 'w') { |file| file.write(new_xml.to_s) }
end
private :pmd_patch

private
def xcode_version
matches = `xcodebuild -version`.match(/^Xcode ([0-9]+\.[0-9]+)/)
matches ? matches[1].to_f : 0.0
end
private :xcode_version

private
def puts_red(str)
puts "\e[31m#{str}\e[0m"
end
private :puts_red

end
end

0 comments on commit 34acbea

Please sign in to comment.