Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 308125
Collapse All | Expand All

(-)plugin.properties (+1 lines)
Lines 6-8 Link Here
6
extPointPresets = Faceted Project Presets Extension Point
6
extPointPresets = Faceted Project Presets Extension Point
7
extPointDetectors = Project Facet Detectors Extension Point
7
extPointDetectors = Project Facet Detectors Extension Point
8
extPointAliases = Project Facet Aliases Extension Point
8
extPointAliases = Project Facet Aliases Extension Point
9
extPointAliases = Project Facet Groups Extension Point
(-)plugin.xml (+5 lines)
Lines 47-52 Link Here
47
    id="aliases" 
47
    id="aliases" 
48
    name="%extPointAliases" 
48
    name="%extPointAliases" 
49
    schema="schemas/aliases.exsd"/>
49
    schema="schemas/aliases.exsd"/>
50
51
  <extension-point 
52
    id="groups" 
53
    name="%extPointGroups" 
54
    schema="schemas/groups.exsd"/>
50
  
55
  
51
  <extension
56
  <extension
52
    id="nature"
57
    id="nature"
(-)schemas/facets.exsd (+5 lines)
Lines 652-659 Link Here
652
652
653
   <element name="group">
653
   <element name="group">
654
      <annotation>
654
      <annotation>
655
         <appInfo>
656
            <meta.element deprecated="true"/>
657
         </appInfo>
655
         <documentation>
658
         <documentation>
656
            Describes a project facet group. A group is a named collection of project facet versions. It is used primarily as a parameter to the &quot;requires&quot; and &quot;conflicts&quot; constraints and allows a level of indirection where a facet does not need to know about all the members of the group. A given project facet version can belong to several groups. Groups are created automatically when used in the &quot;group-member&quot; element, so an explicit group declaration is optional. However, it does allow a label and a description to be associated with the group.
659
            Describes a project facet group. A group is a named collection of project facet versions. It is used primarily as a parameter to the &quot;requires&quot; and &quot;conflicts&quot; constraints and allows a level of indirection where a facet does not need to know about all the members of the group. A given project facet version can belong to several groups. Groups are created automatically when used in the &quot;group-member&quot; element, so an explicit group declaration is optional. However, it does allow a label and a description to be associated with the group.
660
661
&lt;p&gt;&lt;b&gt;DEPRECATED:&lt;/b&gt; Use groups extension point instead.&lt;/p&gt;
657
         </documentation>
662
         </documentation>
658
      </annotation>
663
      </annotation>
659
      <complexType>
664
      <complexType>
