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

#212: m2 repo settings as MAVEN_ARGS #275

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
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
148 changes: 70 additions & 78 deletions cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
*/
Expand All @@ -40,8 +40,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";

Expand Down Expand Up @@ -76,35 +76,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.<br>
* 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.<br> 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";

Expand All @@ -130,8 +127,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();

Expand All @@ -146,8 +142,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() {

Expand Down Expand Up @@ -185,16 +180,15 @@ default boolean question(String question) {
/**
* @param <O> 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> 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.
Expand Down Expand Up @@ -249,30 +243,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();

Expand All @@ -282,63 +273,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();
Expand All @@ -349,14 +332,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();

Expand All @@ -372,15 +354,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();

Expand All @@ -399,8 +379,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();

Expand All @@ -409,6 +388,19 @@ 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;
}
}

/**
* Updates the current working directory (CWD) and configures the environment paths according to the specified parameters.
* This method is central to changing the IDE's notion of where it operates, affecting where configurations, workspaces,
Expand Down
Loading
Loading