jenkinsci / jenkins.rb

Deprecated, see https://www.jenkins.io/jep/7
393 stars 83 forks source link

DataBoundConstructor error #94

Open jdamick opened 11 years ago

jdamick commented 11 years ago

I'm trying to extend the parameterizedtrigger plugin and i'm running the the following error (below), i have my annotation set for DataBoundConstructor but something must not be set right.. Any ideas would be appreciated. thanks

Caused by: java.lang.IllegalArgumentException: Failed to convert the configs parameter of the constructor public hudson.plugins.parameterizedtrigger.BuildTriggerConfig(java.lang.String,hudson.plugins.parameterizedtrigger.ResultCondition,boolean,java.util.List)
    at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:590)
    ... 61 more
Caused by: java.lang.IllegalArgumentException: Failed to instantiate class hudson.plugins.parameterizedtrigger.AbstractBuildParameters from {"stapler-class":"hudson.plugins.parameterizedtrigger.AbstractBuildParameters","kind":"BakeryIngredientsBuilder-IngredientsBuildParameters"}
    at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:596)
    at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:632)
    at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:391)
    at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:588)
    ... 61 more
Caused by: org.kohsuke.stapler.NoStaplerConstructorException: There's no @DataBoundConstructor on any constructor of class hudson.plugins.parameterizedtrigger.AbstractBuildParameters
    at org.kohsuke.stapler.ClassDescriptor.loadConstructorParamNames(ClassDescriptor.java:176)
    at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:575)
    ... 64 more

My code is this:

include Java
java_import Java.hudson.plugins.parameterizedtrigger.AbstractBuildParameters
java_import Java.org.kohsuke.stapler.DataBoundConstructor;

class IngredientsBuildParameters < AbstractBuildParameters
  include Jenkins::Model
  include Jenkins::Model::Describable

  display_name "Bakery Ingredients Parameters"
  describe_as Java.hudson.plugins.parameterizedtrigger.AbstractBuildParameters

  java_annotation "DataBoundConstructor"
  def initialize(attrs={})

  end

  #public abstract Action getAction(AbstractBuild<?,?> build, TaskListener listener)
  #            throws IOException, InterruptedException, DontTriggerException;
  def getAction(build, listener)
  end
end
kohsuke commented 11 years ago

I had the conversation with @jdamick and he seems to think that injecting a Hash would be OK given that the constructor injection is hard with JRuby.

In the mean time, the work around is to override Descriptor.newInstance() but not sure how that translates to the Ruby runtime.