(-)schemas/groups.exsd (+204 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.wst.common.project.facet.core" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.wst.common.project.facet.core" id="groups" name="Project Facet Groups Extension Point"/>
7
      </appInfo>
8
      <documentation>
9
         A group is a collection of project facets that&apos;s used to provide a level of indirection between facets. For instance, instead of specifying a dependency on a specific facet or a list of facets, a facet can specify a dependency on a group. Facets can join or leave the group as requirements change without directly impacting the facet that is specifying the dependency.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <choice minOccurs="0" maxOccurs="unbounded">
21
            <element ref="group"/>
22
            <element ref="members"/>
23
         </choice>
24
         <attribute name="point" type="string" use="required">
25
            <annotation>
26
               <documentation>
27
                  A fully qualified identifier of the target extension point.
28
               </documentation>
29
            </annotation>
30
         </attribute>
31
         <attribute name="id" type="string">
32
            <annotation>
33
               <documentation>
34
                  An optional identifier of the extension instance.
35
               </documentation>
36
            </annotation>
37
         </attribute>
38
         <attribute name="name" type="string">
39
            <annotation>
40
               <documentation>
41
                  An optional name of the extension instance.
42
               </documentation>
43
               <appInfo>
44
                  <meta.attribute translatable="true"/>
45
               </appInfo>
46
            </annotation>
47
         </attribute>
48
      </complexType>
49
   </element>
50
51
   <element name="group">
52
      <annotation>
53
         <documentation>
54
            Defines a project facet group.
55
         </documentation>
56
      </annotation>
57
      <complexType>
58
         <sequence>
59
            <element ref="label"/>
60
            <element ref="description" minOccurs="0" maxOccurs="1"/>
61
            <element ref="include" minOccurs="0" maxOccurs="unbounded"/>
62
         </sequence>
63
         <attribute name="id" type="string" use="required">
64
            <annotation>
65
               <documentation>
66
                  Group identifier.
67
               </documentation>
68
            </annotation>
69
         </attribute>
70
      </complexType>
71
   </element>
72
73
   <element name="label" type="string">
74
      <annotation>
75
         <documentation>
76
            The localizable name that is presented to the user. If not specified, the id will be used for a label.
77
         </documentation>
78
      </annotation>
79
   </element>
80
81
   <element name="description" type="string">
82
      <annotation>
83
         <documentation>
84
            The description text.
85
         </documentation>
86
      </annotation>
87
   </element>
88
89
   <element name="include">
90
      <annotation>
91
         <documentation>
92
            Specifies that one or more version of the facet should be included in the group.
93
         </documentation>
94
      </annotation>
95
      <complexType>
96
         <attribute name="facet" type="string" use="required">
97
            <annotation>
98
               <documentation>
99
                  The facet id.
100
               </documentation>
101
               <appInfo>
102
                  <meta.attribute kind="identifier" basedOn="org.eclipse.wst.common.project.facet.core.facets/project-facet/@id"/>
103
               </appInfo>
104
            </annotation>
105
         </attribute>
106
         <attribute name="versions" type="string">
107
            <annotation>
108
               <documentation>
109
                  Specifies the match expression for the facet version. The expression should be of the form &quot;2.2,2.5,[3.0-5.3],(7.3&quot;, where the comas function as an OR. Brackets and parenthesis are used as part of the range notation. A bracket means inclusive while a parenthesis means exclusive.
110
               </documentation>
111
            </annotation>
112
         </attribute>
113
      </complexType>
114
   </element>
115
116
   <element name="members">
117
      <annotation>
118
         <documentation>
119
            Used by third-partys to enlist facets into a group.
120
         </documentation>
121
      </annotation>
122
      <complexType>
123
         <sequence>
124
            <element ref="include" minOccurs="0" maxOccurs="unbounded"/>
125
         </sequence>
126
         <attribute name="group" type="string" use="required">
127
            <annotation>
128
               <documentation>
129
                  The group id.
130
               </documentation>
131
            </annotation>
132
         </attribute>
133
      </complexType>
134
   </element>
135
136
137
   <annotation>
138
      <appInfo>
139
         <meta.section type="examples"/>
140
      </appInfo>
141
      <documentation>
142
         &lt;p&gt;The following example illustrates creation of a group and various ways that facets can join the group.&lt;/p&gt;
143
144
&lt;pre&gt;&lt;extension point=&quot;org.eclipse.wst.common.project.facet.core.groups&quot;&gt;
145
146
  &lt;!-- 
147
    Groups do not have to be explicitly defined. They come into existence when the
148
    first member is added, however explicit definition is recommended as that&apos;s the
149
    only way to specify a label and a description for the group. You can also 
150
    enlist facets into the group as part of that group&apos;s definition.
151
  --&gt;
152
  
153
  &lt;group id=&quot;gr&quot;&gt;
154
    &lt;label&gt;Test Group&lt;/label&gt;
155
    &lt;description&gt;Test group of facets.&lt;/description&gt;
156
    &lt;include facet=&quot;a&quot;/&gt;
157
    &lt;include facet=&quot;b&quot; versions=&quot;1.2&quot;/&gt;
158
    &lt;include facet=&quot;c&quot; versions=&quot;[1.3-2.0)&quot;/&gt;
159
  &lt;/group&gt;
160
  
161
  &lt;!--
162
    This is the most flexible way of enlisting facets into the group. This
163
    declaration can be made by a third party that is neither the facet author
164
    nor the group creator.
165
  --&gt;
166
  
167
  &lt;members group=&quot;gr&quot;&gt;
168
    &lt;include facet=&quot;d&quot; versions=&quot;2.3,2.4,2.7&quot;/&gt;
169
    &lt;include facet=&quot;e&quot;/&gt;
170
  &lt;/members&gt;
171
  
172
&lt;/extension&gt;
173
174
&lt;!-- Facet can be enlisted into one or more group as part of facet definition. --&gt;
175
176
&lt;extension point=&quot;org.eclipse.wst.common.project.facet.core.facets&quot;&gt;
177
  &lt;project-facet id=&quot;f&quot;&gt;
178
    ...
179
  &lt;/project-facet&gt;
180
  &lt;project-facet-version facet=&quot;f&quot; version=&quot;1.0&quot;&gt;
181
    ...
182
    &lt;group-member id=&quot;gr&quot;/&gt;
183
    ...
184
  &lt;/project-facet-version&gt;
185
&lt;/extension&gt;&lt;/pre&gt;
186
      </documentation>
187
   </annotation>
188
189
190
191
   <annotation>
192
      <appInfo>
193
         <meta.section type="copyright"/>
194
      </appInfo>
195
      <documentation>
196
         Copyright (c) 2010 Oracle and others.&lt;br&gt;
197
All rights reserved. This program and the accompanying materials
198
are made available under the terms of the Eclipse Public License v1.0
199
which accompanies this distribution, and is available at
200
&lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;.
201
      </documentation>
202
   </annotation>
203
204
</schema>
(-)src/org/eclipse/wst/common/project/facet/core/internal/FacetedProjectFrameworkImpl.java (-62 / +9 lines)
Lines 59-64 Link Here
59
import org.eclipse.wst.common.project.facet.core.IConstraint;
59
import org.eclipse.wst.common.project.facet.core.IConstraint;
60
import org.eclipse.wst.common.project.facet.core.IDefaultVersionProvider;
60
import org.eclipse.wst.common.project.facet.core.IDefaultVersionProvider;
61
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
61
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
62
import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
62
import org.eclipse.wst.common.project.facet.core.IFacetedProjectTemplate;
63
import org.eclipse.wst.common.project.facet.core.IFacetedProjectTemplate;
63
import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
64
import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
64
import org.eclipse.wst.common.project.facet.core.IGroup;
65
import org.eclipse.wst.common.project.facet.core.IGroup;
Lines 67-73 Link Here
67
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
68
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
68
import org.eclipse.wst.common.project.facet.core.IVersionExpr;
69
import org.eclipse.wst.common.project.facet.core.IVersionExpr;
69
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
70
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
70
import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
71
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
71
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
72
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectFrameworkEvent;
72
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectFrameworkEvent;
73
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectFrameworkListener;
73
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectFrameworkListener;
Lines 78-85 Link Here
78
import org.eclipse.wst.common.project.facet.core.events.internal.LegacyEventHandlerAdapter;
78
import org.eclipse.wst.common.project.facet.core.events.internal.LegacyEventHandlerAdapter;
79
import org.eclipse.wst.common.project.facet.core.events.internal.ProjectListenerRegistry;
79
import org.eclipse.wst.common.project.facet.core.events.internal.ProjectListenerRegistry;
80
import org.eclipse.wst.common.project.facet.core.util.internal.IndexedSet;
80
import org.eclipse.wst.common.project.facet.core.util.internal.IndexedSet;
81
import org.eclipse.wst.common.project.facet.core.util.internal.VersionExpr;
82
import org.eclipse.wst.common.project.facet.core.util.internal.PluginUtil.InvalidExtensionException;
81
import org.eclipse.wst.common.project.facet.core.util.internal.PluginUtil.InvalidExtensionException;
82
import org.eclipse.wst.common.project.facet.core.util.internal.VersionExpr;
83
import org.osgi.service.prefs.BackingStoreException;
83
import org.osgi.service.prefs.BackingStoreException;
84
import org.osgi.service.prefs.Preferences;
84
import org.osgi.service.prefs.Preferences;
85
85
Lines 112-119 Link Here
112
    private static final String EL_DELEGATE = "delegate"; //$NON-NLS-1$
112
    private static final String EL_DELEGATE = "delegate"; //$NON-NLS-1$
113
    private static final String EL_DESCRIPTION = "description"; //$NON-NLS-1$
113
    private static final String EL_DESCRIPTION = "description"; //$NON-NLS-1$
114
    private static final String EL_EVENT_HANDLER = "event-handler"; //$NON-NLS-1$
114
    private static final String EL_EVENT_HANDLER = "event-handler"; //$NON-NLS-1$
115
    private static final String EL_GROUP = "group"; //$NON-NLS-1$
116
    private static final String EL_GROUP_MEMBER = "group-member"; //$NON-NLS-1$
117
    private static final String EL_LABEL = "label"; //$NON-NLS-1$
115
    private static final String EL_LABEL = "label"; //$NON-NLS-1$
118
    private static final String EL_MEMBER = "member"; //$NON-NLS-1$
116
    private static final String EL_MEMBER = "member"; //$NON-NLS-1$
119
    private static final String EL_PROJECT_FACET = "project-facet"; //$NON-NLS-1$
117
    private static final String EL_PROJECT_FACET = "project-facet"; //$NON-NLS-1$
Lines 597-602 Link Here
597
        return group;
595
        return group;
598
    }
596
    }
