extract the tools into its own repo.

This commit is contained in:
Charles Lowell 2011-08-19 12:56:50 -05:00
commit c855dba214
9 changed files with 238 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
*.gem
.bundle
.idea
Gemfile.lock
pkg/*
target/

4
Gemfile Normal file
View File

@ -0,0 +1,4 @@
source "http://rubygems.org"
# Specify your gem's dependencies in jenkins-plugins.gemspec
gemspec

16
README.md Normal file
View File

@ -0,0 +1,16 @@
# Jenkins plugins
Provide the facility to create, develop and release extensions for [Jenkins](http://jenkins-ci.org) with nothing but knowledge of the language, tools and best practices of the Ruby community.
[read more](http://blog.thefrontside.net/2011/05/12/what-it-take-to-bring-ruby-to-jenkins)...
# Get started
> This is all very theoretical. Don't try this at home.
$ gem install jenkins-plugins
$ jpi create my-awesome-jenkins-plugin
$ cd my-awesome-jenkins-plugin
$ jpi gen build_wrapper MyBuildWrapper
$ rake server

6
Rakefile Normal file
View File

@ -0,0 +1,6 @@
require 'bundler'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

5
bin/jpi Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env ruby
require 'jpi/cli'
JPI::CLI.start

View File

@ -0,0 +1,90 @@
Feature: Generating a new Jenkins Ruby Plugin
Creating a new Ruby plugin for Jenkins needs to be as simple as running a single command
that will generate a project skeleton. This skeleton will come complete with git repository and all
the goodies that you need to do your plugin develompent.
Background: Creating a brand new Jenkins Ruby Plugin
Given I've run "jenkins-plugin create newplugin"
Scenario: The directory skeleton is generated
Then I should see this structure
"""
[-] newplugin
| [+] .git
| .gitignore
| Gemfile
| Rakefile
| [-] lib
| [-] newplugin
| | | version.rb
| | newplugin.rb
| [-] spec
| | spec_helper.rb
| [-] plugin
| | [+] models
| | [+] views
"""
Scenario: The .gitignore contents
When I open ".gitignore"
Then I should see
"""
.bundle
.rvmrc
.rspec
"""
Scenario: The Gemfile contents
When I open "Gemfile"
Then I should see
"""
source :rubygems
gem "jenkins-war"
gem "jenkins-plugins"
"""
Scenario: The Rakefile contents
When I open "Rakefile"
Then I should see
"""
require 'jenkins/rake'
Jenkins::Rake.install_tasks
"""
Scenario: The plugin module contents
When I open "lib/newplugin.rb"
Then I should see
"""
module Newplugin
def self.start
#do any startup when this plugin initializes
end
def self.stop
#perform any necessary cleanup when this plugin is shut down.
end
end
"""
Scenario: The version file is generated
When I open "lib/newplugin/version.rb"
Then I should see
"""
module Newplugin
VERSION = 0.0.1
end
"""
Scenario: The spec_helper is created
When I open "spec/spec_helper.rb"
Then I should see
"""
$:.unshift(Pathname(__FILE__).dirname.join('../lib'))
require 'newplugin'
"""

View File

@ -0,0 +1,30 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "jenkins/plugin/tools/version"
Gem::Specification.new do |s|
s.name = "jenkins-plugin-tools"
s.version = Jenkins::Plugin::Tools::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Charles Lowell"]
s.email = ["cowboyd@thefrontside.net"]
s.homepage = "http://github.com/cowboyd/jenkins-plugins.rb"
s.summary = %q{Tools for creating and building Jenkins Ruby plugins}
s.description = %q{I'll think of a better description later, but if you're reading this, then I haven't}
s.rubyforge_project = "jenkins-plugin-tools"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_dependency "rubyzip"
s.add_dependency "thor"
s.add_dependency "jenkins-war"
s.add_development_dependency "rspec", "~> 2.0"
s.add_development_dependency "cucumber", "~> 1.0"
s.add_development_dependency "jenkins-war"
end

View File

@ -0,0 +1,7 @@
module Jenkins
class Plugin
module Tools
VERSION = "0.0.1"
end
end
end

74
lib/jenkins/rake.rb Normal file
View File

@ -0,0 +1,74 @@
require 'jenkins/plugin/tools/version'
require 'zip/zip'
module Jenkins
class Rake
def self.install_tasks
self.new.install
end
include ::Rake::DSL if defined? ::Rake::DSL
def install
desc "remove built artifacts"
task :clean do
sh "rm -rf pkg"
sh "rm -rf vendor"
end
# verify that necessary metadata constants are defined
task :verify_constants do
["PluginName","PluginVersion"].each do |n|
fail("Constant #{n} is not defined") unless Object.const_defined?(n)
end
end
directory target = "pkg"
desc "bundle gems"
task :bundle => [target] do
require 'java'
puts "bundling..."
ENV['BUNDLE_APP_CONFIG'] = "#{target}/vendor/bundle"
sh "bundle install --standalone --path #{target}/vendor/gems --without development"
end
desc "package up stuff into HPI file"
task :package => [:verify_constants, target, :bundle] do
file_name = "#{target}/#{::PluginName}.hpi"
File.delete file_name if File.exists?(file_name)
Zip::ZipFile.open(file_name, Zip::ZipFile::CREATE) do |zipfile|
zipfile.get_output_stream("META-INF/MANIFEST.MF") do |f|
f.puts "Manifest-Version: 1.0"
f.puts "Created-By: #{Jenkins::Plugin::Tools::VERSION}"
f.puts "Build-Ruby-Platform: #{RUBY_PLATFORM}"
f.puts "Build-Ruby-Version: #{RUBY_VERSION}"
f.puts "Group-Id: org.jenkins-ci.plugins"
f.puts "Short-Name: #{::PluginName}"
f.puts "Long-Name: #{::PluginName}" # TODO: better name
f.puts "Url: http://jenkins-ci.org/" # TODO: better value
# f.puts "Compatible-Since-Version:"
f.puts "Plugin-Class: ruby.RubyPlugin"
f.puts "Plugin-Version: #{::PluginVersion}"
f.puts "Jenkins-Version: 1.426"
f.puts "Plugin-Dependencies: ruby-runtime:0.1-SNAPSHOT"
# f.puts "Plugin-Developers:"
end
zipfile.mkdir("WEB-INF/classes")
["lib","models","views", "#{target}/vendor"].each do |d|
Dir.glob("#{d}/**/*") do |f|
if !File.directory? f
zipfile.add("WEB-INF/classes/#{f.gsub("#{target}/",'')}",f)
end
end
end
end
puts "#{::PluginName} plugin #{::PluginVersion} built to #{file_name}"
end
end
end
end