test-kitchen 1.0.0.alpha.3 → 1.0.0.alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,19 +1,30 @@
1
+ ## 1.0.0.alpha.4 / 2013-04-10
2
+
3
+ ### Bug fixes
4
+
5
+ * #get_all_instances must return actors in parallel mode in CLI. ([@fnichol][], [@bryanwb][]).
6
+
7
+ ### Improvements
8
+
9
+ * Refactor `kitchen plugin create` to drop Bundler dependency completely. ([@fnichol][])
10
+
11
+
1
12
  ## 1.0.0.alpha.3 / 2013-04-05
2
13
 
3
14
  ### Bug fixes
4
15
 
5
- * Fix :require_chef_omnibus driver_config option to eliminate re-installation (@fnichol)
6
- * Remove implicit Bundler dependency in `kitchen init`. (@fnichol)
16
+ * Fix :require_chef_omnibus driver_config option to eliminate re-installation ([@fnichol][])
17
+ * Remove implicit Bundler dependency in `kitchen init`. ([@fnichol][])
7
18
 
8
19
  ### New features
9
20
 
10
- * Add --auto-init flag to `kitchen test` (default: false) (@fnichol)
21
+ * Add --auto-init flag to `kitchen test` (default: false) ([@fnichol][])
11
22
 
12
23
  ### Improvements
13
24
 
14
- * Update base box URLs. (@fnichol)
15
- * Extract .kitchen.yml to an ERB template & update box URLs. (@fnichol)
16
- * Add more spec coverage. (@fnichol)
25
+ * Update base box URLs. ([@fnichol][])
26
+ * Extract .kitchen.yml to an ERB template & update box URLs. ([@fnichol][])
27
+ * Add more spec coverage. ([@fnichol][])
17
28
 
18
29
 
19
30
  ## 1.0.0.alpha.2 / 2013-03-28
