Skip to content

Commit dd9e253

Browse files
move tools defaults
1 parent d205537 commit dd9e253

10 files changed

Lines changed: 90 additions & 67 deletions

File tree

cmd/init.go

Lines changed: 26 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,8 @@ func configFileTemplate(tools []tools.Tool) string {
159159
// Track needed runtimes
160160
neededRuntimes := make(map[string]bool)
161161

162-
// Default versions
163-
defaultVersions := map[string]string{
164-
ESLint: "9.3.0",
165-
Trivy: "0.59.1",
166-
PyLint: "3.3.6",
167-
PMD: "6.55.0",
168-
DartAnalyzer: "3.7.2",
169-
Semgrep: "1.78.0",
170-
Lizard: "1.17.19",
171-
}
162+
// Get tool versions from plugin configurations
163+
defaultVersions := plugins.GetToolVersions()
172164

173165
// Get runtime versions all at once
174166
runtimeVersions := plugins.GetRuntimeVersions()
@@ -179,28 +171,11 @@ func configFileTemplate(tools []tools.Tool) string {
179171
if tool.Version != "" {
180172
toolVersions[tool.Uuid] = tool.Version
181173
} else {
182-
toolVersions[tool.Uuid] = defaultVersions[tool.Uuid]
183-
}
184-
}
185-
186-
// Convert tools to ToolConfig format
187-
var toolConfigs []plugins.ToolConfig
188-
for _, tool := range tools {
189-
toolName := toolNameMap[tool.Uuid]
190-
if toolName == "" {
191-
log.Printf("Warning: Unknown tool UUID %s", tool.Uuid)
192-
continue
193-
}
194-
195-
version := tool.Version
196-
if version == "" {
197-
version = defaultVersions[tool.Uuid]
174+
toolName := toolNameMap[tool.Uuid]
175+
if defaultVersion, ok := defaultVersions[toolName]; ok {
176+
toolVersions[tool.Uuid] = defaultVersion
177+
}
198178
}
199-
200-
toolConfigs = append(toolConfigs, plugins.ToolConfig{
201-
Name: toolName,
202-
Version: version,
203-
})
204179
}
205180

206181
// Process tools to get their configurations
@@ -214,18 +189,6 @@ func configFileTemplate(tools []tools.Tool) string {
214189
runtimeInfos[runtime] = runtimeInfo
215190
}
216191

217-
toolInfos, err := plugins.ProcessTools(toolConfigs, os.TempDir(), runtimeInfos)
218-
if err != nil {
219-
log.Printf("Warning: Failed to process tool configurations: %v", err)
220-
} else {
221-
// Get required runtimes from tool configurations
222-
for _, info := range toolInfos {
223-
if info.Runtime != "" {
224-
neededRuntimes[info.Runtime] = true
225-
}
226-
}
227-
}
228-
229192
// Start building the YAML content
230193
var sb strings.Builder
231194
sb.WriteString("runtimes:\n")
@@ -277,28 +240,33 @@ func configFileTemplate(tools []tools.Tool) string {
277240
// Find the UUID for this tool name to get its version
278241
for uuid, toolName := range toolNameMap {
279242
if toolName == name && toolsMap[uuid] {
280-
sb.WriteString(fmt.Sprintf(" - %s@%s\n", name, toolVersions[uuid]))
243+
version := toolVersions[uuid]
244+
sb.WriteString(fmt.Sprintf(" - %s@%s\n", name, version))
281245
break
282246
}
283247
}
284248
}
285249
} else {
286-
// If no tools were specified (local mode), include all defaults in sorted order
287-
tools := []struct {
288-
name string
289-
uuid string
290-
}{
291-
{"dartanalyzer", DartAnalyzer},
292-
{"eslint", ESLint},
293-
{"lizard", Lizard},
294-
{"pmd", PMD},
295-
{"pylint", PyLint},
296-
{"semgrep", Semgrep},
297-
{"trivy", Trivy},
250+
// If no tools were specified (local mode), include all tools in sorted order
251+
var sortedTools []string
252+
for _, name := range []string{
253+
"dartanalyzer",
254+
"eslint",
255+
"lizard",
256+
"pmd",
257+
"pylint",
258+
"semgrep",
259+
"trivy",
260+
} {
261+
if version, ok := defaultVersions[name]; ok {
262+
sortedTools = append(sortedTools, fmt.Sprintf("%s@%s", name, version))
263+
}
298264
}
265+
sort.Strings(sortedTools)
299266

300-
for _, tool := range tools {
301-
sb.WriteString(fmt.Sprintf(" - %s@%s\n", tool.name, defaultVersions[tool.uuid]))
267+
// Write sorted tools
268+
for _, tool := range sortedTools {
269+
sb.WriteString(fmt.Sprintf(" - %s\n", tool))
302270
}
303271
}
304272

plugins/tool-utils.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type DownloadConfig struct {
7070
type ToolPluginConfig struct {
7171
Name string `yaml:"name"`
7272
Description string `yaml:"description"`
73+
DefaultVersion string `yaml:"default_version"`
7374
Runtime string `yaml:"runtime"`
7475
RuntimeBinaries RuntimeBinaries `yaml:"runtime_binaries"`
7576
Installation InstallationConfig `yaml:"installation"`
@@ -379,3 +380,39 @@ func GetSupportedTools() (map[string]struct{}, error) {
379380

380381
return supportedTools, nil
381382
}
383+
384+
// GetToolVersions returns a map of tool names to their default versions
385+
func GetToolVersions() map[string]string {
386+
versions := make(map[string]string)
387+
388+
// Read the tools directory from embedded filesystem
389+
entries, err := toolsFS.ReadDir("tools")
390+
if err != nil {
391+
return versions
392+
}
393+
394+
// Process each tool directory
395+
for _, entry := range entries {
396+
if !entry.IsDir() {
397+
continue
398+
}
399+
400+
tool := entry.Name()
401+
pluginPath := fmt.Sprintf("tools/%s/plugin.yaml", tool)
402+
data, err := toolsFS.ReadFile(pluginPath)
403+
if err != nil {
404+
continue
405+
}
406+
407+
var config ToolPluginConfig
408+
if err := yaml.Unmarshal(data, &config); err != nil {
409+
continue
410+
}
411+
412+
if config.DefaultVersion != "" {
413+
versions[tool] = config.DefaultVersion
414+
}
415+
}
416+
417+
return versions
418+
}

plugins/tools/dartanalyzer/plugin.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: dartanalyzer
2-
description: Dart Analyzer
2+
description: The Dart analyzer enforces the Dart style guide and other conventions. It's a static analysis tool that looks for potential errors and enforces style guidelines.
3+
default_version: 3.7.2
34
runtime: "{{.Runtime}}"
45
runtime_binaries:
56
package_manager: dart

plugins/tools/eslint/plugin.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: eslint
2-
description: ESLint JavaScript linter
2+
description: ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code.
3+
default_version: 9.3.0
34
runtime: node
45
runtime_binaries:
56
package_manager: npm

plugins/tools/lizard/plugin.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: lizard
2-
description: Lizard code complexity analyzer
2+
description: Lizard is an extensible Cyclomatic Complexity Analyzer for many programming languages.
3+
default_version: 1.17.19
34
runtime: python
45
runtime_binaries:
56
package_manager: python3

plugins/tools/pmd/plugin.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: pmd
2-
description: PMD - An extensible cross-language static code analyzer
2+
description: PMD is a source code analyzer that finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and so forth.
3+
default_version: 6.55.0
34
runtime: java
45
runtime_binaries:
56
execution: java

plugins/tools/pylint/plugin.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: pylint
2-
description: Python linter
2+
description: Pylint is a Python static code analysis tool which looks for programming errors, helps enforcing a coding standard, sniffs for code smells and offers simple refactoring suggestions.
3+
default_version: 3.3.6
34
runtime: python
45
runtime_binaries:
56
package_manager: python3

plugins/tools/semgrep/plugin.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: semgrep
2-
description: Static Analysis Security Testing (SAST) tool
2+
description: Semgrep is a fast, open-source, static analysis tool for finding bugs and enforcing code standards at editor, commit, and CI time.
3+
default_version: 1.78.0
34
runtime: python
45
runtime_binaries:
56
package_manager: python3

plugins/tools/trivy/plugin.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: trivy
2-
description: Trivy vulnerability scanner
2+
description: Trivy is a comprehensive security scanner for containers and other artifacts.
3+
default_version: 0.59.1
34
download:
45
url_template: "https://github.com/aquasecurity/trivy/releases/download/v{{.Version}}/trivy_{{.Version}}_{{.OS}}-{{.Arch}}.{{.Extension}}"
56
file_name_template: "trivy_{{.Version}}_{{.OS}}_{{.Arch}}"

tools/getTools.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package tools
22

33
import (
44
"codacy/cli-v2/plugins"
5+
"codacy/cli-v2/utils/logger"
56
"encoding/json"
67
"errors"
78
"fmt"
89
"io"
910
"net/http"
1011
"strings"
1112
"time"
13+
14+
"github.com/sirupsen/logrus"
1215
)
1316

1417
func enrichToolsWithVersion(tools []Tool) ([]Tool, error) {
@@ -118,18 +121,26 @@ func GetRepositoryTools(codacyBase string, apiToken string, provider string, org
118121

119122
// Filter enabled tools
120123
var enabledTools []Tool
124+
var unsupportedTools []string
125+
121126
for _, tool := range response.Data {
122127
if tool.Settings.Enabled {
123128
toolName := strings.ToLower(tool.Name)
124-
fmt.Printf("Checking tool %s (lowercase: %s)\n", tool.Name, toolName)
125129
if _, exists := supportedTools[toolName]; exists {
126130
enabledTools = append(enabledTools, tool)
127131
} else {
128-
fmt.Printf("Tool %s not found in supported tools\n", tool.Name)
132+
unsupportedTools = append(unsupportedTools, tool.Name)
129133
}
130134
}
131135
}
132136

137+
// Log unsupported tools once
138+
if len(unsupportedTools) > 0 {
139+
logger.Warn("Some tools are not supported", logrus.Fields{
140+
"unsupported_tools": strings.Join(unsupportedTools, ", "),
141+
})
142+
}
143+
133144
return enrichToolsWithVersion(enabledTools)
134145
}
135146

0 commit comments

Comments
 (0)