Skip to content

Commit db36a6f

Browse files
committed
feat: add new variables for relative location pathes to project and
workspace - resource_loc_path: relative location path of file or directory (to workspace) - resource_project_path: relative path of file or directory (to project) - resource_project_loc_path: relative location path of file or directory (to project) - container_loc_path: relative location path of file's parent directory or directory itself (to workspace) - container_project_path: relative path of file's parent directory or directory itself (to project) - container_project_loc_path: relative location path of file's parent directory or directory itself (to project) - parent_loc_path: relative location path of parent directory (to workspace); for files it's equal to ${easyshell:container_loc_path} - parent_project_path: relative path of parent directory (to project); for files it's equal to ${easyshell:container_project_path} - parent_project_loc_path: relative location path of parent directory (to project); for files it's equal to ${easyshell:container_project_loc_path} - project_loc_name: location name (folder) of project - project_parent_loc: absolute path of project's parent - workspace_loc: absolute path of workspace - workspace_loc_name: location name (folder) of workspace Signed-off-by: Andre Bossert <anb0s@anbos.de>
1 parent 738ef06 commit db36a6f

File tree

3 files changed

+240
-8
lines changed

3 files changed

+240
-8
lines changed

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,35 @@ The following substitution variables are available for building the command:
163163
- ```${easyshell:resource_name}``` = name of file or directory
164164
- ```${easyshell:resource_basename}``` = name of file without extension
165165
- ```${easyshell:resource_extension}``` = extension of file name (without '.')
166-
- ```${easyshell:resource_path}``` = relative path to workspace of file or directory
166+
- ```${easyshell:resource_path}``` = relative path of file or directory (to workspace)
167+
- ```${easyshell:resource_loc_path}``` = relative location path of file or directory (to workspace)
168+
- ```${easyshell:resource_project_path}``` = relative path of file or directory (to project)
169+
- ```${easyshell:resource_project_loc_path}``` = relative location path of file or directory (to project)
167170
- ```${easyshell:resource_line_number}``` = line number (within view or editor)
168-
- ```${easyshell:selected_text_start_line}``` = selected text start line (within view or editor), it's equal to ${easyshell:resource_line_number}
171+
- ```${easyshell:selected_text_start_line}``` = selected text start line (within view or editor), it's equal to ```${easyshell:resource_line_number}```
169172
- ```${easyshell:selected_text_end_line}``` = selected text end line (within view or editor)
170173
- ```${easyshell:selected_text_length}``` = selected text length (within view or editor)
171174
- ```${easyshell:selected_text_offset}``` = selected text offset (within view or editor)
172175
- ```${easyshell:selected_text}``` = selected text (within view or editor)
173176
- ```${easyshell:container_loc}``` = absolute path of file directory or directory itself
174177
- ```${easyshell:container_name}``` = name of file directory or directory itself
175-
- ```${easyshell:container_path}``` = relative path to workspace of file directory or directory itself
176-
- ```${easyshell:parent_loc}``` = absolute path of parent directory, for files it's equal to ${easyshell:container_loc}
177-
- ```${easyshell:parent_name}``` = name of parent directory, for files it's equal to ${easyshell:container_name}
178-
- ```${easyshell:parent_path}``` = relative path to workspace of parent directory, for files it's equal to ${easyshell:container_path}
178+
- ```${easyshell:container_path}``` = relative path of file directory or directory itself (to workspace)
179+
- ```${easyshell:container_loc_path}``` = relative location path of file's parent directory or directory itself (to workspace)
180+
- ```${easyshell:container_project_path}``` = relative path of file's parent directory or directory itself (to project)
181+
- ```${easyshell:container_project_loc_path}``` = relative location path of file's parent directory or directory itself (to project)
182+
- ```${easyshell:parent_loc}``` = absolute path of parent directory, for files it's equal to ```${easyshell:container_loc}```
183+
- ```${easyshell:parent_name}``` = name of parent directory, for files it's equal to ```${easyshell:container_name}```
184+
- ```${easyshell:parent_path}``` = relative path to workspace of parent directory, for files it's equal to ```${easyshell:container_path}```
185+
- ```${easyshell:parent_loc_path}``` = relative location path of parent directory (to workspace); for files it's equal to ```${easyshell:container_loc_path}```
186+
- ```${easyshell:parent_project_path}``` = relative path of parent directory (to project); for files it's equal to ```${easyshell:container_project_path}```
187+
- ```${easyshell:parent_project_loc_path}``` = relative location path of parent directory (to project); for files it's equal to ```${easyshell:container_project_loc_path}```
179188
- ```${easyshell:project_loc}``` = absolute path of project
180189
- ```${easyshell:project_name}``` = name of project
181190
- ```${easyshell:project_path}``` = relative path to workspace of project
191+
- ```${easyshell:project_loc_name}``` = location name (folder) of project
192+
- ```${easyshell:project_parent_loc}``` = absolute path of project's parent
193+
- ```${easyshell:workspace_loc}``` = absolute path of workspace
194+
- ```${easyshell:workspace_loc_name}``` = location name (folder) of workspace
182195
- ```${easyshell:windows_drive}``` = drive letter of file or directory on Windows
183196
- ```${easyshell:qualified_name}``` = full qualified (class) name
184197
- ```${easyshell:line_separator}``` = line separator, e.g. '\\n' (Unix) or '\\r\\n' (Windows)

