Search in sources :

Example 1 with BuildInfoProperties

use of org.jfrog.build.api.BuildInfoProperties in project build-info by JFrogDev.

the class GradleArtifactoryClientConfigUpdater method update.

/**
 * Returns a configuration handler object out of a Gradle project. This method will aggregate the properties in our
 * defined hierarchy. First search for the property as a system property, if found return it.
 * Second search for the property in the Gradle {@link org.gradle.StartParameter#getProjectProperties} container
 * and if found there, then return it. Third search for the property in {@link
 * org.gradle.api.Project#property(String)}
 * if not found, search upwards in the project hierarchy until
 * reach the root project. if not found at all in this hierarchy return null
 *
 * @param project the gradle project with properties for build info client configuration (Usually in start parameter
 *                from CI Server)
 */
public static void update(ArtifactoryClientConfiguration config, Project project) {
    Properties props = new Properties();
    // First aggregate properties from parent to child
    fillProperties(project, props);
    // Then start parameters
    StartParameter startParameter = project.getGradle().getStartParameter();
    Map<String, String> startProps = startParameter.getProjectProperties();
    props.putAll(BuildInfoExtractorUtils.filterStringEntries(startProps));
    // Then System properties
    Properties mergedProps = BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(props, config.info.getLog());
    // Then special buildInfo properties
    Properties buildInfoProperties = BuildInfoExtractorUtils.filterDynamicProperties(mergedProps, BUILD_INFO_PROP_PREDICATE);
    buildInfoProperties = BuildInfoExtractorUtils.stripPrefixFromProperties(buildInfoProperties, BUILD_INFO_PROP_PREFIX);
    mergedProps.putAll(buildInfoProperties);
    // Add the collected properties to the Artifactory client configuration.
    // In case the build name and build number have already been added to the configuration
    // from inside the gradle script, we do not want to override them by the values sent from
    // the CI server plugin.
    String prefix = BuildInfoProperties.BUILD_INFO_PREFIX;
    Set<String> excludeIfExist = Sets.newHashSet(prefix + BuildInfoFields.BUILD_NUMBER, prefix + BuildInfoFields.BUILD_NAME, prefix + BuildInfoFields.BUILD_STARTED);
    config.fillFromProperties(mergedProps, excludeIfExist);
    // After props are set, apply missing project props (not set by CI-plugin generated props)
    setMissingBuildAttributes(config, project);
}
Also used : StartParameter(org.gradle.StartParameter) Properties(java.util.Properties) BuildInfoProperties(org.jfrog.build.api.BuildInfoProperties)

Example 2 with BuildInfoProperties

use of org.jfrog.build.api.BuildInfoProperties in project build-info by JFrogDev.

the class BuildInfoExtractorSupportTest method getEnvAndSysPropertiesFromFile.

public void getEnvAndSysPropertiesFromFile() throws IOException {
    // create a property file
    File propsFile = new File("tempPropFile");
    propsFile.createNewFile();
    Properties props = new Properties();
    props.put(ENV_POPO_KEY, "buildname");
    props.put(ENV_MOMO_KEY, "1");
    props.store(new FileOutputStream(propsFile), "");
    System.setProperty(BuildInfoConfigProperties.PROP_PROPS_FILE, propsFile.getAbsolutePath());
    // Put system properties
    String kokoKey = "koko";
    String gogoKey = "gogo";
    System.setProperty(kokoKey, "parent");
    System.setProperty(gogoKey, "2");
    Properties buildInfoProperties = BuildInfoExtractorUtils.getEnvProperties(new Properties(), null);
    assertEquals(buildInfoProperties.getProperty(ENV_POPO_KEY), "buildname", "popo property does not match");
    assertEquals(buildInfoProperties.getProperty(ENV_MOMO_KEY), "1", "momo number property does not match");
    assertEquals(buildInfoProperties.getProperty("koko"), "parent", "koko parent name property does not match");
    assertEquals(buildInfoProperties.getProperty("gogo"), "2", "gogo parent number property does not match");
    propsFile.delete();
    System.clearProperty(BuildInfoConfigProperties.PROP_PROPS_FILE);
    System.clearProperty(kokoKey);
    System.clearProperty(gogoKey);
}
Also used : FileOutputStream(java.io.FileOutputStream) BuildInfoConfigProperties(org.jfrog.build.api.BuildInfoConfigProperties) Properties(java.util.Properties) BuildInfoProperties(org.jfrog.build.api.BuildInfoProperties) File(java.io.File)

Example 3 with BuildInfoProperties

use of org.jfrog.build.api.BuildInfoProperties in project build-info by JFrogDev.

the class BuildInfoExtractorSupportTest method testIncludePatterns.

