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

Support multiple attributes for merge:id #992

Open
hohwille opened this issue Jan 28, 2025 · 2 comments
Open

Support multiple attributes for merge:id #992

hohwille opened this issue Jan 28, 2025 · 2 comments
Labels
enhancement New feature or request intellij IntelliJ IDE from Jet-Brains merger settings ide-settings repo and replated processes and features

Comments

@hohwille
Copy link
Member

We need support to specify multiple attributes in merge:id for the XML merger.
In IntelliJ we have a a problem with the template workspace.xml:

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.configureWorkspace(IdeToolCommandlet.java:83)
        at com.devonfw.tools.ide.tool.ide.IdeToolCommandlet.run(IdeToolCommandlet.java:48)
        at com.devonfw.tools.ide.context.AbstractIdeContext.applyAndRun(AbstractIdeContext.java:887)
        at com.devonfw.tools.ide.context.AbstractIdeContext.run(AbstractIdeContext.java:812)
        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: 45 matches found for XPath configuration[local-name()='configuration'] in workspace XML at /project[@version='4']/component[@name='RunManager' @selected='JUnit.RepositoryCommandletTest.testFoo']
        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)
        ... 17 more

The problem comes from here:
https://github.com/devonfw/ide-settings/blob/ace6919d489a621460f9ef38440e189f02051cbc/intellij/workspace/update/.idea/workspace.xml#L32

    <configuration default="true" type="JUnit" factoryName="JUnit" merge:id="name()">

The problem here is that IntelliJ saves all launch configurations and lots of other aspects in this workspace.xml.
If you have more of them the merger will cause the exception above.
We could change merge:id to @type but then it will still fail once I had run some regular JUnits.
We could also change merge:id to @default but when I add a default launch configuration for Java applications or other stuff, it will still not be unique.
So in the end we can only uniquely identify this with the combination [@default='true' AND @type='JUnit'].
The good news is that our XML merger already allows to define custom XPath expressions so we have a workaround and quickfix for this.
However, for simplicity of configuration, it would be great, if I could just type merge:id="@default,@type" and this would automatically build the according XPath from my values avoiding redundancy and making my template simpler and more readable.
There could even be a shortcut merge:id="@@" to automatically add all attributes to the XPath, what would also work in this case.

@hohwille hohwille added enhancement New feature or request intellij IntelliJ IDE from Jet-Brains merger settings ide-settings repo and replated processes and features labels Jan 28, 2025
@github-project-automation github-project-automation bot moved this to 🆕 New in IDEasy board Jan 28, 2025
@hohwille
Copy link
Member Author

What is also interesting:
I had this error several times with the current state and sometimes I chose to continue and sometimes I chose to exit.
However, no matter what choice I take an additional XML section (JUnit default configuration) was added to my workspace.xml so it got very broken. In IntelliJ I even saw a growl popup showing something like IDE error. Failed to save settings. Please restart IntelliJ IDEA. However, restarting does not solve the problem so we are messing the config so it can only be repaired manually.
My expectation is that in case of such XML merger exception, we do not modify the workspace file at all.
So IMHO this is also a bug in the XML merger that needs to be fixed.

hohwille added a commit to devonfw/ide-settings that referenced this issue Jan 28, 2025
@hohwille
Copy link
Member Author

Since there is a workaround by configuring a full XPath expression, I applied that to our ide-settings.
Therefore this issue is not a blocker and I decided for medium priority.

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 settings ide-settings repo and replated processes and features
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant