<commit_before>package press;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.IOUtils;
import org.mozilla.javascript.WrappedException;

import play.Logger;
import play.cache.Cache;

import com.asual.lesscss.LessEngine;
import com.asual.lesscss.LessException;

/**
 * Copied and modified from
 * https://github.com/lunatech-labs/play-module-less/blob
 * /master/src/play/modules/less/PlayLessEngine.java LessEngine wrapper for Play
 */
public class PlayLessEngine {

    LessEngine lessEngine;
    static Pattern importPattern = Pattern.compile(".*@import\\s*\"(.*?)\".*");

    PlayLessEngine() {
        lessEngine = new LessEngine();
    }

    /**
     * Get the CSS for this less file either from the cache, or compile it.
     */
    public String get(File lessFile, boolean compress) {
        String cacheKey = "less_" + lessFile.getPath() + latestModified(lessFile);
        String css = cacheGet(cacheKey, String.class);
        if (css == null) {
            css = compile(lessFile, compress);
            cacheSet(cacheKey, css);<commit_msg>use play's VirtualFiles to resolve less imports from modules<commit_after>package press;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.asual.lesscss.LessOptions;
import com.asual.lesscss.loader.ResourceLoader;
import org.apache.commons.io.IOUtils;
import org.mozilla.javascript.WrappedException;

import play.Logger;
import play.Play;
import play.cache.Cache;

import com.asual.lesscss.LessEngine;
import com.asual.lesscss.LessException;
import play.vfs.VirtualFile;

/**
 * Copied and modified from
 * https://github.com/lunatech-labs/play-module-less/blob
 * /master/src/play/modules/less/PlayLessEngine.java LessEngine wrapper for Play
 */
public class PlayLessEngine {

    LessEngine lessEngine;
    static Pattern importPattern = Pattern.compile(".*@import\\s*\"(.*?)\".*");

    PlayLessEngine() {
        lessEngine = new LessEngine(new LessOptions(), new ResourceLoader() {
          @Override public boolean exists(String path) throws IOException {
            return Play.getVirtualFile(path).exists();
          }

          @Override public String load(String path, String charset) throws IOException {
            return Play.getVirtualFile(path.replace(Play.applicationPath.getAbsolutePath() + "/", "")).contentAsString();
          }
        });
    }

    /**
     * Get the CSS for this less file either from the cache, or compile it.
     */
    public String get(File lessFile, boolean compress) {
        String cacheKey = "less_" + lessFile.getPath() + latestModified(lessFile);
        String css = cacheGet(cacheKey, String.class);
        if (css == null) {
            css = compile(lessFile, compress);
            cacheSet(cacheKey, css);
{'fraction_non_alphanumeric': 0.1177007299270073, 'fraction_numerical': 0.0, 'mean_word_length': 3.5807799442896937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '943504', 'n_tokens_mistral': 961, 'n_tokens_neox': 953, 'n_words': 231}