2727import com .cloudbees .jenkins .plugins .bitbucket .impl .endpoint .BitbucketServerEndpoint ;
2828import com .cloudbees .jenkins .plugins .bitbucket .impl .webhook .plugin .PluginWebhookConfiguration ;
2929import com .cloudbees .jenkins .plugins .bitbucket .impl .webhook .server .ServerWebhookConfiguration ;
30+ import edu .umd .cs .findbugs .annotations .NonNull ;
3031import hudson .Extension ;
3132import io .jenkins .plugins .casc .ConfigurationAsCode ;
3233import io .jenkins .plugins .casc .ConfigurationContext ;
34+ import io .jenkins .plugins .casc .Configurator ;
3335import io .jenkins .plugins .casc .ConfiguratorException ;
3436import io .jenkins .plugins .casc .impl .configurators .DataBoundConfigurator ;
3537import io .jenkins .plugins .casc .model .Mapping ;
3638import java .util .logging .Logger ;
3739import org .kohsuke .accmod .Restricted ;
3840import org .kohsuke .accmod .restrictions .NoExternalUse ;
3941
40- import static org .apache .commons .lang3 .StringUtils .trimToNull ;
41-
4242/**
4343 * Specialised class to configure how to build a new instance of
4444 * BitbucketServerEndpoint using {@link ConfigurationAsCode}.
@@ -55,19 +55,26 @@ public BitbucketServerEndpointConfigurator() {
5555 }
5656
5757 @ Override
58- protected BitbucketServerEndpoint instance (Mapping mapping , ConfigurationContext context ) throws ConfiguratorException {
59- final String displayName = mapping .getScalarValue ("displayName" );
58+ protected BitbucketServerEndpoint instance (@ NonNull Mapping mapping , @ NonNull ConfigurationContext context ) throws ConfiguratorException {
59+ final Configurator <String > stringConfigurator = context .lookupOrFail (String .class );
60+
61+ final String displayName = stringConfigurator .configure (mapping .get ("displayName" ), context );
62+ mapping .remove ("displayName" );
63+
6064 final String serverURL ;
6165 if (mapping .containsKey ("serverUrl" )) {
62- serverURL = mapping .getScalarValue ("serverUrl" );
66+ serverURL = stringConfigurator .configure (mapping .get ("serverUrl" ), context );
67+ mapping .remove ("serverUrl" );
6368 } else {
64- serverURL = mapping .getScalarValue ("serverURL" );
69+ serverURL = stringConfigurator .configure (mapping .get ("serverURL" ), context );
70+ mapping .remove ("serverURL" );
6571 }
6672 String serverVersion = null ;
6773 if (mapping .containsKey ("serverVersion" )) {
68- serverVersion = mapping .getScalarValue ("serverVersion" );
74+ serverVersion = stringConfigurator .configure (mapping .get ("serverVersion" ), context );
75+ mapping .remove ("serverVersion" );
6976 }
70- BitbucketWebhookConfiguration webhook = getWebhook (mapping );
77+ BitbucketWebhookConfiguration webhook = getWebhook (mapping , context );
7178 BitbucketServerEndpoint endpoint = new BitbucketServerEndpoint (displayName , serverURL , webhook );
7279 if (serverVersion != null ) {
7380 endpoint .setServerVersion (serverVersion );
@@ -85,31 +92,39 @@ protected BitbucketServerEndpoint instance(Mapping mapping, ConfigurationContext
8592 }
8693
8794 @ SuppressWarnings ("deprecation" )
88- private BitbucketWebhookConfiguration getWebhook (Mapping mapping ) {
95+ private BitbucketWebhookConfiguration getWebhook (@ NonNull Mapping mapping , @ NonNull ConfigurationContext context ) {
96+ final Configurator <String > stringConfigurator = context .lookupOrFail (String .class );
97+ final Configurator <Boolean > boolConfigurator = context .lookupOrFail (Boolean .class );
98+
8999 boolean manageHooks = false ;
90100 if (mapping .containsKey ("manageHooks" )) {
91101 logger .warning ("manageHooks is deprecated, replace from your CasC definition with the appropriate webhook definition." );
92- manageHooks = Boolean .parseBoolean (trimToNull (mapping .getScalarValue ("manageHooks" )));
102+ manageHooks = boolConfigurator .configure (mapping .get ("manageHooks" ), context );
103+ mapping .remove ("manageHooks" );
93104 }
94105 String credentialsId = null ;
95106 if (mapping .containsKey ("credentialsId" )) {
96107 logger .warning ("credentialsId is deprecated, replace from your CasC definition with the appropriate webhook definition." );
97- credentialsId = mapping .getScalarValue ("credentialsId" );
108+ credentialsId = stringConfigurator .configure (mapping .get ("credentialsId" ), context );
109+ mapping .remove ("credentialsId" );
98110 }
99111 boolean enableHookSignature = false ;
100112 if (mapping .containsKey ("enableHookSignature" )) {
101113 logger .warning ("enableHookSignature is deprecated, replace from your CasC definition with the appropriate webhook definition." );
102- enableHookSignature = Boolean .parseBoolean (trimToNull (mapping .getScalarValue ("enableHookSignature" )));
114+ enableHookSignature = boolConfigurator .configure (mapping .get ("enableHookSignature" ), context );
115+ mapping .remove ("enableHookSignature" );
103116 }
104117 String hookSignatureCredentialsId = null ;
105118 if (mapping .containsKey ("hookSignatureCredentialsId" )) {
106119 logger .warning ("hookSignatureCredentialsId is deprecated, replace from your CasC definition with the appropriate webhook definition." );
107- hookSignatureCredentialsId = mapping .getScalarValue ("hookSignatureCredentialsId" );
120+ hookSignatureCredentialsId = stringConfigurator .configure (mapping .get ("hookSignatureCredentialsId" ), context );
121+ mapping .remove ("hookSignatureCredentialsId" );
108122 }
109123 String webhookImplementation = null ;
110124 if (mapping .containsKey ("webhookImplementation" )) {
111125 logger .warning ("webhookImplementation is deprecated, replace from your CasC definition with the appropriate webhook definition." );
112- webhookImplementation = mapping .getScalarValue ("webhookImplementation" );
126+ webhookImplementation = stringConfigurator .configure (mapping .get ("webhookImplementation" ), context );
127+ mapping .remove ("webhookImplementation" );
113128 }
114129 BitbucketWebhookConfiguration webhook ;
115130 if ("NATIVE" .equals (webhookImplementation )) {
0 commit comments