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

devonfw / IDEasy / 13210157275

08 Feb 2025 12:10AM UTC coverage: 68.25% (-0.1%) from 68.379%
13210157275

Pull #1021

github

web-flow
Merge 93d542ee7 into 9c2006bd8
Pull Request #1021: #786: support ide upgrade to automatically update to the latest version of IDEasy

2910 of 4683 branches covered (62.14%)

Branch coverage included in aggregate %.

7563 of 10662 relevant lines covered (70.93%)

3.09 hits per line

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

38.55
cli/src/main/java/com/devonfw/tools/ide/merge/PropertiesMerger.java
1
package com.devonfw.tools.ide.merge;
2

3
import java.nio.file.Files;
4
import java.nio.file.Path;
5
import java.util.Properties;
6
import java.util.Set;
7

8
import com.devonfw.tools.ide.context.IdeContext;
9
import com.devonfw.tools.ide.environment.EnvironmentVariables;
10
import com.devonfw.tools.ide.environment.SortedProperties;
11
import com.devonfw.tools.ide.io.FileAccess;
12

13
/**
14
 * Implementation of {@link FileMerger} for {@link Properties} files.
15
 */
16
public class PropertiesMerger extends FileMerger {
17

18
  /**
19
   * The constructor.
20
   *
21
   * @param context the {@link #context}.
22
   */
23
  public PropertiesMerger(IdeContext context) {
24

25
    super(context);
3✔
26
  }
1✔
27

28
  @Override
29
  protected void doMerge(Path setup, Path update, EnvironmentVariables resolver, Path workspace) {
30

31
    FileAccess fileAccess = this.context.getFileAccess();
4✔
32
    SortedProperties properties = new SortedProperties();
4✔
33
    boolean updateFileExists = Files.exists(update);
5✔
34
    Path template = setup;
2✔
35
    if (Files.exists(workspace)) {
5✔
36
      if (!updateFileExists) {
2!
37
        this.context.trace("Nothing to do as update file does not exist: {}", update);
×
38
        return; // nothing to do ...
×
39
      }
40
      fileAccess.readProperties(workspace, properties);
5✔
41
    } else if (Files.exists(setup)) {
5✔
42
      fileAccess.readProperties(setup, properties);
4✔
43
    }
44
    if (updateFileExists) {
2!
45
      fileAccess.readProperties(update, properties);
4✔
46
      template = update;
2✔
47
    }
48
    resolve(properties, resolver, template.toString());
6✔
49
    fileAccess.writeProperties(properties, workspace, true);
5✔
50
    this.context.trace("Saved merged properties to: {}", workspace);
10✔
51
  }
1✔
52

53
  private void resolve(Properties properties, EnvironmentVariables variables, Object src) {
54

55
    Set<Object> keys = properties.keySet();
3✔
56
    for (Object key : keys) {
9✔
57
      String value = properties.getProperty(key.toString());
5✔
58
      properties.setProperty(key.toString(), variables.resolve(value, src, this.legacySupport));
11✔
59
    }
1✔
60
  }
1✔
61

62
  @Override
63
  public void inverseMerge(Path workspace, EnvironmentVariables variables, boolean addNewProperties, Path update) {
64

65
    if (!Files.exists(workspace)) {
×
66
      this.context.trace("Workspace file does not exist: {}", workspace);
×
67
      return;
×
68
    }
69
    if (!Files.exists(update)) {
×
70
      this.context.trace("Update file does not exist: {}", update);
×
71
      return;
×
72
    }
73
    Object src = workspace.getFileName();
×
74
    FileAccess fileAccess = this.context.getFileAccess();
×
75
    Properties updateProperties = fileAccess.readProperties(update);
×
76
    Properties workspaceProperties = fileAccess.readProperties(workspace);
×
77
    SortedProperties mergedProperties = new SortedProperties();
×
78
    mergedProperties.putAll(updateProperties);
×
79
    boolean updated = false;
×
80
    for (Object key : workspaceProperties.keySet()) {
×
81
      Object workspaceValue = workspaceProperties.get(key);
×
82
      Object updateValue = updateProperties.get(key);
×
83
      if ((updateValue != null) || addNewProperties) {
×
84
        String updateValueResolved = null;
×
85
        if (updateValue != null) {
×
86
          updateValueResolved = variables.resolve(updateValue.toString(), src, this.legacySupport);
×
87
        }
88
        if (!workspaceValue.equals(updateValueResolved)) {
×
89
          String workspaceValueInverseResolved = variables.inverseResolve(workspaceValue.toString(), src);
×
90
          mergedProperties.put(key, workspaceValueInverseResolved);
×
91
          updated = true;
×
92
        }
93
      }
94
    }
×
95
    if (updated) {
×
96
      fileAccess.writeProperties(mergedProperties, update);
×
97
      this.context.debug("Saved changes from: {} to: {}", workspace.getFileName(), update);
×
98
    } else {
99
      this.context.trace("No changes for: {}", update);
×
100
    }
101
  }
×
102

103
  @Override
104
  protected boolean doUpgrade(Path workspaceFile) throws Exception {
105

106
    return doUpgradeTextContent(workspaceFile);
×
107
  }
108
}
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

© 2026 Coveralls, Inc