This commit was manufactured by cvs2svn to create tag 'v20051108'.
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/build.properties b/plugins/org.eclipse.jst.common.project.facet.core/build.properties
index 34d2e4d..ffc172d 100644
--- a/plugins/org.eclipse.jst.common.project.facet.core/build.properties
+++ b/plugins/org.eclipse.jst.common.project.facet.core/build.properties
@@ -1,4 +1,5 @@
source.. = src/
output.. = bin/
-bin.includes = META-INF/,\
- .
+bin.includes = .,\
+ plugin.xml,\
+ META-INF/
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/plugin.xml b/plugins/org.eclipse.jst.common.project.facet.core/plugin.xml
index 590bbd1..16ef38b 100644
--- a/plugins/org.eclipse.jst.common.project.facet.core/plugin.xml
+++ b/plugins/org.eclipse.jst.common.project.facet.core/plugin.xml
@@ -7,7 +7,7 @@
<factory
class="org.eclipse.jst.common.project.facet.core.internal.RuntimeClasspathProvider$Factory"
adaptableType="org.eclipse.wst.common.project.facet.core.runtime.IRuntime">
- <adapter type="org.eclipse.jst.common.project.facet.core.ClasspathProvider"/>
+ <adapter type="org.eclipse.jst.common.project.facet.core.IClasspathProvider"/>
</factory>
</extension>
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/ClasspathHelper.java b/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/ClasspathHelper.java
index 20dbde1..e5173b5 100644
--- a/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/ClasspathHelper.java
+++ b/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/ClasspathHelper.java
@@ -23,11 +23,14 @@
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
@@ -105,6 +108,9 @@
public final class ClasspathHelper
{
+ private static final String PLUGIN_ID
+ = "org.eclipse.jst.common.project.facet.core";
+
private static final Object SYSTEM_OWNER = new Object();
private ClasspathHelper() {}
@@ -216,8 +222,11 @@
}
catch( BackingStoreException e )
{
- // TODO: throw CoreException here
- throw new RuntimeException( e );
+ final IStatus st
+ = new Status( IStatus.ERROR, PLUGIN_ID, 0,
+ Resources.failedWritingPreferences, e );
+
+ throw new CoreException( st );
}
}
@@ -283,8 +292,11 @@
}
catch( BackingStoreException e )
{
- // TODO: throw CoreException here
- throw new RuntimeException( e );
+ final IStatus st
+ = new Status( IStatus.ERROR, PLUGIN_ID, 0,
+ Resources.failedWritingPreferences, e );
+
+ throw new CoreException( st );
}
}
@@ -415,10 +427,7 @@
private static Preferences getPreferencesNode( final IProject project )
{
final ProjectScope scope = new ProjectScope( project );
-
- final IEclipsePreferences pluginRoot
- = scope.getNode( "org.eclipse.jst.common.project.facet.core" );
-
+ final IEclipsePreferences pluginRoot = scope.getNode( PLUGIN_ID );
return pluginRoot.node( "classpath.helper" );
}
@@ -441,5 +450,18 @@
return new Path( path.replaceAll( "::", "/" ) );
}
+ private static final class Resources
+
+ extends NLS
+
+ {
+ public static String failedWritingPreferences;
+
+ static
+ {
+ initializeMessages( ClasspathHelper.class.getName(),
+ Resources.class );
+ }
+ }
}
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/ClasspathHelper.properties b/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/ClasspathHelper.properties
new file mode 100644
index 0000000..cb5aee1
--- /dev/null
+++ b/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/ClasspathHelper.properties
@@ -0,0 +1 @@
+failedWritingPreferences = Failed while writing preferences.
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/plugin.xml b/plugins/org.eclipse.wst.common.project.facet.core/plugin.xml
index bf147f9..b275039 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/plugin.xml
+++ b/plugins/org.eclipse.wst.common.project.facet.core/plugin.xml
@@ -21,12 +21,4 @@
</runtime>
</extension>
- <extension point="org.eclipse.core.runtime.adapters">
- <factory
- class="org.eclipse.wst.common.project.facet.core.runtime.classpath.internal.RuntimeClasspathProvider$Factory"
- adaptableType="org.eclipse.wst.common.project.facet.core.runtime.IRuntime">
- <adapter type="org.eclipse.wst.common.project.facet.core.runtime.classpath.IClasspathProvider"/>
- </factory>
- </extension>
-
</plugin>
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/schemas/facets.exsd b/plugins/org.eclipse.wst.common.project.facet.core/schemas/facets.exsd
index a3ad0c2..8d5981f 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/schemas/facets.exsd
+++ b/plugins/org.eclipse.wst.common.project.facet.core/schemas/facets.exsd
@@ -18,6 +18,7 @@
<element ref="category"/>
<element ref="preset"/>
<element ref="template"/>
+ <element ref="action"/>
</choice>
<attribute name="point" type="string" use="required">
<annotation>
@@ -313,6 +314,20 @@
</restriction>
</simpleType>
</attribute>
+ <attribute name="facet" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="version" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
</complexType>
</element>
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/IActionConfig.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/IActionConfig.java
new file mode 100644
index 0000000..68bdbfd
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/IActionConfig.java
@@ -0,0 +1,10 @@
+package org.eclipse.wst.common.project.facet.core;
+
+import org.eclipse.core.runtime.IStatus;
+
+public interface IActionConfig
+{
+ void setVersion( IProjectFacetVersion fv );
+ void setProjectName( String pjname );
+ IStatus validate();
+}
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/IProjectFacet.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/IProjectFacet.java
index 57c89bd..fb56b42 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/IProjectFacet.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/IProjectFacet.java
@@ -15,6 +15,8 @@
import java.util.List;
import java.util.Set;
+import org.eclipse.core.runtime.CoreException;
+
/**
* Contains metadata that describes a project facet. This interface is not
* intended to be implemented by clients.
@@ -113,7 +115,7 @@
IProjectFacetVersion getLatestVersion()
- throws VersionFormatException;
+ throws VersionFormatException, CoreException;
/**
* Returns a sorted list containing the descriptors of all versions of this
@@ -128,7 +130,7 @@
List getSortedVersions( boolean ascending )
- throws VersionFormatException;
+ throws VersionFormatException, CoreException;
/**
* Returns the version comparator specified for this project facet. If no
@@ -138,6 +140,8 @@
* @return the version comparator specified for this project facet
*/
- Comparator getVersionComparator();
+ Comparator getVersionComparator()
+
+ throws CoreException;
}
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/IProjectFacetVersion.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/IProjectFacetVersion.java
index 71b7323..38e6db9 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/IProjectFacetVersion.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/IProjectFacetVersion.java
@@ -67,13 +67,21 @@
* requires no config.
*
* @param type the type of the action.
+ * @param pjname the name of the project that this action will be executed
+ * on
* @return the action config object, or <code>null</code>
* @throws CoreException if this project facet version does not support the
* specified action type or if failed while creating the action config
* object
*/
- Object createActionConfig( Action.Type type )
+ Object createActionConfig( Action.Type type,
+ String pjname )
+
+ throws CoreException;
+
+ boolean isSameActionConfig( Action.Type type,
+ IProjectFacetVersion fv )
throws CoreException;
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/ProjectFacetsManager.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/ProjectFacetsManager.java
index e55f341..dd75a57 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/ProjectFacetsManager.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/ProjectFacetsManager.java
@@ -281,6 +281,17 @@
return impl.create( name, location, monitor );
}
+ public static IFacetedProject create( final IProject project,
+ final boolean convertIfNecessary,
+ final IProgressMonitor monitor )
+
+ throws CoreException
+
+ {
+ return impl.create( project, convertIfNecessary, monitor );
+ }
+
+
/**
* Checks the validity of applying the specified set of actions to the
* specified set of base project facets. Returns the union of all validation
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/Constraint.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/Constraint.java
index 8cc8b4b..e114a29 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/Constraint.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/Constraint.java
@@ -18,6 +18,7 @@
import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.osgi.util.NLS;
@@ -138,7 +139,17 @@
final IProjectFacet rf
= ProjectFacetsManager.getProjectFacet( name );
- final Comparator comp = rf.getVersionComparator();
+ final Comparator comp;
+
+ try
+ {
+ comp = rf.getVersionComparator();
+ }
+ catch( CoreException e )
+ {
+ FacetCorePlugin.log( e );
+ return result;
+ }
boolean found = false;
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetCorePlugin.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetCorePlugin.java
index f26ef01..114a80b 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetCorePlugin.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetCorePlugin.java
@@ -43,15 +43,27 @@
public static void log( final Exception e )
{
final ILog log = getInstance().getLog();
- final String msg = e.getMessage();
+ final String msg = e.getMessage() + "";
log.log( new Status( IStatus.ERROR, PLUGIN_ID, IStatus.OK, msg, e ) );
}
+
+ public static void log( final String msg )
+ {
+ final ILog log = getInstance().getLog();
+
+ log.log( new Status( IStatus.ERROR, PLUGIN_ID, IStatus.OK, msg, null ) );
+ }
public static IStatus createErrorStatus( final String msg )
{
- return new Status( IStatus.ERROR, FacetCorePlugin.PLUGIN_ID, 0, msg,
- null );
+ return createErrorStatus( msg, null );
+ }
+
+ public static IStatus createErrorStatus( final String msg,
+ final Exception e )
+ {
+ return new Status( IStatus.ERROR, FacetCorePlugin.PLUGIN_ID, 0, msg, e );
}
}
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProject.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProject.java
index 491c684..49d799b 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProject.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProject.java
@@ -35,12 +35,15 @@
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.common.project.facet.core.IActionConfig;
import org.eclipse.wst.common.project.facet.core.IDelegate;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
@@ -72,6 +75,9 @@
private final IFile f;
FacetedProject( final IProject project )
+
+ throws CoreException
+
{
this.project = project;
this.facets = new HashSet();
@@ -180,9 +186,62 @@
throw new CoreException( st );
}
+ // Sort the actions into the order of execution.
+
final List copy = new ArrayList( actions );
ProjectFacetsManager.sort( this.facets, copy );
+ // Update and check the action configs.
+
+ for( int i = 0, n = copy.size(); i < n; i++ )
+ {
+ Action action = (Action) copy.get( i );
+ final IProjectFacetVersion fv = action.getProjectFacetVersion();
+ Object config = action.getConfig();
+
+ if( config == null )
+ {
+ config = fv.createActionConfig( action.getType(),
+ this.project.getName() );
+
+ if( config != null )
+ {
+ action = new Action( action.getType(), fv, config );
+ copy.set( i, action );
+ }
+ }
+
+ if( config != null )
+ {
+ IActionConfig cfg = null;
+
+ if( config instanceof IActionConfig )
+ {
+ cfg = (IActionConfig) config;
+ }
+ else
+ {
+ final IAdapterManager m = Platform.getAdapterManager();
+ cfg = (IActionConfig) m.loadAdapter( config, IActionConfig.class.getName() );
+ }
+
+ if( cfg != null )
+ {
+ cfg.setProjectName( this.project.getName() );
+ cfg.setVersion( fv );
+
+ final IStatus status = cfg.validate();
+
+ if( status.getSeverity() != IStatus.OK )
+ {
+ throw new CoreException( status );
+ }
+ }
+ }
+ }
+
+ // Execute the actions.
+
for( Iterator itr = copy.iterator(); itr.hasNext(); )
{
//if( monitor != null && monitor.isCanceled() &&
@@ -213,14 +272,7 @@
= monitor == null
? null : new SubProgressMonitor( monitor, 1 );
- Object config = action.getConfig();
-
- if( config == null )
- {
- config = fv.createActionConfig( type );
- }
-
- callDelegate( this.project, fv, config,
+ callDelegate( this.project, fv, action.getConfig(),
IDelegate.Type.get( type ), delegate,
submonitor );
}
@@ -344,7 +396,7 @@
else
{
cause = new Status( IStatus.ERROR, FacetCorePlugin.PLUGIN_ID,
- 0, e.getMessage(), e );
+ 0, e.getMessage() + "", e );
}
final String msg;
@@ -481,6 +533,9 @@
}
private void open()
+
+ throws CoreException
+
{
if( ! this.f.exists() )
{
@@ -502,25 +557,52 @@
}
else if( name.equals( "fixed" ) )
{
- // TODO: Handle the case where facet is not defined.
+ final String id = e.getAttribute( "facet" );
- final String fid = e.getAttribute( "facet" );
+ if( ! ProjectFacetsManager.isProjectFacetDefined( id ) )
+ {
+ final String msg
+ = NLS.bind( Resources.facetNotDefined, id );
+
+ final IStatus st = FacetCorePlugin.createErrorStatus( msg );
+
+ throw new CoreException( st );
+ }
final IProjectFacet f
- = ProjectFacetsManager.getProjectFacet( fid );
+ = ProjectFacetsManager.getProjectFacet( id );
this.fixed.add( f );
}
else if( name.equals( "installed" ) )
{
- // TODO: Handle the case where facet or version is not defined.
-
final String id = e.getAttribute( "facet" );
final String version = e.getAttribute( "version" );
+ if( ! ProjectFacetsManager.isProjectFacetDefined( id ) )
+ {
+ final String msg
+ = NLS.bind( Resources.facetNotDefined, id );
+
+ final IStatus st = FacetCorePlugin.createErrorStatus( msg );
+
+ throw new CoreException( st );
+ }
+
final IProjectFacet f
= ProjectFacetsManager.getProjectFacet( id );
+ if( ! f.hasVersion( version ) )
+ {
+ final String msg
+ = NLS.bind( Resources.facetVersionNotDefined, id,
+ version );
+
+ final IStatus st = FacetCorePlugin.createErrorStatus( msg );
+
+ throw new CoreException( st );
+ }
+
final IProjectFacetVersion fv = f.getVersion( version );
this.facets.add( fv );
@@ -609,6 +691,8 @@
public static String failedOnUninstall;
public static String failedOnVersionChange;
public static String failedOnRuntimeChanged;
+ public static String facetNotDefined;
+ public static String facetVersionNotDefined;
static
{
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProject.properties b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProject.properties
index 848a035..cb9e69e 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProject.properties
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/FacetedProject.properties
@@ -1,4 +1,6 @@
failedOnInstall = Failed while installing {0}.
failedOnUninstall = Failed while uninstalling {0}.
failedOnVersionChange = Failed while changing version of {0} to {1}.
-failedOnRuntimeChanged = Failed while {0} was reacting to changed runtime.
\ No newline at end of file
+failedOnRuntimeChanged = Failed while {0} was reacting to changed runtime.
+facetNotDefined = Facet {0} is not defined.
+facetVersionNotDefined = Version {1} of facet {0} is not defined.
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/IVersion.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/IVersion.java
new file mode 100644
index 0000000..72b7b8e
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/IVersion.java
@@ -0,0 +1,22 @@
+/******************************************************************************
+ * Copyright (c) 2005 BEA Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Konstantin Komissarchik - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.wst.common.project.facet.core.internal;
+
+/**
+ * @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a>
+ */
+
+public abstract interface IVersion
+{
+ String getVersionString();
+ Versionable getVersionable();
+}
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacet.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacet.java
index d27d872..d399837 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacet.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacet.java
@@ -11,10 +11,16 @@
package org.eclipse.wst.common.project.facet.core.internal;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.project.facet.core.ICategory;
+import org.eclipse.wst.common.project.facet.core.IDelegate;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.VersionFormatException;
@@ -45,6 +51,7 @@
private String description;
private String iconPath;
private ICategory category;
+ private final List actionDefinitions = new ArrayList();
ProjectFacet() {}
@@ -132,7 +139,7 @@
public IProjectFacetVersion getLatestVersion()
- throws VersionFormatException
+ throws VersionFormatException, CoreException
{
final Comparator comp = getVersionComparator( true, VERSION_ADAPTER );
@@ -146,9 +153,58 @@
return VERSION_ADAPTER;
}
+ ActionDefinition getActionDefinition( final IProjectFacetVersion fv,
+ final IDelegate.Type type )
+
+ throws CoreException
+
+ {
+ ActionDefinition result = null;
+
+ for( Iterator itr = this.actionDefinitions.iterator(); itr.hasNext(); )
+ {
+ final ActionDefinition def = (ActionDefinition) itr.next();
+
+ if( def.type == type &&
+ def.versionMatchExpr.evaluate( (IVersion) fv ) )
+ {
+ if( result == null )
+ {
+ result = def;
+ }
+ else
+ {
+ // TODO: Throw better error.
+ throw new RuntimeException();
+ }
+ }
+ }
+
+ return result;
+ }
+
+ void addActionDefinition( final ActionDefinition actionDefinition )
+ {
+ this.actionDefinitions.add( actionDefinition );
+ }
+
+ public String createVersionNotFoundErrMsg( final String verstr )
+ {
+ return NLS.bind( ProjectFacetsManagerImpl.Resources.facetVersionNotDefinedNoPlugin,
+ this.id, verstr );
+ }
+
public String toString()
{
return this.label;
}
+
+ static final class ActionDefinition
+ {
+ public IDelegate.Type type;
+ public VersionMatchExpr versionMatchExpr;
+ public String delegateClassName;
+ public String configFactoryClassName;
+ }
}
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetVersion.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetVersion.java
index afffd00..5c401e2 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetVersion.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetVersion.java
@@ -14,14 +14,18 @@
import java.util.HashMap;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.common.project.facet.core.IActionConfig;
import org.eclipse.wst.common.project.facet.core.IActionConfigFactory;
import org.eclipse.wst.common.project.facet.core.IConstraint;
import org.eclipse.wst.common.project.facet.core.IDelegate;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
+import org.eclipse.wst.common.project.facet.core.internal.ProjectFacet.ActionDefinition;
import org.osgi.framework.Bundle;
/**
@@ -32,15 +36,14 @@
public final class ProjectFacetVersion
- implements IProjectFacetVersion
+ implements IProjectFacetVersion, IVersion
{
- private IProjectFacet facet;
+ private ProjectFacet facet;
private String version;
private IConstraint constraint;
private String plugin;
private final HashMap delegates = new HashMap();
- private final HashMap configFactories = new HashMap();
ProjectFacetVersion() {}
@@ -49,7 +52,7 @@
return this.facet;
}
- void setProjectFacet( final IProjectFacet facet )
+ void setProjectFacet( final ProjectFacet facet )
{
this.facet = facet;
}
@@ -63,6 +66,11 @@
{
this.version = version;
}
+
+ public Versionable getVersionable()
+ {
+ return (Versionable) this.facet;
+ }
public IConstraint getConstraint()
{
@@ -86,10 +94,19 @@
public boolean supports( final Action.Type type )
{
- return this.delegates.containsKey( IDelegate.Type.get( type ) );
+ try
+ {
+ return this.facet.getActionDefinition( this, IDelegate.Type.get( type ) ) != null;
+ }
+ catch( CoreException e )
+ {
+ FacetCorePlugin.log( e );
+ return false;
+ }
}
- public Object createActionConfig( final Action.Type type )
+ public Object createActionConfig( final Action.Type type,
+ final String pjname )
throws CoreException
@@ -103,15 +120,16 @@
throw new CoreException( FacetCorePlugin.createErrorStatus( msg ) );
}
- final String clname
- = (String) this.configFactories.get( IDelegate.Type.get( type ) );
+ final ActionDefinition def
+ = this.facet.getActionDefinition( this, IDelegate.Type.get( type ) );
- if( clname == null )
+ if( def == null || def.configFactoryClassName == null )
{
return null;
}
else
{
+ final String clname = def.configFactoryClassName;
final Object temp = create( clname );
if( ! ( temp instanceof IActionConfigFactory ) )
@@ -123,33 +141,69 @@
throw new CoreException( FacetCorePlugin.createErrorStatus( msg ) );
}
- return ( (IActionConfigFactory) temp ).create();
+ final Object config = ( (IActionConfigFactory) temp ).create();
+
+ IActionConfig cfg = null;
+
+ if( config instanceof IActionConfig )
+ {
+ cfg = (IActionConfig) config;
+ }
+ else
+ {
+ final IAdapterManager m = Platform.getAdapterManager();
+ cfg = (IActionConfig) m.loadAdapter( config, IActionConfig.class.getName() );
+ }
+
+ if( cfg != null )
+ {
+ cfg.setProjectName( pjname );
+ cfg.setVersion( this );
+ }
+
+ return config;
}
}
- void setActionConfigFactory( final IDelegate.Type type,
- final String configFactoryClassName )
+ public boolean isSameActionConfig( final Action.Type type,
+ final IProjectFacetVersion fv )
+
+ throws CoreException
+
{
- this.configFactories.put( type, configFactoryClassName );
+ final IDelegate.Type t = IDelegate.Type.get( type );
+
+ return this.facet.getActionDefinition( fv, t )
+ == this.facet.getActionDefinition( this, t );
}
IDelegate getDelegate( final IDelegate.Type type )
+
+ throws CoreException
+
{
Object delegate = this.delegates.get( type );
if( delegate == null )
{
- return null;
- }
- else if( delegate instanceof String )
- {
- final String clname = (String) delegate;
+ final ActionDefinition def
+ = this.facet.getActionDefinition( this, type );
+
+ if( def == null )
+ {
+ return null;
+ }
+
+ final String clname = def.delegateClassName;
delegate = create( clname );
if( ! ( delegate instanceof IDelegate ) )
{
- // TODO: Handle this better.
- throw new RuntimeException();
+ final String msg
+ = NLS.bind( Resources.notInstanceOf, clname,
+ IDelegate.class.getName() );
+
+ throw new CoreException( FacetCorePlugin.createErrorStatus( msg ) );
}
this.delegates.put( type, delegate );
@@ -158,13 +212,10 @@
return (IDelegate) delegate;
}
- void setDelegate( final IDelegate.Type type,
- final String delegateClassName )
- {
- this.delegates.put( type, delegateClassName );
- }
-
private Object create( final String clname )
+
+ throws CoreException
+
{
final Bundle bundle = Platform.getBundle( this.plugin );
@@ -175,8 +226,12 @@
}
catch( Exception e )
{
- // TODO: handle this.
- return null;
+ final String msg
+ = NLS.bind( Resources.failedToCreate, clname );
+
+ final IStatus st = FacetCorePlugin.createErrorStatus( msg, e );
+
+ throw new CoreException( st );
}
}
@@ -192,6 +247,7 @@
{
public static String actionNotSupported;
public static String notInstanceOf;
+ public static String failedToCreate;
static
{
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetVersion.properties b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetVersion.properties
index 6cdd97c..391e1f9 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetVersion.properties
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetVersion.properties
@@ -1,2 +1,3 @@
actionNotSupported = Project facet {0} does not support action type {1}.
notInstanceOf = Class {0} is not an instance of {1}.
+failedToCreate = Failed to instantiate class {0}.
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetsManagerImpl.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetsManagerImpl.java
index 78c159c..22a21e4 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetsManagerImpl.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetsManagerImpl.java
@@ -25,6 +25,7 @@
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
@@ -37,6 +38,8 @@
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.common.project.facet.core.IActionConfig;
import org.eclipse.wst.common.project.facet.core.ICategory;
import org.eclipse.wst.common.project.facet.core.IConstraint;
import org.eclipse.wst.common.project.facet.core.IDelegate;
@@ -47,6 +50,7 @@
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
+import org.eclipse.wst.common.project.facet.core.internal.ProjectFacet.ActionDefinition;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
@@ -293,6 +297,26 @@
return create( project );
}
+ public IFacetedProject create( final IProject project,
+ final boolean convertIfNecessary,
+ final IProgressMonitor monitor)
+
+ throws CoreException
+ {
+ if( project.exists() && convertIfNecessary ){
+ IProjectDescription description = project.getDescription();
+ String[] prevNatures = description.getNatureIds();
+ String[] newNatures = new String[ prevNatures.length + 1 ];
+ System.arraycopy( prevNatures, 0, newNatures, 0, prevNatures.length );
+ newNatures[ prevNatures.length ] = FacetedProjectNature.NATURE_ID;
+ description.setNatureIds( newNatures );
+ project.setDescription( description, monitor );
+ }
+ project.open( IResource.BACKGROUND_REFRESH,
+ new SubProgressMonitor( monitor, 1 ) );
+ return create( project );
+ }
+
public IStatus check( final Set base,
final Set actions )
{
@@ -777,6 +801,17 @@
readProjectFacetVersion( config );
}
}
+
+ for( int i = 0, n = cfgels.size(); i < n; i++ )
+ {
+ final IConfigurationElement config
+ = (IConfigurationElement) cfgels.get( i );
+
+ if( config.getName().equals( "action" ) )
+ {
+ readAction( config );
+ }
+ }
for( int i = 0, n = cfgels.size(); i < n; i++ )
{
@@ -810,7 +845,8 @@
if( id == null )
{
- // TODO: error
+ reportMissingAttribute( config, "id" );
+ return;
}
category.setId( id );
@@ -845,7 +881,8 @@
if( id == null )
{
- // TODO: error
+ reportMissingAttribute( config, "id" );
+ return;
}
final ProjectFacet descriptor = new ProjectFacet();
@@ -877,7 +914,8 @@
if( clname == null )
{
- // TODO: error
+ reportMissingAttribute( child, "class" );
+ return;
}
descriptor.setVersionComparator( clname );
@@ -891,7 +929,13 @@
if( category == null )
{
- // TODO: error
+ final String msg
+ = NLS.bind( Resources.categoryNotDefined,
+ child.getNamespace(), catname );
+
+ FacetCorePlugin.log( msg );
+
+ return;
}
descriptor.setCategory( category );
@@ -908,21 +952,29 @@
if( fid == null )
{
- // TODO: error
+ reportMissingAttribute( config, "facet" );
+ return;
}
final String ver = config.getAttribute( "version" );
if( ver == null )
{
- // TODO: error
+ reportMissingAttribute( config, "version" );
+ return;
}
final ProjectFacet f = (ProjectFacet) this.facets.get( fid );
if( f == null )
{
- // TODO: error
+ final String msg
+ = NLS.bind( Resources.facetNotDefined,
+ config.getNamespace(), fid );
+
+ FacetCorePlugin.log( msg );
+
+ return;
}
final ProjectFacetVersion fv
@@ -942,17 +994,29 @@
if( childName.equals( "constraint" ) )
{
final IConfigurationElement[] ops = child.getChildren();
+ final ArrayList parsed = new ArrayList();
- if( ops.length == 1 )
+ for( int j = 0; j < ops.length; j++ )
{
- final IConstraint op
- = readConstraint( ops[ 0 ], fv );
+ final IConstraint op = readConstraint( ops[ j ], fv );
- fv.setConstraint( op );
+ if( op != null )
+ {
+ parsed.add( op );
+ }
}
- else if( ops.length != 0 ) // No-op on empty constraints
+
+ if( parsed.size() == 1 )
{
- // TODO: error.
+ fv.setConstraint( (IConstraint) parsed.get( 0 ) );
+ }
+ else if( parsed.size() > 1 )
+ {
+ final IConstraint and
+ = new Constraint( fv, IConstraint.Type.AND,
+ parsed.toArray() );
+
+ fv.setConstraint( and );
}
}
else if( childName.equals( "group-member" ) )
@@ -961,7 +1025,8 @@
if( id == null )
{
- // TODO: error
+ reportMissingAttribute( child, "id" );
+ return;
}
Group group = (Group) this.groups.get( id );
@@ -976,44 +1041,106 @@
group.addMember( fv );
}
- else if( childName.equals( "action" ) )
- {
- readAction( child, fv );
- }
}
f.addVersion( fv );
+
+ // This has to happen after facet version is registered.
+
+ for( int i = 0; i < children.length; i++ )
+ {
+ final IConfigurationElement child = children[ i ];
+ final String childName = child.getName();
+
+ if( childName.equals( "action" ) )
+ {
+ readAction( child, f, ver );
+ }
+ }
+ }
+
+ private void readAction( final IConfigurationElement config )
+ {
+ final String fid = config.getAttribute( "facet" );
+
+ if( fid == null )
+ {
+ reportMissingAttribute( config, "facet" );
+ return;
+ }
+
+ final ProjectFacet f = (ProjectFacet) this.facets.get( fid );
+
+ if( f == null )
+ {
+ final String msg
+ = NLS.bind( Resources.facetNotDefined,
+ config.getNamespace(), fid );
+
+ FacetCorePlugin.log( msg );
+
+ return;
+ }
+
+ final String ver = config.getAttribute( "version" );
+
+ if( ver == null )
+ {
+ reportMissingAttribute( config, "version" );
+ return;
+ }
+
+ readAction( config, f, ver );
}
private void readAction( final IConfigurationElement config,
- final ProjectFacetVersion fv )
+ final ProjectFacet f,
+ final String version )
{
+ final ActionDefinition def = new ActionDefinition();
+
final String type = config.getAttribute( "type" );
- IDelegate.Type t = null;
if( type == null )
{
- // TODO: error
+ reportMissingAttribute( config, "type" );
+ return;
}
else if( type.equals( "install" ) )
{
- t = IDelegate.Type.INSTALL;
+ def.type = IDelegate.Type.INSTALL;
}
else if( type.equals( "uninstall" ) )
{
- t = IDelegate.Type.UNINSTALL;
+ def.type = IDelegate.Type.UNINSTALL;
}
else if( type.equals( "version-change" ) )
{
- t = IDelegate.Type.VERSION_CHANGE;
+ def.type = IDelegate.Type.VERSION_CHANGE;
}
else if( type.equals( "runtime-changed" ) )
{
- t = IDelegate.Type.RUNTIME_CHANGED;
+ def.type = IDelegate.Type.RUNTIME_CHANGED;
}
else
{
- // TODO: error
+ final String msg
+ = NLS.bind( Resources.invalidActionType, config.getNamespace(),
+ type );
+
+ FacetCorePlugin.log( msg );
+
+ return;
+ }
+
+ try
+ {
+ def.versionMatchExpr = new VersionMatchExpr( f, version );
+ }
+ catch( CoreException e )
+ {
+ FacetCorePlugin.log( e );
+ return;
}
final IConfigurationElement[] children = config.getChildren();
@@ -1029,10 +1156,11 @@
if( clname == null )
{
- // TODO: error
+ reportMissingAttribute( child, "class" );
+ return;
}
- fv.setActionConfigFactory( t, clname );
+ def.configFactoryClassName = clname;
}
else if( childName.equals( "delegate" ) )
{
@@ -1040,16 +1168,15 @@
if( clname == null )
{
- // TODO: error
+ reportMissingAttribute( config, "class" );
+ return;
}
- fv.setDelegate( t, clname );
- }
- else
- {
- // TODO: error
+ def.delegateClassName = clname;
}
}
+
+ f.addActionDefinition( def );
}
private IConstraint readConstraint( final IConfigurationElement root,
@@ -1077,14 +1204,16 @@
if( fid == null )
{
- // TODO: error
+ reportMissingAttribute( root, "facet" );
+ return null;
}
final String version = root.getAttribute( "version" );
if( version == null )
{
- // TODO: error
+ reportMissingAttribute( root, "version" );
+ return null;
}
final String allowNewerStr = root.getAttribute( "allow-newer" );
@@ -1107,14 +1236,15 @@
}
else if( type == IConstraint.Type.CONFLICTS )
{
- final String set = root.getAttribute( "group" );
+ final String group = root.getAttribute( "group" );
- if( set == null )
+ if( group == null )
{
- // TODO: error
+ reportMissingAttribute( root, "group" );
+ return null;
}
- operands = new Object[] { set };
+ operands = new Object[] { group };
}
else
{
@@ -1132,7 +1262,8 @@
if( id == null )
{
- // TODO: error
+ reportMissingAttribute( config, "id" );
+ return;
}
template.setId( id );
@@ -1154,12 +1285,19 @@
if( fid == null )
{
- // TODO: error
+ reportMissingAttribute( child, "facet" );
+ return;
}
if( ! isProjectFacetDefined( fid ) )
{
- // TODO: error
+ final String msg
+ = NLS.bind( Resources.facetNotDefined,
+ child.getNamespace(), fid );
+
+ FacetCorePlugin.log( msg );
+
+ return;
}
template.addFixedProjectFacet( getProjectFacet( fid ) );
@@ -1170,12 +1308,19 @@
if( pid == null )
{
- // TODO: error
+ reportMissingAttribute( child, "id" );
+ return;
}
if( ! isPresetDefined( pid ) )
{
- // TODO: error
+ final String msg
+ = NLS.bind( Resources.presetNotDefined,
+ child.getNamespace(), pid );
+
+ FacetCorePlugin.log( msg );
+
+ return;
}
template.setInitialPreset( getPreset( pid ) );
@@ -1193,7 +1338,8 @@
if( id == null )
{
- // TODO: error
+ reportMissingAttribute( config, "id" );
+ return;
}
preset.setId( id );
@@ -1215,14 +1361,16 @@
if( fid == null )
{
- // TODO: error
+ reportMissingAttribute( child, "id" );
+ return;
}
final String fver = child.getAttribute( "version" );
if( fver == null )
{
- // TODO: error
+ reportMissingAttribute( child, "version" );
+ return;
}
final IProjectFacetVersion fv
@@ -1235,6 +1383,17 @@
this.presets.add( id, preset );
}
+ private static void reportMissingAttribute( final IConfigurationElement el,
+ final String attribute )
+ {
+ final String[] params
+ = new String[] { el.getNamespace(), el.getName(), attribute };
+
+ final String msg = NLS.bind( Resources.missingAttribute, params );
+
+ FacetCorePlugin.log( msg );
+ }
+
private void saveUserPresets()
{
try
@@ -1359,4 +1518,24 @@
return pluginRoot.node( "user.presets" );
}
+ public static final class Resources
+
+ extends NLS
+
+ {
+ public static String missingAttribute;
+ public static String categoryNotDefined;
+ public static String facetNotDefined;
+ public static String facetVersionNotDefined;
+ public static String facetVersionNotDefinedNoPlugin;
+ public static String presetNotDefined;
+ public static String invalidActionType;
+
+ static
+ {
+ initializeMessages( ProjectFacetsManagerImpl.class.getName(),
+ Resources.class );
+ }
+ }
+
}
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetsManagerImpl.properties b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetsManagerImpl.properties
new file mode 100644
index 0000000..27270de
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/ProjectFacetsManagerImpl.properties
@@ -0,0 +1,7 @@
+missingAttribute = An extension element <{1}> in plugin {0} is missing a required attribute {2}.
+categoryNotDefined = Category {1} has not been defined. It's used in plugin {0}.
+facetNotDefined = Project facet {1} has not been defined. It's used in plugin {0}.
+facetVersionNotDefined = Version {2} of project facet {1} has not been defined. It's used in plugin {0}.
+facetVersionNotDefinedNoPlugin = Version {1} of project facet {0} has not been defined.
+presetNotDefined = Preset {1} has not been defined. It's used in plugin {0}.
+invalidActionType = "{1}" is an invalid action type. It's used in plugin {0}.
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/VersionMatchExpr.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/VersionMatchExpr.java
new file mode 100644
index 0000000..4645553
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/VersionMatchExpr.java
@@ -0,0 +1,217 @@
+/******************************************************************************
+ * Copyright (c) 2005 BEA Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Konstantin Komissarchik - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.wst.common.project.facet.core.internal;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a>
+ */
+
+public final class VersionMatchExpr
+{
+ private final Versionable versionable;
+ private final List subexprs = new ArrayList();
+
+ public VersionMatchExpr( final Versionable versionable,
+ final String expr )
+
+ throws CoreException
+
+ {
+ this.versionable = versionable;
+
+ final String[] subexprs = expr.split( "," );
+
+ for( int i = 0; i < subexprs.length; i++ )
+ {
+ final String subexpr = subexprs[ i ].trim();
+ final AbstractVersionOperator op;
+
+ if( subexpr.startsWith( "<=" ) )
+ {
+ op = new LessThanOrEq( parseVersion( subexpr, 2 ) );
+ }
+ else if( subexpr.startsWith( "<" ) )
+ {
+ op = new LessThan( parseVersion( subexpr, 1 ) );
+ }
+ else if( subexpr.startsWith( ">=" ) )
+ {
+ op = new GreaterThanOrEq( parseVersion( subexpr, 2 ) );
+ }
+ else if( subexpr.startsWith( ">" ) )
+ {
+ op = new GreaterThan( parseVersion( subexpr, 1 ) );
+ }
+ else
+ {
+ op = new Equals( parseVersion( subexpr, 0 ) );
+ }
+
+ this.subexprs.add( op );
+ }
+ }
+
+ private IVersion parseVersion( final String str,
+ final int offset )
+
+ throws CoreException
+
+ {
+ final String verstr = str.substring( offset ).trim();
+
+ if( ! this.versionable.hasVersion( verstr ) )
+ {
+ final String msg
+ = this.versionable.createVersionNotFoundErrMsg( verstr );
+
+ final IStatus st = FacetCorePlugin.createErrorStatus( msg );
+
+ throw new CoreException( st );
+ }
+ else
+ {
+ return this.versionable.getVersionInternal( verstr );
+ }
+ }
+
+ public boolean evaluate( final IVersion ver )
+
+ throws CoreException
+
+ {
+ for( Iterator itr = this.subexprs.iterator(); itr.hasNext(); )
+ {
+ if( ! ( (AbstractVersionOperator) itr.next() ).evaluate( ver ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private static abstract class AbstractVersionOperator
+ {
+ private final IVersion param;
+
+ public AbstractVersionOperator( final IVersion param )
+ {
+ this.param = param;
+ }
+
+ public boolean evaluate( final IVersion fv )
+
+ throws CoreException
+
+ {
+ final Comparator comp
+ = this.param.getVersionable().getVersionComparator();
+
+ final int result
+ = comp.compare( fv.getVersionString(),
+ param.getVersionString() );
+
+ return evaluate( result );
+ }
+
+ protected abstract boolean evaluate( int result );
+ }
+
+ private static final class Equals
+
+ extends AbstractVersionOperator
+
+ {
+ public Equals( final IVersion param )
+ {
+ super( param );
+ }
+
+ protected boolean evaluate( final int result )
+ {
+ return ( result == 0 );
+ }
+ }
+
+ private static final class LessThan
+
+ extends AbstractVersionOperator
+
+ {
+ public LessThan( final IVersion param )
+ {
+ super( param );
+ }
+
+ protected boolean evaluate( final int result )
+ {
+ return ( result < 0 );
+ }
+ }
+
+ private static final class LessThanOrEq
+
+ extends AbstractVersionOperator
+
+ {
+ public LessThanOrEq( final IVersion param )
+ {
+ super( param );
+ }
+
+ protected boolean evaluate( final int result )
+ {
+ return ( result <= 0 );
+ }
+ }
+
+ private static final class GreaterThan
+
+ extends AbstractVersionOperator
+
+ {
+ public GreaterThan( final IVersion param )
+ {
+ super( param );
+ }
+
+ protected boolean evaluate( final int result )
+ {
+ return ( result > 0 );
+ }
+ }
+
+ private static final class GreaterThanOrEq
+
+ extends AbstractVersionOperator
+
+ {
+ public GreaterThanOrEq( final IVersion param )
+ {
+ super( param );
+ }
+
+ protected boolean evaluate( final int result )
+ {
+ return ( result >= 0 );
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/Versionable.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/Versionable.java
index d698d2d..acdd174 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/Versionable.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/Versionable.java
@@ -14,10 +14,15 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.project.facet.core.DefaultVersionComparator;
import org.eclipse.wst.common.project.facet.core.VersionFormatException;
import org.osgi.framework.Bundle;
@@ -42,6 +47,32 @@
return this.versions.getUnmodifiable();
}
+ public Set getVersions( final String expr )
+
+ throws CoreException
+
+ {
+ final VersionMatchExpr prepared = new VersionMatchExpr( this, expr );
+ final Set result = new HashSet();
+
+ for( Iterator itr = this.versions.iterator(); itr.hasNext(); )
+ {
+ final IVersion ver = (IVersion) itr.next();
+
+ if( prepared.evaluate( ver ) )
+ {
+ result.add( ver );
+ }
+ }
+
+ return result;
+ }
+
+ public IVersion getVersionInternal( final String version )
+ {
+ return (IVersion) this.versions.get( version );
+ }
+
public boolean hasVersion( final String version )
{
return this.versions.containsKey( version );
@@ -49,7 +80,7 @@
public List getSortedVersions( final boolean ascending )
- throws VersionFormatException
+ throws VersionFormatException, CoreException
{
final ArrayList list = new ArrayList( this.versions );
@@ -61,12 +92,18 @@
}
public Comparator getVersionComparator()
+
+ throws CoreException
+
{
return getVersionComparator( true, null );
}
protected Comparator getVersionComparator( final boolean ascending,
final IVersionAdapter adapter )
+
+ throws CoreException
+
{
Comparator comp;
@@ -89,8 +126,14 @@
}
catch( Exception e )
{
- // TODO: handle this.
- return null;
+ final String msg
+ = NLS.bind( Resources.failedToCreate,
+ this.versionComparatorClass );
+
+ final IStatus st
+ = FacetCorePlugin.createErrorStatus( msg, e );
+
+ throw new CoreException( st );
}
}
@@ -135,6 +178,8 @@
this.versionComparatorClass = clname;
}
+ public abstract String createVersionNotFoundErrMsg( String verstr );
+
protected abstract IVersionAdapter getVersionAdapter();
protected static interface IVersionAdapter
@@ -142,4 +187,18 @@
String adapt( Object obj );
}
+ private static final class Resources
+
+ extends NLS
+
+ {
+ public static String failedToCreate;
+
+ static
+ {
+ initializeMessages( Versionable.class.getName(),
+ Resources.class );
+ }
+ }
+
}
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/Versionable.properties b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/Versionable.properties
new file mode 100644
index 0000000..94219a0
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/internal/Versionable.properties
@@ -0,0 +1 @@
+failedToCreate = Failed to instantiate class {0}.
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/IRuntimeComponentType.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/IRuntimeComponentType.java
index e1ef5f8..9cd3941 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/IRuntimeComponentType.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/IRuntimeComponentType.java
@@ -15,6 +15,7 @@
import java.util.List;
import java.util.Set;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.wst.common.project.facet.core.VersionFormatException;
/**
@@ -81,7 +82,9 @@
* @return returns the latest version of this runtime component
*/
- IRuntimeComponentVersion getLatestVersion();
+ IRuntimeComponentVersion getLatestVersion()
+
+ throws CoreException;
/**
* Returns a sorted list containing all of the versions of this runtime
@@ -93,7 +96,9 @@
* @throws VersionFormatException if failed while parsing a version string
*/
- List getSortedVersions( boolean ascending );
+ List getSortedVersions( boolean ascending )
+
+ throws CoreException;
/**
* Returns the version comparator specified for this runtime component type.
@@ -103,7 +108,9 @@
* @return the version comparator specified for this runtime component type
*/
- Comparator getVersionComparator();
+ Comparator getVersionComparator()
+
+ throws CoreException;
/**
* Returns the path that can be used to find the icon to be used with this
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponent.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponent.java
index bba578d..5709940 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponent.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponent.java
@@ -15,9 +15,11 @@
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.wst.common.project.facet.core.internal.FacetCorePlugin;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentType;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentVersion;
@@ -82,7 +84,16 @@
if( res == null )
{
- final IAdapterFactory factory = rcv.getAdapterFactory( type );
+ IAdapterFactory factory = null;
+
+ try
+ {
+ factory = rcv.getAdapterFactory( type );
+ }
+ catch( CoreException e )
+ {
+ FacetCorePlugin.log( e );
+ }
if( factory != null )
{
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponentType.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponentType.java
index e6d7fc6..c671fd0 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponentType.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponentType.java
@@ -14,6 +14,8 @@
import java.util.Collections;
import java.util.Comparator;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.project.facet.core.VersionFormatException;
import org.eclipse.wst.common.project.facet.core.internal.Versionable;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentType;
@@ -85,7 +87,7 @@
public IRuntimeComponentVersion getLatestVersion()
- throws VersionFormatException
+ throws VersionFormatException, CoreException
{
final Comparator comp = getVersionComparator( true, VERSION_ADAPTER );
@@ -109,4 +111,11 @@
return VERSION_ADAPTER;
}
+ public String createVersionNotFoundErrMsg( final String verstr )
+ {
+ return NLS.bind( RuntimeManagerImpl.Resources.runtimeComponentVersionNotDefinedNoPlugin,
+ this.id, verstr );
+ }
+
+
}
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponentVersion.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponentVersion.java
index 7917162..e505bd7 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponentVersion.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponentVersion.java
@@ -13,8 +13,14 @@
import java.util.HashMap;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.common.project.facet.core.internal.FacetCorePlugin;
+import org.eclipse.wst.common.project.facet.core.internal.IVersion;
+import org.eclipse.wst.common.project.facet.core.internal.Versionable;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentType;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentVersion;
import org.osgi.framework.Bundle;
@@ -25,7 +31,7 @@
public final class RuntimeComponentVersion
- implements IRuntimeComponentVersion
+ implements IRuntimeComponentVersion, IVersion
{
private String plugin;
@@ -63,7 +69,15 @@
this.version = version;
}
+ public Versionable getVersionable()
+ {
+ return (Versionable) this.type;
+ }
+
IAdapterFactory getAdapterFactory( final Class type )
+
+ throws CoreException
+
{
synchronized( this.adapterFactories )
{
@@ -83,13 +97,19 @@
{
final Class cl = bundle.loadClass( ref.clname );
factory = cl.newInstance();
- this.adapterFactories.put( type.getName(), factory );
}
catch( Exception e )
{
- // TODO: handle this better
- throw new RuntimeException( e );
+ final String msg
+ = NLS.bind( Resources.failedToCreate, ref.clname );
+
+ final IStatus st
+ = FacetCorePlugin.createErrorStatus( msg );
+
+ throw new CoreException( st );
}
+
+ this.adapterFactories.put( type.getName(), factory );
}
return (IAdapterFactory) factory;
@@ -119,4 +139,19 @@
}
}
+ private static final class Resources
+
+ extends NLS
+
+ {
+ public static String failedToCreate;
+
+ static
+ {
+ initializeMessages( RuntimeComponentVersion.class.getName(),
+ Resources.class );
+ }
+ }
+
+
}
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponentVersion.properties b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponentVersion.properties
new file mode 100644
index 0000000..94219a0
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeComponentVersion.properties
@@ -0,0 +1 @@
+failedToCreate = Failed to instantiate class {0}.
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeManagerImpl.java b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeManagerImpl.java
index 087f481..b35c303 100644
--- a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeManagerImpl.java
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeManagerImpl.java
@@ -20,16 +20,19 @@
import java.util.Map;
import java.util.Set;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.common.project.facet.core.internal.FacetCorePlugin;
import org.eclipse.wst.common.project.facet.core.internal.IndexedSet;
+import org.eclipse.wst.common.project.facet.core.internal.ProjectFacetsManagerImpl;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeBridge;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent;
@@ -109,7 +112,7 @@
public static Set getRuntimes()
{
bridge();
- return runtimes.getUnmodifiable();
+ return (Set) runtimes.clone();
}
public static Set getRuntimes( final Set facets )
@@ -227,10 +230,22 @@
if( m.facetAllowNewer )
{
- final List sorted = m.facet.getSortedVersions( true );
+ final List sorted;
+
+ try
+ {
+ sorted = m.facet.getSortedVersions( true );
+ }
+ catch( CoreException e )
+ {
+ FacetCorePlugin.log( e );
+ continue;
+ }
+
boolean found = false;
- for( Iterator itr3 = sorted.iterator(); itr3.hasNext(); )
+ for( Iterator itr3 = sorted.iterator();
+ itr3.hasNext(); )
{
if( found )
{
@@ -359,7 +374,8 @@
if( id == null )
{
- // TODO: error
+ reportMissingAttribute( config, "id" );
+ return;
}
final RuntimeComponentType rct = new RuntimeComponentType();
@@ -379,7 +395,8 @@
if( clname == null )
{
- // TODO: error
+ reportMissingAttribute( child, "class" );
+ return;
}
rct.setVersionComparator( clname );
@@ -399,14 +416,16 @@
if( type == null )
{
- // TODO: error
+ reportMissingAttribute( config, "type" );
+ return;
}
final String ver = config.getAttribute( "version" );
if( ver == null )
{
- // TODO: error
+ reportMissingAttribute( config, "version" );
+ return;
}
final RuntimeComponentType rct
@@ -414,7 +433,13 @@
if( rct == null )
{
- // TODO: error
+ final String msg
+ = NLS.bind( Resources.runtimeComponentTypeNotDefined,
+ config.getNamespace(), type );
+
+ FacetCorePlugin.log( msg );
+
+ return;
}
final RuntimeComponentVersion rcv = new RuntimeComponentVersion();
@@ -446,12 +471,19 @@
if( id == null )
{
- // TODO: error
+ reportMissingAttribute( child, "id" );
+ return;
}
if( ! isRuntimeComponentTypeDefined( id ) )
{
- // TODO: error
+ final String msg
+ = NLS.bind( Resources.runtimeComponentTypeNotDefined,
+ child.getNamespace(), id );
+
+ FacetCorePlugin.log( msg );
+
+ return;
}
rctype = getRuntimeComponentType( id );
@@ -462,7 +494,17 @@
{
if( ! rctype.hasVersion( version ) )
{
- // TODO: error
+ final String[] params
+ = new String[] { config.getNamespace(), id,
+ version };
+
+ final String msg
+ = NLS.bind( Resources.runtimeComponentVersionNotDefined,
+ params );
+
+ FacetCorePlugin.log( msg );
+
+ return;
}
rcversion = rctype.getVersion( version );
@@ -474,7 +516,8 @@
if( factory == null )
{
- // TODO: error
+ reportMissingAttribute( child, "class" );
+ return;
}
}
else if( childName.equals( "type" ) )
@@ -483,7 +526,8 @@
if( type == null )
{
- // TODO: error
+ reportMissingAttribute( child, "class" );
+ return;
}
else
{
@@ -533,12 +577,19 @@
if( id == null )
{
- // TODO: error
+ reportMissingAttribute( child, "id" );
+ return;
}
if( ! ProjectFacetsManager.isProjectFacetDefined( id ) )
{
- // TODO: error
+ final String msg
+ = NLS.bind( ProjectFacetsManagerImpl.Resources.facetNotDefined,
+ child.getNamespace(), id );
+
+ FacetCorePlugin.log( msg );
+
+ return;
}
m.facet = ProjectFacetsManager.getProjectFacet( id );
@@ -549,7 +600,17 @@
{
if( ! m.facet.hasVersion( version ) )
{
- // TODO: error
+ final String[] params
+ = new String[] { config.getNamespace(), id,
+ version };
+
+ final String msg
+ = NLS.bind( ProjectFacetsManagerImpl.Resources.facetVersionNotDefined,
+ params );
+
+ FacetCorePlugin.log( msg );
+
+ return;
}
m.facetVersion = m.facet.getVersion( version );
@@ -570,12 +631,19 @@
if( id == null )
{
- // TODO: error
+ reportMissingAttribute( child, "id" );
+ return;
}
if( ! isRuntimeComponentTypeDefined( id ) )
{
- // TODO: error
+ final String msg
+ = NLS.bind( Resources.runtimeComponentTypeNotDefined,
+ config.getNamespace(), id );
+
+ FacetCorePlugin.log( msg );
+
+ return;
}
m.runtimeCompType = getRuntimeComponentType( id );
@@ -586,7 +654,17 @@
{
if( ! m.runtimeCompType.hasVersion( version ) )
{
- // TODO: error
+ final String[] params
+ = new String[] { config.getNamespace(), id,
+ version };
+
+ final String msg
+ = NLS.bind( Resources.runtimeComponentVersionNotDefined,
+ params );
+
+ FacetCorePlugin.log( msg );
+
+ return;
}
m.runtimeCompVersion
@@ -606,6 +684,17 @@
mappings.add( m );
}
+ private static void reportMissingAttribute( final IConfigurationElement el,
+ final String attribute )
+ {
+ final String[] params
+ = new String[] { el.getNamespace(), el.getName(), attribute };
+
+ final String msg = NLS.bind( Resources.missingAttribute, params );
+
+ FacetCorePlugin.log( msg );
+ }
+
private static final class Mapping
{
public IProjectFacet facet;
@@ -633,13 +722,22 @@
}
else if( this.runtimeCompAllowNewer )
{
- final Comparator comparator
- = this.runtimeCompType.getVersionComparator();
+ final Comparator comp;
+
+ try
+ {
+ comp = this.runtimeCompType.getVersionComparator();
+ }
+ catch( CoreException e )
+ {
+ FacetCorePlugin.log( e );
+ return false;
+ }
final String v1 = version.getVersionString();
final String v2 = this.runtimeCompVersion.getVersionString();
- if( comparator.compare( v1, v2 ) > 0 )
+ if( comp.compare( v1, v2 ) > 0 )
{
return true;
}
@@ -650,4 +748,21 @@
}
}
+ public static final class Resources
+
+ extends NLS
+
+ {
+ public static String missingAttribute;
+ public static String runtimeComponentTypeNotDefined;
+ public static String runtimeComponentVersionNotDefined;
+ public static String runtimeComponentVersionNotDefinedNoPlugin;
+
+ static
+ {
+ initializeMessages( RuntimeManagerImpl.class.getName(),
+ Resources.class );
+ }
+ }
+
}
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeManagerImpl.properties b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeManagerImpl.properties
new file mode 100644
index 0000000..a351681
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.project.facet.core/src/org/eclipse/wst/common/project/facet/core/runtime/internal/RuntimeManagerImpl.properties
@@ -0,0 +1,4 @@
+missingAttribute = An extension element <{1}> in plugin {0} is missing a required attribute {2}.
+runtimeComponentTypeNotDefined = Runtime component type {1} has not been defined. It's used in plugin {0}.
+runtimeComponentVersionNotDefined = Version {2} of runtime component type {1} has not been defined. It's used in plugin {0}.
+runtimeComponentVersionNotDefinedNoPlugin = Version {1} of runtime component type {0} has not been defined.
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/.cvsignore b/plugins/org.eclipse.wst.common.project.facet.ui/.cvsignore
index fc40a91..1150533 100644
--- a/plugins/org.eclipse.wst.common.project.facet.ui/.cvsignore
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/.cvsignore
@@ -2,5 +2,3 @@
build.xml
facet-ui.jar
temp.folder
-@dot
-src.zip
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/AddRemoveFacetsWizard.java b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/AddRemoveFacetsWizard.java
index 382112d..a30334b 100644
--- a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/AddRemoveFacetsWizard.java
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/AddRemoveFacetsWizard.java
@@ -65,7 +65,7 @@
public void addPages()
{
- this.facetsSelectionPage = new FacetsSelectionPage();
+ this.facetsSelectionPage = new FacetsSelectionPage( context );
if( this.fproj != null )
{
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/AddRemoveFacetsAction.java b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/AddRemoveFacetsAction.java
index 2b12be0..cd95d1d 100644
--- a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/AddRemoveFacetsAction.java
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/AddRemoveFacetsAction.java
@@ -14,10 +14,12 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
@@ -59,8 +61,12 @@
}
catch( CoreException e )
{
- // TODO: Handle this better.
- throw new RuntimeException( e );
+ ErrorDialog.openError( this.shell, Resources.errDlgTitle,
+ e.getMessage(), e.getStatus() );
+
+ FacetUiPlugin.log( e );
+
+ return;
}
final IWizard wizard = new AddRemoveFacetsWizard( fproj );
@@ -76,4 +82,18 @@
this.selection = selection;
}
+ private static final class Resources
+
+ extends NLS
+
+ {
+ public static String errDlgTitle;
+
+ static
+ {
+ initializeMessages( AddRemoveFacetsAction.class.getName(),
+ Resources.class );
+ }
+ }
+
}
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/AddRemoveFacetsAction.properties b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/AddRemoveFacetsAction.properties
new file mode 100644
index 0000000..feb2801
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/AddRemoveFacetsAction.properties
@@ -0,0 +1 @@
+errDlgTitle = Error
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/ConflictingFacetsFilter.java b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/ConflictingFacetsFilter.java
index 99021b5..b68a429 100644
--- a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/ConflictingFacetsFilter.java
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/ConflictingFacetsFilter.java
@@ -15,6 +15,7 @@
import java.util.Iterator;
import java.util.Set;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.wst.common.project.facet.core.IConstraint;
import org.eclipse.wst.common.project.facet.core.IGroup;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
@@ -116,7 +117,17 @@
= ProjectFacetsManager.getProjectFacet( name );
final Set versions = rf.getVersions();
- final Comparator comp = rf.getVersionComparator();
+ final Comparator comp;
+
+ try
+ {
+ comp = rf.getVersionComparator();
+ }
+ catch( CoreException e )
+ {
+ FacetUiPlugin.log( e );
+ return false;
+ }
for( Iterator itr = versions.iterator(); itr.hasNext(); )
{
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetUiPlugin.java b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetUiPlugin.java
index 587c56e..3442418 100644
--- a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetUiPlugin.java
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetUiPlugin.java
@@ -48,5 +48,18 @@
log.log( new Status( IStatus.ERROR, PLUGIN_ID, IStatus.OK, msg, e ) );
}
+
+ public static void log( final String msg )
+ {
+ final ILog log = getInstance().getLog();
+
+ log.log( new Status( IStatus.ERROR, PLUGIN_ID, IStatus.OK, msg, null ) );
+ }
+
+ public static IStatus createErrorStatus( final String msg,
+ final Exception e )
+ {
+ return new Status( IStatus.ERROR, FacetUiPlugin.PLUGIN_ID, 0, msg, e );
+ }
}
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPage.java b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPage.java
index 26c73f3..3e545ba 100644
--- a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPage.java
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPage.java
@@ -13,8 +13,11 @@
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
+import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
@@ -23,10 +26,13 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
+import org.eclipse.wst.common.project.facet.core.IActionConfig;
import org.eclipse.wst.common.project.facet.core.ICategory;
import org.eclipse.wst.common.project.facet.core.IPreset;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
+import org.eclipse.wst.common.project.facet.ui.IWizardContext;
/**
* @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a>
@@ -37,6 +43,7 @@
extends WizardPage
{
+ private IWizardContext context;
private IPreset initialPreset;
private Set initialSelection;
private final Set fixed;
@@ -45,13 +52,14 @@
private FacetsSelectionPanel panel;
private ArrayList listeners;
- public FacetsSelectionPage()
+ public FacetsSelectionPage( final IWizardContext context )
{
super( "facets.selection.page" );
setTitle( "Select Project Facets" );
setDescription( "Select facets for this project." );
+ this.context = context;
this.initialPreset = null;
this.initialSelection = null;
this.fixed = new HashSet();
@@ -114,7 +122,8 @@
public void createControl( final Composite parent )
{
this.panel
- = new FacetsSelectionPanel( parent, SWT.NONE, this.runtime );
+ = new FacetsSelectionPanel( parent, SWT.NONE, this.runtime,
+ context );
this.panel.setFixedProjectFacets( this.fixed );
@@ -189,10 +198,46 @@
( (Listener) this.listeners.get( i ) ).handleEvent( event );
}
- final boolean valid
- = FacetsSelectionPage.this.panel.isSelectionValid();
-
- setPageComplete( valid );
+ setPageComplete( this.panel.isSelectionValid() );
+ }
+
+ public void setVisible( final boolean visible )
+ {
+ if( visible )
+ {
+ for( Iterator itr = this.panel.getActions().iterator();
+ itr.hasNext(); )
+ {
+ final Object config = ( (Action) itr.next() ).getConfig();
+
+ if( config != null )
+ {
+ IActionConfig c = null;
+
+ if( config instanceof IActionConfig )
+ {
+ c = (IActionConfig) config;
+ }
+ else
+ {
+ final IAdapterManager m
+ = Platform.getAdapterManager();
+
+ final String t
+ = IActionConfig.class.getName();
+
+ c = (IActionConfig) m.loadAdapter( config, t );
+ }
+
+ if( c != null )
+ {
+ c.setProjectName( this.context.getProjectName() );
+ }
+ }
+ }
+ }
+
+ super.setVisible( visible );
}
}
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPanel.java b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPanel.java
index 51b9357..14b50d2 100644
--- a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPanel.java
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/FacetsSelectionPanel.java
@@ -21,6 +21,7 @@
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
@@ -72,6 +73,7 @@
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.wst.common.project.facet.core.IActionConfig;
import org.eclipse.wst.common.project.facet.core.ICategory;
import org.eclipse.wst.common.project.facet.core.IConstraint;
import org.eclipse.wst.common.project.facet.core.IPreset;
@@ -80,6 +82,7 @@
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
+import org.eclipse.wst.common.project.facet.ui.IWizardContext;
import org.osgi.framework.Bundle;
/**
@@ -126,6 +129,8 @@
private final ComboBoxCellEditor ceditor;
private final TableViewer problemsView;
private final RuntimesPanel runtimesPanel;
+
+ private final IWizardContext context;
/**
* Contains the <code>TableRowData</code> objects representing all of the
@@ -149,11 +154,13 @@
}
public FacetsSelectionPanel( final Composite parent,
- final int style,
- final IRuntime runtime )
+ final int style,
+ final IRuntime runtime,
+ final IWizardContext context )
{
super( parent, style );
+ this.context = context;
this.data = new ArrayList();
this.fixed = new HashSet();
this.base = new HashSet();
@@ -167,7 +174,14 @@
for( Iterator itr = ProjectFacetsManager.getProjectFacets().iterator();
itr.hasNext(); )
{
- this.data.add( new TableRowData( (IProjectFacet) itr.next() ) );
+ try
+ {
+ this.data.add( new TableRowData( (IProjectFacet) itr.next() ) );
+ }
+ catch( CoreException e )
+ {
+ FacetUiPlugin.log( e );
+ }
}
// Read the dialog settings.
@@ -452,13 +466,31 @@
private static Action getAction( final Set actions,
final Action.Type type,
- final IProjectFacetVersion f )
+ final IProjectFacetVersion fv )
{
for( Iterator itr = actions.iterator(); itr.hasNext(); )
{
final Action action = (Action) itr.next();
- if( action.getType() == type && action.getProjectFacetVersion() == f )
+ if( action.getType() == type && action.getProjectFacetVersion() == fv )
+ {
+ return action;
+ }
+ }
+
+ return null;
+ }
+
+ private static Action getAction( final Set actions,
+ final Action.Type type,
+ final IProjectFacet f )
+ {
+ for( Iterator itr = actions.iterator(); itr.hasNext(); )
+ {
+ final Action action = (Action) itr.next();
+
+ if( action.getType() == type &&
+ action.getProjectFacetVersion().getProjectFacet() == f )
{
return action;
}
@@ -481,7 +513,48 @@
{
try
{
- config = fv.createActionConfig( type );
+ final IProjectFacet f = fv.getProjectFacet();
+
+ action = getAction( actions, type, f );
+
+ if( action != null )
+ {
+ final IProjectFacetVersion current
+ = action.getProjectFacetVersion();
+
+ if( fv.isSameActionConfig( type, current ) )
+ {
+ config = action.getConfig();
+
+ IActionConfig c = null;
+
+ if( config instanceof IActionConfig )
+ {
+ c = (IActionConfig) config;
+ }
+ else
+ {
+ final IAdapterManager m
+ = Platform.getAdapterManager();
+
+ final String t
+ = IActionConfig.class.getName();
+
+ c = (IActionConfig) m.loadAdapter( config, t );
+ }
+
+ if( c != null )
+ {
+ c.setVersion( fv );
+ }
+ }
+ }
+
+ if( config == null )
+ {
+ final String pjname = this.context.getProjectName();
+ config = fv.createActionConfig( type, pjname );
+ }
}
catch( CoreException e )
{
@@ -1179,6 +1252,9 @@
private boolean isFixed;
public TableRowData( final IProjectFacet f )
+
+ throws CoreException
+
{
this.f = f;
this.versions = f.getSortedVersions( false );
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/ProjectFacetsUiManagerImpl.java b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/ProjectFacetsUiManagerImpl.java
index 2c516b5..27dc7e2 100644
--- a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/ProjectFacetsUiManagerImpl.java
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/ProjectFacetsUiManagerImpl.java
@@ -17,11 +17,15 @@
import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
@@ -73,7 +77,14 @@
for( Iterator itr = clnames.iterator(); itr.hasNext(); )
{
- pages.add( create( plugin, (String) itr.next() ) );
+ try
+ {
+ pages.add( create( plugin, (String) itr.next() ) );
+ }
+ catch( CoreException e )
+ {
+ FacetUiPlugin.log( e );
+ }
}
return pages;
@@ -81,6 +92,9 @@
private Object create( final String plugin,
final String clname )
+
+ throws CoreException
+
{
final Bundle bundle = Platform.getBundle( plugin );
@@ -91,8 +105,12 @@
}
catch( Exception e )
{
- // TODO: handle this better.
- throw new RuntimeException( e );
+ final String msg
+ = NLS.bind( Resources.failedToCreate, clname );
+
+ final IStatus st = FacetUiPlugin.createErrorStatus( msg, e );
+
+ throw new CoreException( st );
}
}
@@ -125,37 +143,57 @@
{
readWizardPagesInfo( config );
}
- else
- {
- // TODO: handle this better.
- throw new IllegalStateException();
- }
}
}
}
private void readWizardPagesInfo( final IConfigurationElement config )
{
- final String name = config.getAttribute( "facet" );
+ final String id = config.getAttribute( "facet" );
- if( name == null )
+ if( id == null )
{
- // TODO: handle this better.
- throw new IllegalStateException();
+ reportMissingAttribute( config, "facet" );
+ return;
}
+
+ if( ! ProjectFacetsManager.isProjectFacetDefined( id ) )
+ {
+ final String msg
+ = NLS.bind( Resources.facetNotDefined,
+ config.getNamespace(), id );
+
+ FacetUiPlugin.log( msg );
+
+ return;
+ }
+
+ final IProjectFacet f = ProjectFacetsManager.getProjectFacet( id );
final String version = config.getAttribute( "version" );
if( version == null )
{
- // TODO: handle this better.
- throw new IllegalStateException();
+ reportMissingAttribute( config, "version" );
+ return;
}
- //TODO: Handle the case where the facet is not available.
+ if( ! f.hasVersion( version ) )
+ {
+ final String[] params
+ = new String[] { config.getNamespace(), id,
+ version };
+
+ final String msg
+ = NLS.bind( Resources.facetVersionNotDefined,
+ params );
+
+ FacetUiPlugin.log( msg );
+
+ return;
+ }
- final IProjectFacetVersion fv
- = ProjectFacetsManager.getProjectFacet( name ).getVersion( version );
+ final IProjectFacetVersion fv = f.getVersion( version );
final WizardPagesInfo info = new WizardPagesInfo();
info.plugin = config.getDeclaringExtension().getNamespace();
@@ -177,10 +215,19 @@
{
actionType = Action.Type.UNINSTALL;
}
+ else if( childName.equals( "version-change" ) )
+ {
+ actionType = Action.Type.UNINSTALL;
+ }
else
{
- // TODO: handle this better.
- throw new IllegalStateException();
+ final String msg
+ = NLS.bind( Resources.invalidActionType,
+ config.getNamespace(), childName );
+
+ FacetUiPlugin.log( msg );
+
+ return;
}
info.pagesets.put( actionType, readPageList( child ) );
@@ -205,8 +252,8 @@
if( clname == null )
{
- // TODO: handle this better.
- throw new IllegalStateException();
+ reportMissingAttribute( config, "class" );
+ continue;
}
list.add( clname );
@@ -216,10 +263,39 @@
return list;
}
+ private static void reportMissingAttribute( final IConfigurationElement el,
+ final String attribute )
+ {
+ final String[] params
+ = new String[] { el.getNamespace(), el.getName(), attribute };
+
+ final String msg = NLS.bind( Resources.missingAttribute, params );
+
+ FacetUiPlugin.log( msg );
+ }
+
private static class WizardPagesInfo
{
public String plugin;
public HashMap pagesets = new HashMap();
}
+ private static final class Resources
+
+ extends NLS
+
+ {
+ public static String missingAttribute;
+ public static String facetNotDefined;
+ public static String facetVersionNotDefined;
+ public static String failedToCreate;
+ public static String invalidActionType;
+
+ static
+ {
+ initializeMessages( ProjectFacetsUiManagerImpl.class.getName(),
+ Resources.class );
+ }
+ }
+
}
diff --git a/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/ProjectFacetsUiManagerImpl.properties b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/ProjectFacetsUiManagerImpl.properties
new file mode 100644
index 0000000..485f236
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.project.facet.ui/src/org/eclipse/wst/common/project/facet/ui/internal/ProjectFacetsUiManagerImpl.properties
@@ -0,0 +1,5 @@
+missingAttribute = An extension element <{1}> in plugin {0} is missing a required attribute {2}.
+facetNotDefined = Project facet {1} has not been defined. It's used in plugin {0}.
+facetVersionNotDefined = Version {2} of project facet {1} has not been defined. It's used in plugin {0}.
+failedToCreate = Failed to instantiate class {0}.
+invalidActionType = "{1}" is an invalid action type. It's used in plugin {0}.
\ No newline at end of file