Skip to content

Commit 03d1eb5

Browse files
committed
clean up the code
Signed-off-by: Stephanie <[email protected]>
1 parent ac993a8 commit 03d1eb5

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

pkg/devfile/parser/context/context.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (d *DevfileCtx) Populate() (err error) {
7272
}
7373
klog.V(4).Infof("absolute devfile path: '%s'", d.absPath)
7474
if d.uriMap == nil {
75-
d.uriMap= make(map[string]bool)
75+
d.uriMap = make(map[string]bool)
7676
}
7777
if d.uriMap[d.absPath] {
7878
return fmt.Errorf("URI %v is recursively referenced", d.absPath)
@@ -93,11 +93,7 @@ func (d *DevfileCtx) PopulateFromURL() (err error) {
9393
return err
9494
}
9595
if d.uriMap == nil {
96-
d.uriMap= make(map[string]bool)
97-
}
98-
fmt.Printf("uriMap length is: %v", len(d.uriMap))
99-
for k,_ := range d.uriMap {
100-
fmt.Printf("uriMap now contains: %s", k)
96+
d.uriMap = make(map[string]bool)
10197
}
10298
if d.uriMap[d.url] {
10399
return fmt.Errorf("URI %v is recursively referenced", d.url)
@@ -150,8 +146,6 @@ func (d *DevfileCtx) GetURIMap() map[string]bool {
150146
}
151147

152148
// GetURIMap func returns current devfile uri map
153-
func (d *DevfileCtx) SetURIMap(uriMap map[string]bool){
149+
func (d *DevfileCtx) SetURIMap(uriMap map[string]bool) {
154150
d.uriMap = uriMap
155151
}
156-
157-

pkg/devfile/parser/parse.go

+14-27
Original file line numberDiff line numberDiff line change
@@ -185,51 +185,38 @@ func parseFromURI(uri string, curDevfileCtx devfileCtx.DevfileCtx) (DevfileObj,
185185
}
186186
// NewDevfileCtx
187187
var d DevfileObj
188-
// absolute URL address
189-
if strings.HasPrefix(uri, "http://") || strings.HasPrefix(uri, "https://") {
190-
// return ParseFromURL(uri)
191-
d.Ctx = devfileCtx.NewURLDevfileCtx(uri)
192-
d.Ctx.SetURIMap(curDevfileCtx.GetURIMap())
193-
// Fill the fields of DevfileCtx struct
194-
err = d.Ctx.PopulateFromURL()
195-
if err != nil {
196-
return DevfileObj{}, err
197-
}
198-
return parseDevfile(d, true)
199-
}
188+
absoluteURL := strings.HasPrefix(uri, "http://") || strings.HasPrefix(uri, "https://")
200189

201190
// relative path on disk
202-
if curDevfileCtx.GetAbsPath() != "" {
191+
if !absoluteURL && curDevfileCtx.GetAbsPath() != "" {
203192
d.Ctx = devfileCtx.NewDevfileCtx(path.Join(path.Dir(curDevfileCtx.GetAbsPath()), uri))
204193
d.Ctx.SetURIMap(curDevfileCtx.GetURIMap())
205194

206195
// Fill the fields of DevfileCtx struct
207196
err = d.Ctx.Populate()
208-
if err!= nil {
197+
if err != nil {
209198
return DevfileObj{}, err
210199
}
211-
// return Parse(path.Join(path.Dir(curDevfileCtx.GetAbsPath()), uri))
212200
return parseDevfile(d, true)
213201
}
214202

215-
if curDevfileCtx.GetURL() != "" {
203+
// absolute URL address
204+
if absoluteURL {
205+
d.Ctx = devfileCtx.NewURLDevfileCtx(uri)
206+
} else if curDevfileCtx.GetURL() != "" {
216207
u, err := url.Parse(curDevfileCtx.GetURL())
217208
if err != nil {
218209
return DevfileObj{}, err
219210
}
220-
221211
u.Path = path.Join(path.Dir(u.Path), uri)
222212
d.Ctx = devfileCtx.NewURLDevfileCtx(u.String())
223-
d.Ctx.SetURIMap(curDevfileCtx.GetURIMap())
224-
// Fill the fields of DevfileCtx struct
225-
err = d.Ctx.PopulateFromURL()
226-
if err != nil {
227-
return DevfileObj{}, err
228-
}
229-
return parseDevfile(d, true)
230-
// u.String() is the joint absolute URL path
231-
// return ParseFromURL(u.String())
232213
}
214+
d.Ctx.SetURIMap(curDevfileCtx.GetURIMap())
215+
// Fill the fields of DevfileCtx struct
216+
err = d.Ctx.PopulateFromURL()
217+
if err != nil {
218+
return DevfileObj{}, err
219+
}
220+
return parseDevfile(d, true)
233221

234-
return DevfileObj{}, fmt.Errorf("fail to parse from uri: %s", uri)
235222
}

0 commit comments

Comments
 (0)