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

devonfw / IDEasy / 15157390451

21 May 2025 08:30AM UTC coverage: 67.687% (-0.03%) from 67.716%
15157390451

Pull #1328

github

web-flow
Merge 2d59fe02b into f34447afb
Pull Request #1328: #1292: logs potential welcome file to info level

3122 of 5020 branches covered (62.19%)

Branch coverage included in aggregate %.

8018 of 11438 relevant lines covered (70.1%)

3.07 hits per line

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

49.18
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
import java.util.function.Predicate;
6

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

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

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

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

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

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

38
  @Override
39
  public String getName() {
40

41
    return "create";
2✔
42
  }
43

44
  @Override
45
  public boolean isIdeHomeRequired() {
46

47
    return false;
2✔
48
  }
49

50
  @Override
51
  public void run() {
52

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

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

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

72
  private void initializeCodeRepository(String repoUrl) {
73

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

79
    // check for settings folder and create symlink to IDE_HOME/settings
80
    Path settingsFolder = codeRepoPath.resolve(IdeContext.FOLDER_SETTINGS);
×
81
    if (Files.exists(settingsFolder)) {
×
82
      this.context.getFileAccess().symlink(settingsFolder, this.context.getSettingsPath());
×
83
      // create a file in IDE_HOME with the current local commit id
84
      this.context.getGitContext().saveCurrentCommitId(codeRepoPath, this.context.getSettingsCommitIdPath());
×
85
      Predicate<Path> welcomePredicate = path -> String.valueOf(path.getFileName()).startsWith("welcome.");
×
86
      Path welcomeFile = this.context.getFileAccess().findFirst(settingsFolder, welcomePredicate, false);
×
87
      if (welcomeFile != null) {
×
88
        this.context.info(welcomeFile.toFile().toString());
×
89
      }
90
    } else {
×
91
      this.context.warning("No settings folder was found inside the code repository.");
×
92
    }
93
  }
×
94

95
  private void initializeProject(Path newInstancePath) {
96

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

103
  @Override
104
  protected void updateSettings() {
105

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

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