|
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 |
} |