Test Link的Jenkins插件源码分析(参数)

Datetime:2017-02-03 07:08:22         Topic: Source Code Analysis          Share        Original >>
Here to See The Original Article!!!

POJO类TestLinkInstallation 

public class TestLinkInstallation 
implements Serializable
{

……
	
	@DataBoundConstructor
	public TestLinkInstallation(
		String name, 
		String url, 
		String devKey, 
		String testLinkJavaAPIProperties
	)

Descriptor实现类TestLinkBuilderDescriptor 

public class TestLinkBuilderDescriptor extends BuildStepDescriptor<Builder> {

	@CopyOnWrite
	private volatile TestLinkInstallation[] installations = new TestLinkInstallation[0];

	public TestLinkBuilderDescriptor() {
		super(TestLinkBuilder.class);
		load();
	}

	public TestLinkInstallation[] getInstallations() {
		return this.installations;
	}

	@Override
	public boolean configure(StaplerRequest req, JSONObject json)
			throws hudson.model.Descriptor.FormException {
		this.installations = req.bindParametersToList(
				TestLinkInstallation.class, "TestLink.").toArray(
				new TestLinkInstallation[0]);
		save();
		return true;
	}

	public FormValidation doCheckMandatory(@QueryParameter String value) {
		FormValidation returnValue = FormValidation.ok();
		if (StringUtils.isBlank(value)) {
			returnValue = FormValidation.error(Messages
					.TestLinkBuilder_MandatoryProperty());
		}
		return returnValue;
	}
}

Builder类TestLinkBuilder

public class TestLinkBuilder extends AbstractTestLinkBuilder {

	@Extension
	public static final TestLinkBuilderDescriptor DESCRIPTOR = new TestLinkBuilderDescriptor();

	 
	@Override
	public Descriptor<Builder> getDescriptor() {
	    return (TestLinkBuilderDescriptor) super.getDescriptor();
	}
}

/testlink-plugin/src/main/resources/hudson/plugins/testlink/ TestLinkBuilder/global.jelly

<j:jelly xmlns:j="jelly:core"
         xmlns:f="/lib/form">

    <f:section title="TestLink">
        <f:entry title="${%TestLink Installation}"
                 description="${%List Of TestLink Installations}">
            <f:repeatable var="inst" items="${descriptor.installations}">
                <table width="100%">

                    <f:entry title="${%Name}">
                        <f:textbox name="TestLink.name" value="${inst.name}"
                                   checkUrl="'${rootURL}/builder/TestLinkBuilder/checkMandatory?value='+escape(this.value)"/>
                    </f:entry>

                    <f:entry title="URL" help="${rootURL}/../plugin/testlink/help-testlinkUrl.html">
                        <f:textbox name="TestLink.url" value="${inst.url}"
                                   default="http://localhost/testlink/lib/api/xmlrpc.php"
                                   checkUrl="'${rootURL}/builder/TestLinkBuilder/checkMandatory?value='+escape(this.value)"/>
                    </f:entry>

                    <f:entry title="${%Developer Key}">
                        <f:textbox name="TestLink.devKey" value="${inst.devKey}"
                                   checkUrl="'${rootURL}/builder/TestLinkBuilder/checkMandatory?value='+escape(this.value)"/>
                    </f:entry>

                    <f:advanced>
                        <f:entry title="${%TestLink Java API Properties}"
                                 help="${rootURL}/../plugin/testlink/help-testlinkJavaAPIProperties.html">
                            <f:textbox name="TestLink.testLinkJavaAPIProperties"
                                       value="${inst.testLinkJavaAPIProperties}"/>
                        </f:entry>
                    </f:advanced>

                    <f:entry title="">
                        <div align="right">
                            <f:repeatableDeleteButton/>
                        </div>
                    </f:entry>

                </table>
            </f:repeatable>
        </f:entry>
    </f:section>

</j:jelly>

/testlink-plugin/src/main/resources/hudson/plugins/testlink/ TestLinkBuilder/config.jelly

<f:entry title="${%TestLink Version}" help="${rootURL}/../plugin/testlink/help-testlinkVersion.html">
        <select class="setting-input" name="TestLinkBuilder.testLinkName">
            <option>(Default)</option>
            <j:forEach var="inst" items="${descriptor.installations}">
                <f:option selected="${inst.name==instance.testLinkName}">${inst.name}</f:option>
            </j:forEach>
        </select>
    </f:entry>

TestLink插件源代码地址:

https://github.com/jenkinsci/testlink-plugin








New