plugin/src/de/anbos/eclipse/easyshell/plugin/types/Resource.java

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.io.IOException;
1818
import java.net.URISyntaxException;
1919
import java.net.URL;
20+
import java.nio.file.Path;
21+
import java.nio.file.Paths;
2022

2123
import org.eclipse.core.resources.IResource;
2224
import org.eclipse.core.runtime.FileLocator;
@@ -119,6 +121,45 @@ public String getContainerPath() {
119121
return "";
120122
}
121123

124+
public String getContainerLocPath() {
125+
if (resource != null) {
126+
Path basePath = Paths.get(resource.getProject().getRawLocation().toFile().getParentFile().toURI());
127+
Path resourcePath = null;
128+
if (resource.getType() == IResource.FILE) {
129+
resourcePath = Paths.get(resource.getRawLocation().toFile().getParentFile().toURI());
130+
} else {
131+
resourcePath = Paths.get(resource.getRawLocationURI());
132+
}
133+
return basePath.relativize(resourcePath).toString();
134+
}
135+
return "";
136+
}
137+
138+
public String getContainerProjectPath() {
139+
if (resource != null) {
140+
if (resource.getType() == IResource.FILE) {
141+
return resource.getParent().getProjectRelativePath().toString();
142+
} else {
143+
return resource.getProjectRelativePath().toString();
144+
}
145+
}
146+
return "";
147+
}
148+
149+
public String getContainerProjectLocPath() {
150+
if (resource != null) {
151+
Path basePath = Paths.get(resource.getProject().getRawLocation().toFile().toURI());
152+
Path resourcePath = null;
153+
if (resource.getType() == IResource.FILE) {
154+
resourcePath = Paths.get(resource.getRawLocation().toFile().getParentFile().toURI());
155+
} else {
156+
resourcePath = Paths.get(resource.getRawLocationURI());
157+
}
158+
return basePath.relativize(resourcePath).toString();
159+
}
160+
return "";
161+
}
162+
122163
public String getParentLocation() {
123164
return file.getParent();
124165
}
@@ -138,6 +179,31 @@ public String getParentPath() {
138179
return "";
139180
}
140181

182+
public String getParentLocPath() {
183+
if (resource != null) {
184+
Path basePath = Paths.get(resource.getProject().getRawLocation().toFile().getParentFile().toURI());
185+
Path resourcePath = Paths.get(resource.getRawLocation().toFile().getParentFile().toURI());
186+
return basePath.relativize(resourcePath).toString();
187+
}
188+
return "";
189+
}
190+
191+
public String getParentProjectPath() {
192+
if (resource != null) {
193+
return resource.getParent().getProjectRelativePath().toString();
194+
}
195+
return "";
196+
}
197+
198+
public String getParentProjectLocPath() {
199+
if (resource != null) {
200+
Path basePath = Paths.get(resource.getProject().getRawLocation().toFile().toURI());
201+
Path resourcePath = Paths.get(resource.getRawLocation().toFile().getParentFile().toURI());
202+
return basePath.relativize(resourcePath).toString();
203+
}
204+
return "";
205+
}
206+
141207
public String getResourceLocation() {
142208
return file.getPath();
143209
}
@@ -165,6 +231,31 @@ public String getResourcePath() {
165231
return "";
166232
}
167233

