The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass parameters to my client-web-panel plugin?

Steven Cason
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 2, 2017

I'm creating a plugin to decorate the commit overview page. The decorations will be links to an external Web app. The URLs will vary depending on the environment in which the plugin is running, e.g. dev, val, prd. So each Bitbucket server instance should be configurable to pass the correct URL to the plugin for the encvironment in which it runs.

Based on this, I think I need a server-side .properties file in the home dir, a server-side ContextProvider in Java calling ApplicationPropertiesService.getPluginProperty and returning the result in its getContextMap method, and a client-context-provider on the client side. But it's not working for me: Spring throws an NPE at the first reference to the local (@Inject-ed) ApplicationPropertiesService.

I realize the abovementioned article is about hooks, while I'm doing a plugin, and they're different. Maybe there is no ApplicationPropertiesService in the Spring context when processing a plugin?

Is there a canonical way to pass an environment-specific value to client-side plugin code?

atlassian-plugin.xml:

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="3">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
        <permissions>
            <permission>execute_java</permission>
        </permissions>
    </plugin-info>

    <!-- add our i18n resource -->
    <resource type="i18n" name="i18n" location="v1-for-bitbucket-plugin"/>

    <client-resource key="commit-comment-overview-resources" name="Commit Overview Resources">
        <directory location="/css/" />
        <directory location="/js/" />
        <directory location="/soy/" />

        <dependency>com.atlassian.auiplugin:ajs</dependency>
        <dependency>com.atlassian.bitbucket.server.bitbucket-web-api:amd</dependency>
    </client-resource>
   
    <client-web-panel key="commit-comment-create-story-id" location="bitbucket.commit.related-entities">
     <context-provider class="gov.ssa.mde.v1_4_bb_plugin.PluginContextProvider"/>
        <client-context-provider>Bitbucket.commitcommentstory.ContextProvider</client-context-provider>
        <resource name="view" type="soy"
   location="gov.ssa.mde.v1-4-bb-plugin.versionone-for-bitbucket-plugin:commit-comment-overview-resources/com.bitbucket.commitcommentstory.commitForm" />
        <dependency>gov.ssa.mde.v1-4-bb-plugin.versionone-for-bitbucket-plugin:commit-comment-overview-resources</dependency>
    </client-web-panel>

</atlassian-plugin>

gov.ssa.mde.v1_4_bb_plugin.PluginContextProvider:
(NPE thrown at line 41)

package gov.ssa.mde.v1_4_bb_plugin;

import java.util.Map;

import javax.inject.Inject;

import com.atlassian.bitbucket.server.ApplicationPropertiesService;
import com.atlassian.plugin.PluginParseException;
import com.atlassian.plugin.web.ContextProvider;
import com.google.common.collect.ImmutableMap;

public class PluginContextProvider implements ContextProvider {

 @Inject
  public ApplicationPropertiesService appPropsSvc;
 
 public ApplicationPropertiesService getAppPropsSvc() {
  return appPropsSvc;
 }

 public void setAppPropsSvc(ApplicationPropertiesService appPropsSvc) {
  this.appPropsSvc = appPropsSvc;
 }

 private String baseUrlKey = "plugin.v1_4_bb_plugin.v1_base_url";
 private String missingUrlVal = "V1_base_url_missing!";
 private String baseUrl = null;
 private ImmutableMap<String, Object> newContext = null;
 
 public PluginContextProvider() {
 }

 @Override
 public Map<String, Object> getContextMap(Map<String, Object> arg0) {
  System.out.println(this.getClass().getName() + ".getContextMap invoked.");

  // Seems BB isn't calling the init method, so I'm placing its code here til I figure out the problem.
  this.baseUrl = appPropsSvc.getPluginProperty(baseUrlKey, missingUrlVal);
  System.out.println(this.getClass().getName() + ".getContextMap got base url:" + this.baseUrl + ".");
  this.newContext = ImmutableMap.<String, Object>builder()
                   .put(baseUrlKey, this.baseUrl)
                   .build();
  System.out.println(this.getClass().getName() + ".getContextMap built newContext:" + this.newContext + ".");

  System.out.println(this.getClass().getName() + ".getContextMap returning " + this.newContext.toString());
  return this.newContext;
 }

 @Override
 public void init(Map<String, String> arg0) throws PluginParseException {
  System.out.println(this.getClass().getName() + ".init invoked.");
  this.baseUrl = appPropsSvc.getPluginProperty(baseUrlKey, missingUrlVal);
  this.newContext = ImmutableMap.<String, Object>builder()
                   .put(baseUrlKey, baseUrl)
                   .build();
  System.out.println(this.getClass().getName() + ".init initialized newContext = " + this.newContext.toString());
 }

}

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Steven Cason
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 2, 2017

 

 

 

TAGS
AUG Leaders

Atlassian Community Events