Esempio n. 1
0
        private bool DoesSvnDirectoryExist(IIntegrationResult result)
        {
            string svnDirectory           = Path.Combine(result.BaseFromWorkingDirectory(WorkingDirectory), ".svn");
            string underscoreSvnDirectory = Path.Combine(result.BaseFromWorkingDirectory(WorkingDirectory), "_svn");

            return(Directory.Exists(svnDirectory) || Directory.Exists(underscoreSvnDirectory));
        }
        /// <summary>
        /// Run the task.
        /// </summary>
        /// <param name="result"></param>
        protected override bool Execute(IIntegrationResult result)
        {
            result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : "Running CodeItRight analysis");

            // Run the executable
            var info          = this.CreateProcessInfo(result);
            var processResult = this.TryToRun(info, result);

            // Need to start a new result as CodeItRight returns the number of violation
            processResult = new ProcessResult(
                processResult.StandardOutput,
                processResult.StandardError,
                processResult.ExitCode,
                processResult.TimedOut,
                processResult.ExitCode < 0);
            result.AddTaskResult(new ProcessTaskResult(processResult));
            if (processResult.TimedOut)
            {
                result.AddTaskResult(MakeTimeoutBuildResult(info));
            }

            if (processResult.Succeeded)
            {
                var xmlFile = result.BaseFromWorkingDirectory("codeitright.xml");
                result.AddTaskResult(
                    fileSystem.GenerateTaskResultFromFile(xmlFile, true));
            }

            // Check the failure threshold
            var failed = !processResult.Succeeded;

            if (!failed && (this.FailureThreshold != Severity.None))
            {
                var xmlFile  = result.BaseFromWorkingDirectory("codeitright.xml");
                var document = new XmlDocument();
                if (this.fileSystem.FileExists(xmlFile))
                {
                    using (var stream = this.fileSystem.OpenInputStream(xmlFile))
                    {
                        document.Load(stream);
                    }

                    for (var level = (int)Severity.CriticalError; level >= (int)this.FailureThreshold; level--)
                    {
                        failed = CodeItRightTask.CheckReportForSeverity(document, (Severity)level);
                        if (failed)
                        {
                            break;
                        }
                    }
                }
            }

            return(!failed);
        }
Esempio n. 3
0
        private ProcessInfo GetSourceProcessInfo(IIntegrationResult result, bool getByLabel)
        {
            ProcessArgumentBuilder builder = new ProcessArgumentBuilder();

            if (getByLabel)
            {
                builder.AddArgument("getlabel", Folder);
                builder.AddArgument(result.Label);
            }
            else
            {
                builder.AddArgument("get", Folder);
            }
            if (UseVaultWorkingDirectory)
            {
                builder.AppendArgument("-merge overwrite -performdeletions removeworkingcopy");
            }
            else
            {
                builder.AddArgument("-destpath", result.BaseFromWorkingDirectory(WorkingDirectory));
                builder.AppendArgument("-merge overwrite");
            }
            builder.AppendArgument("-setfiletime checkin -makewritable");
            AddCommonOptionalArguments(builder);
            return(ProcessInfoFor(builder.ToString(), result));
        }
        /// <summary>
        /// Generate and return a label from the file content.
        /// </summary>
        /// <param name="integrationResult">the current integration result</param>
        /// <returns>the label</returns>
        public override string Generate(IIntegrationResult integrationResult)
        {
            string label  = fileReader.GetLabel(integrationResult.BaseFromWorkingDirectory(labelFilePath));
            string suffix = GetSuffixBasedOn(label, integrationResult.LastIntegration.Label);

            return(string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}{1}{2}", prefix, label, suffix));
        }
