Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set-version.sh should set version of boot jar also #308

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions pkg/cmd/projectCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
39 changes: 36 additions & 3 deletions pkg/cmd/projectCreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package cmd
import (
"errors"
"fmt"
"regexp"
"strings"
"testing"

Expand Down Expand Up @@ -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.")
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<plugin>
<groupId>dev.galasa</groupId>
<artifactId>galasa-maven-plugin</artifactId>
<version>0.34.0</version>
<version>{{.GalasaVersion}}</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
}

Expand Down
6 changes: 4 additions & 2 deletions set-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export ORIGINAL_DIR=$(pwd)
cd "${BASEDIR}/.."
WORKSPACE_DIR=$(pwd)


#-----------------------------------------------------------------------------------------
#
# Set Colors
Expand Down Expand Up @@ -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
Expand Down