From f4a0b9417be3405aea7619a95d35fff6386c301c Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 6 Nov 2023 08:45:06 -0800 Subject: [PATCH] Move to static helper --- .../fabric8/maven/docker/config/ConfigHelper.java | 13 +++++++++++++ .../maven/docker/service/BuildService.java | 15 ++------------- .../maven/docker/service/BuildXService.java | 15 ++------------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/main/java/io/fabric8/maven/docker/config/ConfigHelper.java b/src/main/java/io/fabric8/maven/docker/config/ConfigHelper.java index c3ab8a715..df30b9c87 100644 --- a/src/main/java/io/fabric8/maven/docker/config/ConfigHelper.java +++ b/src/main/java/io/fabric8/maven/docker/config/ConfigHelper.java @@ -173,6 +173,19 @@ private static void verifyImageNames(List ret) { } } + public static boolean isNoCache(ImageConfiguration imageConfig) { + String noCache = System.getProperty("docker.noCache"); + if (noCache == null) { + noCache = System.getProperty("docker.nocache"); + } + if (noCache != null) { + return noCache.length() == 0 || Boolean.valueOf(noCache); + } else { + BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration(); + return buildConfig.noCache(); + } + } + // ========================================================================= diff --git a/src/main/java/io/fabric8/maven/docker/service/BuildService.java b/src/main/java/io/fabric8/maven/docker/service/BuildService.java index fe550aad9..3958eb5c7 100644 --- a/src/main/java/io/fabric8/maven/docker/service/BuildService.java +++ b/src/main/java/io/fabric8/maven/docker/service/BuildService.java @@ -10,6 +10,7 @@ import io.fabric8.maven.docker.config.AssemblyConfiguration; import io.fabric8.maven.docker.config.BuildImageConfiguration; import io.fabric8.maven.docker.config.CleanupMode; +import io.fabric8.maven.docker.config.ConfigHelper; import io.fabric8.maven.docker.config.ImageConfiguration; import io.fabric8.maven.docker.model.ImageArchiveManifest; import io.fabric8.maven.docker.model.ImageArchiveManifestEntry; @@ -68,7 +69,7 @@ public void buildImage(ImageConfiguration imageConfig, ImagePullManager imagePul autoPullCacheFromImage(imageConfig, imagePullManager, buildContext); } - buildImage(imageConfig, buildContext.getMojoParameters(), checkForNocache(imageConfig), checkForSquash(imageConfig), addBuildArgs(buildContext), buildArchiveFile); + buildImage(imageConfig, buildContext.getMojoParameters(), ConfigHelper.isNoCache(imageConfig), checkForSquash(imageConfig), addBuildArgs(buildContext), buildArchiveFile); } /** @@ -478,18 +479,6 @@ private void removeImage(String oldImageName, String oldImageId, CleanupMode cle } } - private boolean checkForNocache(ImageConfiguration imageConfig) { - String noCache = System.getProperty("docker.noCache"); - if (noCache == null) { - noCache = System.getProperty("docker.nocache"); - } - if (noCache != null) { - return noCache.length() == 0 || Boolean.valueOf(noCache); - } else { - BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration(); - return buildConfig.noCache(); - } - } private boolean checkForSquash(ImageConfiguration imageConfig) { String squash = System.getProperty("docker.squash"); diff --git a/src/main/java/io/fabric8/maven/docker/service/BuildXService.java b/src/main/java/io/fabric8/maven/docker/service/BuildXService.java index 27b81036b..66daa9e70 100644 --- a/src/main/java/io/fabric8/maven/docker/service/BuildXService.java +++ b/src/main/java/io/fabric8/maven/docker/service/BuildXService.java @@ -8,6 +8,7 @@ import io.fabric8.maven.docker.config.AttestationConfiguration; import io.fabric8.maven.docker.config.BuildImageConfiguration; import io.fabric8.maven.docker.config.BuildXConfiguration; +import io.fabric8.maven.docker.config.ConfigHelper; import io.fabric8.maven.docker.config.ImageConfiguration; import io.fabric8.maven.docker.util.EnvUtil; import io.fabric8.maven.docker.util.ImageName; @@ -170,7 +171,7 @@ protected void buildX(List buildX, String builderName, BuildDirs buildDi cmdLine.add(key + '=' + value); }); } - if (checkForNocache(imageConfig)) { + if (ConfigHelper.isNoCache(imageConfig)) { cmdLine.add("--no-cache"); } @@ -246,18 +247,6 @@ protected void createDirectory(Path cachePath) { throw new IllegalArgumentException("Cannot create " + cachePath); } } - private boolean checkForNocache(ImageConfiguration imageConfig) { - String noCache = System.getProperty("docker.noCache"); - if (noCache == null) { - noCache = System.getProperty("docker.nocache"); - } - if (noCache != null) { - return noCache.length() == 0 || Boolean.valueOf(noCache); - } else { - BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration(); - return buildConfig.noCache(); - } - } protected String createBuilder(Path configPath, List buildX, ImageConfiguration imageConfig, BuildDirs buildDirs) throws MojoExecutionException { BuildXConfiguration buildXConfiguration = imageConfig.getBuildConfiguration().getBuildX();