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

CLI create project --manager creates a manager module #256

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from 3 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
107 changes: 99 additions & 8 deletions pkg/cmd/projectCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ProjectCreateCmdValues struct {
force bool
isOBRProjectRequired bool
featureNamesCommaSeparated string
manager string
useMaven bool
useGradle bool
isDevelopmentProjectCreate bool
Expand Down Expand Up @@ -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\"")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -201,6 +204,7 @@ func createProject(
fileSystem spi.FileSystem,
packageName string,
featureNamesCommaSeparated string,
manager string,
isOBRProjectRequired bool,
forceOverwrite bool,
useMaven bool,
Expand Down Expand Up @@ -235,16 +239,16 @@ func createProject(

if err == nil {
err = createParentFolderContents(
fileGenerator, packageName, featureNames, isOBRProjectRequired,
fileGenerator, packageName, manager, featureNames, isOBRProjectRequired,
forceOverwrite, useMaven, useGradle, isDevelopment)
}

if err == nil {
err = createTestProjects(fileGenerator, packageName, featureNames, forceOverwrite,
err = createTestProjects(fileGenerator, packageName, featureNames, manager, forceOverwrite,
useMaven, useGradle, isDevelopment)
if err == nil {
if isOBRProjectRequired {
err = createOBRProject(fileGenerator, packageName, featureNames,
err = createOBRProject(fileGenerator, packageName, manager, featureNames,
forceOverwrite, useMaven, useGradle)
}
}
Expand All @@ -259,6 +263,7 @@ func createProject(
func createParentFolderContents(
fileGenerator *utils.FileGenerator,
packageName string,
manager string,
featureNames []string,
isOBRProjectRequired bool,
forceOverwrite bool,
Expand All @@ -268,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)
}
}

Expand Down Expand Up @@ -433,6 +440,7 @@ func createTestProjects(
fileGenerator *utils.FileGenerator,
packageName string,
featureNames []string,
manager string,
forceOverwrite bool,
useMaven bool,
useGradle bool,
Expand All @@ -446,6 +454,7 @@ func createTestProjects(
break
}
}
err = createTestManager(fileGenerator, packageName, manager, forceOverwrite, useMaven, useGradle, isDevelopment)
return err
}

Expand Down Expand Up @@ -489,9 +498,47 @@ func createTestProject(
return err
}

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)
techcobweb marked this conversation as resolved.
Show resolved Hide resolved
}

if useGradle {
err = createTestFolderGradle(fileGenerator, targetFolderPath, packageName, manager, forceOverwrite, isDevelopment)
}
}

if err == nil {
err = createJavaSourceFolder(fileGenerator, targetFolderPath, packageName, manager, forceOverwrite)
aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved
}

err = createTestResourceFolder(fileGenerator, targetFolderPath, forceOverwrite)

if err == nil {
log.Printf("Manager project %s created OK.", targetFolderPath)
}
return err
}

func createOBRProject(
fileGenerator *utils.FileGenerator,
packageName string,
manager string,
featureNames []string,
forceOverwrite bool,
useMaven bool,
Expand All @@ -500,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)
}
}

Expand Down Expand Up @@ -660,6 +709,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 createManagerFolder(fileGenerator *utils.FileGenerator, targetTestFolderPath string,
aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved
packageName string, featureName string, forceOverwrite bool, isDevelopment bool) error {

aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved
type TestGradleParameters struct {
aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved
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",
aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand Down