Permalink
Browse files

SHRINKWRAP-432 Fix shallowCopy() for nested assets.

ArchiveBase.shallowCopy() and ContainerBase.shallowCopy() now copies
over pointers if there is an asset associated with the path. If no asset
is available in the specified path, the path is omitted from the copy.
This assumes the presence of an asset in a nested path.
  • Loading branch information...
1 parent c38369d commit 0198e8cbbe7bcd8e7379c629f640b914c67deb95 @VineetReynolds VineetReynolds committed with ALRubinger Nov 16, 2012
@@ -550,7 +550,10 @@ public T merge(final Archive<?> source, final String path) throws IllegalArgumen
// Now loop through and add all content
for (final ArchivePath path : from.getContent().keySet()) {
- to.add(from.get(path).getAsset(), path);
+ Asset asset = from.get(path).getAsset();
+ if (asset != null) {
+ to.add(asset, path);
+ }
}
// Return
@@ -536,7 +536,10 @@ public String getId() {
final Archive<T> newArchive = factory.create(actualClass, this.getName());
final Map<ArchivePath, Node> contents = underlyingArchive.getContent();
for (final ArchivePath path : contents.keySet()) {
- newArchive.add(contents.get(path).getAsset(), path);
+ Asset asset = contents.get(path).getAsset();
+ if (asset != null) {
+ newArchive.add(asset, path);
+ }
}
return newArchive;
}
@@ -1397,6 +1397,20 @@ public void ensureShallowCopyHasASeparateCollectionOfTheSamePointers() {
Assert.assertTrue(copyArchive.contains("location"));
}
+
+ @Test
+ public void ensureShallowCopyOperatesOnNestedAssets() {
+ Archive<T> archive = getArchive();
+ Asset asset = new ClassLoaderAsset(NAME_TEST_PROPERTIES);
+ archive.add(asset, "location/sublocation");
+
+ Archive<T> copyArchive = archive.shallowCopy();
+
+ Assert.assertTrue(copyArchive.contains("location"));
+ Assert.assertTrue(copyArchive.contains("location/sublocation"));
+ Assert.assertSame(copyArchive.get("location/sublocation").getAsset(), archive.get("location/sublocation")
+ .getAsset());
+ }
@Test
public void testId() {

0 comments on commit 0198e8c

Please sign in to comment.