Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

serialize a ruby object to yaml

  • Loading branch information...
commit af8a5b2f856b71d7c8ebd9445c3821f705459405 1 parent 530eff9
@cowboyd authored
View
14 src/main/java/ruby/RubyXStreamConverter.java
@@ -0,0 +1,14 @@
+package ruby;
+
+import com.thoughtworks.xstream.converters.Converter;
+import org.jruby.javasupport.proxy.InternalJavaProxy;
+
+
+public abstract class RubyXStreamConverter implements Converter {
+
+
+ public boolean canConvert(Class type) {
+ System.out.printf("RubyXStreamConverter.canConvert(%s) -> %s\n", type, ("" + InternalJavaProxy.class.isAssignableFrom(type)));
+ return InternalJavaProxy.class.isAssignableFrom(type);
+ }
+}
View
28 src/main/java/thefrontside/ci/Spike.java
@@ -1,28 +0,0 @@
-package thefrontside.ci;
-
-
-import org.jruby.embed.ScriptingContainer;
-
-public class Spike {
-
- public static void needThread(Thread t) {
- System.out.println("t = " + t);
- System.out.println("t.getClass() = " + t.getClass());
- }
-
- public static void main(String[] args) {
- ScriptingContainer ruby = new ScriptingContainer();
- ruby.runScriptlet("" +
- "class Foo < Java::JavaLang::Thread\n" +
- " def run()\n" +
- " end\n" +
- "end\n" +
- "\n" +
- "class Bar < Java::JavaLang::Thread\n" +
- " def run();puts 'hi';end;\n" +
- "end\n" +
- "");
- ruby.runScriptlet("Java::ThefrontsideCi::Spike.needThread(Foo.new)");
- ruby.runScriptlet("Java::ThefrontsideCi::Spike.needThread(Foo.new)");
- }
-}
View
6 src/main/resources/ruby/support/hudson/plugin/cloud.rb
@@ -18,9 +18,12 @@ def provision(label, excess_workload)
[]
end
+
class Wrapper < Java::HudsonSlaves::Cloud
+
def initialize(plugin, object)
super(object.name)
+ puts "Hudson::Plugin::Cloud::Wrapper.new(#{plugin}, #{object})"
@plugin, @object = plugin, object
end
@@ -32,7 +35,7 @@ def provision(label, excess_workload)
@plugin.export @object.provision(@plugin.import(label), excess_workload)
end
- def descriptor
+ def getDescriptor
@plugin.descriptors[Cloud]
end
@@ -41,6 +44,7 @@ def unwrap
end
end
+
module ClassMethods
def new(properties)
allocate.tap do |instance|
View
10 src/main/resources/ruby/support/hudson/plugin/controller.rb
@@ -14,10 +14,13 @@ def initialize(java)
#It takes too long!
require 'bundled-gems.jar'
require 'rubygems'
+ require 'support/hudson/plugin/converter'
DSL.new(self) do |dsl|
script = @java.read("plugin.rb")
dsl.instance_eval(script, "plugin.rb")
end
+ converter = Hudson::Plugin::Converter.new(self)
+ Java::HudsonModel::Hudson::XSTREAM.registerConverter(converter)
end
def start
@@ -35,9 +38,14 @@ def import(object)
end
def export(object)
+ puts "export(#{object})"
return @wrappers[object] if @wrappers[object]
case object
- when Hudson::Plugin::Cloud then @wrappers[object] = Hudson::Plugin::Cloud::Wrapper.new(self, object)
+ when Hudson::Plugin::Cloud
+ puts "it's a cloud, I'm going to wrap it"
+ wrapper = Hudson::Plugin::Cloud::Wrapper.new(self, object)
+ puts "wrapper created: #{wrapper}"
+ return wrapper
else object
end
end
View
23 src/main/resources/ruby/support/hudson/plugin/converter.rb
@@ -0,0 +1,23 @@
+require 'yaml'
+
+module Hudson
+ module Plugin
+ class Converter < Java::Ruby::RubyXStreamConverter
+
+ def initialize(plugin)
+ super()
+ @plugin = plugin
+ end
+
+ def marshal(source, writer, context)
+ puts "marshal:(#{source.inspect})"
+ writer.setValue(source.unwrap.to_yaml)
+ end
+
+ def unmarshal(reader, context)
+ @plugin.export YAML.parse(reader.getValue())
+ end
+
+ end
+ end
+end
View
7 src/main/resources/ruby/support/hudson/plugin/descriptor.rb
@@ -34,10 +34,9 @@ def newInstance(request, form)
properties = JSON.parse(form.toString(2))
properties.delete("kind")
properties.delete("stapler-class")
- @plugin.export(@impl.new(properties)).tap do |described|
- "described new Instance: #{described.inspect}"
- $stdout.flush()
- end
+ instance = @plugin.export(@impl.new(properties))
+ puts "instance created: #{instance}"
+ return instance
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.