Esempio n. 5
0
        private ProcessInfo NewCheckoutProcessInfo(IIntegrationResult result)
        {
            // CCNET-1796: work around a CVS limitation: the -d parameter only accepts limited relative paths
            // so the working directory is one level up of the checkout dir and
            // override checkout directory
            var wd = new DirectoryInfo(result.BaseFromWorkingDirectory(WorkingDirectory));

            if (wd.Parent == null)
            {
                throw new ArgumentException(
                          @"[CVS] Cannot checkout into working directory that denotes a root, such as '\' or 'C:\'.");
            }

            var checkoutWd  = wd.Parent.FullName;
            var checkoutDir = wd.Name;

            Log.Debug("[CVS] Configured Working Directory: '{0}'", wd);
            Log.Debug("[CVS] Checkout Working Directory: '{0}'", checkoutWd);
            Log.Debug("[CVS] Checkout Directory: '{0}'", checkoutDir);

            ProcessArgumentBuilder builder = new ProcessArgumentBuilder();

            AppendCvsRoot(builder);
            builder.AddArgument("-q");
            builder.AddArgument("checkout");
            builder.AddArgument("-R");
            builder.AddArgument("-P");
            builder.AddArgument("-r", Branch);
            builder.AddArgument("-d", StringUtil.AutoDoubleQuoteString(checkoutDir));
            builder.AddArgument(Module);
            var pi = NewProcessInfoWithArgs(result, builder.ToString());

            pi.WorkingDirectory = checkoutWd;
            return(pi);
        }
        /// <summary>
        /// Finds the config file.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <param name="fileSystem">The file system.</param>
        /// <returns>
        /// The path to the file if it exists; <c>null</c> otherwise.
        /// </returns>
        private string FindConfigFile(IIntegrationResult result, IFileSystem fileSystem)
        {
            // Generate the initial file to check
            var configFile = this.SourceFile;

            if (!Path.IsPathRooted(configFile))
            {
                configFile = result.BaseFromWorkingDirectory(configFile);
            }

            // Check if th file exists
            Log.Debug("Checking for configuration file '{0}'", configFile);
            var fileExists = fileSystem.FileExists(configFile);

            if (!fileExists && !configFile.EndsWith("ccnet.config", StringComparison.InvariantCultureIgnoreCase))
            {
                // Try adding ccnet.config and see if it exists
                configFile = Path.Combine(configFile, "ccnet.config");
                Log.Debug("Checking for configuration file '{0}'", configFile);
                fileExists = fileSystem.FileExists(configFile);
            }

            if (!fileExists)
            {
                Log.Info("Unable to find find config file");
                return(null);
            }

            Log.Info("Found config file '{0}'", configFile);
            return(configFile);
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the modifications.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
        {
            DirectoryInfo root          = new DirectoryInfo(from.BaseFromWorkingDirectory(RepositoryRoot));
            var           modifications = GetMods(root, from.StartTime);

            return(modifications.ToArray());
        }
Esempio n. 8
0
        public override void GetSource(IIntegrationResult result)
        {
            result.BuildProgressInformation.SignalStartRunTask("Getting source from Vault");

            if (!_shim.AutoGetSource) return;
            if (_folderVersion <= 0)
            {
                throw new CruiseControlException("_folderVersion <= 0 when attempting to get source.  This shouldn't happen.");
            }

            if (_shim.CleanCopy)
            {
                string cleanCopyWorkingFolder = null;
                if (string.IsNullOrEmpty(_shim.WorkingDirectory))
                {
                    cleanCopyWorkingFolder = GetVaultWorkingFolder(result);
                    if (string.IsNullOrEmpty(cleanCopyWorkingFolder))
                        throw new VaultException(
                            string.Format("Vault user {0} has no working folder set for {1} in repository {2} and no working directory has been specified.",
                                          _shim.Username, _shim.Folder, _shim.Repository));
                }
                else
                    cleanCopyWorkingFolder = result.BaseFromWorkingDirectory(_shim.WorkingDirectory);

                Log.Debug("Cleaning out source folder: " + cleanCopyWorkingFolder);
                fileDirectoryDeleter.DeleteIncludingReadOnlyObjects(cleanCopyWorkingFolder);
            }

            Log.Info("Getting source from Vault");
            Execute(GetSourceProcessInfo(result));
        }
Esempio n. 9
0
        private ProcessInfo NewProcessInfo(string args, IIntegrationResult result)
        {
            ProcessInfo processInfo = new ProcessInfo(Executable, args, result.BaseFromWorkingDirectory(WorkingDirectory));

            processInfo.StreamEncoding = Encoding.UTF8;
            return(processInfo);
        }
Esempio n. 10
0
        public override void GetSource(IIntegrationResult result)
        {
            if (!_shim.AutoGetSource) return;
            Debug.Assert(_folderVersion > 0, "_folderVersion <= 0 when attempting to get source.  This shouldn't happen.");

            if (_shim.CleanCopy)
            {
                string cleanCopyWorkingFolder = null;
                if (StringUtil.IsBlank(_shim.WorkingDirectory))
                {
                    cleanCopyWorkingFolder = GetVaultWorkingFolder(result);
                    if (StringUtil.IsBlank(cleanCopyWorkingFolder))
                        throw new VaultException(
                            string.Format("Vault user {0} has no working folder set for {1} in repository {2} and no working directory has been specified.",
                                          _shim.Username, _shim.Folder, _shim.Repository));
                }
                else
                    cleanCopyWorkingFolder = result.BaseFromWorkingDirectory(_shim.WorkingDirectory);

                Log.Debug("Cleaning out source folder: " + cleanCopyWorkingFolder);
                new IoService().EmptyDirectoryIncludingReadOnlyObjects(cleanCopyWorkingFolder);
            }

            Log.Info("Getting source from Vault");
            Execute(GetSourceProcessInfo(result));
        }
Esempio n. 11
0
        private ProcessInfo NewProcessInfo(PrivateArguments args, IIntegrationResult result)
        {
            string workingDirectory = Path.GetFullPath(result.BaseFromWorkingDirectory(WorkingDirectory));

            if (!Directory.Exists(workingDirectory))
            {
                Directory.CreateDirectory(workingDirectory);
            }

            var processInfo = new ProcessInfo(Executable, args, workingDirectory);

            processInfo.StreamEncoding = Encoding.UTF8;

            if (!string.IsNullOrEmpty(CodePage))
            {
                int codePage;
                if (int.TryParse(CodePage, out codePage))
                {
                    processInfo.StreamEncoding = Encoding.GetEncoding(codePage);
                }
                else
                {
                    throw new CruiseControlException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Code page {0} could not be parsed to an encoding via instruction : Encoding.GetEncoding(codePage)", CodePage));
                }
            }

            processInfo.TimeOut = 600000;
            return(processInfo);
        }
Esempio n. 12
0
        private string[] GetDirectoriesContainingChanges(IIntegrationResult from)
        {
            ProcessResult result = ExecuteHistoryCommand(from);

            historyCommandParser.WorkingDirectory = from.BaseFromWorkingDirectory(WorkingDirectory);
            return(historyCommandParser.ParseOutputFrom(result.StandardOutput));
        }
Esempio n. 13
0
        public override void GetSource(IIntegrationResult result)
        {
            if (!_shim.AutoGetSource)
            {
                return;
            }
            Debug.Assert(_folderVersion > 0, "_folderVersion <= 0 when attempting to get source.  This shouldn't happen.");

            if (_shim.CleanCopy)
            {
                string cleanCopyWorkingFolder = null;
                if (StringUtil.IsBlank(_shim.WorkingDirectory))
                {
                    cleanCopyWorkingFolder = GetVaultWorkingFolder(result);
                    if (StringUtil.IsBlank(cleanCopyWorkingFolder))
                    {
                        throw new VaultException(
                                  string.Format("Vault user {0} has no working folder set for {1} in repository {2} and no working directory has been specified.",
                                                _shim.Username, _shim.Folder, _shim.Repository));
                    }
                }
                else
                {
                    cleanCopyWorkingFolder = result.BaseFromWorkingDirectory(_shim.WorkingDirectory);
                }

                Log.Debug("Cleaning out source folder: " + cleanCopyWorkingFolder);
                new IoService().EmptyDirectoryIncludingReadOnlyObjects(cleanCopyWorkingFolder);
            }

            Log.Info("Getting source from Vault");
            Execute(GetSourceProcessInfo(result));
        }
Esempio n. 14
0
        private ProcessInfo NewProcessInfo(IIntegrationResult result)
        {
            ProcessInfo info = new ProcessInfo(Executable, Args(result), result.BaseFromWorkingDirectory(WorkingDirectory));

            info.TimeOut = Timeout * 1000;
            return(info);
        }
Esempio n. 15
0
        /// <summary>
        /// Gets the source.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <remarks></remarks>
        public override void GetSource(IIntegrationResult result)
        {
            if (!AutoGetSource || !ProjectExists(result))
            {
                return;
            }

            this.WorkingDirectory = result.BaseFromWorkingDirectory(this.WorkingDirectory);

            if (CleanCopy)
            {
                // If we have said we want a clean copy, then delete old copy before getting.
                Log.Debug("[TFS] Deleting " + this.WorkingDirectory);
                this.DeleteDirectory(this.WorkingDirectory);
            }

            TfsWorkspaceStatus workspaceStatus = GetWorkspaceStatus(result);

            if (workspaceStatus.WorkspaceExists)
            {
                if (DeleteWorkspace)
                {
                    // We have asked for a new workspace every time, therefore delete the existing one.
                    Log.Debug("[TFS] Removing existing workspace " + Workspace);
                    LookForErrorReturns(executor.Execute(DeleteWorkSpaceProcessInfo(result)));

                    //Create Workspace
                    Log.Debug("[TFS] Creating New Workspace " + Workspace);
                    LookForErrorReturns(executor.Execute(CreateWorkSpaceProcessInfo(result)));

                    //Map Workspace
                    Log.Debug(string.Format(System.Globalization.CultureInfo.CurrentCulture, "[TFS] Mapping Workspace {0} to {1}", Workspace, WorkingDirectory));
                    LookForErrorReturns(executor.Execute(MapWorkSpaceProcessInfo(result)));
                }
            }
            else
            {
                //Create Workspace
                Log.Debug("[TFS] Creating New Workspace " + Workspace);
                LookForErrorReturns(executor.Execute(CreateWorkSpaceProcessInfo(result)));

                //Map Workspace
                Log.Debug(string.Format(System.Globalization.CultureInfo.CurrentCulture, "[TFS] Mapping Workspace {0} to {1}", Workspace, WorkingDirectory));
                LookForErrorReturns(executor.Execute(MapWorkSpaceProcessInfo(result)));
            }

            if (!workspaceStatus.WorkspaceIsMappedCorrectly)
            {
                //Map Workspace
                Log.Debug(string.Format(System.Globalization.CultureInfo.CurrentCulture, "[TFS] Mapping Workspace {0} to {1}", Workspace, WorkingDirectory));
                LookForErrorReturns(executor.Execute(MapWorkSpaceProcessInfo(result)));
            }

            Log.Debug("[TFS] Getting Files in " + Workspace);
            ProcessInfo pi = GetWorkSpaceProcessInfo(result);

            pi.TimeOut = 3600000;
            LookForErrorReturns(executor.Execute(pi));
        }
Esempio n. 16
0
        private ProcessInfo NewProcessInfo(string args, IIntegrationResult result)
        {
            ProcessInfo pi = new ProcessInfo(Executable, args, result.BaseFromWorkingDirectory(WorkingDirectory));

            // Needed to disable the pager for bk commands, which causes infinite hangs
            pi.EnvironmentVariables.Add("PAGER", "cat");
            return(pi);
        }
Esempio n. 17
0
 private string TagSource(IIntegrationResult result)
 {
     if ((Modification.GetLastChangeNumber(mods) == null) || TagWorkingCopy)
     {
         return(Path.GetFullPath(result.BaseFromWorkingDirectory(WorkingDirectory)).TrimEnd(Path.DirectorySeparatorChar));
     }
     return(TrunkUrl);
 }
Esempio n. 18
0
        /// <summary>
        /// Prepare an AccuRev command for execution.
        /// </summary>
        /// <param name="args">arguments for the "accurev" command</param>
        /// <param name="result">IntegrationResult for which the command will be run</param>
        /// <returns>a ProcessInfo object primed to execute the specified command</returns>
        private ProcessInfo PrepCommand(PrivateArguments args, IIntegrationResult result)
        {
            Log.Debug(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Preparing to run AccuRev command: {0} {1}", Executable, args));
            ProcessInfo command = new ProcessInfo(Executable, args, result.BaseFromWorkingDirectory(Workspace));

            SetEnvironmentVariables(command.EnvironmentVariables, result);
            return(command);
        }
Esempio n. 19
0
 private string TagSource(IIntegrationResult result)
 {
     if (result.LastChangeNumber == 0)
     {
         return(result.BaseFromWorkingDirectory(WorkingDirectory).TrimEnd(Path.DirectorySeparatorChar));
     }
     return(TrunkUrl);
 }
Esempio n. 20
0
        private ProcessInfo CleanupWorkingCopy(IIntegrationResult result)
        {
            var buffer = new PrivateArguments("cleanup");

            buffer.Add(null, Path.GetFullPath(result.BaseFromWorkingDirectory(WorkingDirectory)), true);

            return(NewProcessInfo(buffer, result));
        }
Esempio n. 21
0
        private ProcessInfo RevertWorkingCopy(IIntegrationResult result)
        {
            var buffer = new PrivateArguments("revert", "--recursive");

            buffer.Add(null, Path.GetFullPath(result.BaseFromWorkingDirectory(WorkingDirectory)), true);

            return(NewProcessInfo(buffer, result));
        }
 /// <summary>
 /// Performs the actual evaluation.
 /// </summary>
 /// <param name="result">The result.</param>
 /// <returns>
 /// <c>true</c> if the condition is true; <c>false</c> otherwise.
 /// </returns>
 protected override bool Evaluate(IIntegrationResult result)
 {
     var folderName = result.BaseFromWorkingDirectory(this.FolderName);
     this.LogDescriptionOrMessage("Checking for folder '" + folderName + "'");
     var fileSystem = this.FileSystem ?? new SystemIoFileSystem();
     var exists = fileSystem.DirectoryExists(folderName);
     return exists;
 }
Esempio n. 23
0
        private ProcessInfo NewCheckoutProcessInfo(IIntegrationResult result)
        {
            var buffer = new PrivateArguments("checkout");

            buffer.Add(string.Empty, TrunkUrl, true);
            buffer.Add(null, Path.GetFullPath(result.BaseFromWorkingDirectory(WorkingDirectory)), true);
            AppendCommonSwitches(buffer);
            return(NewProcessInfo(buffer, result));
        }
 public Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
 {
     var path = to.BaseFromWorkingDirectory(this.FileName);
     using (var reader = new StreamReader(path))
     {
         var parser = new IndexFileHistoryParser();
         return parser.Parse(reader, from.StartTime, to.StartTime);
     }
 }
        public Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
        {
            var path = to.BaseFromWorkingDirectory(this.FileName);

            using (var reader = new StreamReader(path))
            {
                var parser = new IndexFileHistoryParser();
                return(parser.Parse(reader, from.StartTime, to.StartTime));
            }
        }
        /// <summary>
        /// Generate a manifest for a package.
        /// </summary>
        /// <param name="result">The result of the build.</param>
        /// <param name="packagedFiles">The files that were packaged.</param>
        /// <returns>An <see cref="XmlDocument"/> containing the manifest.</returns>
        public XmlDocument Generate(IIntegrationResult result, string[] packagedFiles)
        {
            if (string.IsNullOrEmpty(fileName)) throw new ArgumentOutOfRangeException("FileName");

            XmlDocument manifest = new XmlDocument();
            string actualFile = fileName;
            if (!Path.IsPathRooted(actualFile)) actualFile = result.BaseFromWorkingDirectory(actualFile);
            manifest.Load(actualFile);
            return manifest;
        }
        /// <summary>
        /// Performs the actual evaluation.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <returns>
        /// <c>true</c> if the condition is true; <c>false</c> otherwise.
        /// </returns>
        protected override bool Evaluate(IIntegrationResult result)
        {
            var fileName = result.BaseFromWorkingDirectory(this.FileName);

            this.LogDescriptionOrMessage("Checking for file '" + fileName + "'");
            var fileSystem = this.FileSystem ?? new SystemIoFileSystem();
            var exists     = fileSystem.FileExists(fileName);

            return(exists);
        }
Esempio n. 28
0
        private ProcessInfo NewCheckoutProcessInfo(IIntegrationResult result)
        {
            ProcessArgumentBuilder buffer = new ProcessArgumentBuilder();

            buffer.AddArgument("checkout");
            buffer.AddArgument(TrunkUrl);
            buffer.AddArgument(result.BaseFromWorkingDirectory(WorkingDirectory));
            AppendCommonSwitches(buffer);
            return(NewProcessInfo(buffer.ToString(), result));
        }
        protected override bool Evaluate(IIntegrationResult result)
        {
            string str = result.BaseFromWorkingDirectory(this.FolderName);

            LogDescriptionOrMessage(string.Concat("Checking for folder '", str, "'"));
            if (FileSystem == null)
            {
                FileSystem = new SystemIoFileSystem();
            }
            return(!FileSystem.DirectoryExists(str));
        }
 /// <summary>
 /// Ensures the path is rooted.
 /// </summary>
 /// <param name="result">The result.</param>
 /// <param name="path">The path.</param>
 /// <returns>The rooted path.</returns>
 private string EnsurePathIsRooted(IIntegrationResult result, string path)
 {
     if (!Path.IsPathRooted(path))
     {
         return(result.BaseFromWorkingDirectory(path));
     }
     else
     {
         return(path);
     }
 }
Esempio n. 31
0
        /// <summary>
        /// Executes the specified result.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        protected override bool Execute(IIntegrationResult result)
        {
            var relativeLocalFolder = result.BaseFromWorkingDirectory(this.LocalFolderName);

            result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : GetDescription(relativeLocalFolder));

            string remoteFolder = FtpFolderName;
            FtpLib ftp          = new FtpLib(this, result.BuildProgressInformation);


            try
            {
                ftp.LogIn(ServerName, UserName, Password, UseActiveConnectionMode);

                ftp.TimeDifference = new TimeSpan(TimeDifference, 0, 0);



                if (!FtpFolderName.StartsWith("/"))
                {
                    remoteFolder = System.IO.Path.Combine(ftp.CurrentWorkingFolder(), FtpFolderName);
                }

                if (Action == FtpAction.UploadFolder)
                {
                    Log.Debug("Uploading {0} to {1}, recursive : {2}", relativeLocalFolder, remoteFolder, RecursiveCopy);
                    ftp.UploadFolder(remoteFolder, relativeLocalFolder, RecursiveCopy);
                }

                if (Action == FtpAction.DownloadFolder)
                {
                    Log.Debug("Downloading {0} to {1}, recursive : {2}", remoteFolder, relativeLocalFolder, RecursiveCopy);
                    ftp.DownloadFolder(relativeLocalFolder, remoteFolder, RecursiveCopy);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                // try to disconnect in a proper way on getting an error
                try
                {      // swallow exception on disconnect to keep the original error
                    if (ftp.IsConnected())
                    {
                        ftp.DisConnect();
                    }
                }
                catch { }
                Log.Info("throwing");
                throw;
            }

            return(true);
        }
Esempio n. 32
0
        private ProcessInfo NewProcessInfoWithArgs(IIntegrationResult result, string args)
        {
            var wd = result.BaseFromWorkingDirectory(WorkingDirectory);

            // ensure working directory exists
            fileSystem.EnsureFolderExists(wd);

            var pi = new ProcessInfo(Executable, args, wd);

            SetEnvironmentVariables(pi, result);
            return(pi);
        }
Esempio n. 33
0
        /// <summary>
        /// Run the task.
        /// </summary>
        /// <param name="result">The result to use.</param>
        /// <returns>
        /// True if the task was successful, false otherwise.
        /// </returns>
        protected override bool Execute(IIntegrationResult result)
        {
            result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : "Executing DupFinder");
            this.logger = this.logger ?? new DefaultLogger();

            this.executable = string.IsNullOrEmpty(this.Executable) ? DefaultExecutable : this.Executable;
            if (!Path.IsPathRooted(this.executable))
            {
                this.executable = result.BaseFromWorkingDirectory(this.executable);
                this.logger.Debug("Executable changed to " + this.executable);
            }

            // Run the executable
            this.logger.Info("Executing DupFinder");
            var info          = this.CreateProcessInfo(result);
            var processResult = this.TryToRun(info, result);

            if (processResult.TimedOut)
            {
                result.AddTaskResult(MakeTimeoutBuildResult(info));
            }

            if (this.ShortenFileNames || this.IncludeCode)
            {
                // Load the results into an XML document
                var document = new XmlDocument();
                document.LoadXml(processResult.StandardOutput);

                if (this.IncludeCode)
                {
                    this.logger.Info("Including duplicate code lines");
                    this.ImportCode(document);
                }

                if (this.ShortenFileNames)
                {
                    this.logger.Info("Shortening filenames");
                    this.RemoveInputDir(document);
                }

                // Generate a new result
                processResult = new ProcessResult(
                    document.OuterXml,
                    processResult.StandardError,
                    processResult.ExitCode,
                    processResult.TimedOut,
                    processResult.Failed);
            }

            // Add the result
            result.AddTaskResult(new ProcessTaskResult(processResult, false));
            return(processResult.Succeeded);
        }
Esempio n. 34
0
        private bool DoesSvnDirectoryExist(IIntegrationResult result)
        {
            //string svnDirectory = Path.Combine(result.BaseFromWorkingDirectory(WorkingDirectory), ".svn");
            //string underscoreSvnDirectory = Path.Combine(result.BaseFromWorkingDirectory(WorkingDirectory), "_svn");

            //Console.WriteLine(svnDirectory);
            //Console.WriteLine(underscoreSvnDirectory);


            //return fileSystem.DirectoryExists(svnDirectory) || fileSystem.DirectoryExists(underscoreSvnDirectory);

            return(SvnFolderFound(result.BaseFromWorkingDirectory(WorkingDirectory)));
        }
        /// <summary>
        /// Gets the source.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <remarks></remarks>
        public override void GetSource(IIntegrationResult result)
        {
            if (AutoGetSource)
            {
                string destinationDirectory = result.BaseFromWorkingDirectory(WorkingDirectory);

                ProcessArgumentBuilder builder = new ProcessArgumentBuilder();

                AddStandardArguments(builder, destinationDirectory);

                Execute(new ProcessInfo(Executable, builder.ToString(), null, ProcessPriorityClass.Normal, successExitCodes));
            }
        }
 public void GetSource(IIntegrationResult result)
 {
     foreach (var modification in result.Modifications)
     {
         var source = Path.Combine(
             modification.FolderName,
             modification.FileName);
         var destination = result.BaseFromWorkingDirectory(
             modification.FileName);
         if (File.Exists(source))
         {
             File.Copy(source, destination, true);
         }
         else
         {
             File.Delete(destination);
         }
     }
 }
        private ProcessResult ExecuteCommand(IIntegrationResult result, 
            string command, params string[] args)
        {
            var buffer = new PrivateArguments(command);
            buffer.Add(this.Source);
            foreach (var arg in args)
            {
                buffer.Add(string.Empty,
                    arg,
                    true);
            }

            var executable = string.IsNullOrEmpty(this.Executable) ?
                "GetMyCode" : this.Executable;
            var processInfo = new ProcessInfo(
                result.BaseFromWorkingDirectory(executable),
                buffer,
                result.WorkingDirectory);
            var processResult = this.Execute(processInfo);
            return processResult;
        }
Esempio n. 38
0
 protected override string GetProcessBaseDirectory(IIntegrationResult result)
 {
     return result.BaseFromWorkingDirectory(BaseDirectory);
 }
Esempio n. 39
0
		private string BaseWorkingDirectory(IIntegrationResult result)
		{
			return Path.GetFullPath(result.BaseFromWorkingDirectory(WorkingDirectory));
		}
        /// <summary>
        /// Finds the config file.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <param name="fileSystem">The file system.</param>
        /// <returns>
        /// The path to the file if it exists; <c>null</c> otherwise.
        /// </returns>
        private string FindConfigFile(IIntegrationResult result, IFileSystem fileSystem)
        {
            // Generate the initial file to check
            var configFile = this.SourceFile;
            if (!Path.IsPathRooted(configFile))
            {
                configFile = result.BaseFromWorkingDirectory(configFile);
            }

            // Check if th file exists
            Log.Debug("Checking for configuration file '{0}'", configFile);
            var fileExists = fileSystem.FileExists(configFile);
            if (!fileExists && !configFile.EndsWith("ccnet.config", StringComparison.InvariantCultureIgnoreCase))
            {
                // Try adding ccnet.config and see if it exists
                configFile = Path.Combine(configFile, "ccnet.config");
                Log.Debug("Checking for configuration file '{0}'", configFile);
                fileExists = fileSystem.FileExists(configFile);
            }

            if (!fileExists)
            {
                Log.Info("Unable to find find config file");
                return null;
            }

            Log.Info("Found config file '{0}'", configFile);
            return configFile;
        }
Esempio n. 41
0
        /// <summary>
        /// Run the task.
        /// </summary>
        /// <param name="result">The result to use.</param>
        /// <returns>
        /// True if the task was successful, false otherwise.
        /// </returns>
        protected override bool Execute(IIntegrationResult result)
        {
            result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : "Executing DupFinder");
            this.logger = this.logger ?? new DefaultLogger();

            this.executable = string.IsNullOrEmpty(this.Executable) ? DefaultExecutable : this.Executable;
            if (!Path.IsPathRooted(this.executable))
            {
                this.executable = result.BaseFromWorkingDirectory(this.executable);
                this.logger.Debug("Executable changed to " + this.executable);
            }

            // Run the executable
            this.logger.Info("Executing DupFinder");
            var info = this.CreateProcessInfo(result);
            var processResult = this.TryToRun(info, result);
            if (processResult.TimedOut)
            {
                result.AddTaskResult(MakeTimeoutBuildResult(info));
            }

            if (this.ShortenFileNames || this.IncludeCode)
            {
                // Load the results into an XML document
                var document = new XmlDocument();
                document.LoadXml(processResult.StandardOutput);

                if (this.IncludeCode)
                {
                    this.logger.Info("Including duplicate code lines");
                    this.ImportCode(document);
                }

                if (this.ShortenFileNames)
                {
                    this.logger.Info("Shortening filenames");
                    this.RemoveInputDir(document);
                }

                // Generate a new result
                processResult = new ProcessResult(
                    document.OuterXml,
                    processResult.StandardError,
                    processResult.ExitCode,
                    processResult.TimedOut,
                    processResult.Failed);
            }

            // Add the result
            result.AddTaskResult(new ProcessTaskResult(processResult, false));
            return processResult.Succeeded;
        }
