Issue Type: Bug Bug
Assignee: Fred G
Components: extra-columns
Created: 25/Jul/13 2:50 PM
Description:

Hi,

I need to programmatically create some sectioned views (via groovy script to ease maintenance of hundreds of jobs on multiple projects/teams/views)
I was previously using version 1.2 of the plugin with an old version of Jenkins. All was OK.

Since we migrated to Jenkins 1.509.2 + plugin 1.10 my script doesn't work any more because of:
"Failed to instantiate class jenkins.plugins.extracolumns.TestResultColumn from null"

Looking at:
hudson.model.Descriptor.newInstance(StaplerRequest req, JSONObject formData)
showed it "return verifyNewInstance(clazz.newInstance());" where clazz is jenkins.plugins.extracolumns.TestResultColumn and can't instantiate a new instance as there is only one constructor that needs an int in parameter.

It would be handy to add a no param constructor that set the int to a default value to be able to run column creation through their Descriptor and not have to add a specific case for TestResultColumn.

This is a snippet of my groovy script:

import hudson.DescriptorExtensionList
import hudson.model.*
import hudson.model.Descriptor.FormException
import hudson.plugins.sectioned_view.*
import hudson.util.*
import hudson.views.*

DEFAULT_COLUMNS = [
        BuildButtonColumn.class                                                 // OK
        ,com.robestone.hudson.compactcolumns.JobNameColumn.class                // OK
        ,LastDurationColumn.class                                               // OK
        ,jenkins.plugins.extracolumns.TestResultColumn.class                    // NOK
    ]

println("Init our columns ...")
myColumns = [];
DescriptorExtensionList<ListViewColumn, Descriptor<ListViewColumn>> all = ListViewColumn.all();

for (Class<? extends ListViewColumn> d: DEFAULT_COLUMNS) {
    Descriptor<ListViewColumn> des = all.find(d);
    if (des  != null) {
        println("Case " + d)
        switch(d) {
            case jenkins.plugins.extracolumns.TestResultColumn.class:
                println("descriptor = " + des)
                println("descriptor.clazz = " + des.clazz)
                println()
                try {
                    clazzInst = d.newInstance()
                    println("+++Successfully run TestResultColumn.newInstance() = " + clazzInst)
                    myColumns.add(clazzInst);
                } catch (Exception exp) {
                    println("!!!Exception while instantiating new TestResultColumn(): " + exp.getMessage())
                }
                try {
                    clazzInst0 = d.newInstance(0)
                    println("+++Successfully run new TestResultColumn.newInstance(0) = " + clazzInst0)
                    myColumns.add(clazzInst0);
                } catch (Exception exp) {
                    println("!!!Exception while instantiating new TestResultColumn(0): " + exp.getMessage())
                }
                try {
                    tmp = des.newInstance(null,null)
                    myColumns.add(tmp);
                    println("+++Successfully run TestResultColumn.DescriptorImpl.newInstance(null, null) = " + tmp)
                } catch (Error exp) {
                    println("!!!Error while TestResultColumn.DescriptorImpl.newInstance(null, null): " + exp.getMessage())
                }
            break
            default:
                myColumns.add(des.newInstance(null, null));
            break
        }
    }
    else
    {
        println("No descriptior found for " + d)
    }
}

println("\nResulting columns ...")
myColumns.each {println(it)}

Give me your thoughts. Maybe there is another way to do this!

Cheers,

Greg

Environment: Groovy script
Project: Jenkins
Priority: Major Major
Reporter: Greg Nion
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply via email to