Skip to content

Commit

Permalink
Move to static helper
Browse files Browse the repository at this point in the history
  • Loading branch information
tadgh committed Nov 6, 2023
1 parent 5cc04b1 commit f4a0b94
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
13 changes: 13 additions & 0 deletions src/main/java/io/fabric8/maven/docker/config/ConfigHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ private static void verifyImageNames(List<ImageConfiguration> 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();
}
}


// =========================================================================

Expand Down
15 changes: 2 additions & 13 deletions src/main/java/io/fabric8/maven/docker/service/BuildService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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");
Expand Down
15 changes: 2 additions & 13 deletions src/main/java/io/fabric8/maven/docker/service/BuildXService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -170,7 +171,7 @@ protected void buildX(List<String> buildX, String builderName, BuildDirs buildDi
cmdLine.add(key + '=' + value);
});
}
if (checkForNocache(imageConfig)) {
if (ConfigHelper.isNoCache(imageConfig)) {
cmdLine.add("--no-cache");
}

Expand Down Expand Up @@ -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<String> buildX, ImageConfiguration imageConfig, BuildDirs buildDirs) throws MojoExecutionException {
BuildXConfiguration buildXConfiguration = imageConfig.getBuildConfiguration().getBuildX();
Expand Down

0 comments on commit f4a0b94

Please sign in to comment.