Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#102: implement update & create commandlet #150

Merged
merged 176 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
e9d574f
added class RepositoryCommandlet and its help function
salimbouch Nov 8, 2023
76eba65
implemented run method when project is given as argument
salimbouch Nov 9, 2023
0e16de6
implemented loadProperties
salimbouch Nov 10, 2023
69835e3
added record RepositoryConfig, implemented run method, implemented lo…
salimbouch Nov 11, 2023
90145a6
implemented build functionality, import missing
salimbouch Nov 13, 2023
c738a0e
minor improvements
salimbouch Nov 13, 2023
c3de09e
javadoc
salimbouch Nov 14, 2023
c0fbd26
fixed bug: tool installed but not found
salimbouch Nov 16, 2023
89061ae
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch Nov 16, 2023
edc7b1d
created class UpdateCommandlet, implemented updateSettings method
salimbouch Nov 23, 2023
7b43974
created class UpdateCommandlet, implemented updateSettings method
salimbouch Nov 23, 2023
3fc8c23
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Nov 24, 2023
15bdb62
implemented repository update
salimbouch Nov 26, 2023
8063580
solved bug in CustomToolRepositoryImpl, created class CustomToolComma…
salimbouch Nov 28, 2023
1c729ae
removed useless improt
salimbouch Nov 28, 2023
60e72bc
implemented install/update of custom tools
salimbouch Nov 28, 2023
01cb2b9
minor change
salimbouch Nov 28, 2023
db8008a
Update RepositoryCommandlet.java
salimbouch Nov 28, 2023
ec96f35
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Nov 28, 2023
a64b959
made variable constant
salimbouch Nov 28, 2023
6f265e1
added the help function
salimbouch Nov 28, 2023
77fd651
changes after review
salimbouch Nov 30, 2023
82cc617
changes after review
salimbouch Nov 30, 2023
5440755
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Nov 30, 2023
f1fede6
reviewed changes
salimbouch Nov 30, 2023
dbc3bd3
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch Dec 13, 2023
a582601
Update cli/src/main/resources/nls/Ide_de.properties
salimbouch Dec 13, 2023
7e3bdd9
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch Dec 13, 2023
d71f68e
Update cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java
salimbouch Dec 13, 2023
1e5aba8
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch Dec 13, 2023
c8cf771
Update cli/src/main/resources/nls/Ide.properties
salimbouch Dec 13, 2023
4b60135
Update cli/src/main/resources/nls/Ide.properties
salimbouch Dec 13, 2023
061cfa5
Update cli/src/main/resources/nls/Ide_de.properties
salimbouch Dec 13, 2023
c314c08
reviewed changes
salimbouch Dec 13, 2023
e7a8323
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch Dec 13, 2023
07d4a34
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch Dec 13, 2023
37da950
updates
salimbouch Dec 13, 2023
45e16e8
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch Dec 13, 2023
05bcde1
reviewed changes
salimbouch Dec 13, 2023
e055a6a
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch Dec 13, 2023
f2ee210
reviewed changes
salimbouch Dec 13, 2023
268a067
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch Dec 13, 2023
5773121
implemented repositoryProperty
salimbouch Dec 15, 2023
fe607d2
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/UpdateComma…
salimbouch Dec 19, 2023
91d0570
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/UpdateComma…
salimbouch Dec 19, 2023
d047d62
removed useless comment
salimbouch Dec 19, 2023
260750a
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Dec 19, 2023
6397213
merged #100
salimbouch Dec 19, 2023
13578e9
reviewed changes, new class StepContainer
salimbouch Dec 19, 2023
a0eb88f
small change
salimbouch Dec 19, 2023
c53d072
javadoc for StepContainer class
salimbouch Dec 19, 2023
c55c4a8
small changes
salimbouch Dec 19, 2023
68ddfa8
removed useless imports
salimbouch Dec 19, 2023
c40042f
updated updateSettings
salimbouch Dec 25, 2023
25e4167
added stepContainer, update settings asks for link when no settingsfo…
salimbouch Jan 2, 2024
48db7c3
added null check
salimbouch Jan 2, 2024
94c7b73
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Jan 2, 2024
4c2291a
Update RepositoryProperty.java
salimbouch Jan 2, 2024
dcecb50
Update RepositoryProperty.java
salimbouch Jan 2, 2024
f89b889
created CreateCommandlet
salimbouch Jan 2, 2024
4880d12
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch Jan 7, 2024
de061fe
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch Jan 7, 2024
e62ea03
Update cli/src/main/java/com/devonfw/tools/ide/property/RepositoryPro…
salimbouch Jan 7, 2024
8a35bbd
Update cli/src/main/java/com/devonfw/tools/ide/property/RepositoryPro…
salimbouch Jan 7, 2024
e8ba8f7
Update cli/src/main/java/com/devonfw/tools/ide/property/RepositoryPro…
salimbouch Jan 7, 2024
21f14df
reviewed changes
salimbouch Jan 8, 2024
b030586
Merge branch 'main' into 100-implement-repository-commandlet
hohwille Jan 8, 2024
f847820
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch Jan 11, 2024
aa1fcca
init instance
salimbouch Jan 11, 2024
d6c3b4c
created setupConf
salimbouch Jan 17, 2024
60d1e7b
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Jan 17, 2024
da4949d
bug fixes
salimbouch Jan 17, 2024
3181cde
comments
salimbouch Jan 18, 2024
6ea0cc9
updated ide.properties
salimbouch Jan 18, 2024
3bb3926
Merge branch 'main' into 101-implement-create-commandlet
salimbouch Jan 18, 2024
bb2beb8
Merge branch 'main' of https://github.com/devonfw/IDEasy into 100-imp…
salimbouch Jan 18, 2024
7c6de4c
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Jan 18, 2024
7dfdf17
Merge branch '100-implement-repository-commandlet' into 101-implement…
salimbouch Jan 18, 2024
7047ebd
Update UpdateCommandlet.java
salimbouch Jan 18, 2024
e494943
javadoc
salimbouch Jan 18, 2024
fae8577
Merge branch '102-implement-update-commandlet' into 101-implement-cre…
salimbouch Jan 18, 2024
cbeee6b
Update CreateCommandlet.java
salimbouch Jan 19, 2024
ff0d192
fixed conflicts
salimbouch Jan 23, 2024
1420396
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Jan 23, 2024
75a1f01
Merge branch '102-implement-update-commandlet' into 101-implement-cre…
salimbouch Jan 23, 2024
10ca262
Merge branch '101-implement-create-commandlet' of https://github.com/…
salimbouch Jan 23, 2024
bc7b48a
wrote test for repositoryCom
salimbouch Jan 25, 2024
e21f222
changed repositoryProperty to FileProperty inheritance
salimbouch Jan 26, 2024
bf64dfb
Update CreateCommandlet.java
salimbouch Jan 31, 2024
d06a970
Merge branch 'main' of https://github.com/devonfw/IDEasy into 100-imp…
salimbouch Feb 2, 2024
df05c7c
Update Ide_de.properties
salimbouch Feb 2, 2024
edb59cd
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Feb 2, 2024
f1ae20d
Update CommandletManagerImpl.java
salimbouch Feb 2, 2024
e4b885d
Merge branch '102-implement-update-commandlet' into 101-implement-cre…
salimbouch Feb 2, 2024
ea4b410
typo
salimbouch Feb 15, 2024
b911a22
Merge branch 'main' into 101-implement-create-commandlet
salimbouch Feb 15, 2024
7812831
Merge branch 'main' into 102-implement-update-commandlet
salimbouch Feb 15, 2024
3c0584b
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch Feb 15, 2024
a218748
Merge branch 'main' into 100-implement-repository-commandlet
hohwille Feb 19, 2024
0769f2c
Merge branch 'main' into 101-implement-create-commandlet
hohwille Feb 19, 2024
e0a2b50
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch Feb 20, 2024
7b119df
Update cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java
salimbouch Feb 21, 2024
a60cf62
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch Feb 21, 2024
128dbcf
minor change
salimbouch Feb 27, 2024
216260c
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch Feb 27, 2024
8991d5e
Merge branch 'main' of https://github.com/devonfw/ideasy into 102-imp…
salimbouch Feb 29, 2024
03f2f73
resolved conflicts
salimbouch Feb 29, 2024
b76c336
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Feb 29, 2024
9f0bd6c
Merge branch '102-implement-update-commandlet' into 101-implement-cre…
salimbouch Feb 29, 2024
572ffb1
resolved conflicts
salimbouch Feb 29, 2024
c7671c5
Merge branch '102-implement-update-commandlet' into 101-implement-cre…
salimbouch Feb 29, 2024
7a3c3c2
added tests for repo commandlet
salimbouch Feb 29, 2024
e5b794a
removed my stupid fix
salimbouch Feb 29, 2024
ec515f9
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Feb 29, 2024
cd0075f
Merge branch '102-implement-update-commandlet' into 101-implement-cre…
salimbouch Feb 29, 2024
9254184
removed * import
salimbouch Mar 4, 2024
b490f16
adjusted tests
salimbouch Mar 6, 2024
424887f
Merge branch 'main' into 100-implement-repository-commandlet
hohwille Mar 12, 2024
2b99a21
Update cli/src/main/java/com/devonfw/tools/ide/property/RepositoryPro…
salimbouch Mar 13, 2024
6129a5a
Update cli/src/main/java/com/devonfw/tools/ide/property/RepositoryPro…
salimbouch Mar 13, 2024
4b5b005
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch Mar 13, 2024
5dd5d49
Merge branch 'main' of https://github.com/devonfw/ideasy into 100-imp…
salimbouch Mar 13, 2024
d079c78
reviewed changes
salimbouch Mar 13, 2024
34408ea
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch Mar 13, 2024
7a9bb0b
minor change
salimbouch Mar 13, 2024
4236eae
crlf diff
salimbouch Mar 13, 2024
862eabc
diff war
salimbouch Mar 13, 2024
de2c3f9
solved minor bug
salimbouch Mar 13, 2024
6a1eefc
cleanup
salimbouch Mar 13, 2024
62fe8f2
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch Mar 13, 2024
8a06af5
again crlf switching ..
salimbouch Mar 13, 2024
1752f0e
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch Mar 13, 2024
b7e76d0
Update AbstractIdeContext.java
salimbouch Mar 13, 2024
6765d89
Update GitContextImpl.java
salimbouch Mar 13, 2024
6a8bf0e
Update GitContextImpl.java
salimbouch Mar 13, 2024
7b4bc57
Update GitContextImpl.java
salimbouch Mar 13, 2024
b73e83d
small git api improvements
salimbouch Mar 15, 2024
f513dfa
Update GitContextImpl.java
salimbouch Mar 15, 2024
ee986bd
Merge branch '100-implement-repository-commandlet' into 102-implement…
salimbouch Mar 18, 2024
2a31288
Merge branch 'main' into 102-implement-update-commandlet
salimbouch Mar 18, 2024
6315f7d
reviewed changes
salimbouch Mar 18, 2024
4efaccc
Merge branch '102-implement-update-commandlet' of https://github.com/…
salimbouch Mar 18, 2024
af7aeb2
Merge branch 'main' of https://github.com/devonfw/ideasy into 102-imp…
salimbouch Mar 22, 2024
96beaa7
Merge branch '102-implement-update-commandlet' into 101-implement-cre…
salimbouch Mar 22, 2024
caa0be6
adjusting to changes to Update cmdlt
salimbouch Mar 22, 2024
252f633
Merge branch 'main' into 101-implement-create-commandlet
salimbouch Mar 22, 2024
a17bc5c
Merge branch 'main' into 102-implement-update-commandlet
salimbouch Apr 1, 2024
79a4a01
Merge branch 'main' of https://github.com/devonfw/ideasy into 102-imp…
salimbouch Apr 1, 2024
652abb5
Merge branch '102-implement-update-commandlet' of https://github.com/…
salimbouch Apr 1, 2024
5b3880d
Merge branch '101-implement-create-commandlet' into 102-implement-upd…
salimbouch Apr 1, 2024
d32e3de
removed unused improts
salimbouch Apr 1, 2024
a016ac3
unit test for UpdateCommandlet
salimbouch Apr 1, 2024
06b51bd
unit test
salimbouch Apr 1, 2024
a1ac17b
fixed tiny bug in unit tests
salimbouch Apr 1, 2024
88beca8
typo
salimbouch Apr 1, 2024
4c12e12
typo
salimbouch Apr 1, 2024
f7a307c
Merge branch 'main' into 102-implement-update-commandlet
salimbouch Apr 3, 2024
9569abb
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/CreateComma…
salimbouch Apr 3, 2024
15b4f30
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/CreateComma…
salimbouch Apr 3, 2024
caf0a1e
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/CreateComma…
salimbouch Apr 3, 2024
9d4ef31
removed useless files
salimbouch Apr 3, 2024
0471e07
suggested imporvements
salimbouch Apr 3, 2024
7cee5ff
new super class for create and update
salimbouch Apr 4, 2024
27761ce
renamed class
salimbouch Apr 4, 2024
94b3d47
Update CreateCommandlet.java
salimbouch Apr 4, 2024
b7af107
EOL problems
salimbouch Apr 4, 2024
b2d425a
Update UpdateCommandlet.java
salimbouch Apr 4, 2024
2e7b523
Fix EOL
salimbouch Apr 4, 2024
26169f4
Fix EOL Diff
salimbouch Apr 4, 2024
c86e93c
junit test for CreateCommandlet
salimbouch Apr 4, 2024
ba37c7d
changes in meeting
salimbouch Apr 5, 2024
6848e34
added javadoc to setHome and setCwd
salimbouch Apr 7, 2024
59f290a
moved block to setCwd
salimbouch Apr 7, 2024
16cf912
Merge branch 'main' into 102-implement-update-commandlet
salimbouch Apr 7, 2024
9655184
javadoc
salimbouch Apr 7, 2024
5512031
Merge branch '102-implement-update-commandlet' of https://github.com/…
salimbouch Apr 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/main/java/com/devonfw/tools/ide/cli/Ide.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private CliArgument initContext(CliArgument first) {
}

