@@ -48,9 +48,7 @@ func parseDevfile(d DevfileObj, flattenedDevfile bool) (DevfileObj, error) {
48
48
return DevfileObj {}, err
49
49
}
50
50
}
51
- for uri := range devfileCtx .URIMap {
52
- delete (devfileCtx .URIMap , uri )
53
- }
51
+
54
52
// Successful
55
53
return d , nil
56
54
}
@@ -185,27 +183,40 @@ func parseFromURI(uri string, curDevfileCtx devfileCtx.DevfileCtx) (DevfileObj,
185
183
if err != nil {
186
184
return DevfileObj {}, err
187
185
}
188
-
189
- // absolute URL address
190
- if strings .HasPrefix (uri , "http://" ) || strings .HasPrefix (uri , "https://" ) {
191
- return ParseFromURL (uri )
192
- }
186
+ // NewDevfileCtx
187
+ var d DevfileObj
188
+ absoluteURL := strings .HasPrefix (uri , "http://" ) || strings .HasPrefix (uri , "https://" )
193
189
194
190
// relative path on disk
195
- if curDevfileCtx .GetAbsPath () != "" {
196
- return Parse (path .Join (path .Dir (curDevfileCtx .GetAbsPath ()), uri ))
191
+ if ! absoluteURL && curDevfileCtx .GetAbsPath () != "" {
192
+ d .Ctx = devfileCtx .NewDevfileCtx (path .Join (path .Dir (curDevfileCtx .GetAbsPath ()), uri ))
193
+ d .Ctx .SetURIMap (curDevfileCtx .GetURIMap ())
194
+
195
+ // Fill the fields of DevfileCtx struct
196
+ err = d .Ctx .Populate ()
197
+ if err != nil {
198
+ return DevfileObj {}, err
199
+ }
200
+ return parseDevfile (d , true )
197
201
}
198
202
199
- if curDevfileCtx .GetURL () != "" {
203
+ // absolute URL address
204
+ if absoluteURL {
205
+ d .Ctx = devfileCtx .NewURLDevfileCtx (uri )
206
+ } else if curDevfileCtx .GetURL () != "" {
200
207
u , err := url .Parse (curDevfileCtx .GetURL ())
201
208
if err != nil {
202
209
return DevfileObj {}, err
203
210
}
204
-
205
211
u .Path = path .Join (path .Dir (u .Path ), uri )
206
- // u.String() is the joint absolute URL path
207
- return ParseFromURL (u .String ())
212
+ d .Ctx = devfileCtx .NewURLDevfileCtx (u .String ())
208
213
}
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 )
209
221
210
- return DevfileObj {}, fmt .Errorf ("fail to parse from uri: %s" , uri )
211
222
}
0 commit comments