599
    
597
    
598
    void addGroup( final IGroup group )
599
    {
600
        this.groups.addItemWithKey( group.getId(), group );
601
    }
602
    
600
    public Set<IFacetedProject> getFacetedProjects()
603
    public Set<IFacetedProject> getFacetedProjects()
601
    
604
    
602
        throws CoreException
605
        throws CoreException
Lines 1382-1387 Link Here
1382
        
1385
        
1383
        calculateVersionComparisonTables( fvToConstraint, fvToActions );
1386
        calculateVersionComparisonTables( fvToConstraint, fvToActions );
1384
        
1387
        
1388
        ProjectFacetGroupsExtensionPoint.processExtensions( this );        
1389
        
1385
        for( Map.Entry<ProjectFacetVersion,IConfigurationElement> x : fvToConstraint.entrySet() )
1390
        for( Map.Entry<ProjectFacetVersion,IConfigurationElement> x : fvToConstraint.entrySet() )
1386
        {
1391
        {
1387
            readConstraint( x.getValue(), x.getKey() );
1392
            readConstraint( x.getValue(), x.getKey() );
Lines 1417-1437 Link Here
1417
                readDefaultVersionInfo( config );
1422
                readDefaultVersionInfo( config );
1418
            }
1423
            }
1419
        }
1424
        }
1420
        
1421
        for( IConfigurationElement config : cfgels )
