Skip to content

Commit

Permalink
mtar configuring added to assemble command
Browse files Browse the repository at this point in the history
  • Loading branch information
allaVolkov committed Feb 25, 2019
1 parent 166d5e7 commit e0d0f4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions cmd/assembly.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package commands

import (
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/SAP/cloud-mta-build-tool/internal/archive"
"github.com/SAP/cloud-mta-build-tool/internal/artifacts"
"github.com/SAP/cloud-mta-build-tool/internal/logs"
"strconv"
"os"
)

const (
Expand All @@ -18,12 +17,15 @@ const (

var assembleCmdSrc string
var assembleCmdTrg string
var assembleCmdMtarName string

func init() {
assemblyCommand.Flags().StringVarP(&assembleCmdSrc,
"source", "s", "", "the path to the MTA project; the current path is default")
assemblyCommand.Flags().StringVarP(&assembleCmdTrg,
"target", "t", "", "the path to the MBT results folder; the current path is default")
assemblyCommand.Flags().StringVarP(&assembleCmdMtarName,
"mtar", "m", "", "the archive name")
}

// Generate mtar from build artifacts
Expand All @@ -34,15 +36,15 @@ var assemblyCommand = &cobra.Command{
ValidArgs: []string{"Deployment descriptor location"},
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
err := assembly(assembleCmdSrc, assembleCmdTrg, defaultPlatform, os.Getwd)
err := assembly(assembleCmdSrc, assembleCmdTrg, defaultPlatform, mtarCmdMtarName, os.Getwd)
logError(err)
return err
},
SilenceUsage: true,
SilenceErrors: true,
}

func assembly(source, target, platform string, getWd func() (string, error)) error {
func assembly(source, target, platform, mtarName string, getWd func() (string, error)) error {
logs.Logger.Info("assembling the MTA project...")
// copy from source to target
err := artifacts.CopyMtaContent(source, target, dir.Dep, getWd)
Expand All @@ -55,7 +57,7 @@ func assembly(source, target, platform string, getWd func() (string, error)) err
return errors.Wrap(err, "assembly of the MTA project failed when generating the meta information")
}
// generate mtar
err = artifacts.ExecuteGenMtar(source, target, strconv.FormatBool(target != ""), dir.Dep, "", getWd)
err = artifacts.ExecuteGenMtar(source, target, strconv.FormatBool(target != ""), dir.Dep, mtarName, getWd)
if err != nil {
return errors.Wrap(err, "assembly of the MTA project failed when generating the MTA archive")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/assembly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ var _ = Describe("Assembly", func() {
})
It("Sanity", func() {
err := assembly(getTestPath("assembly-sample"),
getTestPath("result"), "cf", os.Getwd)
getTestPath("result"), "cf", "", os.Getwd)
Ω(err).Should(Succeed())
Ω(getTestPath("result", "com.sap.xs2.samples.javahelloworld_0.1.0.mtar")).Should(BeAnExistingFile())
})
var _ = DescribeTable("Fails on location initialization", func(maxCalls int) {
calls := 0
err := assembly("",
getTestPath("result"), "cf", func() (string, error) {
getTestPath("result"), "cf", "", func() (string, error) {
calls++
if calls >= maxCalls {
return "", errors.New("error")
Expand Down

0 comments on commit e0d0f4e

Please sign in to comment.