@@ -65,6 +76,7 @@ The initial release.
65
76
  [#73]: https://github.com/opscode/test/issues/73
66
77
  [#74]: https://github.com/opscode/test/issues/74
67
78
  [@ChrisLundquist]: https://github.com/ChrisLundquist
79
+ [@bryanwb]: https://github.com/bryanwb
68
80
  [@fnichol]: https://github.com/fnichol
69
81
  [@mattray]: https://github.com/mattray
70
- [@reset]: https://github.com/reset
82
+ [@reset]: https://github.com/reset
@@ -0,0 +1,63 @@
1
+ Feature: Create a new Test Kitchen Driver project
2
+ In order to make plugin development a snap
3
+ As a user of Test Kitchen
4
+ I want a command to run that will give me a driver gem project scaffold
5
+
6
+ Scenario: Displaying help
7
+ When I run `kitchen help driver create`
8
+ Then the output should contain:
9
+ """
10
+ Usage:
11
+ kitchen driver create [NAME]
12
+ """
13
+ And the exit status should be 0
14
+
15
+ Scenario: Running with default values
16
+ When I run `kitchen driver create qemu`
17
+ Then a directory named "kitchen-qemu" should exist
18
+ And the file "kitchen-qemu/CHANGELOG.md" should contain:
19
+ """
20
+ ## 0.1.0 / Unreleased
21
+ """
22
+ And the file "kitchen-qemu/Gemfile" should contain "gemspec"
23
+ And the file "kitchen-qemu/Rakefile" should contain "task :stats"
24
+ And the file "kitchen-qemu/README.md" should contain:
25
+ """
26
+ Kitchen::Qemu
27
+ """
28
+ And the file "kitchen-qemu/kitchen-qemu.gemspec" should contain:
29
+ """
30
+ require 'kitchen/driver/qemu_version'
31
+ """
32
+ And the file "kitchen-qemu/LICENSE" should contain:
33
+ """
34
+ Licensed under the Apache License, Version 2.0
35
+ """
36
+ And the file "kitchen-qemu/.gitignore" should contain:
37
+ """
38
+ Gemfile.lock
39
+ """
40
+ And the file "kitchen-qemu/.tailor" should contain:
41
+ """
42
+ config.file_set 'lib/**/*.rb'
43
+ """
44
+ And the file "kitchen-qemu/.travis.yml" should contain:
45
+ """
46
+ language: ruby
47
+ """
48
+ And a file named "kitchen-qemu/.cane" should exist
49
+ And the file "kitchen-qemu/lib/kitchen/driver/qemu_version.rb" should contain:
50
+ """
51
+ QEMU_VERSION = "0.1.0.dev"
52
+ """
53
+ And the file "kitchen-qemu/lib/kitchen/driver/qemu.rb" should contain:
54
+ """
55
+ class Qemu < Kitchen::Driver::SSHBase
56
+ """
57
+
58
+ Scenario: Running with an alternate license
59
+ When I successfully run `kitchen driver create foo --license=reserved`
60
+ Then the file "kitchen-foo/LICENSE" should contain:
61
+ """
62
+ All rights reserved - Do Not Redistribute
63
+ """
data/lib/kitchen/cli.rb CHANGED
@@ -22,8 +22,8 @@ require 'ostruct'
22
22
  require 'thor'
23
23
 
24
24
  require 'kitchen'
25
+ require 'kitchen/generator/driver_create'
25
26
  require 'kitchen/generator/init'
26
- require 'kitchen/generator/new_plugin'
27
27
 
28
28
  module Kitchen
29
29
 
@@ -162,7 +162,7 @@ module Kitchen
162
162
  # @author Fletcher Nichol <fnichol@nichol.ca>
163
163
  class Driver < Thor
164
164
 
165
- register Kitchen::Generator::NewPlugin, "create",
165
+ register Kitchen::Generator::DriverCreate, "create",
166
166
  "create [NAME]", "Create a new Kitchen Driver gem project"
167
167
  long_desc <<-D, :for => "create"
168
168
  Create will generate a project scaffold for a brand new Test Kitchen
@@ -172,7 +172,7 @@ module Kitchen
172
172
 
173
173
  will create a project scaffold for a RubyGem called `kitchen-foobar'.
174
174
  D
175
- tasks["create"].options = Kitchen::Generator::NewPlugin.class_options
175
+ tasks["create"].options = Kitchen::Generator::DriverCreate.class_options
176
176
 
177
177
  desc "discover", "Discover Test Kitchen drivers published on RubyGems"
178
178
  long_desc <<-D
@@ -268,7 +268,12 @@ module Kitchen
268
268
  end
269
269
 
270
270
  def get_all_instances
271
- result = @config.instances
271
+ result = if options[:parallel]
272
+ @config.instance_actors
273
+ else
274
+ @config.instances
275
+ end
276
+
272
277
  if result.empty?
273
278
  die task, "No instances defined"
274
279
  else
@@ -0,0 +1,143 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2013, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require 'thor/group'
20
+ require 'thor/util'
21
+
22
+ module Kitchen
23
+
24
+ module Generator
25
+
26
+ # A generator to create a new Kitchen Driver gem project.
27
+ #
28
+ # @author Fletcher Nichol <fnichol@nichol.ca>
29
+ class DriverCreate < Thor::Group
30
+
31
+ include Thor::Actions
32
+
33
+ argument :name, :type => :string
34
+
35
+ class_option :license, :aliases => "-l", :default => "apachev2",
36
+ :desc => "License type for gem (apachev2, mit, lgplv3, reserved)"
37
+
38
+ def create
39
+ self.class.source_root(Kitchen.source_root.join("templates", "driver"))
40
+
41
+ create_core_files
42
+ create_source_files
43
+ initialize_git
44
+ end
45
+
46
+ private
47
+
48
+ def create_core_files
49
+ empty_directory(target_dir)
50
+
51
+ create_template("CHANGELOG.md.erb", "CHANGELOG.md")
52
+ create_template("Gemfile.erb", "Gemfile")
53
+ create_template("Rakefile.erb", "Rakefile")
54
+ create_template("README.md.erb", "README.md")
55
+ create_template("gemspec.erb", "#{config[:gem_name]}.gemspec")
56
+ create_template("license_#{config[:license]}.erb", license_filename)
57
+ create_template("gitignore.erb", ".gitignore")
58
+ create_template("tailor.erb", ".tailor")
59
+ create_template("travis.yml.erb", ".travis.yml")
60
+ create_file(File.join(target_dir, ".cane"))
61
+ end
62
+
63
+ def create_source_files
64
+ empty_directory(File.join(target_dir, "lib/kitchen/driver"))
65
+
66
+ create_template(
67
+ "version.rb.erb",
68
+ "lib/kitchen/driver/#{name}_version.rb"
69
+ )
70
+ create_template(
71
+ "driver.rb.erb",
72
+ "lib/kitchen/driver/#{name}.rb"
73
+ )
74
+ end
75
+
76
+ def initialize_git
77
+ inside(target_dir) do
78
+ run("git init")
79
+ run("git add .")
80
+ end
81
+ end
82
+
83
+ def create_template(erb, dest)
84
+ template(erb, File.join(target_dir, dest), config)
85
+ end
86
+
87
+ def target_dir
88
+ File.join(Dir.pwd, "kitchen-#{name}")
89
+ end
90
+
91
+ def config
92
+ @config ||= {
93
+ :name => name,
94
+ :gem_name => "kitchen-#{name}",
95
+ :gemspec => "kitchen-#{name}.gemspec",
96
+ :klass_name => ::Thor::Util.camel_case(name),
97
+ :constant_name => ::Thor::Util.snake_case(name).upcase,
98
+ :author => author,
99
+ :email => email,
100
+ :license => options[:license],
101
+ :license_string => license_string,
102
+ :year => Time.now.year,
103
+ }
104
+ end
105
+
106
+ def author
107
+ git_user_name = %x{git config user.name}.chomp
108
+ git_user_name.empty? ? "TODO: Write your name" : git_user_name
109
+ end
110
+
111
+ def email
112
+ git_user_email = %x{git config user.email}.chomp
113
+ git_user_email.empty? ? "TODO: Write your email" : git_user_email
114
+ end
115
+
116
+ def license_string
117
+ case options[:license]
118
+ when "mit" then "MIT"
119
+ when "apachev2" then "Apache 2.0"
120
+ when "lgplv3" then "LGPL 3.0"
121
+ when "reserved" then "All rights reserved"
122
+ else
123
+ raise ArgumentError, "No such license #{options[:license]}"
124
+ end
125
+ end
126
+
127
+ def license_filename
128
+ case options[:license]
129
+ when "mit" then "LICENSE.txt"
130
+ when "apachev2", "reserved" then "LICENSE"
131
+ when "lgplv3" then "COPYING"
132
+ else
133
+ raise ArgumentError, "No such license #{options[:license]}"
134
+ end
135
+ end
136
+
137
+ def license_comment
138
+ @license_comment ||= IO.read(File.join(target_dir, license_filename)).
139
+ gsub(/^/, '# ').gsub(/\s+$/, '')
140
+ end
141
+ end
142
+ end
143
+ end
@@ -44,7 +44,7 @@ module Kitchen
44
44
  D
45
45
 
46
46
  def init
47
- self.class.source_root(Kitchen.source_root.join("templates", "plugin"))
47
+ self.class.source_root(Kitchen.source_root.join("templates", "init"))
48
48
 
49
49
  create_kitchen_yaml
50
50
 
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Kitchen
20
20
 
21
- VERSION = "1.0.0.alpha.3"
21
+ VERSION = "1.0.0.alpha.4"
22
22
  end
@@ -0,0 +1,3 @@
1
+ ## 0.1.0 / Unreleased
2
+
3
+ * Initial release
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,64 @@
1
+ # <a name="title"></a> Kitchen::<%= config[:klass_name] %>
2
+
3
+ A Test Kitchen Driver for <%= config[:klass_name] %>.
4
+
5
+ ## <a name="requirements"></a> Requirements
6
+
7
+ **TODO:** document any software or library prerequisites that are required to
8
+ use this driver. Implement the `#verify_dependencies` method in your Driver
9
+ class to enforce these requirements in code, if possible.
10
+
11
+ ## <a name="installation"></a> Installation and Setup
12
+
13
+ Please read the [Driver usage][driver_usage] page for more details.
14
+
15
+ ## <a name="config"></a> Configuration
16
+
17
+ **TODO:** Write descriptions of all configuration options
18
+
19
+ ### <a name="config-require-chef-omnibus"></a> require\_chef\_omnibus
20
+
21
+ Determines whether or not a Chef [Omnibus package][chef_omnibus_dl] will be
22
+ installed. There are several different behaviors available:
23
+
24
+ * `true` - the latest release will be installed. Subsequent converges
25
+ will skip re-installing if chef is present.
26
+ * `latest` - the latest release will be installed. Subsequent converges
27
+ will always re-install even if chef is present.
28
+ * `<VERSION_STRING>` (ex: `10.24.0`) - the desired version string will
29
+ be passed the the install.sh script. Subsequent converges will skip if
30
+ the installed version and the desired version match.
31
+ * `false` or `nil` - no chef is installed.
32
+
33
+ The default value is unset, or `nil`.
34
+
35
+ ## <a name="development"></a> Development
36
+
37
+ * Source hosted at [GitHub][repo]
38
+ * Report issues/questions/feature requests on [GitHub Issues][issues]
39
+
40
+ Pull requests are very welcome! Make sure your patches are well tested.
41
+ Ideally create a topic branch for every separate change you make. For
42
+ example:
43
+
44
+ 1. Fork the repo
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
49
+
50
+ ## <a name="authors"></a> Authors
51
+
52
+ Created and maintained by [<%= config[:author] %>][author] (<<%= config[:email] %>>)
53
+
54
+ ## <a name="license"></a> License
55
+
56
+ <%= config[:license_string] %> (see [LICENSE][license])
57
+
58
+
59
+ [author]: https://github.com/enter-github-user
60
+ [issues]: https://github.com/enter-github-user/<%= config[:gem_name] %>/issues
61
+ [license]: https://github.com/enter-github-user/<%= config[:gem_name] %>/blob/master/LICENSE
62
+ [repo]: https://github.com/enter-github-user/<%= config[:gem_name] %>
63
+ [driver_usage]: http://docs.kitchen-ci.org/drivers/usage
64
+ [chef_omnibus_dl]: http://www.opscode.com/chef/install/
@@ -0,0 +1,21 @@
1
+ require "bundler/gem_tasks"
2
+ require 'cane/rake_task'
3
+ require 'tailor/rake_task'
4
+
5
+ desc "Run cane to check quality metrics"
6
+ Cane::RakeTask.new do |cane|
7
+ cane.canefile = './.cane'
8
+ end
9
+
10
+ Tailor::RakeTask.new
11
+
12
+ desc "Display LOC stats"
13
+ task :stats do
14
+ puts "\n## Production Code Stats"
15
+ sh "countloc -r lib"
16
+ end
17
+
18
+ desc "Run all quality tasks"
19
+ task :quality => [:cane, :tailor, :stats]
20
+
21
+ task :default => [:quality]
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ <%= license_comment %>
4
+
5
+ require 'kitchen'
6
+
7
+ module Kitchen
8
+
9
+ module Driver
10
+
11
+ # <%= config[:klass_name] %> driver for Kitchen.
12
+ #
13
+ # @author <%= config[:author] %> <<%= config[:email] %>>
14
+ class <%= config[:klass_name] %> < Kitchen::Driver::SSHBase
15
+
16
+ def create(state)
17
+ end
18
+
19
+ def destroy(state)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kitchen/driver/<%= config[:name] %>_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = '<%= config[:gem_name] %>'
8
+ spec.version = Kitchen::Driver::<%= config[:constant_name] %>_VERSION
9
+ spec.authors = ['<%= config[:author] %>']
10
+ spec.email = ['<%= config[:email] %>']
11
+ spec.description = %q{A Test Kitchen Driver for <%= config[:klass_name] %>}
12
+ spec.summary = spec.description
13
+ spec.homepage = ''
14
+ spec.license = '<%= config[:license_string] %>'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = []
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'test-kitchen', '~> 1.0.0.alpha.3'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+
26
+ spec.add_development_dependency 'cane'
27
+ spec.add_development_dependency 'tailor'
28
+ spec.add_development_dependency 'countloc'
29
+ end
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -1,6 +1,6 @@
1
- Author:: <%= author %> (<<%= email %>>)
1
+ Author:: <%= config[:author] %> (<<%= config[:email] %>>)
2
2
 
3
- Copyright (C) <%= year %>, <%= author %>
3
+ Copyright (C) <%= config[:year] %>, <%= config[:author] %>
4
4
 
5
5
  Licensed under the Apache License, Version 2.0 (the "License");
6
6
  you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
- Author:: <%= author %> (<<%= email %>>)
1
+ Author:: <%= config[:author] %> (<<%= config[:email] %>>)
2
2
 
3
- Copyright (C) <%= year %> <%= author %>
3
+ Copyright (C) <%= config[:year] %> <%= config[:author] %>
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify
6
6
  it under the terms of the GNU General Public License as published by
@@ -1,6 +1,6 @@
1
- Author:: <%= author %> (<<%= email %>>)
1
+ Author:: <%= config[:author] %> (<<%= config[:email] %>>)
2
2
 
3
- Copyright (c) <%= year %>, <%= author %>
3
+ Copyright (c) <%= config[:year] %>, <%= config[:author] %>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -0,0 +1,5 @@
1
+ Author:: <%= config[:author] %> (<<%= config[:email] %>>)
2
+
3
+ Copyright (C) <%= config[:year] %>, <%= config[:author] %>
4
+
5
+ All rights reserved - Do Not Redistribute
@@ -0,0 +1,4 @@
1
+ Tailor.config do |config|
2
+ config.formatters "text"
3
+ config.file_set 'lib/**/*.rb'
4
+ end
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - 1.9.2
7
+ - ruby-head
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
@@ -0,0 +1,12 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ <%= license_comment %>
4
+
5
+ module Kitchen
6
+
7
+ module Driver
8
+
9
+ # Version string for <%= config[:klass_name] %> Kitchen driver
10
+ <%= config[:constant_name] %>_VERSION = "0.1.0.dev"
11
+ end
12
+ end
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-kitchen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.3
4
+ version: 1.0.0.alpha.4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-05 00:00:00.000000000 Z
12
+ date: 2013-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid
@@ -334,6 +334,7 @@ files:
334
334
  - Rakefile
335
335
  - bin/kitchen
336
336
  - features/kitchen_command.feature
337
+ - features/kitchen_driver_create_command.feature
337
338
  - features/kitchen_driver_discover_command.feature
338
339
  - features/kitchen_init_command.feature
339
340
  - features/step_definitions/gem_steps.rb
@@ -350,8 +351,8 @@ files:
350
351
  - lib/kitchen/driver/dummy.rb
351
352
  - lib/kitchen/driver/ssh_base.rb
352
353
  - lib/kitchen/errors.rb
354
+ - lib/kitchen/generator/driver_create.rb
353
355
  - lib/kitchen/generator/init.rb
354
- - lib/kitchen/generator/new_plugin.rb
355
356
  - lib/kitchen/instance.rb
356
357
  - lib/kitchen/instance_actor.rb
357
358
  - lib/kitchen/loader/yaml.rb
@@ -380,14 +381,21 @@ files:
380
381
  - spec/kitchen/suite_spec.rb
381
382
  - spec/kitchen/util_spec.rb
382
383
  - spec/spec_helper.rb
383
- - templates/plugin/driver.rb.erb
384
- - templates/plugin/kitchen.yml.erb
385
- - templates/plugin/license_apachev2.erb
386
- - templates/plugin/license_gplv2.erb
387
- - templates/plugin/license_gplv3.erb
388
- - templates/plugin/license_mit.erb
389
- - templates/plugin/license_reserved.erb
390
- - templates/plugin/version.rb.erb
384
+ - templates/driver/CHANGELOG.md.erb
385
+ - templates/driver/Gemfile.erb
386
+ - templates/driver/README.md.erb
387
+ - templates/driver/Rakefile.erb
388
+ - templates/driver/driver.rb.erb
389
+ - templates/driver/gemspec.erb
390
+ - templates/driver/gitignore.erb
391
+ - templates/driver/license_apachev2.erb
392
+ - templates/driver/license_lgplv3.erb
393
+ - templates/driver/license_mit.erb
394
+ - templates/driver/license_reserved.erb
395
+ - templates/driver/tailor.erb
396
+ - templates/driver/travis.yml.erb
397
+ - templates/driver/version.rb.erb
398
+ - templates/init/kitchen.yml.erb
391
399
  - test-kitchen.gemspec
392
400
  homepage: https://github.com/opscode/test-kitchen
393
401
  licenses:
@@ -416,6 +424,7 @@ specification_version: 3
416
424
  summary: A Chef convergence integration test harness
417
425
  test_files:
418
426
  - features/kitchen_command.feature
427
+ - features/kitchen_driver_create_command.feature
419
428
  - features/kitchen_driver_discover_command.feature
420
429
  - features/kitchen_init_command.feature
421
430
  - features/step_definitions/gem_steps.rb
@@ -1,191 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
- #
5
- # Copyright (C) 2013, Fletcher Nichol
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
-
19
- require 'thor/group'
20
- require 'thor/util'
21
-
22
- module Kitchen
23
-
24
- module Generator
25
-
26
- # A generator to create a new Kitchen Driver gem project.
27
- #
28
- # @author Fletcher Nichol <fnichol@nichol.ca>
29
- class NewPlugin < Thor::Group
30
-
31
- include Thor::Actions
32
-
33
- argument :plugin_name
34
-
35
- class_option :license, :aliases => "-l", :default => "apachev2",
36
- :desc => "License type for gem (apachev2, mit, gplv3, gplv2, reserved)"
37
-
38
- def new_plugin
39
- if ! run("command -v bundle", :verbose => false)
40
- die "Bundler must be installed and on your PATH: `gem install bundler'"
41
- end
42
-
43
- @plugin_name = plugin_name
44
- @gem_name = "kitchen-#{plugin_name}"
45
- @gemspec = "#{gem_name}.gemspec"
46
- @klass_name = ::Thor::Util.camel_case(plugin_name)
47
- @constant = ::Thor::Util.snake_case(plugin_name).upcase
48
- @license = options[:license]
49
- @author = %x{git config user.name}.chomp
50
- @email = %x{git config user.email}.chomp
51
- @year = Time.now.year
52
-
53
- create_plugin
54
- end
55
-
56
- private
57
-
58
- attr_reader :plugin_name, :gem_name, :gemspec, :klass_name,
59
- :constant, :license, :author, :email, :year
60
-
61
- def create_plugin
62
- run("bundle gem #{gem_name}") unless File.directory?(gem_name)
63
-
64
- inside(gem_name) do
65
- update_gemspec
66
- update_gemfile
67
- update_rakefile
68
- create_src_files
69
- cleanup
70
- create_license
71
- add_git_files
72
- end
73
- end
74
-
75
- def update_gemspec
76
- gsub_file(gemspec, %r{require '#{gem_name}/version'},
77
- %{require 'kitchen/driver/#{plugin_name}_version.rb'})
78
- gsub_file(gemspec, %r{Kitchen::#{klass_name}::VERSION},
79
- %{Kitchen::Driver::#{constant}_VERSION})
80
- gsub_file(gemspec, %r{(gem\.executables\s*) =.*$},
81
- '\1 = []')
82
- gsub_file(gemspec, %r{(gem\.description\s*) =.*$},
83
- '\1 = "' + "Kitchen::Driver::#{klass_name} - " +
84
- "A Kitchen Driver for #{klass_name}\"")
85
- gsub_file(gemspec, %r{(gem\.summary\s*) =.*$},
86
- '\1 = gem.description')
87
- gsub_file(gemspec, %r{(gem\.homepage\s*) =.*$},
88
- '\1 = "https://github.com/opscode/' +
89
- "#{gem_name}/\"")
90
- insert_into_file(gemspec,
91
- "\n gem.add_dependency 'test-kitchen'\n", :before => "end\n")
92
- insert_into_file(gemspec,
93
- "\n gem.add_development_dependency 'cane'\n", :before => "end\n")
94
- insert_into_file(gemspec,
95
- " gem.add_development_dependency 'tailor'\n", :before => "end\n")
96
- end
97
-
98
- def update_gemfile
99
- append_to_file("Gemfile", "\ngroup :test do\n gem 'rake'\nend\n")
100
- end
101
-
102
- def update_rakefile
103
- append_to_file("Rakefile", <<-RAKEFILE.gsub(/^ {10}/, ''))
104
- require 'cane/rake_task'
105
- require 'tailor/rake_task'
106
-
107
- desc "Run cane to check quality metrics"
108
- Cane::RakeTask.new
109
-
110
- Tailor::RakeTask.new
111
-
112
- task :default => [ :cane, :tailor ]
113
- RAKEFILE
114
- end
115
-
116
- def create_src_files
117
- license_comments = rendered_license.gsub(/^/, '# ').gsub(/\s+$/, '')
118
-
119
- empty_directory("lib/kitchen/driver")
120
- create_template("plugin/version.rb",
121
- "lib/kitchen/driver/#{plugin_name}_version.rb",
122
- :klass_name => klass_name, :constant => constant,
123
- :license => license_comments)
124
- create_template("plugin/driver.rb",
125
- "lib/kitchen/driver/#{plugin_name}.rb",
126
- :klass_name => klass_name, :license => license_comments,
127
- :author => author, :email => email)
128
- end
129
-
130
- def rendered_license
131
- TemplateRenderer.render("plugin/license_#{license}",
132
- :author => author, :email => email, :year => year)
133
- end
134
-
135
- def create_license
136
- dest_file = case license
137
- when "mit" then "LICENSE.txt"
138
- when "apachev2", "reserved" then "LICENSE"
139
- when "gplv2", "gplv3" then "COPYING"
140
- else
141
- raise ArgumentError, "No such license #{license}"
142
- end
143
-
144
- create_file(dest_file, rendered_license)
145
- end
146
-
147
- def cleanup
148
- %W(LICENSE.txt lib/#{gem_name}/version.rb lib/#{gem_name}.rb).each do |f|
149
- run("git rm -f #{f}") if File.exists?(f)
150
- end
151
- remove_dir("lib/#{gem_name}")
152
- end
153
-
154
- def add_git_files
155
- run("git add .")
156
- end
157
-
158
- def create_template(template, destination, data = {})
159
- create_file(destination, TemplateRenderer.render(template, data))
160
- end
161
-
162
- # Renders an ERB template with a hash of template variables.
163
- #
164
- # @author Fletcher Nichol <fnichol@nichol.ca>
165
- class TemplateRenderer < OpenStruct
166
-
167
- def self.render(template, data = {})
168
- renderer = new(template, data)
169
- yield renderer if block_given?
170
- renderer.render
171
- end
172
-
173
- def initialize(template, data = {})
174
- super()
175
- data[:template] = template
176
- data.each { |key, value| send("#{key}=", value) }
177
- end
178
-
179
- def render
180
- ERB.new(IO.read(template_file)).result(binding)
181
- end
182
-
183
- private
184
-
185
- def template_file
186
- Kitchen.source_root.join("templates", "#{template}.erb").to_s
187
- end
188
- end
189
- end
190
- end
191
- end
@@ -1,23 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- <%= license %>
4
-
5
- require 'kitchen'
6
-
7
- module Kitchen
8
-
9
- module Driver
10
-
11
- # <%= klass_name %> driver for Kitchen.
12
- #
13
- # @author <%= author %> <<%= email %>>
14
- class <%= klass_name %> < Kitchen::Driver::SSHBase
15
-
16
- def create(state)
17
- end
18
-
19
- def destroy(state)
20
- end
21
- end
22
- end
23
- end
@@ -1,18 +0,0 @@
1
- Author:: <%= author %> (<<%= email %>>)
2
-
3
- Copyright (C) <%= year %> <%= author %>
4
-
5
- This program is free software; you can redistribute it and/or
6
- modify it under the terms of the GNU General Public License
7
- as published by the Free Software Foundation; either version 2
8
- of the License, or (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU General Public License for more details.
14
-
15
- You should have received a copy of the GNU General Public License
16
- along with this program; if not, write to the Free Software
17
- Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
- Boston, MA 02110-1301, USA.
@@ -1,5 +0,0 @@
1
- Author:: <%= author %> (<<%= email %>>)
2
-
3
- Copyright (C) <%= year %>, <%= author %>
4
-
5
- All rights reserved - Do Not Redistribute
@@ -1,12 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- <%= license %>
4
-
5
- module Kitchen
6
-
7
- module Driver
8
-
9
- # Version string for <%= klass_name %> Kitchen driver
10
- <%= constant %>_VERSION = "0.1.0"
11
- end
12
- end