Пример #1
0
 internal static Result fromCMD(CMDCompiler compiler, CompilerOptions options)
 {
     Result result = new Result(options);
     result.Output = compiler.OutputScript;
     result.Errors.AddRange(compiler.getErrors());
     result.Warnings.AddRange(compiler.getWarnings());
     return result;
 }
        /// <summary>
        /// Builds up a string that is sent through the CommandLine google closure compiler.
        /// </summary>
        /// <param name="options">Compiler options that need to be processed</param>
        /// <returns>String containing all the options as needed by the compiler</returns>
        public string Configure(CompilerOptions options)
        {
            string input = getInputFiles(options);

            if (input == String.Empty)
                return String.Empty;

            string extraArgs = getExtraArg(options);
            string output = getOutputFile(options);
            string debug = getDebug(options);
            string compilation_level = getCompilationLevel(options);
            string warning_level = getWarningLevel(options);
            string outputformat = getOutputFormat(options);
            string idemode = getIdeMode(options);
            return debug + compilation_level + extraArgs + warning_level + outputformat + idemode + input + output;
        }
        /// <summary>
        /// Figures out the compilation level from the compiler options.
        /// </summary>
        /// <param name="options"></param>
        /// <returns>Returns --compilation_level string value for the closure compiler consumption</returns>
        private string getCompilationLevel(CompilerOptions options)
        {
            switch (options.CompilerLevel)
            {
                case CompilerOptions.ECompilerLevel.WhiteSpaceOnly:
                    {
                        return " --compilation_level=WHITESPACE_ONLY";
                    }
                case CompilerOptions.ECompilerLevel.SimpleOptimization:
                    {
                        return " --compilation_level=SIMPLE_OPTIMIZATIONS";
                    }
                case CompilerOptions.ECompilerLevel.AdvancedOptimization:
                    {
                        return " --compilation_level=ADVANCED_OPTIMIZATIONS";
                    }
                default:
                    {
                        break;
                    }
            }

            return String.Empty;
        }
Пример #4
0
        public Result Compile(CompilerOptions options)
        {
            OutputScript = String.Empty;
            Errors.Clear();
            Warnings.Clear();
            Failures.Clear();

            string command = CMDCompilerOptions.Instance.Configure(options);

            if (command != String.Empty)
            {
                var file = createConfigFile(command);
                CompilerState = ECompileState.Running;
                Java.Run("-jar \"" + CMDCompiler.Closure + "\"" + " --flagfile=\"" + file + "\"", compile_OutputDataReceived, compile_ErrorDataReceived);
                File.Delete(file);
                CompilerState = ECompileState.Finished;
            }

            return Result.fromCMD(this, options);;
        }
 /// <summary>
 /// Process the argument string and returns a jsCompiler ready string
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 private string getExtraArg(CompilerOptions options)
 {
     string result = options.ExtraArgs.Trim();
     return result.Length != 0 ? " " + result : String.Empty;
 }
 /// <summary>
 /// Sets the debug flag in the closure compiler
 /// </summary>
 /// <param name="options"></param>
 /// <returns>If enabled, the string --debug closure options.  Otherwise nothing.</returns>
 private string getDebug(CompilerOptions options)
 {
     if (options.Debug == true)
         return " --debug";
     return String.Empty;
 }
        private string getWarningLevel(CompilerOptions options)
        {
            switch (options.WarningLevel)
            {
                case CompilerOptions.EWarningLevel.Quiet:
                    {
                        return " --warning_level=QUIET";
                    }
                case CompilerOptions.EWarningLevel.Verbose:
                    {
                        return " --warning_level=VERBOSE";
                    }
                default:
                    {
                        break;
                    }
            }

            return String.Empty;
        }
        private string getOutputFormat(CompilerOptions options)
        {
            switch (options.OutputFormatting)
            {
                case CompilerOptions.EOutputFormatting.PrettyPrint:
                    {
                        return " --formatting=PRETTY_PRINT";
                    }
                case CompilerOptions.EOutputFormatting.PrintInputDelimeter:
                    {
                        return " --formatting=PRINT_INPUT_DELIMITER";
                    }
                default:
                    {
                        break;
                    }
            }

            return String.Empty;
        }
 /// <summary>
 /// Extracts the output file, if one is provided, and applies the proper closure
 /// compiler flag.  If no outfile file is provided, then we don't provide anything
 /// to the closure compiler, which result in sending the resulting JS to the stdout.
 /// </summary>
 /// <param name="options"></param>
 /// <returns>js file name with the --js_output_file closure options</returns>
 private string getOutputFile(CompilerOptions options)
 {
     if (options.OutputFile != String.Empty)
         return " --js_output_file=\"" + options.OutputFile + "\"";
     return String.Empty;
 }
        /// <summary>
        /// Takes in an array of files and appends the --js required by the
        /// closure compiler.
        /// </summary>
        /// <param name="files">List of files that need processing</param>
        /// <returns>List of files with the --js closure setting</returns>
        private string getInputFiles(CompilerOptions options)
        {
            if (options.InputFiles.Count == 0)
                return String.Empty;

            StringBuilder result = new StringBuilder(5084);
            for (int iFile = 0, length = options.InputFiles.Count; iFile < length; iFile++)
                result.Append(" --js=\"" + options.InputFiles[iFile] + "\"");
            return result.ToString();
        }
 private string getIdeMode(CompilerOptions options)
 {
     return " --ideMode=" + options.IdeMode.ToString().ToLower();
 }
