protected internal override void OnClean(IProgressMonitor monitor, ConfigurationSelector configuration)
        {
            if (ParentSolution == null)
            {
                return;
            }
            SolutionConfiguration conf = ParentSolution.GetConfiguration(configuration);

            if (conf == null)
            {
                return;
            }

            foreach (SolutionItem item in Items)
            {
                if (item is SolutionFolder)
                {
                    item.Clean(monitor, configuration);
                }
                else if (item is SolutionEntityItem)
                {
                    SolutionEntityItem         si = (SolutionEntityItem)item;
                    SolutionConfigurationEntry ce = conf.GetEntryForItem(si);
                    if (ce.Build)
                    {
                        si.Clean(monitor, ce.ItemConfigurationSelector);
                    }
                }
                else
                {
                    item.Clean(monitor, configuration);
                }
            }
        }
        protected override void OnClean(IProgressMonitor monitor, ConfigurationSelector configuration)
        {
            if (ParentSolution == null)
            {
                return;
            }
            SolutionConfiguration conf = ParentSolution.GetConfiguration(configuration);

            if (conf == null)
            {
                return;
            }

            try
            {
                monitor.BeginTask(GettextCatalog.GetString("Cleaning Solution: {0} ({1})", Name, configuration.ToString()), Items.Count);

                foreach (SolutionItem item in Items)
                {
                    if (item is SolutionFolder)
                    {
                        item.Clean(monitor, configuration);
                    }
                    else if (item is SolutionEntityItem)
                    {
                        SolutionEntityItem si = (SolutionEntityItem)item;
                        // ce can be null if you add items to the root solution folder which
                        // causes them to be placed in an autogenerated 'Project Items' folder
                        SolutionConfigurationEntry ce = conf.GetEntryForItem(si);
                        if (ce != null && ce.Build)
                        {
                            si.Clean(monitor, ce.ItemConfigurationSelector);
                        }
                    }
                    else
                    {
                        item.Clean(monitor, configuration);
                    }
                    monitor.Step(1);
                }
            }
            finally
            {
                monitor.EndTask();
            }
        }
