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

devonfw / IDEasy / 28817273758

06 Jul 2026 07:22PM UTC coverage: 71.829% (+0.03%) from 71.798%
28817273758

Pull #2120

github

web-flow
Merge 29a633b86 into 9d9b7004c
Pull Request #2120: #2118: replace java.io.File usages with java.nio.file.Path

4838 of 7432 branches covered (65.1%)

Branch coverage included in aggregate %.

12393 of 16557 relevant lines covered (74.85%)

3.17 hits per line

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

63.29
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.RandomAccessFile;
4
import java.nio.channels.FileLock;
5
import java.nio.file.Files;
6
import java.nio.file.Path;
7
import java.util.List;
8
import java.util.Set;
9

10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12

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

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

32
  private static final Logger LOG = LoggerFactory.getLogger(Eclipse.class);
4✔
33

34
  // version must correspond to eclipse-import.xml
35
  private static final String GROOVY_VERSION = "3.0.23";
36

37
  /** Eclipse CLI option for Java virtual machine arguments. */
38
  public static final String VMARGS = "-vmargs";
39

40
  private boolean groovyInstalled;
41

42
  /**
43
   * The constructor.
44
   *
45
   * @param context the {@link IdeContext}.
46
   */
47
  public Eclipse(IdeContext context) {
48

49
    super(context, "eclipse", Set.of(Tag.ECLIPSE));
6✔
50
  }
1✔
51

52
  @Override
53
  protected void configureToolBinary(ProcessContext pc, ProcessMode processMode) {
54

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

62
  @Override
63
  protected void configureToolArgs(ProcessContext pc, ProcessMode processMode, List<String> args) {
64

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

86
  @Override
87
  protected boolean isPluginUrlNeeded() {
88

89
    return true;
2✔
90
  }
91

92
  @Override
93
  public boolean installPlugin(ToolPluginDescriptor plugin, Step step, ProcessContext pc) {
94

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

111
  @Override
112
  protected void configureWorkspace() {
113

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

121
  /**
122
   * @param lockfile the {@link Path} pointing to the lockfile to check.
123
   * @return {@code true} if the given {@link Path} is locked, {@code false} otherwise.
124
   */
125
  private static boolean isLocked(Path lockfile) {
126

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

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