Skip to content

Commit

Permalink
use linkset instead of list
Browse files Browse the repository at this point in the history
  • Loading branch information
mvomiero committed May 10, 2024
1 parent 86a2206 commit d746a46
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions cli/src/main/java/com/devonfw/tools/ide/tool/mvn/Mvn.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -34,7 +33,7 @@ public class Mvn extends PluginBasedCommandlet {
/** The name of the settings.xml */
public static final String SETTINGS_FILE = "settings.xml";

private static final String M2_REPO = ".m2";
private static final String M2_CONFIG_FOLDER = ".m2";

private static final String SETTINGS_SECURITY_FILE = "settings-security.xml";

Expand Down Expand Up @@ -80,7 +79,7 @@ public void postInstall() {
}

Path settingsFile = this.context.getConfPath().resolve(MVN_CONFIG_FOLDER).resolve(SETTINGS_FILE);
if (!Files.exists(settingsFile)) {
if (!Files.exists(settingsFile) && Files.exists(settingsSecurityFile)) {
Step step = this.context.newStep("Create mvn settings file at " + settingsFile);
try {
createSettingsFile(settingsFile, settingsSecurityFile);
Expand Down Expand Up @@ -122,7 +121,7 @@ private void createSettingsFile(Path settingsFile, Path settingsSecurityFile) {
Path settingsTemplate = this.context.getSettingsPath().resolve(IdeContext.FOLDER_TEMPLATES).resolve(IdeContext.FOLDER_CONF).resolve(MVN_CONFIG_FOLDER)
.resolve(SETTINGS_FILE);
if (!Files.exists(settingsTemplate)) {
settingsTemplate = this.context.getSettingsPath().resolve(IdeContext.FOLDER_LEGACY_TEMPLATES).resolve(IdeContext.FOLDER_CONF).resolve(M2_REPO)
settingsTemplate = this.context.getSettingsPath().resolve(IdeContext.FOLDER_LEGACY_TEMPLATES).resolve(IdeContext.FOLDER_CONF).resolve(M2_CONFIG_FOLDER)
.resolve(SETTINGS_FILE);
if (!Files.exists(settingsTemplate)) {
this.context.warning(SETTINGS_FILE + " template not found in settings folder. " + ERROR_SETTINGS_FILE_MESSAGE, settingsFile);
Expand All @@ -142,7 +141,7 @@ private void createSettingsFile(Path settingsFile, Path settingsSecurityFile) {
}

if (!gitSettingsUrl.equals(gitContext.DEFAULT_SETTINGS_GIT_URL)) {
List<String> variables = findVariables(content);
Set<String> variables = findVariables(content);
for (String variable : variables) {
String secret = getEncryptedPassword(variable, settingsSecurityFile);
content = content.replace("$[" + variable + "]", secret);
Expand Down Expand Up @@ -170,15 +169,13 @@ private String getEncryptedPassword(String variable, Path settingsSecurityFile)
return encryptedPassword;
}

private List<String> findVariables(String content) {
private Set<String> findVariables(String content) {

List<String> variables = new ArrayList<>();
Set<String> variables = new LinkedHashSet<>();
Matcher matcher = VARIABLE_PATTERN.matcher(content);
while (matcher.find()) {
String variableName = matcher.group(1);
if (!variables.contains(variableName)) {
variables.add(variableName);
}
variables.add(variableName);
}
return variables;
}
Expand Down

0 comments on commit d746a46

Please sign in to comment.