Skip to content

Commit

Permalink
Merge pull request #258 from SAP/mtar_folder
Browse files Browse the repository at this point in the history
 use mta_archive subfolder only if target equals source
  • Loading branch information
ShimiT authored Feb 21, 2019
2 parents 8e76f33 + 52addef commit e7e341e
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/assembly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _ = Describe("Assembly", func() {
err := assembly(getTestPath("assembly-sample"),
getTestPath("result"), "cf", os.Getwd)
Ω(err).Should(Succeed())
Ω(getTestPath("result", "mta_archives", "com.sap.xs2.samples.javahelloworld_0.1.0.mtar")).Should(BeAnExistingFile())
Ω(getTestPath("result", "com.sap.xs2.samples.javahelloworld_0.1.0.mtar")).Should(BeAnExistingFile())
})
var _ = DescribeTable("Fails on location initialization", func(maxCalls int) {
calls := 0
Expand Down
2 changes: 1 addition & 1 deletion cmd/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var _ = Describe("Commands", func() {
mtarCmdSrc = getTestPath("mtahtml5")
Ω(metaCmd.RunE(nil, []string{})).Should(Succeed())
Ω(mtarCmd.RunE(nil, []string{})).Should(Succeed())
Ω(getTestPath("result", "mta_archives", "mtahtml5_0.0.1.mtar")).Should(BeAnExistingFile())
Ω(getTestPath("result", "mtahtml5_0.0.1.mtar")).Should(BeAnExistingFile())
})
})

Expand Down
6 changes: 5 additions & 1 deletion internal/artifacts/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ cli_version:["x"]
if err != nil {
fmt.Println(err)
}
mtarPath, err := generateMtar(&ep, &ep)
mtarPath, err := generateMtar(&ep, &ep, &ep)
if err != nil {
fmt.Println(err)
}
Expand All @@ -168,3 +168,7 @@ func (loc *testLoc) GetMtadPath() string {
func (loc *testLoc) GetManifestPath() string {
return filepath.Join(loc.loc.GetManifestPath(), "folderNotExists", "MANIFEST.MF")
}

func (loc *testLoc) GetMtarDir() string {
return loc.GetMtarDir()
}
9 changes: 9 additions & 0 deletions internal/artifacts/module_arch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ module-types:
})
})

var _ = Describe("copyMtaContentFromPath", func() {
It("content is file; fails because target folder exists and it's not a folder, but a file", func() {
file, _ := os.Create(getTestPath("result"))
defer file.Close()
Ω(copyMtaContentFromPath(getTestPath("mta", "mta.yaml"), getTestPath("result", "mta.yaml"),
getTestPath("result", "mta.yaml"), getTestPath("result"))).Should(HaveOccurred())
})
})

