Projects >> wro4j >>44122481e5afcac92be26bc9d41aff63e226fda6

Chunk
Conflicting content
import javax.servlet.ServletContext;

<<<<<<< HEAD
import ro.isdc.wro.cache.CacheChangeCallbackAware;
=======
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

>>>>>>> b106e2af8883ce4072b978287d3ccffbda092452
import ro.isdc.wro.cache.CacheEntry;
import ro.isdc.wro.cache.CacheStrategy;
import ro.isdc.wro.cache.ContentHashEntry;
Solution content
import javax.servlet.ServletContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ro.isdc.wro.cache.CacheChangeCallbackAware;
import ro.isdc.wro.cache.CacheEntry;
import ro.isdc.wro.cache.CacheStrategy;
import ro.isdc.wro.cache.ContentHashEntry;
File
BaseWroManagerFactory.java
Developer's decision
Concatenation
Kind of conflict
Import
Chunk
Conflicting content
   * @return {@link WroModelFactory} implementation
   */
  protected WroModelFactory newModelFactory() {
<<<<<<< HEAD
    return new XmlModelFactory() {
      /**
       * This factory will run properly only when is used inside a web application. The configuration xml file will be
       * read from the following location: /WEB-INF/wro.xml
       */
      @Override
      protected ResourceLocator getModelResourceLocator() {
        return new ServletContextResourceLocator(Context.get().getServletContext(), "/WEB-INF/" + XML_CONFIG_FILE);
      }
    };
=======
    try {
      LOG.info("Trying to use SmartWroModelFactory as default model factory");
      final Class smartFactoryClass = Class.forName(
        "ro.isdc.wro.extensions.model.factory.SmartWroModelFactory").asSubclass(WroModelFactory.class);
      return smartFactoryClass.newInstance();
    } catch (final Exception e) {
      LOG.info("SmartWroModelFactory is not available. Using default model factory: " + e.getMessage());
    }
    return new ServletContextAwareXmlModelFactory();
>>>>>>> b106e2af8883ce4072b978287d3ccffbda092452
  }

Solution content
   * @return {@link WroModelFactory} implementation
   */
  protected WroModelFactory newModelFactory() {
    try {
      LOG.info("Trying to use SmartWroModelFactory as default model factory");
      final Class smartFactoryClass = Class.forName(
        "ro.isdc.wro.extensions.model.factory.SmartWroModelFactory").asSubclass(WroModelFactory.class);
      return smartFactoryClass.newInstance();
    } catch (final Exception e) {
      LOG.info("SmartWroModelFactory is not available. Using default model factory: " + e.getMessage());
    }
    return new XmlModelFactory() {
      /**
       * This factory will run properly only when is used inside a web application. The configuration xml file will be
       * read from the following location: /WEB-INF/wro.xml
       */
      @Override
      protected ResourceLocator getModelResourceLocator() {
        return new ServletContextResourceLocator(Context.get().getServletContext(), "/WEB-INF/" + XML_CONFIG_FILE);
      }
    };
  }

