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

improve behaviour on ambiguous XPath match #1130

Open
hohwille opened this issue Mar 13, 2025 · 1 comment · May be fixed by #1138
Open

improve behaviour on ambiguous XPath match #1130

hohwille opened this issue Mar 13, 2025 · 1 comment · May be fixed by #1138
Assignees
Labels
enhancement New feature or request intellij IntelliJ IDE from Jet-Brains merger

Comments

@hohwille
Copy link
Member

hohwille commented Mar 13, 2025

As a IDEasy user, I want to run my IDE seamlessly so that I do not have to worry about stacktraces or get blocked by errors.

Actual behaviour

$ ide intellij
Start: Configuring workspace main for IDE intellij
Failed to merge workspace file D:\projects\IDEasy\workspaces\main\.idea\workspace.xml with update template D:\projects\IDEasy\settings\intellij\workspace\update\.idea\workspace.xml and setup file D:\projects\IDEasy\settings\intellij\workspace\setup\.idea\workspace.xml!
com.devonfw.tools.ide.merge.xmlmerger.XmlMergeException: Merge strategy combine failed on /project[@version='4']/component[@name='RunManager']
        at com.devonfw.tools.ide.merge.xmlmerger.XmlMergeStrategy.merge(XmlMergeStrategy.java:69)
        at com.devonfw.tools.ide.merge.xmlmerger.XmlMergeStrategy.combineChildNodes(XmlMergeStrategy.java:113)
        at com.devonfw.tools.ide.merge.xmlmerger.XmlMergeStrategy$1.doMerge(XmlMergeStrategy.java:29)
        at com.devonfw.tools.ide.merge.xmlmerger.XmlMergeStrategy.merge(XmlMergeStrategy.java:65)
        at com.devonfw.tools.ide.merge.xmlmerger.XmlMerger.merge(XmlMerger.java:123)
        at com.devonfw.tools.ide.merge.xmlmerger.XmlMerger.doMerge(XmlMerger.java:82)
        at com.devonfw.tools.ide.merge.FileMerger.merge(FileMerger.java:50)
        at com.devonfw.tools.ide.merge.DirectoryMerger.merge(DirectoryMerger.java:69)
        at com.devonfw.tools.ide.merge.DirectoryMerger.merge(DirectoryMerger.java:73)
        at com.devonfw.tools.ide.merge.DirectoryMerger.merge(DirectoryMerger.java:73)
        at com.devonfw.tools.ide.tool.ide.IdeToolCommandlet.mergeWorkspaceSingle(IdeToolCommandlet.java:103)
        at com.devonfw.tools.ide.tool.ide.IdeToolCommandlet.mergeWorkspace(IdeToolCommandlet.java:90)
        at com.devonfw.tools.ide.tool.ide.IdeToolCommandlet.configureWorkspace(IdeToolCommandlet.java:72)
        at com.devonfw.tools.ide.tool.ide.IdeToolCommandlet.run(IdeToolCommandlet.java:48)
        at com.devonfw.tools.ide.context.AbstractIdeContext.applyAndRun(AbstractIdeContext.java:958)
        at com.devonfw.tools.ide.context.AbstractIdeContext.run(AbstractIdeContext.java:876)
        at com.devonfw.tools.ide.cli.Ideasy.runOrThrow(Ideasy.java:95)
        at com.devonfw.tools.ide.cli.Ideasy.run(Ideasy.java:59)
        at com.devonfw.tools.ide.cli.Ideasy.main(Ideasy.java:133)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: java.lang.IllegalStateException: 2 matches found for XPath configuration[@default='true' and @type='JUnit'] in workspace XML at /project[@version='4']/component[@name='RunManager' @selected='JUnit.UninstallCommandletTest']
        at com.devonfw.tools.ide.merge.xmlmerger.matcher.IdComputer.evaluateExpression(IdComputer.java:65)
        at com.devonfw.tools.ide.merge.xmlmerger.matcher.ElementMatcher.matchElement(ElementMatcher.java:61)
        at com.devonfw.tools.ide.merge.xmlmerger.XmlMergeStrategy.combineChildNodes(XmlMergeStrategy.java:107)
        at com.devonfw.tools.ide.merge.xmlmerger.XmlMergeStrategy$1.doMerge(XmlMergeStrategy.java:29)
        at com.devonfw.tools.ide.merge.xmlmerger.XmlMergeStrategy.merge(XmlMergeStrategy.java:65)
        ... 19 more