1422
        {
1423
            if( config.getName().equals( EL_GROUP ) )
1424
            {
1425
                try
1426
                {
1427
                    readGroup( config );
1428
                }
1429
                catch( InvalidExtensionException e )
1430
                {
1431
                    // Continue. The problem has been reported in the log.
1432
                }
1433
            }
1434
        }
1435
    }
1425
    }
1436
    
1426
    
1437
    private void readCategory( final IConfigurationElement config )
1427
    private void readCategory( final IConfigurationElement config )
Lines 1607-1634 Link Here
1607
            {
1597
            {
1608
                fvToConstraint.put( fv, child );
1598
                fvToConstraint.put( fv, child );
1609
            }
1599
            }
1610
            else if( childName.equals( EL_GROUP_MEMBER ) )
1611
            {
1612
                final String id = child.getAttribute( ATTR_ID );
1613
                
1614
                if( id == null )
1615
                {
1616
                    reportMissingAttribute( child, ATTR_ID );
1617
                    return;
1618
                }
1619
                
1620
                Group group = (Group) this.groups.getItemByKey( id );
1621
                
1622
                if( group == null )
1623
                {
1624
                    group = new Group();
1625
                    group.setId( id );
1626
                    
1627
                    this.groups.addItemWithKey( id, group );
1628
                }
1629
                
1630
                group.addMember( fv );
1631
            }
1632
            else if( childName.equals( EL_ACTION ) )
1600
            else if( childName.equals( EL_ACTION ) )
1633
            {
1601
            {
1634
                actions.add( child );
1602
                actions.add( child );
Lines 2312-2338 Link Here
2312
        return new Constraint( fv, type, operands );
2280
        return new Constraint( fv, type, operands );
2313
    }
2281
    }
2314
    
2282
    
2315
    private void readGroup( final IConfigurationElement config )
2316
    
2317
        throws InvalidExtensionException
2318
        
2319
    {
2320
        final String id = findRequiredAttribute( config, ATTR_ID );
2321
        
2322
        if( ! isGroupDefined( id ) )
2323
        {
2324
            return;
2325
        }
2326
        
2327
        final Group group = (Group) getGroup( id );
2328
        
2329
        final IConfigurationElement elLabel = findOptionalElement( config, EL_LABEL );
2330
        group.setLabel( getElementValue( elLabel, group.getId() ) );
2331
        
2332
        final IConfigurationElement elDesc = findOptionalElement( config, EL_DESCRIPTION );
2333
        group.setDescription( getElementValue( elDesc, DEFAULT_DESCRIPTION ) );
2334
    }
2335
    
2336
    private static String toString( final Collection<? extends Object> collection )
2283
    private static String toString( final Collection<? extends Object> collection )