Esempio n. 42
0
        private ProcessInfo NewCheckoutProcessInfo(IIntegrationResult result)
        {
            // CCNET-1796: work around a CVS limitation: the -d parameter only accepts limited relative paths
            // so the working directory is one level up of the checkout dir and
            // override checkout directory
            var wd = result.BaseFromWorkingDirectory(WorkingDirectory);
            var lastDirectorySeparatorIndex = wd.TrimEnd().TrimEnd(Path.DirectorySeparatorChar).LastIndexOf(Path.DirectorySeparatorChar);
            var checkoutWd = wd.Substring(0, lastDirectorySeparatorIndex);
            var checkoutDir = wd.Substring(lastDirectorySeparatorIndex).Trim(Path.DirectorySeparatorChar);
            Log.Debug("[CVS] Configured Working Directory: '{0}'", wd);
            Log.Debug("[CVS] Checkout Working Directory: '{0}'", checkoutWd);
            Log.Debug("[CVS] Checkout Directory: '{0}'", checkoutDir);

            ProcessArgumentBuilder builder = new ProcessArgumentBuilder();
            AppendCvsRoot(builder);
            builder.AddArgument("-q");
            builder.AddArgument("checkout");
            builder.AddArgument("-R");
            builder.AddArgument("-P");
            builder.AddArgument("-r", Branch);
            builder.AddArgument("-d", StringUtil.AutoDoubleQuoteString(checkoutDir));
            builder.AddArgument(Module);
            var pi = NewProcessInfoWithArgs(result, builder.ToString());
            pi.WorkingDirectory = checkoutWd;
            return pi;
        }
        /// <summary>
        /// Gets the modifications.	
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        /// <remarks></remarks>
		public override Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
		{
			string destinationDirectory = from.BaseFromWorkingDirectory(WorkingDirectory);

			ProcessArgumentBuilder builder = new ProcessArgumentBuilder();

			AddStandardArguments(builder, destinationDirectory);

			builder.AddArgument("/L");

			Modification[] modifications = GetModifications(new ProcessInfo(Executable, builder.ToString(), null, ProcessPriorityClass.Normal, successExitCodes), from.StartTime, to.StartTime);

			return modifications;
		}
        /// <summary>
        /// Gets the source.	
        /// </summary>
        /// <param name="result">The result.</param>
        /// <remarks></remarks>
		public override void GetSource(IIntegrationResult result)
		{
			if (AutoGetSource)
			{
				string destinationDirectory = result.BaseFromWorkingDirectory(WorkingDirectory);
		
				ProcessArgumentBuilder builder = new ProcessArgumentBuilder();

				AddStandardArguments(builder, destinationDirectory);

                Execute(new ProcessInfo(Executable, builder.ToString(), null, ProcessPriorityClass.Normal, successExitCodes));
			}
		}
Esempio n. 45
0
 private ProcessInfo NewProcessInfo(string args, IIntegrationResult result)
 {
     ProcessInfo pi = new ProcessInfo(Executable, args, result.BaseFromWorkingDirectory(WorkingDirectory));
     // Needed to disable the pager for bk commands, which causes infinite hangs
     pi.EnvironmentVariables.Add("PAGER", "cat");
     return pi;
 }
Esempio n. 46
0
 /// <summary>
 /// Ensures the path is rooted.
 /// </summary>
 /// <param name="result">The result.</param>
 /// <param name="path">The path.</param>
 /// <returns>The rooted path.</returns>
 private string EnsurePathIsRooted(IIntegrationResult result, string path)
 {
     if (!Path.IsPathRooted(path))
     {
         return result.BaseFromWorkingDirectory(path);
     }
     else
     {
         return path;
     }
 }
Esempio n. 47
0
        private ProcessInfo NewProcessInfo(PrivateArguments args, IIntegrationResult result)
        {
            string workingDirectory = Path.GetFullPath(result.BaseFromWorkingDirectory(WorkingDirectory));
            if (!Directory.Exists(workingDirectory)) Directory.CreateDirectory(workingDirectory);

            ProcessInfo processInfo = new ProcessInfo(Executable, args, workingDirectory);
            processInfo.StreamEncoding = Encoding.UTF8;
            return processInfo;
        }
