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

devonfw / IDEasy / 11113446156

30 Sep 2024 08:14PM UTC coverage: 66.105% (-0.01%) from 66.116%
11113446156

push

github

web-flow
#652: properly report step success/error (#666)

2315 of 3848 branches covered (60.16%)

Branch coverage included in aggregate %.

6083 of 8856 relevant lines covered (68.69%)

3.03 hits per line

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

2.86
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.java.Java;
22
import com.devonfw.tools.ide.tool.plugin.ToolPluginDescriptor;
23

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

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

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

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

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

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

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

67
  @Override
68
  protected void installDependencies() {
69

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

74
  @Override
75
  public void installPlugin(ToolPluginDescriptor plugin, Step step) {
76

77
    ProcessResult result = runTool(ProcessMode.DEFAULT_CAPTURE, null, ProcessErrorHandling.LOG_WARNING, "-application", "org.eclipse.equinox.p2.director",
×
78
        "-repository", plugin.url(), "-installIU", plugin.id());
×
79
    if (result.isSuccessful()) {
×
80
      for (String line : result.getOut()) {
×
81
        if (line.contains("Overall install request is satisfiable")) {
×
82
          step.success();
×
83
          return;
×
84
        }
85
      }
×
86
    }
87
    log(IdeLogLevel.DEBUG, result.getOut());
×
88
    log(IdeLogLevel.ERROR, result.getErr());
×
89
    step.error("Failed to install plugin {} ({}): exit code was {}", plugin.name(), plugin.id(), result.getExitCode());
×
90
  }
×
91

92
  private void log(IdeLogLevel level, List<String> lines) {
93

94
    for (String line : lines) {
×
95
      if (line.startsWith("!MESSAGE ")) {
×
96
        line = line.substring(9);
×
97
      }
98
      this.context.level(level).log(line);
×
99
    }
×
100
  }
×
101

102
  @Override
103
  protected void configureWorkspace() {
104

105
    Path lockfile = this.context.getWorkspacePath().resolve(".metadata/.lock");
×
106
    if (isLocked(lockfile)) {
×
107
      throw new CliException("Your workspace is locked at " + lockfile);
×
108
    }
109
    super.configureWorkspace();
×
110
  }
×
111

112
  /**
113
   * @param lockfile the {@link File} pointing to the lockfile to check.
114
   * @return {@code true} if the given {@link File} is locked, {@code false} otherwise.
115
   */
116
  private static boolean isLocked(Path lockfile) {
117

118
    if (Files.isRegularFile(lockfile)) {
×
119
      try (RandomAccessFile raFile = new RandomAccessFile(lockfile.toFile(), "rw")) {
×
120
        FileLock fileLock = raFile.getChannel().tryLock(0, 1, false);
×
121
        // success, file was not locked so we immediately unlock again...
122
        fileLock.release();
×
123
        return false;
×
124
      } catch (Exception e) {
×
125
        return true;
×
126
      }
127
    }
128
    return false;
×
129
  }
130

131
}
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