One year later, Benoît returned to the XSLT Make project. He will introduce the changes in the Eclipse platform and set up a larger update to Eclipse to make it more closely integrated with XML. First of all, he will investigate a simple interface enhancement, users often propose such requests, support issues and task lists, but more precisely support for markers. As you will see, you need to indirectly use these lists. He will also examine the resource management of Eclipse itself, discuss the technology of writing code that can also run in the Eclipse and command line. Please in this article
Discussions Forum Share your views on this article with author and other readers. (You can also click on the top and bottom of this article
Discuss button to access the forum. )
In this new series, I will revisit an old friend using the XML column: XSLT Make or XM. It can also calculate a reason to use the Eclipse plugin. In July 2001, I am using the first project introduced in the XML column is XM. It is a tool for lightweight, low price, use XML and XSLT release documentation.
In October 2002, I decided to add a graphical user interface for the XM tool. I didn't develop the entire interface from head, but asked for an IDE: Eclipse just appeared. The reason for choosing Eclipse is because it is scalable, written in Java, and provides a magical widget library.
Revision XM, so I have the opportunity to improve Eclipse integration from two aspects: I will fix an annoying user interface restriction (herein) and rewrite the core XM engine to better integrate with Eclipse. By improvement, I will also increase Eclipse scalability and functionality. The work plan on the XM engine will be elaborated in the following two articles.
A brief history review XM has existed for some time. From my consultation experience and readers, it proves their own value in many projects. For example, I use XM as a teaching tool to manage the Web site for the customer, and publish a lot of documentation in HTML and PDF format. For an article on the project, see References.
The advantage of XM development XM is the initial reason to make the use of XML and XSLT more convenient. I need a simple and effective solution that relies on a small or medium-sized team to maintain the Web site. I know that XML and XSLT provide a good foundation, but I didn't find the right tool. Finally, I rolled up the sleeves I made such a tool. The tools that appear at the time of 2001 are not too simple (only for a single file, not the entire website), is too complex (targeted by large teams).
The XM is very powerful (I used to include a project that contains thousands of pages), but there is a simple enough to adapt to the needs of the small and medium-sized team.
XM has two most important features:
It is unpacking, no need to prepare complex scripts, and do not need to write advanced profiles. Using XM, just put the document in a directory, put the style table in another directory, ok, so you can release a document. It generates static sites and provides most of the management advantages of dynamic sites. For example, the layout of the modification site only needs to edit a style sheet.
The second point may be more likely to arouse disputes, but according to my experience, maintaining the workload of static sites smaller and efficient. Some sites need to be combined with static and dynamic web pages, but in a static manner, the maintenance site can avoid many problems: the software package used is less, thus reducing the chance of failure. In addition, because more mature buffering techniques can be used, the response speed of the site is faster. With regard to XM's unique, I suggest you read the original text (see Resources). From the perspective of XM, it has changed a lot of changes in the situation in two years. Now, a large number of open source projects can meet your needs (see Resources). I have used some of the projects, although I don't dare to say a wide range of experience, I really find that some of these projects are more powerful than XM, but there is no easy use like XM.
The Eclipse platform has also undergone fundamental changes. Now, Eclipse is one of the most eye-catching open source IDEs, with thousands of plugins. More importantly, the documentation has been updated and provides more examples. I still remember that the source code with the debugger and the debugger for a particular effect, because there is no document yet, that situation does not exist.
It is technically, the Eclipse project has developed from 2.0 to 3.0. The new API is expected to lay the foundation for a long time in the future. Fortunately, different versions are largely compatible (in fact, the XM plugins written for Eclipse 2.0 can work well in 3.0), but some changes are not backward compatible. A good way is to clean the code and use the new API as much as possible.
This series has two objectives:
Improve Eclipse integration. Although Eclipse has a complete function, there are still some roughings. I hope to be able to relieve deficiencies with eclipse resource management. Rewind the core engine. I used to use XM in many projects, and I have encountered some limitations in the design of the core engine, and I have to temporarily change the implementation. It is time to add these modifications to the project.
Eclipse resource management In the previous column articles, I have repeatedly mentioned that Eclipse is more than just an IDE. It is best to see it as a platform to build IDE. Eclipse can be attributed to a system for managing plugins. It provides services such as loading plugins, management plugins, and management plugins (through extended points) and other services.
Obviously, the services provided by some plugins are required for each application, so they can be part of the core. Part of the library SWT is one of them. Other plugins, such as XM plugins, with stronger dedication, is installed by the user when needed.
There is also a core service is resource management, which is provided by org.eclipse.core.resources plugin. For Eclipse, everything under the workspace is resources. The basic interface of the resource is IResource (very clear). The most common future generations have IFILE, IFOLDER, and iProject, represent files, folders, and projects, respectively.
Although there is a certain relationship, the File object in IResource and JDK is actually two yards. JDK File represents a record in the file system, and Eclipse IResource adds several layers of abstraction on the file system. First, resources have properties, attribute represents information about resources, help plug-in processing resources. For example, the plugin can buffer the content of the XML-STYLESHEET?> Processing instruction as an attribute. At the same time, buffer the data in the properties, which avoids the parsing files every time the plugin is run. Properties can be stored in memory (lost when the user exits the editor) or lasts for a file system. In addition, the resources and file systems are no longer synchronized when adding, deleting or editing resources. IResource records the status of the resource and provides a way to synchronize with the file system. More importantly, Eclipse can notify the plugin resource and file system changes. When the resource is synchronized with the file system, Eclipse will pass a Delta, which is a change list after the last synchronization. Obviously, this will be able to build intelligence, which means recompilation only for the modified resource.
The mark and task list look at the user's point of view, Eclipse supports two questions: XM has its own project rebuild logic and error report logic. In the end, these two problems are characterized by XM ignore the resource management of Eclipse.
I am going to discuss the construction process in the latter two articles in this series, and now I will now solve the problem of misunderstanding.
The mark Eclipse provides a task list and a list of tasks and compilers to report errors, as shown in Figure 1. When the user doubles the error items, the editor opens a problem with the problem. Unfortunately, when writing the first version of the XM plugin, I didn't find a document that added a list item, so I ignored it. As a result, the plugin has its own console, but does not support double-click.
Figure 1. List of tasks and issues
Finally, it is not difficult to add a message to the standard list, but it cannot be added directly. At first, I tried to find a task list object, but did not find the way to add a list item. Finally, it is found that the list item cannot be added or at least not directly. To add an error message, you need to create a mark (interface iMarker) on the resource. Remove a message from the list, you have to remove the mark from the resource. The list will automatically update changes in the translation mark.
CreateMarker () method is used to create a mark. The method is used as a parameter in a marker ID. A number of standard marks IDs are defined in the platform:
Org.eclipse.core.Resources.marker - The root of the mark hierarchy. Org.eclipse.core.Resources.problemmarker - Indicates a problem or error message, appears in the list of questions. Org.eclipse.core.Resources.TaskMarker - Indicates that the work is appeared in the task list. Org.eclipse.core.Resources.bookmark - Indicates files, such as search results. Org.eclipse.core.Resources.TextMarker - Indicates the location of the file, such as an error location.
Define the plug-in sign is a good choice. The ID of the new marker is redefined in the plugin.xml file (like other declarations in Eclipse). Listing 1 shows a marker statement that defines an extension of the marker ID (org.eclipse.core.resources.markers). It also declares a new marker that inherits from Problemmarker from Problemmarker and TextMarker inheritance. Declaring the marker as a lasting thing to save these marks between the sessions. Listing 1. Remarks declaration
Name = "xm message" Point = "Org.eclipse.core.Resources.Markers"> extension> Users can filter messages according to different conditions, such as the type of problem (warning, error), priority, and marker ID. Define the plug-in logo to help users apply specialized filtering rules for plug-in messages. WARNING: Eclipse is likely to filter out the plugin message. If you don't see any message of XM, you should look at these messages is filtered. To change the filter, click the filter icon in the task list or problem list, you must select the XM mark. It is not difficult to integrate into the XM after understanding the tricks. From the beginning, the user interface is abstracted through the Messenger interface. Messenger defines how the core needs to report errors or process information. To support the method list, you only need to write a new Messager implementation to create an appropriate mark, as shown in Listing 2. Note that the Begin () method will delete all the marks to clear the list of questions before building. Listing 2. Messenger implementation of the marker Package org.anas.xm.eclipse; Import java.text.MessageFormat; Import org.eclipse.ui.iworkbench; Import org.anas.xm.core.filename; Import org.anas.xm.core.location; Import org.anas.xm.core.Messenger; Import org.eclipse.ui.iworkbenchpage; Import org.anas.xm.core.xmexception; Import org.eclipse.swt.widgets.display; Import org.eclipse.ui.iworkbenchwindow; Import org.eclipse.core.resources.imarker; Import org.eclipse.core.resources.iproject; Import Org.eclipse.core.Resources.IResource; Import org.eclipse.core.runtime.coreexception; Import org.eclipse.ui.views.markers.MarkerViewUti1; Public Class Messengertasklist Implements Messenger, EclipseConstants { Private iProject Project = NULL; Private iWorkbench Workbench = NULL; Private boolean nomarkersofar = true; Private Static Class ShowmarkerView Implements Runnable { Private iWorkbench Workbench; Private IMARKER MARKER; Public SHOWMARKERVIEW (iWorkbench Workbench, IMARKER MARKER) { THIS.WORKBENCH = WORKBENCH; THIS.MARKER = Marker; } Public void Run () { IWorkbenchWindow Window = Workbench.GetActiveWorkBenchWindow (); IF (window == null) { IWorkbenchWindow [] Windows = Workbench.getWorkbenchWindows (); IF (Windows! = Null && Windows.Length> 0) Window = windows [0]; Else Return; } IWorkbenchPage Page = window.getActivePage (); IF (Page! = NULL) MarkerViewUtil.Showmarker (Page, Marker, True); } } Public Messengertasklist (iWorkbench Workbench, iProject Project) { IF (NULL == Project || null == Workbench) Throw New NullPointerexception ("Null Argument In TasklistMessenger Constructor"); This.Project = Project; THIS.WORKBENCH = WORKBENCH; } Protected Void AddMarker (String Msg, Location Location, Int Severity, Int Priority) Throws XMexception { IResource resource = null; IF (null == location || location.equals (location.unknown)) Resource = Project; Else Resource = (IResource) location.getFileName (). AsPlatformSpecific (); Try { IMARKER MARKER = Resource.createMarker (Marker_ID); IF (null! = location && location.unknown_position! = location.getLine ()) Marker.setttribute (IMARKER.LINE_NUMBER, LOCATION.GETLINE ()); IF (NULL! = MSG) Marker.SetAttribute (IMARKER.MESSAGE, MSG); Marker.SetaTRibute (IMARKER.SEVERITY, SEVERITY); Marker.SetaTribute (IMARKER.PRIORITY, PRIORITY); if (Nomarkersofar) ShowMarkerView (Marker); Else Nomarkersofar = false; } Catch (CoreException E) { Throw new xmexception (e, location); } } Public void error (xmexception x) Throws XMexception { AddMarker (x.getMessage (), X.getLocation (), iMarker.severity_rror, iMarker.Priority_NORMAL); } Public void fatal (xmexception x) Throws XMexception { AddMarker (x.getMessage (), X.getLocation (), IMARKER.SEVERITY_ERROR, IMARKER.PRIORITY_HIGH; } Public void Warning (XMException X) Throws XMexception { AddMarker (x.getMessage (), X.getLocation (), IMARKER.SEVERITY_WARNING, IMARKER.PRIORITY_LOW; } Public Boolean Progress (Filename Sourcefile, FileName Resultfile) { Return True; } Public void info (String MSG, Location location) Throws XMexception { AddMarker (MSG, Location, IMARKER.SEVERITY_INFO, IMARKER.PRIORITY_NORMAL); } Public void info (String Pattern, Object [] arguments, location location Throws XMexception { INFO (Pattern, Arguments), Location; } Public void Begin (String Source, String Target) Throws XMexception { Try { Project.deleteMarkers (Marker_ID, True, IResource.Depth_infinite); Nomarkersofar = true; } Catch (CoreException E) { Throw new XMEXCEPTION (E); } } Public void end () { } Protected Void ShowmarView (IMARKER MARKER) { Display display = display.getcurrent (); IF (Display == Null) Display = display.getDefault (); ShowmarkerView ShowmarView = New ShowmarkerView (Workbench, Marker); Display.Syncexec (ShowmarkerView); } } Further abstract XM has been organized around these two components: core, independent of Eclipse and provides command line interfaces; Eclipse plugins. To port XM to other interfaces, you only need to abstract user interface as a Messenger (see the previous section). I used to define the servlet user interface on Eclipse for some projects. Although I plan to further strengthen the integration of XM and Eclipse, but also want to keep the command line option. The two interfaces have their own use. For day-to-day operations, I am using the Eclipse environment, but the command line version is very convenient for crontab (a UNIX tool for planning work). In order to support both ways, I abstract the resources and files in the XM core engine. The initial XM uses the JDK file object, and you will see that it is the root of most integration issues, and Eclipse does not use the File object. Instead, it uses its own IResource interface. In addition, experience tells me that it is very limited in File. Eclipse is not the only package without files, SAX uses inputsource, while JAXP uses Source. What should I do if the code needs to interact with several different libraries? You can use the proxy mode (see Resources) to abstract individual libraries. In the proxy mode, a universal interface is provided by a library of a (or more) objects as the underlying library. This object can be instantiated and forward the request to any library. The advantage of using this model is that there is no need to worry about the library to be forwarded when calling the code. The XM introduces the FileName interface to abstract files or resources concept. FileName has been implemented on Eclipse IResource (for use within Eclipse) and JDK File objects (in order to use in the command line). Listing 3 is a declaration of FileName. Eclipse dedicated version provides source code (see Resources). Listing 3. Abstraction of files and resources Package org.anas.xm.core; Import java.io.file; Import org.xml.sax.inputsource; Import org.anas.xm.core.xmexception; Public interface filename Extends CoreConstants { Public boolean isroot () Throws xmexception; Public boolean isfile (); Public Boolean IsFolder () Throws xmexception; Public Boolean EXISTS () Throws xmexception; Public string getName () Throws xmexception; Public String getshtename () Throws xmexception; Public String getsuffix () Throws xmexception; Public string getProjectPath () Throws xmexception; Public filename getParent () Throws xmexception; Public filename [] getChildren () Throws xmexception; Public void setPersistentMetadata (String Key, String Value) Throws xmexception; Public void setPersistentMetadata (String Key, String [] Values) throws XMexception; Public void setTransientMetadata (String Key, Object Value) Throws xmexception; Public Object Getmetata (String Key) Throws xmexception; Public String GetMetadataSString (String Key) THROWS XMEXCEPTION, CLASSCASTEXCEPTION; Public string [] GetMetadataASAASARRAY (STRING Key) THROWS XMEXCEPTION, CLASSCASTEXCEPTION; Public file asfile () Throws xmexception; Public InputSource AsinputSource () Throws xmexception; Public Object AsPlatformSpecific () Throws xmexception; Public Boolean Hassamepath (filename document) Throws xmexception; Public Boolean Isdescendantof (Filename Document) Throws xmexception; Public Boolean Remove () Throws xmexception; } All classes in the XM core (such as Messenger) have been rewritten using FILENAME. In the two years, Eclipse has become the actual standard open source IDE of the Java platform, so that Eclipse supports the support of XM. One of the benefits of using Eclipse is that you can make existing more documents to make the write plugin easier. While praising Eclipse, I still believe that the core of the abstract plug-in is worth it. For XM, I chose abstract user interface and resource management. In the next article, I will start discussing another major problem with the XM user interface: Eclipse builds. forward from