Esempio n. 48
0
        /// <summary>
        /// Retrieve the arguments
        /// </summary>
        /// <param name="result">The result.</param>
        /// <returns>A <c>string</c> containing the arguments.</returns>
        protected override string GetProcessArguments(IIntegrationResult result)
        {
            ProcessArgumentBuilder buffer = new ProcessArgumentBuilder();
            buffer.AddArgument("/quiet");
            buffer.AddArgument("/severityThreshold:\"" + this.ReportingThreshold.ToString() + "\"");
            buffer.AddArgument("/out:\"" + result.BaseFromWorkingDirectory("codeitright.xml") + "\"");
            if (!string.IsNullOrEmpty(this.Solution))
            {
                buffer.AddArgument("/Solution:\"" + this.EnsurePathIsRooted(result, this.Solution) + "\"");
            }
            else if (!string.IsNullOrEmpty(this.Project))
            {
                buffer.AddArgument("/Project:\"" + this.EnsurePathIsRooted(result, this.Project) + "\"");
            }
            else
            {
                throw new CruiseControlException("Either a solution or a project must be specified for analysis.");
            }

            if (!string.IsNullOrEmpty(this.Xsl))
            {
                buffer.AddArgument("/outxsl:\"" + this.EnsurePathIsRooted(result, this.Xsl) + "\"");
            }

            if (!string.IsNullOrEmpty(this.CRData))
            {
                buffer.AddArgument("/crdata:\"" + this.EnsurePathIsRooted(result, this.CRData) + "\"");
            }

            if (!string.IsNullOrEmpty(this.Profile))
            {
                buffer.AddArgument("/profile:\"" + this.Profile + "\"");
            }

            return buffer.ToString();
        }
