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

devonfw / IDEasy / 11560364436

28 Oct 2024 06:31PM UTC coverage: 66.705% (-0.04%) from 66.746%
11560364436

push

github

web-flow
#710: make workspace configuration robust (#719)

2406 of 3950 branches covered (60.91%)

Branch coverage included in aggregate %.

6275 of 9064 relevant lines covered (69.23%)

3.05 hits per line

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

63.38
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()) {
8✔
43
      pc.executable(Path.of("eclipsec"));
8✔
44
    } else {
45
      super.configureToolBinary(pc, processMode, errorHandling);
5✔
46
    }
47
  }
1✔
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());
8✔
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"));
12✔
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"));
9✔
58
    if (processMode == ProcessMode.BACKGROUND) {
3✔
59
      // to start eclipse as GUI
60
      pc.addArg("gui").addArg("-showlocation").addArg(this.context.getIdeHome().getFileName());
12✔
61
    } else if (processMode == ProcessMode.DEFAULT_CAPTURE) {
3!
62
      pc.addArg("-consoleLog").addArg("-nosplash");
6✔
63
    }
64
    super.configureToolArgs(pc, processMode, errorHandling, args);
6✔
65
  }
1✔
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();
6✔
72
  }
1✔
73

74
  @Override
75
  protected boolean isPluginUrlNeeded() {
76

77
    return true;
2✔
78
  }
79

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

83
    ProcessResult result = runTool(ProcessMode.DEFAULT_CAPTURE, null, ProcessErrorHandling.LOG_WARNING, "-application", "org.eclipse.equinox.p2.director",
23✔
84
        "-repository", plugin.url(), "-installIU", plugin.id());
11✔
85
    if (result.isSuccessful()) {
3!
86
      for (String line : result.getOut()) {
11!
87
        if (line.contains("Overall install request is satisfiable")) {
4✔
88
          step.success();
2✔
89
          return;
1✔
90
        }
91
      }
1✔
92
    }
93
    log(IdeLogLevel.DEBUG, result.getOut());
×
94
    log(IdeLogLevel.ERROR, result.getErr());
×
95
    step.error("Failed to install plugin {} ({}): exit code was {}", plugin.name(), plugin.id(), result.getExitCode());
×
96
  }
×
97

98
  private void log(IdeLogLevel level, List<String> lines) {
99

100
    for (String line : lines) {
×
101
      if (line.startsWith("!MESSAGE ")) {
×
102
        line = line.substring(9);
×
103
      }
104
      this.context.level(level).log(line);
×
105
    }
×
106
  }
×
107

108
  @Override
109
  protected void configureWorkspace() {
110

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

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

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

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

© 2025 Coveralls, Inc