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

devonfw / IDEasy / 13976747373

20 Mar 2025 06:31PM UTC coverage: 67.674%. Remained the same
13976747373

push

github

web-flow
#1006: fix eclipse vmargs to prevent launching UI instead of installing plugins or importing projects (#1157)

3037 of 4914 branches covered (61.8%)

Branch coverage included in aggregate %.

7824 of 11135 relevant lines covered (70.26%)

3.07 hits per line

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

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

81
  @Override
82
  protected boolean isPluginUrlNeeded() {
83

84
    return true;
2✔
85
  }
86

87
  @Override
88
  public boolean installPlugin(ToolPluginDescriptor plugin, Step step, ProcessContext pc) {
89

90
    ProcessResult result = runTool(ProcessMode.DEFAULT_CAPTURE, ProcessErrorHandling.LOG_WARNING, pc, "-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
          this.context.success("Successfully installed plugin: {}", plugin.name());
11✔
96
          step.success();
2✔
97
          return true;
2✔
98
        }
99
      }
1✔
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
    return false;
×
104
  }
105

106
  @Override
107
  protected void configureWorkspace() {
108

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

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

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

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