Your workspace configuration failed with 1 error(s) - see log above.
This is either a configuration error in your settings git repository or a bug in IDEasy.
Please analyze the above errors with your team or IDE-admin and try to fix the problem.
In order to prevent you from being blocked, you can start your IDE anyhow but some configuration may not be in sync.
Option 1: yes
Option 2: no

If you want to manually reproduce the error you can:

  1. Edit your file $IDE_HOME/workspaces/main/.idea/workspace.xml
  2. Search for configuration default="true" type="JUnit" factoryName="JUnit"
  3. duplicate that XML element (entire fragment until first closing </configuration>).
  4. run ide intellij on your main workspace

Expected behaviour

IntelliJ opens without errors.

Comments

IDEasy is supposed to help projects to setup and update IDE tools and configurations.
It does a great job also merging complex changes into IntelliJ XML configuration files.
However, in such edge-cases, it can get in the way.
While it is still possible to answer yes here, an average user is confused and over time annoyed by this error.
If IDEasy is supposed to make the life of the developer "easy" this experience may conflict.

Technically the error message says that in the actual configuration file in your workspace, something should be unique but is not. So most likely some XML block is actually duplicated in your configuration.

This error should be rare and can have different reasons:

  1. The XML template is simply incorrect (wrong merge:id) and the "IDE admin" who created the XML template has to fix it.
  2. The XML template was wrong before but is already fixed. However, due to problems caused before when the XML template was incorrect, some error sneaked into my actual XML configuration file in my workspace.
  3. Something external (e.g. the IDE tool itself or the end user whilst modifying config files manually) caused this error (quite unlikely, because then mainly the assumption about the unique-ness was wrong as we still have reason 1. - however in very rare cases, we have also seen this)

An experienced IDEasy admin or expert can surely analyse and fix this problem.
However, a regular developer will typically just want to launch IntelliJ and may not have any clue about XML, XPath, the IDEasy XML Merger, etc.
Therefore, it is not helpful for such end-user to print stacktraces and ask questions to continue here.

Solution

Instead, we could consider the following options:

  • Just log a warning with the message but without the stacktrace (Reduce XmlMerger error output for regular users #1132)
  • Instead of raising an exception that prevents the merge, we could take the first match of the XPath and merge that. In 80% of the cases this will still do the job and solve the problem.
  • Probably consider a property for IDE admins to get the current behaviour back with exception because to test that the XML templates and all the settings are sane this may still be helpful.
@hohwille hohwille added the enhancement New feature or request label Mar 13, 2025
@github-project-automation github-project-automation bot moved this to 🆕 New in IDEasy board Mar 13, 2025
@hohwille hohwille added merger intellij IntelliJ IDE from Jet-Brains labels Mar 13, 2025
@hohwille
Copy link
Member Author

See also #1132

@leonrohne27 leonrohne27 moved this from 🆕 New to 🏗 In progress in IDEasy board Mar 14, 2025
leonrohne27 added a commit to leonrohne27/IDEasy that referenced this issue Mar 17, 2025
leonrohne27 added a commit to leonrohne27/IDEasy that referenced this issue Mar 17, 2025
@leonrohne27 leonrohne27 linked a pull request Mar 17, 2025 that will close this issue
@hohwille hohwille added this to the release:2025.03.002 milestone Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request intellij IntelliJ IDE from Jet-Brains merger
Projects
Status: 🏗 In progress
2 participants