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

devonfw / IDEasy / 13206540769

07 Feb 2025 07:17PM UTC coverage: 68.469% (+0.09%) from 68.379%
13206540769

push

github

web-flow
#982: ability for user specific workspace configuration templates (#1010)

Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>

2863 of 4595 branches covered (62.31%)

Branch coverage included in aggregate %.

7393 of 10384 relevant lines covered (71.2%)

3.1 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