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

devonfw / IDEasy / 11061200804

26 Sep 2024 10:27PM UTC coverage: 66.053% (-0.05%) from 66.107%
11061200804

push

github

web-flow
#593: #651: #564: #439: fixed bugs, refactored tool dependencies (#652)

2312 of 3848 branches covered (60.08%)

Branch coverage included in aggregate %.

6078 of 8854 relevant lines covered (68.65%)

3.03 hits per line

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

2.9
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
          return;
×
83
        }
84
      }
×
85
    }
86
    this.context.error("Failed to install plugin {} ({}): exit code was {}", plugin.name(), plugin.id(), result.getExitCode());
×
87
    log(IdeLogLevel.DEBUG, result.getOut());
×
88
    log(IdeLogLevel.ERROR, result.getErr());
×
89
  }
×
90

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

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

101
  @Override
102
  protected void configureWorkspace() {
103

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

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

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

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