Permalink
Browse files

create a separate gem for the jenkins plugins ruby runtime support cl…

…asses
  • Loading branch information...
0 parents commit 8045bc0936b89249da4c9a959b08854ff54e5987 @cowboyd cowboyd committed Aug 19, 2011
Showing with 1,270 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +4 −0 Gemfile
  3. +19 −0 Rakefile
  4. +28 −0 jenkins-plugin-runtime.gemspec
  5. +15 −0 lib/jenkins/launcher.rb
  6. +57 −0 lib/jenkins/model.rb
  7. +37 −0 lib/jenkins/model/action.rb
  8. +21 −0 lib/jenkins/model/build.rb
  9. +52 −0 lib/jenkins/model/descriptor.rb
  10. +47 −0 lib/jenkins/model/listener.rb
  11. +105 −0 lib/jenkins/plugin.rb
  12. +20 −0 lib/jenkins/plugin/cli.rb
  13. +130 −0 lib/jenkins/plugin/proxies.rb
  14. +50 −0 lib/jenkins/plugin/proxies/build_wrapper.rb
  15. +22 −0 lib/jenkins/plugin/proxies/builder.rb
  16. +76 −0 lib/jenkins/plugin/proxy.rb
  17. +13 −0 lib/jenkins/plugin/runtime.rb
  18. +5 −0 lib/jenkins/plugin/version.rb
  19. +9 −0 lib/jenkins/slaves/cloud.rb
  20. +37 −0 lib/jenkins/tasks/build_wrapper.rb
  21. +33 −0 lib/jenkins/tasks/builder.rb
  22. +8 −0 spec/jenkins/launcher_spec.rb
  23. +36 −0 spec/jenkins/model/action_spec.rb
  24. +8 −0 spec/jenkins/model/build_spec.rb
  25. +31 −0 spec/jenkins/model/listener_spec.rb
  26. +71 −0 spec/jenkins/model_spec.rb
  27. +7 −0 spec/jenkins/plugin_spec.rb
  28. +22 −0 spec/jenkins/plugins/proxies/build_wrapper_spec.rb
  29. +24 −0 spec/jenkins/plugins/proxies/builder_spec.rb
  30. +24 −0 spec/jenkins/plugins/proxies/proxy_helper.rb
  31. +148 −0 spec/jenkins/plugins/proxies_spec.rb
  32. +43 −0 spec/jenkins/plugins/proxy_spec.rb
  33. +7 −0 spec/jenkins/tasks/build_wrapper_spec.rb
  34. +8 −0 spec/jenkins/tasks/builder_spec.rb
  35. +11 −0 spec/spec_helper.rb
  36. +18 −0 src/jenkins/ruby/DoDynamic.java
  37. +18 −0 src/jenkins/ruby/Get.java
