Skip to content

Commit dbc533c

Browse files
mbildajan-vcapgeminihohwille
authored
#1007: Implemented granular force options for update command (#1180)
Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com> Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>
1 parent d4aba53 commit dbc533c

File tree

15 files changed

+262
-17
lines changed

15 files changed

+262
-17
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE
66

77
Release with new features and bugfixes:
88

9+
* https://github.com/devonfw/IDEasy/issues/1007[#1007]: Consider explicit option flags instead of overusing force mode
910
* https://github.com/devonfw/IDEasy/issues/951[#951]: Fix text coloring in native cmd and powershell terminals
1011
* https://github.com/devonfw/IDEasy/issues/1202[#1202]: IDEasy can not reset urls on WSL
1112
* https://github.com/devonfw/IDEasy/issues/692[#692]: "Latest" version of Docker causes installation problems

cli/src/main/java/com/devonfw/tools/ide/commandlet/AbstractUpdateCommandlet.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public abstract class AbstractUpdateCommandlet extends Commandlet {
3737
/** {@link FlagProperty} for skipping the setup of git repositories. */
3838
public final FlagProperty skipRepositories;
3939

40+
/** {@link FlagProperty} to force the update of the settings git repository. */
41+
public final FlagProperty forcePull;
42+
43+
/** {@link FlagProperty} to force the installation/update of plugins. */
44+
public final FlagProperty forcePlugins;
45+
46+
/** {@link FlagProperty} to force the setup of git repositories. */
47+
public final FlagProperty forceRepositories;
48+
4049
/**
4150
* The constructor.
4251
*
@@ -48,13 +57,20 @@ public AbstractUpdateCommandlet(IdeContext context) {
4857
addKeyword(getName());
4958
this.skipTools = add(new FlagProperty("--skip-tools"));
5059
this.skipRepositories = add(new FlagProperty("--skip-repositories"));
60+
this.forcePull = add(new FlagProperty("--force-pull"));
61+
this.forcePlugins = add(new FlagProperty("--force-plugins"));
62+
this.forceRepositories = add(new FlagProperty("--force-repositories"));
5163
this.settingsRepo = new StringProperty("", false, "settingsRepository");
5264
}
5365

5466
@Override
5567
public void run() {
5668

57-
if (!this.context.isSettingsRepositorySymlinkOrJunction() || this.context.isForceMode()) {
69+
this.context.setForcePull(forcePull.isTrue());
70+
this.context.setForcePlugins(forcePlugins.isTrue());
71+
this.context.setForceRepositories(forceRepositories.isTrue());
72+
73+
if (!this.context.isSettingsRepositorySymlinkOrJunction() || this.context.isForceMode() || forcePull.isTrue()) {
5874
updateSettings();
5975
}
6076
updateConf();
@@ -201,6 +217,9 @@ private void updateSoftware() {
201217
private void updateRepositories() {
202218

203219
if (this.skipRepositories.isTrue()) {
220+
if (this.forceRepositories.isTrue()) {
221+
this.context.warning("Options to skip and force repositories are incompatible and should not be combined. Ignoring --force-repositories to proceed.");
222+
}
204223
this.context.info("Skipping setup of repositories as specified by the user.");
205224
return;
206225
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,24 @@ public boolean isForceMode() {
611611
return this.startContext.isForceMode();
612612
}
613613

614+
@Override
615+
public boolean isForcePull() {
616+
617+
return this.startContext.isForcePull();
618+
}
619+
620+
@Override
621+
public boolean isForcePlugins() {
622+
623+
return this.startContext.isForcePlugins();
624+
}
625+
626+
@Override
627+
public boolean isForceRepositories() {
628+
629+
return this.startContext.isForceRepositories();
630+
}
631+
614632
@Override
615633
public boolean isOfflineMode() {
616634

@@ -751,7 +769,7 @@ public String askForInput(String message, String defaultValue) {
751769
info(message);
752770
}
753771
if (isBatchMode()) {
754-
if (isForceMode()) {
772+
if (isForceMode() || isForcePull()) {
755773
return defaultValue;
756774
} else {
757775
throw new CliAbortException();
@@ -795,7 +813,7 @@ public <O> O question(String question, O... options) {
795813
}
796814
O option = null;
797815
if (isBatchMode()) {
798-
if (isForceMode()) {
816+
if (isForceMode() || isForcePull()) {
799817
option = options[0];
800818
interaction("" + option);
801819
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ public class IdeContextConsole extends AbstractIdeContext {
1414

1515
private final Scanner scanner;
1616

17+
private boolean forcePull;
18+
19+
private boolean forcePlugins;
20+
21+
private boolean forceRepositories;
22+
1723
/**
1824
* The constructor.
1925
*
@@ -63,4 +69,34 @@ public IdeProgressBar newProgressBar(String title, long size, String unitName, l
6369

6470
return new IdeProgressBarConsole(getSystemInfo(), title, size, unitName, unitSize);
6571
}
72+
73+
@Override
74+
public boolean isForcePull() {
75+
return forcePull;
76+
}
77+
78+
@Override
79+
public boolean isForcePlugins() {
80+
return forcePlugins;
81+
}
82+
83+
@Override
84+
public boolean isForceRepositories() {
85+
return forceRepositories;
86+
}
87+
88+
@Override
89+
public void setForcePull(boolean forcePull) {
90+
this.forcePull = forcePull;
91+
}
92+
93+
@Override
94+
public void setForcePlugins(boolean forcePlugins) {
95+
this.forcePlugins = forcePlugins;
96+
}
97+
98+
@Override
99+
public void setForceRepositories(boolean forceRepositories) {
100+
this.forceRepositories = forceRepositories;
101+
}
66102
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,42 @@ public interface IdeStartContext extends IdeLogger {
2626
*/
2727
boolean isForceMode();
2828

29+
/**
30+
* @return {@code true} in case of force pull, {@code false} otherwise.
31+
*/
32+
boolean isForcePull();
33+
34+
/**
35+
* @return {@code true} in case of force plugins, {@code false} otherwise.
36+
*/
37+
boolean isForcePlugins();
38+
39+
/**
40+
* @return {@code true} in case of force repositories, {@code false} otherwise.
41+
*/
42+
boolean isForceRepositories();
43+
44+
/**
45+
* Sets a new value which indicates if pull from git should be forced
46+
*
47+
* @param forcePull {@code true} if it should be forced, {@code false} otherwise.
48+
*/
49+
void setForcePull(boolean forcePull);
50+
51+
/**
52+
* Sets a new value which indicates if plugins should be forced to be installed/updated
53+
*
54+
* @param forcePlugins {@code true} if it should be forced, {@code false} otherwise.
55+
*/
56+
void setForcePlugins(boolean forcePlugins);
57+
58+
/**
59+
* Sets a new value which indicates if repositories should be forced to be pulled
60+
*
61+
* @param forceRepositories {@code true} if it should be forced, {@code false} otherwise.
62+
*/
63+
void setForceRepositories(boolean forceRepositories);
64+
2965
/**
3066
* @return {@code true} if offline mode is activated (-o/--offline), {@code false} otherwise.
3167
*/

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

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public class IdeStartContextImpl extends IdeLoggerImpl implements IdeStartContex
1919

2020
private boolean forceMode;
2121

22+
private boolean forcePull;
23+
24+
private boolean forcePlugins;
25+
26+
private boolean forceRepositories;
27+
2228
private boolean batchMode;
2329

2430
private boolean quietMode;
@@ -68,14 +74,48 @@ public boolean isForceMode() {
6874
return this.forceMode;
6975
}
7076

71-
/**
72-
* @param forceMode new value of {@link #isForceMode()}.
73-
*/
77+
@Override
78+
public boolean isForcePull() {
79+
80+
return this.forcePull;
81+
}
82+
83+
@Override
84+
public boolean isForcePlugins() {
85+
86+
return this.forcePlugins;
87+
}
88+
89+
@Override
90+
public boolean isForceRepositories() {
91+
92+
return this.forceRepositories;
93+
}
94+
95+
7496
public void setForceMode(boolean forceMode) {
7597

7698
this.forceMode = forceMode;
7799
}
78100

101+
@Override
102+
public void setForcePull(boolean forcePull) {
103+
104+
this.forcePull = forcePull;
105+
}
106+
107+
@Override
108+
public void setForcePlugins(boolean forcePlugins) {
109+
110+
this.forcePlugins = forcePlugins;
111+
}
112+
113+
@Override
114+
public void setForceRepositories(boolean forceRepositories) {
115+
116+
this.forceRepositories = forceRepositories;
117+
}
118+
79119
@Override
80120
public boolean isOfflineMode() {
81121

cli/src/main/java/com/devonfw/tools/ide/git/GitOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private boolean isNeeded(Path targetRepository, IdeContext context) {
148148
if (context.isOffline()) {
149149
context.info("Skipping git {} on {} because we are offline.", this.name, targetRepository);
150150
return false;
151-
} else if (context.isForceMode()) {
151+
} else if (context.isForceMode() || context.isForcePull()) {
152152
context.debug("Enforcing git {} on {} because force mode is active.", this.name, targetRepository);
153153
return true;
154154
}

cli/src/main/java/com/devonfw/tools/ide/git/repository/RepositoryCommandlet.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void run() {
5959
}
6060
List<Path> propertiesFiles = this.context.getFileAccess()
6161
.listChildren(repositoriesPath, path -> path.getFileName().toString().endsWith(".properties"));
62-
boolean forceMode = this.context.isForceMode();
62+
boolean forceMode = this.context.isForceMode() || this.context.isForceRepositories();
6363
for (Path propertiesFile : propertiesFiles) {
6464
doImportRepository(propertiesFile, forceMode);
6565
}
@@ -99,17 +99,17 @@ private void doImportRepository(Path repositoryFile, boolean forceMode, String r
9999
Path repositoryPath = getRepositoryPath(repositoryConfig, repositoryId);
100100
if (Files.isDirectory(repositoryPath.resolve(GitContext.GIT_FOLDER))) {
101101
this.context.info("Repository {} already exists at {}", repositoryId, repositoryPath);
102-
if (!this.context.isForceMode()) {
103-
this.context.info("Ignoring repository {} - use --force to rerun setup.", repositoryId);
102+
if (!(this.context.isForceMode() || this.context.isForceRepositories())) {
103+
this.context.info("Ignoring repository {} - use --force or --force-repositories to rerun setup.", repositoryId);
104104
return;
105105
}
106106
}
107107
Path ideStatusDir = this.context.getIdeHome().resolve(IdeContext.FOLDER_DOT_IDE);
108108
this.context.getFileAccess().mkdirs(ideStatusDir);
109109
Path repositoryCreatedStatusFile = ideStatusDir.resolve("repository." + repositoryId);
110110
if (Files.exists(repositoryCreatedStatusFile)) {
111-
if (!this.context.isForceMode()) {
112-
this.context.info("Ignoring repository {} because it was already setup before - use --force for recreation.", repository);
111+
if (!(this.context.isForceMode() || this.context.isForceRepositories())) {
112+
this.context.info("Ignoring repository {} because it was already setup before - use --force or --force-repositories for recreation.", repository);
113113
return;
114114
}
115115
}

cli/src/main/java/com/devonfw/tools/ide/tool/plugin/PluginBasedCommandlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private void installPlugins(ProcessContext pc) {
127127
protected void installPlugins(Collection<ToolPluginDescriptor> plugins, ProcessContext pc) {
128128
for (ToolPluginDescriptor plugin : plugins) {
129129
if (plugin.active()) {
130-
if (retrievePluginMarkerFilePath(plugin) != null && Files.exists(retrievePluginMarkerFilePath(plugin))) {
130+
if (!this.context.isForcePlugins() && retrievePluginMarkerFilePath(plugin) != null && Files.exists(retrievePluginMarkerFilePath(plugin))) {
131131
this.context.debug("Markerfile for IDE: {} and active plugin: {} already exists.", getName(), plugin.name());
132132
} else {
133133
try (Step step = this.context.newStep("Install plugin " + plugin.name())) {

cli/src/main/resources/nls/Help.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ opt.--batch=enable batch mode (non-interactive).
124124
opt.--code=clone given code repository containing a settings folder into workspaces so that settings can be committed alongside code changes.
125125
opt.--debug=enable debug logging.
126126
opt.--force=enable force mode.
127+
opt.--force-plugins=force plugin (re)installation.
128+
opt.--force-pull=force pull of settings even for code repository.
129+
opt.--force-repositories=force setup of repositories to even clone inactive and pull existing ones.
127130
opt.--locale=the locale (e.g. '--locale=de' for German language).
128131
opt.--offline=enable offline mode (skip updates or git pull, fail downloads or git clone).
129132
opt.--quiet=disable info logging (only log success, warning or error).

0 commit comments

Comments
 (0)