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

devonfw / IDEasy / 13334469710

14 Feb 2025 05:41PM UTC coverage: 68.482% (+0.009%) from 68.473%
13334469710

push

github

web-flow
#1023: remove hardcoded dependencies for eclipse and use dependencies.json (#1032)

2865 of 4597 branches covered (62.32%)

Branch coverage included in aggregate %.

7395 of 10385 relevant lines covered (71.21%)

3.1 hits per line

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

62.34
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.mvn.Mvn;
21
import com.devonfw.tools.ide.tool.mvn.MvnArtifact;
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
  // version must correspond to eclipse-import.xml
30
  private static final String GROOVY_VERSION = "3.0.23";
31

32
  /** Eclipse CLI option for Java virtual machine arguments. */
33
  public static final String VMARGS = "-vmargs";
34

35
  private boolean groovyInstalled;
36

37
  /**
38
   * The constructor.
39
   *
40
   * @param context the {@link IdeContext}.
41
   */
42
  public Eclipse(IdeContext context) {
43

44
    super(context, "eclipse", Set.of(Tag.ECLIPSE));
6✔
45
  }
1✔
46

47
  @Override
48
  protected void configureToolBinary(ProcessContext pc, ProcessMode processMode, ProcessErrorHandling errorHandling) {
49

50
    if (!processMode.isBackground() && this.context.getSystemInfo().isWindows()) {
8✔
51
      pc.executable(Path.of("eclipsec"));
8✔
52
    } else {
53
      super.configureToolBinary(pc, processMode, errorHandling);
5✔
54
    }
55
  }
1✔
56

57
  @Override
58
  protected void configureToolArgs(ProcessContext pc, ProcessMode processMode, ProcessErrorHandling errorHandling, String... args) {
59

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

81
  @Override
82
  protected boolean isPluginUrlNeeded() {
83

84
    return true;
2✔
85
  }
86

87
  @Override
88
  public void installPlugin(ToolPluginDescriptor plugin, Step step) {
89

90
    ProcessResult result = runTool(ProcessMode.DEFAULT_CAPTURE, null, ProcessErrorHandling.LOG_WARNING, "-application", "org.eclipse.equinox.p2.director",
23✔
91
        "-repository", plugin.url(), "-installIU", plugin.id());
11✔
92
    if (result.isSuccessful()) {
3!
93
      for (String line : result.getOut()) {
11!
94
        if (line.contains("Overall install request is satisfiable")) {
4✔
95
          step.success();
2✔
96
          return;
1✔
97
        }
98
      }
1✔
99
    }
100

101
    result.log(IdeLogLevel.DEBUG, context, IdeLogLevel.ERROR);
×
102
    step.error("Failed to install plugin {} ({}): exit code was {}", plugin.name(), plugin.id(), result.getExitCode());
×
103
  }
×
104

105
  @Override
106
  protected void configureWorkspace() {
107

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

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

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

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