Пример #1
0
		public ConsoleProgressMonitor (TextWriter writer, bool leaveOpen)
		{
			this.writer = writer;
			this.leaveOpen = leaveOpen;
			logger = new LogTextWriter ();
			logger.TextWritten += WriteLog;
		}
Пример #2
0
 public ConsoleProgressMonitor(TextWriter writer, bool leaveOpen)
 {
     this.writer         = writer;
     this.leaveOpen      = leaveOpen;
     logger              = new LogTextWriter();
     logger.TextWritten += WriteLog;
 }
		static void EnableFileLogging ( )
		{
			if (Path.DirectorySeparatorChar != '\\')
				return;

			// On Windows log all output to a log file

			string configPath = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
			configPath = Path.Combine (configPath, "MonoDevelop");
			if (!Directory.Exists (configPath))
				Directory.CreateDirectory (configPath);

			string file = Path.Combine (configPath, "log.txt");
			try {
				logFile = new StreamWriter (file);
				logFile.AutoFlush = true;

				LogTextWriter tw = new LogTextWriter ();
				tw.ChainWriter (logFile);
				tw.ChainWriter (Console.Out);
				Console.SetOut (tw);

				tw = new LogTextWriter ();
				tw.ChainWriter (logFile);
				tw.ChainWriter (Console.Error);
				Console.SetError (tw);
			}
			catch {
			}
		}
		static void EnableFileLogging ( )
		{
			if (Path.DirectorySeparatorChar != '\\')
				return;

			// On Windows log all output to a log file

			FilePath logDir = UserProfile.Current.LogDir;
			if (!Directory.Exists (logDir))
				Directory.CreateDirectory (logDir);

			string file = logDir.Combine ("log.txt");
			try {
				logFile = new StreamWriter (file);
				logFile.AutoFlush = true;

				LogTextWriter tw = new LogTextWriter ();
				tw.ChainWriter (logFile);
				tw.ChainWriter (Console.Out);
				Console.SetOut (tw);

				tw = new LogTextWriter ();
				tw.ChainWriter (logFile);
				tw.ChainWriter (Console.Error);
				Console.SetError (tw);
			}
			catch {
			}
		}
Пример #5
0
		static void EnableFileLogging ( )
		{
			if (Path.DirectorySeparatorChar != '\\')
				return;

			// On Windows log all output to a log file

            string configPath = PropertyService.ConfigPath;
			if (!Directory.Exists (configPath))
				Directory.CreateDirectory (configPath);

			string file = Path.Combine (configPath, "log.txt");
			try {
				logFile = new StreamWriter (file);
				logFile.AutoFlush = true;

				LogTextWriter tw = new LogTextWriter ();
				tw.ChainWriter (logFile);
				tw.ChainWriter (Console.Out);
				Console.SetOut (tw);

				tw = new LogTextWriter ();
				tw.ChainWriter (logFile);
				tw.ChainWriter (Console.Error);
				Console.SetError (tw);
			}
			catch {
			}
		}
		public AggregatedProgressMonitor (IProgressMonitor masterMonitor, params IProgressMonitor[] slaveMonitors)
		{
			this.masterMonitor = masterMonitor;
			AddSlaveMonitor (masterMonitor, MonitorAction.All);
			logger = new LogTextWriter ();
			logger.TextWritten += new LogTextEventHandler (OnWriteLog);
			foreach (IProgressMonitor mon in slaveMonitors)
				AddSlaveMonitor (mon);
		}
Пример #7
0
 public AggregatedProgressMonitor(IProgressMonitor masterMonitor, params IProgressMonitor[] slaveMonitors)
 {
     this.masterMonitor = masterMonitor;
     AddSlaveMonitor(masterMonitor, MonitorAction.All);
     logger              = new LogTextWriter();
     logger.TextWritten += new LogTextEventHandler(OnWriteLog);
     foreach (IProgressMonitor mon in slaveMonitors)
     {
         AddSlaveMonitor(mon);
     }
 }
Пример #8
0
		/// <summary>Executes a build command, writing output to the monitor.</summary>
		/// <returns>Whether the command executed successfully.</returns>
		/// <param name='monitor'>Progress monitor for writing output and handling cancellation.</param>
		/// <param name='startInfo'>Process start info. Redirection will be enabled if necessary.</param>
		/// <param name='stdout'>Text writer for stdout. May be null.</param>
		/// <param name='stderr'>Text writer for stderr. May be null.</param>
		public static int ExecuteBuildCommand (IProgressMonitor monitor, ProcessStartInfo startInfo,
			TextWriter stdout, TextWriter stderr)
		{
			monitor.Log.WriteLine (startInfo.FileName + " " + startInfo.Arguments);
			
			startInfo.UseShellExecute = false;
			startInfo.RedirectStandardError = true;
			startInfo.RedirectStandardOutput = true;
			
			int exitCode = -1;
			
			TextWriter outWriter = monitor.Log, errWriter = monitor.Log;
			LogTextWriter chainedOut = null, chainedErr = null;
			
			if (stdout != null) {
				chainedOut = new LogTextWriter ();
				chainedOut.ChainWriter (outWriter);
				chainedOut.ChainWriter (stdout);
				outWriter = chainedOut;
			}
			
			if (stderr != null) {
				chainedErr = new LogTextWriter ();
				chainedErr.ChainWriter (errWriter);
				chainedErr.ChainWriter (stderr);
				errWriter = chainedErr;
			}
			
			var operationMonitor = new AggregatedOperationMonitor (monitor);
			
			IProcessAsyncOperation p = null;
			try {
				p = Runtime.ProcessService.StartProcess (startInfo, outWriter, errWriter, null);
				operationMonitor.AddOperation (p); //handles cancellation
				p.WaitForCompleted ();
				exitCode = p.ExitCode;
			} finally {
				if (chainedErr != null)
					chainedErr.Dispose ();
				if (chainedOut != null)
					chainedOut.Dispose ();
				if (p != null)
					p.Dispose ();
				operationMonitor.Dispose ();
			}
			
			if (exitCode != 0)
				monitor.Log.WriteLine ("{0} exited with code {1}", Path.GetFileName (startInfo.FileName), exitCode);
			
			return exitCode;
		}
		public bool Deploy ( DeployContext ctx, Solution solution, string defaultConf, string targetDir, bool generateFiles, IProgressMonitor monitor  )
		{
			if (generateFiles) {
				if ( !GenerateFiles ( ctx, solution, defaultConf, monitor ) ) 
					return false;
			}
			
			monitor.BeginTask ( GettextCatalog.GetString( "Deploying Solution to Tarball" ) , 3 );
			try
			{
				string baseDir = Path.GetDirectoryName ( solution.FileName);
	
				ProcessWrapper ag_process = Runtime.ProcessService.StartProcess ( "sh", 
						generateAutotools ? "autogen.sh" : "configure",
						baseDir, 
						monitor.Log, 
						monitor.Log, 
						null );
				ag_process.WaitForOutput ();
				
				if ( ag_process.ExitCode > 0 )
					throw new Exception ( GettextCatalog.GetString ("An unspecified error occurred while running '{0}'", generateAutotools ? "autogen.sh" : "configure") );
				
				monitor.Step ( 1 );

				StringWriter sw = new StringWriter ();
				LogTextWriter chainedOutput = new LogTextWriter ();
				chainedOutput.ChainWriter (monitor.Log);
				chainedOutput.ChainWriter (sw);

				ProcessWrapper process = Runtime.ProcessService.StartProcess ( "make", 
						"dist", 
						baseDir, 
						chainedOutput, 
						monitor.Log, 
						null );
				process.WaitForOutput ();

				if ( process.ExitCode > 0 )
					throw new Exception ( GettextCatalog.GetString ("An unspecified error occurred while running '{0}'", "make dist") );

				monitor.Step ( 1 );

				// FIXME: hackish way to get the created tarball's filename
				string output = sw.ToString();
				int targz = output.LastIndexOf  ( "tar.gz" );
				int begin = output.LastIndexOf ( '>', targz );

				string filename = output.Substring ( begin + 1, (targz - begin) + 5 ).Trim ();
				
				FileService.CopyFile (Path.Combine (baseDir, filename), Path.Combine (targetDir, filename));
				monitor.Step ( 1 );
			}
			catch ( Exception e )
			{
				monitor.ReportError ( GettextCatalog.GetString ("Solution could not be deployed: "), e );
				return false;
			}
			finally 
			{
				monitor.EndTask ();
			}
			monitor.ReportSuccess (GettextCatalog.GetString ("Solution was successfully deployed."));
			return true;
		}
Пример #10
0
        /// <summary>
        /// Executes a file and reports events related to the execution to the 'monitor' passed in the parameters.
        /// </summary>
        static int ExecuteCommand(
            string command,
            string args,
            string baseDirectory,

            IProgressMonitor monitor,
            out string errorOutput,
            out string programOutput)
        {
            errorOutput = string.Empty;
            int exitCode = -1;

            var swError = new StringWriter ();
            var swOutput = new StringWriter ();

            var chainedError = new LogTextWriter ();
            chainedError.ChainWriter (monitor.Log);
            chainedError.ChainWriter (swError);

            var chainedOutput = new LogTextWriter ();
            chainedOutput.ChainWriter (monitor.Log);
            chainedOutput.ChainWriter (swOutput);

            monitor.Log.WriteLine ("{0} {1}", command, args);

            var operationMonitor = new AggregatedOperationMonitor (monitor);
            var p = Runtime.ProcessService.StartProcess (command, args, baseDirectory, chainedOutput, chainedError, null);
            operationMonitor.AddOperation (p); //handles cancellation

            p.WaitForOutput ();
            errorOutput = swError.ToString ();
            programOutput = swOutput.ToString ();
            exitCode = p.ExitCode;
            p.Dispose ();

            if (monitor.IsCancelRequested) {
                monitor.Log.WriteLine (GettextCatalog.GetString ("Build cancelled"));
                monitor.ReportError (GettextCatalog.GetString ("Build cancelled"), null);
                if (exitCode == 0)
                    exitCode = -1;
            }
            {
                chainedError.Close ();
                swError.Close ();
                operationMonitor.Dispose ();
            }

            return exitCode;
        }
Пример #11
0
		public ProgressMonitor (SynchronizationContext context, CancellationTokenSource cancellationTokenSource)
		{
			this.cancellationTokenSource = cancellationTokenSource;
			this.context = context;
			logWriter = new LogTextWriter ();
			logWriter.TextWritten += DoWriteLog;

			errorLogWriter = new LogTextWriter ();
			errorLogWriter.TextWritten += DoWriteErrorLog;
		}
Пример #12
0
 public ConsoleProgressMonitor(TextWriter writer)
 {
     this.writer         = writer;
     logger              = new LogTextWriter();
     logger.TextWritten += new LogTextEventHandler(WriteLog);
 }
		public ConsoleProgressMonitor ()
		{
			logger = new LogTextWriter ();
			logger.TextWritten += new LogTextEventHandler (WriteLog);
		}
Пример #14
0
 public ConsoleProgressMonitor()
 {
     logger              = new LogTextWriter();
     logger.TextWritten += new LogTextEventHandler(WriteLog);
 }
		//FIXME: Check whether autogen.sh is required or not
		protected async override Task<BuildResult> OnBuild (ProgressMonitor monitor, ConfigurationSelector configuration, OperationContext operationContext)
		{
			if (data == null || !data.SupportsIntegration || String.IsNullOrEmpty (data.BuildTargetName))
				return await base.OnBuild (monitor, configuration, operationContext);

			//FIXME: Gen autofoo ? autoreconf?

			string output = String.Empty;
			int exitCode = 0;
			monitor.BeginTask (GettextCatalog.GetString ("Building {0}", Project.Name), 1);
			try
			{
				string baseDir = Project.BaseDirectory;
				string args = string.Format ("-j {0} {1}", data.ParallelProcesses, data.BuildTargetName);
	
				using (var swOutput = new StringWriter ()) {
					using (var chainedOutput = new LogTextWriter ()) {
						chainedOutput.ChainWriter (monitor.Log);
						chainedOutput.ChainWriter (swOutput);

						using (ProcessWrapper process = Runtime.ProcessService.StartProcess ("make",
								args,
								baseDir, 
								chainedOutput, 
								chainedOutput,
							null)) {

							await process.Task;

							chainedOutput.UnchainWriter (monitor.Log);
							chainedOutput.UnchainWriter (swOutput);

							exitCode = process.ExitCode;
							output = swOutput.ToString ();
							monitor.Step ( 1 );
						}
					}
				}
			}
			catch ( Exception e )
			{
				monitor.ReportError ( GettextCatalog.GetString ("Project could not be built: "), e );
				return null;
			}
			finally 
			{
				monitor.EndTask ();
			}

			TempFileCollection tf = new TempFileCollection ();
			Regex regexError = data.GetErrorRegex (false);
			Regex regexWarning = data.GetWarningRegex (false);

			BuildResult cr = ParseOutput (tf, output, Project.BaseDirectory, regexError, regexWarning);
			if (exitCode != 0 && cr.FailedBuildCount == 0)
				cr.AddError (GettextCatalog.GetString ("Build failed. See Build Output panel."));

			return cr;
		}
		public ConsoleProgressMonitor (TextWriter writer)
		{
			this.writer = writer;
			logger = new LogTextWriter ();
			logger.TextWritten += WriteLog;
		}
Пример #17
0
        /// <summary>
        /// Executes a file and reports events related to the execution to the 'monitor' passed in the parameters.
        /// </summary>
        public static int ExecuteCommand(
            string command,
            string args,
            string baseDirectory,

            IProgressMonitor monitor,
            out string errorOutput,
            out string programOutput)
        {
            bool useMonitor = monitor != null;
            errorOutput = string.Empty;
            int exitCode = -1;

            var swError = new StringWriter ();
            var swOutput = new StringWriter ();

            var chainedError = new LogTextWriter ();
            chainedError.ChainWriter (swError);

            var chainedOutput = new LogTextWriter ();
            chainedOutput.ChainWriter (swOutput);

            if (useMonitor) {
                chainedError.ChainWriter (monitor.Log);
                chainedOutput.ChainWriter (monitor.Log);
                monitor.Log.WriteLine ("{0} {1}", command, args);
            }

            // Workaround for not handling %PATH% env var expansion properly
            if (!command.Contains(Path.DirectorySeparatorChar))
                command = TryExpandPathEnvVariable(command, baseDirectory);

            var operationMonitor = useMonitor ? new AggregatedOperationMonitor (monitor) : null;
            var p = Runtime.ProcessService.StartProcess (command, args, baseDirectory, chainedOutput, chainedError, null);
            if(useMonitor)
                operationMonitor.AddOperation (p); //handles cancellation

            p.WaitForOutput ();
            swError.Flush ();
            swOutput.Flush ();
            errorOutput = swError.ToString ();
            programOutput = swOutput.ToString ();
            exitCode = p.ExitCode;
            p.Dispose ();

            if (useMonitor) {
                if (monitor.IsCancelRequested) {
                    monitor.Log.WriteLine (GettextCatalog.GetString ("Build cancelled"));
                    monitor.ReportError (GettextCatalog.GetString ("Build cancelled"), null);
                    if (exitCode == 0)
                        exitCode = -1;
                }

                operationMonitor.Dispose ();
            }

            chainedError.Close ();
            swOutput.Close ();
            swError.Close ();

            return exitCode;
        }
Пример #18
0
		//copied from MoonlightBuildExtension
		public static int ExecuteCommand (IProgressMonitor monitor, System.Diagnostics.ProcessStartInfo startInfo, out string errorOutput)
		{
			startInfo.UseShellExecute = false;
			startInfo.RedirectStandardError = true;
			startInfo.RedirectStandardOutput = true;
			
			errorOutput = string.Empty;
			int exitCode = -1;
			
			var swError = new StringWriter ();
			var chainedError = new LogTextWriter ();
			chainedError.ChainWriter (monitor.Log);
			chainedError.ChainWriter (swError);
			
			var operationMonitor = new AggregatedOperationMonitor (monitor);
			
			try {
				var p = Runtime.ProcessService.StartProcess (startInfo, monitor.Log, chainedError, null);
				operationMonitor.AddOperation (p); //handles cancellation
				
				p.WaitForOutput ();
				errorOutput = swError.ToString ();
				exitCode = p.ExitCode;
				p.Dispose ();
				
				if (monitor.IsCancelRequested) {
					monitor.Log.WriteLine (GettextCatalog.GetString ("Build cancelled"));
					monitor.ReportError (GettextCatalog.GetString ("Build cancelled"), null);
					if (exitCode == 0)
						exitCode = -1;
				}
			} finally {
				chainedError.Close ();
				swError.Close ();
				operationMonitor.Dispose ();
			}
			
			return exitCode;
		}
