jenkins-plugin 0.1.5 → 0.1.6

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/bin/jpi CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'jpi/cli'
3
+ require 'jenkins/plugin/cli'
4
4
 
5
- JPI::CLI.start
5
+ Jenkins::Plugin::CLI.start ARGV
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency "thor"
24
24
  s.add_dependency "jenkins-war", ">= 1.427"
25
25
  s.add_dependency "bundler", "~> 1.0.0"
26
+ s.add_dependency "jenkins-plugin-runtime", "~> 0.1.6"
26
27
 
27
28
  s.add_development_dependency "rspec", "~> 2.0"
28
29
  s.add_development_dependency "cucumber", "~> 1.0"
@@ -0,0 +1,41 @@
1
+
2
+ require 'thor'
3
+ require 'jenkins/plugin/specification'
4
+ require 'jenkins/plugin/cli/formatting'
5
+
6
+
7
+ module Jenkins
8
+ class Plugin
9
+ class CLI < Thor
10
+ extend Formatting
11
+
12
+ desc "server", "run a test server with plugin"
13
+ method_option :home, :desc => "set server work directory", :default => 'work'
14
+ method_option :port, :desc => "server http port (currently ignored)", :default => 8080
15
+ def server
16
+ require 'jenkins/plugin/tools/server'
17
+ server = Jenkins::Plugin::Tools::Server.new(spec, options[:home])
18
+ server.run!
19
+ end
20
+
21
+ desc "version", "show jpi version information"
22
+ def version
23
+ require 'jenkins/plugin/version'
24
+ shell.say Jenkins::Plugin::VERSION
25
+ end
26
+ map ["-v","--version"] => "version"
27
+
28
+ desc "help [COMMAND]", "get help for COMMAND, or for jpi itself"
29
+ def help(command = nil)
30
+ super
31
+ end
32
+
33
+ private
34
+
35
+ def spec
36
+ Specification.find!
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,54 @@
1
+
2
+ module Jenkins
3
+ class Plugin
4
+ class CLI < Thor
5
+ module Formatting
6
+ def task_help(shell, task_name)
7
+ meth = normalize_task_name(task_name)
8
+ task = all_tasks[meth]
9
+ handle_no_task_error(meth) unless task
10
+
11
+ shell.say "usage: #{banner(task)}"
12
+ shell.say
13
+ class_options_help(shell, nil => task.options.map { |_, o| o })
14
+ end
15
+
16
+
17
+ def print_options(shell, options, grp = nil)
18
+ return if options.empty?
19
+ table = options.map do |option|
20
+ prototype = if option.default
21
+ " [#{option.default}]"
22
+ elsif option.type == :boolean
23
+ ""
24
+ elsif option.required?
25
+ " #{option.banner}"
26
+ else
27
+ " [#{option.banner}]"
28
+ end
29
+ aliases = option.aliases.empty? ? "" : option.aliases.join(" ") + ","
30
+ [aliases, "--#{option.name}#{prototype}", "\t",option.description]
31
+ end
32
+ shell.print_table(table, :ident => 2)
33
+ shell.say
34
+ end
35
+
36
+ def help(shell, task)
37
+ list = printable_tasks
38
+ print shell.set_color("jpi", :black, true)
39
+ shell.say <<-USEAGE
40
+ - tools to create, build, develop and release Jenkins plugins
41
+
42
+ Usage: jpi command [arguments] [options]
43
+
44
+ USEAGE
45
+
46
+ shell.say "Commands:"
47
+ shell.print_table(list, :ident => 2, :truncate => true)
48
+ shell.say
49
+ class_options_help(shell)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,45 @@
1
+
2
+ module Jenkins
3
+ class Plugin
4
+ module Tools
5
+ class Manifest
6
+
7
+ def initialize(spec)
8
+ @spec = spec
9
+ end
10
+
11
+ def write_hpi(io)
12
+ io.puts "Manifest-Version: 1.0"
13
+ io.puts "Created-By: #{Jenkins::Plugin::VERSION}"
14
+ io.puts "Build-Ruby-Platform: #{RUBY_PLATFORM}"
15
+ io.puts "Build-Ruby-Version: #{RUBY_VERSION}"
16
+
17
+ io.puts "Group-Id: org.jenkins-ci.plugins"
18
+ io.puts "Short-Name: #{@spec.name}"
19
+ io.puts "Long-Name: #{@spec.name}" # TODO: better name
20
+ io.puts "Url: http://jenkins-ci.org/" # TODO: better value
21
+
22
+ io.puts "Plugin-Class: ruby.RubyPlugin"
23
+ io.puts "Plugin-Version: #{@spec.version}"
24
+ io.puts "Jenkins-Version: 1.426"
25
+
26
+ io.puts "Plugin-Dependencies: " + @spec.dependencies.map{|k,v| "#{k}:#{v}"}.join(",")
27
+ end
28
+
29
+ def write_hpl(io, loadpath)
30
+ write_hpi(io)
31
+
32
+ io.puts "Load-Path: #{loadpath.to_a.join(':')}"
33
+ io.puts "Lib-Path: #{Dir.pwd}/lib/"
34
+ io.puts "Models-Path: #{Dir.pwd}/models"
35
+ # Stapler expects view erb/haml scripts to be in the JVM ClassPath
36
+ io.puts "Class-Path: #{Dir.pwd}/views"
37
+ # Directory for static images, javascript, css, etc. of this plugin.
38
+ # The static resources are mapped under #CONTEXTPATH/plugin/SHORTNAME/
39
+ io.puts "Resource-Path: #{Dir.pwd}/static"
40
+
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,61 @@
1
+ require 'net/http'
2
+
3
+ module Jenkins
4
+ class Plugin
5
+ module Tools
6
+ class Resolver
7
+
8
+ def initialize(spec, dir)
9
+ @spec = spec
10
+ @dir = dir
11
+ FileUtils.mkdir_p(dir) unless File.directory? @dir
12
+ end
13
+
14
+ def resolve!
15
+ @spec.dependencies.each do |name, version|
16
+ FileUtils.cp resolve(name, version), @dir
17
+ end
18
+ end
19
+
20
+ def resolve(short_name,version)
21
+ # this is where we expect the retrieved file to be
22
+ cache = File.expand_path "~/.jenkins/cache/plugins/#{short_name}/#{version}/#{short_name}.hpi"
23
+
24
+ return cache if File.exists?(cache)
25
+
26
+ # now we start looking for places to find them
27
+
28
+ # is it in the local maven2 repository?
29
+ maven = File.expand_path "~/.m2/repository/org/jenkins-ci/plugins/#{short_name}/#{version}/#{short_name}-#{version}.hpi"
30
+ return maven if File.exists?(maven)
31
+
32
+ # download from the community update center
33
+ FileUtils.mkdir_p(File.dirname(cache))
34
+ open(cache+".tmp","wb") do |f|
35
+ puts "Downloading #{short_name} #{version}"
36
+ url = "http://updates.jenkins-ci.org/download/plugins/#{short_name}/#{version}/#{short_name}.hpi?for=ruby-plugin"
37
+ puts " from #{url}"
38
+ f.write fetch(url).body
39
+ end
40
+ FileUtils.mv cache+".tmp", cache
41
+
42
+ return cache
43
+ end
44
+
45
+ # download with redirect support
46
+ def fetch(uri, limit = 10)
47
+ # You should choose better exception.
48
+ raise ArgumentError, 'HTTP redirect too deep' if limit == 0
49
+
50
+ response = Net::HTTP.get_response(URI.parse(uri))
51
+ case response
52
+ when Net::HTTPSuccess then response
53
+ when Net::HTTPRedirection then fetch(response['location'], limit - 1)
54
+ else
55
+ response.error!
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,46 @@
1
+ require 'jenkins/plugin/tools/loadpath'
2
+ require 'jenkins/plugin/tools/resolver'
3
+ require 'jenkins/plugin/tools/manifest'
4
+ require 'jenkins/war'
5
+ require 'fileutils'
6
+
7
+ module Jenkins
8
+ class Plugin
9
+ module Tools
10
+ class Server
11
+
12
+ def initialize(spec, workdir)
13
+ @spec = spec
14
+ @workdir = workdir
15
+ @plugindir = "#{workdir}/plugins"
16
+ end
17
+
18
+ def run!
19
+ FileUtils.mkdir_p(@plugindir)
20
+ loadpath = Jenkins::Plugin::Tools::Loadpath.new
21
+ manifest = Jenkins::Plugin::Tools::Manifest.new(@spec)
22
+ resolver = Jenkins::Plugin::Tools::Resolver.new(@spec, @plugindir)
23
+
24
+ resolver.resolve!
25
+ # generate the plugin manifest
26
+
27
+ File.open("#{@plugindir}/#{@spec.name}.hpl",mode="w+") do |f|
28
+ manifest.write_hpl(f, loadpath)
29
+ end
30
+
31
+
32
+ # execute Jenkins
33
+ args = []
34
+ args << "java"
35
+ args << "-Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n"
36
+ args << "-DJENKINS_HOME=#{@workdir}"
37
+ args << "-Dstapler.trace=true"
38
+ args << "-Ddebug.YUI=true"
39
+ args << "-jar"
40
+ args << Jenkins::War::LOCATION
41
+ exec *args
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  module Jenkins
2
2
  class Plugin
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
@@ -11,26 +11,6 @@ module Jenkins
11
11
  @spec ||= Jenkins::Plugin::Specification.load(Dir['*.pluginspec'].first)
