How can I access the repositoryDefinitionManager from a Bamboo Rest plugin

I am writing (updating) a Bamboo REST endpoint to try to manipulate the repository properties. The previous code was doing something along the line of:

BuildDefinition definition = plan.getBuildDefinition();
        Repository repo = definition.getRepository();


        HierarchicalConfiguration config = repo.toConfiguration();

        config.setProperty(key, value);
        repo.populateFromConfig(config);

Starting with Bamboo 3.X and the possibility of having multiple repos, I need to use a repositoryDefinitionManager. I added the following setter, but it does not get executed.

public void setRepositoryDefinitionManager(RepositoryDefinitionManager repositoryDefinitionManager)
    {
        this.repositoryDefinitionManager = repositoryDefinitionManager;
    }

As such, when I try to access the repositories, I get a null pointer ( since the repositoryDefinitionManager is null).

Any thoughts?

Also, is there a generic way to update a repository properties like the original snippet (using HierarchicalConfiguration)? I am still not clear on how to save the changes into the repo.

4 answers

1 accepted

Turns out that doing the following worked - it still seems a bit weird to me as of why (why the default injection mechanism does not pick up the setRepositoryDefinitionManager), but it did !

repositoryDefinitionManager = (RepositoryDefinitionManager) ContainerManager.getComponent("repositoryDefinitionManager");

Thats because the object hasn't been made available for Atlassian Plugin v2 plugins. I've asked an engineer to make it available in 4.1, so the standard injection should work fine with that release.

THe "magic" that atlassian's documentation points towards with these setters is dependency injection, using the Spring framework.

To see why an instance is not being provided you can add the @Required annotation to your method.

You should then se4e in the logs an error for that method, likelty something like "unable to find required bean repositoryDefinitionManager as it required a single unique bean but none were available"

If so, it means that class is not in the current context, and you will not be able to get a handle for it. If you do not see any such warnings, but the object remains null than your class is not being registered as a bean in the context, and would point to some configuration troubles.

I added the @Required annotation, no warning/exception got logged, and the object is still null. What should be looking at as far as the configuration is concerned? I have other setters that seem to work properly:

setVariableDefinitionManager

setPlanManager

So it seems like V2 plugins can't have access to the repositoryDefinitionManager. And from what I understand, V1 plugin can't have REST access--> I can't use the repositoryDefinitionManager

Meanwhile, I tried the approach suggested in https://answers.atlassian.com/questions/38471/bamboo-plugin-help-with-repository-and-repositorydefinition

without success - the new definition is not saved.

HierarchicalConfiguration config = repository.toConfiguration();
            	config.setProperty(key, value);
            	repository.populateFromConfig(config);
            	
            	RepositoryDefinition repositoryDefinitionWithNewData = new RepositoryDefinitionImpl(
            			repositoryDefinition.getId(), 
                        repositoryDefinition.getPluginKey(), 
                        repositoryDefinition.getName(), 
                        repositoryDefinition.getPosition(), 
                        repositoryDefinition.getDescription(),
                        RepositoryConfigHelper.prepareXmlConfiguration(repository, 
                                                                       repositoryDefinition.getWebRepositoryViewer()),
                        repositoryDefinition.isBuildTrigger(),
                        repositoryDefinition.isMarkedForDeletion(), 
                        repositoryDefinition.isGlobal());
                
            	PlanHelper.getRepositoryDefinitionMap(plan).put(repositoryDefinitionWithNewData.getId(), repositoryDefinitionWithNewData);


Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

184 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you