Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Custom Facet Installation fails when no InstallDelegate class is created
Custom Facet Installation fails when no InstallDelegate class is created [message #232243] Mon, 08 June 2009 12:49 Go to next message
Tilak Sharma is currently offline Tilak SharmaFriend
Messages: 48
Registered: July 2009
Member
Hi,

I created one custom facet using the extension point:
"org.eclipse.wst.common.project.facet.core.facets" like:

<extension
point="org.eclipse.wst.common.project.facet.core.facets">
<project-facet
id="sample.facet1">
<label>
Sample Facet
</label>
<description>
Facet used for Sample Project
</description>
</project-facet>
<project-facet-version
facet="sample.facet1"
version="1.0">
<constraint>
<requires
facet="jst.java"
version="5.0">
</requires>
</constraint>
</project-facet-version>
</extension>

Now from my code, when I tried to install this facet (I got this code from
this webtools Newsportal itself! Thanks a Ton! :-) ):

IFacetedProject fp = ProjectFacetsManager.create(iProject, true, monitor);


fp.installProjectFacet(ProjectFacetsManager.getProjectFacet( "jst.java")
.getDefaultVersion(), null, monitor);


fp.installProjectFacet(ProjectFacetsManager.getProjectFacet( "sample.facet1")
.getDefaultVersion(), null, monitor);

The installation of sample.facet1 fails and the below exception is thrown:


java.lang.reflect.InvocationTargetException
at
org.eclipse.ui.actions.WorkspaceModifyOperation.run(Workspac eModifyOperation.java:119)
at
org.eclipse.jface.operation.ModalContext.runInCurrentThread( ModalContext.java:458)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.ja va:366)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java: 934)
at
com.sonicsw.tools.core.project.SonicProjectWizard.createNewP roject(SonicProjectWizard.java:259)
at
com.sonicsw.tools.core.project.SonicProjectWizard.performFin ish(SonicProjectWizard.java:83)
at
org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDi alog.java:742)
at
org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDi alog.java:373)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.jav a:624)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3422)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825 )
at org.eclipse.jface.window.Window.open(Window.java:801)
at
org.eclipse.ui.internal.actions.NewWizardShortcutAction.run( NewWizardShortcutAction.java:135)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498 )
at
org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:583)
at
org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:500)
at
org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3422)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:21 98)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:288)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:113)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:193)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:386)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Caused by: org.eclipse.core.runtime.CoreException: One or more constraints
have not been satisfied.
at
org.eclipse.wst.common.project.facet.core.internal.FacetedPr oject.modifyInternal(FacetedProject.java:343)
at
org.eclipse.wst.common.project.facet.core.internal.FacetedPr oject.mergeChangesInternal(FacetedProject.java:1134)
at
org.eclipse.wst.common.project.facet.core.internal.FacetedPr oject.access$2(FacetedProject.java:1070)
at
org.eclipse.wst.common.project.facet.core.internal.FacetedPr oject$1.run(FacetedProject.java:309)
at org.eclipse.core.internal.resources.Workspace.run(Workspace. java:1800)
at
org.eclipse.wst.common.project.facet.core.internal.FacetedPr oject.modify(FacetedProject.java:319)
at
org.eclipse.wst.common.project.facet.core.internal.FacetedPr oject.installProjectFacet(FacetedProject.java:242)
at
com.sonicsw.tools.core.project.SonicProjectWizard$1.execute( SonicProjectWizard.java:241)
at
org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(Worksp aceModifyOperation.java:104)
at org.eclipse.core.internal.resources.Workspace.run(Workspace. java:1800)
at
org.eclipse.ui.actions.WorkspaceModifyOperation.run(Workspac eModifyOperation.java:116)
... 45 more


I could overcome this problem only after I added the install and uninstall
actions in the project-facet-version in the extension point like:

<action id="com.sample.project.install" type="install">
<delegate
class="com.sample.project.SampleFacetInstallDelegate">
</delegate>
</action>
<action id="com.sample.project.uninstall" type="uninstall">
<delegate
class="com.sample.project.SampleFacetUninstallDelegate">
</delegate>
</action>

The exception message is not at all indicating that I should provide
implementation for the install and uninstall delegates.

Is this really a problem with the exception message (should framework
handle if no install and uninstall delegates are provided?) or Am I
missing something obvious?

