diff --git a/pkg/cmd/projectCreate.go b/pkg/cmd/projectCreate.go index 3ed66944..d99732dc 100644 --- a/pkg/cmd/projectCreate.go +++ b/pkg/cmd/projectCreate.go @@ -696,9 +696,10 @@ func createOBRFolderBuildGradle(fileGenerator *utils.FileGenerator, targetOBRFol featureNames []string, forceOverwrite bool) error { type OBRGradleParameters struct { - Parent GradleCoordinates - Coordinates GradleCoordinates - Modules []GradleCoordinates + Parent GradleCoordinates + Coordinates GradleCoordinates + Modules []GradleCoordinates + GalasaVersion string } buildGradleTemplateParameters := OBRGradleParameters{ @@ -712,12 +713,19 @@ func createOBRFolderBuildGradle(fileGenerator *utils.FileGenerator, targetOBRFol GroupId: packageName, Name: packageName + "." + featureName} } - targetFile := utils.GeneratedFileDef{ - FileType: "gradle", - TargetFilePath: targetOBRFolderPath + "/build.gradle", - EmbeddedTemplateFilePath: "templates/projectCreate/parent-project/obr-project/build.gradle.template", - TemplateParameters: buildGradleTemplateParameters} + var galasaVersion string + var err error + galasaVersion, err = embedded.GetGalasaVersion() + if err == nil { + buildGradleTemplateParameters.GalasaVersion = galasaVersion - err := fileGenerator.CreateFile(targetFile, forceOverwrite, true) + targetFile := utils.GeneratedFileDef{ + FileType: "gradle", + TargetFilePath: targetOBRFolderPath + "/build.gradle", + EmbeddedTemplateFilePath: "templates/projectCreate/parent-project/obr-project/build.gradle.template", + TemplateParameters: buildGradleTemplateParameters} + + err = fileGenerator.CreateFile(targetFile, forceOverwrite, true) + } return err } diff --git a/pkg/cmd/projectCreate_test.go b/pkg/cmd/projectCreate_test.go index 7675125e..c708a7db 100644 --- a/pkg/cmd/projectCreate_test.go +++ b/pkg/cmd/projectCreate_test.go @@ -8,6 +8,7 @@ package cmd import ( "errors" "fmt" + "regexp" "strings" "testing" @@ -323,10 +324,10 @@ func TestCanCreateProjectGoldenPathWithOBR(t *testing.T) { assertParentFolderAndContentsCreated(t, mockFileSystem, isObrProjectRequired, maven, gradle, packageName) assertTestFolderAndContentsCreatedOk(t, mockFileSystem, "test", maven, gradle) - assertOBRFOlderAndContentsCreatedOK(t, mockFileSystem, maven, gradle) + assertOBRFolderAndContentsCreatedOK(t, mockFileSystem, maven, gradle) } -func assertOBRFOlderAndContentsCreatedOK(t *testing.T, mockFileSystem spi.FileSystem, isMaven bool, isGradle bool) { +func assertOBRFolderAndContentsCreatedOK(t *testing.T, mockFileSystem spi.FileSystem, isMaven bool, isGradle bool) { testFolderExists, err := mockFileSystem.DirExists("my.test.pkg/my.test.pkg.obr") assert.Nil(t, err) assert.True(t, testFolderExists, "Test folder was not created.") @@ -352,7 +353,39 @@ func assertOBRFOlderAndContentsCreatedOK(t *testing.T, mockFileSystem spi.FileSy text, err := mockFileSystem.ReadTextFile(expectedBuildGradleFilePath) assert.Nil(t, err) assert.Contains(t, text, "group = 'my.test.pkg'", "Test folder build.gradle didn't substitute the group id") + + var line string + line, err = findLineContaining(text, "dev.galasa.obr") + assert.Nil(t, err) + + pattern := ".*version '(.*)'$" + galasaObrLineRegex, err := regexp.Compile(pattern) + assert.Nil(t, err) + + match := galasaObrLineRegex.FindStringSubmatch(line) + assert.NotNil(t, match, "No line declaring dev.galasa.obr line version") + assert.Equal(t, len(match), 2, "Failed to find more that 0 matches") + assert.NotEmpty(t, match[1]) + + } +} + +func findLineContaining(text string, textToFindOnLine string) (string, error) { + textLines := strings.Split(text, "\n") + lineMatching := "" + isMatched := false + var err error + for _, line := range textLines { + if strings.Contains(line, textToFindOnLine) { + lineMatching = line + isMatched = true + } + } + + if !isMatched { + err = errors.New("Failed to find string " + textToFindOnLine) } + return lineMatching, err } func TestCreateProjectWithTwoFeaturesWorks(t *testing.T) { @@ -457,7 +490,7 @@ func TestCanCreateGradleProjectWithOBR(t *testing.T) { assertParentFolderAndContentsCreated(t, mockFileSystem, isObrProjectRequired, maven, gradle, packageName) assertTestFolderAndContentsCreatedOk(t, mockFileSystem, "test", maven, gradle) - assertOBRFOlderAndContentsCreatedOK(t, mockFileSystem, maven, gradle) + assertOBRFolderAndContentsCreatedOK(t, mockFileSystem, maven, gradle) } func TestCanCreateMavenAndGradleProject(t *testing.T) { diff --git a/pkg/embedded/templates/projectCreate/parent-project/obr-project/build.gradle.template b/pkg/embedded/templates/projectCreate/parent-project/obr-project/build.gradle.template index 04d5a6f7..7cd1cf8e 100644 --- a/pkg/embedded/templates/projectCreate/parent-project/obr-project/build.gradle.template +++ b/pkg/embedded/templates/projectCreate/parent-project/obr-project/build.gradle.template @@ -1,9 +1,19 @@ +{{/* + This template expects the following parameters: + + type OBRGradleParameters struct { + Parent GradleCoordinates + Coordinates GradleCoordinates + Modules []GradleCoordinates + GalasaVersion string + } +*/}} // This section tells gradle which gradle plugins to use to build this project. plugins { id 'base' id 'maven-publish' - id 'dev.galasa.obr' version '0.36.0' - id 'dev.galasa.testcatalog' version '0.36.0' + id 'dev.galasa.obr' version '{{.GalasaVersion}}' + id 'dev.galasa.testcatalog' version '{{.GalasaVersion}}' } // Set the variables which will control what the built OSGi bundle will be called diff --git a/pkg/embedded/templates/projectCreate/parent-project/pom.xml b/pkg/embedded/templates/projectCreate/parent-project/pom.xml index 9f6c1c24..47ac9e93 100644 --- a/pkg/embedded/templates/projectCreate/parent-project/pom.xml +++ b/pkg/embedded/templates/projectCreate/parent-project/pom.xml @@ -122,7 +122,7 @@ dev.galasa galasa-maven-plugin - 0.34.0 + {{.GalasaVersion}} diff --git a/pkg/embedded/templates/projectCreate/parent-project/test-project/build.gradle.template b/pkg/embedded/templates/projectCreate/parent-project/test-project/build.gradle.template index eb70aea3..cc2bf42b 100644 --- a/pkg/embedded/templates/projectCreate/parent-project/test-project/build.gradle.template +++ b/pkg/embedded/templates/projectCreate/parent-project/test-project/build.gradle.template @@ -1,9 +1,23 @@ +{{/* + This template expects the following parameters: + type ParentPomParameters struct { + Coordinates MavenCoordinates + + // Version of Galasa we are targetting + GalasaVersion string + + IsOBRRequired bool + ObrName string + ChildModuleNames []string + IsDevelopment bool + } +*/}} // This section tells gradle which gradle plugins to use to build this project. plugins { id 'java' id 'maven-publish' - id 'dev.galasa.tests' version '0.36.0' + id 'dev.galasa.tests' version '{{.GalasaVersion}}' id 'biz.aQute.bnd.builder' version '6.4.0' } diff --git a/set-version.sh b/set-version.sh index 764f2082..1a14970a 100755 --- a/set-version.sh +++ b/set-version.sh @@ -24,7 +24,6 @@ export ORIGINAL_DIR=$(pwd) cd "${BASEDIR}/.." WORKSPACE_DIR=$(pwd) - #----------------------------------------------------------------------------------------- # # Set Colors @@ -110,7 +109,10 @@ function update_gradle_version { info "Using temporary file $temp_file" info "Updating file $source_file" - cat $source_file | sed "s/galasaFrameworkVersion[ ]*=.*$/galasaFrameworkVersion = '$component_version'/1" > $temp_file + cat $source_file \ + | sed "s/galasaFrameworkVersion[ ]*=.*$/galasaFrameworkVersion = '$component_version'/1" \ + | sed "s/galasaBootJarVersion[ ]*=.*$/galasaBootJarVersion = '$component_version'/1" \ + > $temp_file rc=$?; if [[ "${rc}" != "0" ]]; then error "Failed to set version into $source_file file."; exit 1; fi cp $temp_file ${source_file} rc=$?; if [[ "${rc}" != "0" ]]; then error "Failed to overwrite new version of $source_file file."; exit 1; fi