Skip to content

refactor: comprehensive cleanup and interface improvements#56

Merged
gnodet merged 1 commit intomainfrom
refactor/enhance-getchecksum-interface
Oct 4, 2025
Merged

refactor: comprehensive cleanup and interface improvements#56
gnodet merged 1 commit intomainfrom
refactor/enhance-getchecksum-interface

Conversation

@gnodet
Copy link
Copy Markdown
Owner

@gnodet gnodet commented Oct 4, 2025

Overview

This PR performs a comprehensive cleanup of deprecated/unused code and improves the Tool interface design, resulting in a significantly cleaner and more maintainable codebase.

Changes Made

🧹 Removed Deprecated/Unused Code

Deprecated Installation Methods:

  • ❌ Removed InstallTool(), InstallTools(), InstallToolsParallel(), InstallToolsWithOptions()
  • ❌ Removed unused InstallOptions struct
  • ✅ Updated all callers to use EnsureTools()/EnsureTool() instead

Redundant Tool Methods:

  • ❌ Removed redundant Name() methods from all tools
  • ✅ Consolidated on GetToolName() for consistency

Deprecated Config Fields:

  • ❌ Removed deprecated Pre/Post hook fields from CommandConfig
  • These were part of the old built-in command system that was replaced with user-defined custom commands

Unused Cache Methods:

  • ❌ Removed ClearAllCaches(), ClearPathCache() methods
  • ❌ Removed unused CacheManager interface

🔧 Enhanced GetChecksum Interface

Before:

GetChecksum(version, filename string) (ChecksumInfo, error)

After:

GetChecksum(version string, cfg config.ToolConfig, filename string) (ChecksumInfo, error)

Benefits:

  • Tools now have access to full ToolConfig including distribution info and options
  • Enables more efficient and context-aware checksum fetching
  • Java can now use cfg.Distribution to target specific distributions (temurin, zulu, etc.)
  • More consistent and extensible interface across all tools

🧹 Removed Unused Internal Methods

Removed from all tools:

  • getVersionsURL() - Not used anywhere in the codebase
  • getChecksumURL() from JavaTool, GoTool, NodeTool - Not actually called

Kept where actually used:

  • getChecksumURL() in MavenTool and MvndTool - Still called by their GetChecksum() methods

🔍 Interface Simplification

Eliminated Entire Interface:

  • ❌ Removed ToolMetadataProvider interface entirely
  • ✅ Moved GetDisplayName() into main Tool interface
  • ❌ Removed GetEmoji() method (using default emoji "📦" in display code)

Made Implementation Details Private:

  • ❌ Made GetChecksumURL() and GetVersionsURL() private (lowercase) where not used
  • Better encapsulation of internal implementation details

📋 Updated All Tool Implementations

  • JavaTool: Updated signature, clarified checksum architecture, removed unused methods
  • GoTool: Updated signature, removed unused methods
  • NodeTool: Updated signature, removed unused methods
  • MavenTool: Updated signature, removed unused getVersionsURL
  • MvndTool: Updated signature, removed unused getVersionsURL

🔍 Java Checksum Architecture Clarification

Java has a different checksum architecture than other tools:

Other Tools (Go, Node, Maven, Mvnd):

  • GetChecksum() fetches checksums dynamically when needed
  • Called by download.go during download verification

Java Tool:

  • Checksums are fetched during installation via getDownloadURLWithChecksum()
  • Checksums are added to configuration and used during download
  • GetChecksum() returns informative error since checksums are pre-fetched
  • More efficient integration with Disco API during URL resolution

Files Changed

  • cmd/root.go - Updated to use EnsureTools instead of deprecated methods
  • cmd/setup.go - Updated to use EnsureTools instead of deprecated methods
  • cmd/tools.go - Updated display logic for simplified interface
  • pkg/config/config.go - Removed deprecated Pre/Post hook fields
  • pkg/tools/base_tool.go - Removed deprecated methods and cache interfaces
  • pkg/tools/manager.go - Updated Tool interface, removed deprecated methods
  • pkg/tools/java.go - Updated signature, removed unused methods, clarified architecture
  • pkg/tools/go.go - Updated signature, removed unused methods
  • pkg/tools/node.go - Updated signature, removed unused methods
  • pkg/tools/maven.go - Updated signature, removed unused getVersionsURL
  • pkg/tools/mvnd.go - Updated signature, removed unused getVersionsURL
  • pkg/tools/download.go - Updated GetChecksum call, removed fallback logic
  • pkg/tools/checksum_test.go - Updated tests for new signature

