Skip to content

Commit 69e0030

Browse files
wip duncan support no sarif
1 parent 3c62ea1 commit 69e0030

File tree

7 files changed

+115
-1
lines changed

7 files changed

+115
-1
lines changed

cmd/analyze.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ func runToolByName(toolName string, workDirectory string, pathsToCheck []string,
359359
return tools.RunEnigma(workDirectory, tool.InstallDir, tool.Binaries["codacy-enigma-cli"], pathsToCheck, outputFile, outputFormat)
360360
case "revive":
361361
return reviveTool.RunRevive(workDirectory, tool.Binaries["revive"], pathsToCheck, outputFile, outputFormat)
362+
case "license-sim":
363+
binaryPath := tool.Binaries["duncan"]
364+
return tools.RunLicenseSim(workDirectory, binaryPath, pathsToCheck, outputFile, outputFormat)
362365
}
363366
return fmt.Errorf("unsupported tool: %s", toolName)
364367
}

config/tools-installer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ func InstallTool(name string, toolInfo *plugins.ToolInfo, registry string) error
9292
isRuntimeInstalled = true
9393
}
9494

95+
// Skip installation for local binary tools (no runtime, no download URL)
96+
if toolInfo.Runtime == "" && toolInfo.DownloadURL == "" {
97+
logger.Info("Skipping installation for local binary tool", logrus.Fields{
98+
"tool": name,
99+
"version": toolInfo.Version,
100+
})
101+
return nil
102+
}
103+
95104
if isToolInstalled && isRuntimeInstalled {
96105
logger.Info("Tool and runtime already installed", logrus.Fields{
97106
"tool": name,

plugins/tool-utils.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ func ProcessTools(configs []ToolConfig, toolDir string, runtimes map[string]*Run
154154
Environment: make(map[string]string),
155155
}
156156

157+
// If toolRuntime is empty, set safe defaults for binary-only tools
158+
if toolRuntime == "" {
159+
info.PackageManager = ""
160+
info.ExecutionBinary = ""
161+
info.InstallCommand = ""
162+
info.RegistryCommand = ""
163+
}
164+
157165
// Handle download configuration for directly downloaded tools
158166
if pluginConfig.Download.URLTemplate != "" {
159167
// Get the mapped architecture
@@ -226,6 +234,12 @@ func ProcessTools(configs []ToolConfig, toolDir string, runtimes map[string]*Run
226234
}
227235

228236
var buf bytes.Buffer
237+
var runtimeInstallDir string
238+
if toolRuntime != "" && runtimes != nil && runtimes[toolRuntime] != nil {
239+
runtimeInstallDir = runtimes[toolRuntime].InstallDir
240+
} else {
241+
runtimeInstallDir = ""
242+
}
229243
err = tmpl.Execute(&buf, struct {
230244
Version string
231245
InstallDir string
@@ -234,7 +248,7 @@ func ProcessTools(configs []ToolConfig, toolDir string, runtimes map[string]*Run
234248
}{
235249
Version: config.Version,
236250
InstallDir: installDir,
237-
RuntimeInstallDir: runtimes[toolRuntime].InstallDir,
251+
RuntimeInstallDir: runtimeInstallDir,
238252
Path: os.Getenv("PATH"),
239253
})
240254
if err != nil {

plugins/tool-utils_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func TestGetSupportedTools(t *testing.T) {
171171
"lizard",
172172
"codacy-enigma-cli",
173173
"revive",
174+
"license-sim",
174175
},
175176
expectedError: false,
176177
},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: license-sim
2+
description: Detects GPL and other licenses in code using ML similarity.
3+
default_version: "local"
4+
# This is a local binary tool; venv must be set up manually in ../license-sim/venv
5+
environment:
6+
KMP_DUPLICATE_LIB_OK: "TRUE"
7+
binaries:
8+
- name: duncan
9+
path: "/Users/kendrickcurtis/Documents/GitHub/license-sim/venv/bin/python /Users/kendrickcurtis/Documents/GitHub/license-sim/duncan.py"

runtimes/go/plugin.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: go
2+
# Go Programming Language Runtime
3+
# Provides the Go compiler and tools for building and running Go programs.
4+
description: Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
5+
default_version: 1.22.3
6+
download:
7+
url_template: "https://go.dev/dl/go{{.Version}}.{{.OS}}-{{.Arch}}.tar.gz"
8+
file_name_template: "go{{.Version}}.{{.OS}}-{{.Arch}}.tar.gz"
9+
extension:
10+
default: tar.gz
11+
windows: zip
12+
arch_mapping:
13+
amd64: amd64
14+
arm64: arm64
15+
386: 386
16+
arm: armv6l
17+
os_mapping:
18+
linux: linux
19+
darwin: darwin
20+
windows: windows
21+
binaries:
22+
- name: go
23+
path: bin/go
24+
- name: gofmt
25+
path: bin/gofmt

tools/licenseSimRunner.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package tools
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
"path/filepath"
8+
"strings"
9+
)
10+
11+
// RunLicenseSim runs the license-sim tool (duncan.py) in the Python venv with the required environment variable.
12+
func RunLicenseSim(workDirectory string, binary string, files []string, outputFile string, outputFormat string) error {
13+
// Determine the file to check and extension
14+
var fileToCheck string
15+
var ext string
16+
if len(files) > 0 {
17+
fileToCheck = files[0]
18+
ext = filepath.Ext(fileToCheck)
19+
if ext != "" {
20+
ext = ext[1:] // remove dot
21+
} else {
22+
ext = "py" // default
23+
}
24+
} else {
25+
return fmt.Errorf("No file specified for license-sim")
26+
}
27+
28+
// Prepare command: ../../license-sim/venv/bin/python ../../license-sim/duncan.py search -f <file> -e <ext>
29+
parts := strings.Split(binary, " ")
30+
cmdArgs := append(parts[1:], "search", "-f", fileToCheck, "-e", ext)
31+
cmd := exec.Command(parts[0], cmdArgs...)
32+
cmd.Dir = workDirectory
33+
cmd.Env = append(os.Environ(), "KMP_DUPLICATE_LIB_OK=TRUE")
34+
35+
// Output handling
36+
if outputFile != "" {
37+
outputWriter, err := os.Create(filepath.Clean(outputFile))
38+
if err != nil {
39+
return fmt.Errorf("failed to create output file: %w", err)
40+
}
41+
defer outputWriter.Close()
42+
cmd.Stdout = outputWriter
43+
cmd.Stderr = outputWriter
44+
} else {
45+
cmd.Stdout = os.Stdout
46+
cmd.Stderr = os.Stderr
47+
}
48+
49+
if err := cmd.Run(); err != nil {
50+
return fmt.Errorf("failed to run license-sim: %w", err)
51+
}
52+
return nil
53+
}

0 commit comments

Comments
 (0)