Exemple #3
0
        protected override void OnClean(IProgressMonitor monitor, ConfigurationSelector configuration)
        {
            if (ParentSolution == null)
            {
                return;
            }
            SolutionConfiguration conf = ParentSolution.GetConfiguration(configuration);

            if (conf == null)
            {
                return;
            }

            try {
                monitor.BeginTask(GettextCatalog.GetString("Cleaning Solution {0}", Name), Items.Count);

                foreach (SolutionItem item in Items)
                {
                    if (item is SolutionFolder)
                    {
                        item.Clean(monitor, configuration);
                    }
                    else if (item is SolutionEntityItem)
                    {
                        SolutionEntityItem         si = (SolutionEntityItem)item;
                        SolutionConfigurationEntry ce = conf.GetEntryForItem(si);
                        if (ce.Build)
                        {
                            si.Clean(monitor, ce.ItemConfigurationSelector);
                        }
                    }
                    else
                    {
                        item.Clean(monitor, configuration);
                    }
                    monitor.Step(1);
                }
            }
            finally {
                monitor.EndTask();
            }
        }
        public int Run(string[] arguments)
        {
            Console.WriteLine(BrandingService.BrandApplicationName("MonoDevelop Build Tool"));
            foreach (string s in arguments)
            {
                ReadArgument(s);
            }

            if (help)
            {
                Console.WriteLine("build [options] [build-file]");
                Console.WriteLine("-p --project:PROJECT  Name of the project to build.");
                Console.WriteLine("-t --target:TARGET    Name of the target: Build or Clean.");
                Console.WriteLine("-c --configuration:CONFIGURATION  Name of the solution configuration to build.");
                Console.WriteLine("-r --runtime:PREFIX   Prefix of the Mono runtime to build against.");
                Console.WriteLine();
                Console.WriteLine("Supported targets:");
                Console.WriteLine("  {0}: build the project (the default target).", ProjectService.BuildTarget);
                Console.WriteLine("  {0}: clean the project.", ProjectService.CleanTarget);
                Console.WriteLine();
                return(0);
            }

            string solFile  = null;
            string itemFile = null;

            if (file == null)
            {
                string[] files = Directory.GetFiles(".");
                foreach (string f in files)
                {
                    if (Services.ProjectService.IsWorkspaceItemFile(f))
                    {
                        solFile = f;
                        break;
                    }
                    else if (itemFile == null && Services.ProjectService.IsSolutionItemFile(f))
                    {
                        itemFile = f;
                    }
                }
                if (solFile == null && itemFile == null)
                {
                    Console.WriteLine("Project file not found.");
                    return(1);
                }
            }
            else
            {
                if (Services.ProjectService.IsWorkspaceItemFile(file))
                {
                    solFile = file;
                }
                else if (Services.ProjectService.IsSolutionItemFile(file))
                {
                    itemFile = file;
                }
                else
                {
                    Console.WriteLine("File '{0}' is not a project or solution.", file);
                    return(1);
                }
            }

            IProgressMonitor monitor = new ConsoleProjectLoadProgressMonitor(new ConsoleProgressMonitor());

            TargetRuntime targetRuntime  = null;
            TargetRuntime defaultRuntime = Runtime.SystemAssemblyService.DefaultRuntime;

            if (runtime != null)
            {
                targetRuntime = MonoTargetRuntimeFactory.RegisterRuntime(new MonoRuntimeInfo(runtime));
                if (targetRuntime != null)
                {
                    Runtime.SystemAssemblyService.DefaultRuntime = targetRuntime;
                }
            }

            IBuildTarget item;

            if (solFile != null)
            {
                item = Services.ProjectService.ReadWorkspaceItem(monitor, solFile);
            }
            else
            {
                item = Services.ProjectService.ReadSolutionItem(monitor, itemFile);
            }

            using (var readItem = item) {
                if (project != null)
                {
                    Solution solution = item as Solution;
                    item = null;

                    if (solution != null)
                    {
                        item = solution.FindProjectByName(project);
                    }
                    if (item == null)
                    {
                        Console.WriteLine("The project '" + project + "' could not be found in " + file);
                        return(1);
                    }
                }

                IConfigurationTarget configTarget = item as IConfigurationTarget;
                if (config == null && configTarget != null)
                {
                    config = configTarget.DefaultConfigurationId;
                }

                monitor = new ConsoleProgressMonitor();
                BuildResult res = null;
                if (item is SolutionEntityItem && ((SolutionEntityItem)item).ParentSolution == null)
                {
                    ConfigurationSelector configuration = new ItemConfigurationSelector(config);
                    res = item.RunTarget(monitor, command, configuration);
                }
                else
                {
                    ConfigurationSelector configuration      = new SolutionConfigurationSelector(config);
                    SolutionEntityItem    solutionEntityItem = item as SolutionEntityItem;
                    if (solutionEntityItem != null)
                    {
                        if (command == ProjectService.BuildTarget)
                        {
                            res = solutionEntityItem.Build(monitor, configuration, true);
                        }
                        else if (command == ProjectService.CleanTarget)
                        {
                            solutionEntityItem.Clean(monitor, configuration);
                        }
                        else
                        {
                            res = item.RunTarget(monitor, command, configuration);
                        }
                    }
                    else
                    {
                        res = item.RunTarget(monitor, command, configuration);
                    }
                }


                if (targetRuntime != null)
                {
                    Runtime.SystemAssemblyService.DefaultRuntime = defaultRuntime;
                    MonoTargetRuntimeFactory.UnregisterRuntime((MonoTargetRuntime)targetRuntime);
                }

                if (res != null)
                {
                    foreach (var err in res.Errors)
                    {
                        Console.Error.WriteLine(err);
                    }
                }

                return((res == null || res.ErrorCount == 0) ? 0 : 1);
            }
        }