google-code-export / wro4j

Automatically exported from code.google.com/p/wro4j
1 stars 1 forks source link

ChainedProcessor uses WroTestUtils which uses junit, making it not work at runtime #895

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
ro.isdc.wro.model.resource.processor.support.ChainedProcessor uses 
WroTestUtils. WroTestUtils uses junit. junit isn't available at runtime, and 
ChainedProcessor's javadoc, name, and package give no indication that it would 
only work inside tests.

It's surprising that ChainedProcessor only works inside tests - I think that 
should be fixed (ChainedProcessor shouldn't use WroTestUtils).

Thanks!

Original issue reported on code.google.com by candrews...@gmail.com on 2 Sep 2014 at 5:18

GoogleCodeExporter commented 9 years ago

Original comment by alex.obj...@gmail.com on 3 Sep 2014 at 5:21

GoogleCodeExporter commented 9 years ago
This processor is used currently for tests only. Do you have any use-case for 
this processor?

Original comment by alex.obj...@gmail.com on 3 Sep 2014 at 2:47

GoogleCodeExporter commented 9 years ago
I was using to make one processor that I could use to minify anything:

    ResourcePreProcessor chainedProcessor;

    protected ResourcePreProcessor getChainedProcessor(){
        ServletContextAttributeHelper servletContextAttributeHelper = new ServletContextAttributeHelper(ServletContextHolder.getServletContext());
        boolean minimize = servletContextAttributeHelper.getWroConfiguration().isMinimizeEnabled();

        WroManager wroManager =
            servletContextAttributeHelper.getManagerFactory().create();

        ProcessorsFactory processorsFactory = wroManager.getProcessorsFactory();
        List<ResourcePreProcessor> processors = new ArrayList<ResourcePreProcessor>();
        for(ResourcePreProcessor processor : processorsFactory.getPreProcessors()){
            processors.add(new DefaultProcessorDecorator(processor, minimize));
        }
        for(ResourcePostProcessor processor : processorsFactory.getPostProcessors()){
            processors.add(new DefaultProcessorDecorator(processor, minimize));
        }
        return chainedProcessor = ChainedProcessor.create(processors.toArray(new ResourcePreProcessor[processors.size()]));
    }

    public String compress(String source) {
        if(chainedProcessor==null){
            synchronized(this){
                if(chainedProcessor==null){
                    chainedProcessor = getChainedProcessor();
                }
            }
        }

        final StringWriter stringWriter = new StringWriter();
        try {
            chainedProcessor.process(Resource.create("", resourceType), new StringReader(source), stringWriter);
        } catch (Exception e) {
            throw new RuntimeException("Exception occurred while using wro4j to process inline " + resourceType.getContentType(),e);
        }
        return stringWriter.toString();
    }

So I could just call compress("whatever") and it will returned the processed 
output.

If there's a better way to do that, please do let me know - but either way, it 
would be nice if ChainedProcessor lost that junit dependency. :)

Original comment by candrews...@gmail.com on 3 Sep 2014 at 3:14

GoogleCodeExporter commented 9 years ago
You cannot just minimize anything, simply because each type of resource require 
a certain processor (ex: googleClosure for js, cssMin for css). But I agree 
that since the ChainedProcessor is part of non test code base, it should not 
depend on TestUtils.  

Original comment by alex.obj...@gmail.com on 3 Sep 2014 at 3:24

GoogleCodeExporter commented 9 years ago
In the constructor of this class, a ResourceType is specified. That's how wro4j 
can know which processors to apply.

My motivation for this adapter is to work with 
https://code.google.com/p/htmlcompressor/ btw.

Attached is the class.

Original comment by candrews...@gmail.com on 3 Sep 2014 at 3:32

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed in branch 1.7.x

Original comment by alex.obj...@gmail.com on 4 Sep 2014 at 8:26

GoogleCodeExporter commented 9 years ago

Original comment by alex.obj...@gmail.com on 10 Sep 2014 at 9:06