@@ -0,0 +1,6 @@
+*.gem
+.bundle
+.idea
+Gemfile.lock
+pkg/*
+target/
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in jenkins-plugins.gemspec
+gemspec
@@ -0,0 +1,19 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec)
+
+require 'jenkins/war'
+Jenkins::War.classpath
+ClassPath = FileList[File.join(ENV['HOME'], '.jenkins', 'wars', Jenkins::War::VERSION, "**/*.jar")].to_a.join(':')
+
+desc "compile java source code"
+task "compile" => "target" do
+ puts command = "javac -classpath #{ClassPath} #{FileList['src/**/*.java']} -d target"
+ system(command)
+end
+
+require 'rake/clean'
+directory "target"
+CLEAN.include("target")
@@ -0,0 +1,28 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "jenkins/plugin/version"
+
+Gem::Specification.new do |s|
+ s.name = "jenkins-plugin-runtime"
+ s.version = Jenkins::Plugin::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{Runtime support libraries for 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-runtime"
+
+ 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 "json"
+
+ s.add_development_dependency "rspec", "~> 2.0"
+ s.add_development_dependency "cucumber", "~> 1.0"
+ s.add_development_dependency "jenkins-war"
+
+end
@@ -0,0 +1,15 @@
+
+module Jenkins
+
+ # Launch processes on build slaves. No functionality is currently exposed
+ class Launcher
+ # the nantive hudson.Launcher object
+ attr_reader :native
+
+ def initialize(native = nil)
+ @native = native
+ end
+
+ Plugin::Proxies.register self, Java.hudson.Launcher
+ end
+end
@@ -0,0 +1,57 @@
+
+module Jenkins
+ module Model
+
+ module Included
+ def included(cls)
+ super(cls)
+ if cls.class == Module
+ cls.extend(Included)
+ else
+ cls.extend(ClassMethods)
+ cls.send(:include, InstanceMethods)
+ end
+ end
+ end
+ extend Included
+
+ module InstanceMethods
+ # Get the display name of this Model. This value will be used as a default
+ # whenever this model needs to be shown in the UI. If no display name has
+ # been set, then it will use the Model's class name.
+ #
+ # @return [String] the display name
+ def display_name
+ self.class.display_name
+ end
+ end
+
+ module ClassMethods
+
+ # Set or get the display name of this Model Class.
+ #
+ # If `name` is not nil, then sets the display name.
+ # @return [String] the display name
+ def display_name(name = nil)
+ name.nil? ? @display_name || self.name : @display_name = name.to_s
+ end
+
+ # Mark a set of properties that should not be persisted as part of this Model's lifecycle.
+ #
+ # Jenkins supports transparent persistent
+ def transient(*properties)
+ properties.each do |p|
+ transients[p.to_sym] = true
+ end
+ end
+
+ def transient?(property)
+ transients.keys.member?(property.to_sym) || (superclass < Model && superclass.transient?(property))
+ end
+
+ def transients
+ @transients ||= {}
+ end
+ end
+ end
+end
@@ -0,0 +1,37 @@
+
+module Jenkins
+ module Model
+ module Action
+ include Model
+
+ module Included
+ def included(cls)
+ super(cls)
+ if cls.class == Module
+ cls.extend(Included)
+ else
+ cls.extend(ClassMethods)
+ cls.send(:include, InstanceMethods)
+ end
+ end
+ end
+ extend Included
+
+ # def included(cls)
+ # super(cls)
+ # cls.send(:include)
+ # end
+ module InstanceMethods
+ def icon
+ self.class.icon
+ end
+ end
+ #
+ module ClassMethods
+ def icon(path = nil)
+ path.nil? ? @path : @path = path.to_s
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,21 @@
+
+module Jenkins
+ module Model
+ ##
+ # Represents a single build. In general, you won't need this
+ #
+ class Build
+
+ ##
+ # the Hudson::Model::AbstractBuild represented by this build
+ attr_reader :native
+
+ def initialize(native = nil)
+ @native = native
+ end
+
+ Jenkins::Plugin::Proxies.register self, Java.hudson.model.AbstractBuild
+ end
+
+ end
+end
@@ -0,0 +1,52 @@
+
+require 'json'
+
+module Jenkins
+ module Model
+ class Descriptor < Java.hudson.model.Descriptor
+
+ def initialize(name, impl, plugin, java_type)
+ super(Java.org.jruby.RubyObject.java_class)
+ @name, @impl, @plugin, @java_type = name, impl, plugin, java_type
+ end
+
+ def getDisplayName
+ @impl.display_name
+ end
+
+ def getT()
+ @java_type
+ end
+
+ def getConfigPage
+ "/ruby/plugin/views/#{@name}/config.jelly".tap do |path|
+ puts "getConfigPage -> #{path}"
+ end
+ end
+
+ def getGlobalConfigPage
+ "/ruby/plugin/views/#{@name}/global.jelly".tap do |path|
+ puts "getGlobalConfigPage -> #{path}"
+ end
+ end
+
+ def newInstance(request, form)
+ properties = JSON.parse(form.toString(2))
+ properties.delete("kind")
+ properties.delete("stapler-class")
+ instance = @plugin.export(construct(properties))
+ puts "instance created: #{instance}"
+ return instance
+ end
+
+ private
+
+ def construct(attrs)
+ @impl.new(attrs)
+ rescue ArgumentError
+ @impl.new
+ end
+ end
+
+ end
+end
@@ -0,0 +1,47 @@
+
+module Jenkins
+ module Model
+
+ # Receive/Send events about a running task
+ class Listener
+
+ # the underlying hudson.model.TaskListener object
+ attr_reader :native
+
+ def initialize(native = nil)
+ @native = native
+ end
+
+ ##
+ # Insert a clickable hyperlink into this tasks's output
+ # @param [String] url the link target
+ # @param [String] text the link content
+ def hyperlink(url, text)
+ @native.hyperlink(url, text)
+ end
+
+ ##
+ # Append a message to the task output.
+ # @param [String] msg the message
+ def log(msg)
+ @native.getLogger().write(msg.to_s)
+ end
+
+ ##
+ # Append an error message to the task output.
+ # @param [String] msg the error message
+ def error(msg)
+ @native.error(msg.to_s)
+ end
+
+ ##
+ # Append a fatal error message to the task output
+ # @param [String] msg the fatal error message
+ def fatal(msg)
+ @native.fatalError(msg.to_s)
+ end
+
+ Jenkins::Plugin::Proxies.register self, Java.hudson.util.AbstractTaskListener
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 8045bc0

Please sign in to comment.