private ConfigFeatureBranch startNewBranch(Object id, boolean batch) throws ProvisioningException { if(currentBranch != null && currentBranch.isEmpty() && (currentBranch.anonymous && id == null || id != null && id.equals(currentBranch.id))) { if (currentBranch.isBatch() == batch) { return currentBranch; } currentBranch.setBatch(batch); return currentBranch; } if(id == null) { currentBranch = new ConfigFeatureBranch(featureBranches.size(), batch); } else if (branchesWithId.isEmpty()) { branchesWithId = new HashMap<>(); currentBranch = new ConfigFeatureBranch(id, batch); branchesWithId.put(id, currentBranch); } else { currentBranch = branchesWithId.get(id); if (currentBranch == null) { currentBranch = new ConfigFeatureBranch(id, batch); branchesWithId.put(id, currentBranch); } else { return currentBranch; } } featureBranches.add(currentBranch); return currentBranch; }
void addBranchDep(ConfigFeatureBranch branchDep, boolean child) { final Boolean prevChild = branchDeps.get(branchDep); if(prevChild == null || !prevChild && child) { if(branchDeps.put(branchDep, child) != null && branch != null) { branch.addBranchDep(branchDep); } } }
private boolean createsDepCircle(ConfigFeatureBranch branch, ResolvedFeature feature) { if(branch.isEmpty() || feature.branchDeps.isEmpty()) { return false; } //System.out.println("createDepCircle " + branch + " " + feature.branchDeps); Set<ConfigFeatureBranch> visitedBranches = null; for(ConfigFeatureBranch newDep : feature.branchDeps.keySet()) { if(newDep.id.equals(branch.id)) { continue; } if(branch.dependsOn(newDep)) { continue; } if(newDep.dependsOn(branch)) { return true; } if(visitedBranches == null) { visitedBranches = new HashSet<>(); visitedBranches.add(branch); } if(createsDepCircle(newDep, visitedBranches)) { return true; } } return false; }
private boolean createsDepCircle(ConfigFeatureBranch next, Set<ConfigFeatureBranch> visitedBranches) { if(!next.hasDeps()) { return false; } visitedBranches.add(next); for(ConfigFeatureBranch newDep : next.getDeps()) { if(visitedBranches.contains(newDep)) { return true; } if(createsDepCircle(newDep, visitedBranches)) { return true; } } visitedBranches.remove(next); return false; }
private void orderBranches(ConfigFeatureBranch branch) { if(branch.isOrdered() || branch.isEmpty() /* TODO look into why there could be an empty branch */) { return; if(branch.hasDeps()) { for(ConfigFeatureBranch dep : branch.getDeps()) { orderBranches(dep); branch.ordered(); orderedFeatures.addAll(branch.getFeatures()); } else if(mergeIndependentBranches) { branch.ordered(); // it's important to call ordered on the branch before the batch flags are manipulated if(branch.isBatch()) { if(independentBatchBranch.isEmpty()) { independentBatchBranch = new ArrayList<>(); } else { final ResolvedFeature firstOnBranch = branch.getFeatures().get(0); firstOnBranch.clearStartBranch(); firstOnBranch.clearBatchStart(); independentBatchBranch.addAll(branch.getFeatures()); } else { if(independentNonBatchBranch.isEmpty()) { independentNonBatchBranch = new ArrayList<>(); } else { final ResolvedFeature firstOnBranch = branch.getFeatures().get(0); firstOnBranch.clearStartBranch(); final ResolvedFeature lastOnBranch = independentNonBatchBranch.get(independentNonBatchBranch.size() - 1); lastOnBranch.clearEndBranch();
currentBranch.setFkBranch(); if (feature.branchDeps.size() == 1) { final Map.Entry<ConfigFeatureBranch, Boolean> next = branchDepIter.next(); if (next.getValue() && next.getKey().isFkBranch()) { return next.getKey(); if (!next.getValue() || !next.getKey().isFkBranch()) { continue; branch = startNewBranch(null, feature.spec.isBatchBranch(branchIsBatch)); branch.setFkBranch(); onParentChildrenBranch = true; return branch; || currentBranch.isSpecBranch() || currentBranch.isFkBranch() || createsDepCircle(currentBranch, feature)) { startNewBranch(null, feature.spec.isBatchBranch(branchIsBatch));
private void orderAndMergeBranchesWithSameDeps(ConfigFeatureBranch branch) { if(branch.isOrdered() || branch.isEmpty()) { return; final Set<ConfigFeatureBranch> branchDeps = branch.getDeps(); if(!branchDeps.isEmpty()) { for(ConfigFeatureBranch dep : branchDeps) { branch.ordered(); final List<ResolvedFeature> branchFeatures = branch.getFeatures(); branchesByDeps.put(depsId, new ArrayList<>(branchFeatures)); if(branch.isBatch()) { branchFeatures.get(0).startBatch(); branchFeatures.get(branchFeatures.size() - 1).endBatch(); final ResolvedFeature lastFeature = features.get(features.size() - 1); lastFeature.clearEndBranch(); final List<ResolvedFeature> branchFeatures = branch.getFeatures(); final ResolvedFeature firstFeature = branchFeatures.get(0); firstFeature.clearStartBranch(); if(branch.isBatch()) { if(lastFeature.isBatchEnd()) { lastFeature.clearBatchEnd();
void setBranch(ConfigFeatureBranch branch) throws ProvisioningException { this.branch = branch; if(branchDeps.size() > 1 || !branchDeps.containsKey(branch)) { final Iterator<ConfigFeatureBranch> iter = branchDeps.keySet().iterator(); while(iter.hasNext()) { final ConfigFeatureBranch branchDep = iter.next(); if(!branch.id.equals(branchDep.id)) { branch.addBranchDep(branchDep); } } } if(branchDependees != null) { for(ResolvedFeature branchDependee : branchDependees) { branchDependee.addBranchDep(branch, false); } branchDependees = null; } ordered(); }