12
12
  end
13
13
 
14
- def self.generate_manifest(f)
15
- f.puts "Manifest-Version: 1.0"
16
- f.puts "Created-By: #{Jenkins::Plugin::VERSION}"
17
- f.puts "Build-Ruby-Platform: #{RUBY_PLATFORM}"
18
- f.puts "Build-Ruby-Version: #{RUBY_VERSION}"
19
-
20
- f.puts "Group-Id: org.jenkins-ci.plugins"
21
- f.puts "Short-Name: #{Jenkins.spec.name}"
22
- f.puts "Long-Name: #{Jenkins.spec.name}" # TODO: better name
23
- f.puts "Url: http://jenkins-ci.org/" # TODO: better value
24
- # f.puts "Compatible-Since-Version:"
25
- f.puts "Plugin-Class: ruby.RubyPlugin"
26
- f.puts "Plugin-Version: #{Jenkins.spec.version}"
27
- f.puts "Jenkins-Version: 1.426"
28
-
29
- f.puts "Plugin-Dependencies: " + Jenkins.spec.dependencies.map{|k,v| "#{k}:#{v}"}.join(",")
30
- # f.puts "Plugin-Developers:"
31
- end
32
-
33
-
34
14
  class Rake
35
15
  def self.install_tasks
36
16
  self.new.install
