Search in sources :

Example 41 with BuildConfiguration

use of org.jboss.pnc.dto.BuildConfiguration in project bacon by project-ncl.

the class PncEntitiesImporter method generatePncBuildConfig.

/**
 * @param buildConfig PiG buildconfig to generate
 * @param existing if present, we'll use it as the buildconfig to modify if null: we'll use a fresh buildconfig
 *        object
 *
 * @return BuildConfiguration generated
 */
private BuildConfiguration generatePncBuildConfig(BuildConfig buildConfig, BuildConfiguration existing) {
    ProjectRef project = getOrGenerateProject(buildConfig.getProject());
    SCMRepository repository = getOrGenerateRepository(buildConfig);
    Environment environment = Environment.builder().id(buildConfig.getEnvironmentId()).build();
    BuildConfiguration.Builder builder = BuildConfiguration.builder();
    if (existing != null) {
        builder = existing.toBuilder();
    }
    return builder.productVersion(version).parameters(buildConfig.getGenericParameters(null, false)).name(buildConfig.getName()).project(project).environment(environment).scmRepository(repository).scmRevision(buildConfig.getScmRevision()).buildScript(buildConfig.getBuildScript()).buildType(BuildType.valueOf(buildConfig.getBuildType())).brewPullActive(buildConfig.getBrewPullActive()).build();
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Environment(org.jboss.pnc.dto.Environment) ProjectRef(org.jboss.pnc.dto.ProjectRef) SCMRepository(org.jboss.pnc.dto.SCMRepository)

Example 42 with BuildConfiguration

use of org.jboss.pnc.dto.BuildConfiguration in project bacon by project-ncl.

the class PncEntitiesImporter method updateBuildConfig.

private BuildConfiguration updateBuildConfig(BuildConfigData data, BuildConfiguration existing) {
    String configId = data.getId();
    BuildConfiguration buildConfiguration = generatePncBuildConfig(data.getNewConfig(), existing);
    try {
        buildConfigClient.update(configId, buildConfiguration);
        return buildConfigClient.getSpecific(configId);
    } catch (ClientException e) {
        throw new RuntimeException("Failed to update build configuration " + configId, e);
    }
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) ClientException(org.jboss.pnc.client.ClientException)

Example 43 with BuildConfiguration

use of org.jboss.pnc.dto.BuildConfiguration in project bacon by project-ncl.

the class PncEntitiesImporter method updateOrCreate.

private List<BuildConfigData> updateOrCreate(List<BuildConfiguration> currentConfigs, List<BuildConfig> builds, boolean skipBranchCheck, boolean temporaryBuild) {
    List<BuildConfigData> buildList = new ArrayList<>();
    for (BuildConfig bc : builds) {
        BuildConfigData data = new BuildConfigData(bc);
        for (BuildConfiguration config : currentConfigs) {
            if (config.getName().equals(bc.getName())) {
                data.setOldConfig(config);
                data.setId(config.getId());
                if (data.shouldBeUpdated(skipBranchCheck, temporaryBuild)) {
                    updateBuildConfig(data, config);
                }
            }
        }
        // Check if build exists already (globally)
        // True = Add to BCS and update BC (maybe ask?)
        Optional<BuildConfiguration> matchedBuildConfig = getBuildConfigFromName(bc.getName());
        if (matchedBuildConfig.isPresent()) {
            log.debug("Found matching build config for {}", bc.getName());
            data.setOldConfig(matchedBuildConfig.get());
            data.setId(matchedBuildConfig.get().getId());
            if (data.shouldBeUpdated(skipBranchCheck, temporaryBuild)) {
                updateBuildConfig(data, matchedBuildConfig.get());
            }
            data.setModified(true);
        } else {
            log.debug("No matching build config found in the BCS");
            // False = Create new project/BC
            BuildConfiguration createdConfig = createBuildConfig(data.getNewConfig());
            data.setId(createdConfig.getId());
            data.setModified(true);
            log.debug("Didn't find matching build config for {}", bc.getName());
        }
        buildList.add(data);
    }
    return buildList;
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) ArrayList(java.util.ArrayList) BuildConfig(org.jboss.pnc.bacon.pig.impl.config.BuildConfig)

Example 44 with BuildConfiguration

use of org.jboss.pnc.dto.BuildConfiguration in project bacon by project-ncl.

the class BuildConfigMappingTest method testPigYamlMetadataSet.

@Test
void testPigYamlMetadataSet() {
    Map<String, String> parameters = new HashMap<>();
    parameters.put("PIG_YAML_METADATA", "12345");
    BuildConfiguration buildConfiguration = BuildConfiguration.builder().parameters(parameters).build();
    BuildConfigMapping.setBuildConfigFieldsBasedOnParameters(buildConfiguration, buildConfig);
    assertEquals("12345", buildConfig.getPigYamlMetadata());
    // make sure no other parameters are set
    assertTrue(buildConfig.getAlignmentParameters().size() == 0);
    assertNull(buildConfig.getBuildPodMemory());
    assertNull(buildConfig.getBuildCategory());
    assertNull(buildConfig.getBrewBuildName());
    assertTrue(buildConfig.getExtraRepositories().size() == 0);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 45 with BuildConfiguration

use of org.jboss.pnc.dto.BuildConfiguration in project bacon by project-ncl.

the class BuildConfigMappingTest method testCanSetMultipleParameters.

@Test
void testCanSetMultipleParameters() {
    Map<String, String> parameters = new HashMap<>();
    parameters.put("ALIGNMENT_PARAMETERS", "-Dtest=true -Dme=false");
    parameters.put("BREW_BUILD_NAME", "testme");
    BuildConfiguration buildConfiguration = BuildConfiguration.builder().parameters(parameters).build();
    BuildConfigMapping.setBuildConfigFieldsBasedOnParameters(buildConfiguration, buildConfig);
    assertEquals("-Dtest=true -Dme=false", buildConfig.getAlignmentParameters().stream().findFirst().get());
    assertEquals("testme", buildConfig.getBrewBuildName());
    // make sure no other parameters are set
    assertNull(buildConfig.getBuildPodMemory());
    assertNull(buildConfig.getBuildCategory());
    assertNull(buildConfig.getPigYamlMetadata());
    assertTrue(buildConfig.getExtraRepositories().size() == 0);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)90 Test (org.junit.Test)65 ContainerTest (org.jboss.pnc.test.category.ContainerTest)45 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)31 HashMap (java.util.HashMap)17 InSequence (org.jboss.arquillian.junit.InSequence)17 Build (org.jboss.pnc.dto.Build)13 GroupBuild (org.jboss.pnc.dto.GroupBuild)12 SCMRepository (org.jboss.pnc.dto.SCMRepository)10 Test (org.junit.jupiter.api.Test)10 BuildConfigurationRef (org.jboss.pnc.dto.BuildConfigurationRef)9 Instant (java.time.Instant)8 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)7 BuildStatus (org.jboss.pnc.enums.BuildStatus)7 GroupConfigurationClient (org.jboss.pnc.client.GroupConfigurationClient)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 ArrayList (java.util.ArrayList)4 BuildConfigurationRevision (org.jboss.pnc.dto.BuildConfigurationRevision)4 HashSet (java.util.HashSet)3