@@ -185,51 +185,38 @@ func parseFromURI(uri string, curDevfileCtx devfileCtx.DevfileCtx) (DevfileObj,
185
185
}
186
186
// NewDevfileCtx
187
187
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://" )
200
189
201
190
// relative path on disk
202
- if curDevfileCtx .GetAbsPath () != "" {
191
+ if ! absoluteURL && curDevfileCtx .GetAbsPath () != "" {
203
192
d .Ctx = devfileCtx .NewDevfileCtx (path .Join (path .Dir (curDevfileCtx .GetAbsPath ()), uri ))
204
193
d .Ctx .SetURIMap (curDevfileCtx .GetURIMap ())
205
194
206
195
// Fill the fields of DevfileCtx struct
207
196
err = d .Ctx .Populate ()
208
- if err != nil {
197
+ if err != nil {
209
198
return DevfileObj {}, err
210
199
}
211
- // return Parse(path.Join(path.Dir(curDevfileCtx.GetAbsPath()), uri))
212
200
return parseDevfile (d , true )
213
201
}
214
202
215
- if curDevfileCtx .GetURL () != "" {
203
+ // absolute URL address
204
+ if absoluteURL {
205
+ d .Ctx = devfileCtx .NewURLDevfileCtx (uri )
206
+ } else if curDevfileCtx .GetURL () != "" {
216
207
u , err := url .Parse (curDevfileCtx .GetURL ())
217
208
if err != nil {
218
209
return DevfileObj {}, err
219
210
}
220
-
221
211
u .Path = path .Join (path .Dir (u .Path ), uri )
222
212
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())
232
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 )
233
221
234
- return DevfileObj {}, fmt .Errorf ("fail to parse from uri: %s" , uri )
235
222
}
0 commit comments