Skip to content

Commit d8e732b

Browse files
working for JAVA
1 parent 3d37bab commit d8e732b

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

config/config.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,34 @@ func (c *ConfigType) Tools() map[string]*plugins.ToolInfo {
8383
}
8484

8585
func (c *ConfigType) AddTools(configs []plugins.ToolConfig) error {
86-
// Process the tool configurations using the plugins.ProcessTools function
86+
// Get the plugin manager to access tool configurations
87+
pluginManager := plugins.GetPluginManager()
88+
89+
// Ensure all required runtimes are present before processing tools
90+
for _, toolConfig := range configs {
91+
// Get the tool's plugin configuration to access runtime info
92+
pluginConfig, err := pluginManager.GetToolConfig(toolConfig.Name)
93+
if err != nil {
94+
return fmt.Errorf("failed to get plugin config for tool %s: %w", toolConfig.Name, err)
95+
}
96+
97+
if pluginConfig.Runtime != "" {
98+
runtimeInfo := c.runtimes[pluginConfig.Runtime]
99+
if runtimeInfo == nil {
100+
// Try to install the missing runtime
101+
if err := InstallRuntimeStrict(pluginConfig.Runtime, nil); err != nil {
102+
return fmt.Errorf("failed to install required runtime %s: %w", pluginConfig.Runtime, err)
103+
}
104+
// Fetch the runtimeInfo again
105+
runtimeInfo = c.runtimes[pluginConfig.Runtime]
106+
if runtimeInfo == nil {
107+
return fmt.Errorf("runtime %s still missing after install", pluginConfig.Runtime)
108+
}
109+
}
110+
}
111+
}
112+
113+
// Now safe to process tools
87114
toolInfoMap, err := plugins.ProcessTools(configs, c.toolsDirectory, c.runtimes)
88115
if err != nil {
89116
return err

config/runtimes-installer-strict.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,37 @@ import (
1414

1515
// InstallRuntimeStrict installs a runtime with strict path handling and validation
1616
func InstallRuntimeStrict(name string, runtimeInfo *plugins.RuntimeInfo) error {
17+
logger.Info("InstallRuntimeStrict called", logrus.Fields{"runtime": name, "runtimeInfo_nil": runtimeInfo == nil})
18+
19+
// If runtimeInfo is nil, try to add and process the runtime
20+
if runtimeInfo == nil {
21+
logger.Warn("RuntimeInfo is nil, attempting to add and process runtime", logrus.Fields{"runtime": name})
22+
defaultVersions := plugins.GetRuntimeVersions()
23+
logger.Debug("Default versions map", logrus.Fields{"defaultVersions": defaultVersions})
24+
version, ok := defaultVersions[name]
25+
if !ok {
26+
logger.Error("No default version found for runtime", logrus.Fields{"runtime": name})
27+
return fmt.Errorf("no default version found for runtime %s", name)
28+
}
29+
logger.Info("Adding runtime to config", logrus.Fields{"runtime": name, "version": version})
30+
if err := Config.AddRuntimes([]plugins.RuntimeConfig{{Name: name, Version: version}}); err != nil {
31+
logger.Error("Failed to add runtime to config", logrus.Fields{"runtime": name, "error": err.Error()})
32+
return fmt.Errorf("failed to add runtime %s: %w", name, err)
33+
}
34+
logger.Info("Fetching runtimeInfo from config after add", logrus.Fields{"runtime": name})
35+
runtimeInfo = Config.Runtimes()[name]
36+
if runtimeInfo == nil {
37+
logger.Error("Failed to process runtime after adding (runtimeInfo is still nil)", logrus.Fields{"runtime": name})
38+
return fmt.Errorf("failed to process runtime %s after adding", name)
39+
}
40+
logger.Info("runtimeInfo successfully created", logrus.Fields{"runtime": name, "version": runtimeInfo.Version, "installDir": runtimeInfo.InstallDir, "downloadURL": runtimeInfo.DownloadURL, "binaries": runtimeInfo.Binaries})
41+
}
42+
43+
logger.Info("Proceeding with runtime installation", logrus.Fields{"runtime": name, "version": runtimeInfo.Version})
44+
1745
// Create target directory if it doesn't exist
1846
if err := os.MkdirAll(runtimeInfo.InstallDir, utils.DefaultDirPerms); err != nil {
47+
logger.Error("Failed to create installation directory", logrus.Fields{"runtime": name, "dir": runtimeInfo.InstallDir, "error": err.Error()})
1948
return fmt.Errorf("failed to create installation directory: %w", err)
2049
}
2150

@@ -28,6 +57,7 @@ func InstallRuntimeStrict(name string, runtimeInfo *plugins.RuntimeInfo) error {
2857

2958
archivePath, err := utils.DownloadFile(runtimeInfo.DownloadURL, Config.RuntimesDirectory())
3059
if err != nil {
60+
logger.Error("Failed to download runtime archive", logrus.Fields{"runtime": name, "url": runtimeInfo.DownloadURL, "error": err.Error()})
3161
return fmt.Errorf("failed to download runtime archive: %w", err)
3262
}
3363

@@ -40,6 +70,7 @@ func InstallRuntimeStrict(name string, runtimeInfo *plugins.RuntimeInfo) error {
4070

4171
archive, err := os.Open(archivePath)
4272
if err != nil {
73+
logger.Error("Failed to open archive", logrus.Fields{"runtime": name, "archive": archivePath, "error": err.Error()})
4374
return fmt.Errorf("failed to open archive: %w", err)
4475
}
4576
defer archive.Close()
@@ -51,16 +82,19 @@ func InstallRuntimeStrict(name string, runtimeInfo *plugins.RuntimeInfo) error {
5182
err = utils.ExtractTarGz(archive, Config.RuntimesDirectory())
5283
}
5384
if err != nil {
85+
logger.Error("Failed to extract runtime archive", logrus.Fields{"runtime": name, "archive": archivePath, "error": err.Error()})
5486
return fmt.Errorf("failed to extract runtime archive: %w", err)
5587
}
5688

5789
// Set executable permissions on binaries
5890
logger.Info("Setting binary permissions", logrus.Fields{
59-
"runtime": name,
60-
"version": runtimeInfo.Version,
91+
"runtime": name,
92+
"version": runtimeInfo.Version,
93+
"binaries": runtimeInfo.Binaries,
6194
})
6295

6396
for binaryName, binaryPath := range runtimeInfo.Binaries {
97+
logger.Debug("Checking binary existence", logrus.Fields{"runtime": name, "binary": binaryName, "path": binaryPath})
6498
// Skip if binary doesn't exist yet
6599
if _, err := os.Stat(binaryPath); os.IsNotExist(err) {
66100
logger.Debug("Binary not found, skipping", logrus.Fields{
@@ -72,12 +106,14 @@ func InstallRuntimeStrict(name string, runtimeInfo *plugins.RuntimeInfo) error {
72106

73107
// Set executable permissions
74108
if err := os.Chmod(binaryPath, 0755); err != nil {
109+
logger.Error("Failed to set permissions for binary", logrus.Fields{"runtime": name, "binary": binaryName, "path": binaryPath, "error": err.Error()})
75110
return fmt.Errorf("failed to set permissions for binary %s: %w", binaryName, err)
76111
}
77112
}
78113

79114
// Verify installation
80115
if !Config.IsRuntimeInstalled(name, runtimeInfo) {
116+
logger.Error("Runtime installed but binaries are not available", logrus.Fields{"runtime": name, "version": runtimeInfo.Version})
81117
return fmt.Errorf("runtime %s was installed but binaries are not available", name)
82118
}
83119

@@ -88,6 +124,7 @@ func InstallRuntimeStrict(name string, runtimeInfo *plugins.RuntimeInfo) error {
88124

89125
// Update codacy.yaml with the new runtime
90126
if err := updateRuntimeInCodacyYaml(name, runtimeInfo.Version); err != nil {
127+
logger.Error("Failed to update codacy.yaml with runtime", logrus.Fields{"runtime": name, "error": err.Error()})
91128
return fmt.Errorf("failed to update codacy.yaml with runtime %s: %w", name, err)
92129
}
93130

plugins/tools/dartanalyzer/plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: dartanalyzer
22
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.
33
default_version: 3.7.2
4-
runtime: "{{.Runtime}}"
4+
runtime: "dart"
55
runtime_binaries:
66
package_manager: dart
77
execution: dart

0 commit comments

Comments
 (0)