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

devonfw / IDEasy / 13327588889

14 Feb 2025 10:44AM UTC coverage: 67.947% (-0.5%) from 68.469%
13327588889

Pull #1021

github

web-flow
Merge d03159bfe into 52609dacb
Pull Request #1021: #786: support ide upgrade to automatically update to the latest version of IDEasy

2964 of 4791 branches covered (61.87%)

Branch coverage included in aggregate %.

7688 of 10886 relevant lines covered (70.62%)

3.07 hits per line

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

53.85
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
    super.run();
2✔
65
    this.context.getFileAccess().writeFileContent(IdeVersion.getVersionString(), newProjectPath.resolve(IdeContext.FILE_SOFTWARE_VERSION));
8✔
66
    this.context.success("Successfully created new project '{}'.", newProjectName);
10✔
67
  }
1✔
68

69
  private void initializeCodeRepository(String repoUrl) {
70

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

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

87
  private void initializeProject(Path newInstancePath) {
88

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

95
  @Override
96
  protected void updateSettings() {
97

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

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