Skip to content

Commit 7b7d40a

Browse files
committed
feat: implement URL replacements for enterprise networks
This commit implements comprehensive URL replacement functionality for enterprise environments, along with shell integration, environment management improvements, and enhanced test reliability. **URL Replacement Features:** - Global URL replacement configuration in ~/.mvx/config.json5 - Support for simple string replacements (github.com -> nexus.internal) - Support for regex replacements with capture groups - CLI commands for managing URL replacements - Automatic integration with all tool downloads - First-match-wins processing for predictable behavior - Comprehensive validation for regex patterns **New CLI Commands:** - mvx config show - Display current global configuration - mvx config set-url-replacement <pattern> <replacement> - mvx config remove-url-replacement <pattern> - mvx config clear-url-replacements - mvx config edit - Open config file in editor **Shell Integration Features:** - mvx shell command for executing commands in mvx environment - Shell activation support for automatic environment setup - Cross-platform shell hooks and activation scripts - mvx activate/deactivate commands for shell integration - mvx env command for environment variable management **Environment Management Improvements:** - Safe environment variable management with EnvironmentManager - Intelligent PATH handling with deduplication - Change detection to reduce verbose logging noise - Track original environment variable values - Only log actual environment changes, not passthrough values **Test Reliability Improvements:** - Fix Java executable detection to prevent bin/bin/java path errors - Add proper working directory restoration in test cleanup - Skip 'bin' directories when searching for nested Java installations - Add comprehensive Java installation debug test for CI troubleshooting - Improved test isolation to prevent cross-test contamination **Technical Implementation:** - Added pkg/config/global.go for global configuration management - Added pkg/tools/url_replacements.go for URL replacement logic - Added pkg/tools/environment.go for safe environment variable management - Added pkg/util/log.go for centralized logging utilities - Enhanced EnvironmentManager with change detection capabilities - Integrated URL replacements into pkg/tools/download.go - Added comprehensive test suites and documentation **Files Added/Modified:** - cmd/config.go - CLI commands for configuration management - cmd/shell.go - Shell command implementation - cmd/activate.go - Shell activation support - cmd/deactivate.go - Shell deactivation support - cmd/env.go - Environment variable management - cmd/root.go - Register new commands - pkg/config/global.go - Global configuration management - pkg/tools/url_replacements.go - URL replacement logic - pkg/tools/environment.go - Environment variable management - pkg/tools/download.go - Integration with URL replacements - pkg/tools/manager.go - Enhanced tool management - pkg/util/log.go - Centralized logging utilities - website/content/url-replacements.md - Documentation - test/integration_test.go - Enhanced integration tests - test/java_debug_test.go - CI debugging capabilities This implementation uses global-only configuration for security and simplicity, avoiding the complexity of project-level overrides while providing enterprise users with the flexibility they need for internal mirrors and proxies. Closes #40
1 parent c41eb64 commit 7b7d40a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5981
-565
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,38 @@ jobs:
5353
# Test that wrapper works with current version
5454
./mvx version
5555
56+
- name: Check for website changes
57+
uses: dorny/paths-filter@v3
58+
id: website-changes
59+
with:
60+
filters: |
61+
website:
62+
- 'website/**'
63+
64+
- name: Set up JDK 21 for website
65+
if: steps.website-changes.outputs.website == 'true'
66+
uses: actions/setup-java@v4
67+
with:
68+
java-version: '21'
69+
distribution: 'temurin'
70+
cache: maven
71+
72+
- name: Check website build
73+
if: steps.website-changes.outputs.website == 'true'
74+
run: |
75+
OWNER=$(echo "$GITHUB_REPOSITORY" | cut -d '/' -f 1)
76+
REPO=$(echo "$GITHUB_REPOSITORY" | cut -d '/' -f 2)
77+
SITE_URL="https://${OWNER}.github.io"
78+
SITE_PATH="/${REPO}/"
79+
echo "SITE_URL=$SITE_URL" >> $GITHUB_ENV
80+
echo "SITE_PATH=$SITE_PATH" >> $GITHUB_ENV
81+
echo "GITHUB_REPOSITORY=$GITHUB_REPOSITORY SITE_DIR=$SITE_DIR SITE_URL=$SITE_URL SITE_PATH=$SITE_PATH"
82+
# Build website to catch template syntax errors
83+
cd website
84+
QUARKUS_ROQ_GENERATOR_BATCH=true mvn clean package quarkus:run -DskipTests --no-transfer-progress \
85+
-Dquarkus.http.root-path=$SITE_PATH \
86+
-Dsite.url=$SITE_URL
87+
5688
- name: Upload build artifacts
5789
uses: actions/upload-artifact@v4
5890
with:

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Imagine cloning any project and running:
2727
# Or use tools directly with natural syntax
2828
./mvx mvn -V clean install # Maven with version flag
2929
./mvx --verbose mvn -X test # mvx verbose + Maven debug
30+
31+
# Execute shell commands in mvx environment
32+
./mvx shell 'echo $JAVA_HOME' # Show Java home with mvx tools
33+
./mvx shell 'java -version' # Run Java with mvx environment
3034
```
3135

3236
No more "works on my machine" - every developer gets the exact same environment.
@@ -54,6 +58,7 @@ mvx provides seamless Maven integration with transparent argument passing:
5458
- **🔄 Transparent wrapper**: mvx acts like `mvnw` but with enhanced tool management
5559
- **⚡ No learning curve**: Existing Maven knowledge applies directly
5660
- **🛡️ Backward compatible**: Existing scripts continue to work
61+
- **🏢 Enterprise ready**: URL replacements for corporate networks and mirrors
5762

5863
## 📦 mvx Bootstrap
5964

@@ -199,6 +204,37 @@ cd mvx
199204
./mvx test
200205
```
201206

