SubmoduleOp: make superProjectSubscriptionsForSubmoduleBranch public
We need access to that method in the delete-project plugin, see I456346f67dac4d906fcd016b2dad5fea12459150. Refactor SubmoduleOp and GitModules in a way that we convert IOExceptions to SubmoduleException late instead of in each method. By doing that we do not need to expose the SubmoduleException for superProjectSubscriptionsForSubmoduleBranch. Change-Id: Ic6c05fad9f8581b132f17eebb624d6aa2362bd00 Signed-off-by: Stefan Beller <sbeller@google.com>
This commit is contained in:
@@ -81,7 +81,7 @@ public class GitModules {
|
||||
}
|
||||
}
|
||||
|
||||
void load() throws SubmoduleException {
|
||||
void load() throws IOException {
|
||||
Project.NameKey project = branch.getParentKey();
|
||||
logDebug("Loading .gitmodules of {} for project {}", branch, project);
|
||||
try (Repository repo = repoManager.openRepository(project);
|
||||
@@ -104,8 +104,8 @@ public class GitModules {
|
||||
|
||||
subscriptions = subSecParserFactory.create(bbc, thisServer,
|
||||
branch).parseAllSections();
|
||||
} catch (ConfigInvalidException | IOException e) {
|
||||
throw new SubmoduleException(
|
||||
} catch (ConfigInvalidException e) {
|
||||
throw new IOException(
|
||||
"Could not read .gitmodule file of super project: " +
|
||||
branch.getParentKey(), e);
|
||||
}
|
||||
|
||||
@@ -132,24 +132,20 @@ public class SubmoduleOp {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Collection<SubmoduleSubscription>
|
||||
public Collection<SubmoduleSubscription>
|
||||
superProjectSubscriptionsForSubmoduleBranch(
|
||||
Branch.NameKey branch) throws SubmoduleException {
|
||||
Branch.NameKey branch) throws IOException {
|
||||
logDebug("Calculating possible superprojects for " + branch);
|
||||
Collection<SubmoduleSubscription> ret = new ArrayList<>();
|
||||
Project.NameKey project = branch.getParentKey();
|
||||
ProjectConfig cfg = projectCache.get(project).getConfig();
|
||||
try {
|
||||
for (SubscribeSection s : cfg.getSubscribeSections(branch)) {
|
||||
Collection<Branch.NameKey> branches = getDestinationBranches(branch, s);
|
||||
for (Branch.NameKey targetBranch : branches) {
|
||||
GitModules m = gitmodulesFactory.create(targetBranch, updateId);
|
||||
m.load();
|
||||
ret.addAll(m.subscribedTo(branch));
|
||||
}
|
||||
for (SubscribeSection s : cfg.getSubscribeSections(branch)) {
|
||||
Collection<Branch.NameKey> branches = getDestinationBranches(branch, s);
|
||||
for (Branch.NameKey targetBranch : branches) {
|
||||
GitModules m = gitmodulesFactory.create(targetBranch, updateId);
|
||||
m.load();
|
||||
ret.addAll(m.subscribedTo(branch));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SubmoduleException("Could not update superproject", e);
|
||||
}
|
||||
logDebug("Calculated superprojects for " + branch + " are "+ ret);
|
||||
return ret;
|
||||
@@ -169,11 +165,15 @@ public class SubmoduleOp {
|
||||
Multimap<Branch.NameKey, SubmoduleSubscription> targets =
|
||||
HashMultimap.create();
|
||||
|
||||
for (Branch.NameKey updatedBranch : updatedBranches) {
|
||||
for (SubmoduleSubscription sub :
|
||||
superProjectSubscriptionsForSubmoduleBranch(updatedBranch)) {
|
||||
targets.put(sub.getSuperProject(), sub);
|
||||
try {
|
||||
for (Branch.NameKey updatedBranch : updatedBranches) {
|
||||
for (SubmoduleSubscription sub :
|
||||
superProjectSubscriptionsForSubmoduleBranch(updatedBranch)) {
|
||||
targets.put(sub.getSuperProject(), sub);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SubmoduleException("Could not calculate all superprojects");
|
||||
}
|
||||
updatedSubscribers.addAll(updatedBranches);
|
||||
// Update subscribers.
|
||||
|
||||
Reference in New Issue
Block a user