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

Add JavaContainerBuilder to jib core #1347

Merged
merged 22 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

/** Creates a {@link JibContainerBuilder} for containerizing Java applications. */
Expand Down Expand Up @@ -121,24 +123,37 @@ private JavaContainerBuilder(JibContainerBuilder jibContainerBuilder) {
*
* @param dependencyFiles the list of dependency JARs to add to the image
* @return this
* @throws NoSuchFileException if adding the layer fails
* @throws IOException if adding the layer fails
*/
public JavaContainerBuilder addDependencies(List<Path> dependencyFiles)
throws NoSuchFileException {
public JavaContainerBuilder addDependencies(List<Path> dependencyFiles) throws IOException {
// Make sure all files exist before adding any
for (Path file : dependencyFiles) {
if (!Files.exists(file)) {
TadCordle marked this conversation as resolved.
Show resolved Hide resolved
TadCordle marked this conversation as resolved.
Show resolved Hide resolved
throw new NoSuchFileException(file.toString());
}
}

List<String> duplicates =
TadCordle marked this conversation as resolved.
Show resolved Hide resolved
dependencyFiles
.stream()
.map(Path::getFileName)
.map(Path::toString)
.collect(Collectors.groupingBy(filename -> filename, Collectors.counting()))
.entrySet()
.stream()
.filter(entry -> entry.getValue() > 1)
.map(Entry::getKey)
.collect(Collectors.toList());
for (Path file : dependencyFiles) {
layerConfigurationsBuilder.addFile(
file.getFileName().toString().contains("SNAPSHOT")
? LayerType.SNAPSHOT_DEPENDENCIES
: LayerType.DEPENDENCIES,
file,
DEPENDENCIES_PATH.resolve(file.getFileName()));
DEPENDENCIES_PATH.resolve(
duplicates.contains(file.getFileName().toString())
? file.getFileName().toString().replaceFirst("\\.jar$", "-" + Files.size(file))
+ ".jar"
: file.getFileName().toString()));
}
classpath.add(DEPENDENCIES_CLASSPATH.toString());
return this;
Expand All @@ -149,9 +164,9 @@ public JavaContainerBuilder addDependencies(List<Path> dependencyFiles)
*
* @param dependencyFiles the list of dependency JARs to add to the image
* @return this
* @throws NoSuchFileException if adding the layer fails
* @throws IOException if adding the layer fails
*/
public JavaContainerBuilder addDependencies(Path... dependencyFiles) throws NoSuchFileException {
public JavaContainerBuilder addDependencies(Path... dependencyFiles) throws IOException {
return addDependencies(Arrays.asList(dependencyFiles));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void testToJibContainerBuilder_all()
.addClasses(getResource("application/classes"))
.addDependencies(
getResource("application/dependencies/dependency-1.0.0.jar"),
getResource("application/dependencies/more/dependency-1.0.0.jar"),
getResource("application/dependencies/libraryA.jar"),
getResource("application/dependencies/libraryB.jar"),
getResource("application/snapshot-dependencies/dependency-1.0.0-SNAPSHOT.jar"))
Expand Down Expand Up @@ -97,7 +98,8 @@ public void testToJibContainerBuilder_all()
// Check dependencies
List<AbsoluteUnixPath> expectedDependencies =
ImmutableList.of(
AbsoluteUnixPath.get("/app/libs/dependency-1.0.0.jar"),
AbsoluteUnixPath.get("/app/libs/dependency-1.0.0-770.jar"),
AbsoluteUnixPath.get("/app/libs/dependency-1.0.0-200.jar"),
AbsoluteUnixPath.get("/app/libs/libraryA.jar"),
AbsoluteUnixPath.get("/app/libs/libraryB.jar"));
Assert.assertEquals(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
]e$Ềx���,�
.3��I݅����3�8��V�KA����M��)=5�~�'qю�$[��- :��&�%�� ����E�o����7N���s`�i�Z0MT.����9J[�}?\E ��}U�v���J�d��o(��i��"M��ԛ��_+/�c���I<��Zje��44%���d2?�l>.��-�O�=H�i