Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 parser structure 2 #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

devfilepkg "github.com/devfile/parser/pkg/devfile"
"github.com/devfile/parser/pkg/devfile/parser"
v200 "github.com/devfile/parser/pkg/devfile/parser/data/2.0.0"
v2 "github.com/devfile/parser/pkg/devfile/parser/data/v2"
)

func main() {
Expand All @@ -15,8 +15,8 @@ func main() {
fmt.Println(err)
} else {
devdata := devfile.Data
if (reflect.TypeOf(devdata) == reflect.TypeOf(&v200.Devfile200{})) {
d := devdata.(*v200.Devfile200)
if (reflect.TypeOf(devdata) == reflect.TypeOf(&v2.DevfileV2{})) {
d := devdata.(*v2.DevfileV2)
fmt.Println(d.SchemaVersion)
}

Expand All @@ -36,6 +36,8 @@ func main() {
fmt.Println(command.Exec.Group.Kind)
}
}

fmt.Println("Custom Type is " + devdata.GetCustomType())
}

}
Expand Down
8 changes: 4 additions & 4 deletions pkg/devfile/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package devfile

import (
"github.com/devfile/parser/pkg/devfile/parser"
"github.com/devfile/parser/pkg/devfile/validate"
// "github.com/devfile/parser/pkg/devfile/validate"
)

// This is the top level parse code which has validation code specific to odo hence it cannot be kept inside the
Expand All @@ -21,7 +21,7 @@ func ParseFromURLAndValidate(url string) (d parser.DevfileObj, err error) {
}

// odo specific validation on devfile content
err = validate.ValidateDevfileData(d.Data)
// err = validate.ValidateDevfileData(d.Data)

return d, err
}
Expand All @@ -38,7 +38,7 @@ func ParseFromDataAndValidate(data []byte) (d parser.DevfileObj, err error) {
}

// odo specific validation on devfile content
err = validate.ValidateDevfileData(d.Data)
// err = validate.ValidateDevfileData(d.Data)

return d, err
}
Expand All @@ -56,7 +56,7 @@ func ParseAndValidate(path string) (d parser.DevfileObj, err error) {
}

// odo specific validation on devfile content
err = validate.ValidateDevfileData(d.Data)
// err = validate.ValidateDevfileData(d.Data)

return d, err
}
24 changes: 14 additions & 10 deletions pkg/devfile/parser/context/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package parser
import (
"testing"

v200 "github.com/devfile/parser/pkg/devfile/parser/data/2.0.0"
v200 "github.com/devfile/parser/pkg/devfile/parser/data/v2/2.0.0"
)

const (
Expand All @@ -16,38 +16,42 @@ const (
{
"name": "project",
"git": {
"location": "https://github.com/che-samples/web-nodejs-sample.git"
"remotes": {
"origin": "https://github.com/che-samples/web-nodejs-sample.git"
}
}
}
],
"components": [
{
"name": "che-theia-plugin",
"plugin": {
"id": "eclipse/che-theia/7.1.0"
}
},
{
"name": "che-exec-plugin",
"plugin": {
"id": "eclipse/che-machine-exec-plugin/7.1.0"
}
},
{
"name": "typescript-plugin",
"plugin": {
"name": "typescript-plugin",
"id": "che-incubator/typescript/1.30.2",
"components": [
{
"name": "somecontainer",
"container": {
"name": "??",
"memoryLimit": "512Mi"
}
}
]
}
},
{
"name": "nodejs",
"container": {
"name": "nodejs",
"image": "quay.io/eclipse/che-nodejs10-ubi:nightly",
"memoryLimit": "512Mi",
"endpoints": [
Expand All @@ -63,8 +67,8 @@ const (
],
"commands": [
{
"id": "download dependencies",
"exec": {
"id": "download dependencies",
"component": "nodejs",
"commandLine": "npm install",
"workingDir": "${PROJECTS_ROOT}/project/app",
Expand All @@ -74,8 +78,8 @@ const (
}
},
{
"id": "run the app",
"exec": {
"id": "run the app",
"component": "nodejs",
"commandLine": "nodemon app.js",
"workingDir": "${PROJECTS_ROOT}/project/app",
Expand All @@ -86,8 +90,8 @@ const (
}
},
{
"id": "run the app (debugging enabled)",
"exec": {
"id": "run the app (debugging enabled)",
"component": "nodejs",
"commandLine": "nodemon --inspect app.js",
"workingDir": "${PROJECTS_ROOT}/project/app",
Expand All @@ -97,15 +101,15 @@ const (
}
},
{
"id": "stop the app",
"exec": {
"id": "stop the app",
"component": "nodejs",
"commandLine": "node_server_pids=$(pgrep -fx '.*nodemon (--inspect )?app.js' | tr \"\\\\n\" \" \") && echo \"Stopping node server with PIDs: ${node_server_pids}\" && kill -15 ${node_server_pids} &>/dev/null && echo 'Done.'"
}
},
{
"id": "Attach remote debugger",
"vscodeLaunch": {
"id": "Attach remote debugger",
"inlined": "{\n \"version\": \"0.2.0\",\n \"configurations\": [\n {\n \"type\": \"node\",\n \"request\": \"attach\",\n \"name\": \"Attach to Remote\",\n \"address\": \"localhost\",\n \"port\": 9229,\n \"localRoot\": \"${workspaceFolder}\",\n \"remoteRoot\": \"${workspaceFolder}\"\n }\n ]\n}\n"
}
}
Expand Down
36 changes: 0 additions & 36 deletions pkg/devfile/parser/data/2.0.0/types.go

This file was deleted.

3 changes: 2 additions & 1 deletion pkg/devfile/parser/data/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package data

import (
"fmt"
"k8s.io/klog"
"reflect"

"k8s.io/klog"
)

// String converts supportedApiVersion type to string type
Expand Down
5 changes: 3 additions & 2 deletions pkg/devfile/parser/data/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"strings"
"testing"

v200 "github.com/devfile/parser/pkg/devfile/parser/data/2.0.0"
v2 "github.com/devfile/parser/pkg/devfile/parser/data/v2"
v200 "github.com/devfile/parser/pkg/devfile/parser/data/v2/2.0.0"
)

func TestNewDevfileData(t *testing.T) {
Expand All @@ -14,7 +15,7 @@ func TestNewDevfileData(t *testing.T) {

var (
version = APIVersion200
want = reflect.TypeOf(&v200.Devfile200{})
want = reflect.TypeOf(&v2.DevfileV2{})
obj, err = NewDevfileData(string(version))
got = reflect.TypeOf(obj)
)
Expand Down
2 changes: 2 additions & 0 deletions pkg/devfile/parser/data/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ type DevfileData interface {
AddVolume(volume v1.Component, path string) error
DeleteVolume(name string) error
GetVolumeMountPath(name string) (string, error)

GetCustomType() string
}
6 changes: 6 additions & 0 deletions pkg/devfile/parser/data/v2/2.0.0/components.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package version200

// GetCustomType gets the custom type
func (d *Devfile200) GetCustomType() string {
return "200custom"
}
5 changes: 5 additions & 0 deletions pkg/devfile/parser/data/v2/2.0.0/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package version200

// Devfile200 is the struct for devfile 2.0.0 specific implementation
type Devfile200 struct {
}
6 changes: 6 additions & 0 deletions pkg/devfile/parser/data/v2/2.1.0/components.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package version210

// GetCustomType gets the custom type
func (d *Devfile210) GetCustomType() string {
return "210custom"
}
Loading