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

devonfw / IDEasy / 12875818493

20 Jan 2025 09:19PM UTC coverage: 68.372% (-0.1%) from 68.512%
12875818493

push

github

web-flow
#939: fix NPE on path completion and implement repository completion (#956)

2737 of 4375 branches covered (62.56%)

Branch coverage included in aggregate %.

7075 of 9976 relevant lines covered (70.92%)

3.09 hits per line

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

48.89
cli/src/main/java/com/devonfw/tools/ide/property/RepositoryProperty.java
1
package com.devonfw.tools.ide.property;
2

3
import java.nio.file.Files;
4
import java.nio.file.Path;
5

6
import com.devonfw.tools.ide.commandlet.Commandlet;
7
import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
8
import com.devonfw.tools.ide.context.IdeContext;
9
import com.devonfw.tools.ide.validation.PropertyValidator;
10

11
/**
12
 * Extends {@link FileProperty} for repository properties config file with auto-completion.
13
 */
14
public class RepositoryProperty extends FileProperty {
15

16
  public static final String EXTENSION_PROPERTIES = ".properties";
17

18
  /**
19
   * The constructor.
20
   *
21
   * @param name the {@link #getName() property name}.
22
   * @param required the {@link #isRequired() required flag}.
23
   * @param alias the {@link #getAlias() property alias}.
24
   */
25
  public RepositoryProperty(String name, boolean required, String alias) {
26

27
    super(name, required, alias, true);
6✔
28
  }
1✔
29

30
  /**
31
   * The constructor.
32
   *
33
   * @param name the {@link #getName() property name}.
34
   * @param required the {@link #isRequired() required flag}.
35
   * @param alias the {@link #getAlias() property alias}.
36
   * @param validator the {@link PropertyValidator} used to {@link #validate() validate} the {@link #getValue() value}.
37
   */
38
  public RepositoryProperty(String name, boolean required, String alias, PropertyValidator<Path> validator) {
39

40
    super(name, required, alias, true, validator);
×
41
  }
×
42

43
  @Override
44
  public Path parse(String valueAsString, IdeContext context) {
45

46
    if (valueAsString == null) {
2!
47
      return null;
×
48
    }
49
    Path repositoriesPath = null;
2✔
50
    Path repositoryFile = Path.of(valueAsString);
5✔
51
    if (!Files.exists(repositoryFile)) {
5!
52
      repositoryFile = null;
2✔
53
      repositoriesPath = context.getRepositoriesPath();
3✔
54
      if (repositoriesPath != null) {
2!
55
        String propertiesFileName = valueAsString;
2✔
56
        if (!valueAsString.endsWith(EXTENSION_PROPERTIES)) {
4!
57
          propertiesFileName += EXTENSION_PROPERTIES;
×
58
        }
59
        Path resolvedRepositoriesFile = repositoriesPath.resolve(propertiesFileName);
4✔
60
        if (Files.exists(resolvedRepositoriesFile)) {
5!
61
          repositoryFile = resolvedRepositoriesFile;
2✔
62
        }
63
      }
64
    }
65
    if (repositoryFile == null) {
2!
66
      throw new IllegalStateException("Could not find properties file: " + valueAsString + " in " + repositoriesPath);
×
67
    }
68
    return repositoryFile;
2✔
69
  }
70

71
  @Override
72
  protected void completeValue(String arg, IdeContext context, Commandlet commandlet, CompletionCandidateCollector collector) {
73

74
    Path repositoriesPath = context.getRepositoriesPath();
×
75
    if (repositoriesPath != null) {
×
76
      completeValuesFromFolder(repositoriesPath, arg, context, commandlet, collector);
×
77
    }
78
  }
×
79

80
  @Override
81
  protected String getPathForCompletion(Path path, IdeContext context, Commandlet commandlet) {
82

83
    String filename = path.getFileName().toString();
×
84
    if (filename.endsWith(EXTENSION_PROPERTIES)) {
×
85
      filename = filename.substring(0, filename.length() - EXTENSION_PROPERTIES.length());
×
86
    }
87
    return filename;
×
88
  }
89

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