Skip to content

Commit 43275d8

Browse files
author
Jay Denebeim
committed
BI-181 - Failure to locate properties file during initialization
2 parents a78049b + 8ac713a commit 43275d8

File tree

12 files changed

+85
-58
lines changed

12 files changed

+85
-58
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
build-info.ipr
1515
build-info.iws
1616
atlassian-*.xml
17+
/.nb-gradle/private/

Diff for: build-info-api/src/main/java/org/jfrog/build/api/BuildInfoConfigProperties.java

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ public interface BuildInfoConfigProperties {
4141

4242
String ENV_VARS_EXCLUDE_PATTERNS = "envVarsExcludePatterns";
4343
String PROP_ENV_VARS_EXCLUDE_PATTERNS = BUILD_INFO_CONFIG_PREFIX + ENV_VARS_EXCLUDE_PATTERNS;
44+
45+
/**
46+
* Secondary environment variable to hold the properties file name
47+
*/
48+
String ENV_BUILDINFO_PROPFILE = "BUILDINFO_PROPFILE";
4449
}

Diff for: build-info-client/src/main/java/org/jfrog/build/client/ArtifactoryClientConfiguration.java

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public Map<String, String> getAllRootConfig() {
9292
return rootConfig.props;
9393
}
9494

95+
public Log getLog() {
96+
return root.getLog();
97+
}
98+
9599
public void persistToPropertiesFile() {
96100
if (StringUtils.isEmpty(getPropertiesFile())) {
97101
return;

Diff for: build-info-client/src/main/java/org/jfrog/build/client/PrefixPropertyHandler.java

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ private PrefixPropertyHandler(Log log, Map<String, String> props, String prefix)
2828
this.prefix = prefix;
2929
}
3030

31+
public Log getLog() {
32+
return log;
33+
}
34+
3135
public String getPrefix() {
3236
return prefix;
3337
}

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.jfrog.gradle.plugin.artifactory.extractor;
1818

19-
import com.google.common.base.Predicate;
20-
import com.google.common.collect.Maps;
2119
import org.apache.commons.lang.StringUtils;
2220
import org.gradle.StartParameter;
2321
import org.gradle.api.Project;
@@ -26,7 +24,6 @@
2624
import org.jfrog.build.client.ArtifactoryClientConfiguration;
2725
import org.jfrog.build.extractor.BuildInfoExtractorUtils;
2826

29-
import javax.annotation.Nullable;
3027
import java.text.ParseException;
3128
import java.text.SimpleDateFormat;
3229
import java.util.Date;
@@ -64,7 +61,7 @@ public static void update(ArtifactoryClientConfiguration config, Project project
6461
props.putAll(BuildInfoExtractorUtils.filterStringEntries(startProps));
6562

6663
// Then System properties
67-
Properties mergedProps = BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(props);
64+
Properties mergedProps = BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(props, config.info.getLog());
6865
// Then special buildInfo properties
6966
Properties buildInfoProperties =
7067
BuildInfoExtractorUtils.filterDynamicProperties(mergedProps, BUILD_INFO_PROP_PREDICATE);

Diff for: build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/extractor/GradleBuildInfoExtractor.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public Build extract(Project rootProject) {
216216
if (clientConf.isIncludeEnvVars()) {
217217
Properties envProperties = new Properties();
218218
envProperties.putAll(clientConf.getAllProperties());
219-
envProperties = BuildInfoExtractorUtils.getEnvProperties(envProperties);
219+
envProperties = BuildInfoExtractorUtils.getEnvProperties(envProperties, clientConf.getLog());
220220
for (Map.Entry<Object, Object> envProp : envProperties.entrySet()) {
221221
bib.addProperty(envProp.getKey(), envProp.getValue());
222222
}
@@ -291,6 +291,7 @@ public Artifact apply(GradleDeployDetails from) {
291291
}));
292292
return artifacts;
293293
}
294+
294295
private List<Dependency> calculateDependencies(Project project) throws Exception {
295296
Set<Configuration> configurationSet = project.getConfigurations();
296297
List<Dependency> dependencies = newArrayList();
@@ -360,10 +361,10 @@ public IncludeExcludePredicate(Project project, IncludeExcludePatterns patterns,
360361
}
361362

362363
public boolean apply(@Nullable GradleDeployDetails input) {
363-
if(include){
364+
if (include) {
364365
return input.getProject().equals(project) && !PatternMatcher.pathConflicts(input.getDeployDetails().getArtifactPath(), patterns);
365-
}else{
366-
return input.getProject().equals(project) && PatternMatcher.pathConflicts(input.getDeployDetails().getArtifactPath(), patterns);
366+
} else {
367+
return input.getProject().equals(project) && PatternMatcher.pathConflicts(input.getDeployDetails().getArtifactPath(), patterns);
367368
}
368369
}
369370
}

Diff for: build-info-extractor-ivy/src/main/java/org/jfrog/build/extractor/listener/ArtifactoryBuildListener.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void assertInitialized(BuildEvent event) {
6464
private Properties getMergedEnvAndSystemProps() {
6565
Properties props = new Properties();
6666
props.putAll(System.getenv());
67-
return BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(props);
67+
return BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(props, buildInfoLog);
6868
}
6969

7070
public IvyBuildInfoLog getBuildInfoLog(BuildEvent event) {
@@ -327,7 +327,7 @@ private void doDeploy(BuildEvent event) {
327327
if (clientConf.isIncludeEnvVars()) {
328328
Properties envProperties = new Properties();
329329
envProperties.putAll(clientConf.getAllProperties());
330-
envProperties = BuildInfoExtractorUtils.getEnvProperties(envProperties);
330+
envProperties = BuildInfoExtractorUtils.getEnvProperties(envProperties, clientConf.getLog());
331331
for (Map.Entry<Object, Object> envProp : envProperties.entrySet()) {
332332
builder.addProperty(envProp.getKey(), envProp.getValue());
333333
}

Diff for: build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/BuildInfoRecorder.java

+15-21
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ public void projectDiscoveryStarted(ExecutionEvent event) {
103103

104104
@Override
105105
public void sessionStarted(ExecutionEvent event) {
106-
try
107-
{
106+
try {
108107
logger.info("Initializing Artifactory Build-Info Recording");
109108
buildInfoBuilder = buildInfoModelPropertyResolver.resolveProperties(event, conf);
110109
deployableArtifactBuilderMap = Maps.newHashMap();
@@ -119,12 +118,10 @@ public void sessionStarted(ExecutionEvent event) {
119118
if (wrappedListener != null) {
120119
wrappedListener.sessionStarted(event);
121120
}
122-
}
123-
catch ( Throwable t )
124-
{
121+
} catch (Throwable t) {
125122
String message = getClass().getName() + ".sessionStarted() listener has failed: ";
126-
logger.error( message, t );
127-
throw new RuntimeException( message, t );
123+
logger.error(message, t);
124+
throw new RuntimeException(message, t);
128125
}
129126
}
130127

@@ -135,20 +132,17 @@ public void sessionEnded(ExecutionEvent event) {
135132
if (build != null) {
136133
File basedir = event.getSession().getTopLevelProject().getBasedir();
137134
conf.persistToPropertiesFile();
138-
buildDeploymentHelper.deploy(build, conf, deployableArtifactBuilderMap, projectHasTestFailures,basedir);
135+
buildDeploymentHelper.deploy(build, conf, deployableArtifactBuilderMap, projectHasTestFailures, basedir);
139136
}
140137
deployableArtifactBuilderMap.clear();
141138
if (wrappedListener != null) {
142139
wrappedListener.sessionEnded(event);
143140
}
144-
}
145-
catch ( Throwable t )
146-
{
141+
} catch (Throwable t) {
147142
String message = getClass().getName() + ".sessionEnded() listener has failed: ";
148-
logger.error( message, t );
149-
throw new RuntimeException( message, t );
150-
}
151-
finally {
143+
logger.error(message, t);
144+
throw new RuntimeException(message, t);
145+
} finally {
152146
String propertyFilePath = System.getenv(BuildInfoConfigProperties.PROP_PROPS_FILE);
153147
if (StringUtils.isNotBlank(propertyFilePath)) {
154148
File file = new File(propertyFilePath);
@@ -454,9 +448,9 @@ private void addArtifactsToCurrentModule(MavenProject project, ModuleBuilder mod
454448
String groupId = moduleArtifact.getGroupId();
455449
String deploymentPath = getDeploymentPath(groupId, artifactId, artifactVersion, artifactClassifier, artifactExtension);
456450
// If excludeArtifactsFromBuild and the PatternMatcher found conflict, add the excluded artifact to the excluded artifact set.
457-
if(excludeArtifactsFromBuild && PatternMatcher.pathConflicts(deploymentPath,patterns)){
451+
if (excludeArtifactsFromBuild && PatternMatcher.pathConflicts(deploymentPath, patterns)) {
458452
module.addExcludedArtifact(artifact);
459-
}else{
453+
} else {
460454
module.addArtifact(artifact);
461455
}
462456
if (isPublishArtifacts(artifactFile)) {
@@ -476,9 +470,9 @@ private void addArtifactsToCurrentModule(MavenProject project, ModuleBuilder mod
476470
artifactBuilder.name(pomFileName);
477471
org.jfrog.build.api.Artifact pomArtifact = artifactBuilder.build();
478472
deploymentPath = getDeploymentPath(groupId, artifactId, artifactVersion, artifactClassifier, "pom");
479-
if(excludeArtifactsFromBuild && PatternMatcher.pathConflicts(deploymentPath,patterns)){
473+
if (excludeArtifactsFromBuild && PatternMatcher.pathConflicts(deploymentPath, patterns)) {
480474
module.addExcludedArtifact(pomArtifact);
481-
}else{
475+
} else {
482476
module.addArtifact(pomArtifact);
483477
}
484478
if (isPublishArtifacts(pomFile)) {
@@ -528,7 +522,7 @@ private void addDeployableArtifact(org.jfrog.build.api.Artifact artifact, File a
528522
/**
529523
* @param deployPath the full path string to extract the repo from
530524
* @return Return the target deployment repository. Either the releases repository (default) or snapshots if defined
531-
* and the deployed file is a snapshot.
525+
* and the deployed file is a snapshot.
532526
*/
533527
public String getTargetRepository(String deployPath) {
534528
String snapshotsRepository = conf.publisher.getSnapshotRepoKey();
@@ -604,7 +598,7 @@ public Build extract(ExecutionEvent event) {
604598
if (conf.isIncludeEnvVars()) {
605599
Properties envProperties = new Properties();
606600
envProperties.putAll(conf.getAllProperties());
607-
envProperties = BuildInfoExtractorUtils.getEnvProperties(envProperties);
601+
envProperties = BuildInfoExtractorUtils.getEnvProperties(envProperties, conf.getLog());
608602
for (Map.Entry<Object, Object> envProp : envProperties.entrySet()) {
609603
buildInfoBuilder.addProperty(envProp.getKey(), envProp.getValue());
610604
}

Diff for: build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/BuildInfoRecorderLifecycleParticipant.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ private ArtifactoryClientConfiguration getConfiguration(MavenSession session) {
7474
allMavenProps.putAll(session.getSystemProperties());
7575
allMavenProps.putAll(session.getUserProperties());
7676

77-
Properties allProps = BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(allMavenProps);
78-
internalConfiguration = new ArtifactoryClientConfiguration(new Maven3BuildInfoLogger(logger));
77+
Maven3BuildInfoLogger log = new Maven3BuildInfoLogger(logger);
78+
Properties allProps = BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(allMavenProps, log);
79+
internalConfiguration = new ArtifactoryClientConfiguration(log);
7980
internalConfiguration.fillFromProperties(allProps);
8081
return internalConfiguration;
8182
}

Diff for: build-info-extractor-maven3/src/main/java/org/jfrog/build/extractor/maven/resolver/ResolutionHelper.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public void resolve(Properties allMavenProps, Logger logger) {
2828
return;
2929
}
3030

31-
Properties allProps = BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(allMavenProps);
32-
internalConfiguration = new ArtifactoryClientConfiguration(new Maven3BuildInfoLogger(logger));
31+
Maven3BuildInfoLogger log = new Maven3BuildInfoLogger(logger);
32+
Properties allProps = BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(allMavenProps, log);
33+
internalConfiguration = new ArtifactoryClientConfiguration(log);
3334
internalConfiguration.fillFromProperties(allProps);
3435
}
3536

Diff for: build-info-extractor/src/main/java/org/jfrog/build/extractor/BuildInfoExtractorUtils.java

+35-16
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@
3232
import org.jfrog.build.api.Build;
3333
import org.jfrog.build.api.BuildInfoConfigProperties;
3434
import org.jfrog.build.api.BuildInfoProperties;
35+
import org.jfrog.build.api.util.Log;
3536
import org.jfrog.build.client.ClientProperties;
3637
import org.jfrog.build.client.IncludeExcludePatterns;
3738
import org.jfrog.build.client.PatternMatcher;
3839

39-
import java.io.File;
40-
import java.io.FileInputStream;
41-
import java.io.IOException;
42-
import java.io.InputStream;
43-
import java.io.StringReader;
44-
import java.io.StringWriter;
40+
import java.io.*;
4541
import java.util.HashMap;
4642
import java.util.Map;
4743
import java.util.Properties;
@@ -65,9 +61,9 @@ public abstract class BuildInfoExtractorUtils {
6561
public static final Predicate<Object> MATRIX_PARAM_PREDICATE =
6662
new PrefixPredicate(ClientProperties.PROP_DEPLOY_PARAM_PROP_PREFIX);
6763

68-
public static Properties mergePropertiesWithSystemAndPropertyFile(Properties existingProps) {
64+
public static Properties mergePropertiesWithSystemAndPropertyFile(Properties existingProps, Log log) {
6965
Properties props = new Properties();
70-
String propertiesFilePath = getAdditionalPropertiesFile(existingProps);
66+
String propertiesFilePath = getAdditionalPropertiesFile(existingProps, log);
7167
if (StringUtils.isNotBlank(propertiesFilePath)) {
7268
File propertiesFile = new File(propertiesFilePath);
7369
InputStream inputStream = null;
@@ -115,7 +111,7 @@ public static Properties stripPrefixFromProperties(Properties source, String pre
115111
return props;
116112
}
117113

118-
public static Properties getEnvProperties(Properties startProps) {
114+
public static Properties getEnvProperties(Properties startProps, Log log) {
119115
IncludeExcludePatterns patterns = new IncludeExcludePatterns(
120116
startProps.getProperty(BuildInfoConfigProperties.PROP_ENV_VARS_INCLUDE_PATTERNS),
121117
startProps.getProperty(BuildInfoConfigProperties.PROP_ENV_VARS_EXCLUDE_PATTERNS));
@@ -151,7 +147,7 @@ public static Properties getEnvProperties(Properties startProps) {
151147
}
152148

153149
// TODO: [by FSI] Test if this is needed! Since start props are used now
154-
String propertiesFilePath = getAdditionalPropertiesFile(startProps);
150+
String propertiesFilePath = getAdditionalPropertiesFile(startProps, log);
155151
if (StringUtils.isNotBlank(propertiesFilePath)) {
156152
File propertiesFile = new File(propertiesFilePath);
157153
InputStream inputStream = null;
@@ -215,17 +211,40 @@ public static void saveBuildInfoToFile(Build build, File toFile) throws IOExcept
215211
Files.write(buildInfoJson, toFile, Charsets.UTF_8);
216212
}
217213

218-
private static String getAdditionalPropertiesFile(Properties additionalProps) {
214+
private static String getAdditionalPropertiesFile(Properties additionalProps, Log log) {
219215
String key = BuildInfoConfigProperties.PROP_PROPS_FILE;
220216
String propertiesFilePath = System.getProperty(key);
217+
String propFoundPath = "";
221218
if (StringUtils.isBlank(propertiesFilePath) && additionalProps != null) {
222219
propertiesFilePath = additionalProps.getProperty(key);
220+
propFoundPath = "additionalProps.getProperty";
221+
}
222+
if (StringUtils.isBlank(propertiesFilePath)) {
223+
// Jenkins prefixes these variables with "env." so let's try that
224+
propertiesFilePath = additionalProps.getProperty("env." + key);
223225
if (StringUtils.isBlank(propertiesFilePath)) {
224-
// Jenkins prefixes these variables with "env." so let's try that
225-
propertiesFilePath = additionalProps.getProperty("env." + key);
226-
if (StringUtils.isBlank(propertiesFilePath)) {
227-
propertiesFilePath = System.getenv(key);
228-
}
226+
propertiesFilePath = System.getenv(key);
227+
propFoundPath = StringUtils.isBlank(propertiesFilePath) ? "" : "System.getenv";
228+
} else {
229+
propFoundPath = "additionalProps.getProperty(\"env.\" + key)";
230+
}
231+
}
232+
if (StringUtils.isBlank(propertiesFilePath)) {
233+
// Jenkins prefixes these variables with "env." so let's try that
234+
key = BuildInfoConfigProperties.ENV_BUILDINFO_PROPFILE;
235+
propertiesFilePath = additionalProps.getProperty("env." + key);
236+
if (StringUtils.isBlank(propertiesFilePath)) {
237+
propertiesFilePath = System.getenv(key);
238+
propFoundPath = StringUtils.isBlank(propertiesFilePath) ? "" : " second System.getenv";
239+
} else {
240+
propFoundPath = "additionalProps.getProperty(\"env.\" + key)";
241+
}
242+
}
243+
if (log != null) {
244+
if (StringUtils.isBlank(propFoundPath)) {
245+
log.warn("[buildinfo] Properties file path was not found, this build will probably fail");
246+
} else {
247+
log.debug("[buildinfo] Properties file " + propertiesFilePath + " retrieved from " + propFoundPath);
229248
}
230249
}
231250
return propertiesFilePath;

0 commit comments

Comments
 (0)