-
Notifications
You must be signed in to change notification settings - Fork 36
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
#1008: improve upgrade settings #1146
base: main
Are you sure you want to change the base?
Changes from 14 commits
68623eb
ee0472a
9dcfdc1
f832220
49ef8ef
0dcb661
e37e0b4
c359522
2c30607
e8a9fc0
be644c6
255542a
9610ea9
2dfc249
6345aa9
ad54840
f890489
e17e2b5
2c26a35
e6105ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package com.devonfw.tools.ide.commandlet; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.StandardCopyOption; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import com.devonfw.tools.ide.context.IdeContext; | ||
|
@@ -139,6 +144,7 @@ private void updateProperties(EnvironmentVariablesPropertiesFile environmentVari | |
} | ||
updatePropertiesLegacyEdition(environmentVariables, "INTELLIJ_EDITION_TYPE", "INTELLIJ_EDITION", this::mapLegacyIntellijEdition); | ||
updatePropertiesLegacyEdition(environmentVariables, "ECLIPSE_EDITION_TYPE", "ECLIPSE_EDITION", this::mapLegacyEclipseEdition); | ||
cleanupLegacyProperties(); | ||
environmentVariables.save(); | ||
this.context.getFileAccess().backup(environmentVariables.getLegacyPropertiesFilePath()); | ||
} | ||
|
@@ -181,4 +187,43 @@ private static void updatePropertiesLegacyEdition(EnvironmentVariablesProperties | |
environmentVariables.remove(legacyEditionVariable); | ||
} | ||
} | ||
|
||
private void cleanupLegacyProperties() { | ||
this.context.info("Cleaning up legacy properties..."); | ||
|
||
Path rootDirectory = Paths.get(System.getProperty("user.dir")); | ||
try { | ||
Files.walk(rootDirectory) | ||
.filter(path -> path.getFileName().toString().equals("IDEasy.properties")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obsolete but for the record. This filename |
||
.forEach(filePath -> { | ||
try { | ||
updateProperties(filePath); | ||
} catch (IOException e) { | ||
this.context.warning("Error processing IDEasy.properties at " + filePath); | ||
} | ||
}); | ||
} catch (IOException e) { | ||
this.context.warning("Error walking the file tree to find IDEasy.properties."); | ||
} | ||
} | ||
|
||
private void updateProperties(Path filePath) throws IOException { | ||
leonrohne27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
List<String> lines = Files.readAllLines(filePath); | ||
List<String> updatedLines = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: You can do the modifications directly in the original list ( |
||
|
||
for (String line : lines) { | ||
if (line.startsWith("git.url=") || line.startsWith("git-url")) { | ||
String gitUrl = line.substring("git.url=".length()); | ||
updatedLines.add("git_url=" + gitUrl); | ||
continue; | ||
} | ||
if (line.startsWith("eclipse=import")) { | ||
updatedLines.add("import=eclipse"); | ||
hohwille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue; | ||
} | ||
updatedLines.add(line); | ||
} | ||
Files.write(filePath, updatedLines, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should add a boolean flag |
||
this.context.success("Successfully updated IDEasy.properties at " + filePath); | ||
leonrohne27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont hardcode
user.dir
this will cause JUnits to apply the migration in your home directory but tests should only work in test directories (./target/
) and should never cause such side-effects.Also the variable name could be named more intuitive:
However, why are you searching recursively for
IDEasy.properties
files in the users home directory?This does not make sense.
What you IMHO actually need is something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW: Instead of using
Files.list
directly what also requires a catch statement that I omitted, it seems smarter that you usefileAccess
like already done in the same class here:IDEasy/cli/src/main/java/com/devonfw/tools/ide/commandlet/UpgradeSettingsCommandlet.java
Lines 83 to 89 in 8a9936e
This allows to supply a lambda function that is called for each file found in the directory (you can configure if only flat or recursively). That lambda function is used to map and filter the found child
Path
objects. When it returnsnull
the child is filtered and not returned. You could even map if fromPath
to some other Java type likeString
in this function. By directly applying the modification as "side-effect" inside the lambda function the result of thelistChildrenMapped
method can be ignored. In the example code the side effect ismerger.upgrade
and in your case it would beupdateProperties
instead.