wro4j icon indicating copy to clipboard operation
wro4j copied to clipboard

RFE: Pass the group (name) to the post processors

Open martin-g opened this issue 13 years ago • 6 comments

Hi,

I'm asking for an improvement in Wro4j API, especially ro.isdc.wro.model.resource.processor.ResourcePostProcessor.process(Reader, Writer).

The preprocessors receive the Resource as first argument in their #process() method. I'm asking for something similar for the post processors - I need to know the name of the final artifact, i.e. the name of the group that is being postprocessed. Maybe the type will be also useful. Most of the post processors use @SupportedResourceType and they can be sure what they work with, but maybe there are some processors which process both type ?!

I think the perfect API would be the same as ro.isdc.wro.model.resource.processor.ResourcePreProcessor.process(Resource, Reader, Writer) where the resource is the already merged resource.

I'll be glad to work on that but before starting on it I want to know your opinion on it.

martin-g avatar Dec 05 '11 12:12 martin-g

Hi Martin, I agree with you. This does make sense. If you would take a look in 1.5.x branch (next major release) it has some API changes. More specifically, the ResourcePreProcessor & ResourcePostProcessor interface has been merged into a single one called ResourceProcessor with the same signature the preProcessor has. I think your RFE should be implemented on that branch.

alexo avatar Dec 05 '11 12:12 alexo

Nice! You also went in this direction :-)

Looking at ro.isdc.wro.model.group.processor.GroupsProcessor I see how it should be refactored but GroupsProcessor.getFilteredResources(Collection<Group>, ResourceType) confuses me. This is how I understand it:

  • iterate all groups
  • for each group get all resources by type
  • iterate resources
  • pass the resource to all configured pre processors
  • merge the resources
  • pass the merged resource to all post processors
  • store the post processed final resource

But GroupsProcessor.getFilteredResources(Collection<Group>, ResourceType) puts all (from all groups) resources in one list and then works with this longer list. What's the idea behind ?

martin-g avatar Dec 05 '11 13:12 martin-g

This is indeed a little bit confusing :)... The argument is a collection, but it is never used as a collection, because only a single group is processed at a time. The method was designed in mind with a feature which is not used currently. That is why, I think we can safely replace it from:

 public String process(final Collection<Group> groups, final ResourceType type, final boolean minimize) 

to

 public String process(Group group, final ResourceType type, final boolean minimize)   

alexo avatar Dec 05 '11 13:12 alexo

Btw, I'm not sure if post processors can know the name of the merged resource. At least I'm not aware of what that name would be. The merged resource is a virtual resource which has a type, but no name, unless you name it somehow using a naming strategy (?).... What do you think?

alexo avatar Dec 05 '11 13:12 alexo

Thanks for the response!

I was thinking to use the group name because this is what is being used if there is no explicitly configured naming strategy.

martin-g avatar Dec 05 '11 13:12 martin-g

That would mean if the group name is all, then the merged resource in post processor would be: all.js (when of js type) ? I think this should be ok... at least as initial solution.

alexo avatar Dec 05 '11 13:12 alexo