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

#280: configure maven properly #305

Merged
merged 34 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1d62617
first implementation
mvomiero Apr 19, 2024
6b07d90
first implementation
mvomiero Apr 19, 2024
46968c2
implements variable replacement
mvomiero Apr 19, 2024
b25e444
code refactioring
mvomiero Apr 22, 2024
cd224c6
adds check for existence of settings file
mvomiero Apr 22, 2024
ded8e28
Merge remote-tracking branch 'upstream/main' into enhancement/280-con…
mvomiero Apr 22, 2024
144eaf0
code refactoring
mvomiero Apr 22, 2024
e812881
code refactoring
mvomiero Apr 22, 2024
fc33dad
code cleanup
mvomiero Apr 23, 2024
88a1bc0
Merge remote-tracking branch 'upstream/main' into enhancement/280-con…
mvomiero Apr 23, 2024
5d601f3
renames devon folder to ide
mvomiero Apr 23, 2024
c986f19
Merge branch 'main' into enhancement/280-configureMaven
mvomiero Apr 26, 2024
02242af
implement comments PR
mvomiero Apr 26, 2024
f56485f
implement NoSuchFileException for missing settings template
mvomiero Apr 26, 2024
5774081
implement retrieveGitUrl for GitContext
mvomiero Apr 26, 2024
bd97503
override gitcontextmock
mvomiero Apr 26, 2024
8ad4704
implement logs for errors
mvomiero Apr 29, 2024
5c12573
Merge remote-tracking branch 'upstream/main' into enhancement/280-con…
mvomiero Apr 29, 2024
20f28bd
implement change requests
mvomiero Apr 29, 2024
494c22a
reformat error message
mvomiero Apr 30, 2024
9bc1c21
implement log messages for errors
mvomiero Apr 30, 2024
ba63a41
Merge remote-tracking branch 'upstream/main' into enhancement/280-con…
mvomiero Apr 30, 2024
1f7d2c5
link to docu conf page if there is a problem by the creation of some …
mvomiero Apr 30, 2024
49c58d9
correct MAVEN_ARGS variable in documentation
mvomiero Apr 30, 2024
06d13db
typo
mvomiero Apr 30, 2024
0759e6a
set constants and adjust paths
mvomiero May 3, 2024
51ff292
implement change requests
mvomiero May 3, 2024
c051756
merge upstream main into branch
mvomiero May 7, 2024
5b5be73
correct paths for templates and conf as change requests
mvomiero May 7, 2024
dca2b58
Merge branch 'main' into enhancement/280-configureMaven
hohwille May 7, 2024
e3743fe
Merge branch 'enhancement/280-configureMaven' of github.com:mvomiero/…
mvomiero May 8, 2024
e8133dd
add settingsSecurityFile as parameter for mvn encryption
mvomiero May 8, 2024
86a2206
Merge branch 'main' into enhancement/280-configureMaven
mvomiero May 8, 2024
d746a46
use linkset instead of list
mvomiero May 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import com.devonfw.tools.ide.step.StepImpl;
import com.devonfw.tools.ide.url.model.UrlMetadata;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down
75 changes: 35 additions & 40 deletions cli/src/main/java/com/devonfw/tools/ide/context/GitContext.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.devonfw.tools.ide.context;

import java.nio.file.Path;

import com.devonfw.tools.ide.cli.CliOfflineException;

import java.nio.file.Path;

