Skip to content

Commit

Permalink
Merge pull request #277 from aloubyansky/GAL-300
Browse files Browse the repository at this point in the history
[GAL-300] ProvisioningLayout collecting updates may iterate over dupl…
  • Loading branch information
aloubyansky authored Nov 25, 2019
2 parents 04d5576 + 017778d commit 20c892f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
77 changes: 49 additions & 28 deletions core/src/main/java/org/jboss/galleon/layout/ProvisioningLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ public void close() {
private Set<ProducerSpec> transitiveDeps;
private Map<ProducerSpec, Set<FPID>> conflicts = Collections.emptyMap();
private Map<ProducerSpec, F> featurePacks = new HashMap<>();
private Map<ProducerSpec, F> mavenProducers = null;
private ArrayList<F> ordered = new ArrayList<>();
private Map<FPID, F> allPatches = Collections.emptyMap();
private Map<FPID, List<F>> fpPatches = Collections.emptyMap();
Expand Down Expand Up @@ -407,7 +408,7 @@ private <O extends FeaturePackLayout> ProvisioningLayout(ProvisioningLayout<O> o
while(--i >= 0) {
final O otherFp = other.ordered.get(i);
final F fp = transformer.transform(otherFp);
featurePacks.put(fp.getFPID().getProducer(), fp);
registerFeaturePack(fp.getFPID().getProducer(), fp);
ordered.add(fp);
}
Collections.reverse(ordered);
Expand Down Expand Up @@ -773,9 +774,12 @@ public boolean hasFeaturePack(ProducerSpec producer) {
}

public F getFeaturePack(ProducerSpec producer) throws ProvisioningException {
final F p = featurePacks.get(producer);
F p = featurePacks.get(producer);
if(p == null) {
throw new ProvisioningException(Errors.unknownFeaturePack(producer.getLocation().getFPID()));
p = mavenProducers == null ? null : mavenProducers.get(producer);
if (p == null) {
throw new ProvisioningException(Errors.unknownFeaturePack(producer.getLocation().getFPID()));
}
}
return p;
}
Expand Down Expand Up @@ -1040,26 +1044,24 @@ private void layout(FeaturePackDepsConfig config, Map<ProducerSpec, FPID> branch
transitiveDeps = new HashSet<>();
}
for(FeaturePackConfig transitiveConfig : config.getTransitiveDeps()) {
FPID fpid = transitiveConfig.getLocation().getFPID();
FeaturePackLocation fpl = transitiveConfig.getLocation();
if(transitiveConfig.hasPatches()) {
addPatches(transitiveConfig);
}
final FPID branchId = branch.get(fpid.getProducer());
final FPID branchId = branch.get(fpl.getProducer());
if (branchId != null) {
if (!branchId.getChannel().getName().equals(fpid.getChannel().getName())) {
addConflict(fpid, branchId);
if (!branchId.getChannel().getName().equals(fpl.getChannel().getName())) {
addConflict(fpl.getFPID(), branchId);
}
continue;
}
if(transitiveConfig.getLocation().isMavenCoordinates()) {
buildTracker.processing(transitiveConfig.getLocation().getFPID());
fpid = layoutFactory.resolveFeaturePack(transitiveConfig.getLocation(), FeaturePackLayout.TRANSITIVE_DEP, fpFactory).getSpec().getFPID();
buildTracker.processed(transitiveConfig.getLocation().getFPID());
registerResolvedVersion(transitiveConfig.getLocation().getProducer(), fpid.getLocation());
if(fpl.isMavenCoordinates()) {
fpl = resolveFeaturePack(fpl, FeaturePackLayout.TRANSITIVE_DEP).getSpec().getFPID().getLocation();
registerResolvedVersion(transitiveConfig.getLocation().getProducer(), fpl);
}
transitiveDeps.add(fpid.getProducer());
branch.put(fpid.getProducer(), fpid);
added = CollectionUtils.add(added, fpid.getProducer());
transitiveDeps.add(fpl.getProducer());
branch.put(fpl.getProducer(), fpl.getFPID());
added = CollectionUtils.add(added, fpl.getProducer());
}
}

Expand All @@ -1081,9 +1083,7 @@ private void layout(FeaturePackDepsConfig config, Map<ProducerSpec, FPID> branch
continue;
}
}
buildTracker.processing(fpl.getFPID());
fp = layoutFactory.resolveFeaturePack(fpl, type, fpFactory);
buildTracker.processed(fpl.getFPID());
fp = resolveFeaturePack(fpl, type);
if(fpl.isMavenCoordinates()) {
if(branchId == null) {
branchId = branch.get(fp.getFPID().getProducer());
Expand All @@ -1092,19 +1092,22 @@ private void layout(FeaturePackDepsConfig config, Map<ProducerSpec, FPID> branch
F resolvedFp = featurePacks.get(resolvedFpl.getProducer());
if(resolvedFp != null) {
converge(branchId, resolvedFpl.getFPID(), resolvedFp.getFPID());
featurePacks.put(fpl.getProducer(), resolvedFp);
if(!fpl.equals(resolvedFpl)) {
registerMavenProducer(fpl.getProducer(), resolvedFp);
}
continue;
} else if(branchId != null) {
buildTracker.processing(resolvedFpl.getFPID());
fp = layoutFactory.resolveFeaturePack(resolvedFpl, type, fpFactory);
buildTracker.processed(resolvedFpl.getFPID());
} else if (!fpl.equals(resolvedFpl)) {
registerResolvedVersion(fpl.getProducer(), resolvedFpl);
}
featurePacks.put(fpl.getProducer(), fp);
fpl = resolvedFpl;
if (!fpl.equals(resolvedFpl)) {
if (branchId != null) {
fp = resolveFeaturePack(resolvedFpl, type);
} else {
registerResolvedVersion(fpl.getProducer(), resolvedFpl);
}
registerMavenProducer(fpl.getProducer(), fp);
fpl = resolvedFpl;
}
}
featurePacks.put(fpl.getProducer(), fp);
registerFeaturePack(fpl.getProducer(), fp);

queue.add(fp);

Expand All @@ -1131,6 +1134,24 @@ private void layout(FeaturePackDepsConfig config, Map<ProducerSpec, FPID> branch
}
}

private void registerFeaturePack(ProducerSpec producer, F f) {
featurePacks.put(producer, f);
}

private void registerMavenProducer(ProducerSpec producer, F f) {
if(mavenProducers == null) {
mavenProducers = new HashMap<>();
}
mavenProducers.put(producer, f);
}

private F resolveFeaturePack(FeaturePackLocation fpl, int type) throws ProvisioningException {
buildTracker.processing(fpl.getFPID());
final F fp = layoutFactory.resolveFeaturePack(fpl, type, fpFactory);
buildTracker.processed(fpl.getFPID());
return fp;
}

protected FeaturePackLocation resolveVersion(FeaturePackLocation fpl, final FPID branchId) throws ProvisioningException {
if(branchId == null) {
return normalize(fpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public FeaturePackLocation replaceBuild(String build) {
}

public boolean isMavenCoordinates() {
return universeSpec != null && universeSpec.getLocation() == null && universeSpec.getFactory().equals(Constants.MAVEN);
return universeSpec != null && universeSpec.getLocation() == null && Constants.MAVEN.equals(universeSpec.getFactory());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ protected ProvisioningConfig provisioningConfig() throws ProvisioningException {
protected FeaturePackUpdatePlan[] expectedUpdatePlans() {
return new FeaturePackUpdatePlan[] {
FeaturePackUpdatePlan.request(prodC101).setNewLocation(prodC102).buildPlan(),
FeaturePackUpdatePlan.request(prodB101, true).setNewLocation(prodB102).buildPlan(),
FeaturePackUpdatePlan.request(prodD100).setNewLocation(prodD102).buildPlan(),
FeaturePackUpdatePlan.request(prodA101, true).setNewLocation(prodA102).buildPlan()
FeaturePackUpdatePlan.request(prodA101, true).setNewLocation(prodA102).buildPlan(),
FeaturePackUpdatePlan.request(prodB101, true).setNewLocation(prodB102).buildPlan()
};
}
}

0 comments on commit 20c892f

Please sign in to comment.