207+
## 🔄 Shell Activation
208+
209+
For a seamless development experience, enable shell activation to automatically set up your environment when entering project directories:
210+
211+
**Bash** - Add to `~/.bashrc`:
212+
```bash
213+
eval "$(mvx activate bash)"
214+
```
215+
216+
**Zsh** - Add to `~/.zshrc`:
217+
```bash
218+
eval "$(mvx activate zsh)"
219+
```
220+
221+
**Fish** - Add to `~/.config/fish/config.fish`:
222+
```bash
223+
mvx activate fish | source
224+
```
225+
226+
With shell activation enabled, tools become available automatically:
227+
228+
```bash
229+
cd my-project
230+
# mvx: activating environment in /Users/you/my-project
231+
232+
java -version # Uses mvx-managed Java
233+
mvn -version # Uses mvx-managed Maven
234+
```
235+
236+
**Learn more**: See the [Shell Activation Guide](https://gnodet.github.io/mvx/shell-activation/) for detailed documentation.
237+
202238
## 🎯 Shell Completion
203239

204240
mvx supports shell completion for commands and arguments across multiple shells (bash, zsh, fish, powershell):
@@ -354,6 +390,7 @@ The bootstrap scripts (`mvx` and `mvx.cmd`) are **shell/batch scripts** (not bin
354390
- [x] `mvx build` - Execute configured build commands
355391
- [x] `mvx test` - Execute configured test commands
356392
- [x] `mvx run` - Execute custom commands from configuration
393+
- [x] `mvx shell` - Execute shell commands in mvx environment
357394
- [x] `mvx tools` - Tool management and discovery
358395
- [x] `mvx info` - Detailed command information
359396

@@ -397,6 +434,12 @@ The bootstrap scripts (`mvx` and `mvx.cmd`) are **shell/batch scripts** (not bin
397434
- [x] **Intelligent interpreter selection** - Automatic selection based on script complexity
398435
- [x] **Cross-platform compatibility** - Commands work consistently across operating systems
399436

437+
#### Enterprise & Network Support
438+
439+
- [x] **URL replacements** - Redirect downloads through corporate proxies, mirrors, or alternative sources
440+
- [x] **Global configuration** - System-wide settings for enterprise environments
441+
- [x] **Regex-based URL transformations** - Advanced URL rewriting for complex enterprise setups
442+
400443
### 🚧 Planned Features
401444

402445
#### Extended Tool Support

cmd/activate.go

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
8+
"github.com/gnodet/mvx/pkg/shell"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// activateCmd represents the activate command
13+
var activateCmd = &cobra.Command{
14+
Use: "activate [shell]",
15+
Short: "Generate shell integration code for automatic environment activation",
16+
Long: `Generate shell integration code that automatically activates mvx when entering
17+
directories with .mvx configuration.
18+
19+
This command outputs shell-specific code that should be evaluated in your shell's
20+
configuration file (e.g., ~/.bashrc, ~/.zshrc, ~/.config/fish/config.fish).
21+
22+
When activated, mvx will:
23+
- Detect when you enter a directory with .mvx configuration
24+
- Automatically update PATH with mvx-managed tools
25+
- Set up environment variables from your configuration
26+
- Cache the environment to avoid repeated setup
27+
28+
Supported shells:
29+
- bash
30+
- zsh
31+
- fish
32+
- powershell
33+
34+
Examples:
35+
# Bash - add to ~/.bashrc
36+
eval "$(mvx activate bash)"
37+
38+
# Zsh - add to ~/.zshrc
39+
eval "$(mvx activate zsh)"
40+
41+
# Fish - add to ~/.config/fish/config.fish
42+
mvx activate fish | source
43+
44+
# PowerShell - add to $PROFILE
45+
Invoke-Expression (mvx activate powershell | Out-String)
46+
47+
After adding to your shell configuration, restart your shell or source the file:
48+
source ~/.bashrc # bash
49+
source ~/.zshrc # zsh
50+
source ~/.config/fish/config.fish # fish
51+
52+
Configuration:
53+
MVX_VERBOSE=true # Enable verbose output to see what mvx is doing`,
54+
55+
Args: cobra.ExactArgs(1),
56+
Run: func(cmd *cobra.Command, args []string) {
57+
shellType := args[0]
58+
59+
// Validate shell type
60+
validShells := []string{"bash", "zsh", "fish", "powershell"}
61+
isValid := false
62+
for _, s := range validShells {
63+
if s == shellType {
64+
isValid = true
65+
break
66+
}
67+
}
68+
69+
if !isValid {
70+
printError("Unsupported shell: %s", shellType)
71+
printError("Supported shells: bash, zsh, fish, powershell")
72+
os.Exit(1)
73+
}
74+
75+
// Get the path to the mvx binary
76+
mvxPath, err := getMvxBinaryPath()
77+
if err != nil {
78+
printError("Failed to determine mvx binary path: %v", err)
79+
os.Exit(1)
80+
}
81+
82+
// Generate shell hook
83+
hook, err := shell.GenerateHook(shellType, mvxPath)
84+
if err != nil {
85+
printError("Failed to generate shell hook: %v", err)
86+
os.Exit(1)
87+
}
88+
89+
// Output the hook (this will be evaluated by the shell)
90+
fmt.Print(hook)
91+
},
92+
}
93+
94+
// deactivateCmd represents the deactivate command
95+
var deactivateCmd = &cobra.Command{
96+
Use: "deactivate",
97+
Short: "Deactivate mvx shell integration",
98+
Long: `Deactivate mvx shell integration for the current shell session.
99+
100+
This command is automatically available after running 'mvx activate' and
101+
removes mvx-managed tools from PATH and unsets mvx environment variables.
102+
103+
Note: This only affects the current shell session. To permanently disable
104+
mvx activation, remove the 'eval "$(mvx activate ...)"' line from your
105+
shell configuration file.
106+
107+
Examples:
108+
mvx deactivate # Remove mvx from current session`,
109+
110+
Run: func(cmd *cobra.Command, args []string) {
111+
// This command is primarily handled by the shell hook itself
112+
// When called directly, we just provide information
113+
printInfo("To deactivate mvx in your current shell session:")
114+
printInfo("")
115+
printInfo(" Bash/Zsh:")
116+
printInfo(" Run: mvx_deactivate")
117+
printInfo("")
118+
printInfo(" Fish:")
119+
printInfo(" Run: mvx_deactivate")
120+
printInfo("")
121+
printInfo(" PowerShell:")
122+
printInfo(" Run: mvx-deactivate")
123+
printInfo("")
124+
printInfo("To permanently disable mvx activation, remove the activation")
125+
printInfo("line from your shell configuration file:")
126+
printInfo(" - Bash: ~/.bashrc")
127+
printInfo(" - Zsh: ~/.zshrc")
128+
printInfo(" - Fish: ~/.config/fish/config.fish")
129+
printInfo(" - PowerShell: $PROFILE")
130+
},
131+
}
132+
133+
// getMvxBinaryPath returns the path to the mvx binary
134+
func getMvxBinaryPath() (string, error) {
135+
// Try to get the path from the current executable
136+
exePath, err := os.Executable()
137+
if err != nil {
138+
return "", fmt.Errorf("failed to get executable path: %w", err)
139+
}
140+
141+
// Resolve symlinks
142+
exePath, err = filepath.EvalSymlinks(exePath)
143+
if err != nil {
144+
return "", fmt.Errorf("failed to resolve symlinks: %w", err)
145+
}
146+
147+
return exePath, nil
148+
}

0 commit comments

Comments
 (0)