diff --git a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/JavaProject.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/JavaProject.java index b03ac6e5e0..cd7e9f0990 100644 --- a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/JavaProject.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/JavaProject.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.Serializable; +import java.net.URL; import java.time.LocalDate; import java.util.List; import java.util.Locale; @@ -37,7 +38,14 @@ public class JavaProject implements Serializable { private static final long serialVersionUID = 6438404976521622633L; - + + /** + * Properties file for the project + * + * @param propertiesFile for the project. + * @return Properties file for the project. + */ + private URL propertiesFile; /** * Project's name. * diff --git a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootConfiguration.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootConfiguration.java index ae8103d508..756d00570a 100644 --- a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootConfiguration.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootConfiguration.java @@ -16,6 +16,7 @@ import lombok.Builder; import lombok.Getter; import org.eclipse.jkube.kit.common.JavaProject; +import org.eclipse.jkube.kit.common.PropertiesExtender; import java.util.Optional; import java.util.Properties; @@ -37,9 +38,11 @@ public class SpringBootConfiguration { private String actuatorDefaultBasePath; public static SpringBootConfiguration from(JavaProject project) { - final Properties properties = SpringBootUtil.getSpringBootApplicationProperties( + final PropertiesExtender properties = SpringBootUtil.getSpringBootApplicationProperties( SpringBootUtil.getSpringBootActiveProfile(project), JKubeProjectUtil.getClassLoader(project)); + project.setPropertiesFile(properties.getPropertiesFile()); + final int majorVersion = SpringBootUtil.getSpringBootVersion(project) .map(semVer -> { try { diff --git a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootUtil.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootUtil.java index 018c03b5c9..deafdb268c 100644 --- a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootUtil.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/SpringBootUtil.java @@ -23,6 +23,7 @@ import org.eclipse.jkube.kit.common.JavaProject; import org.eclipse.jkube.kit.common.Plugin; +import org.eclipse.jkube.kit.common.PropertiesExtender; import static org.eclipse.jkube.kit.common.util.PropertiesUtil.getPropertiesFromResource; @@ -64,14 +65,22 @@ public static Properties getSpringBootApplicationProperties(URLClassLoader compi * @param compileClassLoader compile class loader * @return properties object */ - public static Properties getSpringBootApplicationProperties(String springActiveProfile, URLClassLoader compileClassLoader) { + public static PropertiesExtender getSpringBootApplicationProperties(String springActiveProfile, URLClassLoader compileClassLoader) { URL ymlResource = compileClassLoader.findResource("application.yml"); URL propertiesResource = compileClassLoader.findResource("application.properties"); - + Properties props = YamlUtil.getPropertiesFromYamlResource(springActiveProfile, ymlResource); props.putAll(getPropertiesFromResource(propertiesResource)); - return new SpringBootPropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, VALUE_SEPARATOR, true) - .replaceAllPlaceholders(props); + props = new SpringBootPropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, VALUE_SEPARATOR, true) + .replaceAllPlaceholders(props); + + // Extend Properties object with resources file path + PropertiesExtender propsExtender = new PropertiesExtender(); + URL propertiesFile = ymlResource != null ? ymlResource : propertiesResource; + propsExtender.setPropertiesFile(propertiesFile); + propsExtender.putAll(props); + + return propsExtender; } /** diff --git a/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/DefaultGeneratorManager.java b/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/DefaultGeneratorManager.java index e62d1abcbc..59d80303ea 100644 --- a/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/DefaultGeneratorManager.java +++ b/jkube-kit/generator/api/src/main/java/org/eclipse/jkube/generator/api/DefaultGeneratorManager.java @@ -57,6 +57,7 @@ public List generate(List imageConfigs) if (generator.isApplicable(ret)) { log.info("Running generator %s", generator.getName()); ret = generator.customize(ret, genCtx.isPrePackagePhase()); + log.info("The following properties file is used %s", genCtx.getProject().getPropertiesFile()); } } return ret; diff --git a/jkube-kit/generator/api/src/test/java/org/eclipse/jkube/generator/api/DefaultGeneratorManagerTest.java b/jkube-kit/generator/api/src/test/java/org/eclipse/jkube/generator/api/DefaultGeneratorManagerTest.java index e151fdf8a5..55d231b017 100644 --- a/jkube-kit/generator/api/src/test/java/org/eclipse/jkube/generator/api/DefaultGeneratorManagerTest.java +++ b/jkube-kit/generator/api/src/test/java/org/eclipse/jkube/generator/api/DefaultGeneratorManagerTest.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.stream.Collectors; +import org.eclipse.jkube.kit.common.JavaProject; import org.eclipse.jkube.kit.common.KitLogger; import org.eclipse.jkube.kit.config.image.GeneratorManager; import org.eclipse.jkube.kit.config.image.ImageConfiguration; @@ -43,6 +44,7 @@ void setUp() { GeneratorContext generatorContext = GeneratorContext.builder() .config(processorConfig) .logger(logger) + .project(new JavaProject(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)) .build(); generatorManager = new DefaultGeneratorManager(generatorContext); }