if(null == pomFile || !pomFile.exists() || !pomFile.canRead())
{
String pomPath = (null == pomFile) ? "null" : pomFile.getAbsolutePath();
throw new JGitFlowReleaseException("pom file must be readable! " + pomPath);
}
String cleanScmUrl = "not defined";
try
{
String content = ReleaseUtil.readXmlFile(pomFile, ls);
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new StringReader( content ));
Element root = document.getRootElement();
Element scmElement = root.getChild("scm", getNamespaceOrNull(root));
if(null != scmElement)
{
String scmUrl = (null != scm.getDeveloperConnection()) ? scm.getDeveloperConnection() : scm.getConnection();
cleanScmUrl = scmUrl.substring(8);
if(!Strings.isNullOrEmpty(scmUrl) && "git".equals(ScmUrlUtils.getProvider(scmUrl)))
{
foundGitScm = true;
StoredConfig config = flow.git().getRepository().getConfig();
String originUrl = config.getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME,"url");
if(Strings.isNullOrEmpty(originUrl) || !cleanScmUrl.equals(originUrl))
{
getLogger().info("adding origin from scm...");
config.setString(ConfigConstants.CONFIG_REMOTE_SECTION,Constants.DEFAULT_REMOTE_NAME,"url",cleanScmUrl);
config.setString(ConfigConstants.CONFIG_REMOTE_SECTION,Constants.DEFAULT_REMOTE_NAME,"fetch","+refs/heads/*:refs/remotes/origin/*");
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION,flow.getMasterBranchName(),"remote",Constants.DEFAULT_REMOTE_NAME);
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION,flow.getMasterBranchName(),"merge",Constants.R_HEADS + flow.getMasterBranchName());
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION,flow.getDevelopBranchName(),"remote",Constants.DEFAULT_REMOTE_NAME);
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION,flow.getDevelopBranchName(),"merge",Constants.R_HEADS + flow.getDevelopBranchName());
config.save();
try
{
config.load();
flow.git().fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).call();
}
catch (Exception e)
{
throw new JGitFlowReleaseException("error configuring remote git repo with url: " + cleanScmUrl, e);
}
getLogger().info("pulling changes from new origin...");
Ref originMaster = GitHelper.getRemoteBranch(flow.git(), flow.getMasterBranchName());
if(null != originMaster)
{
Ref localMaster = GitHelper.getLocalBranch(flow.git(),flow.getMasterBranchName());
RefUpdate update = flow.git().getRepository().updateRef(localMaster.getName());
update.setNewObjectId(originMaster.getObjectId());
update.forceUpdate();
}
Ref originDevelop = GitHelper.getRemoteBranch(flow.git(),flow.getDevelopBranchName());
if(null != originDevelop)
{
Ref localDevelop = GitHelper.getLocalBranch(flow.git(),flow.getDevelopBranchName());
RefUpdate updateDevelop = flow.git().getRepository().updateRef(localDevelop.getName());
updateDevelop.setNewObjectId(originDevelop.getObjectId());
updateDevelop.forceUpdate();
}
commitAllChanges(flow.git(),"committing changes from new origin");
}
}
}
}
catch (IOException e)
{
throw new JGitFlowReleaseException("error configuring remote git repo with url: " + cleanScmUrl, e);
}
catch (JDOMException e)
{
throw new JGitFlowReleaseException("error configuring remote git repo with url: " + cleanScmUrl, e);
}
catch (JGitFlowIOException e)
{
throw new JGitFlowReleaseException("error configuring remote git repo with url: " + cleanScmUrl, e);
}
}
}
if(!foundGitScm)
{
throw new JGitFlowReleaseException("No GIT Scm url found in reactor projects!");
}
}