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

devonfw / IDEasy / 13210157275

08 Feb 2025 12:10AM UTC coverage: 68.25% (-0.1%) from 68.379%
13210157275

Pull #1021

github

web-flow
Merge 93d542ee7 into 9c2006bd8
Pull Request #1021: #786: support ide upgrade to automatically update to the latest version of IDEasy

2910 of 4683 branches covered (62.14%)

Branch coverage included in aggregate %.

7563 of 10662 relevant lines covered (70.93%)

3.09 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

49
    configureWorkspace();
2✔
50
    super.run();
2✔
51
  }
1✔
52

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

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

59
  /**
60
   * Configure the workspace for this IDE using the templates from the settings.
61
   */
62
  protected void configureWorkspace() {
63

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

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

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

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

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

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

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