Skip to content

Commit 43687d4

Browse files
authored
#212: m2 repo settings as MAVEN_ARGS (#275)
1 parent 43c1a70 commit 43687d4

File tree

3 files changed

+95
-86
lines changed

3 files changed

+95
-86
lines changed

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

+73-78
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.devonfw.tools.ide.context;
22

3-
import java.nio.file.Path;
4-
import java.util.Locale;
5-
63
import com.devonfw.tools.ide.cli.CliAbortException;
74
import com.devonfw.tools.ide.cli.CliException;
85
import com.devonfw.tools.ide.cli.CliOfflineException;
@@ -22,6 +19,9 @@
2219
import com.devonfw.tools.ide.url.model.UrlMetadata;
2320
import com.devonfw.tools.ide.variable.IdeVariables;
2421

22+
import java.nio.file.Path;
23+
import java.util.Locale;
24+
2525
/**
2626
* Interface for interaction with the user allowing to input and output information.
2727
*/
@@ -47,8 +47,8 @@ public interface IdeContext extends IdeLogger {
4747
String FOLDER_CONF = "conf";
4848

4949
/**
50-
* The base folder name of the IDE inside IDE_ROOT. Intentionally starting with an underscore and not a dot (to
51-
* prevent effects like OS hiding, maven filtering, .gitignore, etc.).
50+
* The base folder name of the IDE inside IDE_ROOT. Intentionally starting with an underscore and not a dot (to prevent effects like OS hiding, maven
51+
* filtering, .gitignore, etc.).
5252
*/
5353
String FOLDER_IDE = "_ide";
5454

@@ -83,35 +83,32 @@ public interface IdeContext extends IdeLogger {
8383
String FOLDER_APP = "app";
8484

8585
/**
86-
* The name of the {@link #getPluginsPath() plugins folder} and also the plugins folder inside the IDE folders of
87-
* {@link #getSettingsPath() settings} (e.g. settings/eclipse/plugins).
86+
* The name of the {@link #getPluginsPath() plugins folder} and also the plugins folder inside the IDE folders of {@link #getSettingsPath() settings} (e.g.
87+
* settings/eclipse/plugins).
8888
*/
8989
String FOLDER_PLUGINS = "plugins";
9090

9191
/**
92-
* The name of the workspace folder inside the IDE specific {@link #FOLDER_SETTINGS settings} containing the
93-
* configuration templates in #FOLDER_SETUP #FOLDER_UPDATE.
92+
* The name of the workspace folder inside the IDE specific {@link #FOLDER_SETTINGS settings} containing the configuration templates in #FOLDER_SETUP
93+
* #FOLDER_UPDATE.
9494
*/
9595
String FOLDER_WORKSPACE = "workspace";
9696

9797
/**
98-
* The name of the setup folder inside the {@link #FOLDER_WORKSPACE workspace} folder containing the templates for the
99-
* configuration templates for the initial setup of a workspace. This is closely related with the
100-
* {@link #FOLDER_UPDATE update} folder.
98+
* The name of the setup folder inside the {@link #FOLDER_WORKSPACE workspace} folder containing the templates for the configuration templates for the initial
99+
* setup of a workspace. This is closely related with the {@link #FOLDER_UPDATE update} folder.
101100
*/
102101
String FOLDER_SETUP = "setup";
103102

104103
/**
105-
* The name of the update folder inside the {@link #FOLDER_WORKSPACE workspace} folder containing the templates for
106-
* the configuration templates for the update of a workspace. Configurations in this folder will be applied every time
107-
* the IDE is started. They will override the settings the user may have manually configured every time. This is only
108-
* for settings that have to be the same for every developer in the project. An example would be the number of spaces
109-
* used for indentation and other code-formatting settings. If all developers in a project team use the same formatter
110-
* settings, this will actively prevent diff-wars. However, the entire team needs to agree on these settings.<br>
111-
* Never configure aspects inside this update folder that may be of personal flavor such as the color theme. Otherwise
112-
* developers will hate you as you actively take away their freedom to customize the IDE to their personal needs and
113-
* wishes. Therefore do all "biased" or "flavored" configurations in {@link #FOLDER_SETUP setup} so these are only
114-
* pre-configured but can be changed by the user as needed.
104+
* The name of the update folder inside the {@link #FOLDER_WORKSPACE workspace} folder containing the templates for the configuration templates for the update
105+
* of a workspace. Configurations in this folder will be applied every time the IDE is started. They will override the settings the user may have manually
106+
* configured every time. This is only for settings that have to be the same for every developer in the project. An example would be the number of spaces used
107+
* for indentation and other code-formatting settings. If all developers in a project team use the same formatter settings, this will actively prevent
108+
* diff-wars. However, the entire team needs to agree on these settings.<br> Never configure aspects inside this update folder that may be of personal flavor
109+
* such as the color theme. Otherwise developers will hate you as you actively take away their freedom to customize the IDE to their personal needs and
110+
* wishes. Therefore do all "biased" or "flavored" configurations in {@link #FOLDER_SETUP setup} so these are only pre-configured but can be changed by the
111+
* user as needed.
115112
*/
116113
String FOLDER_UPDATE = "update";
117114

@@ -139,8 +136,7 @@ public interface IdeContext extends IdeLogger {
139136
boolean isQuietMode();
140137

141138
/**
142-
* @return {@code true} in case of batch mode (no {@link #question(String) user-interaction}), {@code false}
143-
* otherwise.
139+
* @return {@code true} in case of batch mode (no {@link #question(String) user-interaction}), {@code false} otherwise.
144140
*/
145141
boolean isBatchMode();
146142

@@ -155,8 +151,7 @@ public interface IdeContext extends IdeLogger {
155151
boolean isOfflineMode();
156152

157153
/**
158-
* @return {@code true} if {@link #isOfflineMode() offline mode} is active or we are NOT {@link #isOnline() online},
159-
* {@code false} otherwise.
154+
* @return {@code true} if {@link #isOfflineMode() offline mode} is active or we are NOT {@link #isOnline() online}, {@code false} otherwise.
160155
*/
161156
default boolean isOffline() {
162157

@@ -194,16 +189,15 @@ default boolean question(String question) {
194189
/**
195190
* @param <O> type of the option. E.g. {@link String}.
196191
* @param question the question to ask.
197-
* @param options the available options for the user to answer. There should be at least two options given as
198-
* otherwise the question cannot make sense.
192+
* @param options the available options for the user to answer. There should be at least two options given as otherwise the question cannot make sense.
199193
* @return the option selected by the user as answer.
200194
*/
201195
@SuppressWarnings("unchecked")
202196
<O> O question(String question, O... options);
203197

204198
/**
205-
* Will ask the given question. If the user answers with "yes" the method will return and the process can continue.
206-
* Otherwise if the user answers with "no" an exception is thrown to abort further processing.
199+
* Will ask the given question. If the user answers with "yes" the method will return and the process can continue. Otherwise if the user answers with "no" an
200+
* exception is thrown to abort further processing.
207201
*
208202
* @param question the yes/no question to {@link #question(String) ask}.
209203
* @throws CliAbortException if the user answered with "no" and further processing shall be aborted.
@@ -258,30 +252,27 @@ default void requireOnline(String purpose) {
258252
CustomToolRepository getCustomToolRepository();
259253

260254
/**
261-
* @return the {@link Path} to the IDE instance directory. You can have as many IDE instances on the same computer as
262-
* independent tenants for different isolated projects.
255+
* @return the {@link Path} to the IDE instance directory. You can have as many IDE instances on the same computer as independent tenants for different
256+
* isolated projects.
263257
* @see com.devonfw.tools.ide.variable.IdeVariables#IDE_HOME
264258
*/
265259
Path getIdeHome();
266260

267261
/**
268-
* @return the {@link Path} to the IDE installation root directory. This is the top-level folder where the
269-
* {@link #getIdeHome() IDE instances} are located as sub-folder. There is a reserved ".ide" folder where
270-
* central IDE data is stored such as the {@link #getUrlsPath() download metadata} and the central software
271-
* repository.
262+
* @return the {@link Path} to the IDE installation root directory. This is the top-level folder where the {@link #getIdeHome() IDE instances} are located as
263+
* sub-folder. There is a reserved ".ide" folder where central IDE data is stored such as the {@link #getUrlsPath() download metadata} and the central
264+
* software repository.
272265
* @see com.devonfw.tools.ide.variable.IdeVariables#IDE_ROOT
273266
*/
274267
Path getIdeRoot();
275268

276269
/**
277-
* @return the current working directory ("user.dir"). This is the directory where the user's shell was located when
278-
* the IDE CLI was invoked.
270+
* @return the current working directory ("user.dir"). This is the directory where the user's shell was located when the IDE CLI was invoked.
279271
*/
280272
Path getCwd();
281273

282274
/**
283-
* @return the {@link Path} for the temporary directory to use. Will be different from the OS specific temporary
284-
* directory (java.io.tmpDir).
275+
* @return the {@link Path} for the temporary directory to use. Will be different from the OS specific temporary directory (java.io.tmpDir).
285276
*/
286277
Path getTempPath();
287278

@@ -291,63 +282,55 @@ default void requireOnline(String purpose) {
291282
Path getTempDownloadPath();
292283

293284
/**
294-
* @return the {@link Path} to the download metadata (ide-urls). Here a git repository is cloned and updated (pulled)
295-
* to always have the latest metadata to download tools.
285+
* @return the {@link Path} to the download metadata (ide-urls). Here a git repository is cloned and updated (pulled) to always have the latest metadata to
286+
* download tools.
296287
* @see com.devonfw.tools.ide.url.model.folder.UrlRepository
297288
*/
298289
Path getUrlsPath();
299290

300291
/**
301-
* @return the {@link UrlMetadata}. Will be lazily instantiated and thereby automatically be cloned or pulled (by
302-
* default).
292+
* @return the {@link UrlMetadata}. Will be lazily instantiated and thereby automatically be cloned or pulled (by default).
303293
*/
304294
UrlMetadata getUrls();
305295

306296
/**
307-
* @return the {@link Path} to the download cache. All downloads will be placed here using a unique naming pattern
308-
* that allows to reuse these artifacts. So if the same artifact is requested again it will be taken from the
309-
* cache to avoid downloading it again.
297+
* @return the {@link Path} to the download cache. All downloads will be placed here using a unique naming pattern that allows to reuse these artifacts. So if
298+
* the same artifact is requested again it will be taken from the cache to avoid downloading it again.
310299
*/
311300
Path getDownloadPath();
312301

313302
/**
314-
* @return the {@link Path} to the software folder inside {@link #getIdeHome() IDE_HOME}. All tools for that IDE
315-
* instance will be linked here from the {@link #getSoftwareRepositoryPath() software repository} as
316-
* sub-folder named after the according tool.
303+
* @return the {@link Path} to the software folder inside {@link #getIdeHome() IDE_HOME}. All tools for that IDE instance will be linked here from the
304+
* {@link #getSoftwareRepositoryPath() software repository} as sub-folder named after the according tool.
317305
*/
318306
Path getSoftwarePath();
319307

320308
/**
321-
* @return the {@link Path} to the global software repository. This is the central directory where the tools are
322-
* extracted physically on the local disc. Those are shared among all IDE instances (see {@link #getIdeHome()
323-
* IDE_HOME}) via symbolic links (see {@link #getSoftwarePath()}). Therefore this repository follows the
324-
* sub-folder structure {@code «repository»/«tool»/«edition»/«version»/}. So multiple versions of the same
325-
* tool exist here as different folders. Further, such software may not be modified so e.g. installation of
326-
* plugins and other kind of changes to such tool need to happen strictly out of the scope of this folders.
309+
* @return the {@link Path} to the global software repository. This is the central directory where the tools are extracted physically on the local disc. Those
310+
* are shared among all IDE instances (see {@link #getIdeHome() IDE_HOME}) via symbolic links (see {@link #getSoftwarePath()}). Therefore this repository
311+
* follows the sub-folder structure {@code «repository»/«tool»/«edition»/«version»/}. So multiple versions of the same tool exist here as different folders.
312+
* Further, such software may not be modified so e.g. installation of plugins and other kind of changes to such tool need to happen strictly out of the scope
313+
* of this folders.
327314
*/
328315
Path getSoftwareRepositoryPath();
329316

330317
/**
331-
* @return the {@link Path} to the {@link #FOLDER_PLUGINS plugins folder} inside {@link #getIdeHome() IDE_HOME}. All
332-
* plugins of the IDE instance will be stored here. For each tool that supports plugins a sub-folder with the
333-
* tool name will be created where the plugins for that tool get installed.
318+
* @return the {@link Path} to the {@link #FOLDER_PLUGINS plugins folder} inside {@link #getIdeHome() IDE_HOME}. All plugins of the IDE instance will be
319+
* stored here. For each tool that supports plugins a sub-folder with the tool name will be created where the plugins for that tool get installed.
334320
*/
335321
Path getPluginsPath();
336322

337323
/**
338-
* @return the {@link Path} to the central tool repository. All tools will be installed in this location using the
339-
* directory naming schema of {@code «repository»/«tool»/«edition»/«version»/}. Actual {@link #getIdeHome()
340-
* IDE instances} will only contain symbolic links to the physical tool installations in this repository. This
341-
* allows to share and reuse tool installations across multiple {@link #getIdeHome() IDE instances}. The
342-
* variable {@code «repository»} is typically {@code default} for the tools from our standard
343-
* {@link #getUrlsPath() ide-urls download metadata} but this will differ for custom tools from a private
344-
* repository.
324+
* @return the {@link Path} to the central tool repository. All tools will be installed in this location using the directory naming schema of
325+
* {@code «repository»/«tool»/«edition»/«version»/}. Actual {@link #getIdeHome() IDE instances} will only contain symbolic links to the physical tool
326+
* installations in this repository. This allows to share and reuse tool installations across multiple {@link #getIdeHome() IDE instances}. The variable
327+
* {@code «repository»} is typically {@code default} for the tools from our standard {@link #getUrlsPath() ide-urls download metadata} but this will differ
328+
* for custom tools from a private repository.
345329
*/
346330
Path getToolRepositoryPath();
347331

348332
/**
349-
* @return the {@link Path} to the users home directory. Typically initialized via the
350-
* {@link System#getProperty(String) system property} "user.home".
333+
* @return the {@link Path} to the users home directory. Typically initialized via the {@link System#getProperty(String) system property} "user.home".
351334
* @see com.devonfw.tools.ide.variable.IdeVariables#HOME
352335
*/
353336
Path getUserHome();
@@ -358,14 +341,13 @@ default void requireOnline(String purpose) {
358341
Path getUserHomeIde();
359342

360343
/**
361-
* @return the {@link Path} to the {@code settings} folder with the cloned git repository containing the project
362-
* configuration.
344+
* @return the {@link Path} to the {@code settings} folder with the cloned git repository containing the project configuration.
363345
*/
364346
Path getSettingsPath();
365347

366348
/**
367349
* @return the {@link Path} to the {@code conf} folder with instance specific tool configurations and the
368-
* {@link EnvironmentVariablesType#CONF user specific project configuration}.
350+
* {@link EnvironmentVariablesType#CONF user specific project configuration}.
369351
*/
370352
Path getConfPath();
371353

@@ -381,15 +363,13 @@ default void requireOnline(String purpose) {
381363
String getWorkspaceName();
382364

383365
/**
384-
* @return the value of the system {@link IdeVariables#PATH PATH} variable. It is automatically extended according to
385-
* the tools available in {@link #getSoftwarePath() software path} unless {@link #getIdeHome() IDE_HOME} was
386-
* not found.
366+
* @return the value of the system {@link IdeVariables#PATH PATH} variable. It is automatically extended according to the tools available in
367+
* {@link #getSoftwarePath() software path} unless {@link #getIdeHome() IDE_HOME} was not found.
387368
*/
388369
SystemPath getPath();
389370

390371
/**
391-
* @return the current {@link Locale}. Either configured via command-line option or {@link Locale#getDefault()
392-
* default}.
372+
* @return the current {@link Locale}. Either configured via command-line option or {@link Locale#getDefault() default}.
393373
*/
394374
Locale getLocale();
395375

@@ -408,8 +388,7 @@ default void requireOnline(String purpose) {
408388
IdeProgressBar prepareProgressBar(String taskName, long size);
409389

410390
/**
411-
* @return the {@link DirectoryMerger} used to configure and merge the workspace for an
412-
* {@link com.devonfw.tools.ide.tool.ide.IdeToolCommandlet IDE}.
391+
* @return the {@link DirectoryMerger} used to configure and merge the workspace for an {@link com.devonfw.tools.ide.tool.ide.IdeToolCommandlet IDE}.
413392
*/
414393
DirectoryMerger getWorkspaceMerger();
415394

@@ -419,6 +398,22 @@ default void requireOnline(String purpose) {
419398
GitContext getGitContext();
420399

421400
/**
401+
* @return the String value for the variable MAVEN_ARGS, or null if called outside an IDEasy installation.
402+
*/
403+
default String getMavenArgs() {
404+
405+
Path ideHome = getIdeHome();
406+
if (ideHome != null) {
407+
return "-s " + ideHome.resolve("conf/.m2/settings.xml");
408+
} else {
409+
return null;
410+
}
411+
}
412+
413+
/**
414+
* Updates the current working directory (CWD) and configures the environment paths according to the specified parameters.
415+
* This method is central to changing the IDE's notion of where it operates, affecting where configurations, workspaces,
416+
* settings, and other resources are located or loaded from.
422417
* @return the current {@link Step} of processing.
423418
*/
424419
Step getCurrentStep();

0 commit comments

Comments
 (0)