Testing

  • ✅ All unit tests pass
  • ✅ All integration tests pass
  • ✅ Build passes successfully
  • ✅ No functionality broken

Impact

  • Massive code reduction: Removed 243+ lines of deprecated/unused code
  • Cleaner Tool interface with only necessary public methods
  • Better separation of concerns between installation-time and on-demand checksum fetching
  • More extensible architecture for future tool implementations
  • Improved maintainability by eliminating dead code
  • SOLID principles compliance with focused, single-responsibility interfaces
  • No breaking changes to existing functionality

Code Quality Improvements

  • Eliminated deprecated wrapper methods that were causing confusion
  • Removed redundant Name() methods in favor of consistent GetToolName()
  • Cleaned up unused cache management interfaces
  • Simplified tool metadata handling
  • Better encapsulation of internal implementation details
  • Improved interface consistency across all tools
  • Enhanced documentation of Java's unique checksum architecture

Migration Path

All deprecated methods have been replaced with their modern equivalents:

  • InstallTool*()EnsureTool()/EnsureTools()
  • tool.Name()tool.GetToolName()
  • ToolMetadataProvider → Direct tool.GetDisplayName() calls

This cleanup significantly improves code maintainability while preserving all existing functionality.

This commit performs a comprehensive cleanup of deprecated/unused code and improves the Tool interface design:

**Removed Deprecated/Unused Code:**
- Removed deprecated InstallTool(), InstallTools(), InstallToolsParallel(), InstallToolsWithOptions() methods
- Removed unused InstallOptions struct (replaced with EnsureTools/EnsureTool)
- Removed redundant Name() methods from all tools (consolidated on GetToolName())
- Removed deprecated Pre/Post hook fields from CommandConfig (part of removed built-in command system)
- Removed unused ClearAllCaches(), ClearPathCache() methods and CacheManager interface
- Updated all callers to use EnsureTools/EnsureTool instead of deprecated methods

**Enhanced GetChecksum Interface:**
- Updated GetChecksum signature from (version, filename) to (version, cfg, filename)
- Provides tools access to full ToolConfig including distribution info and options
- Enables more efficient and context-aware checksum fetching
- Updated all tool implementations: JavaTool, GoTool, NodeTool, MavenTool, MvndTool
- Updated call sites in download.go and tests

**Removed Unused Internal Methods:**
- Removed getChecksumURL() from JavaTool, GoTool, NodeTool (not used)
- Removed getVersionsURL() from all tools (not used anywhere)
- Only kept getChecksumURL() in MavenTool and MvndTool where actually used

**Interface Simplification:**
- Eliminated entire ToolMetadataProvider interface
- Moved GetDisplayName() into main Tool interface
- Removed GetEmoji() method entirely (using default emoji in display code)
- Made GetChecksumURL() and GetVersionsURL() private implementation details

**Java Checksum Architecture Clarification:**
- Java checksums are handled during installation via getDownloadURLWithChecksum()
- GetChecksum() method returns informative error since checksums are pre-fetched
- Maintains existing efficient integration with Disco API during URL resolution

**Benefits:**
- Cleaner Tool interface with only necessary public methods
- Removed 243+ lines of deprecated/unused code
- More consistent and extensible GetChecksum signature
- Better separation of concerns between installation-time and on-demand checksum fetching
- Improved maintainability by eliminating dead code
- Follows SOLID principles with focused interfaces

All tests pass and functionality is preserved while significantly reducing code complexity.
@gnodet gnodet force-pushed the refactor/enhance-getchecksum-interface branch from 76baf9a to 42b2e28 Compare October 4, 2025 10:01
@gnodet gnodet changed the title refactor: enhance GetChecksum interface and remove unused internal methods refactor: comprehensive cleanup and interface improvements Oct 4, 2025
@gnodet gnodet merged commit 06d6e80 into main Oct 4, 2025
1 check passed
@gnodet gnodet deleted the refactor/enhance-getchecksum-interface branch October 4, 2025 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant