private static string GetArguments(string fileName, ClosureCompilerCompressMode compressMode, IList<string> referencePathsOrUrls, string customArgument) { if (String.IsNullOrEmpty(customArgument)) { customArgument = "--warning_level QUIET"; } return string.Format("--js \"{0}\" --compilation_level {1} {2}", fileName, compressMode, customArgument); }
private static string GetArguments(string fileName, ClosureCompilerCompressMode compressMode, IList<string> referencePathsOrUrls, string customArgument) { if (String.IsNullOrEmpty(customArgument)) { customArgument = "--warning_level QUIET"; } return string.Format("--js \"{0}\" --compilation_level {1} {2}", fileName, compressMode, customArgument); }
public static string Compress(string fileName, ClosureCompilerCompressMode compressMode, Action<Microsoft.VisualStudio.Shell.TaskErrorCategory, string, int, int> onError, IList<string> referencePathsOrUrls, string customArgument) { if (!File.Exists(fileName)) { throw new FileNotFoundException("File does not exist: " + fileName); } string toCall = string.Format("-jar \"{0}\" {1}", GetJarPath(), GetArguments(fileName, compressMode, referencePathsOrUrls, customArgument)); string error = string.Empty; string output = string.Empty; try { using (var process = Process.Start(Settings.Instance(fileName).GoogleClosureJavaPath, toCall)) { process.StartInfo.CreateNoWindow = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = process.StartInfo.RedirectStandardError = true; process.Start(); output = process.StandardOutput.ReadToEnd(); error = process.StandardError.ReadToEnd(); if (!process.HasExited) { process.Kill(); } } } catch (Exception e) { onError(Microsoft.VisualStudio.Shell.TaskErrorCategory.Error, "Java error : " + e.ToString(), 0, 0); } if (!string.IsNullOrEmpty(error)) { onError(Microsoft.VisualStudio.Shell.TaskErrorCategory.Error, "Google Closure Compiler error : " + error, 0, 0); return string.Empty; } return output; }
public static string Compress(string fileName, ClosureCompilerCompressMode compressMode, Action<Microsoft.VisualStudio.Shell.TaskErrorCategory, string, int, int> onError, IList<string> referencePathsOrUrls, string customArgument) { if (!File.Exists(fileName)) { throw new FileNotFoundException("File does not exist: " + fileName); } string toCall = string.Format("-jar \"{0}\" {1}", GetJarPath(), GetArguments(fileName, compressMode, referencePathsOrUrls, customArgument)); string error = string.Empty; string output = string.Empty; try { using (var process = Process.Start(Settings.Instance(fileName).GoogleClosureJavaPath, toCall)) { process.StartInfo.CreateNoWindow = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = process.StartInfo.RedirectStandardError = true; process.Start(); output = process.StandardOutput.ReadToEnd(); error = process.StandardError.ReadToEnd(); if (!process.HasExited) { process.Kill(); } } } catch (Exception e) { onError(Microsoft.VisualStudio.Shell.TaskErrorCategory.Error, "Java error : " + e.ToString(), 0, 0); } if (!string.IsNullOrEmpty(error)) { onError(Microsoft.VisualStudio.Shell.TaskErrorCategory.Error, "Google Closure Compiler error : " + error, 0, 0); return string.Empty; } return output; }
public static string Compress(string fileName, string js, ClosureCompilerCompressMode compressMode, Action<Microsoft.VisualStudio.Shell.TaskErrorCategory, string, int, int> onError, string customArgument) { // Create temp file with JS content. string tempFile = fileName + ".tmp.js"; using (var file = System.IO.File.CreateText(tempFile)) { file.Write(js); } try { return Compress(tempFile, compressMode, onError, null, customArgument); } finally { // Delete temp file. try { System.IO.File.Delete(tempFile); } catch { } } }
public static string Minify(string fullFileName, string text, ProjectItem projectItem, ClosureCompilerCompressMode mode, string customArgument) { string returnedCode = null; returnedCode = GoogleClosureCompiler.Compress( fullFileName, text, mode, (category, msg, line, col) => { if (TaskList.Instance == null) { Console.WriteLine(string.Format("{0}({1},{2}){3}", fullFileName, line.ToString(), col.ToString(), msg)); } else { TaskList.Instance.Add(projectItem.ContainingProject, category, fullFileName, line, col, msg); } }, customArgument ); return returnedCode; }
/// <summary> /// Compresses the specified file using Google's Closure Compiler algorithm. /// <remarks> /// The file to compress must be smaller than 200,000 bytes. /// </remarks> /// </summary> /// <param name="fullFileName">Full filename.</param> /// <param name="js">javascript to compiler.</param> /// <param name="compressMode">SIMPLE_OPTIMIZATIONS, WHITESPACE_ONLY, ADVANCED_OPTIMIZATIONS</param> /// <param name="onError">Error event</param> /// <returns>A compressed version of the specified JavaScript file.</returns> public static string Compress(string fullFileName, string js, ClosureCompilerCompressMode compressMode, Action <Microsoft.VisualStudio.Shell.TaskErrorCategory, string, int, int> onError, string customArgument) { if (string.IsNullOrEmpty(js)) { return(string.Empty); } var settings = Settings.Instance(fullFileName); if (!string.IsNullOrEmpty(settings.GoogleClosureJavaPath) && settings.GoogleClosureOffline) { return(GoogleClosureOfflineCompiler.Compress( fullFileName, js, compressMode, onError, customArgument)); } long size = js.Length; if (size < 200000) { XmlDocument xml = CallApi(js, compressMode.ToString()); if (xml == null) { return(GoogleClosureOfflineCompiler.Compress( fullFileName, js, compressMode, onError, customArgument)); } // valid have server error XmlNodeList nodeServerError = xml.SelectNodes("//serverErrors"); if (nodeServerError.Count > 0) { string errorText = string.Empty; foreach (XmlNode node in nodeServerError) { if (!string.IsNullOrEmpty(errorText)) { errorText += System.Environment.NewLine; } errorText += node.InnerText; onError(Microsoft.VisualStudio.Shell.TaskErrorCategory.Error, "Server error : " + node.InnerText, 1, 1); } } // valid have Javascript error XmlNodeList nodeError = xml.SelectNodes("//errors"); if (nodeError.Count > 0) { string errorText = string.Empty; foreach (XmlNode node in nodeError) { if (!string.IsNullOrEmpty(errorText)) { errorText += System.Environment.NewLine; } if (node.Attributes["lineno"] == null && node.Attributes["charno"] == null) { errorText += node.InnerText; } else { errorText += string.Format( "type: {0} Line : {1} Char : {2} Error : {3}", node.Attributes["type"] != null ? node.Attributes["type"].ToString() : string.Empty, node.Attributes["lineno"] != null ? node.Attributes["lineno"].ToString() : string.Empty, node.Attributes["charno"] != null ? node.Attributes["charno"].ToString() : string.Empty, node.InnerText); } string taskErrorText = string.Format( "Type: {0} Error : {1}", node.Attributes["type"] != null ? node.Attributes["type"].ToString() : "General", node.InnerText); onError( Microsoft.VisualStudio.Shell.TaskErrorCategory.Error, taskErrorText, (node.Attributes["lineno"] != null ? node.Attributes["lineno"].ToString() : string.Empty).ToInt(1), (node.Attributes["charno"] != null ? node.Attributes["charno"].ToString() : string.Empty).ToInt(1)); } } return(xml.SelectSingleNode("//compiledCode").InnerText); } else { // file too large (use YUI compressor) string exceptionMessage = "file size too large for Google: " + size.ToString("#,#"); onError(Microsoft.VisualStudio.Shell.TaskErrorCategory.Warning, exceptionMessage, 1, 1); var compressor = new JavaScriptCompressor(); return("//" + exceptionMessage + Environment.NewLine + compressor.Compress(js)); } }
private static string GetArguments(string fileName, ClosureCompilerCompressMode compressMode, IList<string> referencePathsOrUrls) { return GetArguments(fileName, compressMode, referencePathsOrUrls, "--warning_level QUIET"); }
public static string Compress(string fileName, ClosureCompilerCompressMode compressMode, Action<Microsoft.VisualStudio.Shell.TaskErrorCategory, string, int, int> onError,string customArgument) { return Compress(fileName, compressMode, onError, null, customArgument); }
public static string Minify(string fullFileName, string text, ProjectItem projectItem, ClosureCompilerCompressMode mode, string customArgument) { string returnedCode = null; returnedCode = GoogleClosureCompiler.Compress( fullFileName, text, mode, (category, msg, line, col) => { if (TaskList.Instance == null) { Console.WriteLine(string.Format("{0}({1},{2}){3}", fullFileName, line.ToString(), col.ToString(), msg)); } else { TaskList.Instance.Add(projectItem.ContainingProject, category, fullFileName, line, col, msg); } }, customArgument ); return(returnedCode); }
private static string GetArguments(string fileName, ClosureCompilerCompressMode compressMode, IList<string> referencePathsOrUrls) { return GetArguments(fileName, compressMode, referencePathsOrUrls, "--warning_level QUIET"); }
public static string Compress(string fileName, ClosureCompilerCompressMode compressMode, Action<Microsoft.VisualStudio.Shell.TaskErrorCategory, string, int, int> onError,string customArgument) { return Compress(fileName, compressMode, onError, null, customArgument); }
/// <summary> /// Compresses the specified file using Google's Closure Compiler algorithm. /// <remarks> /// The file to compress must be smaller than 200,000 bytes. /// </remarks> /// </summary> /// <param name="fullFileName">Full filename.</param> /// <param name="js">javascript to compiler.</param> /// <param name="compressMode">SIMPLE_OPTIMIZATIONS, WHITESPACE_ONLY, ADVANCED_OPTIMIZATIONS</param> /// <param name="onError">Error event</param> /// <returns>A compressed version of the specified JavaScript file.</returns> public static string Compress(string fullFileName, string js, ClosureCompilerCompressMode compressMode, Action<Microsoft.VisualStudio.Shell.TaskErrorCategory, string, int, int> onError, string customArgument) { if (string.IsNullOrEmpty(js)) { return string.Empty; } var settings = Settings.Instance(fullFileName); if (!string.IsNullOrEmpty(settings.GoogleClosureJavaPath) && settings.GoogleClosureOffline) { return GoogleClosureOfflineCompiler.Compress( fullFileName, compressMode, onError, customArgument); } long size = js.Length; if (size < 200000) { XmlDocument xml = CallApi(js, compressMode.ToString()); if (xml == null) { return GoogleClosureOfflineCompiler.Compress( fullFileName, compressMode, onError, customArgument); } // valid have server error XmlNodeList nodeServerError = xml.SelectNodes("//serverErrors"); if (nodeServerError.Count > 0) { string errorText = string.Empty; foreach (XmlNode node in nodeServerError) { if (!string.IsNullOrEmpty(errorText)) { errorText += System.Environment.NewLine; } errorText += node.InnerText; onError(Microsoft.VisualStudio.Shell.TaskErrorCategory.Error, "Server error : " + node.InnerText, 1, 1); } } // valid have Javascript error XmlNodeList nodeError = xml.SelectNodes("//errors"); if (nodeError.Count > 0) { string errorText = string.Empty; foreach (XmlNode node in nodeError) { if (!string.IsNullOrEmpty(errorText)) { errorText += System.Environment.NewLine; } if (node.Attributes["lineno"] == null && node.Attributes["charno"] == null) { errorText += node.InnerText; } else { errorText += string.Format( "type: {0} Line : {1} Char : {2} Error : {3}", node.Attributes["type"] != null ? node.Attributes["type"].ToString() : string.Empty, node.Attributes["lineno"] != null ? node.Attributes["lineno"].ToString() : string.Empty, node.Attributes["charno"] != null ? node.Attributes["charno"].ToString() : string.Empty, node.InnerText); } string taskErrorText = string.Format( "Type: {0} Error : {1}", node.Attributes["type"] != null ? node.Attributes["type"].ToString() : "General", node.InnerText); onError( Microsoft.VisualStudio.Shell.TaskErrorCategory.Error, taskErrorText, (node.Attributes["lineno"] != null ? node.Attributes["lineno"].ToString() : string.Empty).ToInt(1), (node.Attributes["charno"] != null ? node.Attributes["charno"].ToString() : string.Empty).ToInt(1)); } } return xml.SelectSingleNode("//compiledCode").InnerText; } else { // file too large (use YUI compressor) string exceptionMessage = "file size too large for Google: " + size.ToString("#,#"); onError(Microsoft.VisualStudio.Shell.TaskErrorCategory.Warning, exceptionMessage, 1, 1); return "//" + exceptionMessage + Environment.NewLine + JavaScriptCompressor.Compress(js); } }