Esempio n. 49
0
        /// <summary>
        /// Run the task.
        /// </summary>
        /// <param name="result"></param>
        protected override bool Execute(IIntegrationResult result)
        {
            result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : "Running CodeItRight analysis");

            // Run the executable
            var processResult = TryToRun(CreateProcessInfo(result), result);

            // Need to start a new result as CodeItRight returns the number of violation
            processResult = new ProcessResult(
                processResult.StandardOutput,
                processResult.StandardError,
                processResult.ExitCode,
                processResult.TimedOut,
                processResult.ExitCode < 0);
            result.AddTaskResult(new ProcessTaskResult(processResult));

            if (!processResult.Failed)
            {
                var xmlFile = result.BaseFromWorkingDirectory("codeitright.xml");
                result.AddTaskResult(
                    new FileTaskResult(xmlFile, true));
            }

            // Check the failure threshold
            var failed = processResult.Failed;
            if (!failed && (this.FailureThreshold != Severity.None))
            {
                var xmlFile = result.BaseFromWorkingDirectory("codeitright.xml");
                var document = new XmlDocument();
                if (File.Exists(xmlFile))
                {
                    document.Load(xmlFile);
                    for (var level = (int)Severity.CriticalError; level >= (int)this.FailureThreshold; level--)
                    {
                        failed = CodeItRightTask.CheckReportForSeverity(document, (Severity)level);
                        if (failed)
                        {
                            break;
                        }
                    }
                }
            }

            return !failed;
        }
