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

devonfw / IDEasy / 14640139098

24 Apr 2025 11:09AM UTC coverage: 67.586% (+0.1%) from 67.446%
14640139098

Pull #1262

github

web-flow
Merge 69ff657ac into 81a28a69f
Pull Request #1262: #793: add support for IDE_MIN_VERSION

3085 of 4968 branches covered (62.1%)

Branch coverage included in aggregate %.

7937 of 11340 relevant lines covered (69.99%)

3.06 hits per line

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

57.89
cli/src/main/java/com/devonfw/tools/ide/commandlet/CreateCommandlet.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import static com.devonfw.tools.ide.variable.IdeVariables.IDE_MIN_VERSION;
4

5
import java.nio.file.Files;
6
import java.nio.file.Path;
7

8
import com.devonfw.tools.ide.cli.CliException;
9
import com.devonfw.tools.ide.context.IdeContext;
10
import com.devonfw.tools.ide.git.GitUrl;
11
import com.devonfw.tools.ide.io.FileAccess;
12
import com.devonfw.tools.ide.property.FlagProperty;
13
import com.devonfw.tools.ide.property.StringProperty;
14
import com.devonfw.tools.ide.version.IdeVersion;
15

16
/**
17
 * {@link Commandlet} to create a new IDEasy instance
18
 */
19
public class CreateCommandlet extends AbstractUpdateCommandlet {
20

21
  /** {@link StringProperty} for the name of the new project */
22
  public final StringProperty newProject;
23

24
  /** {@link FlagProperty} for creating a project with settings inside a code repository */
25
  public final FlagProperty codeRepositoryFlag;
26

27
  /**
28
   * The constructor.
29
   *
30
   * @param context the {@link IdeContext}.
31
   */
32
  public CreateCommandlet(IdeContext context) {
33

34
    super(context);
3✔
35
    this.newProject = add(new StringProperty("", true, "project"));
11✔
36
    this.codeRepositoryFlag = add(new FlagProperty("--code"));
9✔
37
    add(this.settingsRepo);
5✔
38
  }
1✔
39

40
  @Override
41
  public String getName() {
42

43
    return "create";
2✔
44
  }
45

46
  @Override
47
  public boolean isIdeHomeRequired() {
48

49
    return false;
2✔
50
  }
51

52
  @Override
53
  public void run() {
54

55
    String newProjectName = this.newProject.getValue();
5✔
56
    Path newProjectPath = this.context.getIdeRoot().resolve(newProjectName);
6✔
57

58
    this.context.info("Creating new IDEasy project in {}", newProjectPath);
10✔
59
    if (!this.context.getFileAccess().isEmptyDir(newProjectPath)) {
6!
60
      this.context.askToContinue("Directory " + newProjectPath + " already exists. Do you want to continue?");
×
61
    } else {
62
      this.context.getFileAccess().mkdirs(newProjectPath);
5✔
63
    }
64

65
    initializeProject(newProjectPath);
3✔
66
    this.context.setIdeHome(newProjectPath);
4✔
67
    if (IdeVersion.getVersionIdentifier().compareVersion(IDE_MIN_VERSION.get(context)).isLess()) {
9✔
68
      throw new CliException(String.format("Your version of IDEasy is currently %s\n"
10✔
69
          + "However, this is too old as your project requires at latest version %s\n"
70
          + "Please run the following command to update to the latest version of IDEasy and fix the problem:\n"
71
          + "ide upgrade", IdeVersion.getVersionIdentifier().toString(), IDE_MIN_VERSION.get(context).toString()));
12✔
72
    }
73
    super.run();
2✔
74
    this.context.getFileAccess().writeFileContent(IdeVersion.getVersionString(), newProjectPath.resolve(IdeContext.FILE_SOFTWARE_VERSION));
8✔
75
    this.context.success("Successfully created new project '{}'.", newProjectName);
10✔
76
  }
1✔
77

78
  private void initializeCodeRepository(String repoUrl) {
79

80
    // clone the given repository into IDE_HOME/workspaces/main
81
    GitUrl gitUrl = GitUrl.of(repoUrl);
×
82
    Path codeRepoPath = this.context.getWorkspacePath().resolve(gitUrl.getProjectName());
×
83
    this.context.getGitContext().pullOrClone(gitUrl, codeRepoPath);
×
84

85
    // check for settings folder and create symlink to IDE_HOME/settings
86
    Path settingsFolder = codeRepoPath.resolve(IdeContext.FOLDER_SETTINGS);
×
87
    if (Files.exists(settingsFolder)) {
×
88
      this.context.getFileAccess().symlink(settingsFolder, this.context.getSettingsPath());
×
89
      // create a file in IDE_HOME with the current local commit id
90
      this.context.getGitContext().saveCurrentCommitId(codeRepoPath, this.context.getSettingsCommitIdPath());
×
91
    } else {
92
      this.context.warning("No settings folder was found inside the code repository.");
×
93
    }
94
  }
×
95

96
  private void initializeProject(Path newInstancePath) {
97

98
    FileAccess fileAccess = this.context.getFileAccess();
4✔
99
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_SOFTWARE));
5✔
100
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_PLUGINS));
5✔
101
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_WORKSPACES).resolve(IdeContext.WORKSPACE_MAIN));
7✔
102
  }
1✔
103

104
  @Override
105
  protected void updateSettings() {
106

107
    if (this.codeRepositoryFlag.isTrue()) {
4!
108
      String codeRepository = this.settingsRepo.getValue();
×
109
      if (codeRepository == null || codeRepository.isBlank()) {
×
110
        String message = """
×
111
            No code repository was given after '--code'.
112
            Please give the code repository below that includes your settings folder.
113
            Further details can be found here: https://github.com/devonfw/IDEasy/blob/main/documentation/settings.adoc
114
            Code repository URL:
115
            """;
116
        codeRepository = this.context.askForInput(message);
×
117
      }
118
      initializeCodeRepository(codeRepository);
×
119
    } else {
×
120
      super.updateSettings();
2✔
121
    }
122

123
  }
1✔
124
}
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