Skip to content
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

Fix Maven cache move #3898

Merged
merged 3 commits into from
Oct 1, 2024
Merged

Fix Maven cache move #3898

merged 3 commits into from
Oct 1, 2024

Conversation

SohamDas2021
Copy link
Contributor

@SohamDas2021 SohamDas2021 commented Sep 24, 2024

Summary of the pull request

Dev drive documentation initially suggested moving all contents of %userprofile%/.m2 to dev drive for optimization. However we only need to move contents of %userprofile%/.m2/repository to dev drive and set MAVEN_OPTS="-Dmaven.repo.local=<dev drive location for .m2\repository>"

References and relevant issues

#3336

Detailed description of the pull request / Additional comments

Validation steps performed

Manual tests. Tested with real Maven cache and repository.

if (string.Equals(variableName, "MAVEN_OPTS", StringComparison.OrdinalIgnoreCase))
{
var existingValue = Environment.GetEnvironmentVariable(variableName, EnvironmentVariableTarget.User);
var newValue = (!string.IsNullOrEmpty(existingValue) ? existingValue + " " : string.Empty) + "-Dmaven.repo.local = " + value;
Copy link
Contributor

@dhoehna dhoehna Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Consider making -Dmaven.repo.local = a const string in a common location. #WontFix

@SohamDas2021 SohamDas2021 marked this pull request as draft September 27, 2024 21:20
private void UpdateSettingsXML(string localRepositoryLocation)
{
int index = ExistingCacheLocation.IndexOf("repository", StringComparison.OrdinalIgnoreCase);
var settingsXMLPath = string.Concat(this.ExistingCacheLocation.AsSpan(0, index), "settings.xml");
Copy link
Contributor

@dhoehna dhoehna Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this #Resolved


private void UpdateSettingsXML(string localRepositoryLocation)
{
int index = ExistingCacheLocation.IndexOf("repository", StringComparison.OrdinalIgnoreCase);
Copy link
Contributor

@dhoehna dhoehna Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if -1 is returned? #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code won't execute if index is -1 here. So we are good.

if (File.Exists(settingsXMLPath))
{
// Update settings.xml with the new repository path
UpdateOrCreateSubkey(settingsXMLPath, key, subkey, localRepositoryLocation);
Copy link
Contributor

@dhoehna dhoehna Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment says Update... but the method name is UpdateOrCreate please update the comment. #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It updates or creates the subkey, not the file itself.

@SohamDas2021 SohamDas2021 marked this pull request as ready for review October 1, 2024 17:56
@SohamDas2021 SohamDas2021 merged commit 9654c0e into main Oct 1, 2024
4 checks passed
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.

3 participants