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; }
DefaultBranchedConfigArranger(ConfigModelStack configStack) { this.configStack = configStack; this.specFeatures = configStack.specFeatures; this.features = configStack.features; branchPerSpec = getBooleanProp(configStack.props, ConfigModel.BRANCH_PER_SPEC, false); orderReferencedSpec = branchPerSpec; branchIsBatch = getBooleanProp(configStack.props, ConfigModel.BRANCH_IS_BATCH, false); isolateCircularDeps = getBooleanProp(configStack.props, ConfigModel.ISOLATE_CIRCULAR_DEPS, false); mergeIndependentBranches = getBooleanProp(configStack.props, ConfigModel.MERGE_INDEPENDENT_BRANCHES, false); }
private List<CircularRefInfo> orderProviders(CapabilityProviders providers) throws ProvisioningException { if(providers.isProvided()) { return Collections.emptyList(); } List<CircularRefInfo> firstLoop = null; if (!providers.specs.isEmpty()) { for (SpecFeatures specFeatures : providers.specs) { final List<CircularRefInfo> loop = orderFeaturesInSpec(specFeatures, !specFeatures.isFree()); if (providers.isProvided()) { return Collections.emptyList(); } if (firstLoop == null) { firstLoop = loop; } } } if (!providers.features.isEmpty()) { for (ResolvedFeature provider : providers.features) { final List<CircularRefInfo> loop = orderFeature(provider); if (providers.isProvided()) { return Collections.emptyList(); } if (firstLoop == null) { firstLoop = loop; } } } return firstLoop == null ? Collections.emptyList() : firstLoop; }
circularRefs = orderCapabilityProviders(feature, circularRefs); circularRefs = orderReferencedFeatures(feature, feature.deps.keySet(), false, circularRefs); circularRefs = orderReferencedFeatures(feature, refIds, true, circularRefs); feature.free(); for(CircularRefInfo ref : initiatedCircularRefs) { if(orderFeature(ref.firstInConfig) != null) { throw new IllegalStateException(); startNewBranch(isolateBranchId, true); determineBranch(feature).add(feature); if(orderFeature(ref.nextOnPath) != null) { throw new IllegalStateException(); startNewBranch(null, branchIsBatch); determineBranch(feature).add(feature);
List<ResolvedFeature> orderFeatures() throws ProvisioningException { try { doOrder(configStack.rt); } catch (ProvisioningException e) { throw new ProvisioningException(Errors.failedToBuildConfigSpec(configStack.id.getModel(), configStack.id.getName()), e); if(getBooleanProp(configStack.props, ConfigModel.MERGE_SAME_DEPS_BRANCHES, false)) { this.branchesByDeps = new LinkedHashMap<>(featureBranches.size()); for(ConfigFeatureBranch branch : featureBranches) { orderAndMergeBranchesWithSameDeps(branch); orderBranches(branch);
for(CapabilitySpec cap : specFeatures.spec.xmlSpec.getProvidedCapabilities()) { if(cap.isStatic()) { getProviders(cap.toString(), true).add(specFeatures); } else { for(ResolvedFeature feature : specFeatures.getFeatures()) { getProviders(resolvedCap, true).add(feature); orderFeaturesInSpec(features, false); orderFeature(feature); orderFeature(feature);
final String arranger = System.getProperty(Constants.PROP_CONFIG_ARRANGER); if(arranger == null) { orderedFeatures = new DefaultBranchedConfigArranger(this).orderFeatures(); } else if(Constants.CONFIG_ARRANGER_SPEC_ONLY.equals(arranger)) { orderedFeatures = new SpecOnlyConfigArranger().orderFeatures(this);
if (onParentChildrenBranch) { onParentChildrenBranch = false; startNewBranch(null, branchIsBatch); allCircularRefs = orderFeature(features.get(i++));
if (!createsDepCircle(candidate, feature)) { return candidate; branch = spec.isBranchSet() ? spec.getBranch() : (spec.spec.branchId == null ? null : branchesWithId.get(spec.spec.branchId)); if(branch == null) { branch = startNewBranch(spec.spec.branchId, feature.spec.isBatchBranch(branchIsBatch)); spec.setBranch(branch); } else if (createsDepCircle(branch, feature)) { branch = startNewBranch(null, branchIsBatch); } else if(!spec.isBranchSet()) { spec.setBranch(branch); branch = startNewBranch(null, feature.spec.isBatchBranch(branchIsBatch)); || currentBranch.isSpecBranch() || currentBranch.isFkBranch() || createsDepCircle(currentBranch, feature)) { startNewBranch(null, feature.spec.isBatchBranch(branchIsBatch));
private List<CircularRefInfo> orderCapabilityProviders(ResolvedFeature feature, List<CircularRefInfo> circularRefs) throws ProvisioningException { for (CapabilitySpec capSpec : feature.spec.xmlSpec.getRequiredCapabilities()) { final List<String> resolvedCaps = capResolver.resolve(capSpec, feature); if (resolvedCaps.isEmpty()) { continue; } for (String resolvedCap : resolvedCaps) { final CapabilityProviders providers; try { providers = getProviders(resolvedCap, false); } catch (ProvisioningException e) { throw new ProvisioningException(Errors.noCapabilityProvider(feature, capSpec, resolvedCap)); } circularRefs = CollectionUtils.addAll(circularRefs, orderProviders(providers)); if(providers.isProvided()) { feature.addBranchDep(providers.branches.iterator().next(), false); //System.out.println("added branch dep on cap provider " + feature.getId() + " -> " + providers.branches); } else { providers.addBranchDependee(feature); } } } return circularRefs; }
if(!branchDeps.isEmpty()) { for(ConfigFeatureBranch dep : branchDeps) { orderAndMergeBranchesWithSameDeps(dep);
throw new ProvisioningDescriptionException(Errors.unresolvedFeatureDep(feature, refId)); final List<CircularRefInfo> specLoops = orderFeaturesInSpec(targetSpecFeatures, false); if (specLoops != null) { List<CircularRefInfo> featureLoops = null; throw new ProvisioningDescriptionException(Errors.unresolvedFeatureDep(feature, refId)); final List<CircularRefInfo> circularRefs = orderFeature(dep); if(dep.branch != null) { feature.addBranchDep(dep.branch, refId.isChildRef());
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; }