From 7e393244d828fbfdd87539fd4efd0ed3fbb98325 Mon Sep 17 00:00:00 2001 From: Marco Vomiero Date: Fri, 22 Mar 2024 15:54:09 +0100 Subject: [PATCH 1/2] implements variable MAVEN_ARGS --- .../tools/ide/variable/IdeVariables.java | 14 ++++++++------ .../ide/variable/VariableDefinitionString.java | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java b/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java index 4d2f9a48f..90747c70e 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java +++ b/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java @@ -26,15 +26,13 @@ public interface IdeVariables { /** * {@link VariableDefinition} for {@link com.devonfw.tools.ide.context.IdeContext#getWorkspacePath() WORKSPACE_PATH}. */ - VariableDefinitionPath WORKSPACE_PATH = new VariableDefinitionPath("WORKSPACE_PATH", null, c -> c.getWorkspacePath(), - true); + VariableDefinitionPath WORKSPACE_PATH = new VariableDefinitionPath("WORKSPACE_PATH", null, c -> c.getWorkspacePath(), true); /** {@link VariableDefinition} for list of tools to install by default. */ VariableDefinitionStringList IDE_TOOLS = new VariableDefinitionStringList("IDE_TOOLS", "DEVON_IDE_TOOLS"); /** {@link VariableDefinition} for list of IDE tools to create start scripts for. */ - VariableDefinitionStringList CREATE_START_SCRIPTS = new VariableDefinitionStringList("CREATE_START_SCRIPTS", - "DEVON_CREATE_START_SCRIPTS"); + VariableDefinitionStringList CREATE_START_SCRIPTS = new VariableDefinitionStringList("CREATE_START_SCRIPTS", "DEVON_CREATE_START_SCRIPTS"); /** {@link VariableDefinition} for minimum IDE product version. */ // TODO define initial IDEasy version as default value @@ -43,6 +41,10 @@ public interface IdeVariables { /** {@link VariableDefinition} for version of maven (mvn). */ VariableDefinitionVersion MVN_VERSION = new VariableDefinitionVersion("MVN_VERSION", "MAVEN_VERSION"); + /** {@link VariableDefinition} arguments for maven to set the m2 repo location. */ + VariableDefinitionString MAVEN_ARGS = new VariableDefinitionString("MAVEN_ARGS", null, c -> "-s " + c.getIdeHome().resolve("conf/.m2/settings.xml"), false, + true); + /** {@link VariableDefinition} for {@link com.devonfw.tools.ide.context.IdeContext#getWorkspaceName() WORKSPACE}. */ VariableDefinitionString DOCKER_EDITION = new VariableDefinitionString("DOCKER_EDITION", null, c -> "rancher"); @@ -54,8 +56,8 @@ public interface IdeVariables { c -> "algorithm=PBEWITHHMACSHA512ANDAES_256 ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator"); /** A {@link Collection} with all pre-defined {@link VariableDefinition}s. */ - Collection> VARIABLES = List.of(PATH, HOME, WORKSPACE_PATH, IDE_HOME, IDE_ROOT, WORKSPACE, - IDE_TOOLS, CREATE_START_SCRIPTS, IDE_MIN_VERSION, MVN_VERSION, DOCKER_EDITION, GRAALVM_EDITION, JASYPT_OPTS); + Collection> VARIABLES = List.of(PATH, HOME, WORKSPACE_PATH, IDE_HOME, IDE_ROOT, WORKSPACE, IDE_TOOLS, CREATE_START_SCRIPTS, + IDE_MIN_VERSION, MVN_VERSION, DOCKER_EDITION, GRAALVM_EDITION, JASYPT_OPTS, MAVEN_ARGS); /** * @param name the name of the requested {@link VariableDefinition}. diff --git a/cli/src/main/java/com/devonfw/tools/ide/variable/VariableDefinitionString.java b/cli/src/main/java/com/devonfw/tools/ide/variable/VariableDefinitionString.java index 101a9ff5d..0d0e292ec 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/variable/VariableDefinitionString.java +++ b/cli/src/main/java/com/devonfw/tools/ide/variable/VariableDefinitionString.java @@ -51,12 +51,25 @@ public VariableDefinitionString(String name, String legacyName, Function defaultValueFactory, - boolean forceDefaultValue) { + public VariableDefinitionString(String name, String legacyName, Function defaultValueFactory, boolean forceDefaultValue) { super(name, legacyName, defaultValueFactory, forceDefaultValue); } + /** + * The constructor. + * + * @param name the {@link #getName() variable name}. + * @param legacyName the {@link #getLegacyName() legacy name}. + * @param defaultValueFactory the factory {@link Function} for the {@link #getDefaultValue(IdeContext) default value}. + * @param forceDefaultValue the {@link #isForceDefaultValue() forceDefaultValue} flag. + * @param export the {@link #isExport() value}. + */ + public VariableDefinitionString(String name, String legacyName, Function defaultValueFactory, boolean forceDefaultValue, boolean export) { + + super(name, legacyName, defaultValueFactory, forceDefaultValue, export); + } + @Override public Class getValueType() { From 9ba9a01807735323848dc833848baeaed8f75ffb Mon Sep 17 00:00:00 2001 From: Marco Vomiero Date: Wed, 10 Apr 2024 15:58:59 +0200 Subject: [PATCH 2/2] implements null check while setting MAVEN_ARGS --- .../devonfw/tools/ide/context/IdeContext.java | 148 +++++++++--------- .../tools/ide/variable/IdeVariables.java | 3 +- 2 files changed, 71 insertions(+), 80 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java b/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java index 4090da8bb..9074a0e44 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java +++ b/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java @@ -1,8 +1,5 @@ package com.devonfw.tools.ide.context; -import java.nio.file.Path; -import java.util.Locale; - import com.devonfw.tools.ide.cli.CliAbortException; import com.devonfw.tools.ide.cli.CliException; import com.devonfw.tools.ide.commandlet.CommandletManager; @@ -20,6 +17,9 @@ import com.devonfw.tools.ide.url.model.UrlMetadata; import com.devonfw.tools.ide.variable.IdeVariables; +import java.nio.file.Path; +import java.util.Locale; + /** * Interface for interaction with the user allowing to input and output information. */ @@ -38,8 +38,8 @@ public interface IdeContext extends IdeLogger { String FOLDER_CONF = "conf"; /** - * 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 filtering, .gitignore, etc.). + * 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 + * filtering, .gitignore, etc.). */ String FOLDER_IDE = "_ide"; @@ -74,35 +74,32 @@ public interface IdeContext extends IdeLogger { String FOLDER_APP = "app"; /** - * The name of the {@link #getPluginsPath() plugins folder} and also the plugins folder inside the IDE folders of - * {@link #getSettingsPath() settings} (e.g. settings/eclipse/plugins). + * The name of the {@link #getPluginsPath() plugins folder} and also the plugins folder inside the IDE folders of {@link #getSettingsPath() settings} (e.g. + * settings/eclipse/plugins). */ String FOLDER_PLUGINS = "plugins"; /** - * The name of the workspace folder inside the IDE specific {@link #FOLDER_SETTINGS settings} containing the - * configuration templates in #FOLDER_SETUP #FOLDER_UPDATE. + * The name of the workspace folder inside the IDE specific {@link #FOLDER_SETTINGS settings} containing the configuration templates in #FOLDER_SETUP + * #FOLDER_UPDATE. */ String FOLDER_WORKSPACE = "workspace"; /** - * The name of the setup folder inside the {@link #FOLDER_WORKSPACE workspace} folder containing the templates for the - * configuration templates for the initial setup of a workspace. This is closely related with the - * {@link #FOLDER_UPDATE update} folder. + * The name of the setup folder inside the {@link #FOLDER_WORKSPACE workspace} folder containing the templates for the configuration templates for the initial + * setup of a workspace. This is closely related with the {@link #FOLDER_UPDATE update} folder. */ String FOLDER_SETUP = "setup"; /** - * The name of the update folder inside the {@link #FOLDER_WORKSPACE workspace} folder containing the templates for - * the configuration templates for the update 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 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 for indentation and other code-formatting settings. If all developers in a project team use the same formatter - * settings, this will actively prevent diff-wars. However, the entire team needs to agree on these settings.
- * Never configure aspects inside this update folder that may be of personal flavor 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 - * 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 user as needed. + * The name of the update folder inside the {@link #FOLDER_WORKSPACE workspace} folder containing the templates for the configuration templates for the update + * 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 + * 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 + * for indentation and other code-formatting settings. If all developers in a project team use the same formatter settings, this will actively prevent + * diff-wars. However, the entire team needs to agree on these settings.
Never configure aspects inside this update folder that may be of personal flavor + * 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 + * 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 + * user as needed. */ String FOLDER_UPDATE = "update"; @@ -124,8 +121,7 @@ public interface IdeContext extends IdeLogger { boolean isQuietMode(); /** - * @return {@code true} in case of batch mode (no {@link #question(String) user-interaction}), {@code false} - * otherwise. + * @return {@code true} in case of batch mode (no {@link #question(String) user-interaction}), {@code false} otherwise. */ boolean isBatchMode(); @@ -140,8 +136,7 @@ public interface IdeContext extends IdeLogger { boolean isOfflineMode(); /** - * @return {@code true} if {@link #isOfflineMode() offline mode} is active or we are NOT {@link #isOnline() online}, - * {@code false} otherwise. + * @return {@code true} if {@link #isOfflineMode() offline mode} is active or we are NOT {@link #isOnline() online}, {@code false} otherwise. */ default boolean isOffline() { @@ -170,16 +165,15 @@ default boolean question(String question) { /** * @param type of the option. E.g. {@link String}. * @param question the question to ask. - * @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. + * @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. * @return the option selected by the user as answer. */ @SuppressWarnings("unchecked") O question(String question, O... options); /** - * 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 exception is thrown to abort further processing. + * 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 + * exception is thrown to abort further processing. * * @param question the yes/no question to {@link #question(String) ask}. * @throws CliAbortException if the user answered with "no" and further processing shall be aborted. @@ -234,30 +228,27 @@ default void requireOnline(String purpose) { CustomToolRepository getCustomToolRepository(); /** - * @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 isolated projects. + * @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 + * isolated projects. * @see com.devonfw.tools.ide.variable.IdeVariables#IDE_HOME */ Path getIdeHome(); /** - * @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 sub-folder. There is a reserved ".ide" folder where - * central IDE data is stored such as the {@link #getUrlsPath() download metadata} and the central software - * repository. + * @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 + * sub-folder. There is a reserved ".ide" folder where central IDE data is stored such as the {@link #getUrlsPath() download metadata} and the central + * software repository. * @see com.devonfw.tools.ide.variable.IdeVariables#IDE_ROOT */ Path getIdeRoot(); /** - * @return the current working directory ("user.dir"). This is the directory where the user's shell was located when - * the IDE CLI was invoked. + * @return the current working directory ("user.dir"). This is the directory where the user's shell was located when the IDE CLI was invoked. */ Path getCwd(); /** - * @return the {@link Path} for the temporary directory to use. Will be different from the OS specific temporary - * directory (java.io.tmpDir). + * @return the {@link Path} for the temporary directory to use. Will be different from the OS specific temporary directory (java.io.tmpDir). */ Path getTempPath(); @@ -267,63 +258,55 @@ default void requireOnline(String purpose) { Path getTempDownloadPath(); /** - * @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 download tools. + * @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 + * download tools. * @see com.devonfw.tools.ide.url.model.folder.UrlRepository */ Path getUrlsPath(); /** - * @return the {@link UrlMetadata}. Will be lazily instantiated and thereby automatically be cloned or pulled (by - * default). + * @return the {@link UrlMetadata}. Will be lazily instantiated and thereby automatically be cloned or pulled (by default). */ UrlMetadata getUrls(); /** - * @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 the same artifact is requested again it will be taken from the - * cache to avoid downloading it again. + * @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 + * the same artifact is requested again it will be taken from the cache to avoid downloading it again. */ Path getDownloadPath(); /** - * @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 {@link #getSoftwareRepositoryPath() software repository} as - * sub-folder named after the according tool. + * @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 + * {@link #getSoftwareRepositoryPath() software repository} as sub-folder named after the according tool. */ Path getSoftwarePath(); /** - * @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 are shared among all IDE instances (see {@link #getIdeHome() - * IDE_HOME}) via symbolic links (see {@link #getSoftwarePath()}). Therefore this repository follows the - * sub-folder structure {@code «repository»/«tool»/«edition»/«version»/}. So multiple versions of the same - * tool exist here as different folders. 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 of this folders. + * @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 + * are shared among all IDE instances (see {@link #getIdeHome() IDE_HOME}) via symbolic links (see {@link #getSoftwarePath()}). Therefore this repository + * follows the sub-folder structure {@code «repository»/«tool»/«edition»/«version»/}. So multiple versions of the same tool exist here as different folders. + * 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 + * of this folders. */ Path getSoftwareRepositoryPath(); /** - * @return the {@link Path} to the {@link #FOLDER_PLUGINS plugins folder} inside {@link #getIdeHome() IDE_HOME}. All - * plugins of the IDE instance will be 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. + * @return the {@link Path} to the {@link #FOLDER_PLUGINS plugins folder} inside {@link #getIdeHome() IDE_HOME}. All plugins of the IDE instance will be + * 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. */ Path getPluginsPath(); /** - * @return the {@link Path} to the central tool repository. All tools will be installed in this location using the - * directory naming schema of {@code «repository»/«tool»/«edition»/«version»/}. Actual {@link #getIdeHome() - * IDE instances} will only contain symbolic links to the physical tool installations in this repository. This - * allows to share and reuse tool installations across multiple {@link #getIdeHome() IDE instances}. The - * variable {@code «repository»} is typically {@code default} for the tools from our standard - * {@link #getUrlsPath() ide-urls download metadata} but this will differ for custom tools from a private - * repository. + * @return the {@link Path} to the central tool repository. All tools will be installed in this location using the directory naming schema of + * {@code «repository»/«tool»/«edition»/«version»/}. Actual {@link #getIdeHome() IDE instances} will only contain symbolic links to the physical tool + * installations in this repository. This allows to share and reuse tool installations across multiple {@link #getIdeHome() IDE instances}. The variable + * {@code «repository»} is typically {@code default} for the tools from our standard {@link #getUrlsPath() ide-urls download metadata} but this will differ + * for custom tools from a private repository. */ Path getToolRepositoryPath(); /** - * @return the {@link Path} to the users home directory. Typically initialized via the - * {@link System#getProperty(String) system property} "user.home". + * @return the {@link Path} to the users home directory. Typically initialized via the {@link System#getProperty(String) system property} "user.home". * @see com.devonfw.tools.ide.variable.IdeVariables#HOME */ Path getUserHome(); @@ -334,14 +317,13 @@ default void requireOnline(String purpose) { Path getUserHomeIde(); /** - * @return the {@link Path} to the {@code settings} folder with the cloned git repository containing the project - * configuration. + * @return the {@link Path} to the {@code settings} folder with the cloned git repository containing the project configuration. */ Path getSettingsPath(); /** * @return the {@link Path} to the {@code conf} folder with instance specific tool configurations and the - * {@link EnvironmentVariablesType#CONF user specific project configuration}. + * {@link EnvironmentVariablesType#CONF user specific project configuration}. */ Path getConfPath(); @@ -357,15 +339,13 @@ default void requireOnline(String purpose) { String getWorkspaceName(); /** - * @return the value of the system {@link IdeVariables#PATH PATH} variable. It is automatically extended according to - * the tools available in {@link #getSoftwarePath() software path} unless {@link #getIdeHome() IDE_HOME} was - * not found. + * @return the value of the system {@link IdeVariables#PATH PATH} variable. It is automatically extended according to the tools available in + * {@link #getSoftwarePath() software path} unless {@link #getIdeHome() IDE_HOME} was not found. */ SystemPath getPath(); /** - * @return the current {@link Locale}. Either configured via command-line option or {@link Locale#getDefault() - * default}. + * @return the current {@link Locale}. Either configured via command-line option or {@link Locale#getDefault() default}. */ Locale getLocale(); @@ -384,8 +364,7 @@ default void requireOnline(String purpose) { IdeProgressBar prepareProgressBar(String taskName, long size); /** - * @return the {@link DirectoryMerger} used to configure and merge the workspace for an - * {@link com.devonfw.tools.ide.tool.ide.IdeToolCommandlet IDE}. + * @return the {@link DirectoryMerger} used to configure and merge the workspace for an {@link com.devonfw.tools.ide.tool.ide.IdeToolCommandlet IDE}. */ DirectoryMerger getWorkspaceMerger(); @@ -394,4 +373,17 @@ default void requireOnline(String purpose) { */ GitContext getGitContext(); + /** + * @return the String value for the variable MAVEN_ARGS, or null if called outside an IDEasy installation. + */ + default String getMavenArgs() { + + Path ideHome = getIdeHome(); + if (ideHome != null) { + return "-s " + ideHome.resolve("conf/.m2/settings.xml"); + } else { + return null; + } + } + } diff --git a/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java b/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java index 90747c70e..96aef352d 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java +++ b/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java @@ -42,8 +42,7 @@ public interface IdeVariables { VariableDefinitionVersion MVN_VERSION = new VariableDefinitionVersion("MVN_VERSION", "MAVEN_VERSION"); /** {@link VariableDefinition} arguments for maven to set the m2 repo location. */ - VariableDefinitionString MAVEN_ARGS = new VariableDefinitionString("MAVEN_ARGS", null, c -> "-s " + c.getIdeHome().resolve("conf/.m2/settings.xml"), false, - true); + VariableDefinitionString MAVEN_ARGS = new VariableDefinitionString("MAVEN_ARGS", null, c -> c.getMavenArgs(), false, true); /** {@link VariableDefinition} for {@link com.devonfw.tools.ide.context.IdeContext#getWorkspaceName() WORKSPACE}. */ VariableDefinitionString DOCKER_EDITION = new VariableDefinitionString("DOCKER_EDITION", null, c -> "rancher");