-
Notifications
You must be signed in to change notification settings - Fork 6
Feature/linux cross platform support #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ement - Complete doSetEnv function implementation for Linux platform - Add support for system-level and user-level environment variable setting - Implement intelligent permission handling (root/non-root users) - Add multi-shell environment support (bash, zsh, fish, profile) - Implement environment variable persistence across shell sessions - Add Linux-specific PATH management functions - Update constants for cross-platform symlink paths - Support both /etc/environment and user shell config files Key functions added: - doSetEnv(): Main environment variable setting function - updateUserEnvironmentVariables(): Multi-shell user-level config - detectUserShells(): Automatic shell detection - updateShellEnvironment(): Shell-specific configuration - SetSystemEnvPath()/SetCurrentUserEnvPath(): PATH management - QuerySystemEnvironmentVariable(): Linux environment variable queries This implementation ensures jenv works seamlessly on Linux with proper environment variable persistence and multi-shell compatibility.
- Create dedicated shell management module for cross-platform support - Implement shell detection and configuration for bash, zsh, fish, profile - Add Windows-specific shell support (PowerShell, CMD, GitBash) - Provide unified interface for environment variable management across shells New files: - shell.go: Core shell management for Unix-like systems - shell_windows.go: Windows-specific shell management - shell_test.go: Comprehensive test suite for shell functionality Key features: - Automatic shell detection based on config files - Shell-specific syntax generation (export vs set -gx) - Environment variable addition, update, and removal - Cross-platform compatibility with build tags - Support for nested config directories (fish) This module provides the foundation for persistent environment variable management across different shell environments on Linux and other Unix-like systems, while maintaining Windows compatibility.
- Enhance GetDefaultSymlinkPath() for intelligent cross-platform path selection - Add support for user-level vs system-level configuration based on privileges - Implement platform-specific default symlink paths - Update InitializeConfig() to use cross-platform defaults Key improvements: - Windows: C:\Java\JAVA_HOME (unchanged for compatibility) - Linux: /opt/jenv/java_home (system) or ~/.jenv/java_home (user) - macOS: /opt/jenv/java_home (system) or ~/.jenv/java_home (user) - Automatic privilege detection and path selection - Fallback mechanisms for edge cases This ensures jenv configuration works seamlessly across platforms while respecting user privileges and system conventions. The configuration files remain compatible between platforms for easy migration.
System tools enhancements: - Restore IsSymlink() function for symbolic link detection - Improve CreateSymlink() with intelligent permission handling - Add isSystemPath() function for Linux system directory detection - Implement smart privilege requirements (Windows vs Linux) - Add automatic parent directory creation for symlinks Style system improvements: - Add Warning style for better user feedback - Implement Warning color themes (orange variants) - Update ApplyTheme() to include Warning style - Support for light/dark/default theme warning colors Key improvements: - Linux: Only require root for system paths (/opt, /usr, etc.) - Windows: Maintain existing administrator requirement - Better error messages and user guidance - Consistent styling across platforms - Improved symlink reliability and error handling This ensures jenv works smoothly on Linux with appropriate permission handling while maintaining Windows compatibility and providing better user experience through improved styling and error messages.
… logic New init command: - Add dedicated 'jenv init' command for explicit initialization - Platform-specific initialization logic and user guidance - Clear permission requirements and privilege handling - Comprehensive next-steps guidance for users Root command improvements: - Replace automatic initialization with user-friendly prompts - Implement intelligent permission handling per platform - Add cross-platform privilege detection and warnings - Improve user experience with clear guidance messages Key features: - Windows: Requires administrator privileges (unchanged behavior) - Linux: Optional root privileges with graceful degradation - Clear warning messages for permission limitations - User-level vs system-level configuration explanation - Step-by-step setup guidance for new users Platform-specific behavior: - Windows: Mandatory admin check, exit if not admin - Linux: Warning for non-root, continue with user-level config - Consistent command interface across platforms - Better error messages and user guidance This change improves the user experience by making initialization explicit and providing clear guidance for different privilege levels and platforms.
…support Test coverage: - Add env_linux_test.go with comprehensive Linux environment variable tests - Test multi-shell detection and configuration - Test environment variable setting, updating, and removal - Test PATH cleaning and management functions - Test shell-specific configuration file updates - Validate cross-platform functionality Documentation updates: - Update README.md with Linux installation and usage instructions - Add cross-platform setup guidance and shell-specific instructions - Update feature descriptions to reflect Linux support completion - Add platform-specific scanning paths and examples - Include permission level explanations and troubleshooting New comprehensive documentation: - Add LINUX_CROSS_PLATFORM_SUPPORT.md with complete feature summary - Document all new and modified files with detailed explanations - Provide Linux-specific usage examples and best practices - Document platform differences and compatibility information - Include testing coverage and development guidelines Key test scenarios: - Multi-shell environment detection (bash, zsh, fish) - Environment variable persistence across shell sessions - Permission-based configuration (root vs user) - PATH management and cleaning operations - Configuration file creation and updates This ensures the Linux cross-platform support is thoroughly tested and well-documented for users and contributors.
…upport - Document all 6 feature commits with detailed descriptions - Provide complete file change summary and code statistics - Include quality assurance checklist and verification status - Add merge strategy recommendations and next steps - Document testing coverage and platform compatibility - Provide comprehensive overview of the entire feature implementation This summary serves as a complete reference for the Linux cross-platform support feature development and can be used for code review, documentation, and future maintenance purposes.
Remove shell_windows.go as Windows uses registry-based environment variable management, not shell configuration files. This eliminates: - Redundant environment variable management mechanisms - Potential conflicts between registry and shell configs - Non-standard Windows practices - Unnecessary code complexity (~300 lines) Windows will now exclusively use the standard registry approach for environment variables, which is the expected behavior for Windows users.
- Rename env_linux.go → env_unix.go to support both Linux and macOS - Rename env_linux_test.go → env_unix_test.go for broader Unix coverage - Update build tags from 'linux' to '!windows' for Unix-like systems - Add env_darwin.go for macOS-specific implementations if needed This change makes the environment variable management more inclusive of Unix-like systems while maintaining the same functionality. The shell-based environment variable approach is appropriate for all Unix-like systems (Linux, macOS, BSD, etc.).
Update shell.go to clarify that it's designed for Unix-like systems only: - Add documentation explaining Windows uses registry-based management - Maintain existing multi-shell support (bash, zsh, fish, profile) - Keep all shell detection and configuration functionality - Ensure build tags properly exclude Windows This makes the code intent clearer: Windows uses registry, Unix-like systems use shell configuration files.
Improve the init command to provide clear, platform-specific guidance: Windows: - Explain registry-based environment variable management - Require administrator privileges with clear error messages - Provide Windows-specific next steps and alternatives Unix-like systems: - Explain shell configuration file approach - Support both root and non-root users with appropriate messaging - Provide shell-specific reload instructions (bash, zsh, fish) - Show detected shell configurations This makes the initialization process much clearer for users on different platforms and sets proper expectations.
Update environment variable management interfaces: - Remove any remaining shell-related dependencies from Windows code - Ensure clean separation between Windows (registry) and Unix (shell) approaches - Maintain consistent interface while using platform-appropriate implementations - Update any cross-platform helper functions This ensures Windows exclusively uses registry management while Unix systems use shell configuration files, with no cross-contamination.
Update all documentation to reflect the simplified architecture: - README.md: Clarify platform-specific environment variable management - LINUX_CROSS_PLATFORM_SUPPORT.md: Update file lists and remove Windows shell references - WINDOWS_SHELL_REFACTOR_PROPOSAL.md: Add comprehensive refactor proposal - WINDOWS_SHELL_REFACTOR_SUMMARY.md: Document the completed refactor Key documentation changes: - Windows: Registry-based environment variable management (standard) - Unix: Shell configuration file-based management (standard) - Remove references to Windows shell configuration files - Add technical rationale for the architectural decision
Add project configuration files and assets: - .env.example: Environment variable template - .gitignore: Updated ignore patterns - jreleaser.yml: Release configuration updates - assets/theme.gif: Theme demonstration asset These files support the improved cross-platform functionality and project maintenance.
Add extensive project documentation: - doc/architecture.mmd & .svg: System architecture diagrams - doc/guide-zh.md: Chinese user guide - doc/contest*.md: Contest and promotion materials - doc/jenv-landing-page-requirements.md: Landing page specifications - doc/promotion-copy.md & tweet.md: Marketing materials These documents support project promotion, user onboarding, and technical understanding of the system architecture.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚀 Add comprehensive Linux cross-platform support and Windows shell refactor
📋 Summary
This PR adds complete Linux/Unix cross-platform support to jenv while refactoring Windows shell support for better architecture and user experience. The implementation provides native environment variable management for each platform using their respective best practices.
🎯 Key Features
✅ Linux/Unix Cross-Platform Support
✅ Windows Architecture Simplification
✅ Enhanced User Experience
jenv initcommand with platform-specific guidance📊 Technical Changes
New Files (6)
src/internal/shell/shell.go- Unix shell environment managementsrc/internal/shell/shell_test.go- Shell module testssrc/internal/env/env_unix.go- Unix environment variable managementsrc/internal/env/env_unix_test.go- Unix environment testssrc/cmd/init.go- New initialization commandModified Files (8)
src/internal/constants/constants.go- Cross-platform constantssrc/internal/config/config.go- Cross-platform configurationsrc/internal/sys/system.go- Enhanced system toolssrc/internal/style/styles.go&theme.go- Warning stylessrc/cmd/root.go- Cross-platform initialization logicREADME.md- Updated with Linux usage instructionsRemoved Files (1)
src/internal/shell/shell_windows.go- Unnecessary Windows shell support🏗️ Architecture Improvements
Before
After
🔧 Platform-Specific Implementation
Windows
Linux/Unix
📈 Code Quality Metrics
🧪 Testing
Automated Tests
Manual Testing
📚 Documentation
Updated Documentation
New Documentation
LINUX_CROSS_PLATFORM_SUPPORT.md- Complete feature guideWINDOWS_SHELL_REFACTOR_SUMMARY.md- Refactor explanationGIT_COMMIT_SUMMARY.md- Development history🎯 User Experience
Windows Users
Linux Users
⚡ Breaking Changes
None - This is a purely additive change that maintains full backward compatibility for existing Windows users.
🔍 Review Checklist
🚀 Deployment Notes
For Windows Users
For Linux Users
jenv initfor first-time setup📋 Post-Merge Tasks
🤝 Acknowledgments
This implementation was driven by the need for true cross-platform Java version management while respecting each platform's conventions and user expectations.
Ready for review and testing! 🎉