Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes unnecessary check that actually breaks legitimate builds. #73

Merged
merged 4 commits into from
Feb 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -11,4 +11,7 @@ All notable changes to this project will be documented in this file.
## 0.1.1
### Added
- Simple example `helloworld` project under `examples/` ([#62](https://github.com/google/jib/pull/62))

### Fixed
- Infers common credential helper names (for GCR and ECR) ([#64](https://github.com/google/jib/pull/64))
- Building applications with no resources ([#73](https://github.com/google/jib/pull/73))
Original file line number Diff line number Diff line change
@@ -43,10 +43,6 @@ static LayerMetadata from(List<Path> sourceFiles, FileTime lastModifiedTime) {
private final FileTime lastModifiedTime;

LayerMetadata(List<String> sourceFiles, FileTime lastModifiedTime) {
if (sourceFiles.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would allow possibly invalid apps through? All resources, no source? I mean I guess we don't need to care if the user is being insane.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would allow that, though I think our guarantee could be that the application runs in the container like it would locally.

throw new IllegalArgumentException("Source files for application layer cannot be empty");
}

this.sourceFiles = sourceFiles;
this.lastModifiedTime = lastModifiedTime;
}
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
import com.google.cloud.tools.jib.image.LayerPropertyNotFoundException;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -98,7 +97,7 @@ public void testFilter_bySourceFiles()
throws LayerPropertyNotFoundException, DuplicateLayerException,
CacheMetadataCorruptedException {
List<CachedLayer> mockLayers =
Stream.generate(CacheMetadataTest::mockCachedLayer).limit(5).collect(Collectors.toList());
Stream.generate(CacheMetadataTest::mockCachedLayer).limit(6).collect(Collectors.toList());

LayerMetadata fakeExpectedSourceFilesClassesLayerMetadata =
new LayerMetadata(
@@ -109,6 +108,8 @@ public void testFilter_bySourceFiles()
LayerMetadata fakeOtherSourceFilesLayerMetadata =
new LayerMetadata(
Collections.singletonList("not/the/same/source/file"), FileTime.fromMillis(0));
LayerMetadata fakeEmptySourceFilesLayerMetadata =
new LayerMetadata(Collections.emptyList(), FileTime.fromMillis(0));

List<CachedLayerWithMetadata> cachedLayers =
Arrays.asList(
@@ -121,11 +122,13 @@ public void testFilter_bySourceFiles()
new CachedLayerWithMetadata(
mockLayers.get(2), CachedLayerType.CLASSES, fakeOtherSourceFilesLayerMetadata),
new CachedLayerWithMetadata(
mockLayers.get(3),
mockLayers.get(3), CachedLayerType.DEPENDENCIES, fakeEmptySourceFilesLayerMetadata),
new CachedLayerWithMetadata(
mockLayers.get(4),
CachedLayerType.CLASSES,
fakeExpectedSourceFilesClassesLayerMetadata),
new CachedLayerWithMetadata(
mockLayers.get(4),
mockLayers.get(5),
CachedLayerType.RESOURCES,
fakeExpectedSourceFilesResourcesLayerMetadata));

@@ -138,10 +141,8 @@ public void testFilter_bySourceFiles()
cacheMetadata
.filterLayers()
.bySourceFiles(
new ArrayList<>(
Arrays.asList(
Paths.get("some", "source", "file"),
Paths.get("some", "source", "directory"))))
Arrays.asList(
Paths.get("some", "source", "file"), Paths.get("some", "source", "directory")))
.filter();

Assert.assertEquals(3, filteredLayers.size());
@@ -152,4 +153,36 @@ public void testFilter_bySourceFiles()
Assert.assertEquals(
fakeExpectedSourceFilesResourcesLayerMetadata, filteredLayers.get(2).getMetadata());
}

@Test
public void testFilter_byEmptySourceFiles()
throws LayerPropertyNotFoundException, DuplicateLayerException,
CacheMetadataCorruptedException {
List<CachedLayer> mockLayers =
Stream.generate(CacheMetadataTest::mockCachedLayer).limit(2).collect(Collectors.toList());

LayerMetadata fakeSourceFilesLayerMetadata =
new LayerMetadata(
Arrays.asList("some/source/file", "some/source/directory"), FileTime.fromMillis(0));
LayerMetadata fakeEmptySourceFilesLayerMetadata =
new LayerMetadata(Collections.emptyList(), FileTime.fromMillis(0));

List<CachedLayerWithMetadata> cachedLayers =
Arrays.asList(
new CachedLayerWithMetadata(
mockLayers.get(0), CachedLayerType.CLASSES, fakeSourceFilesLayerMetadata),
new CachedLayerWithMetadata(
mockLayers.get(1), CachedLayerType.CLASSES, fakeEmptySourceFilesLayerMetadata));

CacheMetadata cacheMetadata = new CacheMetadata();
for (CachedLayerWithMetadata cachedLayer : cachedLayers) {
cacheMetadata.addLayer(cachedLayer);
}

ImageLayers<CachedLayerWithMetadata> filteredLayers =
cacheMetadata.filterLayers().bySourceFiles(Collections.emptyList()).filter();

Assert.assertEquals(1, filteredLayers.size());
Assert.assertEquals(fakeEmptySourceFilesLayerMetadata, filteredLayers.get(0).getMetadata());
}
}