234+
public String getResourceLocPath() {
235+
if (resource != null) {
236+
Path basePath = Paths.get(resource.getProject().getRawLocation().toFile().getParentFile().toURI());
237+
Path resourcePath = Paths.get(resource.getRawLocation().toFile().toURI());
238+
return basePath.relativize(resourcePath).toString();
239+
}
240+
return "";
241+
}
242+
243+
public String getResourceProjectPath() {
244+
if (resource != null) {
245+
return resource.getProjectRelativePath().toString();
246+
}
247+
return "";
248+
}
249+
250+
public String getResourceProjectLocPath() {
251+
if (resource != null) {
252+
Path basePath = Paths.get(resource.getProject().getRawLocation().toFile().toURI());
253+
Path resourcePath = Paths.get(resource.getRawLocation().toFile().toURI());
254+
return basePath.relativize(resourcePath).toString();
255+
}
256+
return "";
257+
}
258+
168259
public String getSelectedTextStartLine() {
169260
if (textSelection != null && textSelection instanceof ITextSelection) {
170261
return String.valueOf(((ITextSelection)textSelection).getStartLine()+1);
@@ -229,6 +320,27 @@ public String getProjectPath() {
229320
return "";
230321
}
231322

323+
public String getProjectLocName() {
324+
if (resource != null) {
325+
return resource.getProject().getRawLocation().toFile().getName();
326+
}
327+
return "";
328+
}
329+
330+
public String getProjectLocPath() {
331+
if (resource != null) {
332+
return resource.getProject().getRawLocation().toFile().getName();
333+
}
334+
return "";
335+
}
336+
337+
public String getProjectParentLoc() {
338+
if (resource != null) {
339+
return resource.getProject().getLocation().toFile().getParent().toString();
340+
}
341+
return "";
342+
}
343+
232344
public String getWorkspaceLocation() {
233345
if (resource != null) {
234346
return resource.getWorkspace().getRoot().getLocation().toFile().toString();

plugin/src/de/anbos/eclipse/easyshell/plugin/types/Variable.java

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ public String resolve(Object object, Object parameter) {
7979
return ((Resource)object).getResourcePath();
8080
};
8181
}),
82+
// ${easyshell:resource_loc_path}
83+
varResourceLocPath(true, false, "resource_loc_path", "relative location path of file or directory (to workspace)", new IVariableResolver() {
84+
public String resolve(Object object, Object parameter) {
85+
if(!(object instanceof Resource)) {
86+
return "";
87+
}
88+
return ((Resource)object).getResourceLocPath();
89+
};
90+
}),
91+
// ${easyshell:resource_project_path}
92+
varResourceProjectPath(true, false, "resource_project_path", "relative path of file or directory (to project)", new IVariableResolver() {
93+
public String resolve(Object object, Object parameter) {
94+
if(!(object instanceof Resource)) {
95+
return "";
96+
}
97+
return ((Resource)object).getResourceProjectPath();
98+
};
99+
}),
100+
// ${easyshell:resource_project_loc_path}
101+
varResourceProjectLocPath(true, false, "resource_project_loc_path", "relative location path of file or directory (to project)", new IVariableResolver() {
102+
public String resolve(Object object, Object parameter) {
103+
if(!(object instanceof Resource)) {
104+
return "";
105+
}
106+
return ((Resource)object).getResourceProjectLocPath();
107+
};
108+
}),
82109
// ${easyshell:resource_line_number}
83110
varResourceLineNumber(true, false, "resource_line_number", "selected text line number", new IVariableResolver() {
84111
public String resolve(Object object, Object parameter) {
@@ -160,6 +187,33 @@ public String resolve(Object object, Object parameter) {
160187
return ((Resource)object).getContainerPath();
161188
};
162189
}),
190+
// ${easyshell:container_loc_path}
191+
varContainerLocPath(true, false, "container_loc_path", "relative location path of file's parent directory or directory itself (to workspace)", new IVariableResolver() {
192+
public String resolve(Object object, Object parameter) {
193+
if(!(object instanceof Resource)) {
194+
return "";
195+
}
196+
return ((Resource)object).getContainerLocPath();
197+
};
198+
}),
199+
// ${easyshell:container_project_path}
200+
varContainerProjectPath(true, false, "container_project_path", "relative path of file's parent directory or directory itself (to project)", new IVariableResolver() {
201+
public String resolve(Object object, Object parameter) {
202+
if(!(object instanceof Resource)) {
203+
return "";
204+
}
205+
return ((Resource)object).getContainerProjectPath();
206+
};
207+
}),
208+
// ${easyshell:container_project_loc_path}
209+
varContainerProjectLocPath(true, false, "container_project_loc_path", "relative location path of file's parent directory or directory itself (to project)", new IVariableResolver() {
210+
public String resolve(Object object, Object parameter) {
211+
if(!(object instanceof Resource)) {
212+
return "";
213+
}
214+
return ((Resource)object).getContainerProjectLocPath();
215+
};
216+
}),
163217
// ${easyshell:parent_loc} for file it's equal to ${easyshell:container_loc}
164218
varParentLoc(true, false, "parent_loc", "absolute path of parent directory\n\nfor files it's equal to ${easyshell:container_loc}", new IVariableResolver() {
165219
public String resolve(Object object, Object parameter) {
@@ -187,6 +241,33 @@ public String resolve(Object object, Object parameter) {
187241
return ((Resource)object).getParentPath();
188242
};
189243
}),
244+
// ${easyshell:parent_loc_path} for file it's equal to ${easyshell:container_loc_path}
245+
varParentLocPath(true, false, "parent_loc_path", "relative location path of parent directory (to workspace)\n\nfor files it's equal to ${easyshell:container_loc_path}", new IVariableResolver() {
246+
public String resolve(Object object, Object parameter) {
247+
if(!(object instanceof Resource)) {
248+
return "";
249+
}
250+
return ((Resource)object).getParentLocPath();
251+
};
252+
}),
253+
// ${easyshell:parent_project_path} for file it's equal to ${easyshell:container_project_path}
254+
varParentProjectPath(true, false, "parent_project_path", "relative path of parent directory (to project)\n\nfor files it's equal to ${easyshell:container_project_path}", new IVariableResolver() {
255+
public String resolve(Object object, Object parameter) {
256+
if(!(object instanceof Resource)) {
257+
return "";
258+
}
259+
return ((Resource)object).getParentProjectPath();
260+
};
261+
}),
262+
// ${easyshell:parent_project_loc_path} for file it's equal to ${easyshell:container_project_loc_path}
263+
varParentProjectLocPath(true, false, "parent_project_loc_path", "relative location path of parent directory (to project)\n\nfor files it's equal to ${easyshell:container_project_loc_path}", new IVariableResolver() {
264+
public String resolve(Object object, Object parameter) {
265+
if(!(object instanceof Resource)) {
266+
return "";
267+
}
268+
return ((Resource)object).getParentProjectLocPath();
269+
};
270+
}),
190271
// ${easyshell:project_loc}
191272
varProjectLoc(true, false, "project_loc", "absolute path of project", new IVariableResolver() {
192273
public String resolve(Object object, Object parameter) {
@@ -211,6 +292,32 @@ public String resolve(Object object, Object parameter) {
211292
return ((Resource)object).getProjectPath();
212293
};
213294
}),
295+
// ${easyshell:project_loc_name} == {4}
296+
varProjectLocName(true, false, "project_loc_name", "location name (folder) of project", new IVariableResolver() {
297+
public String resolve(Object object, Object parameter) {
298+
return ((Resource)object).getProjectLocName();
299+
};
300+
}),
301+
/*
302+
// ${easyshell:project_loc_path}
303+
varProjectLocPath(true, false, "project_loc_path", "relative location path of project (to workspace)", new IVariableResolver() {
304+
public String resolve(Object object, Object parameter) {
305+
if(!(object instanceof Resource)) {
306+
return "";
307+
}
308+
return ((Resource)object).getProjectLocPath();
309+
};
310+
}),
311+
*/
312+
// ${easyshell:project_parent_loc}
313+
varProjectParentLoc(true, false, "project_parent_loc", "absolute path of project's parent", new IVariableResolver() {
314+
public String resolve(Object object, Object parameter) {
315+
if(!(object instanceof Resource)) {
316+
return "";
317+
}
318+
return ((Resource)object).getProjectParentLoc();
319+
};
320+
}),
214321
// ${easyshell:workspace_loc}
215322
varWorkspaceLoc(true, false, "workspace_loc", "absolute path of workspace", new IVariableResolver() {
216323
public String resolve(Object object, Object parameter) {
@@ -222,14 +329,14 @@ public String resolve(Object object, Object parameter) {
222329
}),
223330
/*
224331
// ${easyshell:workspace_name}
225-
varWorkspaceName(true, false, "workspace_name", "name of workspace (same as workspace_foldername if not configured)", new IVariableResolver() {
332+
varWorkspaceName(true, false, "workspace_name", "name of workspace (same as workspace_loc_name if not configured)", new IVariableResolver() {
226333
public String resolve(Object object, Object parameter) {
227334
return ((Resource)object).getWorkspaceName();
228335
};
229336
}),
230337
*/
231338
// ${easyshell:workspace_loc_name}
232-
varWorkspaceLocName(true, false, "workspace_loc_name", "name of workspace's folder", new IVariableResolver() {
339+
varWorkspaceLocName(true, false, "workspace_loc_name", "location name (folder) of workspace", new IVariableResolver() {
233340
public String resolve(Object object, Object parameter) {
234341
return ((Resource)object).getWorkspaceLocName();
235342
};

0 commit comments

Comments
 (0)