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

devonfw / IDEasy / 13063267543

30 Jan 2025 11:34PM UTC coverage: 68.379% (-0.2%) from 68.557%
13063267543

push

github

web-flow
#954: improve repository support (#990)

Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>
Co-authored-by: jan-vcapgemini <jan-vincent.hoelzle@capgemini.com>

2857 of 4597 branches covered (62.15%)

Branch coverage included in aggregate %.

7391 of 10390 relevant lines covered (71.14%)

3.1 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

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

36
  private boolean groovyInstalled;
37

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

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

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

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

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

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

82
  @Override
83
  protected void installDependencies() {
84

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

89
  @Override
90
  protected boolean isPluginUrlNeeded() {
91

92
    return true;
2✔
93
  }
94

95
  @Override
96
  public void installPlugin(ToolPluginDescriptor plugin, Step step) {
97

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

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

113
  @Override
114
  protected void configureWorkspace() {
115

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

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

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

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