/**
* @param argument the current {@link CliArgument} (position) to match.
* @param current the current {@link CliArgument} (position) to match.
* @param commandlet the potential {@link Commandlet} to {@link #apply(CliArgument, Commandlet) apply} and
* {@link Commandlet#run() run}.
* @return {@code true} if the given {@link Commandlet} matched and did {@link Commandlet#run() run} successfully,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.devonfw.tools.ide.tool.gh.Gh;
import com.devonfw.tools.ide.tool.gradle.Gradle;
import com.devonfw.tools.ide.tool.helm.Helm;
import com.devonfw.tools.ide.tool.intellij.Intellij;
import com.devonfw.tools.ide.tool.java.Java;
import com.devonfw.tools.ide.tool.kotlinc.Kotlinc;
import com.devonfw.tools.ide.tool.kotlinc.KotlincNative;
Expand Down Expand Up @@ -58,6 +59,8 @@ private CommandletManagerImpl(IdeContext context) {
add(new VersionSetCommandlet(context));
add(new VersionGetCommandlet(context));
add(new VersionListCommandlet(context));
add(new RepositoryCommandlet(context));
add(new UpdateCommandlet(context));
add(new Gh(context));
add(new Helm(context));
add(new Java(context));
Expand All @@ -72,6 +75,7 @@ private CommandletManagerImpl(IdeContext context) {
add(new KotlincNative(context));
add(new Vscode(context));
add(new Azure(context));
add(new Intellij(context));
}

private void add(Commandlet commandlet) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package com.devonfw.tools.ide.commandlet;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.property.PathProperty;
import com.devonfw.tools.ide.property.StringProperty;
import com.devonfw.tools.ide.util.FilenameUtil;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

/**
* {@link Commandlet} to setup a repository
*/
public class RepositoryCommandlet extends Commandlet {

/** the repository to setup. */
public final PathProperty repository;

/**
* The constructor.
*
* @param context the {@link IdeContext}.
*/
public RepositoryCommandlet(IdeContext context) {

super(context);
addKeyword(getName());
add(new StringProperty("setup", true, null));
this.repository = add(new PathProperty("", false, "repository"));
}

@Override
public String getName() {

return "repository";
}

@Override
public void run() {

Path repositoriesPath = this.context.getSettingsPath().resolve("repositories");
Path legacyRepositoriesPath = this.context.getSettingsPath().resolve("projects");
Path repositoryFile = repository.getValue();

if (repositoryFile != null) {
// Handle the case when a specific repository is provided
if (!Files.exists(repositoryFile)) {
repositoryFile = repositoriesPath.resolve(repositoryFile.getFileName().toString() + ".properties");
}
if (!Files.exists(repositoryFile)) {
Path legacyRepositoryFile = legacyRepositoriesPath.resolve(repositoryFile.getFileName().toString());
if (Files.exists(legacyRepositoryFile)) {
repositoryFile = legacyRepositoryFile;
} else {
this.context.warning("Could not find " + repositoryFile);
return;
}
}
doImportRepository(repositoryFile, true);
} else {
// If no specific repository is provided, check for repositories folder
Path repositories = Files.exists(repositoriesPath) ? repositoriesPath :
Files.exists(legacyRepositoriesPath) ? legacyRepositoriesPath : null;

if (repositories == null) return;

List <Path> propertiesFiles = this.context.getFileAccess().getFilesInDir(repositories,
path -> "properties".equals(FilenameUtil.getExtension(path.getFileName().toString())));

if (propertiesFiles != null) {
boolean forceMode = this.context.isForceMode();
for (Path propertiesFile : propertiesFiles) {
doImportRepository(propertiesFile, forceMode);
}
}
}
}

private void doImportRepository(Path repositoryFile, boolean forceMode) {

this.context.info("Importing from {} ...", repositoryFile.toString());
RepositoryConfig repositoryConfig = loadProperties(repositoryFile);

if (!repositoryConfig.active()) {
this.context.info("Repository is not active by default.");
if (forceMode) {
this.context.info("Repository setup is forced, hence proceeding ...");
} else {
this.context.info("Skipping repository - use force (-f) to setup all repositories ...");
return;
}
}

String repository = repositoryConfig.path();
String gitUrl = repositoryConfig.gitUrl();
if (repository == null || "".equals(repository) || gitUrl == null || "".equals(gitUrl)) {
this.context.warning("Invalid repository configuration {} - both 'path' and 'git-url' have to be defined."
, repositoryFile);
return;
}

this.context.debug(repositoryConfig.toString());
this.context.debug("Pull or clone git repository {} ...", repository);

String workspace = repositoryConfig.workspace() != null ? repositoryConfig.workspace() : "main";
Path workspacePath = this.context.getIdeHome().resolve("workspaces").resolve(workspace);
this.context.getFileAccess().mkdirs(workspacePath);

if (repositoryConfig.gitBranch() != null && !repositoryConfig.gitBranch().isEmpty()) {
gitUrl = gitUrl + "#" + repositoryConfig.gitBranch();
}

Path repositoryPath = workspacePath.resolve(repository);
this.context.gitPullOrClone(repositoryPath, gitUrl);

String buildCmd = repositoryConfig.buildCmd();
this.context.debug("Building project with ide command: {}", buildCmd);
if (buildCmd != null && !buildCmd.isEmpty()) {
String[] command = buildCmd.split("\\s+");
this.context.getCommandletManager().getToolCommandlet(command[0]).install(true);
ProcessContext pc = this.context.newProcess();
pc.executable(command[0]);
pc.addArgs(Arrays.copyOfRange(command, 1, command.length));
Path buildPath = repositoryPath;
if (repositoryConfig.buildPath() != null) {
buildPath = buildPath.resolve(repositoryConfig.buildPath());
}
pc.directory(buildPath);
pc.run();
} else {
this.context.info("Build command not set. Skipping build for repository.");
}

if ("import".equals(repositoryConfig.eclipse()) && !Files.exists(repositoryPath.resolve(".project"))) {
//TODO: import repository to eclipse
}
}


private RepositoryConfig loadProperties(Path filePath) {

Properties properties = new Properties();
try (InputStream input = new FileInputStream(filePath.toString())) {
properties.load(input);
} catch (IOException e) {
throw new IllegalStateException("Failed to read file: " + filePath, e);
}

return new RepositoryConfig(
properties.getProperty("path"),
properties.getProperty("workingsets"),
properties.getProperty("workspace"),
properties.getProperty("git_url"),
properties.getProperty("git_branch"),
properties.getProperty(("build_path")),
properties.getProperty("build_cmd"),
properties.getProperty("eclipse"),
Boolean.parseBoolean(properties.getProperty("active"))
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.devonfw.tools.ide.commandlet;

/**
* Represents the configuration of a repository to be used by the {@link RepositoryCommandlet}.
*
* @param path Path into which the project is cloned. This path is relative to the workspace.
* @param workingSets The working sets associated with the repository.
* @param workspace Workspace to use for checkout and import. Default is main.
* @param gitUrl Git URL to use for cloning the project.
* @param gitBranch Git branch to checkout. Git default branch is default.
* @param buildPath The build path for the repository.
* @param buildCmd The command to invoke to build the repository after clone or pull. If omitted no build is triggered.
* @param eclipse Desired action for eclipse IDE. If equals to "import" all modules will be imported into eclipse.
* @param active {@code true} to setup the repository during setup, {@code false} to skip.
*/
public record RepositoryConfig(
String path,
String workingSets,
String workspace,
String gitUrl,
String gitBranch,
String buildPath,
String buildCmd,
String eclipse,
boolean active) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.devonfw.tools.ide.commandlet;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.repo.CustomTool;
import com.devonfw.tools.ide.tool.CustomToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;

/**
* {@link Commandlet} to update settings, software and repositories
*/
public class UpdateCommandlet extends Commandlet {

private static final String SETTINGS_REPO_URL = "https://github.com/devonfw/ide-settings";

/**
* The constructor.
*
* @param context the {@link IdeContext}.
*/
public UpdateCommandlet(IdeContext context) {

super(context);
addKeyword(getName());
}

@Override
public String getName() {

return "update";
}

@Override
public void run() {

updateSettings();
updateSoftware();
updateRepositories();
}


private void updateSettings() {

this.context.info("Updating settings repository ...");
Path settingsPath = this.context.getSettingsPath();
if (Files.isDirectory(settingsPath)) {
// perform git pull on the settings repo
this.context.gitPullOrClone(settingsPath, SETTINGS_REPO_URL);
this.context.success("Successfully updated settings repository.");
} else {
throw new IllegalStateException("Cannot find settings repository.");
}
}

private void updateSoftware() {

Set<ToolCommandlet> toolCommandlets = new HashSet<>();

// installed tools in IDE_HOME/software
List<Path> softwares = this.context.getFileAccess().getFilesInDir(this.context.getSoftwarePath(), path -> true);
for (Path software : softwares) {
String toolName = software.getFileName().toString();
try {
toolCommandlets.add(this.context.getCommandletManager().getToolCommandlet(toolName));
} catch (IllegalArgumentException e) {
//tool is a custom tool, ignore ...
}
}

// regular tools in $IDE_TOOLS
String regularToolsString = this.context.getVariables().get("IDE_TOOLS");
String[] regularTools = regularToolsString.split(",\\s");
for (String regularTool : regularTools) {
toolCommandlets.add(this.context.getCommandletManager().getToolCommandlet(regularTool));
}

// custom tools
for (CustomTool customTool : this.context.getCustomToolRepository().getTools()) {
CustomToolCommandlet customToolCommandlet = new CustomToolCommandlet(this.context, customTool);
toolCommandlets.add(customToolCommandlet);
}

// update/install the toolCommandlets
Map<String, String> tool2exception = new HashMap<>();
for (ToolCommandlet toolCommandlet : toolCommandlets) {
try {
this.context.step("Setting up {}", toolCommandlet.getName());
toolCommandlet.install(false);
} catch (Exception e) {
tool2exception.put(toolCommandlet.getName(), e.getMessage());
}
}

if (tool2exception.isEmpty()) {
this.context.success("All tools were successfully installed.");
} else {
this.context.warning("Following tools could not be installed:");
for (String toolName : tool2exception.keySet())
this.context.warning("{}: {}", toolName, tool2exception.get(toolName));
}
}

private void updateRepositories() {
this.context.getCommandletManager().getCommandlet(RepositoryCommandlet.class).run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public Path getPath(String tool) {
*/
public void setPath(String tool, Path path) {

this.paths.add(path);
this.tool2pathMap.put(tool, path);
}

Expand Down
9 changes: 9 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.devonfw.tools.ide.io;

import java.nio.file.Path;
import java.util.List;
import java.util.function.Predicate;

/**
Expand Down Expand Up @@ -131,4 +132,12 @@ default void copy(Path source, Path target) {
*/
Path findFirst(Path dir, Predicate<Path> filter, boolean recursive);

/**
* Retrieves a list of file paths from the specified directory that satisfy the given predicate.
* @param dir the folder to iterate through
* @param filter the {@link Predicate} that determines whether a file should be included in the list.
* @return a list of paths that satisfy the provided {@link Predicate} or {@code null} if no match was found.
*/
List<Path> getFilesInDir(Path dir, Predicate<Path> filter);

}
17 changes: 17 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,21 @@ private Path findFirstRecursive(Path dir, Predicate<Path> filter, boolean recurs
return null;
}

@Override
public List<Path> getFilesInDir(Path dir, Predicate<Path> filter) {
List<Path> files = new ArrayList<>();
try (Stream<Path> childStream = Files.list(dir)) {
Iterator<Path> iterator = childStream.iterator();
while (iterator.hasNext()) {
Path child = iterator.next();
if (filter.test(child)) {
files.add(child);
}
}
} catch (IOException e) {
throw new IllegalStateException("Failed to iterate through " + dir, e);
}
return files;
}

}
Loading