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

devonfw / IDEasy / 14661121862

25 Apr 2025 09:11AM UTC coverage: 67.586% (+0.1%) from 67.448%
14661121862

Pull #1262

github

web-flow
Merge bb585752e into af5a7ba20
Pull Request #1262: #793: add support for IDE_MIN_VERSION

3089 of 4976 branches covered (62.08%)

Branch coverage included in aggregate %.

7935 of 11335 relevant lines covered (70.0%)

3.06 hits per line

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

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

3
import java.nio.file.Files;
4
import java.nio.file.Path;
5

6
import com.devonfw.tools.ide.context.IdeContext;
7
import com.devonfw.tools.ide.git.GitUrl;
8
import com.devonfw.tools.ide.io.FileAccess;
9
import com.devonfw.tools.ide.property.FlagProperty;
10
import com.devonfw.tools.ide.property.StringProperty;
11
import com.devonfw.tools.ide.version.IdeVersion;
12

13
/**
14
 * {@link Commandlet} to create a new IDEasy instance
15
 */
16
public class CreateCommandlet extends AbstractUpdateCommandlet {
17

18
  /** {@link StringProperty} for the name of the new project */
19
  public final StringProperty newProject;
20

21
  /** {@link FlagProperty} for creating a project with settings inside a code repository */
22
  public final FlagProperty codeRepositoryFlag;
23

24
  /**
25
   * The constructor.
26
   *
27
   * @param context the {@link IdeContext}.
28
   */
29
  public CreateCommandlet(IdeContext context) {
30

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

37
  @Override
38
  public String getName() {
39

40
    return "create";
2✔
41
  }
42

43
  @Override
44
  public boolean isIdeHomeRequired() {
45

46
    return false;
2✔
47
  }
48

49
  @Override
50
  public void run() {
51

52
    String newProjectName = this.newProject.getValue();
5✔
53
    Path newProjectPath = this.context.getIdeRoot().resolve(newProjectName);
6✔
54

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

62
    initializeProject(newProjectPath);
3✔
63
    this.context.setIdeHome(newProjectPath);
4✔
64
    this.context.verifyIdeMinVersion(true);
4✔
65
    super.run();
2✔
66
    this.context.getFileAccess().writeFileContent(IdeVersion.getVersionString(), newProjectPath.resolve(IdeContext.FILE_SOFTWARE_VERSION));
8✔
67
    this.context.success("Successfully created new project '{}'.", newProjectName);
10✔
68
  }
1✔
69

70
  private void initializeCodeRepository(String repoUrl) {
71

72
    // clone the given repository into IDE_HOME/workspaces/main
73
    GitUrl gitUrl = GitUrl.of(repoUrl);
×
74
    Path codeRepoPath = this.context.getWorkspacePath().resolve(gitUrl.getProjectName());
×
75
    this.context.getGitContext().pullOrClone(gitUrl, codeRepoPath);
×
76

77
    // check for settings folder and create symlink to IDE_HOME/settings
78
    Path settingsFolder = codeRepoPath.resolve(IdeContext.FOLDER_SETTINGS);
×
79
    if (Files.exists(settingsFolder)) {
×
80
      this.context.getFileAccess().symlink(settingsFolder, this.context.getSettingsPath());
×
81
      // create a file in IDE_HOME with the current local commit id
82
      this.context.getGitContext().saveCurrentCommitId(codeRepoPath, this.context.getSettingsCommitIdPath());
×
83
    } else {
84
      this.context.warning("No settings folder was found inside the code repository.");
×
85
    }
86
  }
×
87

88
  private void initializeProject(Path newInstancePath) {
89

90
    FileAccess fileAccess = this.context.getFileAccess();
4✔
91
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_SOFTWARE));
5✔
92
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_PLUGINS));
5✔
93
    fileAccess.mkdirs(newInstancePath.resolve(IdeContext.FOLDER_WORKSPACES).resolve(IdeContext.WORKSPACE_MAIN));
7✔
94
  }
1✔
95

96
  @Override
97
  protected void updateSettings() {
98

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

115
  }
1✔
116
}
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