2337
    {
2284
    {
2338
        final StringBuffer buf = new StringBuffer();
2285
        final StringBuffer buf = new StringBuffer();
(-)src/org/eclipse/wst/common/project/facet/core/internal/Group.java (+6 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.wst.common.project.facet.core.internal;
12
package org.eclipse.wst.common.project.facet.core.internal;
13
13
14
import java.util.Collection;
14
import java.util.Collections;
15
import java.util.Collections;
15
import java.util.HashSet;
16
import java.util.HashSet;
16
import java.util.Set;
17
import java.util.Set;
Lines 87-92 Link Here
87
        this.members.add( fv );
88
        this.members.add( fv );
88
    }
89
    }
89
    
90
    
91
    void addMembers( final Collection<IProjectFacetVersion> facets )
92
    {
93
        this.members.addAll( facets );
94
    }
95
    
90
    public String toString()
96
    public String toString()
91
    {
97
    {
92
        return getLabel();
98
        return getLabel();
(-)src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetGroupsExtensionPoint.java (+226 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2010 Oracle
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
10
 ******************************************************************************/
11
12
package org.eclipse.wst.common.project.facet.core.internal;
13
14
import static org.eclipse.wst.common.project.facet.core.internal.FacetCorePlugin.PLUGIN_ID;
15
import static org.eclipse.wst.common.project.facet.core.util.internal.PluginUtil.findExtensions;
16
import static org.eclipse.wst.common.project.facet.core.util.internal.PluginUtil.findOptionalElement;
17
import static org.eclipse.wst.common.project.facet.core.util.internal.PluginUtil.findRequiredAttribute;
18
import static org.eclipse.wst.common.project.facet.core.util.internal.PluginUtil.findRequiredElement;
19
import static org.eclipse.wst.common.project.facet.core.util.internal.PluginUtil.getElementValue;
20
import static org.eclipse.wst.common.project.facet.core.util.internal.PluginUtil.getTopLevelElements;
21
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IConfigurationElement;
24
import org.eclipse.osgi.util.NLS;
25
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
26
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
27
import org.eclipse.wst.common.project.facet.core.util.internal.PluginUtil.InvalidExtensionException;
28
29
/**
30
 * Contains the logic for processing the <code>groups</code> extension point, along with the
31
 * <code>group</code> and <code>group-member</code> elements of the <code>facets</code> extension 
32
 * point. 
33
 * 
34
 * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
35
 */
36
37
public final class ProjectFacetGroupsExtensionPoint
38
{
39
    private static final String GROUPS_EXTENSION_POINT_ID = "groups"; //$NON-NLS-1$
40
    private static final String FACETS_EXTENSION_POINT_ID = "facets"; //$NON-NLS-1$
41
    
42
    private static final String EL_GROUP = "group"; //$NON-NLS-1$
43
    private static final String EL_LABEL = "label"; //$NON-NLS-1$
44
    private static final String EL_DESCRIPTION = "description"; //$NON-NLS-1$
45
    private static final String EL_INCLUDE = "include"; //$NON-NLS-1$
46
    private static final String EL_MEMBERS = "members"; //$NON-NLS-1$
47
    private static final String EL_PROJECT_FACET_VERSION = "project-facet-version"; //$NON-NLS-1$
48
    private static final String EL_GROUP_MEMBER = "group-member"; //$NON-NLS-1$
49
50
    private static final String ATTR_ID = "id"; //$NON-NLS-1$
51
    private static final String ATTR_GROUP = "group"; //$NON-NLS-1$
52
    private static final String ATTR_FACET = "facet"; //$NON-NLS-1$
53
    private static final String ATTR_VERSION = "version"; //$NON-NLS-1$
54
    private static final String ATTR_VERSIONS = "versions"; //$NON-NLS-1$
55
    
56
    public static void processExtensions( final FacetedProjectFrameworkImpl framework )
57
    {
58
        // Process group definitions and stand-alone group enlistments.
59
        
60
        for( IConfigurationElement element 
61
             : getTopLevelElements( findExtensions( PLUGIN_ID, GROUPS_EXTENSION_POINT_ID ) ) )
62
        {
63
            try
64
            {
65
                final String elname = element.getName();
66
                
67
                if( elname.equals( EL_GROUP ) )
68
                {
69
                    final String id = findRequiredAttribute( element, ATTR_ID );
70
                    final String label = getElementValue( findRequiredElement( element, EL_LABEL ), null );
71
                    final String description = getElementValue( findOptionalElement( element, EL_DESCRIPTION ), "" ); //$NON-NLS-1$
72
                    
73
                    final Group group = findOrCreateGroup( framework, id );
74
                    
75
                    group.setLabel( label );
76
                    group.setDescription( description );
77
                    
78
                    processIncludeDirectives( framework, group, element );
79
                }
80
                else if( elname.equals( EL_MEMBERS ) )
81
                {
82
                    final String gid = findRequiredAttribute( element, ATTR_GROUP );
83
                    final Group group = findOrCreateGroup( framework, gid );
84
                    
85
                    processIncludeDirectives( framework, group, element );
86
                }
87
            }
88
            catch( InvalidExtensionException e )
89
            {
90
                // Continue. The problem has been reported to the user via the log.
91
            }
92
        }
93
        
94
        // Process group enlistments as part of facet declaration.
95
        
96
        for( IConfigurationElement element 
97
             : getTopLevelElements( findExtensions( PLUGIN_ID, FACETS_EXTENSION_POINT_ID ) ) )
98
        {
99
            if( element.getName().equals( EL_PROJECT_FACET_VERSION ) )
100
            {
101
                final IConfigurationElement[] groupMemberElements = element.getChildren( EL_GROUP_MEMBER );
102
                
103
                if( groupMemberElements.length > 0 )
104
                {
105
                    final String fid = element.getAttribute( ATTR_FACET );
106
                    
107
                    if( fid != null && framework.isProjectFacetDefined( fid ) )
108
                    {
109
                        final IProjectFacet f = framework.getProjectFacet( fid );
110
                        final String version = element.getAttribute( ATTR_VERSION );
111
                        
112
                        if( version != null && f.hasVersion( version ) )
113
                        {
114
                            final IProjectFacetVersion fv = f.getVersion( version );
115
                            
116
                            for( IConfigurationElement groupMemberElement : groupMemberElements )
117
                            {
118
                                try
119
                                {
120
                                    final String gid = findRequiredAttribute( groupMemberElement, ATTR_ID );
121
                                    findOrCreateGroup( framework, gid ).addMember( fv );
122
                                }
123
                                catch( InvalidExtensionException e )
124
                                {
125
                                    // Continue. The problem has been reported to the user via the log.
126
                                }
127
                            }
128
                        }
129
                    }
130
                }
131
            }
132
        }
133
        
134
        // Process the deprecated declaration of groups within facets extension point.
135
136
        for( IConfigurationElement element 
137
             : getTopLevelElements( findExtensions( PLUGIN_ID, FACETS_EXTENSION_POINT_ID ) ) )
138
        {
139
            if( element.getName().equals( EL_GROUP ) )
140
            {
141
                try
142
                {
143
                    final String id = findRequiredAttribute( element, ATTR_ID );
144
                    final String label = getElementValue( findRequiredElement( element, EL_LABEL ), null );
145
                    final String description = getElementValue( findOptionalElement( element, EL_DESCRIPTION ), "" ); //$NON-NLS-1$
146
                    
147
                    final Group group = findOrCreateGroup( framework, id );
148
                    
149
                    group.setLabel( label );
150
                    group.setDescription( description );
151
                }
152
                catch( InvalidExtensionException e )
153
                {
154
                    // Continue. The problem has been reported to the user via the log.
155
                }
156
            }
157
        }
158
    }
159
    
160
    private static void processIncludeDirectives( final FacetedProjectFrameworkImpl framework,
161
                                                  final Group group,
162
                                                  final IConfigurationElement context )
163
    {
164
        final String bundleId = context.getContributor().getName();
165
        
166
        for( IConfigurationElement element : context.getChildren( EL_INCLUDE ) )
167
        {
168
            try
169
            {
170
                final String fid = findRequiredAttribute( element, ATTR_FACET );
171
                final String versions = element.getAttribute( ATTR_VERSIONS );
172
                
173
                if( framework.isProjectFacetDefined( fid ) )
174
                {
175
                    final IProjectFacet f = framework.getProjectFacet( fid );
176
                    group.addMembers( versions == null ? f.getVersions() : f.getVersions( versions ) );
177
                }
178
                else
179
                {
180
                    ProblemLog.reportMissingFacet( fid, bundleId );
181
                }
182
            }
183
            catch( InvalidExtensionException e )
184
            {
185
                // Continue. The problem has been reported to the user via the log.
186
            }
187
            catch( CoreException e )
188
            {
189
                FacetCorePlugin.log( e );
190
            }
191
        }
192
    }
193
    
194
    private static Group findOrCreateGroup( final FacetedProjectFrameworkImpl framework,
195
                                            final String id )
196
    {
197
        final Group group;
198
        
199
        if( framework.isGroupDefined( id ) )
200
        {
201
            group = (Group) framework.getGroup( id );
202
        }
203
        else
204
        {
205
            group = new Group();
206
            group.setId( id );
207
            framework.addGroup( group );
208
        }
209
        
210
        return group;
211
    }
212
213
    public static final class Resources
214
    
215
        extends NLS
216
        
217
    {
218
        public static String invalidEventType;
219
        
220
        static
221
        {
222
            initializeMessages( ProjectFacetGroupsExtensionPoint.class.getName(), Resources.class );
223
        }
224
    }
225
    
226
}
(-)plugin.xml (+125 lines)
Lines 592-595 Link Here
592
    
592
    
593
  </extension>
593
  </extension>
594
  
594
  
595
  <!-- ProjectFacetGroupsTests -->
596
  
597
  <extension point="org.eclipse.wst.common.project.facet.core.facets">
598
  
599
    <project-facet id="grp-f1"/>
600
    <project-facet-version facet="grp-f1" version="1.0">
601
      <group-member id="grp-g3"/>
602
    </project-facet-version>
603
    <project-facet-version facet="grp-f1" version="1.2">
604
      <group-member id="grp-g3"/>
605
    </project-facet-version>
606
    <project-facet-version facet="grp-f1" version="2.0">
607
      <group-member id="grp-g3"/>
608
    </project-facet-version>
609
    <action facet="grp-f1" type="INSTALL">
610
      <delegate class="org.eclipse.wst.common.project.facet.core.tests.support.NoOpDelegate"/>
611
    </action>
612
613
    <project-facet id="grp-f2"/>
614
    <project-facet-version facet="grp-f2" version="1.0"/>
615
    <project-facet-version facet="grp-f2" version="1.2">
616
      <group-member id="grp-g3"/>
617
    </project-facet-version>
618
    <project-facet-version facet="grp-f2" version="2.0"/>
619
    <action facet="grp-f2" type="INSTALL">
620
      <delegate class="org.eclipse.wst.common.project.facet.core.tests.support.NoOpDelegate"/>
621
    </action>
622
623
    <project-facet id="grp-f3"/>
624
    <project-facet-version facet="grp-f3" version="1.0"/>
625
    <project-facet-version facet="grp-f3" version="1.2">
626
      <group-member id="grp-g3"/>
627
    </project-facet-version>
628
    <project-facet-version facet="grp-f3" version="2.0">
629
      <group-member id="grp-g3"/>
630
    </project-facet-version>
631
    <action facet="grp-f3" type="INSTALL">
632
      <delegate class="org.eclipse.wst.common.project.facet.core.tests.support.NoOpDelegate"/>
633
    </action>
634
635
    <project-facet id="grp-f4"/>
636
    <project-facet-version facet="grp-f4" version="1.0">
637
      <group-member id="grp-g3"/>
638
    </project-facet-version>
639
    <project-facet-version facet="grp-f4" version="1.2">
640
      <group-member id="grp-g3"/>
641
    </project-facet-version>
642
    <project-facet-version facet="grp-f4" version="2.0">
643
      <group-member id="grp-g3"/>
644
    </project-facet-version>
645
    <action facet="grp-f4" type="INSTALL">
646
      <delegate class="org.eclipse.wst.common.project.facet.core.tests.support.NoOpDelegate"/>
647
    </action>
648
    
649
    <project-facet id="grp-f5"/>
650
    <project-facet-version facet="grp-f5" version="1.0">
651
      <group-member id="grp-g3"/>
652
    </project-facet-version>
653
    <project-facet-version facet="grp-f5" version="1.2">
654
      <group-member id="grp-g3"/>
655
    </project-facet-version>
656
    <project-facet-version facet="grp-f5" version="2.0"/>
657
    <action facet="grp-f5" type="INSTALL">
658
      <delegate class="org.eclipse.wst.common.project.facet.core.tests.support.NoOpDelegate"/>
659
    </action>
660
    
661
    <project-facet id="grp-f6"/>
662
    <project-facet-version facet="grp-f6" version="1.0"/>
663
    <project-facet-version facet="grp-f6" version="1.2">
664
      <group-member id="grp-g1"/>
665
      <group-member id="grp-g2"/>
666
      <group-member id="grp-g3"/>
667
    </project-facet-version>
668
    <project-facet-version facet="grp-f6" version="2.0">
669
      <group-member id="grp-g1"/>
670
      <group-member id="grp-g2"/>
671
      <group-member id="grp-g3"/>
672
    </project-facet-version>
673
    <action facet="grp-f6" type="INSTALL">
674
      <delegate class="org.eclipse.wst.common.project.facet.core.tests.support.NoOpDelegate"/>
675
    </action>
676
    
677
  </extension>
678
  
679
  <extension point="org.eclipse.wst.common.project.facet.core.groups">
680
  
681
    <group id="grp-g1">
682
      <label>Group 1</label>
683
      <description>Description for Group 1.</description>
684
      <include facet="grp-f1"/>
685
      <include facet="grp-f2" versions="1.2"/>
686
      <include facet="grp-f3" versions="[1.2-3.0)"/>
687
    </group>
688
    
689
    <members group="grp-g1">
690
      <include facet="grp-f4"/>
691
      <include facet="grp-f5" versions="1.0,1.2"/>
692
    </members>
693
  
694
  </extension>
695
  
696
  <extension point="org.eclipse.wst.common.project.facet.core.facets">
697
  
698
    <group id="grp-g2">
699
      <label>Group 2</label>
700
      <description>Description for Group 2.</description>
701
    </group>
702
    
703
  </extension>
704
  
705
  <extension point="org.eclipse.wst.common.project.facet.core.groups">
706
  
707
    <members group="grp-g2">
708
      <include facet="grp-f1"/>
709
      <include facet="grp-f2" versions="1.2"/>
710
      <include facet="grp-f3" versions="[1.2-3.0)"/>
711
    </members>
712
    
713
    <members group="grp-g2">
714
      <include facet="grp-f4"/>
715
      <include facet="grp-f5" versions="1.0,1.2"/>
716
    </members>
717
  
718
  </extension>
719
  
595
</plugin>
720
</plugin>
(-)src/org/eclipse/wst/common/project/facet/core/tests/AllTests.java (+1 lines)
Lines 41-46 Link Here
41
        suite.addTest( DefaultVersionTests.suite() );
41
        suite.addTest( DefaultVersionTests.suite() );
42
        suite.addTest( EventDeliveryTests.suite() );
42
        suite.addTest( EventDeliveryTests.suite() );
43
        suite.addTest( AliasingSystemTests.suite() );
43
        suite.addTest( AliasingSystemTests.suite() );
44
        suite.addTest( ProjectFacetGroupsTests.suite() );
44
        
45
        
45
        return suite;
46
        return suite;
46
    }
47
    }
(-)src/org/eclipse/wst/common/project/facet/core/tests/ProjectFacetGroupsTests.java (+164 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2010 Oracle
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
10
 ******************************************************************************/
11
12
package org.eclipse.wst.common.project.facet.core.tests;
13
14
import java.io.IOException;
15
import java.util.HashSet;
16
import java.util.Set;
17
18
import junit.framework.Test;
19
import junit.framework.TestSuite;
20
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.wst.common.project.facet.core.IGroup;
23
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
24
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
25
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
26
27
/**
28
 * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
29
 */
30
31
@SuppressWarnings( "unused" )
32
33
public final class ProjectFacetGroupsTests
34
35
    extends AbstractTests
36
    
37
{
38
    private static IProjectFacet f1;
39
    private static IProjectFacetVersion f1v10;
40
    private static IProjectFacetVersion f1v12;
41
    private static IProjectFacetVersion f1v20;
42
    
43
    private static IProjectFacet f2;
44
    private static IProjectFacetVersion f2v10;
45
    private static IProjectFacetVersion f2v12;
46
    private static IProjectFacetVersion f2v20;
47
    
48
    private static IProjectFacet f3;
49
    private static IProjectFacetVersion f3v10;
50
    private static IProjectFacetVersion f3v12;
51
    private static IProjectFacetVersion f3v20;
52
    
53
    private static IProjectFacet f4;
54
    private static IProjectFacetVersion f4v10;
55
    private static IProjectFacetVersion f4v12;
56
    private static IProjectFacetVersion f4v20;
57
    
58
    private static IProjectFacet f5;
59
    private static IProjectFacetVersion f5v10;
60
    private static IProjectFacetVersion f5v12;
61
    private static IProjectFacetVersion f5v20;
62
    
63
    private static IProjectFacet f6;
64
    private static IProjectFacetVersion f6v10;
65
    private static IProjectFacetVersion f6v12;
66
    private static IProjectFacetVersion f6v20;
67
    
68
    static
69
    {
70
        f1 = ProjectFacetsManager.getProjectFacet( "grp-f1" );
71
        f1v10 = f1.getVersion( "1.0" );
72
        f1v12 = f1.getVersion( "1.2" );
73
        f1v20 = f1.getVersion( "2.0" );
74
75
        f2 = ProjectFacetsManager.getProjectFacet( "grp-f2" );
76
        f2v10 = f2.getVersion( "1.0" );
77
        f2v12 = f2.getVersion( "1.2" );
78
        f2v20 = f2.getVersion( "2.0" );
79
        
80
        f3 = ProjectFacetsManager.getProjectFacet( "grp-f3" );
81
        f3v10 = f3.getVersion( "1.0" );
82
        f3v12 = f3.getVersion( "1.2" );
83
        f3v20 = f3.getVersion( "2.0" );
84
        
85
        f4 = ProjectFacetsManager.getProjectFacet( "grp-f4" );
86
        f4v10 = f4.getVersion( "1.0" );
87
        f4v12 = f4.getVersion( "1.2" );
88
        f4v20 = f4.getVersion( "2.0" );
89
        
90
        f5 = ProjectFacetsManager.getProjectFacet( "grp-f5" );
91
        f5v10 = f5.getVersion( "1.0" );
92
        f5v12 = f5.getVersion( "1.2" );
93
        f5v20 = f5.getVersion( "2.0" );
94
        
95
        f6 = ProjectFacetsManager.getProjectFacet( "grp-f6" );
96
        f6v10 = f6.getVersion( "1.0" );
97
        f6v12 = f6.getVersion( "1.2" );
98
        f6v20 = f6.getVersion( "2.0" );
99
    }
100
101
    private ProjectFacetGroupsTests( final String name )
102
    {
103
        super( name );
104
    }
105
    
106
    public static Test suite()
107
    {
108
        final TestSuite suite = new TestSuite();
109
        
110
        suite.setName( "Project Facet Groups Tests" );
111
112
        suite.addTest( new ProjectFacetGroupsTests( "testCreationAndEnlistment" ) );
113
        
114
        return suite;
115
    }
116
117
    /**
118
     * Tests creation of groups and enlistment of facets.
119
     * 
120
     * @throws CoreException
121
     * @throws IOException
122
     */
123
    
124
    public void testCreationAndEnlistment()
125
    
126
        throws CoreException, IOException
127
    
128
    {
129
        final Set<IProjectFacetVersion> expected = new HashSet<IProjectFacetVersion>();
130
        
131
        expected.add( f1v10 );
132
        expected.add( f1v12 );
133
        expected.add( f1v20 );
134
        expected.add( f2v12 );
135
        expected.add( f3v12 );
136
        expected.add( f3v20 );
137
        expected.add( f4v10 );
138
        expected.add( f4v12 );
139
        expected.add( f4v20 );
140
        expected.add( f5v10 );
141
        expected.add( f5v12 );
142
        expected.add( f6v12 );
143
        expected.add( f6v20 );
144
        
145
        assertTrue( ProjectFacetsManager.isGroupDefined( "grp-g1" ) );
146
        final IGroup g1 = ProjectFacetsManager.getGroup( "grp-g1" );
147
        assertEquals( expected, g1.getMembers() );
148
        assertEquals( "Group 1", g1.getLabel() );
149
        assertEquals( "Description for Group 1.", g1.getDescription() );
150
        
151
        assertTrue( ProjectFacetsManager.isGroupDefined( "grp-g2" ) );
152
        final IGroup g2 = ProjectFacetsManager.getGroup( "grp-g2" );
153
        assertEquals( expected, g2.getMembers() );
154
        assertEquals( "Group 2", g2.getLabel() );
155
        assertEquals( "Description for Group 2.", g2.getDescription() );
156
        
157
        assertTrue( ProjectFacetsManager.isGroupDefined( "grp-g3" ) );
158
        final IGroup g3 = ProjectFacetsManager.getGroup( "grp-g3" );
159
        assertEquals( expected, g3.getMembers() );
160
        assertEquals( "grp-g3", g3.getLabel() );
161
        assertEquals( "", g3.getDescription() );
162
    }
163
    
164
}

Return to bug 308125