Bug 64603 - ScriptFilter has no way to reuse it
Summary: ScriptFilter has no way to reuse it
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Documentation (show other bugs)
Version: 1.10.8
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: 1.10.9
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-15 14:08 UTC by Robert Flaherty
Modified: 2020-08-23 12:20 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Flaherty 2020-07-15 14:08:02 UTC
I see no way to reuse a ScriptFilter in various tasks.

- I thought a FilterSet might work, but it doesn't support nesting standard filters.

- Possibly a new ScriptFilterDef would be needed, and maybe provide an "id", then use a ScriptFilter with "refid" in say a copy task.

- Currently I'm trying to hack this by creating a ScriptDef with an attribute, and do:
	var sText = String(attributes.get("input"));
	sText = "ScriptDef(" + sText + ")";
	project.setProperty("output", sText);
and in a ScriptFilter do:
	var sText = self.getToken();
	sText = "ScriptFilter(" + sText + ")";
	var oMinifyTask = project.createTask("minify");
	oMinifyTask.setDynamicAttribute("input", sText);
	oMinifyTask.perform();
	sText = project.getProperty("output");
	self.setToken(sText);
I saw no other way to pass back a value.  I'll try to use a Local to minimize the scope.
Comment 1 Robert Flaherty 2020-07-15 14:38:14 UTC
- One other idea is if FilterChain could support the id/refid combo.  I don't know if FilterChains can be nested, but that may also be desirable.
Comment 2 Stefan Bodewig 2020-08-11 13:18:48 UTC
I think <filterchain> can be defined once and reused via refid later. Doesn't this work?
Comment 3 Robert Flaherty 2020-08-12 15:36:20 UTC
Well, the FilterChain worked.

Firstly, can this be turned into a doc bug for the "Manual" docs:
- The "FilterChains and FilterReaders" section has no grid of info for FilterChain; I think "refid" is the only attribute.
- Looking at the JavaDocs, anything extending from DataType would support the "refid", but that should be documented in the corresponding "Manual" docs.  I don't see "refid" for FileList, FilterSet, PatternSet, etc...

Secondly, is it technically possible to push the Reference concept down from DataType to ProjectComponent, where even tasks could leverage this?
Comment 4 Stefan Bodewig 2020-08-23 10:21:25 UTC
if you look at the actual implementations you'll see that refid by itself doesn't do anything and that all implmentations of DataType contain custom code to make it work. Pushing it down to ProjectComponent wouldn't change anything as each implementation of ProjectComponent add support for it explicitly.

There isn't anything that would stop a task from implementing refid today - or from extending DataType. Tasks don't need to extend Task, they don't even have to be ProjectComponents. All that is required of a task is to have a no-arg void execure method. Pure duck-typing :-)

As for the documentation there is a section of references in https://ant.apache.org/manual/using.html#references but it is not cross-references from all places where it could be. I'll try to improve that.