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

devonfw / IDEasy / 11611100303

31 Oct 2024 11:29AM UTC coverage: 66.915% (+0.2%) from 66.715%
11611100303

push

github

web-flow
#608: enhance error messages (#653)

2415 of 3952 branches covered (61.11%)

Branch coverage included in aggregate %.

6302 of 9075 relevant lines covered (69.44%)

3.06 hits per line

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

75.0
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.Set;
9

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

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

28
  /**
29
   * The constructor.
30
   *
31
   * @param context the {@link IdeContext}.
32
   */
33
  public Eclipse(IdeContext context) {
34

35
    super(context, "eclipse", Set.of(Tag.ECLIPSE));
6✔
36
  }
1✔
37

38
  @Override
39
  protected void configureToolBinary(ProcessContext pc, ProcessMode processMode, ProcessErrorHandling errorHandling) {
40

41
    if ((processMode == ProcessMode.DEFAULT_CAPTURE) && this.context.getSystemInfo().isWindows()) {
8✔
42
      pc.executable(Path.of("eclipsec"));
8✔
43
    } else {
44
      super.configureToolBinary(pc, processMode, errorHandling);
5✔
45
    }
46
  }
1✔
47

48
  @Override
49
  protected void configureToolArgs(ProcessContext pc, ProcessMode processMode, ProcessErrorHandling errorHandling, String... args) {
50

51
    // configure workspace location
52
    pc.addArg("-data").addArg(this.context.getWorkspacePath());
8✔
53
    // use keyring from user home to keep secrets and share across projects and workspaces
54
    pc.addArg("-keyring").addArg(this.context.getUserHome().resolve(".eclipse").resolve(".keyring"));
12✔
55
    // use isolated plugins folder from project instead of modifying eclipse installation in software repo on plugin installation
56
    pc.addArg("-configuration").addArg(getPluginsInstallationPath().resolve("configuration"));
9✔
57
    if (processMode == ProcessMode.BACKGROUND) {
3✔
58
      // to start eclipse as GUI
59
      pc.addArg("gui").addArg("-showlocation").addArg(this.context.getIdeHome().getFileName());
12✔
60
    } else if (processMode == ProcessMode.DEFAULT_CAPTURE) {
3!
61
      pc.addArg("-consoleLog").addArg("-nosplash");
6✔
62
    }
63
    super.configureToolArgs(pc, processMode, errorHandling, args);
6✔
64
  }
1✔
65

66
  @Override
67
  protected void installDependencies() {
68

69
    // TODO create eclipse/eclipse/dependencies.json file in ide-urls and delete this method
70
    getCommandlet(Java.class).install();
6✔
71
  }
1✔
72

73
  @Override
74
  protected boolean isPluginUrlNeeded() {
75

76
    return true;
2✔
77
  }
78

79
  @Override
80
  public void installPlugin(ToolPluginDescriptor plugin, Step step) {
81

82
    ProcessResult result = runTool(ProcessMode.DEFAULT_CAPTURE, null, ProcessErrorHandling.LOG_WARNING, "-application", "org.eclipse.equinox.p2.director",
23✔
83
        "-repository", plugin.url(), "-installIU", plugin.id());
11✔
84
    if (result.isSuccessful()) {
3!
85
      for (String line : result.getOut()) {
11!
86
        if (line.contains("Overall install request is satisfiable")) {
4✔
87
          step.success();
2✔
88
          return;
1✔
89
        }
90
      }
1✔
91
    }
92

93
    result.log(IdeLogLevel.DEBUG, context, IdeLogLevel.ERROR);
×
94
    step.error("Failed to install plugin {} ({}): exit code was {}", plugin.name(), plugin.id(), result.getExitCode());
×
95
  }
×
96

97
  @Override
98
  protected void configureWorkspace() {
99

100
    Path lockfile = this.context.getWorkspacePath().resolve(".metadata/.lock");
6✔
101
    if (isLocked(lockfile)) {
3!
102
      throw new CliException("Your workspace is locked at " + lockfile);
×
103
    }
104
    super.configureWorkspace();
2✔
105
  }
1✔
106

107
  /**
108
   * @param lockfile the {@link File} pointing to the lockfile to check.
109
   * @return {@code true} if the given {@link File} is locked, {@code false} otherwise.
110
   */
111
  private static boolean isLocked(Path lockfile) {
112

113
    if (Files.isRegularFile(lockfile)) {
5!
114
      try (RandomAccessFile raFile = new RandomAccessFile(lockfile.toFile(), "rw")) {
×
115
        FileLock fileLock = raFile.getChannel().tryLock(0, 1, false);
×
116
        // success, file was not locked so we immediately unlock again...
117
        fileLock.release();
×
118
        return false;
×
119
      } catch (Exception e) {
×
120
        return true;
×
121
      }
122
    }
123
    return false;
2✔
124
  }
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

© 2026 Coveralls, Inc