@@ -48,13 +28,6 @@ module Jenkins
48
28
  sh "rm -rf vendor"
49
29
  end
50
30
 
51
- # verify that necessary metadata constants are defined
52
- task :verify_constants do
53
- ["PluginName","PluginVersion"].each do |n|
54
- fail("Constant #{n} is not defined") unless Object.const_defined?(n)
55
- end
56
- end
57
-
58
31
  desc "output the development servers loadpath"
59
32
  task :loadpath do
60
33
  loadpath = Jenkins::Plugin::Tools::Loadpath.new(:default)
@@ -75,7 +48,7 @@ module Jenkins
75
48
  end
76
49
 
77
50
  desc "package up stuff into HPI file"
78
- task :package => [:verify_constants, target, :bundle] do
51
+ task :package => [target, :bundle] do
79
52
 
80
53
  file_name = "#{target}/#{Jenkins.spec.name}.hpi"
81
54
  File.delete file_name if File.exists?(file_name)
@@ -98,53 +71,13 @@ module Jenkins
98
71
  puts "#{Jenkins.spec.name} plugin #{Jenkins.spec.version} built to #{file_name}"
99
72
  end
100
73
 
101
- desc "resolve dependency plugins into #{work}/plugins"
102
- task :'resolve-dependency-plugins' => [work] do
103
- FileUtils.mkdir_p("#{work}/plugins")
104
-
105
- puts "Copying plugin dependencies into #{work}/plugins"
106
- Jenkins.spec.dependencies.each do |short_name,version|
107
- FileUtils.cp Jenkins::Plugin::Tools::Hpi::resolve(short_name,version), "#{work}/plugins/#{short_name}.hpi", :verbose=>true
108
- end
109
- end
110
-
111
74
  desc "run a Jenkins server with this plugin"
