@Override
	public String compress(String source) {
		
		StringWriter writer = new StringWriter();
		
		//prepare source
		List<JSSourceFile> input = new ArrayList<JSSourceFile>();
		input.add(JSSourceFile.fromCode("source.js", source));
		
		//prepare externs
		List<JSSourceFile> externsList = new ArrayList<JSSourceFile>();
		if(compilationLevel.equals(CompilationLevel.ADVANCED_OPTIMIZATIONS)) {
			//default externs
			if(!customExternsOnly) {
				try {
					externsList = getDefaultExterns();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			//add user defined externs
			if(externs != null) {
				for(JSSourceFile extern : externs) {
					externsList.add(extern);
				}
			}
			//add empty externs
			if(externsList.size() == 0) {
				externsList.add(JSSourceFile.fromCode("externs.js", ""));
			}
		} else {
			//empty externs
			externsList.add(JSSourceFile.fromCode("externs.js", ""));
		}
		
		Compiler.setLoggingLevel(loggingLevel);
		
		Compiler compiler = new Compiler();
		compiler.disableThreads();
		
		compilationLevel.setOptionsForCompilationLevel(compilerOptions);
		warningLevel.setOptionsForWarningLevel(compilerOptions);
		
		Result result = compiler.compile(externsList, input, compilerOptions);
		
		if (result.success) {
			writer.write(compiler.toSource());
		} else {
			writer.write(source);
		}

		return writer.toString();

	}