Thanks in advance,
Tilak
Re: Custom Facet Installation fails when no InstallDelegate class is created [message #232264 is a reply to message #232243] Tue, 09 June 2009 21:27 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
> The exception message is not at all indicating that I should provide
> implementation for the install and uninstall delegates.

The exception message is indeed not particularly accurate. A generic
message (which also happens to not be generic enough) is hiding the
specific problem. Could you open a bug for this?

> Is this really a problem with the exception message (should framework
> handle if no install and uninstall delegates are provided?) or Am I
> missing something obvious?

Yes, this is an error message problem. A facet action is treated as
unsupported if not provided by facet author. Note that you didn't need to
provide both install and uninstall actions to get past this problem. For
this part, you just needed the install action implementation.

It is fairly common (also not recommended) for people to not provide
uninstall action at all. The reason that it is not recommended is that it
tends to tick off the users if they install your facet and then later
cannot remove it. On the other hand, providing uninstall cleanup is
frequently a non-trivial exercise, so developers like the flexibility to
defer that feature for a later date.

Not providing the install action is fairly rare, but can also be useful
for migration purposes. Say you want to continue supporting users with
projects that have the facet installed, but you want to prevent users from
adding this facet to new projects.

I hope that answered your questions.

- Konstantin
Re: Custom Facet Installation fails when no InstallDelegate class is created [message #232290 is a reply to message #232264] Wed, 10 June 2009 13:51 Go to previous messageGo to next message
Tilak Sharma is currently offline Tilak SharmaFriend
Messages: 48
Registered: July 2009
Member
Thanks a lot for your reply with such a clear explanation !

I have created a bug
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=279795) for the change in
the exception message when no install delegate is provided.

I am providing only an install delegate now and inside that I am adding
few natures to my project. Its working!

I have one more small problem: How to install a facet and set it as fixed
facet at the same time?

Currently, I am using this code:
IFacetedProject fp = ProjectFacetsManager.create(project, true, monitor);
IProjectFacet javaFacet = ProjectFacetsManager.getProjectFacet("jst.java");
IProjectFacet sampleFacet =
ProjectFacetsManager.getProjectFacet("sample.facet");

fp.installProjectFacet(javaFacet.getDefaultVersion(), null, monitor);
fp.installProjectFacet(sampleFacet.getDefaultVersion(), null, monitor);

Set<IProjectFacet> fixedFacets = new HashSet<IProjectFacet>();
fixedFacets.add(javaFacet);
fixedFacets.add(sampleFacet);
fp.setFixedProjectFacets(fixedFacets);

By this, I have both java and sample facets installed and fixed (they
cannot be unchecked) in the 'Project Facets' Preference page in the
project properties.

I tried using IFacetedProjectWorkingCopy, but in vain:

IFacetedProjectWorkingCopy facetedWorkingCopy = fp.createWorkingCopy();
facetedWorkingCopy.setFixedProjectFacets(fixedFacets);

Is there any option to install a facet and also set it to be a fixed
facet, programatically?

Thanks a lot!
Tilak
Re: Custom Facet Installation fails when no InstallDelegate class is created [message #232520 is a reply to message #232290] Mon, 15 June 2009 16:40 Go to previous message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
> I have one more small problem: How to install a facet and set it as fixed
> facet at the same time?

> Currently, I am using this code:
> IFacetedProject fp = ProjectFacetsManager.create(project, true, monitor);
> IProjectFacet javaFacet = ProjectFacetsManager.getProjectFacet("jst.java");
> IProjectFacet sampleFacet =
> ProjectFacetsManager.getProjectFacet("sample.facet");

> fp.installProjectFacet(javaFacet.getDefaultVersion(), null, monitor);
> fp.installProjectFacet(sampleFacet.getDefaultVersion(), null, monitor);

> Set<IProjectFacet> fixedFacets = new HashSet<IProjectFacet>();
> fixedFacets.add(javaFacet);
> fixedFacets.add(sampleFacet);
> fp.setFixedProjectFacets(fixedFacets);

> By this, I have both java and sample facets installed and fixed (they
> cannot be unchecked) in the 'Project Facets' Preference page in the
> project properties.

> I tried using IFacetedProjectWorkingCopy, but in vain:

> IFacetedProjectWorkingCopy facetedWorkingCopy = fp.createWorkingCopy();
> facetedWorkingCopy.setFixedProjectFacets(fixedFacets);

> Is there any option to install a facet and also set it to be a fixed
> facet, programatically?

I am not understanding what exactly you are having a problem with. Either
of the approaches that you've described will work, although the working
copy technique is the recommended pattern, especially when you need to
make several changes to the project. Just make sure you didn't forget to
call IFacetedPrjectWorkingCopy.commitChanges() when you are done.

- Konstantin
Previous Topic:Faceted Project framework question
Next Topic:Validate a project facet
Goto Forum:
  


Current Time: Sat Apr 20 00:53:30 GMT 2024

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

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

Back to the top