0

i writing an Eclipse Plugin that creates a new "EAR Application Project", using APIs from Eclipse WTP. I m issuing some difficulties to set the "runtime" value for this new project.

That's the content of "org.eclipse.wst.common.project.facet.core.xml" when I create the same project using Eclipse GUI (as an 'normal' user):

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <runtime name="GlassFish 3.1.2"/>
  <fixed facet="jst.ear"/>
  <installed facet="jst.ear" version="6.0"/>
  <installed facet="sun.facet" version="9"/>
</faceted-project>

But when creating a Faceted Project (using provided APIs from WTP plugins) I cannot find a way to set the following values to my EAP project:

  <runtime name="GlassFish 3.1.2"/>
  <fixed facet="jst.ear"/>

following is the same XML that is written when i create this project programmatically:

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <installed facet="jst.ear" version="6.0"/>
  <installed facet="sun.facet" version="9"/>
</faceted-project>

Here's how im creating this project:

        IFacetedProject facetedProject = ProjectFacetsManager.create("prj1", new Path(prj), null);
        IFacetedProjectWorkingCopy workingCopy = facetedProject.createWorkingCopy();

        IProjectFacet jstFacet = ProjectFacetsManager.getProjectFacet("jst.ear");
        IProjectFacet sunFacet = ProjectFacetsManager.getProjectFacet("sun.facet");

        IProjectFacetVersion defaultJstFacet = jstFacet.getDefaultVersion();
        IProjectFacetVersion defaultSunFacet = sunFacet.getDefaultVersion();
        workingCopy.addProjectFacet(defaultJstFacet);
        workingCopy.addProjectFacet(defaultSunFacet);
        workingCopy.commitChanges(null);

Am i doing something wrong?

1 Answers1

0

To set the fixed facets, you are need to use IFacetedProjectWorkingCopy.setFixedProjectFacets() method.

To set the runtime, you need to use IFacetedProjectWorkingCopy.setTargetedRuntimes() method. You can locate IRuntime instances via RuntimeManager API such as getRuntimes() or getRuntimes( name ).

Konstantin Komissarchik
  • 28,879
  • 6
  • 61
  • 61
  • Great! It works. But when I run it as a Junit Plugin Test the same runtime is not loaded. I think that JUnit do not load the required bundles. Do you have any idea what is required to recognize that Runtime (in my case, Glassfish 3.1.2) when running with JUnit Plugin Test? Thank you Mr. Komissarchik. – Vitor Enio Jun 13 '12 at 18:59