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

devonfw / IDEasy / 20003978026

07 Dec 2025 12:09PM UTC coverage: 70.101% (+0.2%) from 69.903%
20003978026

push

github

web-flow
#39: refactoring to extract package-manager logic out of node/npm (#1638)

3892 of 6090 branches covered (63.91%)

Branch coverage included in aggregate %.

9955 of 13663 relevant lines covered (72.86%)

3.15 hits per line

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

62.82
cli/src/main/java/com/devonfw/tools/ide/tool/eclipse/Eclipse.java
1
package com.devonfw.tools.ide.tool.eclipse;
2

3
import java.io.File;
4
import java.io.RandomAccessFile;
5
import java.nio.channels.FileLock;
6
import java.nio.file.Files;
7
import java.nio.file.Path;
8
import java.util.List;
9
import java.util.Set;
10

11
import com.devonfw.tools.ide.cli.CliException;
12
import com.devonfw.tools.ide.common.Tag;
13
import com.devonfw.tools.ide.context.IdeContext;
14
import com.devonfw.tools.ide.log.IdeLogLevel;
15
import com.devonfw.tools.ide.process.ProcessContext;
16
import com.devonfw.tools.ide.process.ProcessErrorHandling;
17
import com.devonfw.tools.ide.process.ProcessMode;
18
import com.devonfw.tools.ide.process.ProcessResult;
19
import com.devonfw.tools.ide.step.Step;
20
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
21
import com.devonfw.tools.ide.tool.mvn.Mvn;
22
import com.devonfw.tools.ide.tool.mvn.MvnArtifact;
23
import com.devonfw.tools.ide.tool.plugin.ToolPluginDescriptor;
24

25
/**
26
 * {@link IdeToolCommandlet} for <a href="https://www.eclipse.org/">Eclipse</a>.
27
 */