public void testIncludePatterns() throws IOException {
    // Put system properties
    String gogoKey = "gogo1";
    String gogo2Key = "gogo2a";
    String kokoKey = "koko";
    System.setProperty(kokoKey, "parent");
    System.setProperty(gogoKey, "1");
    System.setProperty(gogo2Key, "2");
    Properties startProps = new Properties();
    startProps.put(BuildInfoConfigProperties.PROP_ENV_VARS_INCLUDE_PATTERNS, "gogo?*");
    Properties buildInfoProperties = BuildInfoExtractorUtils.getEnvProperties(startProps, null);
    assertEquals(buildInfoProperties.getProperty("gogo1"), "1", "gogo1 parent number property does not match");
    assertEquals(buildInfoProperties.getProperty("gogo2a"), "2", "gogo2a parent number property does not match");
    assertNull(buildInfoProperties.getProperty("koko"), "Should not find koko property due to include patterns");
    System.clearProperty(gogoKey);
    System.clearProperty(gogo2Key);
    System.clearProperty(kokoKey);
}
Also used : BuildInfoConfigProperties(org.jfrog.build.api.BuildInfoConfigProperties) Properties(java.util.Properties) BuildInfoProperties(org.jfrog.build.api.BuildInfoProperties)

Example 4 with BuildInfoProperties

use of org.jfrog.build.api.BuildInfoProperties in project build-info by JFrogDev.

the class BuildInfoExtractorSupportTest method getBuildInfoProperties.

public void getBuildInfoProperties() throws IOException {
    // create a property file
    File propsFile = new File("tempPropFile");
    propsFile.createNewFile();
    Properties props = new Properties();
    props.put(POPO_KEY, "buildname");
    props.put(MOMO_KEY, "1");
    props.store(new FileOutputStream(propsFile), "");
    System.setProperty(BuildInfoConfigProperties.PROP_PROPS_FILE, propsFile.getAbsolutePath());
    // Put system properties
    String kokoKey = BuildInfoProperties.BUILD_INFO_PROP_PREFIX + "koko";
    String gogoKey = BuildInfoProperties.BUILD_INFO_PROP_PREFIX + "gogo";
    System.setProperty(kokoKey, "parent");
    System.setProperty(gogoKey, "2");
    Properties buildInfoProperties = BuildInfoExtractorUtils.filterDynamicProperties(BuildInfoExtractorUtils.mergePropertiesWithSystemAndPropertyFile(new Properties()), BuildInfoExtractorUtils.BUILD_INFO_PROP_PREDICATE);
    assertEquals(buildInfoProperties.size(), 4, "There should be 4 properties");
    assertEquals(buildInfoProperties.getProperty(POPO_KEY), "buildname", "popo property does not match");
    assertEquals(buildInfoProperties.getProperty(MOMO_KEY), "1", "momo number property does not match");
    assertEquals(buildInfoProperties.getProperty(kokoKey), "parent", "koko parent name property does not match");
    assertEquals(buildInfoProperties.getProperty(gogoKey), "2", "gogo parent number property does not match");
    propsFile.delete();
    System.clearProperty(BuildInfoConfigProperties.PROP_PROPS_FILE);
    System.clearProperty(kokoKey);
    System.clearProperty(gogoKey);
}
Also used : FileOutputStream(java.io.FileOutputStream) BuildInfoConfigProperties(org.jfrog.build.api.BuildInfoConfigProperties) Properties(java.util.Properties) BuildInfoProperties(org.jfrog.build.api.BuildInfoProperties) File(java.io.File)

Example 5 with BuildInfoProperties

use of org.jfrog.build.api.BuildInfoProperties in project build-info by JFrogDev.

the class BuildInfoExtractorSupportTest method testExcludePatterns.

public void testExcludePatterns() throws IOException {
    // Put system properties
    String kokoKey = "koko";
    String koko2Key = "akoko";
    String gogoKey = "gogo";
    System.setProperty(kokoKey, "parent");
    System.setProperty(koko2Key, "parent2");
    System.setProperty(gogoKey, "2");
    Properties startProps = new Properties();
    startProps.put(BuildInfoConfigProperties.PROP_ENV_VARS_EXCLUDE_PATTERNS, "*koko");
    Properties buildInfoProperties = BuildInfoExtractorUtils.getEnvProperties(startProps, null);
    assertNull(buildInfoProperties.getProperty("koko"), "Should not find koko property due to exclude patterns");
    assertNull(buildInfoProperties.getProperty("akoko"), "Should not find akoko property due to exclude patterns");
    assertEquals(buildInfoProperties.getProperty("gogo"), "2", "gogo parent number property does not match");
    System.clearProperty(kokoKey);
    System.clearProperty(gogoKey);
}
Also used : BuildInfoConfigProperties(org.jfrog.build.api.BuildInfoConfigProperties) Properties(java.util.Properties) BuildInfoProperties(org.jfrog.build.api.BuildInfoProperties)

Aggregations

Properties (java.util.Properties)5 BuildInfoProperties (org.jfrog.build.api.BuildInfoProperties)5 BuildInfoConfigProperties (org.jfrog.build.api.BuildInfoConfigProperties)4 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 StartParameter (org.gradle.StartParameter)1