File
BaseWroManagerFactory.java
Developer's decision
Combination
Kind of conflict
Method invocation
Return statement
Try statement
Chunk
Conflicting content
  public WroModel create() {
    try {
      final Type type = new TypeToken() {}.getType();
<<<<<<< HEAD:wro4j-extensions/src/main/java/ro/isdc/wro/extensions/model/factory/JsonModelFactory.java
      final InputStream is = getModelResourceLocator().getInputStream();
      if (is == null) {
        throw new WroRuntimeException("Invalid model stream provided!");
      }
      final WroModel model = new Gson().fromJson(new InputStreamReader(is), type);
=======
      final InputStream is = getConfigResourceAsStream();
      if (is == null) {
        throw new WroRuntimeException("Invalid model stream provided!");
      }
      final WroModel model = new Gson().fromJson(new InputStreamReader(getConfigResourceAsStream()), type);
>>>>>>> b106e2af8883ce4072b978287d3ccffbda092452:wro4j-extensions/src/main/java/ro/isdc/wro/extensions/model/factory/JsonWroModelFactory.java
      LOG.debug("json model: {}", model);
      if (model == null) {
        throw new WroRuntimeException("Invalid content provided, cannot build model!");
Solution content
  public WroModel create() {
    try {
      final Type type = new TypeToken() {}.getType();
      final InputStream is = getModelResourceLocator().getInputStream();
      if (is == null) {
        throw new WroRuntimeException("Invalid model stream provided!");
      }
      final WroModel model = new Gson().fromJson(new InputStreamReader(is), type);
      LOG.debug("json model: {}", model);
      if (model == null) {
        throw new WroRuntimeException("Invalid content provided, cannot build model!");
File
JsonWroModelFactory.java
Developer's decision
Version 1
Kind of conflict
If statement
Method invocation
Variable
Chunk
Conflicting content
    }
  }

<<<<<<< HEAD:wro4j-extensions/src/main/java/ro/isdc/wro/extensions/model/factory/JsonModelFactory.java
  protected ResourceLocator getModelResourceLocator() {
    return new ClasspathResourceLocator("wro.json");
=======
  /**
   * Override this method, in order to provide different json model location.
   *
   * @return stream of the json representation of the model.
   * @throws IOException if the stream couldn't be read.
   */
  protected InputStream getConfigResourceAsStream() throws IOException {
    return getClass().getResourceAsStream("wro.json");
>>>>>>> b106e2af8883ce4072b978287d3ccffbda092452:wro4j-extensions/src/main/java/ro/isdc/wro/extensions/model/factory/JsonWroModelFactory.java
  }

  /**
Solution content
    }
  }

  protected ResourceLocator getModelResourceLocator() {
    return new ClasspathResourceLocator("wro.json");
  }

  /**
File
JsonWroModelFactory.java
Developer's decision
Version 1
Kind of conflict
Comment
Method invocation
Method signature
Return statement
Chunk
Conflicting content
  public void testInvalidStream() throws Exception {
    factory = new JsonWroModelFactory() {
      @Override
<<<<<<< HEAD:wro4j-extensions/src/test/java/ro/isdc/wro/extensions/model/factory/TestJsonModelFactory.java
      protected ResourceLocator getModelResourceLocator() {
        return new ClasspathResourceLocator("INVALID.json");
=======
      protected InputStream getConfigResourceAsStream()
        throws IOException {
        throw new IOException();
>>>>>>> b106e2af8883ce4072b978287d3ccffbda092452:wro4j-extensions/src/test/java/ro/isdc/wro/extensions/model/factory/TestJsonWroModelFactory.java
      };
    };
    factory.create();
Solution content
  public void testInvalidStream() throws Exception {
    factory = new JsonWroModelFactory() {
      @Override
      protected ResourceLocator getModelResourceLocator() {
        return new ClasspathResourceLocator("INVALID.json");
      };
    };
    factory.create();
File
TestJsonWroModelFactory.java
Developer's decision
Version 1
Kind of conflict
Method invocation
Method signature
Return statement
Throw statement
Chunk
Conflicting content
  public void testInvalidContent() {
    factory = new JsonWroModelFactory() {
      @Override
<<<<<<< HEAD:wro4j-extensions/src/test/java/ro/isdc/wro/extensions/model/factory/TestJsonModelFactory.java
      protected ResourceLocator getModelResourceLocator() {
        return new AbstractResourceLocator() {
          @Override
          public InputStream getInputStream()
            throws IOException {
            return new ByteArrayInputStream("".getBytes());
          }
        };
=======
      protected InputStream getConfigResourceAsStream() throws IOException {
        return new ByteArrayInputStream("".getBytes());
>>>>>>> b106e2af8883ce4072b978287d3ccffbda092452:wro4j-extensions/src/test/java/ro/isdc/wro/extensions/model/factory/TestJsonWroModelFactory.java
      };
    };
    Assert.assertNull(factory.create());
Solution content
  public void testInvalidContent() {
    factory = new JsonWroModelFactory() {
      @Override
      protected ResourceLocator getModelResourceLocator() {
        return new AbstractResourceLocator() {
          @Override
          public InputStream getInputStream()
            throws IOException {
            return new ByteArrayInputStream("".getBytes());
          }
        };
      };
    };
    Assert.assertNull(factory.create());
File
TestJsonWroModelFactory.java
Developer's decision
Version 1
Kind of conflict
Method invocation
Method signature
Return statement
Chunk
Conflicting content
  @Test
  public void createValidModel() {
<<<<<<< HEAD:wro4j-extensions/src/test/java/ro/isdc/wro/extensions/model/factory/TestJsonModelFactory.java
    factory = new JsonModelFactory() {
      @Override
      protected ResourceLocator getModelResourceLocator() {
        return new UrlResourceLocator(TestJsonModelFactory.class.getResource("wro.json"));
      };
    };
=======
    factory = new JsonWroModelFactory();
>>>>>>> b106e2af8883ce4072b978287d3ccffbda092452:wro4j-extensions/src/test/java/ro/isdc/wro/extensions/model/factory/TestJsonWroModelFactory.java
    final WroModel model = factory.create();
    Assert.assertNotNull(model);
    Assert.assertEquals(Arrays.asList("g2", "g1"), model.getGroupNames());
Solution content
  @Test
  public void createValidModel() {
    factory = new JsonModelFactory() {
      @Override
      protected ResourceLocator getModelResourceLocator() {
        return new UrlResourceLocator(TestJsonModelFactory.class.getResource("wro.json"));
      };
    };
    final WroModel model = factory.create();
    Assert.assertNotNull(model);
    Assert.assertEquals(Arrays.asList("g2", "g1"), model.getGroupNames());
File
TestJsonWroModelFactory.java
Developer's decision
Version 1
Kind of conflict
Attribute
Method invocation
Chunk
Conflicting content
  public void createIncompleteModel() {
    factory = new JsonWroModelFactory() {
      @Override
<<<<<<< HEAD:wro4j-extensions/src/test/java/ro/isdc/wro/extensions/model/factory/TestJsonModelFactory.java
      protected ResourceLocator getModelResourceLocator() {
        return new UrlResourceLocator(TestJsonModelFactory.class.getResource("incomplete-wro.json"));
=======
      protected InputStream getConfigResourceAsStream() throws IOException {
        return getClass().getResourceAsStream("incomplete-wro.json");
>>>>>>> b106e2af8883ce4072b978287d3ccffbda092452:wro4j-extensions/src/test/java/ro/isdc/wro/extensions/model/factory/TestJsonWroModelFactory.java
      };
    };
    final WroModel model = factory.create();
Solution content
  public void createIncompleteModel() {
    factory = new JsonWroModelFactory() {
      @Override
      protected ResourceLocator getModelResourceLocator() {
        return new UrlResourceLocator(TestJsonModelFactory.class.getResource("incomplete-wro.json"));
      };
    };
    final WroModel model = factory.create();
File
TestJsonWroModelFactory.java
Developer's decision
Version 1
Kind of conflict
Method invocation
Method signature
Return statement