Esempio n. 50
0
        private ProcessInfo NewProcessInfoWithArgs(IIntegrationResult result, string args)
        {
            var wd = result.BaseFromWorkingDirectory(WorkingDirectory);
            // ensure working directory exists
            fileSystem.EnsureFolderExists(wd);

            var pi = new ProcessInfo(Executable, args, wd);
            SetEnvironmentVariables(pi, result);
            return pi;
        }
        /// <summary>
        /// Execute the actual task functionality.
        /// </summary>
        /// <param name="result"></param>
        /// <returns>
        /// True if the task was successful, false otherwise.
        /// </returns>
        protected override bool Execute(IIntegrationResult result)
        {
            result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : "Publishing build results");

            if (result.Succeeded || AlwaysPublish)
            {
                var srcDir = new DirectoryInfo(result.BaseFromWorkingDirectory(SourceDir));
                var pubDir = new DirectoryInfo(result.BaseFromArtifactsDirectory(PublishDir));
                Log.Debug("Publish directory is '{0}'", pubDir.FullName);
                Log.Debug("Source directory is '{0}'", srcDir.FullName);
                if (!srcDir.Exists)
                {
                    Log.Warning("Source directory '{0}' does not exist - cancelling task", srcDir.FullName);
                    var errorResult = new GeneralTaskResult(
                        false,
                        "Unable to find source directory '" + srcDir.FullName + "'");
                    result.AddTaskResult(errorResult);
                    return false;
                }

                if (!pubDir.Exists)
                {
                    Log.Info("Publish directory '{0}' does not exist - creating", pubDir.FullName);
                    pubDir.Create();
                }
                else
                {
                    if (CleanPublishDirPriorToCopy)
                    {
                        DeleteFolder(pubDir.FullName);
                        pubDir.Create();
                    }
                }

                if (UseLabelSubDirectory)
                    pubDir = pubDir.CreateSubdirectory(result.Label);

                RecurseSubDirectories(srcDir, pubDir, this.Recurse);

                switch (CleanUpMethod)
                {
                    case CleanupPolicy.NoCleaning:
                        break;

                    case CleanupPolicy.DeleteBuildsOlderThanXDays:
                        DeleteSubDirsOlderThanXDays(new DirectoryInfo(result.BaseFromArtifactsDirectory(PublishDir)).FullName,
                                                    CleanUpValue, result.BuildLogDirectory);
                        break;

                    case CleanupPolicy.KeepLastXBuilds:
                        KeepLastXSubDirs(new DirectoryInfo(result.BaseFromArtifactsDirectory(PublishDir)).FullName,
                                                    CleanUpValue, result.BuildLogDirectory);
                        break;

                    default:
                        throw new System.Exception(string.Format(System.Globalization.CultureInfo.CurrentCulture, "unmapped cleaning method choosen {0}", CleanUpMethod));
                }
            }

            return true;
        }
