Skip to content

Commit 255542a

Browse files
committed
devonfw#1008: improve upgrade-settings commandlet
1 parent be644c6 commit 255542a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

cli/src/main/java/com/devonfw/tools/ide/commandlet/UpgradeSettingsCommandlet.java

+45
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package com.devonfw.tools.ide.commandlet;
22

3+
import java.io.IOException;
34
import java.nio.file.Files;
45
import java.nio.file.Path;
6+
import java.nio.file.Paths;
57
import java.nio.file.StandardCopyOption;
8+
import java.nio.file.StandardOpenOption;
9+
import java.util.ArrayList;
10+
import java.util.List;
611
import java.util.function.Function;
712

813
import com.devonfw.tools.ide.context.IdeContext;
@@ -139,6 +144,7 @@ private void updateProperties(EnvironmentVariablesPropertiesFile environmentVari
139144
}
140145
updatePropertiesLegacyEdition(environmentVariables, "INTELLIJ_EDITION_TYPE", "INTELLIJ_EDITION", this::mapLegacyIntellijEdition);
141146
updatePropertiesLegacyEdition(environmentVariables, "ECLIPSE_EDITION_TYPE", "ECLIPSE_EDITION", this::mapLegacyEclipseEdition);
147+
cleanupLegacyProperties();
142148
environmentVariables.save();
143149
this.context.getFileAccess().backup(environmentVariables.getLegacyPropertiesFilePath());
144150
}
@@ -181,4 +187,43 @@ private static void updatePropertiesLegacyEdition(EnvironmentVariablesProperties
181187
environmentVariables.remove(legacyEditionVariable);
182188
}
183189
}
190+
191+
private void cleanupLegacyProperties() {
192+
this.context.info("Cleaning up legacy properties...");
193+
194+
Path rootDirectory = Paths.get(System.getProperty("user.dir"));
195+
try {
196+
Files.walk(rootDirectory)
197+
.filter(path -> path.getFileName().toString().equals("IDEasy.properties"))
198+
.forEach(filePath -> {
199+
try {
200+
updateProperties(filePath);
201+
} catch (IOException e) {
202+
this.context.warning("Error processing IDEasy.properties at " + filePath);
203+
}
204+
});
205+
} catch (IOException e) {
206+
this.context.warning("Error walking the file tree to find IDEasy.properties.");
207+
}
208+
}
209+
210+
private void updateProperties(Path filePath) throws IOException {
211+
List<String> lines = Files.readAllLines(filePath);
212+
List<String> updatedLines = new ArrayList<>();
213+
214+
for (String line : lines) {
215+
if (line.startsWith("git.url=") || line.startsWith("git-url")) {
216+
String gitUrl = line.substring("git.url=".length());
217+
updatedLines.add("git_url=" + gitUrl);
218+
continue;
219+
}
220+
if (line.startsWith("eclipse=import")) {
221+
updatedLines.add("import=eclipse");
222+
continue;
223+
}
224+
updatedLines.add(line);
225+
}
226+
Files.write(filePath, updatedLines, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
227+
this.context.success("Successfully updated IDEasy.properties at " + filePath);
228+
}
184229
}

0 commit comments

Comments
 (0)