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

devonfw / IDEasy / 13011549187

28 Jan 2025 01:29PM UTC coverage: 68.278% (-0.2%) from 68.45%
13011549187

Pull #990

github

web-flow
Merge f75f88113 into 05af7d1fc
Pull Request #990: #954: improve repository support

2841 of 4577 branches covered (62.07%)

Branch coverage included in aggregate %.

7342 of 10337 relevant lines covered (71.03%)

3.09 hits per line

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

63.29
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.java.Java;
21
import com.devonfw.tools.ide.tool.mvn.Mvn;
22
import com.devonfw.tools.ide.tool.mvn.MvnArtifact;
23
import com.devonfw.tools.ide.tool.plugin.ToolPluginDescriptor;
24

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

30
  // version must correspond to eclipse-import.xml
31
  private static final String GROOVY_VERSION = "3.0.23";
32
  public static final String VMARGS = "-vmargs";
33

34
  private boolean groovyInstalled;
35

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

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

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

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

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

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

80
  @Override
81
  protected void installDependencies() {
82

83
    // TODO create eclipse/eclipse/dependencies.json file in ide-urls and delete this method
84
    getCommandlet(Java.class).install();
6✔
85
  }
1✔
86

87
  @Override
88
  protected boolean isPluginUrlNeeded() {
89

90
    return true;
2✔
91
  }
92

93
  @Override
94
  public void installPlugin(ToolPluginDescriptor plugin, Step step) {
95

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

107
    result.log(IdeLogLevel.DEBUG, context, IdeLogLevel.ERROR);
×
108
    step.error("Failed to install plugin {} ({}): exit code was {}", plugin.name(), plugin.id(), result.getExitCode());
×
109
  }
×
110

111
  @Override
112
  protected void configureWorkspace() {
113

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

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

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

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