Examples of ResourcePreProcessor


Examples of ro.isdc.wro.model.resource.processor.ResourcePreProcessor

  private void checkFormattedReportsFromFolder(final URL url, final ReportXmlFormatter.FormatterType formatterType)
      throws IOException {
    final File testFolder = new File(url.getFile(), "test");
    final File expectedFolder = new File(url.getFile(), "expected");
    WroTestUtils.compareFromDifferentFoldersByExtension(testFolder, expectedFolder, "*", new ResourcePreProcessor() {
      @Override
      public void process(final Resource resource, final Reader reader, final Writer writer)
          throws IOException {
        final Type type = new TypeToken<LintReport<LinterError>>() {}.getType();
        final LintReport<LinterError> errors = new Gson().fromJson(reader, type);
View Full Code Here

Examples of ro.isdc.wro.model.resource.processor.ResourcePreProcessor


  @Test
  public void shouldDetectProperlyCssImportStatements()
      throws Exception {
    final ResourcePreProcessor processor = victim;
    final URL url = getClass().getResource("lesscss");

    final File testFolder = new File(url.getFile(), "test");
    final File expectedFolder = new File(url.getFile(), "expectedLessCssImport");
    WroTestUtils.compareFromDifferentFoldersByExtension(testFolder, expectedFolder, "css", processor);
View Full Code Here

Examples of ro.isdc.wro.model.resource.processor.ResourcePreProcessor

  }

  @Test
  public void testFromFolder()
      throws Exception {
    final ResourcePreProcessor processor = new RhinoLessCssProcessor();
    final URL url = getClass().getResource("lesscss");

    final File testFolder = new File(url.getFile(), "test");
    final File expectedFolder = new File(url.getFile(), "expected");
    WroTestUtils.compareFromDifferentFoldersByExtension(testFolder, expectedFolder, "css", processor);
View Full Code Here

Examples of ro.isdc.wro.model.resource.processor.ResourcePreProcessor

   * Test that processing invalid less css produces exceptions
   */
  @Test
  public void shouldFailWhenInvalidLessCssIsProcessed()
      throws Exception {
    final ResourcePreProcessor processor = new RhinoLessCssProcessor() {
      @Override
      protected void onException(final WroRuntimeException e) {
        LOG.debug("[FAIL] Exception message is: {}", e.getMessage());
        throw e;
      };
    };
    final URL url = getClass().getResource("lesscss");

    final File testFolder = new File(url.getFile(), "invalid");
    WroTestUtils.forEachFileInFolder(testFolder, new Function<File, Void>() {
      @Override
      public Void apply(final File input)
          throws Exception {
        try {
          processor.process(null, new FileReader(input), new StringWriter());
          Assert.fail("Expected to fail, but didn't");
        } catch (final WroRuntimeException e) {
          // expected to throw exception, continue
        }
        return null;
View Full Code Here

Examples of ro.isdc.wro.model.resource.processor.ResourcePreProcessor

  }

  @Test
  public void shouldWorkProperlyWithCssImportPreProcessor()
      throws Exception {
    final ResourcePreProcessor processor = ChainedProcessor.create(initProcessor(new CssImportPreProcessor()),
        initProcessor((ResourcePreProcessor) new RhinoLessCssProcessor()));
    final URL url = getClass().getResource("lesscss");

    final File testFolder = new File(url.getFile(), "test");
    final File expectedFolder = new File(url.getFile(), "expectedUrlRewriting");
View Full Code Here

Examples of ro.isdc.wro.model.resource.processor.ResourcePreProcessor

        return getPreProcessorStrategies(provider);
      }
     
      @Override
      protected ResourcePreProcessor getStrategyForAlias(final String alias) {
        ResourcePreProcessor processor = super.getStrategyForAlias(alias);
        if (processor == null) {
          final String extension = FilenameUtils.getExtension(alias);
          boolean hasExtension = !StringUtils.isEmpty(extension);
          if (hasExtension) {
            final String processorName = FilenameUtils.getBaseName(alias);
View Full Code Here

Examples of ro.isdc.wro.model.resource.processor.ResourcePreProcessor

  @Test
  public void shouldApplyProcessor()
      throws Exception {
    final String processedMessage = "DONE";
    final List<ResourcePreProcessor> processors = new ArrayList<ResourcePreProcessor>();
    processors.add(new ResourcePreProcessor() {
      public void process(final Resource resource, final Reader reader, final Writer writer)
          throws IOException {
        writer.write(processedMessage);
      }
    });
View Full Code Here

Examples of ro.isdc.wro.model.resource.processor.ResourcePreProcessor

  @Test(expected = WroRuntimeException.class)
  public void shouldThrowExceptionWhenProcessorFails()
      throws Exception {
    final List<ResourcePreProcessor> processors = new ArrayList<ResourcePreProcessor>();
    processors.add(new ResourcePreProcessor() {
      public void process(final Resource resource, final Reader reader, final Writer writer)
          throws IOException {
        throw new WroRuntimeException("processor fails");
      }
    });
View Full Code Here

Examples of ro.isdc.wro.model.resource.processor.ResourcePreProcessor

   * @param groupName
   *          the name of the group being processed.
   * @return a processor used to detect changes in imported resources.
   */
  private ResourcePreProcessor createCssImportProcessor(final AtomicBoolean changeDetected, final String groupName) {
    final ResourcePreProcessor cssImportProcessor = new AbstractCssImportPreProcessor() {
      @Override
      protected void onImportDetected(final String importedUri) {
        LOG.debug("Found @import {}", importedUri);
        final boolean isImportChanged = isChanged(Resource.create(importedUri, ResourceType.CSS), groupName);
        LOG.debug("\tisImportChanged={}", isImportChanged);
        if (isImportChanged) {
          changeDetected.set(true);
          // we need to continue in order to store the hash for all imported resources, otherwise the change won't be
          // computed correctly.
        }
      };

      @Override
      protected String doTransform(final String cssContent, final List<Resource> foundImports)
          throws IOException {
        // no need to build the content, since we are interested in finding imported resources only
        return "";
      }

      @Override
      public String toString() {
        return CssImportPreProcessor.class.getSimpleName();
      }
    };
    /**
     * Ignore processor failure, since we are interesting in detecting change only. A failure is treated as lack of
     * change.
     */
    final ResourcePreProcessor processor = new ExceptionHandlingProcessorDecorator(cssImportProcessor) {
      @Override
View Full Code Here

Examples of ro.isdc.wro.model.resource.processor.ResourcePreProcessor

      }
    }
    if (!processors.isEmpty()) {
      Writer writer = null;
      for (final ResourcePreProcessor processor : processors) {
        final ResourcePreProcessor decoratedProcessor = decoratePreProcessor(processor, criteria);

        writer = new StringWriter();
        final Reader reader = new StringReader(resourceContent);
        // decorate and process
        decoratedProcessor.process(resource, reader, writer);
        // use the outcome for next input
        resourceContent = writer.toString();
      }
    }
    // add explicitly new line at the end to avoid unexpected comment issue
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.