/**
* Interface for git commands with input and output of information for the user.
*/
Expand All @@ -13,14 +13,12 @@ public interface GitContext {
String DEFAULT_REMOTE = "origin";

/**
* Checks if the Git repository in the specified target folder needs an update by inspecting the modification time of
* a magic file.
* Checks if the Git repository in the specified target folder needs an update by inspecting the modification time of a magic file.
*
* @param repoUrl the git remote URL to clone from.
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
* @throws CliOfflineException if offline and cloning is needed.
*/
void pullOrCloneIfNeeded(String repoUrl, String branch, Path targetRepository);
Expand All @@ -29,9 +27,8 @@ public interface GitContext {
* Attempts a git pull and reset if required.
*
* @param repoUrl the git remote URL to clone from.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
* @throws CliOfflineException if offline and cloning is needed.
*/
default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository) {
Expand All @@ -43,9 +40,8 @@ default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository)
* Attempts a git pull and reset if required.
*
* @param repoUrl the git remote URL to clone from.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
* @throws CliOfflineException if offline and cloning is needed.
*/
Expand All @@ -58,9 +54,8 @@ default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository,
* Attempts a git pull and reset if required.
*
* @param repoUrl the git remote URL to clone from.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
* @param remoteName the remote name e.g. origin.
* @throws CliOfflineException if offline and cloning is needed.
Expand All @@ -71,9 +66,8 @@ default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository,
* Runs a git pull or a git clone.
*
* @param gitRepoUrl the git remote URL to clone from.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
* @throws CliOfflineException if offline and cloning is needed.
*/
void pullOrClone(String gitRepoUrl, Path targetRepository);
Expand All @@ -83,9 +77,8 @@ default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository,
*
* @param gitRepoUrl the git remote URL to clone from.
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
* @throws CliOfflineException if offline and cloning is needed.
*/
void pullOrClone(String gitRepoUrl, String branch, Path targetRepository);
Expand All @@ -94,28 +87,25 @@ default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository,
* Runs a git clone.
*
* @param gitRepoUrl the {@link GitUrl} to use for the repository URL.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the *
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
* @throws CliOfflineException if offline and cloning is needed.
*/
void clone(GitUrl gitRepoUrl, Path targetRepository);

/**
* Runs a git pull.
*
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the *
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
*/
void pull(Path targetRepository);

/**
* Runs a git diff-index to detect local changes and if so reverts them via git reset.
*
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
*/
default void reset(Path targetRepository) {

Expand All @@ -125,9 +115,8 @@ default void reset(Path targetRepository) {
/**
* Runs a git diff-index to detect local changes and if so reverts them via git reset.
*
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
*/
default void reset(Path targetRepository, String branch) {
Expand All @@ -138,9 +127,8 @@ default void reset(Path targetRepository, String branch) {
/**
* Runs a git reset reverting all local changes to the git repository.
*
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the *
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
* @param remoteName the name of the git remote e.g. "origin".
*/
Expand All @@ -149,10 +137,17 @@ default void reset(Path targetRepository, String branch) {
/**
* Runs a git cleanup if untracked files were found.
*
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the *
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
*/
void cleanup(Path targetRepository);

/**
* Returns the URL of a git repository
*
* @param repository the {@link Path} to the folder where the git repository should be hosted.
* @return the url of the repository as a {@link String}.
*/
String retrieveGitUrl(Path repository);

}
64 changes: 35 additions & 29 deletions cli/src/main/java/com/devonfw/tools/ide/context/GitContextImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.devonfw.tools.ide.context;

import com.devonfw.tools.ide.cli.CliOfflineException;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.process.ProcessErrorHandling;
import com.devonfw.tools.ide.process.ProcessMode;
import com.devonfw.tools.ide.process.ProcessResult;

import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
Expand All @@ -12,12 +18,6 @@
import java.util.Map;
import java.util.Objects;

import com.devonfw.tools.ide.cli.CliOfflineException;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.process.ProcessErrorHandling;
import com.devonfw.tools.ide.process.ProcessMode;
import com.devonfw.tools.ide.process.ProcessResult;

/**
* Implements the {@link GitContext}.
*/
Expand Down Expand Up @@ -101,8 +101,7 @@ public void pullOrClone(String gitRepoUrl, String branch, Path targetRepository)
ProcessResult result = this.processContext.addArg("remote").run(ProcessMode.DEFAULT_CAPTURE);
List<String> remotes = result.getOut();
if (remotes.isEmpty()) {
String message = targetRepository
+ " is a local git repository with no remote - if you did this for testing, you may continue...\n"
String message = targetRepository + " is a local git repository with no remote - if you did this for testing, you may continue...\n"
+ "Do you want to ignore the problem and continue anyhow?";
this.context.askToContinue(message);
} else {
Expand All @@ -120,9 +119,8 @@ public void pullOrClone(String gitRepoUrl, String branch, Path targetRepository)
/**
* Handles errors which occurred during git pull.
*
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
* It is not the parent directory where git will by default create a sub-folder by default on clone but the *
* final folder that will contain the ".git" subfolder.
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled. It is not the parent directory where git
* will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
* @param result the {@link ProcessResult} to evaluate.
*/
private void handleErrors(Path targetRepository, ProcessResult result) {
Expand All @@ -135,11 +133,9 @@ private void handleErrors(Path targetRepository, ProcessResult result) {
} else {
this.context.error(message);
if (this.context.isOnline()) {
this.context
.error("See above error for details. If you have local changes, please stash or revert and retry.");
this.context.error("See above error for details. If you have local changes, please stash or revert and retry.");
} else {
this.context.error(
"It seems you are offline - please ensure Internet connectivity and retry or activate offline mode (-o or --offline).");
this.context.error("It seems you are offline - please ensure Internet connectivity and retry or activate offline mode (-o or --offline).");
}
this.context.askToContinue("Typically you should abort and fix the problem. Do you want to continue anyways?");
}
Expand Down Expand Up @@ -173,8 +169,7 @@ public void clone(GitUrl gitRepoUrl, Path targetRepository) {
}
}
} else {
throw new CliOfflineException(
"Could not clone " + parsedUrl + " to " + targetRepository + " because you are offline.");
throw new CliOfflineException("Could not clone " + parsedUrl + " to " + targetRepository + " because you are offline.");
}
}

Expand All @@ -188,8 +183,8 @@ public void pull(Path targetRepository) {

if (!result.isSuccessful()) {
Map<String, String> remoteAndBranchName = retrieveRemoteAndBranchName();
this.context.warning("Git pull for {}/{} failed for repository {}.", remoteAndBranchName.get("remote"),
remoteAndBranchName.get("branch"), targetRepository);
this.context.warning("Git pull for {}/{} failed for repository {}.", remoteAndBranchName.get("remote"), remoteAndBranchName.get("branch"),
targetRepository);
handleErrors(targetRepository, result);
}
}
Expand All @@ -206,17 +201,15 @@ private Map<String, String> retrieveRemoteAndBranchName() {
remoteAndBranchName.put("remote", checkedOutBranch.substring(0, checkedOutBranch.indexOf("/")));
// check if current repo is behind remote and omit message
if (checkedOutBranch.contains(":")) {
remoteAndBranchName.put("branch",
checkedOutBranch.substring(checkedOutBranch.indexOf("/") + 1, checkedOutBranch.indexOf(":")));
remoteAndBranchName.put("branch", checkedOutBranch.substring(checkedOutBranch.indexOf("/") + 1, checkedOutBranch.indexOf(":")));
} else {
remoteAndBranchName.put("branch", checkedOutBranch.substring(checkedOutBranch.indexOf("/") + 1));
}

}
}
} else {
return Map.ofEntries(new AbstractMap.SimpleEntry<>("remote", "unknown"),
new AbstractMap.SimpleEntry<>("branch", "unknown"));
return Map.ofEntries(new AbstractMap.SimpleEntry<>("remote", "unknown"), new AbstractMap.SimpleEntry<>("branch", "unknown"));
}

return remoteAndBranchName;
Expand All @@ -235,10 +228,8 @@ public void reset(Path targetRepository, String branchName, String remoteName) {

if (!result.isSuccessful()) {
// reset to origin/master
this.context.warning("Git has detected modified files -- attempting to reset {} to '{}/{}'.", targetRepository,
remoteName, branchName);
result = this.processContext.addArg("reset").addArg("--hard").addArg(remoteName + "/" + branchName)
.run(PROCESS_MODE);
this.context.warning("Git has detected modified files -- attempting to reset {} to '{}/{}'.", targetRepository, remoteName, branchName);
result = this.processContext.addArg("reset").addArg("--hard").addArg(remoteName + "/" + branchName).run(PROCESS_MODE);

if (!result.isSuccessful()) {
this.context.warning("Git failed to reset {} to '{}/{}'.", remoteName, branchName, targetRepository);
Expand All @@ -253,8 +244,7 @@ public void cleanup(Path targetRepository) {
this.processContext.directory(targetRepository);
ProcessResult result;
// check for untracked files
result = this.processContext.addArg("ls-files").addArg("--other").addArg("--directory").addArg("--exclude-standard")
.run(ProcessMode.DEFAULT_CAPTURE);
result = this.processContext.addArg("ls-files").addArg("--other").addArg("--directory").addArg("--exclude-standard").run(ProcessMode.DEFAULT_CAPTURE);

if (!result.getOut().isEmpty()) {
// delete untracked files
Expand All @@ -267,4 +257,20 @@ public void cleanup(Path targetRepository) {
}
}

@Override
public String retrieveGitUrl(Path repository) {

this.processContext.directory(repository);
ProcessResult result;
result = this.processContext.addArgs("-C", repository, "remote", "-v").run(ProcessMode.DEFAULT_CAPTURE);
for (String line : result.getOut()) {
if (line.contains("(fetch)")) {
return line.split("\\s+")[1]; // Extract the URL from the line
}
}

throw new IllegalStateException("Failed to retrieve git URL for repository: " + repository);
}
}


Loading
Loading