Package ro.isdc.wro.model.resource.support.hash

Examples of ro.isdc.wro.model.resource.support.hash.HashStrategy


        managerFactory.setUriLocatorFactory(mockLocatorFactory);
        managerFactory.setModelFactory(WroTestUtils.simpleModelFactory(model));
        return managerFactory;
      }
    };
    final HashStrategy hashStrategy = victim.getManagerFactory().create().getHashStrategy();
    setUpMojo(victim);

    final String importedInitialContent = "initial";

    when(mockLocator.locate(Mockito.eq(importResource))).thenAnswer(answerWithContent(importedInitialContent));
    when(mockBuildContext.isIncremental()).thenReturn(true);
    when(mockBuildContext.getValue(Mockito.eq(parentResource))).thenReturn(
        hashStrategy.getHash(new ByteArrayInputStream(parentContent.getBytes())));
    when(mockBuildContext.getValue(Mockito.eq(importResource))).thenReturn(
        hashStrategy.getHash(new ByteArrayInputStream(importedInitialContent.getBytes())));
    victim.setIgnoreMissingResources(true);
  }
View Full Code Here


  public boolean isResourceChanged(final Resource resource) {
    notNull(resource, "Invalid resource provided");

    final WroManager manager = getManagerFactory().create();
    final HashStrategy hashStrategy = manager.getHashStrategy();
    final UriLocatorFactory locatorFactory = manager.getUriLocatorFactory();
    // using AtomicBoolean because we need to mutate this variable inside an anonymous class.
    final AtomicBoolean changeDetected = new AtomicBoolean(false);
    try {
      final String fingerprint = hashStrategy.getHash(locatorFactory.locate(resource.getUri()));
      final String previousFingerprint = getBuildContextHolder().getValue(resource.getUri());

      final boolean newValue = fingerprint != null && !fingerprint.equals(previousFingerprint);
      changeDetected.set(newValue);
View Full Code Here

   * @param resource
   *          {@link Resource} to touch.
   */
  public void remember(final Resource resource) {
    final WroManager manager = getManagerFactory().create();
    final HashStrategy hashStrategy = manager.getHashStrategy();
    final UriLocatorFactory locatorFactory = manager.getUriLocatorFactory();

    if (rememberedSet.contains(resource.getUri())) {
      // only calculate fingerprints and check imports if not already done
      getLog().debug("Resource with uri '" + resource.getUri() + "' has already been updated in this run.");
    } else {
      try {
        final String fingerprint = hashStrategy.getHash(locatorFactory.locate(resource.getUri()));
        getBuildContextHolder().setValue(resource.getUri(), fingerprint);
        rememberedSet.add(resource.getUri());
        getLog().debug("Persist fingerprint for resource '" + resource.getUri() + "' : " + fingerprint);
        if (resource.getType() == ResourceType.CSS) {
          final Reader reader = new InputStreamReader(locatorFactory.locate(resource.getUri()));
View Full Code Here

  public void shouldUseConfiguredHashStrategy()
      throws Exception {
    final Properties configProperties = new Properties();
    configProperties.setProperty(ConfigurableHashStrategy.KEY, MD5HashStrategy.ALIAS);
    victim.setConfigProperties(configProperties);
    final HashStrategy actual = ((ConfigurableHashStrategy) victim.create().getHashStrategy()).getConfiguredStrategy();
    assertEquals(MD5HashStrategy.class, actual.getClass());
  }
View Full Code Here

  }
 
  @Test
  public void testCache()
      throws IOException {
    final HashStrategy builder = new CRC32HashStrategy();
    final CacheKey key = new CacheKey("testGroup", ResourceType.JS, false);
   
    final String content = "var foo = 'Hello World';";
    final String hash = builder.getHash(new ByteArrayInputStream(content.getBytes()));
   
    Assert.assertNull(cache.get(key));
   
    cache.put(key, CacheValue.valueOf(content, hash));
   
View Full Code Here

    cache = new LruMemoryCacheStrategy<CacheKey, CacheValue>(3);
  }

  @Test
  public void testLruCache() throws IOException {
    final HashStrategy builder = new CRC32HashStrategy();
    final CacheKey key1 = new CacheKey("testGroup01", ResourceType.JS, false);
    final CacheKey key2 = new CacheKey("testGroup02", ResourceType.CSS, false);
    final CacheKey key3 = new CacheKey("testGroup03", ResourceType.JS, false);
    final CacheKey key4 = new CacheKey("testGroup04", ResourceType.CSS, false);

    final String content = "var foo = 'Hello World';";
    final String hash = builder.getHash(new ByteArrayInputStream(content.getBytes()));

    cache.put(key1, CacheValue.valueOf(content, hash));
    cache.put(key2, CacheValue.valueOf(content, hash));
    cache.put(key3, CacheValue.valueOf(content, hash));
    assertNotNull(cache.get(key1));
View Full Code Here

  @Before
  public void setUp() {
    namingStrategy = new DefaultHashEncoderNamingStrategy() {
      @Override
      protected HashStrategy getHashStrategy() {
        return new HashStrategy() {
          public String getHash(final InputStream inputStream)
              throws IOException {
            return HASH;
          }
        };
View Full Code Here

TOP

Related Classes of ro.isdc.wro.model.resource.support.hash.HashStrategy

Copyright © 2018 www.massapicom. 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.