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

devonfw / IDEasy / 15050126544

15 May 2025 04:21PM UTC coverage: 67.707% (+0.01%) from 67.693%
15050126544

push

github

web-flow
#793: fix missing exception on create (#1310)

Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>

3104 of 4992 branches covered (62.18%)

Branch coverage included in aggregate %.

7981 of 11380 relevant lines covered (70.13%)

3.07 hits per line

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

55.56
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.verifyIdeMinVersion(true);
4✔
67
    this.context.getFileAccess().writeFileContent(IdeVersion.getVersionString(), newProjectPath.resolve(IdeContext.FILE_SOFTWARE_VERSION));
8✔
68
    this.context.success("Successfully created new project '{}'.", newProjectName);
10✔
69
  }
1✔
70

71
  private void initializeCodeRepository(String repoUrl) {
72

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

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

89
  private void initializeProject(Path newInstancePath) {
90

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

97
  @Override
98
  protected void updateSettings() {
99

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

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