Пример #19
0
		public BuildResult RunTarget (MonoDevelop.Core.IProgressMonitor monitor, string target, ConfigurationSelector configuration)
		{
			if (target == ProjectService.BuildTarget)
				target = "all";
			else if (target == ProjectService.CleanTarget)
				target = "clean";
			
			DotNetProjectConfiguration conf = (DotNetProjectConfiguration) project.GetConfiguration (configuration);

			using (var output = new StringWriter ()) {
				using (var tw = new LogTextWriter ()) {
					tw.ChainWriter (output);
					tw.ChainWriter (monitor.Log);

					using (ProcessWrapper proc = Runtime.ProcessService.StartProcess ("make", "PROFILE=" + conf.Id + " " + target, conf.OutputDirectory, monitor.Log, tw, null))
						proc.WaitForOutput ();

					tw.UnchainWriter (output);
					tw.UnchainWriter (monitor.Log);

					CompilerResults cr = new CompilerResults (null);
					string[] lines = output.ToString().Split ('\n');
					foreach (string line in lines) {
						CompilerError err = CreateErrorFromString (line);
						if (err != null) cr.Errors.Add (err);
					}

					return new BuildResult (cr, output.ToString());
				}
			}

		}
Пример #20
0
		public BaseProgressMonitor ()
		{
			progressTracker = new ProgressTracker ();
			logger = new LogTextWriter ();
			logger.TextWritten += new LogTextEventHandler (WriteLogInternal);
		}
Пример #21
0
		int ExecuteCommand (string command, string args, string baseDirectory, ProgressMonitor monitor, out string errorOutput)
		{
			errorOutput = string.Empty;
			int exitCode = -1;
			
			using (var swError = new StringWriter ()) {
				using (var chainedError = new LogTextWriter ()) {
					chainedError.ChainWriter (monitor.Log);
					chainedError.ChainWriter (swError);
			
					monitor.Log.WriteLine ("{0} {1}", command, args);
			
					using (ProcessWrapper p = Runtime.ProcessService.StartProcess (command, args, baseDirectory, monitor.Log, chainedError, null))
					using (monitor.CancellationToken.Register (p.Cancel)) {
						p.WaitForOutput ();
						chainedError.UnchainWriter (monitor.Log);
						chainedError.UnchainWriter (swError);

						errorOutput = swError.ToString ();
						exitCode = p.ExitCode;
			
						if (monitor.CancellationToken.IsCancellationRequested) {
							monitor.Log.WriteLine (GettextCatalog.GetString ("Build cancelled"));
							monitor.ReportError (GettextCatalog.GetString ("Build cancelled"), null);
							if (exitCode == 0)
								exitCode = -1;
						}
					}
				}
			}
			
			return exitCode;
		}
Пример #22
0
		public ConsoleProgressMonitor (TextWriter writer)
		{
			this.writer = writer;
			logger = new LogTextWriter ();
			logger.TextWritten += new LogTextEventHandler (WriteLog);
		}
