diff --git a/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java b/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java index 3d3af1d6c..bec36ffa8 100644 --- a/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java +++ b/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java @@ -2,15 +2,11 @@ import java.io.File; import java.io.IOException; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Properties; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; -import com.google.common.collect.ImmutableList; import io.fabric8.maven.docker.access.DockerAccess; import io.fabric8.maven.docker.access.DockerAccessException; import io.fabric8.maven.docker.access.ExecException; @@ -501,8 +497,9 @@ protected LogDispatcher getLogDispatcher(ServiceHub hub) { return dispatcher; } - private ImmutableList getAllImages() { - ImmutableList.Builder allImages = ImmutableList.builder(); + private List getAllImages() { + List allImages = new ArrayList<>(); + if (images != null) { allImages.addAll(images); } @@ -514,7 +511,7 @@ private ImmutableList getAllImages() { allImages.add(config); }); } - return allImages.build(); + return Collections.unmodifiableList(allImages); } public ImagePullManager getImagePullManager(String imagePullPolicy, String autoPull) { diff --git a/src/main/java/io/fabric8/maven/docker/util/ContainerNamingUtil.java b/src/main/java/io/fabric8/maven/docker/util/ContainerNamingUtil.java index 44285a45c..40686b3f9 100644 --- a/src/main/java/io/fabric8/maven/docker/util/ContainerNamingUtil.java +++ b/src/main/java/io/fabric8/maven/docker/util/ContainerNamingUtil.java @@ -1,15 +1,9 @@ package io.fabric8.maven.docker.util; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; -import com.google.common.collect.ImmutableSet; import io.fabric8.maven.docker.config.ImageConfiguration; import io.fabric8.maven.docker.config.RunImageConfiguration; import io.fabric8.maven.docker.model.Container; @@ -164,11 +158,12 @@ private static Collection keepOnlyLastIndexedContainer(Collection extractContainerNames(final Collection existingContainers) { - final ImmutableSet.Builder containerNamesBuilder = ImmutableSet.builder(); + final Set containerNamesBuilder = new HashSet<>(); for (final Container container : existingContainers) { containerNamesBuilder.add(container.getName()); } - return containerNamesBuilder.build(); + + return Collections.unmodifiableSet(containerNamesBuilder); } private static String extractContainerNamePattern(ImageConfiguration image, String defaultContainerNamePattern) { diff --git a/src/main/java/io/fabric8/maven/docker/util/CredentialHelperClient.java b/src/main/java/io/fabric8/maven/docker/util/CredentialHelperClient.java index ba6046587..a9975fc1e 100644 --- a/src/main/java/io/fabric8/maven/docker/util/CredentialHelperClient.java +++ b/src/main/java/io/fabric8/maven/docker/util/CredentialHelperClient.java @@ -1,12 +1,11 @@ package io.fabric8.maven.docker.util; -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; import com.google.gson.JsonObject; import org.apache.maven.plugin.MojoExecutionException; import java.io.IOException; +import java.util.LinkedList; import java.util.List; import io.fabric8.maven.docker.access.AuthConfig; @@ -93,7 +92,7 @@ public String getVersion() throws IOException { // echo | docker-credential-XXX get private class GetCommand extends ExternalCommand { - private List reply = Lists.newLinkedList(); + private final List reply = new LinkedList<>(); GetCommand() { super(CredentialHelperClient.this.log); @@ -119,9 +118,10 @@ public JsonObject getCredentialNode(String registryToLookup) throws IOException throw ex; } } - JsonObject credentials = JsonFactory.newJsonObject(Joiner.on('\n').join(reply)); + String joinedReply = String.join("\n", reply); + JsonObject credentials = JsonFactory.newJsonObject(joinedReply); if (!credentials.has(SECRET_KEY) || !credentials.has(USERNAME_KEY)) { - return null; + return null; // If keys are missing, return null } return credentials; } diff --git a/src/main/java/io/fabric8/maven/docker/util/ImageNameFormatter.java b/src/main/java/io/fabric8/maven/docker/util/ImageNameFormatter.java index 20da0d258..c39ec0a6f 100644 --- a/src/main/java/io/fabric8/maven/docker/util/ImageNameFormatter.java +++ b/src/main/java/io/fabric8/maven/docker/util/ImageNameFormatter.java @@ -20,8 +20,8 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Objects; -import com.google.common.base.Strings; import io.fabric8.maven.docker.config.ConfigHelper; import org.apache.maven.project.MavenProject; @@ -178,7 +178,7 @@ public String doTransform(String tag, Date now) { public String transform(MavenProject project, String tag, Date now) { // In case the Maven property is also a placeholder, replace it as well - if (Strings.isNullOrEmpty(tag) || tag.equals("%" + letter)) { + if(isNullorEmpty(tag) || tag.equals("%" + letter)) { tag = project.getVersion(); } return doTransform(tag, now); @@ -248,4 +248,8 @@ private static String sanitizeName(String name) { // All characters must be lowercase return ret.toString().toLowerCase(); } + + private static boolean isNullorEmpty(String s) { + return Objects.isNull(s) || s.isEmpty(); + } } diff --git a/src/main/java/io/fabric8/maven/docker/util/JibServiceUtil.java b/src/main/java/io/fabric8/maven/docker/util/JibServiceUtil.java index 28d8179ff..ffd0d4107 100644 --- a/src/main/java/io/fabric8/maven/docker/util/JibServiceUtil.java +++ b/src/main/java/io/fabric8/maven/docker/util/JibServiceUtil.java @@ -20,7 +20,6 @@ import io.fabric8.maven.docker.config.Arguments; import io.fabric8.maven.docker.config.BuildImageConfiguration; import io.fabric8.maven.docker.config.ImageConfiguration; -import io.fabric8.maven.docker.model.Image; import org.apache.commons.lang3.StringUtils; import java.io.File;