Skip to content

Refactor getMavenConfigurationFolder #1294

@jan-vcapgemini

Description

@jan-vcapgemini

We need to remove the redundant implementation of getMavenConfiguration in IdeContext:

/**
* @return the {@link Path} pointing to the maven configuration directory (where "settings.xml" or "settings-security.xml" are located).
*/
default Path getMavenConfigurationFolder() {
Path confPath = getConfPath();
Path mvnConfFolder = null;
if (confPath != null) {
mvnConfFolder = confPath.resolve(Mvn.MVN_CONFIG_FOLDER);
if (!Files.isDirectory(mvnConfFolder)) {
Path m2LegacyFolder = confPath.resolve(Mvn.MVN_CONFIG_LEGACY_FOLDER);
if (Files.isDirectory(m2LegacyFolder)) {
mvnConfFolder = m2LegacyFolder;
} else {
mvnConfFolder = null; // see fallback below
}
}
}
if (mvnConfFolder == null) {
// fallback to USER_HOME/.m2 folder
mvnConfFolder = getUserHome().resolve(Mvn.MVN_CONFIG_LEGACY_FOLDER);
}
return mvnConfFolder;
}

And in Mvn
/**
* @param legacy - {@code true} to enforce legacy fallback creation, {@code false} otherwise.
* @return the {@link Path} to the maven configuration folder (where "settings.xml" can be found).
*/
public Path getMavenConfFolder(boolean legacy) {
Path confPath = this.context.getConfPath();
Path mvnConfigFolder = confPath.resolve(MVN_CONFIG_FOLDER);
if (!Files.isDirectory(mvnConfigFolder)) {
Path mvnConfigLegacyFolder = confPath.resolve(Mvn.MVN_CONFIG_LEGACY_FOLDER);
if (Files.isDirectory(mvnConfigLegacyFolder)) {
mvnConfigFolder = mvnConfigLegacyFolder;
} else {
if (legacy) {
mvnConfigFolder = mvnConfigLegacyFolder;
}
this.context.getFileAccess().mkdirs(mvnConfigFolder);
}
}
return mvnConfigFolder;
}

The implementation in IdeContext should be replaced by Mvn to follow SoC.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestinternalNothing to be added to CHANGELOG, only internal story

Type

Projects

Status

✅ Done

Relationships

None yet

Development

No branches or pull requests

Issue actions