Eric Crahen wrote:
I have a question on using custom JobProperties, I'm noticing some strange
behavior.
My plugin adds a custom JobDescriptor to the Jobs.PROPERTIES list and I've
included a very basic config.jelly. in the correct resource path
resources/hudson/plugins/MyJobProperty/global.jelly and a similar one for
config.jelly. It contains a simple f:entry with some text fields to display
some data,
The first thing was that when I create a new Job and enter the Job
Configuration page, I thought I would see some of what was in the
config.jelly in the UI, but there is no addition. Also, there never was a
call to isApplicable() or configure() so it would make sense that nothing
gets added to the UI, but I'm not quire sure why this is.
I just checked the code and apparently this part was broken. I just
committed the change.
The next odd thing was that if I visit the Manage Hudson -> System
Configuration page, I do see the additional fields on the UI for my custom
property, but there isn't a call to configure() until after I hit save. And
load() was never called, so I'm not sure where I have the chance to load the
global settings for a custom property.
The config() will be only invoked when the browser submits the form, so
that sounds correct to me.
The derived class is responsible for calling the load() method by
itself, actually. See for example Ant.DescriptorImpl l.114.
This is quite error prone, yes, but I couldn't do that in the base class
constructor. Maybe I should call the load when descriptors are added to
their respective list?
// -------
package hudson.plugins;
import hudson.model.AbstractProject;
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import hudson.tasks.BuildStep;
import org.kohsuke.stapler.StaplerRequest;
public class MyJobProperty extends JobProperty<AbstractProject<?,?>> {
public static final JobPropertyDescriptor DESCRIPTOR = new Descriptor();
public JobPropertyDescriptor getDescriptor() {
return DESCRIPTOR;
}
private static class Descriptor extends JobPropertyDescriptor {
Descriptor() {
super(MyJobProperty.class);
}
public boolean isApplicable(java.lang.Class<? extends Job> jobType) {
System.out.println(jobType);
return AbstractProject.class.isAssignableFrom(jobType);
}
// TODO: support per-project override to the system-wide setting
public IvyJobProperty newInstance(StaplerRequest req) throws
FormException {
System.err.println("NEW INSTANCE!" + req);
return new IvyJobProperty();
}
public boolean configure(StaplerRequest req) throws FormException {
System.err.println("CONFIG!" + req);
return true;
}
public String getDisplayName() {
return MyJobProperty.class.toString();
}
}
}
// -----------
// Same for global.jelly & config.jelly
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler"
xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson"
xmlns:f="/lib/form">
<f:entry title="MyProperties" help="${rootURL}/plugin/build-timeout/help-
projectConfig.html">
<f:textbox name="myproperties.instance" value="${instance} default" />
<f:textbox name="myproperties.it" value="${it} default" />
</f:entry>
</j:jelly>
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi@xxxxxxx
smime.p7s
Description: S/MIME Cryptographic Signature
|