forked from arangamani/jenkins_api_client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
86 lines (73 loc) · 2.61 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'jenkins_api_client/version'
require 'rake'
require 'yard'
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rubygems/package_task'
require 'bump/tasks'
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:unit_tests) do |spec|
spec.pattern = 'spec/unit_tests/*_spec.rb'
end
RSpec::Core::RakeTask.new(:func_tests) do |spec|
spec.pattern = 'spec/func_tests/*_spec.rb'
end
RSpec::Core::RakeTask.new(:test) do |spec|
spec.pattern = 'spec/*/*.rb'
end
YARD::Config.load_plugin 'thor'
YARD::Rake::YardocTask.new do |t|
t.files = ['lib/**/*.rb', 'lib/**/**/*.rb']
end
namespace :doc do
# This task requires that graphviz is installed locally. For more info:
# http://www.graphviz.org/
desc "Generates the class diagram using the yard generated dot file"
task :generate_class_diagram do
puts "Generating the dot file..."
`yard graph --file jenkins_api_client.dot`
puts "Generating class diagram from the dot file..."
`dot jenkins_api_client.dot -Tpng -o jenkins_api_client_class_diagram.png`
end
desc "Applies Google Analytics tracking script to all generated html files"
task :apply_google_analytics do
files = Dir.glob("**/*.html")
string_to_replace = "</body>"
string_to_replace_with = <<-EOF
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-37519629-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
EOF
files.each do |html_file|
puts "Processing file: #{html_file}"
contents = ""
# Read the file contents
file = File.open(html_file)
file.each { |line| contents << line }
file.close
# If the file already has google analytics tracking info, skip it.
if contents.include?(string_to_replace_with)
puts "Skipped..."
next
end
# Apply google analytics tracking info to the html file
contents.gsub!(string_to_replace, string_to_replace_with)
# Write the contents with the google analytics info to the file
file = File.open(html_file, "w")
file.write(contents)
file.close
end
end
end
task default: :unit_tests