Skip to content

Commit 503cde4

Browse files
committed
Refactored OomphIdeExtension.linkedResource to be local, and to lazily resolve the file.
In a gradle DSL, anytime you want a File, you can do `project.file(Object input)` and it will give you a file. That way the input can be a File or a relative path, and gradle will resolve it to relative to the project.
1 parent 7434506 commit 503cde4

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -213,28 +213,14 @@ public void addSetupActionLazy(Action<List<SetupAction>> lazyInternalSetupAction
213213
setupActions.addLazyAction(lazyInternalSetupAction);
214214
}
215215

216-
final static String CORE_RES_PREFS_FILE = ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs";
217-
final static String WS_PATHVAR_FMT = "pathvariable.%s";
218-
219-
public void linkedResource(String linkName, File linkTarget) {
220-
workspaceProp(CORE_RES_PREFS_FILE, new LinkedResourceAction(linkName, linkTarget));
221-
}
222-
223-
static class LinkedResourceAction implements Action<Map<String, String>> {
224-
private String linkName;
225-
private File linkTarget;
226-
227-
public LinkedResourceAction(String linkName, File linkTarget) {
228-
super();
229-
this.linkName = linkName;
230-
this.linkTarget = linkTarget;
231-
}
232-
233-
@Override
234-
public void execute(Map<String, String> props) {
216+
/** Links the given target into the workspace with the given name, see [eclipse manual](http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fconcepts-13.htm). */
217+
public void linkedResource(String linkName, Object linkTarget) {
218+
final String CORE_RES_PREFS_FILE = ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs";
219+
final String WS_PATHVAR_FMT = "pathvariable.%s";
220+
workspaceProp(CORE_RES_PREFS_FILE, props -> {
235221
//Eclipse cannot handle backslashes in this value. It expects path separators to be '/'
236-
props.put(String.format(WS_PATHVAR_FMT, linkName), linkTarget.getAbsolutePath().replace("\\", "/"));
237-
}
222+
props.put(String.format(WS_PATHVAR_FMT, linkName), project.file(linkTarget).getAbsolutePath().replace("\\", "/"));
223+
});
238224
}
239225

240226
////////////////

0 commit comments

Comments
 (0)