diff --git a/cmd/gen.go b/cmd/gen.go index 0edaad36e..f4b6a4893 100644 --- a/cmd/gen.go +++ b/cmd/gen.go @@ -32,7 +32,8 @@ func init() { "the path to the MTA project; the current path is default") mtadCmd.Flags().StringVarP(&mtadCmdTrg, "target", "t", "", "the path to the MBT results folder; the current path is default") - mtadCmd.Flags().StringVarP(&mtadCmdPlatform, "platform", "p", "", "Provide MTA platform ") + mtadCmd.Flags().StringVarP(&mtadCmdPlatform, "platform", "p", "cf", + "the deployment platform; supported plaforms: cf (default), xsa, neo") // set flags of meta command metaCmd.Flags().StringVarP(&metaCmdSrc, "source", "s", "", @@ -41,8 +42,8 @@ func init() { "the path to the MBT results folder; the current path is default") metaCmd.Flags().StringVarP(&metaCmdDesc, "desc", "d", "", "the MTA descriptor; supported values: dev (development descriptor, default value) and dep (deployment descriptor)") - metaCmd.Flags().StringVarP(&metaCmdPlatform, "platform", "p", "", - "the deployment platform; supported plaforms: cf, xsa") + metaCmd.Flags().StringVarP(&metaCmdPlatform, "platform", "p", "cf", + "the deployment platform; supported plaforms: cf (default), xsa, neo") // set flags of mtar command mtarCmd.Flags().StringVarP(&mtarCmdSrc, "source", "s", "", diff --git a/cmd/module.go b/cmd/module.go index 2ee823612..077edb70b 100644 --- a/cmd/module.go +++ b/cmd/module.go @@ -34,7 +34,7 @@ func init() { packModuleCmd.Flags().StringVarP(&packCmdModule, "module", "m", "", "the name of the module") packModuleCmd.Flags().StringVarP(&packCmdPlatform, "platform", "p", "", - "the deployment platform; supported plaforms: cf, xsa") + "the deployment platform; supported plaforms: cf, xsa, neo") // set flags of command build Module buildModuleCmd.Flags().StringVarP(&buildCmdSrc, "source", "s", "", @@ -46,7 +46,7 @@ func init() { buildModuleCmd.Flags().StringVarP(&buildCmdModule, "module", "m", "", "the name of the module") buildModuleCmd.Flags().StringVarP(&buildCmdPlatform, "platform", "p", "", - "the deployment platform; supported plaforms: cf, xsa") + "the deployment platform; supported plaforms: cf, xsa, neo") } // buildModuleCmd - Build module diff --git a/internal/artifacts/meta.go b/internal/artifacts/meta.go index a056c9c7d..3723f95d7 100644 --- a/internal/artifacts/meta.go +++ b/internal/artifacts/meta.go @@ -53,6 +53,7 @@ func generateMeta(parser dir.IMtaParser, ep dir.ITargetArtifacts, targetPathGett // GenMetaInfo generates a MANIFEST.MF file and updates the build artifacts paths for deployment purposes. func GenMetaInfo(ep dir.ITargetArtifacts, targetPathGetter dir.ITargetPath, deploymentDesc bool, platform string, mtaStr *mta.MTA, modules []string, onlyModules bool) (rerr error) { + err := genMtad(mtaStr, ep, deploymentDesc, platform, yaml.Marshal) if err != nil { return errors.Wrap(err, "generation of metadata failed when generating the MTAD file") diff --git a/internal/artifacts/mtad.go b/internal/artifacts/mtad.go index 151a26261..b3574655b 100644 --- a/internal/artifacts/mtad.go +++ b/internal/artifacts/mtad.go @@ -1,18 +1,19 @@ package artifacts import ( + "fmt" + "gopkg.in/yaml.v2" "io/ioutil" "os" + "path/filepath" "github.com/pkg/errors" - "gopkg.in/yaml.v2" + + "github.com/SAP/cloud-mta/mta" "github.com/SAP/cloud-mta-build-tool/internal/buildops" "github.com/SAP/cloud-mta-build-tool/internal/fs" "github.com/SAP/cloud-mta-build-tool/internal/logs" - - "github.com/SAP/cloud-mta/mta" - "path/filepath" ) type mtadLoc struct { @@ -43,33 +44,56 @@ func ExecuteGenMtad(source, target, platform string, wdGetter func() (string, er return errors.Wrap(err, "generation of the MTAD file failed when initializing the location") } + // get mta object mtaStr, err := loc.ParseFile() if err != nil { return errors.Wrapf(err, `generation of the MTAD file failed when parsing the "%v" file`, loc.GetMtaYamlFilename()) } + // get extension object if defined mtaExt, err := loc.ParseExtFile(platform) if err != nil { return errors.Wrapf(err, `generation of the MTAD file failed when parsing the "%v" file`, loc.GetMtaExtYamlPath(platform)) } + // merge mta and extension objects mta.Merge(mtaStr, mtaExt) + // init mtad object from the extended mta adaptMtadForDeployment(mtaStr, platform) return genMtad(mtaStr, &mtadLoc{target}, false, platform, yaml.Marshal) } +func validatePlatform(platform string) error { + if platform != "xsa" && platform != "cf" && platform != "neo" { + return fmt.Errorf("the %s deployment platform is not supported; supported values: cf, xsa, neo", platform) + } + return nil +} + // genMtad generates an mtad.yaml file from a mta.yaml file and a platform configuration file. func genMtad(mtaStr *mta.MTA, ep dir.ITargetArtifacts, deploymentDesc bool, platform string, marshal func(interface{}) (out []byte, err error)) error { + + // validate platform + err := validatePlatform(platform) + if err != nil { + return err + } + // Create META-INF folder under the mtar folder metaPath := ep.GetMetaPath() - err := dir.CreateDirIfNotExist(metaPath) - if err != nil { - logs.Logger.Infof(`the "%v" folder already exists`, metaPath) + + // if meta folder provided, mtad will be saved in this folder, so we create it if not exists + if metaPath != "" { + err := dir.CreateDirIfNotExist(metaPath) + if err != nil { + logs.Logger.Infof(`the "%v" folder already exists`, metaPath) + } } if !deploymentDesc { - err = ConvertTypes(*mtaStr, platform) + // convert modules types according to platform + err := ConvertTypes(*mtaStr, platform) if err != nil { return errors.Wrapf(err, `generation of the MTAD file failed when converting types according to the "%v" platform`, diff --git a/internal/artifacts/mtad_test.go b/internal/artifacts/mtad_test.go index 6b5c099bf..5c77b5215 100644 --- a/internal/artifacts/mtad_test.go +++ b/internal/artifacts/mtad_test.go @@ -34,6 +34,11 @@ var _ = Describe("Mtad", func() { return "", errors.New("err") })).Should(HaveOccurred()) }) + It("Fails on platform validation", func() { + Ω(ExecuteGenMtad(getTestPath("mta"), getTestPath("resultMtad"), "ab", func() (string, error) { + return "", errors.New("err") + })).Should(HaveOccurred()) + }) It("Fails on wrong source path - parse fails", func() { Ω(ExecuteGenMtad(getTestPath("mtax"), getTestPath("resultMtad"), "cf", os.Getwd)).Should(HaveOccurred()) }) @@ -116,3 +121,14 @@ var _ = Describe("adaptMtadForDeployment", func() { Ω(mta.Parameters["hcp-deployer-version"]).ShouldNot(BeNil()) }) }) + +var _ = Describe("mtadLoc", func() { + It("GetManifestPath", func() { + loc := mtadLoc{"anyPath"} + Ω(loc.GetManifestPath()).Should(Equal("")) + }) + It("GetMtarDir", func() { + loc := mtadLoc{"anyPath"} + Ω(loc.GetMtarDir()).Should(Equal("")) + }) +})