28
public class Eclipse extends IdeToolCommandlet {
29

30
  // version must correspond to eclipse-import.xml
31
  private static final String GROOVY_VERSION = "3.0.23";
32

33
  /** Eclipse CLI option for Java virtual machine arguments. */
34
  public static final String VMARGS = "-vmargs";
35

36
  private boolean groovyInstalled;
37

38
  /**
39
   * The constructor.
40
   *
41
   * @param context the {@link IdeContext}.
42
   */
43
  public Eclipse(IdeContext context) {
44

45
    super(context, "eclipse", Set.of(Tag.ECLIPSE));
6✔
46
  }
1✔
47

48
  @Override
49
  protected void configureToolBinary(ProcessContext pc, ProcessMode processMode) {
50

51
    if (!processMode.isBackground() && this.context.getSystemInfo().isWindows()) {
8✔
52
      pc.executable(Path.of("eclipsec"));
8✔
53
    } else {
54
      super.configureToolBinary(pc, processMode);
4✔
55
    }
56
  }
1✔
57

58
  @Override
59
  protected void configureToolArgs(ProcessContext pc, ProcessMode processMode, List<String> args) {
60

61
    // configure workspace location
62
    pc.addArg("-data").addArg(this.context.getWorkspacePath());
8✔
63
    // use keyring from user home to keep secrets and share across projects and workspaces
64
    pc.addArg("-keyring").addArg(this.context.getUserHome().resolve(".eclipse").resolve(".keyring"));
12✔
65
    // use isolated plugins folder from project instead of modifying eclipse installation in software repo on plugin installation
66
    pc.addArg("-configuration").addArg(getPluginsInstallationPath().resolve("configuration"));
9✔
67
    if (processMode == ProcessMode.BACKGROUND) {
3✔
68
      // to start eclipse as GUI
69
      pc.addArg("gui").addArg("-showlocation").addArg(this.context.getIdeHome().getFileName());
12✔
70
    } else {
71
      pc.addArg("-consoleLog").addArg("-nosplash");
6✔
72
    }
73
    super.configureToolArgs(pc, processMode, args);
5✔
74
    if ((!args.isEmpty()) && !VMARGS.equals(args.getFirst())) {
8!
75
      String vmArgs = this.context.getVariables().get("ECLIPSE_VMARGS");
6✔
76
      if ((vmArgs != null) && !vmArgs.isEmpty()) {
2!
77
        pc.addArg(VMARGS).addArg(vmArgs);
×
78
      }
79
    }
80
  }
1✔
81

82
  @Override
83
  protected boolean isPluginUrlNeeded() {
84

85
    return true;
2✔
86
  }
87

88
  @Override
89
  public boolean installPlugin(ToolPluginDescriptor plugin, Step step, ProcessContext pc) {
90

91
    ProcessResult result = runTool(pc, ProcessMode.DEFAULT_CAPTURE, List.of("-application", "org.eclipse.equinox.p2.director",
10✔
92
        "-repository", plugin.url(), "-installIU", plugin.id()));
4✔
93
    if (result.isSuccessful()) {
3!
94
      for (String line : result.getOut()) {
11!
95
        if (line.contains("Overall install request is satisfiable")) {
4✔
96
          this.context.success("Successfully installed plugin: {}", plugin.name());
11✔
97
          step.success();
2✔
98
          return true;
2✔
99
        }
100
      }
1✔
101
    }
102
    result.log(IdeLogLevel.DEBUG, context, IdeLogLevel.ERROR);
×
103
    step.error("Failed to install plugin {} ({}): exit code was {}", plugin.name(), plugin.id(), result.getExitCode());
×
104
    return false;
×
105
  }
106

107
  @Override
108
  protected void configureWorkspace() {
109

110
    Path lockfile = this.context.getWorkspacePath().resolve(".metadata/.lock");
6✔
111
    if (isLocked(lockfile)) {
3!
112
      throw new CliException("Your workspace is locked at " + lockfile);
×
113
    }
114
    super.configureWorkspace();
2✔
115
  }
1✔
116

117
  /**
118
   * @param lockfile the {@link File} pointing to the lockfile to check.
119
   * @return {@code true} if the given {@link File} is locked, {@code false} otherwise.
120
   */
121
  private static boolean isLocked(Path lockfile) {
122

123
    if (Files.isRegularFile(lockfile)) {
5!
124
      try (RandomAccessFile raFile = new RandomAccessFile(lockfile.toFile(), "rw")) {
×
125
        FileLock fileLock = raFile.getChannel().tryLock(0, 1, false);
×
126
        // success, file was not locked so we immediately unlock again...
127
        fileLock.release();
×
128
        return false;
×
129
      } catch (Exception e) {
×
130
        return true;
×
131
      }
132
    }
133
    return false;
2✔
134
  }
135

136
  @Override
137
  public void importRepository(Path repositoryPath) {
138
    if (!this.groovyInstalled) {
×
139
      Mvn maven = this.context.getCommandletManager().getCommandlet(Mvn.class);
×
140
      MvnArtifact groovyAnt = new MvnArtifact("org.codehaus.groovy", "groovy-ant", GROOVY_VERSION);
×
141
      maven.getOrDownloadArtifact(groovyAnt);
×
142
      this.groovyInstalled = true;
×
143
    }
144
    // -DdevonImportPath=\"${import_path}\" -DdevonImportWorkingSet=\"${importWorkingSets}\""
145
    runTool(ProcessMode.DEFAULT, null, ProcessErrorHandling.THROW_CLI, List.of(VMARGS,
×
146
        "-DrepositoryImportPath=\"" + repositoryPath + "\" -DrepositoryImportWorkingSet=\"" + "" + "\"", "-application", "org.eclipse.ant.core.antRunner",
147
        "-buildfile", this.context.getIdeInstallationPath().resolve(IdeContext.FOLDER_INTERNAL).resolve("eclipse-import.xml").toString()));
×
148
  }
×
149
}
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