Skip to content

Commit 3a348cc

Browse files
integration with hardcoded license-sim
1 parent 754c549 commit 3a348cc

File tree

7 files changed

+58
-14
lines changed

7 files changed

+58
-14
lines changed

.codacy/codacy.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ runtimes:
55
66
77
tools:
8-
98
109
1110
12-
- license-sim@1.0.0
11+
- license-sim@local

cmd/analyze.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ func LoadLanguageConfig() (*LanguagesConfig, error) {
6262
return nil, fmt.Errorf("failed to parse YAML languages configuration file: %w", err)
6363
}
6464

65+
// Ensure license-sim entry for PHP files
66+
ensureLicenseSimEntry(&config)
6567
return &config, nil
6668
}
6769

@@ -83,9 +85,38 @@ func LoadLanguageConfig() (*LanguagesConfig, error) {
8385
return nil, fmt.Errorf("failed to parse JSON languages configuration file: %w", err)
8486
}
8587

88+
// Ensure license-sim entry for PHP files
89+
ensureLicenseSimEntry(&config)
8690
return &config, nil
8791
}
8892

93+
// ensureLicenseSimEntry adds or updates the license-sim entry to only support .php files
94+
func ensureLicenseSimEntry(config *LanguagesConfig) {
95+
found := false
96+
for i, tool := range config.Tools {
97+
if tool.Name == "license-sim" {
98+
// Overwrite to only support .php files
99+
config.Tools[i].Extensions = []string{".php"}
100+
config.Tools[i].Languages = []string{"PHP"}
101+
found = true
102+
break
103+
}
104+
}
105+
if !found {
106+
config.Tools = append(config.Tools, struct {
107+
Name string `yaml:"name" json:"name"`
108+
Languages []string `yaml:"languages" json:"languages"`
109+
Extensions []string `yaml:"extensions" json:"extensions"`
110+
Files []string `yaml:"files" json:"files"`
111+
}{
112+
Name: "license-sim",
113+
Languages: []string{"PHP"},
114+
Extensions: []string{".php"},
115+
Files: nil,
116+
})
117+
}
118+
}
119+
89120
// GetFileExtension extracts the file extension from a path
90121
func GetFileExtension(filePath string) string {
91122
return strings.ToLower(filepath.Ext(filePath))
@@ -113,14 +144,14 @@ func IsToolSupportedForFile(toolName string, filePath string, langConfig *Langua
113144
if tool.Name == toolName {
114145
// If tool has no extensions defined, assume it supports all files
115146
if len(tool.Extensions) == 0 {
116-
fmt.Printf("[DEBUG] Tool %s has no extensions defined, supports all files. File: %s\n", toolName, filePath)
147+
fmt.Printf("[DEBUG1] Tool %s has no extensions defined, supports all files. File: %s\n", toolName, filePath)
117148
return true
118149
}
119150

120-
fmt.Printf("[DEBUG] Checking if tool %s supports file %s (ext: %s). Tool extensions: %v\n", toolName, filePath, fileExt, tool.Extensions)
151+
//fmt.Printf("[DEBUG] Checking if tool %s supports file %s (ext: %s). Tool extensions: %v\n", toolName, filePath, fileExt, tool.Extensions)
121152
for _, ext := range tool.Extensions {
122153
if strings.EqualFold(ext, fileExt) {
123-
fmt.Printf("[DEBUG] Tool %s supports file %s (matched ext: %s)\n", toolName, filePath, fileExt)
154+
//fmt.Printf("[DEBUG2] Tool %s supports file %s (matched ext: %s)\n", toolName, filePath, fileExt)
124155
return true
125156
}
126157
}
@@ -138,7 +169,7 @@ func IsToolSupportedForFile(toolName string, filePath string, langConfig *Langua
138169
}
139170

140171
// If tool not found in config, assume it's supported
141-
fmt.Printf("[DEBUG] Tool %s not found in language config, assuming it supports file %s\n", toolName, filePath)
172+
//fmt.Printf("[DEBUG3] Tool %s not found in language config, assuming it supports file %s\n", toolName, filePath)
142173
return true
143174
}
144175

config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ func (c *ConfigType) IsRuntimeInstalled(name string, runtime *plugins.RuntimeInf
380380

381381
// IsToolInstalled checks if a tool is already installed
382382
func (c *ConfigType) IsToolInstalled(name string, tool *plugins.ToolInfo) bool {
383+
// Special case for license-sim: treat as installed if duncan.py exists in a sibling directory
384+
if name == "license-sim" {
385+
repoParent := filepath.Dir(c.repositoryDirectory)
386+
scriptPath := filepath.Join(repoParent, "license-sim", "duncan.py")
387+
if _, err := os.Stat(scriptPath); err == nil {
388+
return true
389+
}
390+
}
383391
// If there are no binaries, check the install directory
384392
if len(tool.Binaries) == 0 {
385393
_, err := os.Stat(tool.InstallDir)

config/tools-installer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ 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{
95+
// Skip installation for local binary tools (no runtime, no download URL, and version == "local")
96+
if toolInfo.Version == "local" {
97+
logger.Info("Skipping installation for local binary tool (version=local)", logrus.Fields{
9898
"tool": name,
9999
"version": toolInfo.Version,
100100
})

domain/tool.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
Semgrep string = "6792c561-236d-41b7-ba5e-9d6bee0d548b"
3232
Lizard string = "76348462-84b3-409a-90d3-955e90abfb87"
3333
Revive string = "bd81d1f4-1406-402d-9181-1274ee09f1aa"
34+
LicenseSim string = "b7e1c2a4-5f3d-4e2a-9c8b-1a2b3c4d5e6f" // generated UUID
3435
)
3536

3637
type ToolInfo struct {
@@ -50,4 +51,5 @@ var SupportedToolsMetadata = map[string]ToolInfo{
5051
Lizard: {Name: "lizard", Priority: 0},
5152
Semgrep: {Name: "semgrep", Priority: 0},
5253
Revive: {Name: "revive", Priority: 0},
54+
LicenseSim: {Name: "license-sim", Priority: 0},
5355
}

tools/licenseSimRunner.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ func RunLicenseSim(workDirectory string, binary string, files []string, outputFi
3232
parts := strings.Split(binary, " ")
3333
cmdArgs := append(parts[1:], "search", "-f", fileToCheck, "-e", ext)
3434

35+
// Always add --json for machine-readable output
36+
cmdArgs = append(cmdArgs, "--json")
37+
3538
if outputFormat == "sarif" {
3639
tempFile, err := os.CreateTemp("", "license-sim-*.json")
3740
if err != nil {
@@ -41,7 +44,6 @@ func RunLicenseSim(workDirectory string, binary string, files []string, outputFi
4144
tempFile.Close()
4245
defer os.Remove(tempFilePath)
4346

44-
cmdArgs = append(cmdArgs, "--json")
4547
cmd := exec.Command(parts[0], cmdArgs...)
4648
cmd.Dir = workDirectory
4749
cmd.Env = append(os.Environ(), "KMP_DUPLICATE_LIB_OK=TRUE")

utils/sarif.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,16 +342,18 @@ func ConvertLicenseSimToSarifWithFile(licenseSimOutput []byte, scannedFile strin
342342
}
343343

344344
for _, issue := range issues {
345-
referenceFile := issue.FilePath
346345
ruleId := issue.License
347346
if ruleId == "" {
348347
ruleId = "license-sim-match"
349348
}
349+
// Compose message with similarity score and reference file if available
350+
percent := int(issue.Similarity * 100)
350351
msg := issue.Message
351352
if msg == "" {
352-
msg = "code similar to licensed code in " + referenceFile
353-
} else {
354-
msg = msg + " (reference: " + referenceFile + ")"
353+
msg = fmt.Sprintf("code similar to licensed code (%d%%)", percent)
354+
if issue.FilePath != "" {
355+
msg += " in " + issue.FilePath
356+
}
355357
}
356358
startLine := issue.Line
357359
if startLine <= 0 {

0 commit comments

Comments
 (0)