How to create a plugin that will modify the pom.xml file in a repository?

I created a Bitbucket plugin that is forking a repository and automatically creating a develop branch.
This is working fine so far.

I’m now trying to update the pom.xml file at the root of my repo.

In the rest API of my plugin i’m trying to use the gitExtendedCommandFactory.editFile function but i can’t figure how to get the pom that is actually in the repo to perfom the update.(I need to modify the artifactId and the groupId)

  		Builder pom = new Builder(develop, "pom.xml");

Is it feasible and does anyone has any example ?

Best regards,

PS:I’d like to do it all in the plugin and not use any shell so it can be triggered by end users while they browse repositories in Bitbucket server.

I use ParallelGit to read/write/commit files and maven-model to manipulate pom files.

I would suggest using the ContentService APIs to update the pom.xml. You can use ContentService.streamFile() to retrieve the content of the file and then use ContentService.editFile() to update the content of the file.

        Path tempFile = Files.createTempFile("pom", "xml");
        OutputStream outputStream = Files.newOutputStream(tempFile, APPEND);

        contentService.streamFile(repository, "master", "pom.xml", type -> outputStream);
        //Update pom.xml

        InputStream inputStream = Files.newInputStream(tempFile);

        EditFileRequest request = new EditFileRequest.Builder(branch.getId(), "pom.xml", repository)
                .content(() -> inputStream)
                .message("Updated pom.xml")
1 Like

Hi @jthomas, this looks promissing. However how do I get a reference to contentService? I tried to get a reference to RefService in @EventListener method, but Spring failes to find any implementations of it. I’m using BitBucket 4.9.1 with Spring Resolver. What should be used to write BitBucket plugin to fill newly created repositories with a content? Any hits on

  • availalbe in API services
  • ways to find references to them?