Skip to content

Commit d8e1902

Browse files
leonrohne27KianRolfhohwillejan-vcapgemini
authored
#1008: improve upgrade settings (#1146)
Co-authored-by: KianRolf <kian.loroff@capgemini.com> Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com> Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>
1 parent 175374c commit d8e1902

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
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;
56
import java.nio.file.StandardCopyOption;
7+
import java.nio.file.StandardOpenOption;
8+
import java.util.List;
69
import java.util.function.Function;
710

811
import com.devonfw.tools.ide.context.IdeContext;
@@ -139,6 +142,7 @@ private void updateProperties(EnvironmentVariablesPropertiesFile environmentVari
139142
}
140143
updatePropertiesLegacyEdition(environmentVariables, "INTELLIJ_EDITION_TYPE", "INTELLIJ_EDITION", this::mapLegacyIntellijEdition);
141144
updatePropertiesLegacyEdition(environmentVariables, "ECLIPSE_EDITION_TYPE", "ECLIPSE_EDITION", this::mapLegacyEclipseEdition);
145+
cleanupLegacyProperties();
142146
environmentVariables.save();
143147
this.context.getFileAccess().backup(environmentVariables.getLegacyPropertiesFilePath());
144148
}
@@ -181,4 +185,53 @@ private static void updatePropertiesLegacyEdition(EnvironmentVariablesProperties
181185
environmentVariables.remove(legacyEditionVariable);
182186
}
183187
}
188+
189+
private void cleanupLegacyProperties() {
190+
this.context.info("Cleaning up legacy properties...");
191+
192+
Path settingsPath = context.getSettingsPath();
193+
Path repositoriesPath = settingsPath.resolve(IdeContext.FOLDER_REPOSITORIES);
194+
195+
FileAccess fileAccess = this.context.getFileAccess();
196+
if (fileAccess.isExpectedFolder(repositoriesPath)) {
197+
fileAccess.listChildrenMapped(repositoriesPath, child -> {
198+
try {
199+
if (Files.isRegularFile(child) && child.getFileName().toString().endsWith(".properties")) {
200+
updateRepositoryPropertiesFile(child);
201+
}
202+
} catch (IOException e) {
203+
throw new RuntimeException(e);
204+
}
205+
return null;
206+
});
207+
}
208+
}
209+
210+
private void updateRepositoryPropertiesFile(Path filePath) throws IOException {
211+
List<String> lines = Files.readAllLines(filePath);
212+
boolean updated = false;
213+
214+
for (int i = 0; i < lines.size(); i++) {
215+
String line = lines.get(i).trim();
216+
if (line.startsWith("git.url=") || line.startsWith("git-url")) {
217+
String gitUrl = line.substring(line.indexOf("=") + 1).trim();
218+
lines.set(i, "git_url=" + gitUrl);
219+
updated = true;
220+
continue;
221+
}
222+
if (line.startsWith("eclipse=import")) {
223+
lines.set(i, "import=eclipse");
224+
updated = true;
225+
}
226+
}
227+
if (updated) {
228+
try {
229+
Files.write(filePath, lines, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
230+
this.context.success("Successfully updated repository configuration file {}", filePath);
231+
} catch (IOException e) {
232+
this.context.error("Failed to write updated repository configuration file {}", filePath);
233+
throw e;
234+
}
235+
}
236+
}
184237
}

0 commit comments

Comments
 (0)