• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 13694215079

06 Mar 2025 08:20AM UTC coverage: 68.249% (-0.004%) from 68.253%
13694215079

push

github

web-flow
#910 Can not update intellij on linux (#1101)

Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>
Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>

3032 of 4891 branches covered (61.99%)

Branch coverage included in aggregate %.

7868 of 11080 relevant lines covered (71.01%)

3.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.2
cli/src/main/java/com/devonfw/tools/ide/commandlet/UpgradeSettingsCommandlet.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import java.nio.file.Files;
4
import java.nio.file.Path;
5
import java.nio.file.StandardCopyOption;
6
import java.util.function.Function;
7

8
import com.devonfw.tools.ide.context.IdeContext;
9
import com.devonfw.tools.ide.environment.EnvironmentVariables;
10
import com.devonfw.tools.ide.environment.EnvironmentVariablesPropertiesFile;
11
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
12
import com.devonfw.tools.ide.io.FileAccess;
13
import com.devonfw.tools.ide.merge.DirectoryMerger;
14
import com.devonfw.tools.ide.tool.mvn.Mvn;
15
import com.devonfw.tools.ide.tool.repository.CustomToolsJson;
16
import com.devonfw.tools.ide.tool.repository.CustomToolsJsonMapper;
17
import com.devonfw.tools.ide.variable.IdeVariables;
18
import com.devonfw.tools.ide.variable.VariableDefinition;
19

20
/**
21
 * {@link Commandlet} to upgrade settings after a migration from devonfw-ide to IDEasy.
22
 */