Пример #12
0
        internal static Result fromJNI(com.google.javascript.jscomp.Compiler compiler, com.google.javascript.jscomp.Result gcResult, CompilerOptions options)
        {
            Result result = new Result(options);

            result.Output = compiler.toSource();

            com.google.javascript.jscomp.JSError[] errors = compiler.getErrors();
            for (int index = 0, length = errors.Length; index < length; index++)
            {
                com.google.javascript.jscomp.JSError error = errors[index];
                result.Errors.Add(new Error(error.sourceName, error.description, error.getLineNumber(), error.getCharno(), Error.ESeverity.High));
            }

            com.google.javascript.jscomp.JSError[] warnings = compiler.getWarnings();
            for (int index = 0, length = warnings.Length; index < length; index++)
            {
                com.google.javascript.jscomp.JSError warning = warnings[index];
                result.Warnings.Add(new Error(warning.sourceName, warning.description, warning.getLineNumber(), warning.getCharno(), Error.ESeverity.Medium));
            }

            return result;
        }
Пример #13
0
 private Result(CompilerOptions options)
 {
     _Errors = new List<Error>();
     _Warnings = new List<Error>();
     _Options = options;
 }
Пример #14
0
 /// <summary>
 /// Invokes the google closure compiler with the provided options.  At the very least,
 /// a list of JavaScript files need to be provided.
 /// </summary>
 /// <param name="options">CompilerOptions for the google closure compiler.</param>
 /// <returns>Result object, which has the compiled JavaScript, Warnings and Errors</returns>
 /// 
 public jsCompiler.Core.Result Compile(CompilerOptions options)
 {
     return gcCompiler.Compile(options);
 }
Пример #15
0
        public Result Compile(CompilerOptions options)
        {
            com.google.javascript.jscomp.CompilerOptions gcOptions = jsCompiler.Core.JNICompilerOptions.Instance.Configure(options);

            com.google.javascript.jscomp.JSSourceFile[] gcInputFile = jsCompiler.gcBridge.SourceFiles.Configure(options);
            com.google.javascript.jscomp.JSSourceFile[] gcExternFile = jsCompiler.gcBridge.ExternFiles.Configure(options);

            // Compile the source...
            com.google.javascript.jscomp.Result gcResult = gcCompiler.compile(gcExternFile, gcInputFile, gcOptions);
            Result result = Result.fromJNI(gcCompiler, gcResult, options);

            // We set this to null so that we get a new instance when we compile source again.
            gcCompiler = null;
            return result;
        }