Skip to content

Commit a36348f

Browse files
pmd install works
1 parent 0f51dbf commit a36348f

File tree

5 files changed

+66
-3
lines changed

5 files changed

+66
-3
lines changed

.codacy/codacy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ runtimes:
33
tools:
44
55
6+

.cursor/rules/cursor.mdc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
7+
# Your rule content
8+
9+
## Code Style Guidelines
10+
- **Imports**: Standard lib first, external packages second, internal last
11+
- **Naming**: PascalCase for exported (public), camelCase for unexported (private)
12+
- **Error handling**: Return errors as last value, check with `if err != nil`
13+
- **Testing**: Use testify/assert package for assertions
14+
- **Package organization**: Keep related functionality in dedicated packages
15+
- **Documentation**: Document all exported functions, types, and packages
16+
- **Commit messages**: Start with verb, be concise and descriptive
17+
18+
## Project Structure
19+
- `cmd/`: CLI command implementations
20+
- `config/`: Configuration handling
21+
- `tools/`: Tool-specific implementations
22+
- `utils/`: Utility functions

.cursorignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Add directories or file patterns to ignore during indexing (e.g. foo/ or *.csv)

plugins/tools/pmd/plugin.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: pmd
2+
description: PMD - An extensible cross-language static code analyzer
3+
runtime: java
4+
runtime_binaries:
5+
package_manager: mvn
6+
execution: java
7+
installation:
8+
command: unzip -o {{.InstallDir}}/{{.FileName}} -d {{.InstallDir}}
9+
registry_template: mvn org.apache.maven.plugins:maven-dependency-plugin:3.6.1:get -Dartifact=net.sourceforge.pmd:pmd:{{.Version}}
10+
download:
11+
url_template: https://github.com/pmd/pmd/releases/download/pmd_releases%2F{{.Version}}/pmd-dist-{{.Version}}-bin.zip
12+
file_name_template: pmd-dist-{{.Version}}-bin.zip
13+
extension:
14+
windows: .zip
15+
default: .zip
16+
binaries:
17+
- name: pmd
18+
path: pmd-dist-{{.Version}}-bin/bin/pmd

utils/download.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@ package utils
33
import (
44
"fmt"
55
"io"
6+
"log"
67
"net/http"
78
"os"
89
"path/filepath"
910
)
1011

1112
func DownloadFile(url string, destDir string) (string, error) {
13+
log.Printf("Attempting to download from URL: %s", url)
14+
1215
// Get the file name from the URL
1316
fileName := filepath.Base(url)
17+
log.Printf("Target filename: %s", fileName)
1418

1519
// Create the destination file path
1620
destPath := filepath.Join(destDir, fileName)
21+
log.Printf("Destination path: %s", destPath)
1722

1823
_, errInfo := os.Stat(destPath)
1924
if errInfo != nil && os.IsExist(errInfo) {
25+
log.Printf("File already exists at destination, skipping download")
2026
return destPath, nil
2127
}
28+
2229
// Create the destination file
2330
outFile, err := os.Create(destPath)
2431
if err != nil {
@@ -27,22 +34,36 @@ func DownloadFile(url string, destDir string) (string, error) {
2734
defer outFile.Close()
2835

2936
// Make the HTTP GET request
30-
resp, err := http.Get(url)
37+
log.Printf("Making HTTP GET request...")
38+
client := &http.Client{}
39+
req, err := http.NewRequest("GET", url, nil)
40+
if err != nil {
41+
return "", fmt.Errorf("failed to create request: %w", err)
42+
}
43+
req.Header.Set("User-Agent", "Codacy-CLI")
44+
resp, err := client.Do(req)
3145
if err != nil {
3246
return "", fmt.Errorf("failed to make GET request: %w", err)
3347
}
3448
defer resp.Body.Close()
3549

3650
// Check if the request was successful
3751
if resp.StatusCode != http.StatusOK {
38-
return "", fmt.Errorf("failed to download file: status code %d", resp.StatusCode)
52+
body, _ := io.ReadAll(resp.Body)
53+
return "", fmt.Errorf("failed to download file: status code %d, URL: %s, Response: %s", resp.StatusCode, url, string(body))
3954
}
4055

4156
// Copy the response body to the destination file
42-
_, err = io.Copy(outFile, resp.Body)
57+
log.Printf("Downloading file content...")
58+
written, err := io.Copy(outFile, resp.Body)
4359
if err != nil {
4460
return "", fmt.Errorf("failed to copy file contents: %w", err)
4561
}
62+
log.Printf("Downloaded %d bytes", written)
63+
64+
if written == 0 {
65+
return "", fmt.Errorf("downloaded file is empty (0 bytes)")
66+
}
4667

4768
return destPath, nil
4869
}

0 commit comments

Comments
 (0)