Skip to content

Commit 5c95a79

Browse files
authored
#280: configure maven properly (#305)
1 parent 023f8de commit 5c95a79

File tree

7 files changed

+261
-81
lines changed

7 files changed

+261
-81
lines changed

cli/src/main/java/com/devonfw/tools/ide/context/AbstractIdeContext.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,18 @@ public String askForInput(String message, String defaultValue) {
695695
return input.isEmpty() ? defaultValue : input;
696696
}
697697

698+
@Override
699+
public String askForInput(String message) {
700+
701+
String input;
702+
do {
703+
info(message);
704+
input = readLine().trim();
705+
} while (input.isEmpty());
706+
707+
return input;
708+
}
709+
698710
@SuppressWarnings("unchecked")
699711
@Override
700712
public <O> O question(String question, O... options) {
Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.devonfw.tools.ide.context;
22

3-
import java.nio.file.Path;
4-
53
import com.devonfw.tools.ide.cli.CliOfflineException;
64

5+
import java.nio.file.Path;
6+
77
/**
88
* Interface for git commands with input and output of information for the user.
99
*/
@@ -12,15 +12,16 @@ public interface GitContext {
1212
/** The default git remote name. */
1313
String DEFAULT_REMOTE = "origin";
1414

15+
/** The default git url of the settings repository for IDEasy developers */
16+
String DEFAULT_SETTINGS_GIT_URL = "https://github.com/devonfw/ide-settings.git";
17+
1518
/**
16-
* Checks if the Git repository in the specified target folder needs an update by inspecting the modification time of
17-
* a magic file.
19+
* Checks if the Git repository in the specified target folder needs an update by inspecting the modification time of a magic file.
1820
*
1921
* @param repoUrl the git remote URL to clone from.
2022
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
21-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
22-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
23-
* final folder that will contain the ".git" subfolder.
23+
* @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
24+
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
2425
* @throws CliOfflineException if offline and cloning is needed.
2526
*/
2627
void pullOrCloneIfNeeded(String repoUrl, String branch, Path targetRepository);
@@ -29,9 +30,8 @@ public interface GitContext {
2930
* Attempts a git pull and reset if required.
3031
*
3132
* @param repoUrl the git remote URL to clone from.
32-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
33-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
34-
* final folder that will contain the ".git" subfolder.
33+
* @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
34+
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
3535
* @throws CliOfflineException if offline and cloning is needed.
3636
*/
3737
default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository) {
@@ -43,9 +43,8 @@ default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository)
4343
* Attempts a git pull and reset if required.
4444
*
4545
* @param repoUrl the git remote URL to clone from.
46-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
47-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
48-
* final folder that will contain the ".git" subfolder.
46+
* @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
47+
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
4948
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
5049
* @throws CliOfflineException if offline and cloning is needed.
5150
*/
@@ -58,9 +57,8 @@ default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository,
5857
* Attempts a git pull and reset if required.
5958
*
6059
* @param repoUrl the git remote URL to clone from.
61-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
62-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
63-
* final folder that will contain the ".git" subfolder.
60+
* @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
61+
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
6462
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
6563
* @param remoteName the remote name e.g. origin.
6664
* @throws CliOfflineException if offline and cloning is needed.
@@ -71,9 +69,8 @@ default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository,
7169
* Runs a git pull or a git clone.
7270
*
7371
* @param gitRepoUrl the git remote URL to clone from.
74-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
75-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
76-
* final folder that will contain the ".git" subfolder.
72+
* @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
73+
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
7774
* @throws CliOfflineException if offline and cloning is needed.
7875
*/
7976
void pullOrClone(String gitRepoUrl, Path targetRepository);
@@ -83,9 +80,8 @@ default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository,
8380
*
8481
* @param gitRepoUrl the git remote URL to clone from.
8582
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
86-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
87-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
88-
* final folder that will contain the ".git" subfolder.
83+
* @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
84+
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
8985
* @throws CliOfflineException if offline and cloning is needed.
9086
*/
9187
void pullOrClone(String gitRepoUrl, String branch, Path targetRepository);
@@ -94,28 +90,25 @@ default void pullOrCloneAndResetIfNeeded(String repoUrl, Path targetRepository,
9490
* Runs a git clone.
9591
*
9692
* @param gitRepoUrl the {@link GitUrl} to use for the repository URL.
97-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
98-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the *
99-
* final folder that will contain the ".git" subfolder.
93+
* @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
94+
* will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
10095
* @throws CliOfflineException if offline and cloning is needed.
10196
*/
10297
void clone(GitUrl gitRepoUrl, Path targetRepository);
10398

10499
/**
105100
* Runs a git pull.
106101
*
107-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
108-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the *
109-
* final folder that will contain the ".git" subfolder.
102+
* @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
103+
* will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
110104
*/
111105
void pull(Path targetRepository);
112106

113107
/**
114108
* Runs a git diff-index to detect local changes and if so reverts them via git reset.
115109
*
116-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
117-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
118-
* final folder that will contain the ".git" subfolder.
110+
* @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
111+
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
119112
*/
120113
default void reset(Path targetRepository) {
121114

@@ -125,9 +118,8 @@ default void reset(Path targetRepository) {
125118
/**
126119
* Runs a git diff-index to detect local changes and if so reverts them via git reset.
127120
*
128-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
129-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the
130-
* final folder that will contain the ".git" subfolder.
121+
* @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
122+
* will by default create a sub-folder by default on clone but the final folder that will contain the ".git" subfolder.
131123
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
132124
*/
133125
default void reset(Path targetRepository, String branch) {
@@ -138,9 +130,8 @@ default void reset(Path targetRepository, String branch) {
138130
/**
139131
* Runs a git reset reverting all local changes to the git repository.
140132
*
141-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
142-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the *
143-
* final folder that will contain the ".git" subfolder.
133+
* @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
134+
* will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
144135
* @param branch the explicit name of the branch to checkout e.g. "main" or {@code null} to use the default branch.
145136
* @param remoteName the name of the git remote e.g. "origin".
146137
*/
@@ -149,10 +140,17 @@ default void reset(Path targetRepository, String branch) {
149140
/**
150141
* Runs a git cleanup if untracked files were found.
151142
*
152-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
153-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the *
154-
* final folder that will contain the ".git" subfolder.
143+
* @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
144+
* will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
155145
*/
156146
void cleanup(Path targetRepository);
157147

148+
/**
149+
* Returns the URL of a git repository
150+
*
151+
* @param repository the {@link Path} to the folder where the git repository is located.
152+
* @return the url of the repository as a {@link String}.
153+
*/
154+
String retrieveGitUrl(Path repository);
155+
158156
}

cli/src/main/java/com/devonfw/tools/ide/context/GitContextImpl.java

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package com.devonfw.tools.ide.context;
22

3+
import com.devonfw.tools.ide.cli.CliOfflineException;
4+
import com.devonfw.tools.ide.process.ProcessContext;
5+
import com.devonfw.tools.ide.process.ProcessErrorHandling;
6+
import com.devonfw.tools.ide.process.ProcessMode;
7+
import com.devonfw.tools.ide.process.ProcessResult;
8+
39
import java.io.IOException;
410
import java.net.URL;
511
import java.nio.file.Files;
@@ -12,12 +18,6 @@
1218
import java.util.Map;
1319
import java.util.Objects;
1420

15-
import com.devonfw.tools.ide.cli.CliOfflineException;
16-
import com.devonfw.tools.ide.process.ProcessContext;
17-
import com.devonfw.tools.ide.process.ProcessErrorHandling;
18-
import com.devonfw.tools.ide.process.ProcessMode;
19-
import com.devonfw.tools.ide.process.ProcessResult;
20-
2121
/**
2222
* Implements the {@link GitContext}.
2323
*/
@@ -101,8 +101,7 @@ public void pullOrClone(String gitRepoUrl, String branch, Path targetRepository)
101101
ProcessResult result = this.processContext.addArg("remote").run(ProcessMode.DEFAULT_CAPTURE);
102102
List<String> remotes = result.getOut();
103103
if (remotes.isEmpty()) {
104-
String message = targetRepository
105-
+ " is a local git repository with no remote - if you did this for testing, you may continue...\n"
104+
String message = targetRepository + " is a local git repository with no remote - if you did this for testing, you may continue...\n"
106105
+ "Do you want to ignore the problem and continue anyhow?";
107106
this.context.askToContinue(message);
108107
} else {
@@ -120,9 +119,8 @@ public void pullOrClone(String gitRepoUrl, String branch, Path targetRepository)
120119
/**
121120
* Handles errors which occurred during git pull.
122121
*
123-
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
124-
* It is not the parent directory where git will by default create a sub-folder by default on clone but the *
125-
* final folder that will contain the ".git" subfolder.
122+
* @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
123+
* will by default create a sub-folder by default on clone but the * final folder that will contain the ".git" subfolder.
126124
* @param result the {@link ProcessResult} to evaluate.
127125
*/
128126
private void handleErrors(Path targetRepository, ProcessResult result) {
@@ -135,11 +133,9 @@ private void handleErrors(Path targetRepository, ProcessResult result) {
135133
} else {
136134
this.context.error(message);
137135
if (this.context.isOnline()) {
138-
this.context
139-
.error("See above error for details. If you have local changes, please stash or revert and retry.");
136+
this.context.error("See above error for details. If you have local changes, please stash or revert and retry.");
140137
} else {
141-
this.context.error(
142-
"It seems you are offline - please ensure Internet connectivity and retry or activate offline mode (-o or --offline).");
138+
this.context.error("It seems you are offline - please ensure Internet connectivity and retry or activate offline mode (-o or --offline).");
143139
}
144140
this.context.askToContinue("Typically you should abort and fix the problem. Do you want to continue anyways?");
145141
}
@@ -173,8 +169,7 @@ public void clone(GitUrl gitRepoUrl, Path targetRepository) {
173169
}
174170
}
175171
} else {
176-
throw new CliOfflineException(
177-
"Could not clone " + parsedUrl + " to " + targetRepository + " because you are offline.");
172+
throw new CliOfflineException("Could not clone " + parsedUrl + " to " + targetRepository + " because you are offline.");
178173
}
179174
}
180175

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

189184
if (!result.isSuccessful()) {
190185
Map<String, String> remoteAndBranchName = retrieveRemoteAndBranchName();
191-
this.context.warning("Git pull for {}/{} failed for repository {}.", remoteAndBranchName.get("remote"),
192-
remoteAndBranchName.get("branch"), targetRepository);
186+
this.context.warning("Git pull for {}/{} failed for repository {}.", remoteAndBranchName.get("remote"), remoteAndBranchName.get("branch"),
187+
targetRepository);
193188
handleErrors(targetRepository, result);
194189
}
195190
}
@@ -206,17 +201,15 @@ private Map<String, String> retrieveRemoteAndBranchName() {
206201
remoteAndBranchName.put("remote", checkedOutBranch.substring(0, checkedOutBranch.indexOf("/")));
207202
// check if current repo is behind remote and omit message
208203
if (checkedOutBranch.contains(":")) {
209-
remoteAndBranchName.put("branch",
210-
checkedOutBranch.substring(checkedOutBranch.indexOf("/") + 1, checkedOutBranch.indexOf(":")));
204+
remoteAndBranchName.put("branch", checkedOutBranch.substring(checkedOutBranch.indexOf("/") + 1, checkedOutBranch.indexOf(":")));
211205
} else {
212206
remoteAndBranchName.put("branch", checkedOutBranch.substring(checkedOutBranch.indexOf("/") + 1));
213207
}
214208

215209
}
216210
}
217211
} else {
218-
return Map.ofEntries(new AbstractMap.SimpleEntry<>("remote", "unknown"),
219-
new AbstractMap.SimpleEntry<>("branch", "unknown"));
212+
return Map.ofEntries(new AbstractMap.SimpleEntry<>("remote", "unknown"), new AbstractMap.SimpleEntry<>("branch", "unknown"));
220213
}
221214

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

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

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

259249
if (!result.getOut().isEmpty()) {
260250
// delete untracked files
@@ -267,4 +257,21 @@ public void cleanup(Path targetRepository) {
267257
}
268258
}
269259

260+
@Override
261+
public String retrieveGitUrl(Path repository) {
262+
263+
this.processContext.directory(repository);
264+
ProcessResult result;
265+
result = this.processContext.addArgs("-C", repository, "remote", "-v").run(ProcessMode.DEFAULT_CAPTURE);
266+
for (String line : result.getOut()) {
267+
if (line.contains("(fetch)")) {
268+
return line.split("\\s+")[1]; // Extract the URL from the line
269+
}
270+
}
271+
272+
this.context.error("Failed to retrieve git URL for repository: {}", repository);
273+
return null;
274+
}
270275
}
276+
277+

0 commit comments

Comments
 (0)