Esempio n. 52
0
        private ProcessInfo RevertWorkingCopy(IIntegrationResult result)
        {
            var buffer = new PrivateArguments("revert", "--recursive");
            buffer.Add(null, Path.GetFullPath(result.BaseFromWorkingDirectory(WorkingDirectory)), true);

            return NewProcessInfo(buffer, result);
        }
Esempio n. 53
0
        private ProcessInfo NewProcessInfoWith(PrivateArguments args, IIntegrationResult result)
        {
            string workingDirectory = result.BaseFromWorkingDirectory(WorkingDirectory);
            if (! Directory.Exists(workingDirectory)) Directory.CreateDirectory(workingDirectory);

            ProcessInfo processInfo = new ProcessInfo(Executable, args, workingDirectory);
            if (SsDir != null)
            {
                processInfo.EnvironmentVariables[SS_DIR_KEY] = SsDir;
            }
            return processInfo;
        }
Esempio n. 54
0
 private bool DoesSvnDirectoryExist(IIntegrationResult result)
 {
     string svnDirectory = Path.Combine(result.BaseFromWorkingDirectory(WorkingDirectory), ".svn");
     string underscoreSvnDirectory = Path.Combine(result.BaseFromWorkingDirectory(WorkingDirectory), "_svn");
     return fileSystem.DirectoryExists(svnDirectory) || fileSystem.DirectoryExists(underscoreSvnDirectory);
 }
Esempio n. 55
0
 private string BaseDirectory(IIntegrationResult result)
 {
     return result.BaseFromWorkingDirectory(ConfiguredScriptsDirectory);
 }
Esempio n. 56
0
 private bool DoesCvsDirectoryExist(IIntegrationResult result)
 {
     string cvsDirectory = Path.Combine(result.BaseFromWorkingDirectory(WorkingDirectory), "CVS");
     return fileSystem.DirectoryExists(cvsDirectory);
 }
Esempio n. 57
0
 private ProcessInfo NewGetSourceProcessInfo(IIntegrationResult result)
 {
     var buffer = new PrivateArguments("update");
     buffer.Add(null, Path.GetFullPath(result.BaseFromWorkingDirectory(WorkingDirectory)), true);
     // Do not use Modification.GetLastChangeNumber() here directly.
     AppendRevision(buffer, latestRevision);
     AppendCommonSwitches(buffer);
     if (ForceUpdate) buffer.Add("--force");
     return NewProcessInfo(buffer, result);
 }
Esempio n. 58
0
 private ProcessInfo NewCheckoutProcessInfo(IIntegrationResult result)
 {
     var buffer = new PrivateArguments("checkout");
     buffer.Add(string.Empty, TrunkUrl, true);
     buffer.Add(null, Path.GetFullPath(result.BaseFromWorkingDirectory(WorkingDirectory)), true);
     AppendCommonSwitches(buffer);
     return NewProcessInfo(buffer, result);
 }
Esempio n. 59
0
 /// <summary>
 /// Generate and return a label from the file content.
 /// </summary>
 /// <param name="integrationResult">the current integration result</param>
 /// <returns>the label</returns>
 public override string Generate(IIntegrationResult integrationResult)
 {
     string label = fileReader.GetLabel(integrationResult.BaseFromWorkingDirectory(labelFilePath));
     string suffix = GetSuffixBasedOn(label, integrationResult.LastIntegration.Label);
     return string.Format("{0}{1}{2}", prefix, label, suffix);
 }
Esempio n. 60
0
 private string TagSource(IIntegrationResult result)
 {
     if (Modification.GetLastChangeNumber(mods) == null)
     {
         return Path.GetFullPath(result.BaseFromWorkingDirectory(WorkingDirectory)).TrimEnd(Path.DirectorySeparatorChar);
     }
     return TrunkUrl;
 }