Skip to content

Commit 8a62b98

Browse files
committed
URI/URL
1 parent 60914d5 commit 8a62b98

File tree

2 files changed

+118
-3
lines changed

2 files changed

+118
-3
lines changed

content/posts/eclipse-project.md

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
author: "Phong Nguyen"
3-
title: "Eclipse Project"
3+
title: "Eclipse Platform Plug-in Development"
44
date: "2025-02-05"
5-
description: "Eclipse Project."
5+
description: "Platform Plug-in Developer Guide."
66
tags: ["eclipse"] #tags search
77
FAcategories: ["syntax"] #The category of the post, similar to tags but usually for broader classification.
88
FAseries: ["Themes Guide"] #indicates that this post is part of a series of related posts
@@ -14,7 +14,9 @@ weight: 10 # The order in which the post appears in a list of posts. Lower nu
1414
Explain how to create the eclipse project.
1515
**References:**
1616
[Wizards and Dialogs](https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.pde.doc.user%2Fguide%2Ftools%2Fproject_wizards%2Fnew_fragment_project.htm)
17-
[Eclipse fragment projects - Tutorial](https://www.vogella.com/tutorials/EclipseFragmentProject/article.html#example-manifest-for-a-fragment)<br>
17+
[Eclipse fragment projects - Tutorial](https://www.vogella.com/tutorials/EclipseFragmentProject/article.html#example-manifest-for-a-fragment)
18+
[Refer](https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresInt.htm)<br>
19+
1820
## 1. New Project Creation Wizards
1921
- Every `plugin, fragment, feature` and update site is represented by a single project in the workspace and allow PDE(Plugin Development Environment) to validate their manifest file(s).
2022
- `File > New > Project... > Plug-in Development`
@@ -126,3 +128,95 @@ public class Cool implements IApplication{
126128
```
127129

128130
- `eclipse -application coolApplication`
131+
132+
## 3. Resources
133+
- The resources plug-in (**org.eclipse.core.resource**) provides services for accessing the projects, folders, and files that a user is working with.
134+
### 3.1. Resources and Workspace
135+
- The resources plug-in provides APIs for resources in a workspace. Our plug-in can also use these APIs.
136+
### 3.2. Resources and file system
137+
- `.metadata`: platform metadata directory for holding its internal information, including workspace structure.
138+
- `.project`: project metadata
139+
- `IWorkspace`: an instance represent of the workspace when the platform is running and resources plug-in is active.
140+
- `IWorkspaceRoot`: the top o the resource hierarchy in the workspace
141+
- `IProjectDescription`: contain the project information (like .project)
142+
- `IProject, IFolder, IFile`: resource types
143+
- `org.eclipse.core.runtime.IPath`: resouce /file system paths. A path is simple (String -> IPath) or (String -> URI)
144+
- `IProgressMonitor`: use to report progress and allow user to cancel etc, use this when our code has a user interface (UI). `null` indicating no progress monitor
145+
146+
- Based on `java.io.File`
147+
148+
```java
149+
// get workspace/workspace root
150+
IWorkspace workspace = ResourcesPlugin.getWorkspace();
151+
IWorkspaceRoot workspaceRoot = workspace.getRoot();
152+
153+
// get and must open project
154+
IProject projectA = workspaceRoot.getProject("projectNameA");
155+
if(projectA != null && !projectA.isOpen()){
156+
projectA.open(null);
157+
}
158+
159+
// open folder and create st
160+
IFolder folder = projectA.getFolder("folderName");
161+
if(folder.exists()){
162+
// create a new file
163+
IFile newFile = folder.getFile("newFile.txt");
164+
165+
FileInputStream fileStream = new FileInputStream(
166+
"c:/MyOtherData/newLogo.png");
167+
newLogo.create(fileStream, false, null);
168+
// create closes the file stream, so no worries.
169+
170+
}
171+
```
172+
## 3.3 Mapping resources to disk locations
173+
- Resource paths are always based o the project's location (workspace directory e.g. C:\MySDK\workspace). e.g. IFile file1 = src/com/example/Main.java.
174+
- To get the full file system path to a resource, we must query its location using `IResource.getLocationURI`
175+
- To get the corresponding resource object given a file system path, we can using `IWorkspaceRoot.findFilesForLocationURI/findContainersForLocationURI`
176+
177+
- When we make some changes to resource files using external methods, we need to call a file system refresh to sync with platform. e.g. `IResource.refreshLocal(int dept, IProgressMonitor monitor)`
178+
179+
## 3.4. Resource Properties
180+
- There are two kinds of this:
181+
- Session properties: cache
182+
- Persistent properties:
183+
- Using `IResource API` to get this info.
184+
185+
## 3.5. Project-scoped preferences
186+
- How to define additional scope for preferences.
187+
- TBD
188+
189+
## 3.6. File encoding and content types
190+
- Content types for data stream (Charset etc)
191+
- TBD
192+
193+
## 3.7. Linked resources
194+
- This concept let we know how the files and folders inside a project can be stored in a file system outside of the project's location.
195+
-
196+
197+
## 4. Advanced resource
198+
## 4.1. Alternate file system
199+
- How to contribute/work with resources stored in the different file systems.
200+
### 4.1.1. File System API
201+
- The `org.eclipse.core.filesystem` plug-in provides a lot of API which is similar to `java.io.File`. With a few differences:
202+
- Plug-ins can install providers for different types of file systems.
203+
- All methods integrate support for reporting progress and responding to cancelation, making it easier to integrate into a graphical user interface.
204+
- There is support for some additional functionality not available in java.io.File, such as getting and setting file permissions.
205+
- There are more convenience methods, such as copy, move, and recursive deletion.
206+
207+
- `java.net.URI`: represent for any given file in the File System API
208+
- `IFileStore`: represents a single file (like IResource). Use this to create, delete, copy, move...
209+
- `IFileSystem`: represents a single URI scheme (e.g. file:, ftp: )
210+
- `IFileInfo`: represents the state(isExist etc) of a file at a particular moment
211+
- `org.eclipse.core.filesystem.EFS`: is the main entry point for clients of the Eclipse file system API. This class has factory methods for obtaining instances of file systems and file stores, and provides constants for option values and error codes.
212+
213+
```java
214+
URI uri = ...;
215+
IFileStore store = EFS.getStore(uri); // get file store from URI
216+
store.openOutputStream(EFS.APPEND, null); // using EFS flag to allow extra options
217+
218+
IFileInfo info = store.fetchInfo();
219+
boolean state = info.isDirectory();
220+
221+
```
222+
### 4.1.2. Working With Resources in Other File Systems

content/posts/java-basic.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,24 @@ public class REGEX {
118118
}
119119
}
120120
```
121+
122+
### 4.2. URL - URI
123+
- `URI`: Uniform Resource Identifier: the complete identification of any resources. e.g. `urn:isbn:1234567890`
124+
- `URL`: Uniform Resource Locator: a subset of URI that, in addition to identifying where a resource is available. And let we know the mechanism to access it. e.g. `"http://somehost:80/path?thequery"`
125+
126+
- Every `URL` is a `URI`, but the opposite is not true.
127+
128+
- URI syntax: `scheme:[//authority][/path][?query][#fragment]`
129+
- `scheme`: protocol to access the resource
130+
- `authority`: optional part, include user,host, port,...
131+
- `path`: identify a resource
132+
- `query`: also identify a resource, for URLs, this is the query string
133+
- `fragment`: optional part, specific part of the resource
134+
135+
- URI have ftp, http, https, file wil be a URL.
136+
> The easiest way to see the difference between URL and URI is to remember that:
137+
URI = identifier (the broad concept — anything that uniquely names or locates a resource)
138+
URL = locator (a URI that tells you where and how to get it)
139+
URI
140+
├── URL → has location + access method
141+
└── URN → name only, no access method

0 commit comments

Comments
 (0)