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

devonfw / IDEasy / 15558256102

10 Jun 2025 11:28AM UTC coverage: 67.761% (+0.02%) from 67.746%
15558256102

Pull #1328

github

web-flow
Merge cf2a3bd1c into 7be183ce9
Pull Request #1328: #1292: logs potential welcome file to info level

3163 of 5074 branches covered (62.34%)

Branch coverage included in aggregate %.

8122 of 11580 relevant lines covered (70.14%)

3.07 hits per line

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

54.41
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

71
    logWelcomeMessage(newProjectPath);
3✔
72
  }
1✔
73

74
  private void initializeCodeRepository(String repoUrl) {
75

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

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

92
  private void initializeProject(Path newInstancePath) {
93

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

100
  @Override
101
  protected void updateSettings() {
102

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

119
  }
1✔
120

121
  private void logWelcomeMessage(Path newProjectPath) {
122
    GitUrl gitUrl = GitUrl.of(newProjectPath.toString());
4✔
123
    Path codeRepoPath = this.context.getWorkspacePath().resolve(gitUrl.getProjectName());
7✔
124
    Path settingsFolder = codeRepoPath.resolve(IdeContext.FOLDER_SETTINGS);
4✔
125
    if (Files.exists(settingsFolder)) {
5!
126
      Predicate<Path> welcomePredicate = path -> String.valueOf(path.getFileName()).startsWith("welcome.");
×
127
      Path welcomeFilePath = this.context.getFileAccess().findFirst(settingsFolder, welcomePredicate, false);
×
128
      if (welcomeFilePath != null) {
×
129
        this.context.info(this.context.getFileAccess().readFileContent(welcomeFilePath));
×
130
      }
131
    }
132
  }
1✔
133
}
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