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

devonfw / IDEasy / 14856597402

06 May 2025 09:45AM UTC coverage: 67.59% (-0.08%) from 67.672%
14856597402

Pull #1242

github

web-flow
Merge d3d39f777 into a0320eff8
Pull Request #1242: #809: Enhance uninstall with --force to remove from the software repo

3108 of 5006 branches covered (62.09%)

Branch coverage included in aggregate %.

7997 of 11424 relevant lines covered (70.0%)

3.06 hits per line

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

77.59
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.ProcessMode;
11
import com.devonfw.tools.ide.step.Step;
12
import com.devonfw.tools.ide.tool.ToolCommandlet;
13
import com.devonfw.tools.ide.tool.eclipse.Eclipse;
14
import com.devonfw.tools.ide.tool.intellij.Intellij;
15
import com.devonfw.tools.ide.tool.plugin.PluginBasedCommandlet;
16
import com.devonfw.tools.ide.tool.vscode.Vscode;
17

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

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

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

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

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

46
  @Override
47
  public final void run() {
48
    configureWorkspace();
2✔
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
  /**
59
   * Configure the workspace for this IDE using the templates from the settings.
60
   */
61
  protected void configureWorkspace() {
62

63
    FileAccess fileAccess = this.context.getFileAccess();
4✔
64
    Path workspaceFolder = this.context.getWorkspacePath();
4✔
65
    if (!fileAccess.isExpectedFolder(workspaceFolder)) {
4!
66
      this.context.warning("Current workspace does not exist: {}", workspaceFolder);
×
67
      return; // should actually never happen...
×
68
    }
69
    try (Step step = this.context.newStep("Configuring workspace " + workspaceFolder.getFileName() + " for IDE " + this.tool)) {
10✔
70
      int errors = 0;
2✔
71
      errors = mergeWorkspace(this.context.getUserHomeIde(), workspaceFolder, errors);
8✔
72
      errors = mergeWorkspace(this.context.getSettingsPath(), workspaceFolder, errors);
8✔
73
      errors = mergeWorkspace(this.context.getConfPath(), workspaceFolder, errors);
8✔
74
      if (errors == 0) {
2!
75
        step.success();
3✔
76
      } else {
77
        step.error("Your workspace configuration failed with {} error(s) - see log above.\n"
×
78
            + "This is either a configuration error in your settings git repository or a bug in IDEasy.\n"
79
            + "Please analyze the above errors with your team or IDE-admin and try to fix the problem.", errors);
×
80
        this.context.askToContinue(
×
81
            "In order to prevent you from being blocked, you can start your IDE anyhow but some configuration may not be in sync.");
82
      }
83
    }
84
  }
1✔
85

86
  private int mergeWorkspace(Path configFolder, Path workspaceFolder, int errors) {
87

88
    int result = errors;
2✔
89
    result = mergeWorkspaceSingle(configFolder.resolve(IdeContext.FOLDER_WORKSPACE), workspaceFolder, result);
8✔
90
    result = mergeWorkspaceSingle(configFolder.resolve(this.tool).resolve(IdeContext.FOLDER_WORKSPACE), workspaceFolder, result);
11✔
91
    return result;
2✔
92
  }
93

94
  private int mergeWorkspaceSingle(Path templatesFolder, Path workspaceFolder, int errors) {
95

96
    Path setupFolder = templatesFolder.resolve(IdeContext.FOLDER_SETUP);
4✔
97
    Path updateFolder = templatesFolder.resolve(IdeContext.FOLDER_UPDATE);
4✔
98
    if (!Files.isDirectory(setupFolder) && !Files.isDirectory(updateFolder)) {
10✔
99
      this.context.trace("Skipping empty or non-existing workspace template folder {}.", templatesFolder);
10✔
100
      return errors;
2✔
101
    }
102
    this.context.debug("Merging workspace templates from {}...", templatesFolder);
10✔
103
    return errors + this.context.getWorkspaceMerger().merge(setupFolder, updateFolder, this.context.getVariables(), workspaceFolder);
13✔
104
  }
105

106
  /**
107
   * Imports the repository specified by the given {@link Path} into the IDE managed by this {@link IdeToolCommandlet}.
108
   *
109
   * @param repositoryPath the {@link Path} to the repository directory to import.
110
   */
111
  public void importRepository(Path repositoryPath) {
112

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