<commit_before>package se.l4.dust.js.uglify;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.mozilla.javascript.JavaScriptException;

import com.google.inject.Inject;

import se.l4.crayon.Environment;
import se.l4.dust.api.asset.AssetProcessor;
import se.l4.dust.api.resource.MemoryResource;
import se.l4.dust.api.resource.NamedResource;
import se.l4.dust.api.resource.Resource;
import se.l4.dust.js.env.JavascriptEnvironment;

/**
 * Processor that runs UglifyJS on JavaScript files and compresses them. This
 * processor can be used together with asset merging for maximum effect.
 * 
 * @author <NAME>
 *
 */
public class UglifyProcessor
	implements AssetProcessor
{
	private final Environment env;

	@Inject
	public UglifyProcessor(Environment env)
	{
		this.env = env;
	}

	public Resource process(String namespace, String path, Resource in,
			Object... arguments)
		throws IOException
	{
		Environment minimum = Environment.PRODUCTION;
		if(arguments.length > 0)
		{
			if(arguments[0] instanceof Environment)
			{
				minimum = (Environment) arguments[0];
			}
			else
			{
				throw new RuntimeException("Passed unknown argument to UglifyProcessor");
			}
		}
		
		if(minimum == Environment.PRODUCTION && minimum != env)
		{
			/*
			 * Do nothing if we should only run in production, but we are in
			 * development. <commit_msg>Using Stage instead of Environment<commit_after>package se.l4.dust.js.uglify;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.mozilla.javascript.JavaScriptException;

import se.l4.dust.api.asset.AssetProcessor;
import se.l4.dust.api.resource.MemoryResource;
import se.l4.dust.api.resource.NamedResource;
import se.l4.dust.api.resource.Resource;
import se.l4.dust.js.env.JavascriptEnvironment;

import com.google.inject.Inject;
import com.google.inject.Stage;

/**
 * Processor that runs UglifyJS on JavaScript files and compresses them. This
 * processor can be used together with asset merging for maximum effect.
 * 
 * @author <NAME>
 *
 */
public class UglifyProcessor
	implements AssetProcessor
{
	private final Stage stage;

	@Inject
	public UglifyProcessor(Stage stage)
	{
		this.stage = stage;
	}

	public Resource process(String namespace, String path, Resource in,
			Object... arguments)
		throws IOException
	{
		Stage minimum = Stage.PRODUCTION;
		if(arguments.length > 0)
		{
			if(arguments[0] instanceof Stage)
			{
				minimum = (Stage) arguments[0];
			}
			else
			{
				throw new RuntimeException("Passed unknown argument to UglifyProcessor");
			}
		}
		
		if(minimum == Stage.PRODUCTION && minimum != stage)
		{
			/*
			 * Do nothing if we should only run in production, but we are in
			 * development. 
{'fraction_non_alphanumeric': 0.09841954022988506, 'fraction_numerical': 0.006824712643678161, 'mean_word_length': 3.964349376114082, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '4628237', 'n_tokens_mistral': 949, 'n_tokens_neox': 836, 'n_words': 228}