Skip to content

Commit b77eae5

Browse files
authored
Reading Extractor Property Temp File Path From System Property
1 parent a691d17 commit b77eae5

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/extractor/GradleArtifactoryClientConfigUpdater.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
import org.gradle.api.Project;
55
import org.jfrog.build.extractor.ci.BuildInfoFields;
66
import org.jfrog.build.extractor.ci.BuildInfoProperties;
7+
import org.jfrog.build.extractor.ci.BuildInfoConfigProperties;
8+
import org.apache.commons.lang3.StringUtils;
79
import org.jfrog.build.api.util.CommonUtils;
810
import org.jfrog.build.extractor.BuildInfoExtractorUtils;
911
import org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration;
1012

13+
import java.io.File;
14+
import java.io.FileInputStream;
15+
import java.io.InputStream;
1116
import java.util.Map;
1217
import java.util.Properties;
1318
import java.util.Set;
@@ -46,6 +51,25 @@ public static void update(ArtifactoryClientConfiguration config, Project project
4651

4752
// Then System properties
4853
Properties mergedProps = BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(props, config.info.getLog());
54+
55+
// Override file loading with explicit system property check to avoid Gradle daemon caching issues.
56+
String buildInfoPropFile = System.getProperty(BuildInfoConfigProperties.PROP_PROPS_FILE);
57+
String propSource = "system property (" + BuildInfoConfigProperties.PROP_PROPS_FILE + ")";
58+
59+
if (StringUtils.isBlank(buildInfoPropFile)) {
60+
buildInfoPropFile = System.getProperty(BuildInfoConfigProperties.ENV_BUILDINFO_PROPFILE);
61+
propSource = "system property (" + BuildInfoConfigProperties.ENV_BUILDINFO_PROPFILE + ")";
62+
}
63+
64+
// If we found a system property-based file path, reload it to ensure it takes priority over env var
65+
if (StringUtils.isNotBlank(buildInfoPropFile)) {
66+
Properties fileProps = loadBuildInfoProperties(buildInfoPropFile, config.info.getLog());
67+
if (fileProps != null) {
68+
mergedProps.putAll(fileProps);
69+
config.info.getLog().debug("Overriding with properties from " + propSource + ": " + buildInfoPropFile);
70+
}
71+
}
72+
4973
// Then special buildInfo properties
5074
Properties buildInfoProperties =
5175
BuildInfoExtractorUtils.filterDynamicProperties(mergedProps, BUILD_INFO_PROP_PREDICATE);
@@ -65,6 +89,29 @@ public static void update(ArtifactoryClientConfiguration config, Project project
6589
addDefaultPublisherAttributes(config, project.getRootProject().getName(), "Gradle", project.getGradle().getGradleVersion());
6690
}
6791

92+
/**
93+
* Helper method to load build info properties from a file with proper error handling
94+
*/
95+
private static Properties loadBuildInfoProperties(String filePath, org.jfrog.build.api.util.Log log) {
96+
if (StringUtils.isBlank(filePath)) {
97+
return null;
98+
}
99+
100+
File propertiesFile = new File(filePath);
101+
if (!propertiesFile.exists()) {
102+
log.warn("Properties file not found at: " + filePath);
103+
return null;
104+
}
105+
106+
try (InputStream inputStream = new FileInputStream(propertiesFile)) {
107+
Properties fileProps = new Properties();
108+
fileProps.load(inputStream);
109+
return fileProps;
110+
} catch (Exception e) {
111+
log.error("Failed to load properties from: " + filePath + " - " + e.getMessage());
112+
return null;
113+
}
114+
}
68115

69116
private static void fillProperties(Project project, Properties props) {
70117
Project parent = project.getParent();

build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/task/DeployTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ private void collectProjectBuildInfo() throws IOException {
5353
log.debug("Starting build info extraction for project '{}' using last task in graph '{}'",
5454
new Object[]{getProject().getPath(), getPath()});
5555
prepareAndDeploy();
56-
String propertyFilePath = System.getenv(BuildInfoConfigProperties.PROP_PROPS_FILE);
56+
String propertyFilePath = System.getProperty(BuildInfoConfigProperties.PROP_PROPS_FILE);
5757
if (StringUtils.isBlank(propertyFilePath)) {
58-
propertyFilePath = System.getenv(BuildInfoConfigProperties.ENV_BUILDINFO_PROPFILE);
58+
propertyFilePath = System.getProperty(BuildInfoConfigProperties.ENV_BUILDINFO_PROPFILE);
5959
}
6060
if (StringUtils.isNotBlank(propertyFilePath)) {
6161
File file = new File(propertyFilePath);

0 commit comments

Comments
 (0)