Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Oomph » Can Oomph import code templates?
Can Oomph import code templates? [message #1843264] Wed, 21 July 2021 19:08 Go to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Hi

Can I import code templates with an Oomph SetupTask?

As those code templates are all stored into a single preference, i want to avoid to overwrite existing templates.
Hence I ask for import.
More precisely I mean those in the Preferences > Java > Editor > Templates

Frank
Re: Can Oomph import code templates? [message #1843266 is a reply to message #1843264] Thu, 22 July 2021 06:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33258
Registered: July 2009
Senior Member
There is specialized merging support for this:

https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/impl/PreferenceTaskImpl.java#n973

So it should merge /add each <template> based on its id="..." value.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Can Oomph import code templates? [message #1843274 is a reply to message #1843266] Thu, 22 July 2021 11:05 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
I tried it.
The templates that come with Eclipse were still available. But another template that i created before, did get removed.
Is there a bug, or do I need to do something differnet?

  <setupTask
      xsi:type="setup:CompoundTask"
      name="Preferences">
    <annotation
        source="http://www.eclipse.org/oomph/setup/UserPreferences"/>
    <setupTask
        xsi:type="setup:PreferenceTask"
        key="/instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.custom_templates"
        value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?>&lt;templates>&lt;...;/template>&lt;/templates>">
      <description>Some description</description>
    </setupTask>
  </setupTask>
Re: Can Oomph import code templates? [message #1843279 is a reply to message #1843274] Thu, 22 July 2021 13:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33258
Registered: July 2009
Senior Member
It's very easy to create a development environment.

https://www.eclipse.org/setups/installer/?url=http://git.eclipse.org/c/oomph/org.eclipse.oomph.git/plain/setups/configurations/OomphConfiguration.setup&show=true

There will be a launcher to launch an IDE and you can set a breakpoint in org.eclipse.oomph.setup.impl.PreferenceTaskImpl.XMLPreferenceHandler.XMLPreferenceHandler(URI, String, String[], String[]) and in org.eclipse.oomph.setup.impl.PreferenceTaskImpl.ListPreferenceHandler.merge() to see if something is going wrong. In the debug launched IDE, use Navigate -> Open Setup -> Workspace and copy your task to the workspace setup. When you Perform Setup Tasks... in this IDE, you will be able to debug. If there is a bug, you can help fix it.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Can Oomph import code templates? [message #1843280 is a reply to message #1843274] Thu, 22 July 2021 13:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33258
Registered: July 2009
Senior Member
It's very easy to create a development environment.

https://www.eclipse.org/setups/installer/?url=http://git.eclipse.org/c/oomph/org.eclipse.oomph.git/plain/setups/configurations/OomphConfiguration.setup&show=true

There will be a launcher to launch an IDE and you can set a breakpoint in org.eclipse.oomph.setup.impl.PreferenceTaskImpl.XMLPreferenceHandler.XMLPreferenceHandler(URI, String, String[], String[]) and in org.eclipse.oomph.setup.impl.PreferenceTaskImpl.ListPreferenceHandler.merge() to see if something is going wrong. In the debug launched IDE, use Navigate -> Open Setup -> Workspace and copy your task to the workspace setup. When you Perform Setup Tasks... in this IDE, you will be able to debug. If there is a bug, you can help fix it.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Can Oomph import code templates? [message #1843339 is a reply to message #1843280] Sat, 24 July 2021 05:02 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/impl/PreferenceTaskImpl.java#n977
Line 977

I think the problem is the configured attribute name, is should not be "id", but instead "name".
     registry.put(URI.createURI("//instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.custom_templates"), new Factory() //$NON-NLS-1$
      {
        public PreferenceHandler create(URI key)
        {
          //return new XMLPreferenceHandler(key, "template", new String[] { "id" }, null); //$NON-NLS-1$ //$NON-NLS-2$
          return new XMLPreferenceHandler(key, "template", new String[] { "name" }, null); //$NON-NLS-1$ //$NON-NLS-2$
        }
      });


An entry looks like this:
<template autoinsert="true" context="java" deleted="false" description="D..." enabled="true" name="doc">...</template>
Re: Can Oomph import code templates? [message #1843340 is a reply to message #1843280] Sat, 24 July 2021 05:02 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.setup/src/org/eclipse/oomph/setup/impl/PreferenceTaskImpl.java#n977
Line 977

I think the problem is the configured attribute name, is should not be "id", but instead "name".
     registry.put(URI.createURI("//instance/org.eclipse.jdt.ui/org.eclipse.jdt.ui.text.custom_templates"), new Factory() //$NON-NLS-1$
      {
        public PreferenceHandler create(URI key)
        {
          //return new XMLPreferenceHandler(key, "template", new String[] { "id" }, null); //$NON-NLS-1$ //$NON-NLS-2$
          return new XMLPreferenceHandler(key, "template", new String[] { "name" }, null); //$NON-NLS-1$ //$NON-NLS-2$
        }
      });


An entry looks like this:
<template autoinsert="true" context="java" deleted="false" description="D..." enabled="true" name="doc">...</template>
Re: Can Oomph import code templates? [message #1843342 is a reply to message #1843340] Sat, 24 July 2021 06:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33258
Registered: July 2009
Senior Member
Hmm. The existing templates use a style like this:
<template autoinsert="true" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment">/**
 * @return the ${bare_field_name}
 */</template>
And the name is something you can edit but the ID is not something you can edit. But you're right of course that if you add your own template, it doesn't have an ID. E.g., here's where I add one and edit an existing one:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates>
<template autoinsert="true" context="javadoc" deleted="false" description="author name" enabled="true" id="org.eclipse.jdt.ui.templates.author" name="@author">@author - ${user}</template>
<template autoinsert="true" context="java" deleted="false" description="foo" enabled="true" name="bar">foo bar</template>
</templates>
So it would seem better to use the name given there isn't necessarily an id=...

Please open a Bugzilla.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Can Oomph import code templates? [message #1843343 is a reply to message #1843342] Sat, 24 July 2021 06:29 Go to previous message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
done:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=575012
Previous Topic:Eclipse Installation Error
Next Topic:P2 error using archived Babel - handshake_failure
Goto Forum:
  


Current Time: Fri Dec 06 11:18:07 GMT 2024

Powered by FUDForum. Page generated in 0.04750 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top