Skip to content

Commit

Permalink
Fix the feature "Asset Override on child scope"
Browse files Browse the repository at this point in the history
  • Loading branch information
rlespinasse authored and tduchateau committed May 24, 2014
1 parent 4a194b7 commit f3d9c67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -253,8 +253,9 @@ private Map<String, Asset> assetsMapFor(String... scopes) {
scopedAssetsMap.put(key, Asset.class.cast(asset.clone(false)));
}

Map<String, Asset> parentAssets = assetsMapFor(assetScope.parentScope);
mergeAssets(scopedAssetsMap, parentAssets);
if(!MASTER_SCOPE.equalsIgnoreCase(assetScope.parentScope)) {
mergeAssets(scopedAssetsMap, assetsMapFor(assetScope.parentScope));
}
mergeAssets(assetsMap, scopedAssetsMap);
}
}
Expand All @@ -270,13 +271,21 @@ private void mergeAssets(Map<String, Asset> container, Map<String, Asset> others
for (Map.Entry<String, Asset> other : others.entrySet()) {
if (container.containsKey(other.getKey())) {
Asset asset = container.get(other.getKey());
asset.storagePosition = other.getValue().storagePosition;
int smallestValue = asset.storagePosition<other.getValue().storagePosition
?asset.storagePosition:other.getValue().storagePosition;
if (asset.getVersion().equalsIgnoreCase(other.getValue().getVersion())) {
asset.storagePosition = smallestValue;
for (Map.Entry<String, String> location : other.getValue().getLocations().entrySet()) {
if (!asset.getLocations().containsKey(location.getKey())) {
asset.getLocations().put(location.getKey(), location.getValue());
}
}
} else if(smallestValue == asset.storagePosition) {
Asset _asset = other.getValue();
_asset.storagePosition = asset.storagePosition;
container.put(other.getKey(), _asset);
} else if (smallestValue == other.getValue().storagePosition) {
asset.storagePosition = smallestValue;
}
} else {
container.put(other.getKey(), other.getValue());
Expand Down
Expand Up @@ -204,7 +204,8 @@ public void should_manage_conflicts_on_demand() {

@Test
public void should_manage_priorities() {
Asset assetPriority = new Asset("name", "version2", AssetType.js, locations);
Asset assetPriority = asset.clone(false);
assetPriority.setVersion("versionAssetPriority");

assetsStorage.store(asset);
assetsStorage.store(asset4);
Expand Down

0 comments on commit f3d9c67

Please sign in to comment.