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

devonfw / IDEasy / 13063227142

30 Jan 2025 11:31PM UTC coverage: 68.379% (-0.2%) from 68.557%
13063227142

Pull #990

github

web-flow
Merge dde1c0e39 into aaf4eb4e0
Pull Request #990: #954: improve repository support

2857 of 4597 branches covered (62.15%)

Branch coverage included in aggregate %.

7391 of 10390 relevant lines covered (71.14%)

3.1 hits per line

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

82.93
cli/src/main/java/com/devonfw/tools/ide/tool/plugin/ToolPluginDescriptor.java
1
package com.devonfw.tools.ide.tool.plugin;
2

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

8
import com.devonfw.tools.ide.common.Tag;
9
import com.devonfw.tools.ide.common.Tags;
10
import com.devonfw.tools.ide.context.IdeContext;
11
import com.devonfw.tools.ide.log.IdeLogger;
12

13
/**
14
 * Implementation of {@link ToolPluginDescriptor}.
15
 *
16
 * @param id the unique identifier of the plugin.
17
 * @param name the name of the plugin properties file excluding the extension.
18
 * @param url the optional plugin URL (download/update site).
19
 * @param active {@code true} if the plugin is active and shall be installed automatically, {@code false} otherwise.
20
 * @param tags the {@link #tags () tags}.
21
 */
22
public record ToolPluginDescriptor(String id, String name, String url, boolean active, Set<Tag> tags) implements Tags {
18✔
23

24
  @Override
25
  public Set<Tag> getTags() {
26

27
    return this.tags;
×
28
  }
29

30
  /**
31
   * @param propertiesFile the {@link Path} to the plugin {@link Properties} file.
32
   * @param context the {@link IdeContext}.
33
   * @param needUrl - {@code true} if {@link ToolPluginDescriptor#url () URL} needs to be present and a warning shall be logged if missing, {@code false}
34
   *     otherwise.
35
   * @return the loaded {@link ToolPluginDescriptor}.
36
   */
37
  public static ToolPluginDescriptor of(Path propertiesFile, IdeContext context, boolean needUrl) {
38

39
    String name = propertiesFile.getFileName().toString();
4✔
40
    name = name.substring(0, name.length() - IdeContext.EXT_PROPERTIES.length());
9✔
41
    Properties properties = context.getFileAccess().readProperties(propertiesFile);
5✔
42
    String id = getString(properties, "id", "plugin_id");
5✔
43
    String url = getString(properties, "url", "plugin_url");
5✔
44
    if (needUrl && ((url == null) || url.isBlank())) {
7!
45
      context.warning("Missing plugin URL in {}", propertiesFile);
×
46
    }
47
    boolean active = getBoolean(properties, "active", "plugin_active", propertiesFile, context);
7✔
48
    String tagsCsv = getString(properties, "tags", "plugin_tags");
5✔
49
    Set<Tag> tags = Tag.parseCsv(tagsCsv);
3✔
50
    return new ToolPluginDescriptor(id, name, url, active, tags);
9✔
51
  }
52

53
  private static boolean getBoolean(Properties properties, String key, String legacyKey, Path propertiesFile,
54
      IdeLogger logger) {
55

56
    String value = getString(properties, key, legacyKey);
5✔
57
    if (value == null) {
2✔
58
      return false;
2✔
59
    }
60
    String lower = value.toLowerCase(Locale.ROOT);
4✔
61
    if ("true".equals(lower)) {
4✔
62
      return true;
2✔
63
    } else if ("false".equals(lower)) {
4!
64
      return false;
2✔
65
    }
66
    logger.warning("Invalid boolean value '{}' for property '{}' in {}", value, key, propertiesFile);
×
67
    return false;
×
68
  }
69

70
  private static String getString(Properties properties, String key, String legacyKey) {
71

72
    String value = properties.getProperty(key);
4✔
73
    if (value == null) {
2✔
74
      value = properties.getProperty(legacyKey);
4✔
75
    }
76
    return value;
2✔
77
  }
78

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