-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpluginDetails.go
137 lines (125 loc) · 4.54 KB
/
pluginDetails.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package main
import (
utilsPB "code-analyser/protos/pb/output/utils"
pluginDetailsPB "code-analyser/protos/pb/pluginDetails"
"gopkg.in/yaml.v2"
"io/ioutil"
"path/filepath"
)
//TODO error bhi return karni hai
//GetLanguagePluginsPath It will read pluginDetails.yaml files in plugin directory of given languagePath
//func GetLanguagePluginsPath(ctx context.Context, languagePluginsRootPath string) *pluginDetailsPB.LanguagePlugins {
//
// pluginYamlFiles, err := SearchFileInDirectory("pluginDetails.yaml", languagePluginsRootPath)
// if err != nil {
// utils.Logger(err)
// return nil
// }
//
// languagePlugins := &pluginDetailsPB.LanguagePlugins{
// Frameworks: map[string]*pluginDetailsPB.DependencyDetails{},
// Databases: map[string]*pluginDetailsPB.DependencyDetails{},
// Orms: map[string]*pluginDetailsPB.DependencyDetails{},
// Libraries: map[string]*pluginDetailsPB.DependencyDetails{},
// RuntimeVersions: map[string]*pluginDetailsPB.DependencyVersionDetails{},
// }
//
// //TODO: discuss with Atul better ways to implement concurrency
// for _, pluginFile := range pluginYamlFiles {
//
// parsedRawFile, err := ReadPluginYamlFile(ctx, pluginFile)
// if err != nil {
// log.Println(err)
// //TODO remove this continue , on error whole function should stop
// continue
// }
//
// pluginYamlFile := parsedRawFile.PluginDetails
//
// switch pluginYamlFile.Type {
// case "detectRuntime":
// languagePlugins.DetectRuntimePluginPath = pluginYamlFile.Command
// case "commands":
// languagePlugins.CommandsPluginPath = pluginYamlFile.Command
// case "env":
// languagePlugins.EnvPluginPath = pluginYamlFile.Command
// case "preDetectCommand":
// languagePlugins.PreDetectCommandPluginPath = pluginYamlFile.Command
// case "staticAssets":
// languagePlugins.StaticAssetsPluginPath = pluginYamlFile.Command
// case "buildDirectory":
// languagePlugins.BuildDirectoryPluginPath = pluginYamlFile.Command
// case "testCasesCommands":
// languagePlugins.TestCasesCommandPluginPath = pluginYamlFile.Command
//
// case "framework":
// if framework, ok := languagePlugins.Frameworks[pluginYamlFile.Name]; ok {
// AddPluginVersionDetails(framework, pluginYamlFile)
// } else {
// languagePlugins.Frameworks[pluginYamlFile.Name] = CreatePluginVersionMap(pluginYamlFile)
// }
//
// case "orm":
// if orm, ok := languagePlugins.Orms[pluginYamlFile.Name]; ok {
// AddPluginVersionDetails(orm, pluginYamlFile)
// } else {
// languagePlugins.Orms[pluginYamlFile.Name] = CreatePluginVersionMap(pluginYamlFile)
// }
//
// case "library":
// if library, ok := languagePlugins.Libraries[pluginYamlFile.Name]; ok {
// AddPluginVersionDetails(library, pluginYamlFile)
// } else {
// languagePlugins.Libraries[pluginYamlFile.Name] = CreatePluginVersionMap(pluginYamlFile)
// }
//
// case "database":
// if database, ok := languagePlugins.Databases[pluginYamlFile.Name]; ok {
// AddPluginVersionDetails(database, pluginYamlFile)
// } else {
// languagePlugins.Databases[pluginYamlFile.Name] = CreatePluginVersionMap(pluginYamlFile)
// }
//
// case "getDependencies":
// languagePlugins.RuntimeVersions[pluginYamlFile.Version] = &pluginDetailsPB.DependencyVersionDetails{
// Semver: pluginYamlFile.Semver,
// PluginPath: pluginYamlFile.Command,
// }
// }
//
// }
// return languagePlugins
//}
func AddPluginVersionDetails(dependencyMap *pluginDetailsPB.DependencyDetails, pluginYamlFile *utilsPB.Details) {
dependencyMap.Version[pluginYamlFile.Version] = &pluginDetailsPB.DependencyVersionDetails{
Semver: pluginYamlFile.Semver,
PluginPath: pluginYamlFile.Command,
Libraries: pluginYamlFile.Libraries,
}
}
func CreatePluginVersionMap(pluginYamlFile *utilsPB.Details) *pluginDetailsPB.DependencyDetails {
return &pluginDetailsPB.DependencyDetails{
Version: map[string]*pluginDetailsPB.DependencyVersionDetails{
pluginYamlFile.Version: {
Semver: pluginYamlFile.Semver,
PluginPath: pluginYamlFile.Command,
Libraries: pluginYamlFile.Libraries,
},
},
}
}
const SupportedLanguages = "./static/supportedLanguages.yaml"
//SupportedLanguagesParser it reads yaml file and fetch out supported languages by our system (like go or js )
func SupportedLanguagesParser() (*pluginDetailsPB.SupportedLanguages, error) {
filename, _ := filepath.Abs(SupportedLanguages)
yamlFile, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
var lang pluginDetailsPB.SupportedLanguages
err = yaml.Unmarshal(yamlFile, &lang)
if err != nil {
return nil, err
}
return &lang, nil
}