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

Use JavaContainerBuilder in plugins #1572

Merged
merged 22 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from 19 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.cloud.tools.jib.ProjectInfo;
import com.google.cloud.tools.jib.filesystem.AbsoluteUnixPath;
import com.google.cloud.tools.jib.filesystem.DirectoryWalker;
import com.google.cloud.tools.jib.filesystem.RelativeUnixPath;
import com.google.cloud.tools.jib.frontend.JavaEntrypointConstructor;
import com.google.cloud.tools.jib.frontend.JavaLayerConfigurations;
Expand All @@ -32,6 +33,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map.Entry;
Expand Down Expand Up @@ -227,8 +229,8 @@ public JavaContainerBuilder addDependencies(List<Path> dependencyFiles) throws I
if (!Files.exists(file)) {
throw new NoSuchFileException(file.toString());
}
addedDependencies.add(file);
TadCordle marked this conversation as resolved.
Show resolved Hide resolved
}
addedDependencies.addAll(dependencyFiles);
classpathOrder.add(LayerType.DEPENDENCIES);
return this;
}
Expand All @@ -245,6 +247,40 @@ public JavaContainerBuilder addDependencies(Path... dependencyFiles) throws IOEx
return addDependencies(Arrays.asList(dependencyFiles));
}

/**
* Adds the contents of a dependency JAR directory to the image. Duplicate JAR filenames are
TadCordle marked this conversation as resolved.
Show resolved Hide resolved
* renamed with the filesize in order to avoid collisions.
*
* @param dependenciesDirectory the directory containing dependency JARs to add to the image
* @return this
* @throws IOException if adding the layer fails
*/
public JavaContainerBuilder addDependencies(Path dependenciesDirectory) throws IOException {
if (!Files.isDirectory(dependenciesDirectory)) {
return addDependencies(Collections.singletonList(dependenciesDirectory));
}
return addDependencies(dependenciesDirectory, path -> true);
}

/**
* Adds the contents of a dependency JAR directory to the image. Duplicate JAR filenames are
* renamed with the filesize in order to avoid collisions.
*
* @param dependenciesDirectory the directory containing dependency JARs to add to the image
* @param pathFilter filter that determines which files (not directories) should be added
* @return this
* @throws IOException if adding the layer fails
*/
public JavaContainerBuilder addDependencies(
TadCordle marked this conversation as resolved.
Show resolved Hide resolved
Path dependenciesDirectory, Predicate<Path> pathFilter) throws IOException {
return addDependencies(
new DirectoryWalker(dependenciesDirectory)
.filterRoot()
.filter(pathFilter)
.filter(path -> !Files.isDirectory(path))
.walk()
.asList());
}
/**
* Adds the contents of a resources directory to the image.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ JibContainer containerize(
* @throws IOException if an I/O exception occurs
*/
@VisibleForTesting
TadCordle marked this conversation as resolved.
Show resolved Hide resolved
BuildConfiguration toBuildConfiguration(
public BuildConfiguration toBuildConfiguration(
Containerizer containerizer, ExecutorService executorService)
throws CacheDirectoryCreationException, IOException {
buildConfigurationBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public enum LayerType {
}

@VisibleForTesting
TadCordle marked this conversation as resolved.
Show resolved Hide resolved
String getName() {
public String getName() {
return name;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public MethodVisitor visitMethod(
* @param files the files to check
* @param eventDispatcher used for dispatching log events.
*/
public MainClassFinder(ImmutableList<Path> files, EventDispatcher eventDispatcher) {
this.files = files;
public MainClassFinder(List<Path> files, EventDispatcher eventDispatcher) {
this.files = ImmutableList.copyOf(files);
this.eventDispatcher = eventDispatcher;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ public void buildDocker()
PluginConfigurationProcessor.getAppRootChecked(
gradleRawConfiguration, TaskCommon.isWarProject(getProject()));
GradleProjectProperties projectProperties =
GradleProjectProperties.getForProject(
getProject(),
getLogger(),
jibExtension.getExtraDirectory().getPath(),
jibExtension.getExtraDirectory().getPermissions(),
appRoot);
GradleProjectProperties.getForProject(getProject(), getLogger(), appRoot);

GradleHelpfulSuggestionsBuilder gradleHelpfulSuggestionsBuilder =
new GradleHelpfulSuggestionsBuilder(HELPFUL_SUGGESTIONS_PREFIX, jibExtension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,7 @@ public void buildImage()
PluginConfigurationProcessor.getAppRootChecked(
gradleRawConfiguration, TaskCommon.isWarProject(getProject()));
GradleProjectProperties projectProperties =
GradleProjectProperties.getForProject(
getProject(),
getLogger(),
jibExtension.getExtraDirectory().getPath(),
jibExtension.getExtraDirectory().getPermissions(),
appRoot);
GradleProjectProperties.getForProject(getProject(), getLogger(), appRoot);

if (Strings.isNullOrEmpty(jibExtension.getTo().getImage())) {
throw new GradleException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,7 @@ public void buildTar()
PluginConfigurationProcessor.getAppRootChecked(
gradleRawConfiguration, TaskCommon.isWarProject(getProject()));
GradleProjectProperties projectProperties =
GradleProjectProperties.getForProject(
getProject(),
getLogger(),
jibExtension.getExtraDirectory().getPath(),
jibExtension.getExtraDirectory().getPermissions(),
appRoot);

GradleProjectProperties.getForProject(getProject(), getLogger(), appRoot);
GradleHelpfulSuggestionsBuilder gradleHelpfulSuggestionsBuilder =
new GradleHelpfulSuggestionsBuilder(HELPFUL_SUGGESTIONS_PREFIX, jibExtension);

Expand Down

This file was deleted.

Loading