Ejemplo n.º 1
0
        private void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            ThreadFailed = false;

            // start the the loggers, to make sure we get some feedback
            foreach (var loggerInfo in _options.Loggers)
            {
                Type loggerType = Type.GetType(loggerInfo.Key);
                if (loggerType == null)
                {
                    loggerType = Type.GetType("Tada.Loggers." + loggerInfo.Key);
                }
                Logger logger = (Logger)Activator.CreateInstance(loggerType);
                foreach (string loggerOption in loggerInfo.Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    int equalsIndex = loggerOption.IndexOf('=');
                    if (equalsIndex < 0)
                    {
                        throw new ArgumentException("Missing value for option " + loggerOption);
                    }
                    SetProperty(logger, loggerOption.Remove(equalsIndex), loggerOption.Substring(equalsIndex + 1));
                }
                AddLogger(logger);
            }

            #if DEBUG
            Log(LogLevel.Warning, "Running Tada in debug mode!");
            #endif

            if (!string.IsNullOrEmpty(_options.ExecuteBefore))
            {
                Log(LogLevel.Info, "Executing the \"before\" command...");

                int spaceIndex = _options.ExecuteBefore.IndexOf(' ');
                // there's a command to execute before starting the script
                string dir = !string.IsNullOrEmpty(_options.BuildFile) ? Path.GetDirectoryName(_options.BuildFile) : Path.GetDirectoryName(_options.DllFilename);
                ExecTask execTask = new ExecTask(Path.Combine(dir, spaceIndex < 0 ? _options.ExecuteBefore : _options.ExecuteBefore.Remove(spaceIndex)));
                execTask.WorkingDir = dir;
                if (spaceIndex >= 0)
                {
                    execTask.Args = _options.ExecuteBefore.Substring(spaceIndex);
                }
                execTask.Execute();
            }

            #if !DEBUG
            if (!string.IsNullOrEmpty(_options.ProjectFilename))
            {
                Log(LogLevel.Info, "Compiling the project...");

                try
                {
                    Project tempProject = new Project();
                    tempProject.TargetFramework = Framework.DotNet_4_0;
                    MSBuildTask msbuild = new MSBuildTask()
                    {
                        ProjectFile = _options.ProjectFilename,
                        Configuration = "Release",
                        Platform = "AnyCPU",
                        Target = "build",
                        Verbosity = MSBuildVerbosity.Quiet
                    };
                    //msbuild.Properties["MSBuildToolsPath"] = tempProject.TargetFrameworkToolsPath;
                    msbuild.Execute();
                }
                catch (Exception ex)
                {
                    Log(LogLevel.Error, ex.ToString());
                    throw;
                }
            }
            #endif

            Assembly assembly = Assembly.LoadFrom(_options.DllFilename);
            foreach (Type type in assembly.GetTypes())
            {
                if (typeof(Project).IsAssignableFrom(type))
                {
                    _projectType = type;
                    break;
                }
            }
            if (_projectType == null)
            {
                throw new ProjectNotFoundException(string.Format("Could not find a class inheriting from {0} in the given assembly.", typeof(Project).FullName));
            }

            _mainThread = NewThread("Main");

            _project = (Project)Activator.CreateInstance(_projectType);

            _initialized = true;
        }
Ejemplo n.º 2
0
 internal void WakeUp(BuildThread buildThread)
 {
     Interlocked.Decrement(ref _sleepingThreadsCount);
 }
Ejemplo n.º 3
0
 internal void BeginThread(BuildThread buildThread)
 {
     foreach (Logger logger in _loggers)
     {
         logger.BeginThread(buildThread);
     }
 }
Ejemplo n.º 4
0
 internal void Sleep(BuildThread buildThread, bool firstSleep)
 {
     if (!firstSleep)
     {
         Log(LogLevel.Info, string.Format("{0} Thread {1} waiting for a task or target to execute...", DateTime.Now.ToLongTimeString(), buildThread.Name));
     }
     Interlocked.Increment(ref _sleepingThreadsCount);
 }
Ejemplo n.º 5
0
 public BuildThread NewThread(string name)
 {
     BuildThread thread = new BuildThread(this, name);
     lock (_threadsSyncRoot)
     {
         _threads.Add(thread);
     }
     return thread;
 }