112
- task :server => :'resolve-dependency-plugins' do
113
- require 'jenkins/war'
114
- require 'zip/zip'
115
- require 'fileutils'
116
-
117
- loadpath = Jenkins::Plugin::Tools::Loadpath.new
118
-
119
- # generate the plugin manifest
120
- FileUtils.mkdir_p("#{work}/plugins")
121
- File.open("#{work}/plugins/#{Jenkins.spec.name}.hpl",mode="w+") do |f|
122
- Jenkins.generate_manifest f
75
+ task :server do
76
+ require 'jenkins/plugin/tools/server'
123
77
 
124
- f.puts "Load-Path: #{loadpath.to_a.join(':')}"
125
- f.puts "Lib-Path: #{Dir.pwd}/lib/"
126
- f.puts "Models-Path: #{Dir.pwd}/models"
127
- # Stapler expects view erb/haml scripts to be in the JVM ClassPath
128
- f.puts "Class-Path: #{Dir.pwd}/views"
129
- # Directory for static images, javascript, css, etc. of this plugin.
130
- # The static resources are mapped under #CONTEXTPATH/plugin/SHORTNAME/
131
- f.puts "Resource-Path: #{Dir.pwd}/static"
132
- end
133
-
134
- # TODO: assemble dependency plugins
135
-
136
- # execute Jenkins
137
- args = []
138
- args << "java"
139
- args << "-Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n"
140
- args << "-DJENKINS_HOME=#{work}"
141
- args << "-Dstapler.trace=true"
142
- args << "-Ddebug.YUI=true"
143
- args << "-jar"
144
- args << Jenkins::War::LOCATION
145
- exec *args
78
+ server = Jenkins::Plugin::Tools::Server.new(Jenkins.spec, "work")
79
+ server.run!
146
80
  end
147
-
148
81
  end
149
82
  end
150
83
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jenkins-plugin
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.5
5
+ version: 0.1.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Charles Lowell
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-16 00:00:00 -05:00
13
+ date: 2011-09-19 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -58,27 +58,38 @@ dependencies:
58
58
  type: :runtime
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
61
- name: rspec
61
+ name: jenkins-plugin-runtime
62
62
  prerelease: false
63
63
  requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.6
69
+ type: :runtime
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
64
75
  none: false
65
76
  requirements:
66
77
  - - ~>
67
78
  - !ruby/object:Gem::Version
68
79
  version: "2.0"
69
80
  type: :development
70
- version_requirements: *id005
81
+ version_requirements: *id006
71
82
  - !ruby/object:Gem::Dependency
72
83
  name: cucumber
73
84
  prerelease: false
74
- requirement: &id006 !ruby/object:Gem::Requirement
85
+ requirement: &id007 !ruby/object:Gem::Requirement
75
86
  none: false
76
87
  requirements:
77
88
  - - ~>
78
89
  - !ruby/object:Gem::Version
79
90
  version: "1.0"
80
91
  type: :development
81
- version_requirements: *id006
92
+ version_requirements: *id007
82
93
  description: I'll think of a better description later, but if you're reading this, then I haven't
83
94
  email:
84
95
  - cowboyd@thefrontside.net
@@ -96,8 +107,13 @@ files:
96
107
  - bin/jpi
97
108
  - features/create-new-plugin.feature
98
109
  - jenkins-plugin.gemspec
110
+ - lib/jenkins/plugin/cli.rb
111
+ - lib/jenkins/plugin/cli/formatting.rb
99
112
  - lib/jenkins/plugin/tools/hpi.rb
100
113
  - lib/jenkins/plugin/tools/loadpath.rb
114
+ - lib/jenkins/plugin/tools/manifest.rb
115
+ - lib/jenkins/plugin/tools/resolver.rb
116
+ - lib/jenkins/plugin/tools/server.rb
101
117
  - lib/jenkins/plugin/version.rb
102
118
  - lib/jenkins/rake.rb
103
119
  has_rdoc: true