Skip to content

Commit

Permalink
refactor: Remove @deprecated fields from BuildConfiguration
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa authored and rohanKanojia committed Jun 18, 2020
1 parent 107d3bf commit d290c13
Show file tree
Hide file tree
Showing 32 changed files with 740 additions and 523 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Usage:
* Fix #237: Remove deprecated fields and method calls
* Fix #192: Removed `@Deprecated` fields from ClusterAccess
* Fix #190: Removed `@Deprecated` fields from AssemblyConfiguration
* Fix #189: Removed `@Deprecated` fields from BuildConfiguration


### 1.0.0-alpha-4 (2020-06-08)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private AssemblyConfigurationUtils() {}

static AssemblyConfiguration getAssemblyConfigurationOrCreateDefault(BuildConfiguration buildConfiguration) {
final AssemblyConfiguration ac = Optional.ofNullable(buildConfiguration)
.map(BuildConfiguration::getAssemblyConfiguration)
.map(BuildConfiguration::getAssembly)
.orElse(AssemblyConfiguration.builder().user(DEFAULT_USER).build());
final AssemblyConfiguration.AssemblyConfigurationBuilder builder = ac.toBuilder();
final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private void interpolateDockerfile(File dockerFile, BuildDirs params, Properties

// visible for testing
void verifyGivenDockerfile(File dockerFile, BuildConfiguration buildConfig, Properties properties, KitLogger log) throws IOException {
AssemblyConfiguration assemblyConfig = buildConfig.getAssemblyConfiguration();
AssemblyConfiguration assemblyConfig = buildConfig.getAssembly();
if (assemblyConfig == null) {
return;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ public AssemblyFiles getAssemblyFiles(String name, BuildConfiguration buildConfi

BuildDirs buildDirs = createBuildDirs(name, jKubeConfiguration);

AssemblyConfiguration assemblyConfig = buildConfig.getAssemblyConfiguration();
AssemblyConfiguration assemblyConfig = buildConfig.getAssembly();
String assemblyName = assemblyConfig.getName();

AssemblyFiles assemblyFiles = new AssemblyFiles(buildDirs.getOutputDirectory());
Expand Down Expand Up @@ -285,7 +285,7 @@ DockerFileBuilder createDockerFileBuilder(BuildConfiguration buildConfig, Assemb
builder.workdir(buildConfig.getWorkdir());
}
if (assemblyConfig != null) {
builder.add(assemblyConfig.getName(), "")
builder.add(assemblyConfig.getTargetDir(), "")
.basedir(assemblyConfig.getTargetDir())
.assemblyUser(assemblyConfig.getUser())
.exportTargetDir(assemblyConfig.getExportTargetDir());
Expand Down Expand Up @@ -472,13 +472,13 @@ private File processAssemblyConfigToCreateTarball(BuildConfiguration buildConfig
archiveCustomizers.add(archiver -> {
File finalArtifactFile = JKubeProjectUtil.getFinalOutputArtifact(params.getProject());
if (finalArtifactFile != null) {
archiver.includeFile(finalArtifactFile, assemblyConfig.getName() + File.separator + finalArtifactFile.getName());
archiver.includeFile(finalArtifactFile, assemblyConfig.getTargetDir() + File.separator + finalArtifactFile.getName());
}
return archiver;
});
}

List<String> filesToExclude = getJKubeAssemblyFileSetsExcludes(buildConfig.getAssemblyConfiguration());
List<String> filesToExclude = getJKubeAssemblyFileSetsExcludes(buildConfig.getAssembly());
archiveCustomizers.add(archiver -> {
filesToExclude.forEach(archiver::excludeFile);
fileToPermissionsMap.forEach(archiver::setFilePermissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private String extractBaseFromConfiguration(BuildConfiguration buildConfig) {
String fromImage;
fromImage = buildConfig.getFrom();
if (fromImage == null) {
AssemblyConfiguration assemblyConfig = buildConfig.getAssemblyConfiguration();
AssemblyConfiguration assemblyConfig = buildConfig.getAssembly();
if (assemblyConfig == null) {
fromImage = DockerAssemblyManager.DEFAULT_DATA_BASE_IMAGE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.jkube.kit.build.service.docker.config.RunVolumeConfiguration;
import org.eclipse.jkube.kit.build.service.docker.config.WatchImageConfiguration;
import org.eclipse.jkube.kit.build.service.docker.helper.StartOrderResolver;
import org.eclipse.jkube.kit.common.KitLogger;
import org.eclipse.jkube.kit.common.util.EnvUtil;
import org.eclipse.jkube.kit.config.image.ImageName;

Expand Down Expand Up @@ -156,11 +155,11 @@ public String getDescription() {
return String.format("[%s] %s", new ImageName(name).getFullName(), (alias != null ? "\"" + alias + "\"" : "")).trim();
}

public String initAndValidate(ConfigHelper.NameFormatter nameFormatter, KitLogger log) {
public String initAndValidate(ConfigHelper.NameFormatter nameFormatter) {
name = nameFormatter.format(name);
String minimalApiVersion = null;
if (build != null) {
minimalApiVersion = build.initAndValidate(log);
minimalApiVersion = build.initAndValidate();
}
if (run != null) {
minimalApiVersion = EnvUtil.extractLargerVersion(minimalApiVersion, run.initAndValidate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public synchronized void watch(WatchContext context, JKubeConfiguration buildCon
ArrayList<String> tasks = new ArrayList<>();

if (imageConfig.getBuildConfiguration() != null &&
imageConfig.getBuildConfiguration().getAssemblyConfiguration() != null) {
imageConfig.getBuildConfiguration().getAssembly() != null) {
if (watcher.isCopy()) {
String containerBaseDir = imageConfig.getBuildConfiguration().getAssemblyConfiguration().getTargetDir();
String containerBaseDir = imageConfig.getBuildConfiguration().getAssembly().getTargetDir();
schedule(executor, createCopyWatchTask(watcher, context.getBuildContext(), containerBaseDir), interval);
tasks.add("copying artifacts");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,12 @@ public static String getExternalConfigActivationProperty(JavaProject project) {
* @param images the images to check
* @param apiVersion the original API version intended to use
* @param nameFormatter formatter for image names
* @param log a logger for printing out diagnostic messages
* @return the minimal API Docker API required to be used for the given configuration.
*/
public static String initAndValidate(List<ImageConfiguration> images, String apiVersion, NameFormatter nameFormatter,
KitLogger log) {
public static String initAndValidate(List<ImageConfiguration> images, String apiVersion, NameFormatter nameFormatter) {
// Init and validate configs. After this step, getResolvedImages() contains the valid configuration.
for (ImageConfiguration imageConfiguration : images) {
apiVersion = EnvUtil.extractLargerVersion(apiVersion, imageConfiguration.initAndValidate(nameFormatter, log));
apiVersion = EnvUtil.extractLargerVersion(apiVersion, imageConfiguration.initAndValidate(nameFormatter));
}
return apiVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public enum ConfigKey {
DNS_SEARCH,
DOCKER_ARCHIVE,
DOCKER_FILE,
DOCKER_FILE_DIR,
ENTRYPOINT,
ENV,
ENV_PROPERTY_FILE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.DNS_SEARCH;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.DOCKER_ARCHIVE;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.DOCKER_FILE;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.DOCKER_FILE_DIR;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.DOMAINNAME;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.ENTRYPOINT;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.ENV;
Expand Down Expand Up @@ -114,7 +113,6 @@
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.PORT_PROPERTY_FILE;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.PRIVILEGED;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.READ_ONLY;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.REGISTRY;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.RESTART_POLICY_NAME;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.RESTART_POLICY_RETRY;
import static org.eclipse.jkube.kit.build.service.docker.config.handler.property.ConfigKey.RUN;
Expand Down Expand Up @@ -195,29 +193,24 @@ private static boolean isStringValueNull(ValueProvider valueProvider, BuildConfi
return valueProvider.getString(key, config == null ? null : supplier.get()) != null;
}

// Enable build config only when a `.from.`, `.dockerFile.`, or `.dockerFileDir.` is configured
// Enable build config only when a `.from.`, or `.dockerFile.` is configured
private boolean buildConfigured(BuildConfiguration config, ValueProvider valueProvider, JavaProject project) {


if (isStringValueNull(valueProvider, config, FROM, config::getFrom)) {
return true;
}

if (valueProvider.getMap(FROM_EXT, config == null ? null : config.getFromExt()) != null) {
return true;
}
if (isStringValueNull(valueProvider, config, DOCKER_FILE, () -> config.getDockerFileRaw() )) {
return true;
}
if (isStringValueNull(valueProvider, config, DOCKER_ARCHIVE, () -> config.getDockerArchiveRaw())) {
if (isStringValueNull(valueProvider, config, DOCKER_FILE, config::getDockerFileRaw)) {
return true;
}

if (isStringValueNull(valueProvider, config, CONTEXT_DIR, () -> config.getContextDirRaw())) {
if (isStringValueNull(valueProvider, config, DOCKER_ARCHIVE, config::getDockerArchiveRaw)) {
return true;
}

if (isStringValueNull(valueProvider, config, DOCKER_FILE_DIR, () -> config.getDockerFileDirRaw())) {
if (isStringValueNull(valueProvider, config, CONTEXT_DIR, config::getContextDirRaw)) {
return true;
}

Expand All @@ -237,10 +230,10 @@ private BuildConfiguration extractBuildConfiguration(ImageConfiguration fromConf
return BuildConfiguration.builder()
.cmd(extractArguments(valueProvider, CMD, valueOrNull(config, BuildConfiguration::getCmd)))
.cleanup(valueProvider.getString(CLEANUP, valueOrNull(config, BuildConfiguration::getCleanup)))
.nocache(valueProvider.getBoolean(NOCACHE, valueOrNull(config, BuildConfiguration::getNoCache)))
.nocache(valueProvider.getBoolean(NOCACHE, valueOrNull(config, BuildConfiguration::getNocache)))
.optimise(valueProvider.getBoolean(OPTIMISE, valueOrNull(config, BuildConfiguration::getOptimise)))
.entryPoint(extractArguments(valueProvider, ENTRYPOINT, valueOrNull(config, BuildConfiguration::getEntryPoint)))
.assembly(extractAssembly(valueOrNull(config, BuildConfiguration::getAssemblyConfiguration), valueProvider))
.assembly(extractAssembly(valueOrNull(config, BuildConfiguration::getAssembly), valueProvider))
.env(MapUtil.mergeMaps(
valueProvider.getMap(ENV_BUILD, valueOrNull(config, BuildConfiguration::getEnv)),
valueProvider.getMap(ENV, Collections.emptyMap())
Expand All @@ -252,7 +245,6 @@ private BuildConfiguration extractBuildConfiguration(ImageConfiguration fromConf
.runCmds(valueProvider.getList(RUN, valueOrNull(config, BuildConfiguration::getRunCmds)))
.from(valueProvider.getString(FROM, valueOrNull(config, BuildConfiguration::getFrom)))
.fromExt(valueProvider.getMap(FROM_EXT, valueOrNull(config, BuildConfiguration::getFromExt)))
.registry(valueProvider.getString(REGISTRY, valueOrNull(config, BuildConfiguration::getRegistry)))
.volumes(valueProvider.getList(VOLUMES, valueOrNull(config, BuildConfiguration::getVolumes)))
.tags(valueProvider.getList(TAGS, valueOrNull(config, BuildConfiguration::getTags)))
.maintainer(valueProvider.getString(MAINTAINER, valueOrNull(config, BuildConfiguration::getMaintainer)))
Expand All @@ -262,9 +254,8 @@ private BuildConfiguration extractBuildConfiguration(ImageConfiguration fromConf
.contextDir(valueProvider.getString(CONTEXT_DIR, valueOrNull(config, BuildConfiguration::getContextDirRaw)))
.dockerArchive(valueProvider.getString(DOCKER_ARCHIVE, valueOrNull(config, BuildConfiguration::getDockerArchiveRaw)))
.dockerFile(valueProvider.getString(DOCKER_FILE, valueOrNull(config, BuildConfiguration::getDockerFileRaw)))
.dockerFileDir(valueProvider.getString(DOCKER_FILE_DIR, valueOrNull(config, BuildConfiguration::getDockerFileDirRaw)))
.buildOptions(valueProvider.getMap(BUILD_OPTIONS, valueOrNull(config, BuildConfiguration::getBuildOptions)))
.filter(valueProvider.getString(FILTER, valueOrNull(config, BuildConfiguration::getFilterRaw)))
.filter(valueProvider.getString(FILTER, valueOrNull(config, BuildConfiguration::getFilter)))
.user(valueProvider.getString(USER, valueOrNull(config, BuildConfiguration::getUser)))
.healthCheck(extractHealthCheck(valueOrNull(config, BuildConfiguration::getHealthCheck), valueProvider))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void getAssemblyConfigurationOrCreateDefaultNoConfigurationShouldReturnDe

// Given
new Expectations() {{
buildConfiguration.getAssemblyConfiguration();
buildConfiguration.getAssembly();
result = null;
}};
// When
Expand All @@ -63,7 +63,7 @@ public void getAssemblyConfigurationOrCreateDefaultWithConfigurationShouldReturn
// Given
final AssemblyConfiguration configuration = AssemblyConfiguration.builder().user("OtherUser").name("ImageName").build();
new Expectations() {{
buildConfiguration.getAssemblyConfiguration();
buildConfiguration.getAssembly();
result = configuration;
}};
// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class DockerAssemblyManagerTest {
@Test
public void testNoAssembly() {
BuildConfiguration buildConfig = BuildConfiguration.builder().build();
AssemblyConfiguration assemblyConfig = buildConfig.getAssemblyConfiguration();
AssemblyConfiguration assemblyConfig = buildConfig.getAssembly();

DockerFileBuilder builder = assemblyManager.createDockerFileBuilder(buildConfig, assemblyConfig);
String content = builder.content();
Expand Down Expand Up @@ -253,7 +253,7 @@ public void testCreateDockerTarArchiveWithDockerfile() throws IOException {
File dockerDirectory = new File(targetDirectory, "docker");


final JKubeConfiguration jKubeBuildContext = JKubeConfiguration.builder()
final JKubeConfiguration configuration = JKubeConfiguration.builder()
.project(JavaProject.builder()
.groupId("org.eclipse.jkube")
.artifactId("test")
Expand All @@ -269,14 +269,13 @@ public void testCreateDockerTarArchiveWithDockerfile() throws IOException {
.sourceDirectory(baseProjectDir.getPath() + "/src/main/docker")
.build();
final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder()
.dockerFileDir(baseProjectDir.getPath())
.dockerFile(dockerFile.getPath())
.dockerFileFile(dockerFile)
.build();


// When
File dockerArchiveFile = assemblyManager.createDockerTarArchive("test-image", jKubeBuildContext, jKubeBuildConfiguration, prefixedLogger, null);
File dockerArchiveFile = assemblyManager.createDockerTarArchive("test-image", configuration, jKubeBuildConfiguration, prefixedLogger, null);

// Then
assertNotNull(dockerArchiveFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.build.service.docker;

import mockit.Expectations;
import org.eclipse.jkube.kit.build.service.docker.config.ConfigHelper;
import org.eclipse.jkube.kit.build.service.docker.config.RunImageConfiguration;
import org.eclipse.jkube.kit.config.image.build.BuildConfiguration;

import mockit.Mocked;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class ImageConfigurationTest {

@Test
public void initAndValidateWithBuildAndRun(
@Mocked ConfigHelper.NameFormatter nameFormatter, @Mocked BuildConfiguration buildConfiguration,
@Mocked RunImageConfiguration runImageConfiguration) {

// Given
final ImageConfiguration imageConfiguration = ImageConfiguration.builder()
.build(buildConfiguration)
.run(runImageConfiguration)
.build();
// @formatter:off
new Expectations() {{
buildConfiguration.initAndValidate(); result = "1.337";
runImageConfiguration.initAndValidate(); result = "13.37";
}};
// @formatter:on
// When
final String result = imageConfiguration.initAndValidate(nameFormatter);
// Then
assertThat(result, is("13.37"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ public static Map<File, String> processAssemblyFileSet(

final Map<File, String> fileToPermissionsMap = new HashMap<>();
final File sourceDirectory = resolveSourceDirectory(baseDirectory, assemblyFileSet);
final File targetDirectory = outputDirectory.toPath()
.resolve(Objects.requireNonNull(assemblyConfiguration.getName(), "Assembly Configuration name is required"))
.toFile();
final File targetDirectory = new File(outputDirectory, Objects.requireNonNull(
assemblyConfiguration.getTargetDir(), "Assembly Configuration target dir is required"));
final File destinationDirectory;
if (assemblyFileSet.getOutputDirectory() == null) {
destinationDirectory = new File(targetDirectory, sourceDirectory.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public static File getAssemblyFileOutputDirectory(
if (assemblyFile.getOutputDirectory().isAbsolute()) {
outputDirectory = assemblyFile.getOutputDirectory();
} else {
outputDirectory = outputDirectoryForRelativePaths.toPath()
.resolve(Objects.requireNonNull(assemblyConfiguration.getName(), "Assembly Configuration name is required"))
.resolve(assemblyFile.getOutputDirectory().toPath())
.toFile();
outputDirectory = new File(outputDirectoryForRelativePaths, Objects.requireNonNull(
assemblyConfiguration.getTargetDir(), "Assembly Configuration target dir is required")).toPath()
.resolve(assemblyFile.getOutputDirectory().toPath())
.toFile();
}
return outputDirectory;
}
Expand Down
Loading

0 comments on commit d290c13

Please sign in to comment.