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

devonfw / IDEasy / 16294769564

15 Jul 2025 01:34PM UTC coverage: 68.52% (+0.07%) from 68.446%
16294769564

Pull #1408

github

web-flow
Merge 54e79f74c into ab7eb024e
Pull Request #1408: Fix IDEasy complete double-matching issue by preventing duplicate candidates

3291 of 5206 branches covered (63.22%)

Branch coverage included in aggregate %.

8419 of 11884 relevant lines covered (70.84%)

3.13 hits per line

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

78.69
cli/src/main/java/com/devonfw/tools/ide/tool/ide/IdeToolCommandlet.java
1
package com.devonfw.tools.ide.tool.ide;
2

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

7
import com.devonfw.tools.ide.common.Tag;
8
import com.devonfw.tools.ide.context.IdeContext;
9
import com.devonfw.tools.ide.io.FileAccess;
10
import com.devonfw.tools.ide.process.ProcessContext;
11
import com.devonfw.tools.ide.process.ProcessMode;
12
import com.devonfw.tools.ide.step.Step;
13
import com.devonfw.tools.ide.tool.ToolCommandlet;
14
import com.devonfw.tools.ide.tool.eclipse.Eclipse;
15
import com.devonfw.tools.ide.tool.intellij.Intellij;
16
import com.devonfw.tools.ide.tool.plugin.PluginBasedCommandlet;
17
import com.devonfw.tools.ide.tool.vscode.Vscode;
18

19
/**
20
 * {@link ToolCommandlet} for an IDE (integrated development environment) such as {@link Eclipse}, {@link Vscode}, or {@link Intellij}.
21
 */
22
public abstract class IdeToolCommandlet extends PluginBasedCommandlet {
1✔
23

24
  /**
25
   * The constructor.
26
   *
27
   * @param context the {@link IdeContext}.
28
   * @param tool the {@link #getName() tool name}.
29
   * @param tags the {@link #getTags() tags} classifying the tool. Should be created via {@link Set#of(Object) Set.of} method.
30
   */
31
  public IdeToolCommandlet(IdeContext context, String tool, Set<Tag> tags) {
32

33
    super(context, tool, tags);
5✔
34
    assert (hasIde(tags));
5!
35
  }
1✔
36

37
  private boolean hasIde(Set<Tag> tags) {
38

39
    for (Tag tag : tags) {
10!
40
      if (tag.isAncestorOf(Tag.IDE) || (tag == Tag.IDE)) {
7!
41
        return true;
2✔
42
      }
43
    }
×
44
    throw new IllegalStateException("Tags of IdeTool has to be connected with tag IDE: " + tags);
×
45
  }
46

47
  @Override
48
  public final void run() {
49
    super.run();
2✔
50
  }
1✔
51

52
  @Override
53
  public void runTool(String... args) {
54

55
    runTool(ProcessMode.BACKGROUND, null, args);
5✔
56
  }
1✔
57

58
  @Override
59
  public boolean install(boolean silent, ProcessContext processContext, Step step) {
60

61
    configureWorkspace();
2✔
62
    return super.install(silent, processContext, step);
6✔
63
  }
64

65
  /**
66
   * Configure (initialize or update) the workspace for this IDE using the templates from the settings.
67
   */
68
  protected void configureWorkspace() {
69

70
    FileAccess fileAccess = this.context.getFileAccess();
4✔
71
    Path workspaceFolder = this.context.getWorkspacePath();
4✔
72
    if (!fileAccess.isExpectedFolder(workspaceFolder)) {
4!
73
      this.context.warning("Current workspace does not exist: {}", workspaceFolder);
×
74
      return; // should actually never happen...
×
75
    }
76
    Step step = this.context.newStep("Configuring workspace " + workspaceFolder.getFileName() + " for IDE " + this.tool);
10✔
77
    step.run(() -> doMergeWorkspaceStep(step, workspaceFolder));
12✔
78
  }
1✔
79

80
  private void doMergeWorkspaceStep(Step step, Path workspaceFolder) {
81

82
    int errors = 0;
2✔
83
    errors = mergeWorkspace(this.context.getUserHomeIde(), workspaceFolder, errors);
8✔
84
    errors = mergeWorkspace(this.context.getSettingsPath(), workspaceFolder, errors);
8✔
85
    errors = mergeWorkspace(this.context.getConfPath(), workspaceFolder, errors);
8✔
86
    if (errors == 0) {
2!
87
      step.success();
3✔
88
    } else {
89
      step.error("Your workspace configuration failed with {} error(s) - see log above.\n"
×
90
          + "This is either a configuration error in your settings git repository or a bug in IDEasy.\n"
91
          + "Please analyze the above errors with your team or IDE-admin and try to fix the problem.", errors);
×
92
      this.context.askToContinue(
×
93
          "In order to prevent you from being blocked, you can start your IDE anyhow but some configuration may not be in sync.");
94
    }
95
  }
1✔
96

97
  private int mergeWorkspace(Path configFolder, Path workspaceFolder, int errors) {
98

99
    int result = errors;
2✔
100
    result = mergeWorkspaceSingle(configFolder.resolve(IdeContext.FOLDER_WORKSPACE), workspaceFolder, result);
8✔
101
    result = mergeWorkspaceSingle(configFolder.resolve(this.tool).resolve(IdeContext.FOLDER_WORKSPACE), workspaceFolder, result);
11✔
102
    return result;
2✔
103
  }
104

105
  private int mergeWorkspaceSingle(Path templatesFolder, Path workspaceFolder, int errors) {
106

107
    Path setupFolder = templatesFolder.resolve(IdeContext.FOLDER_SETUP);
4✔
108
    Path updateFolder = templatesFolder.resolve(IdeContext.FOLDER_UPDATE);
4✔
109
    if (!Files.isDirectory(setupFolder) && !Files.isDirectory(updateFolder)) {
10✔
110
      this.context.trace("Skipping empty or non-existing workspace template folder {}.", templatesFolder);
10✔
111
      return errors;
2✔
112
    }
113
    this.context.debug("Merging workspace templates from {}...", templatesFolder);
10✔
114
    return errors + this.context.getWorkspaceMerger().merge(setupFolder, updateFolder, this.context.getVariables(), workspaceFolder);
13✔
115
  }
116

117
  /**
118
   * Imports the repository specified by the given {@link Path} into the IDE managed by this {@link IdeToolCommandlet}.
119
   *
120
   * @param repositoryPath the {@link Path} to the repository directory to import.
121
   */
122
  public void importRepository(Path repositoryPath) {
123

124
    throw new UnsupportedOperationException("Repository import is not yet implemented for IDE " + this.tool);
×
125
  }
126
}
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