Polish
This commit is contained in:
@@ -45,7 +45,7 @@ public abstract class AbstractBuildLog implements BuildLog {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pulledBulder(BuildRequest request, Image image) {
|
||||
public void pulledBuilder(BuildRequest request, Image image) {
|
||||
log(" > Pulled builder image '" + getDigest(image) + "'");
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public interface BuildLog {
|
||||
* @param request the build request
|
||||
* @param image the builder image that was pulled
|
||||
*/
|
||||
void pulledBulder(BuildRequest request, Image image);
|
||||
void pulledBuilder(BuildRequest request, Image image);
|
||||
|
||||
/**
|
||||
* Log that a run image is being pulled.
|
||||
@@ -73,7 +73,7 @@ public interface BuildLog {
|
||||
/**
|
||||
* Log that the lifecycle is executing.
|
||||
* @param request the build request
|
||||
* @param version the lifecyle version
|
||||
* @param version the lifecycle version
|
||||
* @param buildCacheVolume the name of the build cache volume in use
|
||||
*/
|
||||
void executingLifecycle(BuildRequest request, LifecycleVersion version, VolumeName buildCacheVolume);
|
||||
|
||||
@@ -47,7 +47,7 @@ public class BuildRequest {
|
||||
|
||||
private final boolean cleanCache;
|
||||
|
||||
private final boolean versboseLogging;
|
||||
private final boolean verboseLogging;
|
||||
|
||||
BuildRequest(ImageReference name, Function<Owner, TarArchive> applicationContent) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
@@ -57,17 +57,17 @@ public class BuildRequest {
|
||||
this.builder = DEFAULT_BUILDER;
|
||||
this.env = Collections.emptyMap();
|
||||
this.cleanCache = false;
|
||||
this.versboseLogging = false;
|
||||
this.verboseLogging = false;
|
||||
}
|
||||
|
||||
BuildRequest(ImageReference name, Function<Owner, TarArchive> applicationContent, ImageReference builder,
|
||||
Map<String, String> env, boolean cleanCache, boolean versboseLogging) {
|
||||
Map<String, String> env, boolean cleanCache, boolean verboseLogging) {
|
||||
this.name = name;
|
||||
this.applicationContent = applicationContent;
|
||||
this.builder = builder;
|
||||
this.env = env;
|
||||
this.cleanCache = cleanCache;
|
||||
this.versboseLogging = versboseLogging;
|
||||
this.verboseLogging = verboseLogging;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +78,7 @@ public class BuildRequest {
|
||||
public BuildRequest withBuilder(ImageReference builder) {
|
||||
Assert.notNull(builder, "Builder must not be null");
|
||||
return new BuildRequest(this.name, this.applicationContent, builder.inTaggedForm(), this.env, this.cleanCache,
|
||||
this.versboseLogging);
|
||||
this.verboseLogging);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,10 +90,10 @@ public class BuildRequest {
|
||||
public BuildRequest withEnv(String name, String value) {
|
||||
Assert.hasText(name, "Name must not be empty");
|
||||
Assert.hasText(value, "Value must not be empty");
|
||||
Map<String, String> env = new LinkedHashMap<String, String>(this.env);
|
||||
Map<String, String> env = new LinkedHashMap<>(this.env);
|
||||
env.put(name, value);
|
||||
return new BuildRequest(this.name, this.applicationContent, this.builder, Collections.unmodifiableMap(env),
|
||||
this.cleanCache, this.versboseLogging);
|
||||
this.cleanCache, this.verboseLogging);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,10 +103,10 @@ public class BuildRequest {
|
||||
*/
|
||||
public BuildRequest withEnv(Map<String, String> env) {
|
||||
Assert.notNull(env, "Env must not be null");
|
||||
Map<String, String> updatedEnv = new LinkedHashMap<String, String>(this.env);
|
||||
Map<String, String> updatedEnv = new LinkedHashMap<>(this.env);
|
||||
updatedEnv.putAll(env);
|
||||
return new BuildRequest(this.name, this.applicationContent, this.builder,
|
||||
Collections.unmodifiableMap(updatedEnv), this.cleanCache, this.versboseLogging);
|
||||
Collections.unmodifiableMap(updatedEnv), this.cleanCache, this.verboseLogging);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +116,7 @@ public class BuildRequest {
|
||||
*/
|
||||
public BuildRequest withCleanCache(boolean cleanCache) {
|
||||
return new BuildRequest(this.name, this.applicationContent, this.builder, this.env, cleanCache,
|
||||
this.versboseLogging);
|
||||
this.verboseLogging);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,7 +177,7 @@ public class BuildRequest {
|
||||
* @return if verbose logging should be used
|
||||
*/
|
||||
public boolean isVerboseLogging() {
|
||||
return this.versboseLogging;
|
||||
return this.verboseLogging;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -81,7 +81,7 @@ public class Builder {
|
||||
Consumer<TotalProgressEvent> progressConsumer = this.log.pullingBuilder(request, builderImageReference);
|
||||
TotalProgressPullListener listener = new TotalProgressPullListener(progressConsumer);
|
||||
Image builderImage = this.docker.image().pull(builderImageReference, listener);
|
||||
this.log.pulledBulder(request, builderImage);
|
||||
this.log.pulledBuilder(request, builderImage);
|
||||
return builderImage;
|
||||
}
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ class BuilderMetadata extends MappedObject {
|
||||
*/
|
||||
static final class Update {
|
||||
|
||||
private ObjectNode copy;
|
||||
private final ObjectNode copy;
|
||||
|
||||
private Update(BuilderMetadata source) {
|
||||
this.copy = source.getNode().deepCopy();
|
||||
|
||||
@@ -70,16 +70,16 @@ class Lifecycle implements Closeable {
|
||||
* @param log build output log
|
||||
* @param docker the Docker API
|
||||
* @param request the request to process
|
||||
* @param runImageReferece a reference to run image that should be used
|
||||
* @param runImageReference a reference to run image that should be used
|
||||
* @param builder the ephemeral builder used to run the phases
|
||||
*/
|
||||
Lifecycle(BuildLog log, DockerApi docker, BuildRequest request, ImageReference runImageReferece,
|
||||
Lifecycle(BuildLog log, DockerApi docker, BuildRequest request, ImageReference runImageReference,
|
||||
EphemeralBuilder builder) {
|
||||
checkPlatformVersion(builder);
|
||||
this.log = log;
|
||||
this.docker = docker;
|
||||
this.request = request;
|
||||
this.runImageReference = runImageReferece;
|
||||
this.runImageReference = runImageReference;
|
||||
this.builder = builder;
|
||||
this.version = LifecycleVersion.parse(builder.getBuilderMetadata().getLifecycle().getVersion());
|
||||
this.layersVolume = createRandomVolumeName("pack-layers-");
|
||||
@@ -258,7 +258,7 @@ class Lifecycle implements Closeable {
|
||||
* convention of using {@code '/workspace'}.
|
||||
* <p>
|
||||
* Note that application content is uploaded to the container with the first phase
|
||||
* that runs and saved in a volume that is passed to supsequent phases. The folder
|
||||
* that runs and saved in a volume that is passed to subsequent phases. The folder
|
||||
* is mutable and buildpacks may modify the content.
|
||||
*/
|
||||
static final String APPLICATION = "/workspace";
|
||||
|
||||
@@ -114,7 +114,7 @@ class Phase {
|
||||
}
|
||||
update.withCommand("/lifecycle/" + this.name, StringUtils.toStringArray(this.args));
|
||||
update.withLabel("author", "spring-boot");
|
||||
this.binds.forEach((source, dest) -> update.withBind(source, dest));
|
||||
this.binds.forEach(update::withBind);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -227,9 +227,8 @@ public class DockerApi {
|
||||
private ContainerReference createContainer(ContainerConfig config) throws IOException {
|
||||
URI createUri = buildUrl("/containers/create");
|
||||
try (Response response = http().post(createUri, "application/json", config::writeTo)) {
|
||||
ContainerReference containerReference = ContainerReference
|
||||
return ContainerReference
|
||||
.of(SharedObjectMapper.get().readTree(response.getContent()).at("/Id").asText());
|
||||
return containerReference;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.apache.http.util.Args;
|
||||
*/
|
||||
class DockerSchemePortResolver implements SchemePortResolver {
|
||||
|
||||
private static int DEFAULT_DOCKER_PORT = 2376;
|
||||
private static final int DEFAULT_DOCKER_PORT = 2376;
|
||||
|
||||
@Override
|
||||
public int resolve(HttpHost host) throws UnsupportedSchemeException {
|
||||
|
||||
@@ -82,7 +82,7 @@ interface Http {
|
||||
|
||||
/**
|
||||
* Return the content of the response.
|
||||
* @return the reseponse content
|
||||
* @return the response content
|
||||
* @throws IOException on IO error
|
||||
*/
|
||||
InputStream getContent() throws IOException;
|
||||
|
||||
@@ -156,7 +156,7 @@ class HttpClientHttp implements Http {
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
private class WritableHttpEntity extends AbstractHttpEntity {
|
||||
private static class WritableHttpEntity extends AbstractHttpEntity {
|
||||
|
||||
private final IOConsumer<OutputStream> writer;
|
||||
|
||||
|
||||
@@ -93,10 +93,7 @@ public class TotalProgressPullListener implements UpdateListener<PullImageUpdate
|
||||
if (value < 0) {
|
||||
return 0;
|
||||
}
|
||||
if (value > 100) {
|
||||
return 100;
|
||||
}
|
||||
return value;
|
||||
return Math.min(value, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +122,7 @@ public class TotalProgressPullListener implements UpdateListener<PullImageUpdate
|
||||
|
||||
private int updateProgress(int current, ProgressDetail detail) {
|
||||
int result = withinPercentageBounds((int) ((100.0 / detail.getTotal()) * detail.getCurrent()));
|
||||
return (result > current) ? result : current;
|
||||
return Math.max(result, current);
|
||||
}
|
||||
|
||||
void finish() {
|
||||
|
||||
@@ -103,11 +103,11 @@ public class ContainerConfig {
|
||||
|
||||
private String command;
|
||||
|
||||
private List<String> args = new ArrayList<>();
|
||||
private final List<String> args = new ArrayList<>();
|
||||
|
||||
private Map<String, String> labels = new LinkedHashMap<>();
|
||||
private final Map<String, String> labels = new LinkedHashMap<>();
|
||||
|
||||
private Map<String, String> binds = new LinkedHashMap<>();
|
||||
private final Map<String, String> binds = new LinkedHashMap<>();
|
||||
|
||||
Update(ImageReference image) {
|
||||
this.image = image;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Image extends MappedObject {
|
||||
|
||||
private final ImageConfig config;
|
||||
|
||||
private List<LayerId> layers;
|
||||
private final List<LayerId> layers;
|
||||
|
||||
private final String os;
|
||||
|
||||
@@ -104,7 +104,7 @@ public class Image extends MappedObject {
|
||||
/**
|
||||
* Create a new {@link Image} instance from the specified JSON content.
|
||||
* @param content the JSON content
|
||||
* @return a new {@link Image} instace
|
||||
* @return a new {@link Image} instance
|
||||
* @throws IOException on IO error
|
||||
*/
|
||||
public static Image of(InputStream content) throws IOException {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ImageArchive implements TarArchive {
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ISO_ZONED_DATE_TIME
|
||||
.withZone(ZoneOffset.UTC);
|
||||
|
||||
private static final IOConsumer<Update> NO_UPDDATES = (update) -> {
|
||||
private static final IOConsumer<Update> NO_UPDATES = (update) -> {
|
||||
};
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
@@ -189,14 +189,14 @@ public class ImageArchive implements TarArchive {
|
||||
ArrayNode manifest = this.objectMapper.createArrayNode();
|
||||
ObjectNode entry = manifest.addObject();
|
||||
entry.set("Config", entry.textNode(config));
|
||||
entry.set("Layers", getManfiestLayers(writtenLayers));
|
||||
entry.set("Layers", getManifestLayers(writtenLayers));
|
||||
if (this.tag != null) {
|
||||
entry.set("RepoTags", entry.arrayNode().add(this.tag.toString()));
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
private ArrayNode getManfiestLayers(List<LayerId> writtenLayers) {
|
||||
private ArrayNode getManifestLayers(List<LayerId> writtenLayers) {
|
||||
ArrayNode layers = this.objectMapper.createArrayNode();
|
||||
for (int i = 0; i < this.existingLayers.size(); i++) {
|
||||
layers.add("");
|
||||
@@ -212,7 +212,7 @@ public class ImageArchive implements TarArchive {
|
||||
* @throws IOException on IO error
|
||||
*/
|
||||
public static ImageArchive from(Image image) throws IOException {
|
||||
return from(image, NO_UPDDATES);
|
||||
return from(image, NO_UPDATES);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.boot.buildpack.platform.json.MappedObject;
|
||||
*/
|
||||
public class ImageConfig extends MappedObject {
|
||||
|
||||
private Map<String, String> labels;
|
||||
private final Map<String, String> labels;
|
||||
|
||||
private final Map<String, String> configEnv;
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ImageConfig extends MappedObject {
|
||||
*/
|
||||
public static final class Update {
|
||||
|
||||
private ObjectNode copy;
|
||||
private final ObjectNode copy;
|
||||
|
||||
private Update(ImageConfig source) {
|
||||
this.copy = source.getNode().deepCopy();
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ImageName {
|
||||
|
||||
private static final String DEFAULT_DOMAIN = "docker.io";
|
||||
|
||||
private static final String OFFICAL_REPOSITORY_NAME = "library";
|
||||
private static final String OFFICIAL_REPOSITORY_NAME = "library";
|
||||
|
||||
private static final String LEGACY_DOMAIN = "index.docker.io";
|
||||
|
||||
@@ -128,7 +128,7 @@ public class ImageName {
|
||||
}
|
||||
}
|
||||
if (DEFAULT_DOMAIN.equals(domain) && !value.contains("/")) {
|
||||
value = OFFICAL_REPOSITORY_NAME + "/" + value;
|
||||
value = OFFICIAL_REPOSITORY_NAME + "/" + value;
|
||||
}
|
||||
return new String[] { domain, value };
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ public final class VolumeName {
|
||||
|
||||
/**
|
||||
* Factory method to create a {@link VolumeName} with a specific value.
|
||||
* @param value the volme reference value
|
||||
* @param value the volume reference value
|
||||
* @return a new {@link VolumeName} instance
|
||||
*/
|
||||
public static VolumeName of(String value) {
|
||||
|
||||
@@ -141,7 +141,7 @@ public class InspectedContent implements Content {
|
||||
|
||||
private File tempFile;
|
||||
|
||||
private byte[] singleByteBuffer = new byte[0];
|
||||
private final byte[] singleByteBuffer = new byte[0];
|
||||
|
||||
private InspectingOutputStream(Inspector[] inspectors) {
|
||||
this.inspectors = inspectors;
|
||||
|
||||
@@ -35,7 +35,7 @@ class TarLayoutWriter implements Layout, Closeable {
|
||||
|
||||
static final long NORMALIZED_MOD_TIME = TarArchive.NORMALIZED_TIME.toEpochMilli();
|
||||
|
||||
private TarArchiveOutputStream outputStream;
|
||||
private final TarArchiveOutputStream outputStream;
|
||||
|
||||
TarLayoutWriter(OutputStream outputStream) {
|
||||
this.outputStream = new TarArchiveOutputStream(outputStream);
|
||||
|
||||
@@ -88,7 +88,7 @@ class FileDescriptor {
|
||||
*/
|
||||
private enum Status {
|
||||
|
||||
OPEN, CLOSE_PENDING, CLOSED;
|
||||
OPEN, CLOSE_PENDING, CLOSED
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ public class NamedPipeSocket extends Socket {
|
||||
/**
|
||||
* Waits for the name pipe file using a simple sleep.
|
||||
*/
|
||||
private class SleepAwaiter implements Consumer<String> {
|
||||
private static class SleepAwaiter implements Consumer<String> {
|
||||
|
||||
@Override
|
||||
public void accept(String path) {
|
||||
@@ -150,7 +150,7 @@ public class NamedPipeSocket extends Socket {
|
||||
/**
|
||||
* Waits for the name pipe file using Windows specific logic.
|
||||
*/
|
||||
private class WindowsAwaiter implements Consumer<String> {
|
||||
private static class WindowsAwaiter implements Consumer<String> {
|
||||
|
||||
@Override
|
||||
public void accept(String path) {
|
||||
|
||||
@@ -59,7 +59,7 @@ class PrintStreamBuildLogTests {
|
||||
log.start(request);
|
||||
Consumer<TotalProgressEvent> pullBuildImageConsumer = log.pullingBuilder(request, builderImageReference);
|
||||
pullBuildImageConsumer.accept(new TotalProgressEvent(100));
|
||||
log.pulledBulder(request, builderImage);
|
||||
log.pulledBuilder(request, builderImage);
|
||||
Consumer<TotalProgressEvent> pullRunImageConsumer = log.pullingRunImage(request, runImageReference);
|
||||
pullRunImageConsumer.accept(new TotalProgressEvent(100));
|
||||
log.pulledRunImage(request, runImage);
|
||||
|
||||
@@ -130,8 +130,7 @@ public abstract class AbstractPackagerMojo extends AbstractDependencyFilterMojo
|
||||
*/
|
||||
protected final Libraries getLibraries(Collection<Dependency> unpacks) throws MojoExecutionException {
|
||||
Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(), getFilters(getAdditionalFilters()));
|
||||
Libraries libraries = new ArtifactsLibraries(artifacts, unpacks, getLog());
|
||||
return libraries;
|
||||
return new ArtifactsLibraries(artifacts, unpacks, getLog());
|
||||
}
|
||||
|
||||
private ArtifactsFilter[] getAdditionalFilters() {
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
||||
import org.apache.commons.compress.archivers.tar.TarConstants;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugin.logging.Log;
|
||||
import org.apache.maven.plugins.annotations.Execute;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
@@ -65,41 +64,36 @@ public class BuildImageMojo extends AbstractPackagerMojo {
|
||||
|
||||
/**
|
||||
* Directory containing the JAR.
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Parameter(defaultValue = "${project.build.directory}", required = true)
|
||||
private File sourceDirectory;
|
||||
|
||||
/**
|
||||
* Name of the JAR.
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Parameter(defaultValue = "${project.build.finalName}", readonly = true)
|
||||
private String finalName;
|
||||
|
||||
/**
|
||||
* Skip the execution.
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Parameter(property = "spring-boot.build-image.skip", defaultValue = "false")
|
||||
private boolean skip;
|
||||
|
||||
/**
|
||||
* Classifier used when finding the source jar.
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Parameter
|
||||
private String classifier;
|
||||
|
||||
/**
|
||||
* Image configuration operations.
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@Parameter
|
||||
private Image image;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
public void execute() throws MojoExecutionException {
|
||||
if (this.project.getPackaging().equals("pom")) {
|
||||
getLog().debug("build-image goal could not be applied to pom project.");
|
||||
return;
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.maven;
|
||||
|
||||
import org.springframework.boot.loader.tools.Layout;
|
||||
import org.springframework.boot.loader.tools.Layouts.Expanded;
|
||||
import org.springframework.boot.loader.tools.Layouts.Jar;
|
||||
import org.springframework.boot.loader.tools.Layouts.None;
|
||||
import org.springframework.boot.loader.tools.Layouts.War;
|
||||
|
||||
/**
|
||||
* Archive layout types.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public enum LayoutType {
|
||||
|
||||
/**
|
||||
* Jar Layout.
|
||||
*/
|
||||
JAR(new Jar()),
|
||||
|
||||
/**
|
||||
* War Layout.
|
||||
*/
|
||||
WAR(new War()),
|
||||
|
||||
/**
|
||||
* Zip Layout.
|
||||
*/
|
||||
ZIP(new Expanded()),
|
||||
|
||||
/**
|
||||
* Dir Layout.
|
||||
*/
|
||||
DIR(new Expanded()),
|
||||
|
||||
/**
|
||||
* No Layout.
|
||||
*/
|
||||
NONE(new None());
|
||||
|
||||
private final Layout layout;
|
||||
|
||||
LayoutType(Layout layout) {
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
public Layout layout() {
|
||||
return this.layout;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user