23
public class UpgradeSettingsCommandlet extends Commandlet {
24

25
  /**
26
   * The constructor.
27
   *
28
   * @param context the {@link IdeContext}.
29
   */
30
  public UpgradeSettingsCommandlet(IdeContext context) {
31

32
    super(context);
3✔
33
    addKeyword(getName());
4✔
34
  }
1✔
35

36
  @Override
37
  public String getName() {
38

39
    return "upgrade-settings";
2✔
40
  }
41

42
  @Override
43
  public void run() {
44
    updateLegacyFolders();
2✔
45
    updateProperties();
2✔
46
    updateWorkspaceTemplates();
2✔
47
  }
1✔
48

49
  private void updateLegacyFolders() {
50
    this.context.info("Updating legacy folders if present...");
4✔
51
    Path settingsPath = context.getSettingsPath();
4✔
52
    updateLegacyFolder(settingsPath, IdeContext.FOLDER_LEGACY_REPOSITORIES, IdeContext.FOLDER_REPOSITORIES);
5✔
53
    updateLegacyFolder(settingsPath, IdeContext.FOLDER_LEGACY_TEMPLATES, IdeContext.FOLDER_TEMPLATES);
5✔
54
    updateLegacyFolder(settingsPath.resolve(IdeContext.FOLDER_TEMPLATES).resolve(IdeContext.FOLDER_CONF), Mvn.MVN_CONFIG_LEGACY_FOLDER, Mvn.MVN_CONFIG_FOLDER);
9✔
55
  }
1✔
56

57
  private void updateLegacyFolder(Path folder, String legacyName, String newName) {
58
    FileAccess fileAccess = this.context.getFileAccess();
4✔
59
    Path legacyFolder = folder.resolve(legacyName);
4✔
60
    Path newFolder = folder.resolve(newName);
4✔
61
    if (fileAccess.isExpectedFolder(legacyFolder)) {
4✔
62
      try {
63
        if (!Files.exists(newFolder)) {
5!
64
          fileAccess.move(legacyFolder, newFolder, StandardCopyOption.REPLACE_EXISTING);
10✔
65
          this.context.success("Successfully renamed folder '{}' to '{}' in {}.", legacyName, newName, folder);
18✔
66
        }
67
      } catch (IllegalStateException e) {
×
68
        this.context.error(e, "Error renaming folder {} to {} in {}", legacyName, newName, folder);
×
69
      }
1✔
70
    }
71
  }
1✔
72

73
  private void updateWorkspaceTemplates() {
74
    this.context.info("Updating workspace templates (replace legacy variables and change variable syntax)...");
4✔
75

76
    FileAccess fileAccess = this.context.getFileAccess();
4✔
77
    DirectoryMerger merger = this.context.getWorkspaceMerger();
4✔
78
    Path settingsDir = this.context.getSettingsPath();
4✔
79
    Path workspaceDir = settingsDir.resolve(IdeContext.FOLDER_WORKSPACE);
4✔
80
    if (fileAccess.isExpectedFolder(workspaceDir)) {
4!
81
      merger.upgrade(workspaceDir);
3✔
82
    }
83
    fileAccess.listChildrenMapped(settingsDir, child -> {
7✔
84
      Path childWorkspaceDir = child.resolve(IdeContext.FOLDER_WORKSPACE);
4✔
85
      if (fileAccess.isExpectedFolder(childWorkspaceDir)) {
4✔
86
        merger.upgrade(childWorkspaceDir);
3✔
87
      }
88
      return null;
2✔
89
    });
90
  }
1✔
91

92
  private void updateProperties() {
93
    // updates DEVON_IDE_CUSTOM_TOOLS to new ide-custom-tools.json
94
    String devonCustomTools = IdeVariables.DEVON_IDE_CUSTOM_TOOLS.get(this.context);
6✔
95
    if (devonCustomTools != null) {
2✔
96
      CustomToolsJson customToolsJson = CustomToolsJsonMapper.parseCustomToolsFromLegacyConfig(devonCustomTools, context);
5✔
97
      if (customToolsJson != null) {
2!
98
        CustomToolsJsonMapper.saveJson(customToolsJson, this.context.getSettingsPath().resolve(IdeContext.FILE_CUSTOM_TOOLS));
7✔
99
      }
100
    }
101

102
    // update properties (devon.properties -> ide.properties, convert legacy properties)
103
    EnvironmentVariables environmentVariables = context.getVariables();
4✔
104
    while (environmentVariables != null) {
2✔
105
      if (environmentVariables instanceof EnvironmentVariablesPropertiesFile environmentVariablesProperties) {
6✔
106
        updateProperties(environmentVariablesProperties);
3✔
107
      }
108
      environmentVariables = environmentVariables.getParent();
4✔
109
    }
110
    Path templatePropertiesDir = this.context.getSettingsTemplatePath().resolve(IdeContext.FOLDER_CONF);
6✔
111
    if (Files.exists(templatePropertiesDir)) {
5!
112
      EnvironmentVariablesPropertiesFile environmentVariablesProperties = new EnvironmentVariablesPropertiesFile(null, EnvironmentVariablesType.CONF,
10✔
113
          templatePropertiesDir, null, this.context);
114
      updateProperties(environmentVariablesProperties);
3✔
115
    }
116
  }
1✔
117

118
  private void updateProperties(EnvironmentVariablesPropertiesFile environmentVariables) {
119
    Path propertiesFilePath = environmentVariables.getPropertiesFilePath();
3✔
120
    if (environmentVariables.getLegacyConfiguration() != null) {
3!
121
      if (environmentVariables.getType() == EnvironmentVariablesType.SETTINGS) {
4✔
122
        // adds disabled legacySupportEnabled variable if missing in ide.properties
123
        environmentVariables.set(IdeVariables.IDE_VARIABLE_SYNTAX_LEGACY_SUPPORT_ENABLED.getName(), "false", false);
7✔
124
      }
125
      environmentVariables.remove(IdeVariables.DEVON_IDE_CUSTOM_TOOLS.getName());
4✔
126
      for (VariableDefinition<?> var : IdeVariables.VARIABLES) {
10✔
127
        String legacyName = var.getLegacyName();
3✔
128
        if (legacyName != null) {
2✔
129
          String value = environmentVariables.get(legacyName);
4✔
130
          if (value != null) {
2!
131
            String name = var.getName();
×
132
            String newValue = environmentVariables.get(name);
×
133
            if (newValue == null) {
×
134
              environmentVariables.set(name, value, environmentVariables.isExported(name));
×
135
            }
136
          }
137
          environmentVariables.remove(legacyName);
3✔
138
        }
139
      }
1✔
140
      updatePropertiesLegacyEdition(environmentVariables, "INTELLIJ_EDITION_TYPE", "INTELLIJ_EDITION", this::mapLegacyIntellijEdition);
6✔
141
      updatePropertiesLegacyEdition(environmentVariables, "ECLIPSE_EDITION_TYPE", "ECLIPSE_EDITION", this::mapLegacyEclipseEdition);
6✔
142
      environmentVariables.save();
2✔
143
      this.context.getFileAccess().backup(environmentVariables.getLegacyPropertiesFilePath());
7✔
144
    }
145
  }
1✔
146

147
  private String mapLegacyIntellijEdition(String legacyEdition) {
148

149
    return switch (legacyEdition) {
9!
150
      case "U" -> "ultimate";
2✔
151
      case "C" -> "intellij";
×
152
      default -> {
153
        this.context.warning("Undefined legacy edition {}", legacyEdition);
×
154
        yield "intellij";
×
155
      }
156
    };
157
  }
158

159
  private String mapLegacyEclipseEdition(String legacyEdition) {
160

161
    return switch (legacyEdition) {
×
162
      case "java" -> "eclipse";
×
163
      case "jee" -> "jee";
×
164
      case "cpp" -> "cpp";
×
165
      default -> {
166
        this.context.warning("Undefined legacy edition {}", legacyEdition);
×
167
        yield "eclipse";
×
168
      }
169
    };
170
  }
171

172
  private static void updatePropertiesLegacyEdition(EnvironmentVariablesPropertiesFile environmentVariables, String legacyEditionVariable,
173
      String newEditionVariable, Function<String, String> editionMapper) {
174

175
    String legacyEdition = environmentVariables.get(legacyEditionVariable);
4✔
176
    if (legacyEdition != null) {
2✔
177
      String newEdition = environmentVariables.get(newEditionVariable);
4✔
178
      if (newEdition == null) {
2✔
179
        environmentVariables.set(newEditionVariable, editionMapper.apply(legacyEdition), false);
9✔
180
      }
181
      environmentVariables.remove(legacyEditionVariable);
3✔
182
    }
183
  }
1✔
184
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc