Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Better Stapler integration that support the view directories to be in

  'foo_bar_zot' format.

- Added a new XStream integration that converts Ruby objects into XML,
  not YAML.
  • Loading branch information...
commit 4bec5787757cd3c76723b072545fff683c059bad 1 parent 0223437
@kohsuke kohsuke authored
View
12 pom.xml
@@ -19,6 +19,11 @@
<artifactId>jruby-complete</artifactId>
<version>1.6.1</version>
</dependency>
+ <dependency>
+ <groupId>org.jenkins-ci</groupId>
+ <artifactId>jruby-xstream</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
@@ -32,6 +37,13 @@
<id>codehaus</id>
<url>http://repository.codehaus.org/</url>
</repository>
+ <repository>
+ <id>maven.jenkins-ci.org</id>
+ <url>http://maven.jenkins-ci.org/content/repositories/snapshots/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
</repositories>
View
22 src/main/java/ruby/RubyPlugin.java
@@ -1,5 +1,6 @@
package ruby;
+import com.thoughtworks.xstream.XStream;
import hudson.Extension;
import hudson.ExtensionComponent;
import hudson.Plugin;
@@ -7,8 +8,11 @@
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.Items;
+import hudson.util.XStream2;
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.Script;
+import org.jenkinsci.jruby.JRubyMapper;
+import org.jenkinsci.jruby.JRubyXStream;
import org.jruby.embed.LocalContextScope;
import org.jruby.embed.ScriptingContainer;
import org.jruby.javasupport.proxy.InternalJavaProxy;
@@ -33,6 +37,11 @@
public static RubyPlugin get() {
return Hudson.getInstance().getPlugin(RubyPlugin.class);
}
+
+ public static Object getRubyController() {
+ return get().plugin;
+ }
+
public static Object callMethod(Object object, String methodName, Object... args) {
return RubyPlugin.get().ruby.callMethod(object, methodName, args);
}
@@ -46,8 +55,6 @@ public static String readf(String resource, Object... args) {
}
public RubyPlugin() {
- Hudson.XSTREAM.aliasType("rubyobject", InternalJavaProxy.class);
- Items.XSTREAM.aliasType("rubyobject", InternalJavaProxy.class);
this.ruby = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
this.ruby.setClassLoader(this.getClass().getClassLoader());
this.ruby.getLoadPaths().add(0, this.getClass().getResource("support").getPath());
@@ -57,9 +64,18 @@ public RubyPlugin() {
Object pluginClass = this.ruby.runScriptlet("Hudson::Plugin::Controller");
this.plugin = this.ruby.callMethod(pluginClass, "new", this);
+ register((XStream2)Hudson.XSTREAM, ruby);
+ register((XStream2)Items.XSTREAM, ruby);
}
- public String read(String resource) {
+ private void register(XStream2 xs, ScriptingContainer ruby) {
+ JRubyXStream.register(xs,ruby);
+ synchronized (xs) {
+ xs.setMapper(new JRubyMapper(xs.getMapperInjectionPoint()));
+ }
+ }
+
+ public String read(String resource) {
InputStream stream = this.getClass().getResourceAsStream(resource);
try {
if (stream == null) {
View
15 src/main/java/ruby/RubyXStreamConverter.java
@@ -1,15 +0,0 @@
-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
10 src/main/resources/ruby/support/hudson/plugin/build_wrapper.rb
@@ -20,7 +20,7 @@ class Wrapper < Java::HudsonTasks::BuildWrapper
def initialize(plugin, object)
super()
puts "Hudson::Plugin::BuildWrapper::Wrapper.new(#{plugin}, #{object})"
- @plugin, @object = plugin, object
+ @object = object
end
def setUp(build, launcher, listener)
@@ -29,8 +29,12 @@ def setUp(build, launcher, listener)
end
def getDescriptor
- puts "object.class: #{@object.class} -> #{@plugin.descriptors[@object.class]}"
- @plugin.descriptors[@object.class]
+ puts "object.class: #{@object.class} -> #{plugin.descriptors[@object.class]}"
+ plugin.descriptors[@object.class]
+ end
+
+ def plugin
+ Java::Ruby::RubyPlugin.getRubyController()
end
def unwrap
View
4 src/main/resources/ruby/support/hudson/plugin/controller.rb
@@ -12,16 +12,12 @@ def initialize(java)
@wrappers = {}
require 'bundled-gems.jar'
require 'rubygems'
- require 'support/hudson/plugin/converter'
script = 'support/hudson/plugin/models.rb'
self.instance_eval @java.read(script), script
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)
- Java::HudsonModel::Items::XSTREAM.registerConverter(converter)
end
def start
View
22 src/main/resources/ruby/support/hudson/plugin/converter.rb
@@ -1,22 +0,0 @@
-require 'yaml'
-
-module Hudson
- module Plugin
- class Converter < Java::Ruby::RubyXStreamConverter
-
- def initialize(plugin)
- super()
- @plugin = plugin
- end
-
- def marshal(source, writer, context)
- writer.setValue("\n" + source.unwrap.to_yaml)
- end
-
- def unmarshal(reader, context)
- @plugin.export YAML.load(reader.getValue())
- end
-
- end
- end
-end
View
0  src/main/resources/TestRootAction/call-tags.erb → src/main/resources/test_root_action/call-tags.erb
File renamed without changes
View
2  src/main/resources/TestRootAction/index.erb → src/main/resources/test_root_action/index.erb
@@ -1,6 +1,6 @@
<html>
<body>
-I am <%= it.class %>
+I am <%= it.class %>!!
<%= 1+1 %>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.