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

devonfw / IDEasy / 20330220431

18 Dec 2025 07:58AM UTC coverage: 70.087% (+0.03%) from 70.061%
20330220431

push

github

hohwille
#1596: Add support for comma-separated workspace values in repository configuration (#1569)

Co-authored-by: Malte Brunnlieb <malte.brunnlieb@capgemini.com>
Co-authored-by: Malte Brunnlieb <maybeec@users.noreply.github.com>

3980 of 6253 branches covered (63.65%)

Branch coverage included in aggregate %.

10186 of 13959 relevant lines covered (72.97%)

3.15 hits per line

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

88.37
cli/src/main/java/com/devonfw/tools/ide/git/repository/RepositoryProperties.java
1
package com.devonfw.tools.ide.git.repository;
2

3
import java.nio.file.Path;
4
import java.util.ArrayList;
5
import java.util.Arrays;
6
import java.util.Collections;
7
import java.util.HashSet;
8
import java.util.List;
9
import java.util.Properties;
10
import java.util.Set;
11
import java.util.stream.Collectors;
12

13
import com.devonfw.tools.ide.cli.CliException;
14
import com.devonfw.tools.ide.context.IdeContext;
15

16
/**
17
 * {@link Properties} for {@link RepositoryConfig}.
18
 */
19
final class RepositoryProperties {
20

21
  private final Path file;
22

23
  private final Properties properties;
24

25
  private final IdeContext context;
26

27
  /**
28
   * The constructor.
29
   *
30
   * @param file the {@link Path} to the properties file.
31
   * @param context the {@link IdeContext}.
32
   */
33
  public RepositoryProperties(Path file, IdeContext context) {
34
    this(file, context, context.getFileAccess().readProperties(file));
8✔
35
  }
1✔
36

37
  /**
38
   * @param file the {@link Path} to the properties file.
39
   * @param context the {@link IdeContext}.
40
   * @param properties the actual {@link Properties} loaded from the file.
41
   */
42
  RepositoryProperties(Path file, IdeContext context, Properties properties) {
43
    super();
2✔
44
    this.file = file;
3✔
45
    this.properties = properties;
3✔
46
    this.context = context;
3✔
47
  }
1✔
48

49
  /**
50
   * @param name the name of the requested property.
51
   * @return the value of the requested property or {@code null} if undefined.
52
   */
53
  public String getProperty(String name) {
54
    return getProperty(name, false);
5✔
55
  }
56

57
  /**
58
   * @param name the name of the requested property.
59
   * @param required - {@code true} if the requested property is required, {@code false} otherwise.
60
   * @return the value of the requested property or {@code null} if undefined.
61
   */
62
  public String getProperty(String name, boolean required) {
63

64
    String value = this.properties.getProperty(name);
5✔
65
    if (value == null) {
2✔
66
      String legacyName = name.replace("_", ".");
5✔
67
      if (!legacyName.equals(name)) {
4✔
68
        value = getLegacyProperty(legacyName, name);
5✔
69
        if (value == null) {
2!
70
          legacyName = name.replace("_", "-");
5✔
71
          value = getLegacyProperty(legacyName, name);
5✔
72
        }
73
      }
74
    }
75
    if (isEmpty(value)) {
3✔
76
      if (required) {
2✔
77
        throw new CliException("The properties file " + this.file + " must have a non-empty value for the required property " + name);
9✔
78
      }
79
      return null;
2✔
80
    }
81
    return value;
2✔
82
  }
83

84
  private static boolean isEmpty(String value) {
85

86
    return (value == null) || value.isBlank();
9✔
87
  }
88

89
  private String getLegacyProperty(String legacyName, String name) {
90

91
    String value = this.properties.getProperty(legacyName);
5✔
92
    if (value != null) {
2!
93
      this.context.warning("The properties file {} uses the legacy property {} instead of {}", this.file, legacyName, name);
×
94
    }
95
    return value;
2✔
96
  }
97

98
  /**
99
   * @return the IDEs where to import the repository.
100
   */
101
  public Set<String> getImports() {
102

103
    String importProperty = this.properties.getProperty(RepositoryConfig.PROPERTY_IMPORT);
5✔
104
    if (importProperty != null) {
2✔
105
      if (importProperty.isEmpty()) {
3!
106
        return Set.of();
×
107
      }
108
      return Arrays.stream(importProperty.split(",")).map(String::trim).collect(Collectors.toUnmodifiableSet());
10✔
109
    }
110

111
    String legacyImportProperty = getLegacyProperty(RepositoryConfig.PROPERTY_ECLIPSE, RepositoryConfig.PROPERTY_IMPORT);
5✔
112
    if ("import".equals(legacyImportProperty)) {
4!
113
      this.context.warning("Property {} is deprecated and should be replaced with {} (invert key and value).", RepositoryConfig.PROPERTY_ECLIPSE,
×
114
          RepositoryConfig.PROPERTY_IMPORT);
115
      return Set.of("eclipse");
×
116
    } else {
117
      return Set.of();
2✔
118
    }
119
  }
120

121
  /**
122
   * @return the workspaces where to clone the repository. Returns a set containing "main" as default if not specified.
123
   */
124
  public List<String> getWorkspaces() {
125

126
    String workspaceProperty = this.properties.getProperty(RepositoryConfig.PROPERTY_WORKSPACES);
5✔
127
    if (workspaceProperty == null) {
2✔
128
      workspaceProperty = this.properties.getProperty("workspace");
5✔
129
      if (workspaceProperty != null) {
2✔
130
        this.context.debug("Property workspace is legacy, please change property name to workspaces in {}", this.file);
11✔
131
      }
132
    }
133
    if ((workspaceProperty != null) && !workspaceProperty.isEmpty()) {
5✔
134
      List<String> list = new ArrayList<>();
4✔
135
      Set<String> set = new HashSet<>();
4✔
136
      for (String workspace : workspaceProperty.split(",")) {
18✔
137
        workspace = workspace.trim();
3✔
138
        boolean added = set.add(workspace);
4✔
139
        if (added) {
2!
140
          list.add(workspace);
5✔
141
        } else {
142
          this.context.warning("Ignoring duplicate workspace {} from {}", workspace, workspaceProperty);
×
143
        }
144
      }
145
      return Collections.unmodifiableList(list);
3✔
146
    }
147
    return List.of(IdeContext.WORKSPACE_MAIN);
3✔
148
  }
149

150
}
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