Пример #23
0
		static void CompileToAssembly (IProgressMonitor monitor, DotNetProjectConfiguration configuration, JavaCompilerParameters compilerparameters, ProjectItemCollection projectItems, TextWriter output, TextWriter error)
		{
			monitor.Log.WriteLine (GettextCatalog.GetString ("Generating assembly ..."));
			
			LogTextWriter chainedError = new LogTextWriter ();
			chainedError.ChainWriter (monitor.Log);
			chainedError.ChainWriter (error);
			
			LogTextWriter chainedOutput = new LogTextWriter ();
			chainedOutput.ChainWriter (monitor.Log);
			chainedOutput.ChainWriter (output);
			
			string outdir = configuration.OutputDirectory;
			string outclass = Path.Combine (outdir, configuration.OutputAssembly + ".class");
			string asm = Path.GetFileNameWithoutExtension (outclass);
			
			StringBuilder args = new StringBuilder ("-recurse:*.class ");
			
			args.Append ("-assembly:"); args.Append (asm);
			args.Append (" -target:"); args.Append (TargetToString (configuration.CompileTarget));
			if (configuration.DebugMode)
				args.Append (" -debug");
			args.Append (" -srcpath:"); args.Append (configuration.ParentItem.BaseDirectory);
			
			foreach (ProjectReference lib in projectItems.GetAll<ProjectReference> ()) {
				foreach (string fileName in lib.GetReferencedFileNames (configuration.Selector)) {
					args.Append (" -r:"); args.Append (fileName);
				}
			}
			
			foreach (string fileName in new ProjectReference(ReferenceType.Gac, "mscorlib").GetReferencedFileNames (configuration.Selector)) {
				args.Append (" -r:"); args.Append (fileName);
			}
			
			monitor.Log.WriteLine ("ikvmc " + args);
			Process process = Runtime.ProcessService.StartProcess ("ikvmc", args.ToString (), configuration.OutputDirectory, chainedOutput, chainedError, null);
			process.WaitForExit ();
		}
		//FIXME: Check whether autogen.sh is required or not
		protected override BuildResult Build (IProgressMonitor monitor, SolutionEntityItem entry, ConfigurationSelector configuration)
		{
			Project project = entry as Project;
			if (project == null)
				return base.Build (monitor, entry, configuration);

			MakefileData data = project.ExtendedProperties ["MonoDevelop.Autotools.MakefileInfo"] as MakefileData;
			if (data == null || !data.SupportsIntegration || String.IsNullOrEmpty (data.BuildTargetName))
				return base.Build (monitor, entry, configuration);

			//FIXME: Gen autofoo ? autoreconf?

			string output = String.Empty;
			int exitCode = 0;
			monitor.BeginTask (GettextCatalog.GetString ("Building {0}", project.Name), 1);
			try {
				string baseDir = project.BaseDirectory;
				StringBuilder args = new StringBuilder ();
				
				if (data.RelativeMakeCommand.EndsWith ("make", StringComparison.OrdinalIgnoreCase))
					args.AppendFormat (" -j {0}", data.ParallelProcesses, data.BuildTargetName);
				args.AppendFormat (" {0}", data.BuildTargetName);
	
				StringWriter swOutput = new StringWriter ();
				LogTextWriter chainedOutput = new LogTextWriter ();
				chainedOutput.ChainWriter (monitor.Log);
				chainedOutput.ChainWriter (swOutput);
				
				ProcessWrapper process = Runtime.ProcessService.StartProcess (data.AbsoluteMakeCommand, 
						args.ToString (), 
						baseDir, 
						chainedOutput, 
						chainedOutput, 
						null);
				process.WaitForOutput ();

				exitCode = process.ExitCode;
				output = swOutput.ToString ();
				chainedOutput.Close ();
				swOutput.Close ();
				monitor.Step (1);
			} catch (Exception e) {
				monitor.ReportError (GettextCatalog.GetString ("Project could not be built: "), e);
				return null;
			} finally {
				monitor.EndTask ();
			}

			TempFileCollection tf = new TempFileCollection ();
			Regex regexError = data.GetErrorRegex (false);
			Regex regexWarning = data.GetWarningRegex (false);

			BuildResult cr = ParseOutput (tf, output, project.BaseDirectory, regexError, regexWarning);
			if (exitCode != 0 && cr.FailedBuildCount == 0)
				cr.AddError (GettextCatalog.GetString ("Build failed. See Build Output panel."));
			else
				entry.SetNeedsBuilding (false, configuration);

			return cr;
		}
Пример #25
0
		static bool Compile (IProgressMonitor monitor, string compiler, string args, DotNetProjectConfiguration configuration, JavaCompilerParameters compilerparameters, TextWriter output, TextWriter error)
		{
			LogTextWriter chainedError = new LogTextWriter ();
			chainedError.ChainWriter (monitor.Log);
			chainedError.ChainWriter (error);
			
			LogTextWriter chainedOutput = new LogTextWriter ();
			chainedOutput.ChainWriter (monitor.Log);
			chainedOutput.ChainWriter (output);
			
			monitor.Log.WriteLine (GettextCatalog.GetString ("Compiling Java source code ..."));
			monitor.Log.WriteLine (compiler + " " + args);
			
			Process process = Runtime.ProcessService.StartProcess (compiler, args, null, chainedOutput, chainedError, null);
			process.WaitForExit ();
			return process.ExitCode == 0;
        }