-
Notifications
You must be signed in to change notification settings - Fork 84
#1676 import extra sdks automatically into ide #2073
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
base: main
Are you sure you want to change the base?
Changes from 26 commits
040cfdc
cb6288f
becc527
545d71d
8f7769d
98a77be
ddfd368
df62d45
0a5b9fa
4e996ff
f18a437
a06dfa4
1162c0b
96afb63
9a7eb4b
c64b534
e4ad045
39dbb99
caaa822
9361305
88be370
1b4d02b
a108c07
b7ec91b
0cf86fb
507c37e
64a14df
2c59544
eff2e29
a1ecaba
b41deaf
d602c63
b5c3608
3a145e2
fce92ca
836c602
27f1c50
fc56853
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,22 +2,35 @@ | |
|
|
||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.w3c.dom.Document; | ||
|
|
||
| import com.devonfw.tools.ide.common.Tag; | ||
| import com.devonfw.tools.ide.context.IdeContext; | ||
| import com.devonfw.tools.ide.environment.AbstractEnvironmentVariables; | ||
| import com.devonfw.tools.ide.environment.ExtensibleEnvironmentVariables; | ||
| import com.devonfw.tools.ide.io.FileAccess; | ||
| import com.devonfw.tools.ide.log.IdeLogLevel; | ||
| import com.devonfw.tools.ide.merge.xml.XmlMergeDocument; | ||
| import com.devonfw.tools.ide.merge.xml.XmlMerger; | ||
| import com.devonfw.tools.ide.process.ProcessMode; | ||
| import com.devonfw.tools.ide.process.ProcessResult; | ||
| import com.devonfw.tools.ide.step.Step; | ||
| import com.devonfw.tools.ide.tool.ToolCommandlet; | ||
| import com.devonfw.tools.ide.tool.ToolInstallRequest; | ||
| import com.devonfw.tools.ide.tool.ToolInstallation; | ||
| import com.devonfw.tools.ide.tool.eclipse.Eclipse; | ||
| import com.devonfw.tools.ide.tool.extra.ExtraToolInstallation; | ||
| import com.devonfw.tools.ide.tool.extra.ExtraTools; | ||
| import com.devonfw.tools.ide.tool.extra.ExtraToolsMapper; | ||
| import com.devonfw.tools.ide.tool.intellij.Intellij; | ||
| import com.devonfw.tools.ide.tool.plugin.PluginBasedCommandlet; | ||
| import com.devonfw.tools.ide.tool.vscode.Vscode; | ||
|
|
@@ -29,6 +42,8 @@ public abstract class IdeToolCommandlet extends PluginBasedCommandlet { | |
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(IdeToolCommandlet.class); | ||
|
|
||
|
hohwille marked this conversation as resolved.
|
||
| private final Map<String, Set<Path>> extraSdkMap; | ||
|
|
||
| /** | ||
| * The constructor. | ||
| * | ||
|
|
@@ -40,6 +55,7 @@ public IdeToolCommandlet(IdeContext context, String tool, Set<Tag> tags) { | |
|
|
||
| super(context, tool, tags); | ||
| assert (hasIde(tags)); | ||
|
vivu001 marked this conversation as resolved.
|
||
| this.extraSdkMap = new HashMap<>(); | ||
| } | ||
|
|
||
| private boolean hasIde(Set<Tag> tags) { | ||
|
|
@@ -66,10 +82,17 @@ public ProcessResult runTool(List<String> args) { | |
| @Override | ||
| public ToolInstallation install(ToolInstallRequest request) { | ||
|
|
||
| configureWorkspace(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah great finding. So the big picture gets clearer.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested it: without In the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the current state and how can we finally resolve this. However, as you also found out and confirmed the plugin installation requires somehow the workspace configuration to be triggered.
I really like to merge this PR finally but IMHO this is still not 100% cleared to the end. |
||
| return super.install(request); | ||
| } | ||
|
|
||
| /** | ||
| * Synchronizes extra tool installations into the IDE workspace. | ||
| * This is called after extra tools are installed during ide create/update and before launching the IDE. | ||
| */ | ||
| public void synchronizeExtraTools() { | ||
| configureWorkspace(); | ||
| } | ||
|
|
||
|
hohwille marked this conversation as resolved.
Outdated
|
||
| /** | ||
| * Configure (initialize or update) the workspace for this IDE using the templates from the settings. | ||
| */ | ||
|
|
@@ -91,6 +114,9 @@ private void doMergeWorkspaceStep(Step step, Path workspaceFolder) { | |
| errors = mergeWorkspace(this.context.getUserHomeIde(), workspaceFolder, errors); | ||
| errors = mergeWorkspace(this.context.getSettingsPath(), workspaceFolder, errors); | ||
| errors = mergeWorkspace(this.context.getConfPath(), workspaceFolder, errors); | ||
|
|
||
| synchronizeExtraToolInstallations(); | ||
|
|
||
| if (errors == 0) { | ||
|
hohwille marked this conversation as resolved.
|
||
| step.success(); | ||
| } else { | ||
|
|
@@ -131,4 +157,86 @@ public void importRepository(Path repositoryPath) { | |
|
|
||
| throw new UnsupportedOperationException("Repository import is not yet implemented for IDE " + this.tool); | ||
| } | ||
|
|
||
| /** | ||
| * Registers support for synchronizing an extra SDK/template for this IDE. | ||
| * | ||
| * <p> | ||
| * The registered template path must be relative to the IDE workspace root. During workspace synchronization, the generic extra-SDK handling in | ||
| * {@link #synchronizeExtraToolInstallations()} uses this mapping to locate the corresponding template file in the settings repository and merge it into the | ||
| * current workspace. | ||
| * </p> | ||
| * | ||
| * @param sdk the name of the extra SDK/tool as configured in {@code ide-extra-tools.json}. | ||
| * @param relativeTemplatePath the workspace-relative path of the IDE-specific template file to merge. | ||
| */ | ||
| protected void registerExtraSdkTemplate(String sdk, Path relativeTemplatePath) { | ||
| Set<Path> templatePaths = this.extraSdkMap.computeIfAbsent(sdk, _ -> new HashSet<>()); | ||
| templatePaths.add(relativeTemplatePath); | ||
| } | ||
|
|
||
| /** | ||
| * Synchronizes extra IDEasy tool installations into the current IDE workspace configuration if supported. | ||
| * | ||
| * <p> | ||
| * By default, nothing will happen. Your IDE commandlet has to register one or more according templates in its constructor. | ||
| * </p> | ||
| */ | ||
| protected void synchronizeExtraToolInstallations() { | ||
| ExtraTools extraTools = ExtraToolsMapper.get().loadJsonFromFolder(this.context.getSettingsPath()); | ||
| if (extraTools == null) { | ||
| return; | ||
| } | ||
| for (String sdk : extraTools.getSortedToolNames()) { | ||
| Set<Path> templatePaths = this.extraSdkMap.get(sdk); | ||
| if ((templatePaths == null) || templatePaths.isEmpty()) { | ||
| LOG.debug("Skipping import of extra tool {} into {} because not configured or supported.", sdk, this.tool); | ||
| continue; | ||
| } | ||
| List<ExtraToolInstallation> extraInstallations = extraTools.getExtraInstallations(sdk); | ||
| synchronizeExtraToolInstallation(sdk, templatePaths, extraInstallations); | ||
| } | ||
| } | ||
|
|
||
| private void synchronizeExtraToolInstallation(String sdk, Set<Path> templatePaths, List<ExtraToolInstallation> extraInstallations) { | ||
| for (Path templatePath : templatePaths) { | ||
| Path workspaceFile = this.context.getWorkspacePath().resolve(templatePath); | ||
| Path templateFile = this.context.getSettingsPath().resolve(this.tool).resolve(IdeContext.FOLDER_WORKSPACE) | ||
| .resolve("repository") // TODO: create and use constant IdeContext.FOLDER_REPOSITORY - this string literal exists at least 16 times in our code base | ||
|
hohwille marked this conversation as resolved.
Outdated
|
||
| .resolve(templatePath); | ||
| if (Files.exists(templateFile)) { | ||
| for (ExtraToolInstallation extraInstallation : extraInstallations) { | ||
| synchronizeExtraToolInstallation(sdk, templateFile, workspaceFile, extraInstallation); | ||
| } | ||
| } else { | ||
| LOG.warn("You are missing a template file at {}.", templatePath); | ||
| IdeLogLevel.INTERACTION.log(LOG, "Please ask the IDEasy admin in your project to merge your settings with upstream."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void synchronizeExtraToolInstallation(String sdk, Path templateFile, Path workspaceFile, ExtraToolInstallation installation) { | ||
| String name = installation.name(); | ||
| Path extraToolHome = this.context.getSoftwareExtraPath().resolve(sdk).resolve(name); | ||
| if (!Files.isDirectory(extraToolHome)) { | ||
| LOG.warn("Skipping extra tool installation import to {} because it is missing at {}", this.tool, extraToolHome); | ||
| IdeLogLevel.INTERACTION.log(LOG, "Please run the following command to fix:\nide update"); | ||
| return; | ||
| } | ||
| ExtensibleEnvironmentVariables environmentVariables = new ExtensibleEnvironmentVariables( | ||
| (AbstractEnvironmentVariables) this.context.getVariables().getParent(), this.context); | ||
| String variablePrefix = "EXTRA_" + sdk.toUpperCase(Locale.ROOT); | ||
| environmentVariables.setValue(variablePrefix + "_NAME", name); | ||
| environmentVariables.setValue(variablePrefix + "_HOME", extraToolHome.toString().replace('\\', '/')); | ||
| environmentVariables.setValue(variablePrefix + "_VERSION", installation.version().toString()); | ||
| if (installation.edition() != null) { | ||
| environmentVariables.setValue(variablePrefix + "_EDITION", installation.edition()); | ||
| } | ||
|
|
||
| XmlMerger xmlMerger = new XmlMerger(this.context); | ||
| XmlMergeDocument workspaceDocument = xmlMerger.load(workspaceFile); | ||
| XmlMergeDocument templateDocument = xmlMerger.loadAndResolve(templateFile, environmentVariables); | ||
| Document mergedDocument = xmlMerger.merge(templateDocument, workspaceDocument, false); | ||
| xmlMerger.save(mergedDocument, workspaceFile); | ||
| } | ||
|
hohwille marked this conversation as resolved.
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.