-
Couldn't load subscription status.
- Fork 45
#100: implement repository commandlet #143
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
Merged
hohwille
merged 81 commits into
devonfw:main
from
salimbouch:100-implement-repository-commandlet
Mar 19, 2024
Merged
Changes from all commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
e9d574f
added class RepositoryCommandlet and its help function
salimbouch 76eba65
implemented run method when project is given as argument
salimbouch 0e16de6
implemented loadProperties
salimbouch 69835e3
added record RepositoryConfig, implemented run method, implemented lo…
salimbouch 90145a6
implemented build functionality, import missing
salimbouch c738a0e
minor improvements
salimbouch c3de09e
javadoc
salimbouch c0fbd26
fixed bug: tool installed but not found
salimbouch 89061ae
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch 1c729ae
removed useless improt
salimbouch 01cb2b9
minor change
salimbouch db8008a
Update RepositoryCommandlet.java
salimbouch 82cc617
changes after review
salimbouch dbc3bd3
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch a582601
Update cli/src/main/resources/nls/Ide_de.properties
salimbouch 7e3bdd9
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch d71f68e
Update cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java
salimbouch 1e5aba8
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch c8cf771
Update cli/src/main/resources/nls/Ide.properties
salimbouch 4b60135
Update cli/src/main/resources/nls/Ide.properties
salimbouch 061cfa5
Update cli/src/main/resources/nls/Ide_de.properties
salimbouch c314c08
reviewed changes
salimbouch e7a8323
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch 07d4a34
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch 37da950
updates
salimbouch 45e16e8
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch 05bcde1
reviewed changes
salimbouch e055a6a
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch f2ee210
reviewed changes
salimbouch 268a067
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch 5773121
implemented repositoryProperty
salimbouch d047d62
removed useless comment
salimbouch 48db7c3
added null check
salimbouch dcecb50
Update RepositoryProperty.java
salimbouch 4880d12
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch de061fe
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch e62ea03
Update cli/src/main/java/com/devonfw/tools/ide/property/RepositoryPro…
salimbouch 8a35bbd
Update cli/src/main/java/com/devonfw/tools/ide/property/RepositoryPro…
salimbouch e8ba8f7
Update cli/src/main/java/com/devonfw/tools/ide/property/RepositoryPro…
salimbouch 21f14df
reviewed changes
salimbouch b030586
Merge branch 'main' into 100-implement-repository-commandlet
hohwille f847820
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch bb2beb8
Merge branch 'main' of https://github.com/devonfw/IDEasy into 100-imp…
salimbouch ff0d192
fixed conflicts
salimbouch bc7b48a
wrote test for repositoryCom
salimbouch e21f222
changed repositoryProperty to FileProperty inheritance
salimbouch d06a970
Merge branch 'main' of https://github.com/devonfw/IDEasy into 100-imp…
salimbouch df05c7c
Update Ide_de.properties
salimbouch 3c0584b
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch a218748
Merge branch 'main' into 100-implement-repository-commandlet
hohwille e0a2b50
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch 7b119df
Update cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java
salimbouch a60cf62
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch 128dbcf
minor change
salimbouch 216260c
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch 7a3c3c2
added tests for repo commandlet
salimbouch e5b794a
removed my stupid fix
salimbouch 9254184
removed * import
salimbouch b490f16
adjusted tests
salimbouch 424887f
Merge branch 'main' into 100-implement-repository-commandlet
hohwille 2b99a21
Update cli/src/main/java/com/devonfw/tools/ide/property/RepositoryPro…
salimbouch 6129a5a
Update cli/src/main/java/com/devonfw/tools/ide/property/RepositoryPro…
salimbouch 4b5b005
Update cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryC…
salimbouch 5dd5d49
Merge branch 'main' of https://github.com/devonfw/ideasy into 100-imp…
salimbouch d079c78
reviewed changes
salimbouch 34408ea
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch 7a9bb0b
minor change
salimbouch 4236eae
crlf diff
salimbouch 862eabc
diff war
salimbouch de2c3f9
solved minor bug
salimbouch 6a1eefc
cleanup
salimbouch 62fe8f2
Merge branch 'main' into 100-implement-repository-commandlet
salimbouch 8a06af5
again crlf switching ..
salimbouch 1752f0e
Merge branch '100-implement-repository-commandlet' of https://github.…
salimbouch b7e76d0
Update AbstractIdeContext.java
salimbouch 6765d89
Update GitContextImpl.java
salimbouch 6a8bf0e
Update GitContextImpl.java
salimbouch 7b4bc57
Update GitContextImpl.java
salimbouch b73e83d
small git api improvements
salimbouch f513dfa
Update GitContextImpl.java
salimbouch 5854687
Merge branch 'main' into 100-implement-repository-commandlet
hohwille File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryCommandlet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package com.devonfw.tools.ide.commandlet; | ||
|
|
||
| import com.devonfw.tools.ide.context.IdeContext; | ||
| import com.devonfw.tools.ide.property.PathProperty; | ||
| import com.devonfw.tools.ide.property.RepositoryProperty; | ||
| import com.devonfw.tools.ide.tool.ToolCommandlet; | ||
|
|
||
| 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.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Properties; | ||
|
|
||
| import static com.devonfw.tools.ide.commandlet.RepositoryConfig.loadProperties; | ||
|
|
||
| /** | ||
| * {@link Commandlet} to setup one or multiple GIT repositories for development. | ||
| */ | ||
| public class RepositoryCommandlet extends Commandlet { | ||
|
|
||
| /** the repository to setup. */ | ||
| public final RepositoryProperty repository; | ||
|
|
||
| /** | ||
| * The constructor. | ||
| * | ||
| * @param context the {@link IdeContext}. | ||
| */ | ||
| public RepositoryCommandlet(IdeContext context) { | ||
|
|
||
| super(context); | ||
| addKeyword(getName()); | ||
| addKeyword("setup"); | ||
| this.repository = add(new RepositoryProperty("", false, "repository")); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
|
|
||
| return "repository"; | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
|
|
||
| Path repositoryFile = repository.getValue(); | ||
|
|
||
| if (repositoryFile != null) { | ||
| // Handle the case when a specific repository is provided | ||
| doImportRepository(repositoryFile, true); | ||
| } else { | ||
| // If no specific repository is provided, check for repositories folder | ||
| Path repositoriesPath = this.context.getSettingsPath().resolve(IdeContext.FOLDER_REPOSITORIES); | ||
| Path legacyRepositoriesPath = this.context.getSettingsPath().resolve(IdeContext.FOLDER_LEGACY_REPOSITORIES); | ||
| Path repositories; | ||
| if (Files.exists(repositoriesPath)) { | ||
| repositories = repositoriesPath; | ||
| } else if (Files.exists(legacyRepositoriesPath)) { | ||
| repositories = legacyRepositoriesPath; | ||
| } else { | ||
| this.context.warning("Cannot find repositories folder nor projects folder."); | ||
| return; | ||
| } | ||
|
|
||
| List <Path> propertiesFiles = this.context.getFileAccess().listChildren(repositories, | ||
| path -> path.getFileName().toString().endsWith(".properties")); | ||
|
|
||
| boolean forceMode = this.context.isForceMode(); | ||
| for (Path propertiesFile : propertiesFiles) { | ||
| doImportRepository(propertiesFile, forceMode); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void doImportRepository(Path repositoryFile, boolean forceMode) { | ||
|
|
||
| this.context.info("Importing repository from {} ...", repositoryFile.getFileName().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.getFileName().toString()); | ||
| return; | ||
| } | ||
|
|
||
| this.context.debug(repositoryConfig.toString()); | ||
|
|
||
| String workspace = repositoryConfig.workspace() != null ? repositoryConfig.workspace() : "main"; | ||
| Path workspacePath = this.context.getIdeHome().resolve("workspaces").resolve(workspace); | ||
| this.context.getFileAccess().mkdirs(workspacePath); | ||
|
|
||
| Path repositoryPath = workspacePath.resolve(repository); | ||
| this.context.getGitContext().pullOrClone(gitUrl, repositoryConfig.gitBranch(), repositoryPath); | ||
|
|
||
| String buildCmd = repositoryConfig.buildCmd(); | ||
| this.context.debug("Building repository with ide command: {}", buildCmd); | ||
| if (buildCmd != null && !buildCmd.isEmpty()) { | ||
| String[] command = buildCmd.split("\\s+"); | ||
| ToolCommandlet commandlet = this.context.getCommandletManager().getToolCommandlet(command[0]); | ||
| List<String> args = new ArrayList<>(command.length - 1); | ||
| for (int i = 1; i < command.length; i++) { | ||
| args.add(command[i]); | ||
| } | ||
| commandlet.arguments.setValue(args); | ||
| commandlet.run(); | ||
| } else { | ||
| this.context.info("Build command not set. Skipping build for repository."); | ||
| } | ||
|
|
||
| } | ||
| } | ||
65 changes: 65 additions & 0 deletions
65
cli/src/main/java/com/devonfw/tools/ide/commandlet/RepositoryConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package com.devonfw.tools.ide.commandlet; | ||
|
|
||
| import java.io.FileInputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.file.Path; | ||
| import java.util.Collections; | ||
| import java.util.Properties; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * 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 imports list of IDEs where the repository will be imported to. | ||
| * @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, | ||
| Set<String> imports, | ||
| boolean active) { | ||
| public static 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); | ||
| } | ||
|
|
||
| Set<String> importsSet = getImports(properties); | ||
|
|
||
| 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"), importsSet, | ||
| Boolean.parseBoolean(properties.getProperty("active").trim())); | ||
| } | ||
|
|
||
| private static Set<String> getImports(Properties properties) { | ||
|
|
||
| String importProperty = properties.getProperty("import"); | ||
| if (importProperty != null && !importProperty.isEmpty()) { | ||
| return Set.of(importProperty.split("\\s*,\\s*")); | ||
| } | ||
|
|
||
| String legacyImportProperty = properties.getProperty("eclipse"); | ||
| if ("import".equals(legacyImportProperty)) { | ||
| return Set.of("eclipse"); | ||
| } else { | ||
| return Collections.emptySet(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.