From 63c6399554a6321ad13b7cff3bc3a7bd2ecf4412 Mon Sep 17 00:00:00 2001 From: aadityasinha-dotcom Date: Tue, 2 Jul 2024 18:28:32 +0530 Subject: [PATCH 1/4] added project --manager module Signed-off-by: aadityasinha-dotcom --- pkg/cmd/projectCreate.go | 88 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/projectCreate.go b/pkg/cmd/projectCreate.go index 3ed66944..956a2e80 100644 --- a/pkg/cmd/projectCreate.go +++ b/pkg/cmd/projectCreate.go @@ -38,6 +38,7 @@ type ProjectCreateCmdValues struct { force bool isOBRProjectRequired bool featureNamesCommaSeparated string + manager string useMaven bool useGradle bool isDevelopmentProjectCreate bool @@ -118,7 +119,8 @@ func (cmd *ProjectCreateCommand) createCobraCommand( projectCreateCmd.Flags().BoolVar(&cmd.values.force, "force", false, "Force-overwrite files which already exist.") projectCreateCmd.Flags().BoolVar(&cmd.values.isOBRProjectRequired, "obr", false, "An OSGi Object Bundle Resource (OBR) project is needed.") - projectCreateCmd.Flags().StringVar(&cmd.values.featureNamesCommaSeparated, "features", "feature1", + projectCreateCmd.Flags().StringVar(&cmd.values.manager, "manager", "", "manager to create manager") + projectCreateCmd.Flags().StringVar(&cmd.values.featureNamesCommaSeparated, "features", "feature1", "A comma-separated list of features you are testing. "+ "These must be able to form parts of a java package name. "+ "For example: \"payee,account\"") @@ -151,6 +153,7 @@ func (cmd *ProjectCreateCommand) executeCreateProject(factory spi.Factory, rootC err = createProject(fileSystem, cmd.values.packageName, cmd.values.featureNamesCommaSeparated, + cmd.values.manager, cmd.values.isOBRProjectRequired, cmd.values.force, cmd.values.useMaven, @@ -201,6 +204,7 @@ func createProject( fileSystem spi.FileSystem, packageName string, featureNamesCommaSeparated string, + manager string, isOBRProjectRequired bool, forceOverwrite bool, useMaven bool, @@ -208,7 +212,7 @@ func createProject( isDevelopment bool, ) error { - log.Printf("Creating project using packageName:%s\n", packageName) + log.Printf("Hello my name Creating project using packageName:%s\n", packageName) var err error @@ -240,7 +244,7 @@ func createProject( } if err == nil { - err = createTestProjects(fileGenerator, packageName, featureNames, forceOverwrite, + err = createTestProjects(fileGenerator, packageName, featureNames, manager, forceOverwrite, useMaven, useGradle, isDevelopment) if err == nil { if isOBRProjectRequired { @@ -433,6 +437,7 @@ func createTestProjects( fileGenerator *utils.FileGenerator, packageName string, featureNames []string, + manager string, forceOverwrite bool, useMaven bool, useGradle bool, @@ -446,6 +451,7 @@ func createTestProjects( break } } + err = createTestManager(fileGenerator, packageName, manager, forceOverwrite, useMaven, useGradle, isDevelopment) return err } @@ -489,6 +495,40 @@ func createTestProject( return err } +// createTestProject - creates a single project to contain tests which test a feature. +func createTestManager( + fileGenerator *utils.FileGenerator, + packageName string, + manager string, + forceOverwrite bool, + useMaven bool, + useGradle bool, + isDevelopment bool, +) error { + + targetFolderPath := packageName + "/" + packageName + "." + manager + log.Printf("Creating tests project %s\n", targetFolderPath) + + // Create the base test folder + err := fileGenerator.CreateFolder(targetFolderPath) + if err == nil { + if useMaven { + err = createTestFolderPom(fileGenerator, targetFolderPath, packageName, manager, forceOverwrite) + } + + err = createTestFolderGradle(fileGenerator, targetFolderPath, packageName, manager, forceOverwrite, isDevelopment) + } + + err = createJavaSourceFolder(fileGenerator, targetFolderPath, packageName, manager, forceOverwrite) + + err = createTestResourceFolder(fileGenerator, targetFolderPath, forceOverwrite) + + if err == nil { + log.Printf("Tests project %s created OK.", targetFolderPath) + } + return err +} + func createOBRProject( fileGenerator *utils.FileGenerator, packageName string, @@ -660,6 +700,48 @@ func createTestFolderGradle(fileGenerator *utils.FileGenerator, targetTestFolder return err } +// Creates a build.gradle and a bnd.bnd file in a Gradle test project directory. +func createTestFolderManager(fileGenerator *utils.FileGenerator, targetTestFolderPath string, + packageName string, featureName string, forceOverwrite bool, isDevelopment bool) error { + + type TestGradleParameters struct { + Parent GradleCoordinates + Coordinates GradleCoordinates + // Version of Galasa we are targetting + GalasaVersion string + IsDevelopment bool + } + + galasaVersion, err := embedded.GetGalasaVersion() + + if err == nil { + gradleProjectTemplateParameters := TestGradleParameters{ + Parent: GradleCoordinates{GroupId: packageName, Name: packageName}, + Coordinates: GradleCoordinates{GroupId: packageName, Name: packageName + "." + featureName}, + GalasaVersion: galasaVersion, + IsDevelopment: isDevelopment} + + buildGradleFile := utils.GeneratedFileDef{ + FileType: "gradle", + TargetFilePath: targetTestFolderPath + "/build.gradle", + EmbeddedTemplateFilePath: "templates/projectCreate/parent-project/test-project/build.gradle.template", + TemplateParameters: gradleProjectTemplateParameters} + + err = fileGenerator.CreateFile(buildGradleFile, forceOverwrite, true) + + if err == nil { + bndFile := utils.GeneratedFileDef{ + FileType: "bnd", + TargetFilePath: targetTestFolderPath + "/bnd.bnd", + EmbeddedTemplateFilePath: "templates/projectCreate/parent-project/test-project/bnd.bnd", + TemplateParameters: gradleProjectTemplateParameters} + err = fileGenerator.CreateFile(bndFile, forceOverwrite, true) + } + } + + return err +} + // Creates a pom.xml file in an OBR project directory. func createOBRFolderPom(fileGenerator *utils.FileGenerator, targetOBRFolderPath string, packageName string, featureNames []string, forceOverwrite bool) error { From d40d7337d6f0eda15e596fdbfd10ad2e3e3f0fd3 Mon Sep 17 00:00:00 2001 From: aadityasinha-dotcom Date: Fri, 12 Jul 2024 23:04:15 +0530 Subject: [PATCH 2/4] changes according to the review Signed-off-by: aadityasinha-dotcom --- pkg/cmd/projectCreate.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/projectCreate.go b/pkg/cmd/projectCreate.go index 956a2e80..ed06f68e 100644 --- a/pkg/cmd/projectCreate.go +++ b/pkg/cmd/projectCreate.go @@ -212,7 +212,7 @@ func createProject( isDevelopment bool, ) error { - log.Printf("Hello my name Creating project using packageName:%s\n", packageName) + log.Printf("Creating project using packageName:%s\n", packageName) var err error @@ -495,7 +495,6 @@ func createTestProject( return err } -// createTestProject - creates a single project to contain tests which test a feature. func createTestManager( fileGenerator *utils.FileGenerator, packageName string, @@ -515,16 +514,20 @@ func createTestManager( if useMaven { err = createTestFolderPom(fileGenerator, targetFolderPath, packageName, manager, forceOverwrite) } - - err = createTestFolderGradle(fileGenerator, targetFolderPath, packageName, manager, forceOverwrite, isDevelopment) + + if useGradle { + err = createTestFolderGradle(fileGenerator, targetFolderPath, packageName, manager, forceOverwrite, isDevelopment) + } } - - err = createJavaSourceFolder(fileGenerator, targetFolderPath, packageName, manager, forceOverwrite) + + if err == nil { + err = createJavaSourceFolder(fileGenerator, targetFolderPath, packageName, manager, forceOverwrite) + } err = createTestResourceFolder(fileGenerator, targetFolderPath, forceOverwrite) if err == nil { - log.Printf("Tests project %s created OK.", targetFolderPath) + log.Printf("Manager project %s created OK.", targetFolderPath) } return err } @@ -701,7 +704,7 @@ func createTestFolderGradle(fileGenerator *utils.FileGenerator, targetTestFolder } // Creates a build.gradle and a bnd.bnd file in a Gradle test project directory. -func createTestFolderManager(fileGenerator *utils.FileGenerator, targetTestFolderPath string, +func createManagerFolder(fileGenerator *utils.FileGenerator, targetTestFolderPath string, packageName string, featureName string, forceOverwrite bool, isDevelopment bool) error { type TestGradleParameters struct { From d0d32307e1abc2ca25eaa46e7eb5fdcbf445a74b Mon Sep 17 00:00:00 2001 From: aadityasinha-dotcom Date: Tue, 23 Jul 2024 14:30:08 +0530 Subject: [PATCH 3/4] added changes to obr and gradle file with structuring the parents folder Signed-off-by: aadityasinha-dotcom --- pkg/cmd/projectCreate.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/cmd/projectCreate.go b/pkg/cmd/projectCreate.go index ed06f68e..8a5aec5b 100644 --- a/pkg/cmd/projectCreate.go +++ b/pkg/cmd/projectCreate.go @@ -239,7 +239,7 @@ func createProject( if err == nil { err = createParentFolderContents( - fileGenerator, packageName, featureNames, isOBRProjectRequired, + fileGenerator, packageName, manager, featureNames, isOBRProjectRequired, forceOverwrite, useMaven, useGradle, isDevelopment) } @@ -248,7 +248,7 @@ func createProject( useMaven, useGradle, isDevelopment) if err == nil { if isOBRProjectRequired { - err = createOBRProject(fileGenerator, packageName, featureNames, + err = createOBRProject(fileGenerator, packageName, manager, featureNames, forceOverwrite, useMaven, useGradle) } } @@ -263,6 +263,7 @@ func createProject( func createParentFolderContents( fileGenerator *utils.FileGenerator, packageName string, + manager string, featureNames []string, isOBRProjectRequired bool, forceOverwrite bool, @@ -272,15 +273,17 @@ func createParentFolderContents( ) error { var err error + features := append(featureNames, manager) + if useMaven { - err = createParentFolderPom(fileGenerator, packageName, featureNames, + err = createParentFolderPom(fileGenerator, packageName, features, isOBRProjectRequired, forceOverwrite, isDevelopment) } if err == nil { if useGradle { err = createParentFolderSettingsGradle(fileGenerator, packageName, - featureNames, isOBRProjectRequired, forceOverwrite, isDevelopment) + features, isOBRProjectRequired, forceOverwrite, isDevelopment) } } @@ -535,6 +538,7 @@ func createTestManager( func createOBRProject( fileGenerator *utils.FileGenerator, packageName string, + manager string, featureNames []string, forceOverwrite bool, useMaven bool, @@ -543,15 +547,17 @@ func createOBRProject( targetFolderPath := packageName + "/" + packageName + ".obr" log.Printf("Creating obr project %s\n", targetFolderPath) + features := append(featureNames, manager) + // Create the base test folder err := fileGenerator.CreateFolder(targetFolderPath) if err == nil { if useMaven { - err = createOBRFolderPom(fileGenerator, targetFolderPath, packageName, featureNames, forceOverwrite) + err = createOBRFolderPom(fileGenerator, targetFolderPath, packageName, features, forceOverwrite) } if useGradle { - err = createOBRFolderBuildGradle(fileGenerator, targetFolderPath, packageName, featureNames, forceOverwrite) + err = createOBRFolderBuildGradle(fileGenerator, targetFolderPath, packageName, features, forceOverwrite) } } From a7442fee7b3e3e286b79860fc22be7c20d3d783c Mon Sep 17 00:00:00 2001 From: aadityasinha-dotcom Date: Fri, 26 Jul 2024 12:27:22 +0530 Subject: [PATCH 4/4] few changes Signed-off-by: aadityasinha-dotcom --- pkg/cmd/projectCreate.go | 46 +++------------------------------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/pkg/cmd/projectCreate.go b/pkg/cmd/projectCreate.go index 8a5aec5b..f6bab795 100644 --- a/pkg/cmd/projectCreate.go +++ b/pkg/cmd/projectCreate.go @@ -527,7 +527,9 @@ func createTestManager( err = createJavaSourceFolder(fileGenerator, targetFolderPath, packageName, manager, forceOverwrite) } - err = createTestResourceFolder(fileGenerator, targetFolderPath, forceOverwrite) + if err == nil{ + err = createTestResourceFolder(fileGenerator, targetFolderPath, forceOverwrite) + } if err == nil { log.Printf("Manager project %s created OK.", targetFolderPath) @@ -709,48 +711,6 @@ func createTestFolderGradle(fileGenerator *utils.FileGenerator, targetTestFolder return err } -// Creates a build.gradle and a bnd.bnd file in a Gradle test project directory. -func createManagerFolder(fileGenerator *utils.FileGenerator, targetTestFolderPath string, - packageName string, featureName string, forceOverwrite bool, isDevelopment bool) error { - - type TestGradleParameters struct { - Parent GradleCoordinates - Coordinates GradleCoordinates - // Version of Galasa we are targetting - GalasaVersion string - IsDevelopment bool - } - - galasaVersion, err := embedded.GetGalasaVersion() - - if err == nil { - gradleProjectTemplateParameters := TestGradleParameters{ - Parent: GradleCoordinates{GroupId: packageName, Name: packageName}, - Coordinates: GradleCoordinates{GroupId: packageName, Name: packageName + "." + featureName}, - GalasaVersion: galasaVersion, - IsDevelopment: isDevelopment} - - buildGradleFile := utils.GeneratedFileDef{ - FileType: "gradle", - TargetFilePath: targetTestFolderPath + "/build.gradle", - EmbeddedTemplateFilePath: "templates/projectCreate/parent-project/test-project/build.gradle.template", - TemplateParameters: gradleProjectTemplateParameters} - - err = fileGenerator.CreateFile(buildGradleFile, forceOverwrite, true) - - if err == nil { - bndFile := utils.GeneratedFileDef{ - FileType: "bnd", - TargetFilePath: targetTestFolderPath + "/bnd.bnd", - EmbeddedTemplateFilePath: "templates/projectCreate/parent-project/test-project/bnd.bnd", - TemplateParameters: gradleProjectTemplateParameters} - err = fileGenerator.CreateFile(bndFile, forceOverwrite, true) - } - } - - return err -} - // Creates a pom.xml file in an OBR project directory. func createOBRFolderPom(fileGenerator *utils.FileGenerator, targetOBRFolderPath string, packageName string, featureNames []string, forceOverwrite bool) error {