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

issue #1834: Refactor to Replace Guava with JDK Built-In Functionalities #1836

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Properties;
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;
Expand Down Expand Up @@ -501,8 +502,9 @@ protected LogDispatcher getLogDispatcher(ServiceHub hub) {
return dispatcher;
}

private ImmutableList<ImageConfiguration> getAllImages() {
ImmutableList.Builder<ImageConfiguration> allImages = ImmutableList.builder();
private List<ImageConfiguration> getAllImages() {
List<ImageConfiguration> allImages = new ArrayList<>();

if (images != null) {
allImages.addAll(images);
}
Expand All @@ -514,7 +516,7 @@ private ImmutableList<ImageConfiguration> getAllImages() {
allImages.add(config);
});
}
return allImages.build();
return Collections.unmodifiableList(allImages);
}

public ImagePullManager getImagePullManager(String imagePullPolicy, String autoPull) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -164,11 +158,12 @@ private static Collection<Container> keepOnlyLastIndexedContainer(Collection<Con
}

private static Set<String> extractContainerNames(final Collection<Container> existingContainers) {
final ImmutableSet.Builder<String> containerNamesBuilder = ImmutableSet.builder();
final Set<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -93,7 +92,7 @@ public String getVersion() throws IOException {
// echo <registryToLookup> | docker-credential-XXX get
private class GetCommand extends ExternalCommand {

private List<String> reply = Lists.newLinkedList();
private final List<String> reply = new LinkedList<>();

GetCommand() {
super(CredentialHelperClient.this.log);
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading