| Eclipse 3.1 - Plan item |
This is the plan item:
"The Eclipse Platform supports a strong physical view of projects, files, and folders in the workspace. However, there are many situations where a physical view is not the most salient or useful for many purposes. In some cases, multiple distinct objects happen to be stored in a single file, like an archive. Conversely, in other cases, something that is logically a single object is stored across multiple files. This discrepancy between logical and physical creates problems for common operations such as searching, comparing, and versioning, which need to work in the physical realm. Eclipse should support some way of mapping between a logical view and the physical organization of files on disk."
Last Modified: August 12th, 2004
By definition Eclipse supports logical resources. It's a "an open extensible IDE for anything and nothing in particular". The applications that are built with it can be tailored to a particular problem domain and the workbench extensions can be used to provide support for the logical model. What Eclipse really doesn't support is integrating tools at the logical model level. It's simple: to integrate two plugins in Eclipse either one plugin must know about the other (through a plugin reference), or both plugins must depend on some common plugin. While the first option is satisfactory for a few cases, the second case is the most common and the most problematic. To illustrate, consider the Eclipse SDK itself. In the SDK, the Resources plugin acts as the common plugin that other plugins use as a point of intergration (e.g. Team, Search, Compare, JDT). Thus, the common model between these plugins is the resource model defined by the Resources plugin.This model is basically the same as the physical file system model and does not provide integration for any other logical models.
As you will see later, even the users of the SDK (JDT+CVS+Resources) can observe some of the problems associated with the lack of support for logical resources and the implicit mapping to physical resources. The lack of a logical integration point causes the co-existance of plugins in Eclipse to be error prone for the user. The next sections will examine the relationships between logical and physical resources and outline the visible problems with Eclipse 2.1.
Bug 32582
logical to physical mapping problem , 1 model element = 2 Files problem
Bug 3979 [CVS
Decorator] show version info works incorrectly for sub packages (1GFDIEB)
Whereas logical resources are elements of the application that model the data/processes of a particular problem domain, the physical resources are the file system resources (e.g. files and folders) into which an application will eventually transform their application model for storage. Applications that don't use file system resources are not being considered as part of this plan item. For example, an application that stores it's application data directly into a database.
The following table enumerates concrete examples of how logical and physical resources are used in current applications integrated into Eclipse.
Table 1: Example logical to physical uses
Object contributions and decorators are key mechanisms for providing rich integration between tools. Using object contributions and adaptable objects, any plugin can provide actions and decorators that will show in another plugin's view.
Since IResource is the lowest common integration class and is strongly mapped to its physical storage as files and folders, the integration point for actions and decorators cannot be the logical types in the view. The actions will consequently use the adaptable type from the selection to perform the action or the decorator the resource from the getImage request.
Here is an example to illustrate the problem with the CVS plugin. When running a CVS commit action in the packages view the action doesn't know that the IFolder is a Java package and is a shallow namespace. It will use the selection and traverse the selected IContainer using IContainer.members() and commit all child resources. This is the same when the CVS outgoing decorator is shown on a package. It will reflect the deep outgoing state of the IContainer. This can lead to unexpected behavior because the user expected the action to run on the model that the action was displayed on.
Example object contribution for the CVS commit action:
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
objectClass="org.eclipse.core.resources.IResource"
adaptable="true"
id="org.eclipse.team.ccvs.ui.IResourceContributions">
<filter
name="projectPersistentProperty"
value="org.eclipse.team.core.repository=org.eclipse.team.cvs.core.cvsnature">
</filter>
<action
label="Commit"
tooltip="Commit resource to CVS repository"
class="org.eclipse.team.internal.ccvs.ui.actions.CommitAction"
menubarPath="team.main/group3"
id="org.eclipse.team.ccvs.ui.commit">
</action> <objectContribution> </extension>
Example code run in the commit action to calculate the resources to commit:
public static Object[] getSelectedAdaptables(ISelection selection) {
ArrayList result = null;
if (!selection.isEmpty()) {
result = new ArrayList();
Iterator elements = ((IStructuredSelection) selection).iterator();
while (elements.hasNext()) {
Object adapter = getAdapter(elements.next(), IResource.class);
if (c.isInstance(adapter)) {
result.add(adapter);
}
}
}
if (result != null && !result.isEmpty()) {
return (Object[])result.toArray((Object[])Array.newInstance(IResource.class, result.size()));
}
return (Object[])Array.newInstance(IResource.class, 0);
}
Example code for defining an IResource adaptable decorator:
<extension
point="org.eclipse.ui.decorators">
<decorator objectClass="org.eclipse.core.resources.IResource"
adaptable="true"
label="%DecoratorStandard.name"
state="false"
lightweight= "true"
quadrant = "BOTTOM_RIGHT"
class="org.eclipse.team.internal.ccvs.ui.CVSLightweightDecorator"
id="org.eclipse.team.cvs.ui.decorator">
<description>
%DecoratorStandard.desc
</description>
</decorator>
</extension>
When the CVS decorator decorates a logical container in a view, the desire is to decorate parents with the dirty indicator if one or more of their logical children are dirty. To do this properly, the decorator would need to query the dirty status of each of the logical children of the container. This can be a costly operation as each child may itself be a logical container. We have optimized the dirty decoration by caching folder dirty states. This optimization becomes far more complicated with logical models where the caching must be based on this alternate model (i.e. the state must be cached for each model).
In addition, often decorators rely on IResource change events to re-calculate some new state. In the case of a logical elements representing several physical resources there is no easy way of associated a IResource change event to its files and the actual logical element.
It would be nice to see the Java logical view in the Synchronize view or the CVS Repositories View. However, the entries in these views may not be IResources so an IResource independent mapping mechanism would be required. This could be a considerable amount if work for anyone providing a logical model. This problem is partly being addressed by the introduction of customizable content providers as described in the Generic Navigator item.
Also if an action prompts the user, for example to add resources to CVS, what icons and labels are used in the dialog? It would be nice to show those that are most familiar to the user.
Consider a user's action as a logical change, for example, the user renames a class using the JDT refactoring action. In the user's mind he 'renamed a class' and as a result there has been many other file changes. Currently there is not way of capturing these logical actions and associating the set of affected resources. This problem manifests itself more in tools where almost every change to the model has side effects.
Some tools that integrate into Eclipse are file based and don't use IResources. And thus wouldn't be able to operation logical elements.
There are basically two approaches to solving the problems discussed above:
At the present time, the second approach, by itself, is not viable due to its complexity. There is a JSR (JSR 147) that defines such an ineterface but it is not yet finalized and there is not timetable for when it will be. However, to do the first approach properly will require some repository provider API. This is discussed in the following section which propese a solution.
In this section, we propose a soluton that is centered on API for traversing logical model elements with a minimal amout of repository provider API.
One possible solution is to introduce a logical model element API that can
be the basis for integration between plugins. This solution attempts to solve
the most common uses described in Table1, namely examples
1a, 1b and 3a. The generic
navigator plan item should address the 2b and 3b
examples by providing extensions that would allow a logical model to be available
to other plugins for display purposes. Finally, 2a is currently
solved with the existing IResource adapter mechanism.
Naturally another possible solution would be to change IResource
to not be analogous to file system resources. However this scope of change is
beyond the 3.0 timeframe and would cause, in my opinion, non-justifiable breaking
changes to all plugins.
This solution involves adding an interface to the Resources plugin that maps logical elements to physical ones. The interface is purposely simple with logical model manipulations ommitted. A client can't use this interface to display logical models or gain any interesting additional knowledge about it. In fact, the only way that a plugin will be able to gain access to the model for those purposes, would be via the navigator extensions proposed in the generic nagivator plan item.
Current plugins that add object contributions to IResource (CVS,
Search, Compare) would have to also add them to IModelElement and
honour the biddings provided by the logical resource. Moreover, the plugins
that adapted to IResource to these object contributions shown in
the context menu should no longer adapt the IResource and instead
implement IModelElement (this could be simplified by adding a tag
to the objectConribution XML that indicates that it can be used with IResource
or IModelElement).
/**
* This interface defines an element of an application that models the
* data/processes of a particular problem domain. This purpose of this interface
* is to support the transformation of the application model into its underlying
* file system resources for the purposes of reconciling the model with versions
* of the model stored in a repository. Hence, this interface provides the
* bridge between a logical element and the physical resource(s) into which it
* is stored but does not provide more comprehensive model access or
* manipulations.
*
* @see IResource
*/
public interface IModelElement {
/**
* Returns the project which contains this model element. This is a resource
* handle operation; neither the element nor the resulting project need
* exist. Model elements may not span multiple projects. In other words, all
* physical resources that constitute a logical resource are located in the
* same project.
*
* @return the project handle
*/
public IProject getProject();
/**
* Returns one or more traversals that can be used to access all the
* physical resources that constitute the logical resource. A traversal is
* simply a set of resources and the depth to which they are to be
* traversed. This method returns an array of traversals in order to provide
* flexibility in describing the traversals that constitute a model element.
* A depth is included to allow the clients of this interface (most likely
* repository providers) an opportunity to optimize the operation and also
* ensure that resources that were or have become members of the model
* element are included in the operation.
*
* Implementors of this interface should ensure, as much as possible, that
* all resources that are or may be members of the model element are
* included. For instance, a model element should return the same list of
* resources regardless of the existance of the files on the file system.
* For example, if a logical resource called "form" maps to "/p1/form.xml"
* and "/p1/form.java" then whether form.xml or form.java existed, they
* should be returned by this method.
*
* In some cases, it may not be possible for a model element to know all the
* resources that may consitite the element without accessing the state of
* the model element in another location (e.g. a repository). This method is
* provided with a context which, when provided, gives access to
* the members of correcponding remote containers and the contenst of
* corresponding remote files. This gives the model element the opportunity
* to deduce what additional resources should be included in the traversal.
*
* @param context gives access to the state of
* remote resources that correspond to local resources for the
* purpose of determining traversals that adequately cover the
* model element resources given the state of the model element
* in another location. A null may be provided, in
* which case the implementor can assume that only the local
* resources are of interest to the client.
* @param monitor a progress monitor
* @return a set of traversals that cover the resources that constitute the
* model element
*/
public ITraversal[] getTraversals(IModelContext context,
IProgressMonitor monitor) throws CoreException;
}
A logical model element can be made up of one or more traversals that define the physical resources that make up the model element. Traversals are used to allow the clients of the traversal to optimize their operations based on the depth of the resources being traversed.
/**
* A model element traversal is simply a set of resources and
* the depth to which each are to be traversed. A set of traversals
* is used to describe the resources that constitute a model element.
*
* @see org.eclipse.core.resources.IResource
* @see org.eclipse.core.resources.model.IModelElement
*/
public interface ITraversal {
/**
* Returns the project which contains the resources that
* make up this taversal.
*
* @return the project handle
*/
public IProject getProject();
/**
* Returns the file system resource(s) for this traversal.
* The returned resources must be contained within the same project
* and need not exist in the local file system.
*
* The traversal of the returned resources should be done considering
* the flag returned by getDepth. If a resource returned by a
* traversal is a file, it should always be visited. If a resource of a traversal
* is a folder then files contained in the folder can only be visited if the folder is
* IResource.DEPTH_ONE or IResource.DEPTH_INFINITE.
* Child folders should only be visited if the depth is IResource.DEPTH_INFINITE.
*/
public IResource[] getResources();
/**
* Return the depth to which the resources should be traversed.
* @return the depth to which the physical resources are to be traversed
* (one of IResource.DEPTH_ZERO, IResource.DEPTH_ONE or IResource.DEPTH_INFINITE)
*/
public int getDepth();
}
For some model elements, simple traversals can be used to describe the element. For instance, here is an example traversal that represents a Java package.
/**
* An example traversal for a Java package
*/
public class JavaPackageTraversal implements ITraversal {
IContainer javaPackage;
public JavaPackageTraversal(IContainer javaPackage) {
this.javaPackage = javaPackage;
}
public IProject getProject() {
return javaPackage.getProject();
}
public IResource[] getResources() {
return new IResource[] { javaPackage };
}
public int getDepth() {
return IResource.DEPTH_ONE;
}
}
The next example class shows a traversal for a fixed set of files. The chosen example is for the data files that define the properties of a plugin in Eclipse. The same files are always returned even if they don't exist locally. It is up to the client of the interface in this case to decide how to handle the files that don't exist locally. If the client is a repository and the operation is an update to fetch the latest contents from the server, then the repository provider would fetch the files from the server if they now esist there or ignore them if they don't exist either locally or remotely.
/**
* An example of a fixed traversal that always includes
* a certain set of files even if they don't exist
* locally
*/
public class PluginDataTraversal implements ITraversal {
IProject pluginProject;
public PluginDataTraversal(IProject project) {
this.pluginProject = project;
}
public IProject getProject() {
return pluginProject;
}
public IResource[] getResources() {
return new IResource[] {
pluginProject.getFile(new Path("plugin.xml")),
pluginProject.getFile(new Path("plugin.properties")),
pluginProject.getFile(new Path("build.properties")),
pluginProject.getFile(new Path("META-INF/MANIFEST.MF"))
};
}
public int getDepth() {
return IResource.DEPTH_ZERO;
}
}
Assuming that the plugin data consists of the above mentioned files and the contents of the schema directory, the mdel element class for a plugin's data model could be the following:
/**
* A plugin model element
*/
public class PluginModel implements IModelElement {
IProject pluginProject;
public IProject getProject() {
return pluginProject;
}
public ITraversal[] getTraversals(ITraversalContext context,
IProgressMonitor monitor) throws CoreException {
return new ITraversal[] {
new PluginDataTraversal(pluginProject),
new ITraversal() {
public IProject getProject() {
return pluginProject;
}
public IResource[] getResources() {
return new IResource[] {
pluginProject.getFolder("schema")
};
}
// Traverse the folder deeply to include all children
public int getDepth() {
return IResource.DEPTH_INFINITE;
}
}
};
}
}
One of the advantages of a logical model traversal API is that it allows the repository provider to implement any operations they desire in terms of logical resources (e.g. update, commit, tag, dirty decoration, etc.). However, the context of the operation may imply that resources that don't exist locally should be included in the operation. This is not a problem for some logical models. For instance, a java package is a container visited to a depth of one. Also, the plugin example knows all the files that vould potentially be involved, even if they don't exist locally. Given this, a repository provider can easily determine that outgoing deletions should be included when committing or that incoming additions should be included when updating.
However, properly determining the set of traversals that adequately cover a model element gets more complicated if the resources that constitute the element depend of the contents of a manifest file (or some other similar mechanism) and may change over time. In this case, it is possible that the model element could access the contents of the manifest file as contained in the remote location. Given this ability, the model element provider is provided with enough context about the operation to the logical model element so a set of traversal can be returned that adequately cover all resources that constitute the model element.
This has led to the definition of the following IModelContext
interface.
/**
* A model context provides a model element with a view of the remote state
* of a local resource as it relates to a repository operation that is in
* progress. A repository provider can pass an instance of this interface to a
* model element when obtaining a set of traversals for a model element. This
* allows the model element to query the remote state of a resource in order to
* determine if there are resources that exist remotely but do not exist locally
* that should be included in the traversal.
*/
public interface IModelContext {
/**
* Return whether the contents of the corresponding remote differs from the
* content of the local file. This can be used by clients to determine if
* they nee to fetch the remote contents in order to determine if the
* resources that constitute the model element are different in another
* location.
*
* @param file the local file
* @param monitor a progress monitor
* @return whether the contents of the corresponding remote differs from the
* content of the local file
* @throws CoreException if this method fails. Reasons include:
* - The corresponding remote resource does not exist (status
* code will be IResourceStatus.REMOTE_DOES_NOT_EXIST).
* - The corresponding remote resource is not a container
* (status code will be IResourceStatus.REMOTE_WRONG_TYPE).
* - The server communications failed (status code will be
* IResourceStatus.REMOTE_COMMUNICATION_FAILURE).
*/
public boolean contentDiffers(IFile file, IProgressMonitor monitor)
throws CoreException;
/**
* Returns an instance of IStorage in order to allow the
* caller to access the contents of the remote that corresponds to the given
* local resource. The provided local file handle need not exist locally. A
* exception is thrown if the corresponding remote resource does not exist
* or is not a file.
*
* This method may be long running as a server may need to be contacted to
* obtain the contents of the file.
*
* @param file the local file
* @param monitor a progress monitor
* @return a storage that provides access to the contents of the local
* resource's corresponding remote resource
* @throws CoreException if this method fails. Reasons include:
* - The corresponding remote resource does not exist (status
* code will beIResourceStatus.REMOTE_DOES_NOT_EXIST).
* - The corresponding remote resource is not a file (status
* code will be IResourceStatus.REMOTE_WRONG_TYPE).
* - The server communications failed (status code will be
* IResourceStatus.REMOTE_COMMUNICATION_FAILURE).
*/
public IStorage fetchContents(IFile file, IProgressMonitor monitor)
throws CoreException;
/**
* Returns the list of member resources whose corresponding remote resources
* are members of the corresponding remote resource of the given local
* container. The container need not exist locally and the result may
* include entries that do not exist locally and may not include all local
* children. An empty list is returned if the remote resource which
* corresponds to the container is empty. An exception is thrown if the
* corresponding remote does not exist or is not capable of having members.
*
* This method may be long running as a server may need to be contacted to
* obtain the members of the containers corresponding remote resource.
*
* @param container the local container
* @param monitor a progress monitor
* @return a list of member resources whose corresponding remote resources
* are members of the remote counterpart of the given container
* @throws CoreException if this method fails. Reasons include:
* - The corresponding remote resource does not exist (status
* code will be IResourceStatus.REMOTE_DOES_NOT_EXIST).
* - The corresponding remote resource is not a container
* (status code will be IResourceStatus.REMOTE_WRONG_TYPE).
* - The server communications failed (status code will be
* IResourceStatus.REMOTE_COMMUNICATION_FAILURE).
*/
public IResource[] fetchMembers(IContainer container,
IProgressMonitor monitor) throws CoreException;
}
Although this can be thought of as a repository provider API, it bypasses the complexity by allowing the repository provider to implement the interface in a maner specific to the operation being performed. For instance, for a commit, the repository provider would provide the contents of files that define the base of a manifest file. In other words, the contents of the file would match the contents before the user modified the model element. This would allow for the inclusion of any outgoing deletions. For an update, the repository provider would provide access to the contents of the file in the repository.
This section is devided into two sections. Client isses which indicate what isses the implementators of the above mentioned interfaces face, and Eclipse Platform issues that will need to be addressed when and if the solution is implemented.
There are uncertainties for this solution:
Either of these efforts may be non-trivial depending on the structure and functionality of the repository provider's or model provider's Eclispse intergration.
The following issues would need to be addressed for this solutions
IResource and ILogicalResource.
ILogicalResource that is done for IResourceOne aspect that is not covered by logic element traversal but is related to repository operations is the ability to synchronize, compare and merge model elements at the model level as opposed to the file system resource level.
The Synchronize view in Eclipse 3.0 supports an infrastructure for choosing the presentation that is used by the view. However, the types of presentations are limited and are resource based. It is possible, however, to allow the presentation to be determined by the provider of a logical model. Here is a summary of what this would involve:
IModelElement that could
be used by the repository provider to determine the state of the sync element
and the resources to be considered when performing an operation. The repository
provider would make use of an IModelContext to obtain the remote
version of the model element (and a different context to determine the base
for a 3-way compare).This is fairly straightforward given the current structure of the synchronze view (and assuming that the logical model traversal API is in place).
Just as the logical model provider would be responsible for providing the content provider to be used in the Synchronize view, they would also be reponsible for providing a compare editor that is suitable for comparing and merging a model elements. Input to the compare editor would be the model elements involved and the model contexts for the remote and the base (for a 3-way compare). The logical model provider would be responsible fro generating, comparing and merging the model changes into the local copy of the model.
Another input to the compare editor could be a set of actions so that , for instance, during an update that involves conflicting changes, a "done" action could be provided by the repository provider to indicate that a merge is complete and the local resources should no longer be considered conflicts.
Here are some of the issues for the synchronize view and compare editors: