Eclipse resource management. Outline Introduction Basic resource management Further resource management.

Slides:



Advertisements
Similar presentations
Object orientation and persistent objects Dragos Chirila Finsiel Romania Copenhagen, 24 May 2004.
Advertisements

Java Card Technology Ch04: Java Card Object
Written by: Dr. JJ Shepherd
Goals Give you a feeling of what Eclipse is.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Eclipse resource management. Outline Introduction Basic resource management Further resource management.
1 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference l Parameter passing org.eclipse.core.resources.
Preferences in Eclipse 3.0 Present by Kun-Tse Wu.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 7: Advanced File System Management.
Why Do We Need Files? Must store large amounts of data. Information stored must survive the termination of the process using it - that is, be persistent.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of Creating Eclipse plug-ins.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 7: Advanced File System Management.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, VUW Indexing Large Data COMP
Classes and objects Practice 2. Basic terms  Classifier is an element of the model, which specifies some general features for a set of objects. Features.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 7: Advanced File System Management.
Programming Languages and Paradigms Object-Oriented Programming.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Java File Structure.  File class which is defined by java.io does not operate on streams  deals directly with files and the file system  File class.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 7: Advanced File System Management.
Parsley Introduction Kui Huang Oct. 13, Topics Background Dependency Injection Object Lifecycle Message Bus Sample FW Extensions.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Introduction to Eclipse Plug-in Development. Who am I? Scott Kellicker Java, C++, JNI, Eclipse.
Chapter 8 Cookies And Security JavaScript, Third Edition.
The Java Programming Language
TOOLS FOR DESIGN AND DEVELOPMENT ENVIRONMENTS. Case study - ECLIPSE Lecture notes 1.
File Systems (1). Readings r Reading: Disks, disk scheduling (3.7 of textbook; “How Stuff Works”) r Reading: File System Implementation ( of textbook)
BlackBerry Persistent Storage Models Persistent Storage APIs and Record Management System.
1 Chapter 17 Object-Oriented Data Structures. 2 Objectives F To describe what a data structure is (§17.1). F To explain the limitations of arrays (§17.1).
1 Chapter 12: Form Builder Objects and Flexible Code.
ABC of Platform Workspace | Copyright © IBM Corp., All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder.
ABC of Platform Workspace | Copyright © IBM Corp., ABC of Platform Workspace Szymon Brandys Tomasz Zarna IBM Krakow Software Lab.
Selena Extension Christian Brand Eckart Langhuth Matthias Metzler
MCSE Guide to Microsoft Exchange Server 2003 Administration Chapter Five Managing Addresses.
Introduction to Java Beans CIS 421 Web-based Java Programming.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Server-Side Java Mapping Copyright © ZeroC, Inc. Ice Programming with Java 6. Server-Side Java Mapping.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
The Prototype Pattern (Creational) ©SoftMoore ConsultingSlide 1.
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally FILE SYSTEM.
Extending Eclipse General concepts and Project related APIs Yearly project, Winter 05/06 The Technion.
The Memento Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
File Systems May 12, 2000 Instructor: Gary Kimura.
Interstage BPM v11.2 1Copyright © 2010 FUJITSU LIMITED INTERSTAGE BPM API DEVELOPMENT.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 7: Advanced File System Management.
3 Introduction to Classes and Objects.
Goals Give you a feeling of what Eclipse is.
University of Central Florida COP 3330 Object Oriented Programming
18 Files and Streams.
Pre-assessment Questions
University of Central Florida COP 3330 Object Oriented Programming
Programming Language Concepts (CIS 635)
Creating and Modifying Text part 2
Chapter 17 Object-Oriented Data Structures
Operation System Program 4
Java Methods Stacks and Queues A & AB Object-Oriented Programming
null, true, and false are also reserved.
Eclipse Plug-in Development
Eclipse Plug-in Development
Introduction to Data Structure
CIS 199 Final Review.
File System Management
Plug-In Architecture Pattern
Presentation transcript:

Eclipse resource management

Outline Introduction Basic resource management Further resource management

Introduction Package org.eclipse.core.resources Define the notions of workspaces and resources Provides basic support for managing a workspace and its resources for resource plug- in Resource retrieve, create, delete, move..Etc. Tracking resource lifecycle changes Similar to a file system

Basic resource management Resource and the workspace Resource and the local file system Resource properties

Resource and the workspace Workspace : central hub of user ’ s file Plug-in use resource API to create, navigate, manipulate resource in the workspace Three kinds of resource Project Folder file

Resources (I) Project Collection of folders and files Organize resources related to specific projects Interface IProject Folder Contains other folder and files Like directory in file system Interface IFolder

Resource (II) File Arbitrary sequence of bytes Interface IFile Interface Iworkspace Interface IResource

Resource organization Tree structure Project at top Folder and file underneath Workspace root

Resource and file system When resource plug-in is activate, the workspace is represented by an instance of IWorkspace The IWorkspace instance represent all files and directories in file system Get the IWorkspace instance : ResourcePlugin.getWorkspace();

Manipulate resource First get the IWorkspaceRoot instance, which represents the root of the resource tree in the workspace Access projects in the workspace Access folders and files in projects Access files in folders Similar to java.io.File

Get and open project IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject myWebProject = myWorkspaceRoot.getProject("MyWeb"); // open if necessary if (myWebProject.exists() && !myWebProject.isOpen()) myWebProject.open(null);

Get folder, create file IFolder imagesFolder = myWebProject.getFolder("images"); if (imagesFolder.exists()) { // create a new file IFile newLogo = imagesFolder.getFile("newLogo.gif"); FileInputStream fileStream = new FileInputStream( "c:/MyOtherData/newLogo.gif"); newLogo.create(fileStream, false, null); // create closes the file stream, so no worries. }

File copy IFile logo = imagesFolder.getFile("logo.gif"); if (logo.exists()) { IPath newLogoPath = new Path("newLogo.gif"); logo.copy(newLogoPath, false, null); IFile newLogo = imagesFolder.getFile("newLogo.gif");... }

File move IFolder newImagesFolder = myWebProject.getFolder("newimages"); newImagesFolder.create(false, true, null); IPath renamedPath = newImagesFolder.getFullPath().append("renamedLogo.gif"); newLogo.move(renamedPath, false, null); IFile renamedLogo = newImagesFolder.getFile("renamedLogo.gif");

Resource and real file location Use IResource.getLocation() to get the full system path of a resource Use IProjectDescription.setLocation() to change a project location Get a resource via a file system path IWorkspaceRoot.getFileForLocation() IWorkspaceRoot.getContainerForLocation()

Resource properties Session properties Cache information in key-value pair in memory Lost when a resource is deleted or the project or workspace is closed Persistent properties Store resource-specific information on disk Store with system metadata and maintained across platform shutdown and restart

Used Interface and class Class ResourcePlugin The plug-in run-time class The start point for resource manipulation Interface IWorkspace Represent the workspace in the platform Interface IResource The resource in the workspace Superinterface of IFile, IFolder, IProject, IWorkspaceRoot

Used interface and class Interface IFile, IFolder, IProject, IWorkspaceRoot System resource instance Provide manipulation methods of resources Interface IProjectDescription Contain the metadata require to define a project Contain the information in file.project with all projects

Further resource management Resource markers Tracking resource changes Incremental project builders Workspace save participation Project natures Derived resource Resource modification hooks

Marker Like a small tag to a resource Record information about a problem or a task, or simply record a location as bookmark User can jump to the marked location within a resource Platform defined five standard markers (marker, taskmarker, problemmark,bookmark,textmark)

Resource API defines methods for creating, setting value, extending the platform with new marker type Platform manage markers, it will throw away markers attached to resource that are deleted Plug-in control marker ’ s creation, removal and attribute value. It also removes markers that no longer apply to a resource Interface IMarker

Marker operation Marker creation Using factory method IResource.createMarker() Ex: IMarker marker = file.createMarker(IMarker.TASK); Marker deletion Ex: try { marker.delete(); } catch (CoreException e) { // Something went wrong }

Batch delete int depth = IResource.DEPTH_INFINITE; try { resource.deleteMarkers(IMarker.PROBLEM, true, depth); } catch (CoreException e) { // something went wrong } Attribute setting if (marker.exists()) { try { marker.setAttribute(IMarker.MESSAGE, "A sample marker message"); marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH); } catch (CoreException e) { // You need to handle the case where the marker no longer exists } }

Querying markers Resource can be queried for their markers and the markers of their children IMarker[] problems = null; int depth = IResource.DEPTH_INFINITE; try { problems = resource.findMarkers(IMarker.PROBLEM, true, depth); } catch (CoreException e) { // something went wrong }

Extension platform with new marker type New marker type are derived from existing ones using multiple inheritance, it will inherit all of the attribute from supertypes Plug-ins must declare new marker type in plugin.xml before using it Persistent Markers saved when workspace is saved.

point="org.eclipse.core.resources.markers" />

public IMarker createMyMarker(IResource resource){ try { Imarker marker= resource.createMarker("com.example.markers.myproblem "); marker.setAttribute("myAttribute", "MYVALUE"); return marker; } catch (CoreException e) { // You need to handle the cases where attribute value is rejected } }

Tracking resource changes The resource API include a event mechanism for resource changes Use IResourceChangeListener and IResourceChangeEvent to track resource change Method that create, delete or change a resource typically trigger a resource change event

Must register a resource change listener with the workspace IResourceChangeListener listener = new MyResourceChangeReporter(); ResourcesPlugin.getWorkspace().addResourceChangeListener( liste ner, IResourceChangeEvent.POST_CHANGE); Use IWorkspace.run(runnable,monitor) can batch the change operation, resource change event will be triggered once when the runnable is completed

Resource deltas Resource change event contains a resource delta that describes the net effect of change Structured as a tree rooted at the workspace root Describe four type of resource change Created, deleted, or changed Moved or renamed via IResource.move() Marker that has been added, removed, or changed Files that has been modified

To traverse a resource tree, implement the interface IResourceDeltaVisitor or using IResourceDelta.getAffectedChildren()

Resource change event PRE_CLOSE PRE_DELETE PRE_AUTOBUILD POST_AUTOBUILE POST_CHANGE

Implementing a resource change listener IResourceChangeListener listener = new MyResourceChangeReporter(); ResourcesPlugin.getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_AUTO_BUILD| IResourceChangeEvent.POST_AUTO_BUILD | IResourceChangeEvent.POST_CHANGE);

public class MyResourceChangeReporter implements IResourceChangeListener { public void resourceChanged(IResourceChangeEvent event) { IResource res = event.getResource(); switch (event.getType()) { case IResourceChangeEvent.PRE_CLOSE: System.out.print("Project "); System.out.print(res.getFullPath()); System.out.println(" is about to close."); break; case IResourceChangeEvent.PRE_DELETE: System.out.print("Project "); System.out.print(res.getFullPath()); System.out.println(" is about to be deleted."); break; case IResourceChangeEvent.POST_CHANGE: System.out.println("Resources have changed."); event.getDelta().accept(new DeltaPrinter()); break; } } }

Incremental project builder Manipulate the resource in a project in a fashion defined by the builder itself Often used to apply a transformation on a resource to produce a resource or other kind Platform define two kind of builds Full build Incremental build

Incremental builds are seeded with a resource change delta to reflect the net effect of all resource change

Invoke a build A build can be invoked in two ways IProject.build() for the reciving project IWorkspace.build() for all open project in the workspace An incremental project builders are also invoked implicitly by the platform during an auto-build

Defining an incremental project builder <builder

public class BuilderExample extends IncrementalProjectBuilder{ IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { // add your build logic here return null; } Protected void startupOnInitialize() { // add builder init logic here } }

Builder implementation protected IProject[] build(int kind, Map args, IProgressMonitor monitor throws CoreException { if (kind == IncrementalProjectBuilder.FULL_BUILD) { fullBuild(monitor); } //full build else { IResourceDelta delta = getDelta(getProject()); if (delta == null) { fullBuild(monitor); } // auto build else { incrementalBuild(delta, monitor); } } return null; }

protected void fullBuild(final IProgressMonitor monitor) throws CoreException { try { getProject().accept(new MyBuildVisitor()); } catch (CoreException e) { } } class MyBuildVisitor implements IResourceVisitor { public boolean visit(IResource res) { //build the specified resource. //return true to continue visiting children. return true; }

protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException { // the visitor does the work. delta.accept(new MyBuildDeltaVisitor()); }

Association an incremental project builder with a project IProjectDescription desc = project.getDescription(); ICommand[] commands = desc.getBuildSpec(); boolean found = false; for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(BUILDER_ID)) { found = true; break; } } if (!found) { //add builder to project ICommand command = desc.newCommand(); command.setBuilderName(BUILDER_ID); ICommand[] newCommands = new ICommand[commands.length + 1];

// Add it before other builders. System.arraycopy(commands, 0, newCommands, 1, commands.length); newCommands[0] = command; desc.setBuildSpec(newCommands); project.setDescription(desc, null); }

Workspace save participation Plug-in can participate in workspace save process to save plug-in data To participate in saving, add a save participation to the workspace in plug-in startup() method ResourcesPlugin.getWorkspace().addSaveParticipa nt(this, saveParticipant);

Save participation implementation Interface ISaveParticipant defines the protocol for a workspace save participation Provide behavior for different stages of the save process Implement method for each stage

Saving steps prepareToSave Notify the participant the workspace is about to be saved, it should suspend normal operation saving Tell the participant to save its important state

doneSaving Notifies the participant that the workspace has been saved and the participant can continue normal operation rollback Tells the participant to rollback the important state because the save operation has failed

Project natures Allow a plug-in to tag a project as a specific kink of project A project can have more then one nature Special constrains for the nature One-of-nature Requires-nature Interface IProjectNature

Defining a nature <extension point="org.eclipse.core.resources.natures" id="myNature" name="My Nature">

Implement a nature public class MyNature implements IProjectNature { private IProject project; public void configure() throws CoreException { // Add nature-specific information // for the project, such as adding a builder // to a project's build spec. } public void deconfigure() throws CoreException { // Remove the nature-specific information here. } public IProject getProject() { return project; } public void setProject(IProject value) { project = value; } }

Associate a nature to a project try { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = "com.example.natures.myNature"; description.setNatureIds(newNatures); project.setDescription(description, null); } catch (CoreException e) { // Something went wrong }

Derived resources Resources that are not original data, and can be recreated from their source files Use IResource.setDerived(boolean) to indicate that a resource is derived Use IResource.isDerived() to determine a resource is derived

Resource modification hooks Enable the team support plug-in