Bamboo repositories: how to get from PlanRepositoryDefinition to a Git or SVN repository

In the past I developed a Bamboo plugin that works with an SVN repository. For example, I got an instance of com.atlassian.bamboo.repository.svn.SvnRepository through (SvnRepository) buildContext.getRepositoryDefinitions().getRepository().
In the 5.14 API much of this has changed. Now I’m confused and I also need to add support for a Git repository.

How can I get from a PlanRepositoryDefinition to an SVN repository and to a Git repository. Also, how can I check what type of repository I’m dealing with?
Some code snippets would be highly appreciated.

Thank you!.

Figured out this is one way to do it, based on one of the existing plugins for SVN:

A few snippets from my code, based on the existing class com.atlassian.bamboo.plugins.vcs.task.configuration.VcsCheckoutTaskConfigurator:

VcsRepositoryModuleDescriptor moduleDescriptor = getModuleDescriptor(repositoryToCheckout);

SvnChangeDetector svnChangeDetector = (SvnChangeDetector) moduleDescriptor.getChangeDetector();
final Key entityKey = taskContext.getCommonContext().getResultKey().getEntityKey();
PlanKey planKey = PlanKeys.getPlanKey(entityKey.getKey());
VcsRepositoryData vcsRepositoryData = repositoryDefinitionManager.getVcsRepositoryData(repositoryToCheckout.getId());
String startCommitId = moduleDescriptor.getBranchDetector().getFirstCommitApproximation(vcsRepositoryData).getChangeSetId();
PlanVcsRevisionData planVcsRevisionData = new PlanVcsRevisionData(startCommitId,null,null);
BuildRepositoryChanges buildRepositoryChanges = svnChangeDetector.collectChangesSinceRevision(planKey, vcsRepositoryData, planVcsRevisionData);