Skip to content

Commit

Permalink
Moved Guava classes with JDK inbuilt functionalities
Browse files Browse the repository at this point in the history
Signed-off-by: mdxabu <[email protected]>
  • Loading branch information
mdxabu committed Nov 9, 2024
1 parent 003398e commit d7eee24
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
13 changes: 5 additions & 8 deletions src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -501,8 +497,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 +511,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

0 comments on commit d7eee24

Please sign in to comment.