var _ = Describe("cleanUpCopiedContent", func() {
It("Sanity", func() {
err := cleanUpCopiedContent(getTestPath(), []string{"result"})
Expand Down
4 changes: 4 additions & 0 deletions internal/artifacts/mtad.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func (loc *mtadLoc) GetManifestPath() string {
return ""
}

func (loc *mtadLoc) GetMtarDir() string {
return ""
}

// ExecuteGenMtad - generates MTAD from MTA
func ExecuteGenMtad(source, target, platform string, wdGetter func() (string, error)) error {
logs.Logger.Info("generating the MTAD file...")
Expand Down
11 changes: 5 additions & 6 deletions internal/artifacts/mtar.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

const (
mtarExtension = ".mtar"
mtarFolder = "mta_archives"
)

// ExecuteGenMtar - generates MTAR
Expand All @@ -21,7 +20,7 @@ func ExecuteGenMtar(source, target, desc string, wdGetter func() (string, error)
if err != nil {
return errors.Wrap(err, "generation of the MTA archive failed when initializing the location")
}
path, err := generateMtar(loc, loc)
path, err := generateMtar(loc, loc, loc)
if err != nil {
return err
}
Expand All @@ -30,7 +29,7 @@ func ExecuteGenMtar(source, target, desc string, wdGetter func() (string, error)
}

// generateMtar - generate mtar archive from the build artifacts
func generateMtar(targetLoc dir.ITargetPath, parser dir.IMtaParser) (string, error) {
func generateMtar(targetLoc dir.ITargetPath, targetArtifacts dir.ITargetArtifacts, parser dir.IMtaParser) (string, error) {
// get MTA object
m, err := parser.ParseFile()
if err != nil {
Expand All @@ -41,11 +40,11 @@ func generateMtar(targetLoc dir.ITargetPath, parser dir.IMtaParser) (string, err

// create the mta_archives folder
// get directory - where mtar will be saved
mtarFolderPath := filepath.Join(targetLoc.GetTarget(), mtarFolder)
mtarFolderPath := targetArtifacts.GetMtarDir()
err = dir.CreateDirIfNotExist(mtarFolderPath)
if err != nil {
return "", errors.Wrap(err,
`generation of the MTA archive failed when creating the "mta_archives" folder`)
return "", errors.Wrapf(err,
`generation of the MTA archive failed when creating the "%s" folder`, mtarFolderPath)
}
// archive building artifacts to mtar
mtarPath := filepath.Join(mtarFolderPath, m.ID+"_"+m.Version+mtarExtension)
Expand Down
19 changes: 13 additions & 6 deletions internal/artifacts/mtar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var _ = Describe("Mtar", func() {
os.MkdirAll(getTestPath("result", ".mtahtml5_mta_build_tmp", "ui5app2"), os.ModePerm)
Ω(ExecuteGenMeta(getTestPath("mtahtml5"), getResultPath(), "dev", "cf", true, os.Getwd)).Should(Succeed())
Ω(ExecuteGenMtar(getTestPath("mtahtml5"), getResultPath(), "dev", os.Getwd)).Should(Succeed())
Ω(getTestPath("result", "mta_archives", "mtahtml5_0.0.1.mtar")).Should(BeAnExistingFile())
Ω(getTestPath("result", "mtahtml5_0.0.1.mtar")).Should(BeAnExistingFile())
})

It("Fails on location initialization", func() {
Expand All @@ -43,33 +43,40 @@ var _ = Describe("Mtar", func() {
os.MkdirAll(getTestPath("result", ".mtahtml5_mta_build_tmp", "testapp"), os.ModePerm)
os.MkdirAll(getTestPath("result", ".mtahtml5_mta_build_tmp", "ui5app2"), os.ModePerm)
Ω(generateMeta(&ep, &ep, &ep, false, "cf", true)).Should(Succeed())
mtarPath, err := generateMtar(&ep, &ep)
mtarPath, err := generateMtar(&ep, &ep, &ep)
Ω(err).Should(Succeed())
Ω(mtarPath).Should(BeAnExistingFile())
})

It("Generate Mtar - Fails on wrong source", func() {
ep := dir.Loc{SourcePath: getTestPath("not_existing"), TargetPath: getResultPath()}
ep1 := dir.Loc{SourcePath: getTestPath("mtahtml5"), TargetPath: getResultPath()}
_, err := generateMtar(&ep, &ep1)
_, err := generateMtar(&ep, &ep1, &ep1)
Ω(err).Should(HaveOccurred())
})

It("Generate Mtar - Invalid mta", func() {
ep := dir.Loc{SourcePath: getTestPath("mtahtml5"), TargetPath: getResultPath(), MtaFilename: "mtaBroken.yaml"}
_, err := generateMtar(&ep, &ep)
_, err := generateMtar(&ep, &ep, &ep)
Ω(err).Should(HaveOccurred())
})
It("Generate Mtar - Mta not exists", func() {
ep := dir.Loc{SourcePath: getTestPath("mtahtml5"), TargetPath: getResultPath(), MtaFilename: "mtaNotExists.yaml"}
_, err := generateMtar(&ep, &ep)
_, err := generateMtar(&ep, &ep, &ep)
Ω(err).Should(HaveOccurred())
})
It("Generate Mtar - results file exists, folder results can't be created ", func() {
file, _ := os.Create(getTestPath("result"))
defer file.Close()
ep := dir.Loc{SourcePath: getTestPath("mtahtml5"), TargetPath: getResultPath()}
_, err := generateMtar(&ep, &ep, &ep)
Ω(err).Should(HaveOccurred())
})

var _ = Describe("Target Failures", func() {
var _ = DescribeTable("Invalid location", func(loc *testMtarLoc) {
ep := dir.Loc{}
_, err := generateMtar(loc, &ep)
_, err := generateMtar(loc, &ep, &ep)
Ω(err).Should(HaveOccurred())
},
Entry("Fails on GetTargetTmpDir", &testMtarLoc{
Expand Down
14 changes: 14 additions & 0 deletions internal/fs/mta_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
TempFolderSuffix = "_mta_build_tmp"
// Mtad - deployment descriptor file name
Mtad = "mtad.yaml"
// MtarFolder - default archives folder
MtarFolder = "mta_archives"
)

// IMtaParser - MTA Parser interface
Expand Down Expand Up @@ -71,6 +73,7 @@ type ITargetArtifacts interface {
GetMetaPath() string
GetMtadPath() string
GetManifestPath() string
GetMtarDir() string
}

// Loc - MTA tool file properties
Expand Down Expand Up @@ -100,6 +103,17 @@ func (ep *Loc) GetDescriptor() string {
return ep.Descriptor
}

// GetMtarDir - gets archive folder
// if the target folder differs from the source folder archive folder is target folder
// otherwise archives folder - "mta_archives" subfolder in the project folder
func (ep *Loc) GetMtarDir() string {
if ep.SourcePath == ep.TargetPath {
return filepath.Join(ep.SourcePath, MtarFolder)
}

return ep.TargetPath
}

// GetTarget gets the target path;
// if it is not provided, use the path of the processed project.
func (ep *Loc) GetTarget() string {
Expand Down
8 changes: 8 additions & 0 deletions internal/fs/mta_location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ var _ = Describe("Path", func() {
location := Loc{SourcePath: getPath("xyz"), TargetPath: getPath("abc")}
Ω(location.GetMtadPath()).Should(Equal(getPath("abc", ".xyz_mta_build_tmp", "META-INF", "mtad.yaml")))
})
It("GetMtarDir - mta_archives subfolder", func() {
location := Loc{SourcePath: getPath("xyz"), TargetPath: getPath("xyz")}
Ω(location.GetMtarDir()).Should(Equal(getPath("xyz", "mta_archives")))
})
It("GetMtarDir - target folder", func() {
location := Loc{SourcePath: getPath("xyz"), TargetPath: getPath("abc")}
Ω(location.GetMtarDir()).Should(Equal(getPath("abc")))
})
It("GetManifestPath", func() {
location := Loc{SourcePath: getPath("xyz"), TargetPath: getPath("abc")}
Ω(location.GetManifestPath()).Should(Equal(getPath("abc", ".xyz_mta_build_tmp", "META-INF", "MANIFEST.MF")))
Expand Down

0 comments on commit e7e341e

Please sign in to comment.