Exemplo n.º 1
0
 /// <summary>
 /// Default constructor - initializes all fields to default values
 /// </summary>
 public LogFile(CvsRoot cvsRoot)
 {
     this.repositoryFnm = "";
     this.workingFnm    = "";
     this.description   = "";
     this.cvsRoot       = cvsRoot;
 }
Exemplo n.º 2
0
        private void UpdateAllRecursive(String rootDir, String overrideDirectory)
        {
            CvsRoot          root    = new CvsRoot(this.settings.Config.Cvsroot);
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     this.settings.Config.LocalPath,
                                     this.settings.Config.Module);

            working.OverrideDirectory = overrideDirectory;

            CVSServerConnection connection = new CVSServerConnection();

            Assert.IsNotNull(connection);

            ICommand command = new UpdateCommand2(working);

            Assert.IsNotNull(command);

            connection.Connect(working, this.settings.Config.ValidPassword);

            // Update all files...
            LOGGER.Debug("Fetching all files from rootDir=[" + rootDir + "]");
            working.FoldersToUpdate =
                this.manager.FetchFilesToUpdate(rootDir);

            command.Execute(connection);
            connection.Close();
        }
        public void UpdateFromCvsntTest_Checkout()
        {
            string cvsPath =
                Path.Combine(this.settings.Config.LocalPath, CVSNT_MODULE);
            Manager manager = new Manager(cvsPath);

            CvsRoot          root    = new CvsRoot(CVSNT_CVSROOT);
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     this.settings.Config.LocalPath,
                                     CVSNT_MODULE);

            CVSServerConnection connection = new CVSServerConnection();

            Assert.IsNotNull(connection);

            ICommand command = new CheckoutModuleCommand(working);

            Assert.IsNotNull(command);

            try {
                connection.Connect(working, this.settings.Config.ValidPassword);
            } catch (AuthenticationException) {
                Assert.IsTrue(true);
            }

            command.Execute(connection);
            connection.Close();

            this.PerformUpdate();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Login to a cvs repository with workDirectory object
 /// </summary>
 /// <param name="cvsRoot">The repository root.</param>
 /// <param name="workingDirectory">User information</param>
 public LoginCommand(CvsRoot cvsRoot, WorkingDirectory workingDirectory)
 {
     this.cvsRoot          = cvsRoot;
     this.workingDirectory = workingDirectory;
     // Is there a password file?
     //     yes, get password for this username
     //     no, prompt user for password to use
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new instance of the command parser.
 /// </summary>
 /// <param name="command"></param>
 /// <param name="args"></param>
 /// <param name="cvsRoot"></param>
 /// <param name="workingDirectory"></param>
 public CommandParserFactory(string command, string[] args,
                             CvsRoot cvsRoot, WorkingDirectory workingDirectory)
 {
     this.command          = command;
     this.args             = GetArgsAfterCommandName(args);
     this.cvsRoot          = cvsRoot;
     this.workingDirectory = workingDirectory;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Create the command object that will be used to act on the repository.
        /// </summary>
        /// <returns>The command object that will be used to act on the
        ///     repository.</returns>
        /// <exception cref="Exception">TODO: Make a more specific exception</exception>
        /// <exception cref="NotImplementedException">If the command argument
        ///     is not implemented currently.  TODO: Implement the argument.</exception>
        public override ICommand CreateCommand()
        {
            DirectoryInfo dir =
                new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "CVS"));

            UpdateCommand2 updateCommand;

            this.ParseOptions(this.unparsedOptions);
            // note the sandbox is actually above the CVS directory
            Manager manager = new Manager(dir.Parent);

            Repository repository = null;
            Root       root       = null;

            try {
                repository = Repository.Load(dir);
                root       = Root.Load(dir);
            } catch (NullReferenceException) {
                this.InvalidRepository();
            } catch (CvsFileNotFoundException) {
                this.InvalidRepository();
            }

            if (null == repository)
            {
                this.InvalidRepository();
            }

            try {
                this.cvsRootVar = new CvsRoot(root.FileContents);
            } catch (ICSharpCode.SharpCvsLib.Exceptions.CvsRootParseException) {
                this.InvalidRepository();
            }

            // If this fails error out and state the user
            //    is not in a CVS repository directory tree.
            if (localDirectory == null)
            {
                localDirectory = dir.Parent.FullName;
            }
            CurrentWorkingDirectory = new WorkingDirectory(this.CvsRootVar,
                                                           localDirectory, repository.FileContents);
            if (revision != null)
            {
                CurrentWorkingDirectory.Revision = revision;
            }
            if (!date.Equals(DateTime.MinValue))
            {
                CurrentWorkingDirectory.Date = date;
            }
            CurrentWorkingDirectory.FoldersToUpdate =
                manager.FetchFilesToUpdate(dir.FullName);
            // Create new UpdateCommand2 object
            updateCommand = new UpdateCommand2(CurrentWorkingDirectory);

            return(updateCommand);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get the repository folder in order to strip it from the RCS file.
        /// The repository folder is the last part of the CVSRoot path -- unless the local protocol is used on windows machines.
        /// Examples:
        ///		CvsRoot=":pserver:[email protected]:/cvsroot/cruisecontrol", Module="cruisecontrol", RepositoryFolder="/cvsroot/cruisecontrol/cruisecontrol"
        ///		CvsRoot=":local:C:\dev\CVSRoot", Module="fitwebservice", RepositoryFolder="C:\dev\CVSRoot/fitwebservice"
        /// </summary>
        private string GetRepositoryFolder()
        {
            string modulePath = '/' + Module + '/';

            if (CvsRoot.StartsWith(LocalCvsProtocolString))
            {
                return(CvsRoot.Substring(LocalCvsProtocolString.Length) + modulePath);
            }
            return(CvsRoot.Substring(CvsRoot.LastIndexOf(':') + 1) + modulePath);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Create a new <see cref="ListCommand"/>, initialize the variables that are used
        ///     in a checkout.
        /// </summary>
        /// <param name="cvsRoot">The cvs root to use for this checkout.</param>
        /// <param name="args">Commandline arguments to be parsed out and used for the command.</param>
        public ListCommandParser(CvsRoot cvsRoot, string[] args)
        {
            this.CvsRoot = cvsRoot;
            StringBuilder coOptions = new StringBuilder();

            foreach (string arg in args)
            {
                coOptions.Append(arg);
            }
            this.unparsedOptions = coOptions.ToString();
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Constructor, parses out the orgainizational path response from
        ///         the cvs server.
        /// </summary>
        /// <param name="workingDirectory">Contains information about the working
        ///     repository.</param>
        /// <param name="repositoryPath">The relative path to the file served
        ///     down from the cvs server.</param>
        public PathTranslator(WorkingDirectory workingDirectory,
                              String repositoryPath)
        {
            this.baseDir      = new DirectoryInfo(workingDirectory.LocalDirectory);
            this.moduleFacade = workingDirectory.WorkingDirectoryName;

            this.repositoryPath   = repositoryPath;
            this.workingDirectory = workingDirectory;
            this.cvsRoot          = workingDirectory.CvsRoot;
            this.relativePath     =
                this.GetRelativePath(repositoryPath);

            this._currentDir =
                new DirectoryInfo(Path.Combine(Path.Combine(baseDir.FullName,
                                                            this.workingDirectory.WorkingDirectoryName), this.relativePath));
        }
Exemplo n.º 10
0
        public void AddToCvsPass()
        {
            Manager  manager     = new Manager(Path.GetTempPath());
            CvsRoot  root        = this.settings.GetCvsRoot();
            FileInfo cvsPassFile = new FileInfo(Path.Combine(Path.GetTempPath(), ".cvspass"));

            Assertion.Assert(!cvsPassFile.Exists);
            manager.UpdatePassFile("password", root, cvsPassFile);
            Assertion.Assert(string.Format("File does not exist {0}",
                                           cvsPassFile.FullName), File.Exists(cvsPassFile.FullName));
            using (StreamReader stream = new StreamReader(cvsPassFile.FullName)) {
                string line = stream.ReadToEnd();
                Assertion.AssertNotNull(line);
            }

            cvsPassFile.Delete();
        }
Exemplo n.º 11
0
        public void TestSlashMaintained()
        {
            CvsRoot          cvsRoot          = new CvsRoot(ROOT_ENTRY1);
            WorkingDirectory workingDirectory =
                new WorkingDirectory(cvsRoot, LOCAL_ROOT_DIR1, REPOS_NAME1);
            PathTranslator pathTranslator =
                new PathTranslator(workingDirectory, REPOS_DIR_PATH1);

            Assert.AreEqual("src/ICSharpCode/SharpCvsLib/FileSystem/", pathTranslator.RelativePath);
            Assert.AreEqual("FileSystem", pathTranslator.Filename);
            String expectedLocalPath =
                PathTranslator.ConvertToOSSpecificPath(Path.Combine(LOCAL_DIR1, "src/ICSharpCode/SharpCvsLib/FileSystem/"));

            Assert.AreEqual(expectedLocalPath, pathTranslator.LocalPathAndFilename);
            Assert.AreEqual(expectedLocalPath, pathTranslator.LocalPathAndFilename);
            Assert.IsTrue(pathTranslator.IsDirectory == true);
        }
Exemplo n.º 12
0
        private static WorkingDirectory DeriveWorkingDirectory()
        {
            DirectoryInfo currDir = new DirectoryInfo(Environment.CurrentDirectory);

            LOGGER.Info(string.Format("Repository is null, " +
                                      "attempting to derive from current directory: {0}.", currDir.FullName));

            Manager    manager    = new Manager(currDir);
            Repository repository =
                manager.FetchRepository(currDir.FullName);
            Root root =
                manager.FetchRoot(currDir.FullName);
            CvsRoot cvsRoot = new CvsRoot(root.FileContents);

            return
                (new WorkingDirectory(cvsRoot, Environment.CurrentDirectory, repository.ModuleName));
        }
        private void PerformUpdate()
        {
            CvsRoot          root    = new CvsRoot(CVSNT_CVSROOT);
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     this.settings.Config.LocalPath,
                                     CVSNT_MODULE);

            CVSServerConnection connection = new CVSServerConnection();

            Assert.IsNotNull(connection);

            ICommand command = new UpdateCommand2(working);

            Assert.IsNotNull(command);

            connection.Connect(working, this.settings.Config.ValidPassword);
        }
        public void UpdateNoCheckoutTest()
        {
            CvsRoot          root    = new CvsRoot(this.settings.Config.Cvsroot);
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     this.settings.Config.LocalPath,
                                     CVSNT_MODULE);

            CVSServerConnection connection = new CVSServerConnection();

            Assert.IsNotNull(connection);

            ICommand command = new UpdateCommand2(working);

            Assert.IsNotNull(command);

            connection.Connect(working, this.settings.Config.ValidPassword);
        }
Exemplo n.º 15
0
        public void TestAddTag()
        {
            CvsRoot          root             = new CvsRoot(this.settings.Config.Cvsroot);
            WorkingDirectory workingDirectory =
                new WorkingDirectory(root,
                                     this.settings.Config.LocalPath,
                                     this.settings.Config.Module);
            CVSServerConnection connection = new CVSServerConnection();

            this.Checkout(workingDirectory, connection);

            RTagCommand command = new RTagCommand(workingDirectory);

            command.TagName = TEST_TAG_1;

            connection.Connect(workingDirectory, this.settings.ValidPassword);
            command.Execute(connection);
        }
Exemplo n.º 16
0
        public IExternalSource Checkout(string cvsroot, string module, string password,
                                        out string target)
        {
            //Set temp checkout dir
            target = System.IO.Path.Combine(Globals.TempDirectory, Guid.NewGuid().ToString());
            Directory.CreateDirectory(target);

            //Setup CVS vars
            CvsRoot          root    = new CvsRoot(cvsroot);
            WorkingDirectory working = new WorkingDirectory(root, target, module);

            CVSServerConnection connection = new CVSServerConnection();

            if (connection == null)
            {
                throw new ToolExecutionException("Unable to connect to the CVS server");
            }

            //Connect to CVS
            ICSharpCode.SharpCvsLib.Commands.ICommand command =
                new CheckoutModuleCommand(working);
            if (command == null)
            {
                throw new ToolExecutionException("Failure to create a checkout command object");
            }
            try {
                connection.Connect(working, password);
            } catch (AuthenticationException) {
                throw new ToolExecutionException("CVS rejected access (doublecheck all fields): Authentication failure");
            } catch (Exception er) {
                throw new ToolExecutionException("CVS rejected access (doublecheck all fields): " + er.Message);
            }

            //Execute checkout command
            try {
                command.Execute(connection);
                connection.Close();
            } catch (Exception er) {
                throw new ToolExecutionException("CVS error: " + er.Message);
            }

            //Create source from module root
            return(CreateSource(Path.Combine(target, module)));
        }
Exemplo n.º 17
0
        public void TestRepeatedFileComponent()
        {
            CvsRoot          cvsRoot;
            WorkingDirectory workingDirectory;
            PathTranslator   pathTranslator;

            cvsRoot          = new CvsRoot(ROOT_ENTRY1);
            workingDirectory = new WorkingDirectory(cvsRoot, LOCAL_ROOT_DIR1, REPOS_NAME1);
            pathTranslator   = new PathTranslator(workingDirectory, REPOS_FILE_PATH2);

            Assert.AreEqual("/cvsroot/sharpcvslib", pathTranslator.CvsRoot.CvsRepository, pathTranslator.CvsRoot.CvsRepository);
            Assert.AreEqual("src/ICSharpCode/SharpCvsLib/FileSystem/Sharp", pathTranslator.RelativePath);
            Assert.AreEqual("Sharp", pathTranslator.Filename, pathTranslator.Filename);
            String expectedLocalPath =
                PathTranslator.ConvertToOSSpecificPath(Path.Combine(LOCAL_DIR1, "src/ICSharpCode/SharpCvsLib/FileSystem/Sharp"));

            Assert.AreEqual(expectedLocalPath, pathTranslator.LocalPathAndFilename);
            Assert.AreEqual(false, pathTranslator.IsDirectory);
        }
Exemplo n.º 18
0
        public void MakeConnection_Good()
        {
            LOGGER.Debug("Entering MakeConnection_Good");
            CvsRoot          root    = new CvsRoot(this.Settings.Config.Cvsroot);
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     this.Settings.Config.LocalPath,
                                     this.Settings.Config.Module);

            CVSServerConnection connection = new CVSServerConnection();

            Assert.IsNotNull(connection, "Should have a connection object.  WorkingDirectory=[" + working + "]");

            try {
                connection.Connect(working, this.Settings.Config.ValidPassword);
            } catch (Exception e) {
                Assert.Fail(e.ToString() + "; WorkingDirectory=[" + working + "]");
            }
            connection.Close();
        }
Exemplo n.º 19
0
        public void TestDirPathTranslation()
        {
            CvsRoot          cvsRoot;
            WorkingDirectory workingDirectory;
            PathTranslator   pathTranslator;

            cvsRoot          = new CvsRoot(ROOT_ENTRY1);
            workingDirectory = new WorkingDirectory(cvsRoot, LOCAL_ROOT_DIR1, REPOS_NAME1);
            pathTranslator   = new PathTranslator(workingDirectory, REPOS_DIR_PATH1);

            Assert.AreEqual("/cvsroot/sharpcvslib", pathTranslator.CvsRoot.CvsRepository,
                            pathTranslator.CvsRoot.CvsRepository);
            Assert.AreEqual("src/ICSharpCode/SharpCvsLib/FileSystem/", pathTranslator.RelativePath, pathTranslator.RelativePath);
            Assert.AreEqual("dev-src", pathTranslator.BaseDir.Name);
            String expectedLocalPath =
                PathTranslator.ConvertToOSSpecificPath(Path.Combine(LOCAL_DIR1, "src/ICSharpCode/SharpCvsLib/FileSystem/"));

            Assert.AreEqual(expectedLocalPath, pathTranslator.CurrentDir.FullName);
            Assert.AreEqual(expectedLocalPath, pathTranslator.LocalPathAndFilename);
            Assert.IsTrue(pathTranslator.IsDirectory == true);
        }
Exemplo n.º 20
0
        public void MakeConnection_Bad()
        {
            CvsRoot root = new CvsRoot(this.Settings.Config.Cvsroot);

            root.User = "******";
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     this.Settings.Config.LocalPath,
                                     this.Settings.Config.Module);

            CVSServerConnection connection = new CVSServerConnection();

            Assert.IsNotNull(connection, "Should have a connection object.");

            try {
                connection.Connect(working, this.Settings.Config.InvalidPassword);
            } catch (AuthenticationException e) {
                connection.Close();
                throw e;
            }
        }
Exemplo n.º 21
0
        private void Checkout()
        {
            CvsRoot          root    = new CvsRoot(this.settings.Config.Cvsroot);
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     this.settings.Config.LocalPath,
                                     this.settings.Config.Module);

            CVSServerConnection connection = new CVSServerConnection();

            Assert.IsNotNull(connection, "Should have a connection object.");

            ICommand command = new CheckoutModuleCommand(working);

            Assert.IsNotNull(command, "Should have a command object.");

            connection.Connect(working, this.settings.Config.ValidPassword);

            command.Execute(connection);
            connection.Close();
        }
Exemplo n.º 22
0
        public void FindAllWorkingFolders()
        {
            Manager manager =
                new Manager(Path.Combine(this.settings.LocalPath, this.settings.Module));
            string rootDir =
                Path.Combine(this.settings.Config.LocalPath, this.settings.Config.Module);

            CvsRoot          root    = new CvsRoot(this.settings.Config.Cvsroot);
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     rootDir,
                                     this.settings.Config.Module);

            this.WriteTestDirectoryEntries(rootDir);
            Repository repository = new Repository(rootDir, this.REPOSITORY_ENTRY);

            manager.AddRepository(repository);
            working.FoldersToUpdate = manager.FetchFilesToUpdate(rootDir);

            Assert.IsTrue(working.FoldersToUpdate.Length > 1,
                          "Working folders count should be greater than 1.");
        }
Exemplo n.º 23
0
        /// <summary>
        /// Create the command object that will be used to act on the repository.
        /// </summary>
        /// <returns>The command object that will be used to act on the
        ///     repository.</returns>
        /// <exception cref="Exception">TODO: Make a more specific exception</exception>
        /// <exception cref="NotImplementedException">If the command argument
        ///     is not implemented currently.  TODO: Implement the argument.</exception>
        public override ICommand CreateCommand()
        {
            ICSharpCode.SharpCvsLib.Commands.LogCommand logCommand;
            DirectoryInfo dir = new DirectoryInfo(Directory.GetCurrentDirectory());

            this.ParseOptions(this.unparsedOptions);
            try {
                Repository repository = Repository.Load(dir);
                if (null == repository || null == repository.FileContents)
                {
                    throw new CvsFileNotFoundException(
                              string.Format("Valid CVS\\Repository file not found in {0}",
                                            dir));
                }
                this.repository = repository.FileContents;
                Root root = Root.Load(dir);
                if (null == root || null == root.FileContents)
                {
                    throw new CvsFileNotFoundException(
                              string.Format("Valid CVS\\Root file not found in {0}",
                                            dir));
                }
                this.cvsRoot = new CvsRoot(root.FileContents);
            } catch (CvsFileNotFoundException e) {
                LOGGER.Error(e);
                ConsoleMain.ExitProgram("Not a CVS repository.", e);
            }

            CurrentWorkingDirectory = new WorkingDirectory(this.cvsRoot,
                                                           dir.FullName, this.repository);


            logCommand =
                new ICSharpCode.SharpCvsLib.Commands.LogCommand(
                    CurrentWorkingDirectory, folders);

            return(logCommand);
        }
Exemplo n.º 24
0
 /// <summary>
 ///    Remove file(s) in the cvs repository
 /// </summary>
 /// <param name="cvsroot">User Information</param>
 /// <param name="fileNames">Files to remove</param>
 /// <param name="rmOptions">Options</param>
 public RemoveCommandParser(CvsRoot cvsroot, string fileNames, string rmOptions)
 {
     this.cvsRoot         = cvsroot;
     this.fileNames       = fileNames;
     this.unparsedOptions = rmOptions;
 }
Exemplo n.º 25
0
 /// <summary>
 ///    Update modules or files in the cvs repository
 /// </summary>
 /// <param name="cvsroot">User Information</param>
 /// <param name="fileNames">Files</param>
 /// <param name="upOptions">Options</param>
 public StatusCommandParser(CvsRoot cvsroot, string fileNames, string upOptions)
 {
     this.cvsRootVar      = cvsroot;
     this.fileNames       = fileNames;
     this.unparsedOptions = upOptions;
 }
Exemplo n.º 26
0
        /// <summary>
        /// Produce the report
        /// Alternate interface for when we are given a server cooection
        /// This is needed for the SharpCvsLib command line client
        /// </summary>
        public LogReport Run(ICommandConnection connection)
        {
            // read Root and Repository from local directory
            if (null == this.cvsRoot)
            {
                Manager manager = new Manager(localDirectory);
                Root    root    = (Root)manager.FetchSingle(localDirectory,
                                                            Factory.FileType.Root);

                this.cvsRoot = new CvsRoot(root.FileContents);
            }

            if (null == workingDirectory)
            {
                Manager    manager    = new Manager(localDirectory);
                Repository repository = (Repository)manager.FetchSingle(localDirectory,
                                                                        Factory.FileType.Repository);

                this.workingDirectory = new WorkingDirectory(cvsRoot,
                                                             localDirectory,
                                                             repository.FileContents);
            }

            ILogCommand command;

            // Recursively add all cvs folders/files under the localDirectory
            System.Console.WriteLine("GNE workingDirectory.WorkingPath = {0}", workingDirectory.WorkingPath);
            System.Console.WriteLine("GNE localDirectory: {0}", localDirectory);
            //           if (Directory.Exists(workingDirectory.WorkingPath)) {
            if (Directory.Exists(localDirectory) && File.Exists(Path.Combine(localDirectory, "Repository")))
            {
                workingDirectory.FoldersToUpdate = FetchFiles(localDirectory);
                command =
                    new LogCommand(workingDirectory, this.workingDirectory.ModuleName, null);
            }
            else
            {
                command =
// GNE - this wont compile                   new LogCommand(workingDirectory, this.workingDirectory.ModuleName);
                    new RLogCommand(workingDirectory, this.workingDirectory.ModuleName);
            }

            // add any date restrictions
            if (hasStartDate && hasEndDate)
            {
                command.AddInclusiveDateRange(startDate, endDate);
            }
            else if (hasStartDate)
            {
                command.AddInclusiveDateStart(startDate);
            }
            else if (hasEndDate)
            {
                command.AddInclusiveDateEnd(endDate);
            }

            // Initialse state machine
            curLogReport   = new LogReport(); // this is what we are going to return to the caller
            curLogFile     = new LogFile(this.cvsRoot);
            curLogRevision = new LogRevision();
            logState       = LogState.WANT_FILE_HEADER_START;

            if (connection.GetType() == typeof(CVSServerConnection))
            {
                CVSServerConnection cvsServerConnection = (CVSServerConnection)connection;
                cvsServerConnection.MessageEvent.MessageEvent += new EncodedMessage.MessageHandler(OnMessage);
            }
            command.Execute(connection);

            // return curLogReport but clear our reference to it
            LogReport report = curLogReport;

            curLogReport = null;
            return(report);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Parse the command line options.  There are two (2) general sweeps
        ///     at parsing the command line.  The first sweep looks for command line
        ///     help switches, denoted by -- parameters.
        /// </summary>
        /// <returns>A command object from the library which will be used to
        ///     access the repsository.</returns>
        /// <exception cref="CommandLineParseException">If there is a problem
        ///     parsing the command line arguments (i.e. if invalid arguments
        ///     are entered.</exception>
        public ICommand Execute()
        {
            if (LOGGER.IsDebugEnabled)
            {
                StringBuilder msg = new StringBuilder();
                msg.Append("\n Command line arguments:");
                foreach (String argument in this.arguments)
                {
                    msg.Append("\n\t argument=[").Append(argument).Append("]");
                }
                LOGGER.Debug(msg);
            }

            bool isHelp = this.ParseHelp(this.arguments);

            if (isHelp)
            {
                return(null);
            }

            int startIndex = 0;
            // TODO: Remove = null when all other code paths return a value,
            //      this was just put in so it would compile.
            ICommand command = null;

            if (arguments.Length < 1)
            {
                System.Console.WriteLine(Usage.General);
            }

            if (arguments.Length > 0 &&
                (arguments[0] == "-d"))
            {
                this.cvsRoot = new CvsRoot(this.arguments[1]);
                startIndex   = 2;
            }
            else if (arguments.Length > 0 &&
                     (arguments[0].Length > 2) &&
                     arguments[0].Substring(0, 2) == "-d")
            {
                this.cvsRoot = new CvsRoot(this.arguments[0].Substring(2).Trim());
                startIndex   = 1;
            }

            for (int i = startIndex; i < arguments.Length; i++)
            {
                if (LOGGER.IsDebugEnabled)
                {
                    StringBuilder msg = new StringBuilder();
                    msg.Append("arguments[").Append(i).Append("]=[").Append(arguments[i]).Append("]");
                    LOGGER.Debug(msg);
                }
                LOGGER.Debug("Before we grab the arguments.");
                string commandString = arguments[i].Trim();
                CommandParserFactory factory;
                ICommandParser       parser;
                switch (commandString)
                {
                case "add":
                case "ad":
                case "new":
                    // no single options for the Add command
                    this.commandTxt = arguments[i];
                    i++;
                    // get rest of arguments which is options on the commit command.
                    while (arguments.Length > i && arguments[i].IndexOf("-", 0, 1) >= 0)
                    {
                        // Get options with second parameters?
                        if (arguments[i].IndexOfAny(singleOptions.ToCharArray(), 1, 1) >= 0)
                        {
                            for (int cnt = 1; cnt < arguments[i].Length; cnt++)
                            {
                                this.options = this.options + "-" + arguments[i][cnt] + " ";     // No
                            }
                        }
                        else
                        {
                            this.options = this.options + arguments[i++];           // Yes
                            this.options = this.options + arguments[i] + " ";
                        }
                        i++;
                    }
                    if (arguments.Length > i)
                    {
                        // Safely grab the module, if not specified then
                        //  pass null into the repository...the cvs command
                        //  line for cvsnt/ cvs seems to bomb out when
                        //  it sends to the server
                        this.repository = arguments[i];
                    }
                    else
                    {
                        this.repository = String.Empty;
                    }
                    AddCommandParser addCommand =
                        new AddCommandParser(this.CvsRoot, repository, options);
                    command = addCommand.CreateCommand();
                    this.currentWorkingDirectory =
                        addCommand.CurrentWorkingDirectory;
                    break;

                case "commit":
                case "ci":
                case "com":
                    singleOptions   = "DRcfln";
                    this.commandTxt = arguments[i];
                    i++;
                    // get rest of arguments which is options on the commit command.
                    while (arguments.Length > i && arguments[i].IndexOf("-", 0, 1) >= 0)
                    {
                        LOGGER.Debug("Parsing arguments.  Argument[" + i + "]=[" + arguments[i]);
                        // Get options with second parameters?
                        if (arguments[i].IndexOfAny(singleOptions.ToCharArray(), 1, 1) >= 0)
                        {
                            for (int cnt = 1; cnt < arguments[i].Length; cnt++)
                            {
                                this.options = this.options + "-" + arguments[i][cnt] + " ";     // No
                            }
                        }
                        else
                        {
                            this.options = this.options + arguments[i++];           // Yes
                            this.options = this.options + arguments[i] + " ";
                        }
                        i++;
                    }
                    if (arguments.Length > i)
                    {
                        // Safely grab the module, if not specified then
                        //  pass null into the repository...the cvs command
                        //  line for cvsnt/ cvs seems to bomb out when
                        //  it sends to the server
                        this.repository = arguments[i];
                    }
                    else
                    {
                        this.repository = String.Empty;
                    }
                    CommitCommandParser commitCommand =
                        new CommitCommandParser(this.CvsRoot, repository, options);
                    command = commitCommand.CreateCommand();
                    this.currentWorkingDirectory =
                        commitCommand.CurrentWorkingDirectory;
                    break;

                case "checkout":
                case "co":
                case "get":
                    singleOptions   = "ANPRcflnps";
                    this.commandTxt = arguments[i];
                    i++;
                    // get rest of arguments which is options on the checkout command.
                    while (arguments.Length > i && arguments[i].Trim().IndexOf("-") == 0)
                    {
                        // Get options with second parameters?
                        if (arguments[i].Trim().IndexOfAny(singleOptions.ToCharArray(), 1, 1) >= 0)
                        {
                            for (int cnt = 1; cnt < arguments[i].Length; cnt++)
                            {
                                this.options = this.options + "-" + arguments[i][cnt] + " ";     // No
                            }
                        }
                        else
                        {
                            this.options = this.options + arguments[i++];           // Yes
                            this.options = this.options + arguments[i] + " ";
                        }
                        i++;
                    }
                    if (arguments.Length > i)
                    {
                        // Safely grab the module, if not specified then
                        //  pass null into the repository...the cvs command
                        //  line for cvsnt/ cvs seems to bomb out when
                        //  it sends to the server
                        this.repository = arguments[i];
                    }
                    else
                    {
                        this.repository = String.Empty;
                    }
                    CheckoutCommandParser checkoutCommand =
                        new CheckoutCommandParser(this.CvsRoot, this.Repository, options);
                    command = checkoutCommand.CreateCommand();
                    this.currentWorkingDirectory =
                        checkoutCommand.CurrentWorkingDirectory;
                    break;

                case "import":
                case "imp":
                case "im":
                    i++;
                    string [] tempArgs = new string[arguments.Length - i];
                    Array.Copy(arguments, i, tempArgs, 0, arguments.Length - i);
                    ImportCommandParser importCommand =
                        new ImportCommandParser(this.CvsRoot, tempArgs);
                    command = importCommand.CreateCommand();
                    this.currentWorkingDirectory =
                        importCommand.CurrentWorkingDirectory;
                    i = arguments.Length;
                    break;

                case "init":
                    this.commandTxt = arguments[i];
                    InitCommandParser initCommand = new InitCommandParser(this.CvsRoot);
                    command = initCommand.CreateCommand();
                    this.currentWorkingDirectory = initCommand.CurrentWorkingDirectory;
                    break;

                case "log":
                case "lo":
                    this.commandTxt = arguments[i++];
                    string[] logArgs = new string[arguments.Length - i];
                    Array.Copy(arguments, i, logArgs, 0, arguments.Length - i);
                    LogCommandParser logCommandParser =
                        new LogCommandParser(this.CvsRoot, logArgs);
                    command = logCommandParser.CreateCommand();
                    this.currentWorkingDirectory = logCommandParser.CurrentWorkingDirectory;
                    i = arguments.Length;
                    break;

                case "login":
                case "logon":
                case "lgn":
                    // login to server
                    this.commandTxt = arguments[i];
                    LoginCommand loginCommand =
                        new LoginCommand(this.CvsRoot, this.currentWorkingDirectory);
                    loginCommand.Args            = arguments;
                    this.currentWorkingDirectory = loginCommand.CurrentWorkingDirectory;
                    command = loginCommand;
                    break;

                case "dir":
                case "list":
                case "ls":
                    factory =
                        new CommandParserFactory("ls", arguments,
                                                 this.cvsRoot, this.currentWorkingDirectory);

                    parser  = factory.GetCommandParser();
                    i       = arguments.Length;
                    command = parser.CreateCommand();
                    this.currentWorkingDirectory =
                        parser.CurrentWorkingDirectory;
                    break;

                case "passwd":
                case "password":
                case "setpass":
                    this.commandTxt = arguments[i];
                    break;

                case "remove":
                case "delete":
                case "rm":
                    singleOptions   = "Rfl";
                    this.commandTxt = arguments[i];
                    i++;
                    // get rest of arguments which is options on the update command.
                    while (arguments.Length > i && arguments[i].IndexOf("-", 0, 1) >= 0)
                    {
                        // Get options with second parameters?
                        if (arguments[i].IndexOfAny(singleOptions.ToCharArray(), 1, 1) >= 0)
                        {
                            for (int cnt = 1; cnt < arguments[i].Length; cnt++)
                            {
                                this.options = this.options + "-" + arguments[i][cnt] + " ";     // No
                            }
                        }
                        else
                        {
                            this.options = this.options + arguments[i];           // Yes
                            this.options = this.options + arguments[i] + " ";
                        }
                        i++;
                    }
                    if (arguments.Length > i)
                    {
                        // Safely grab the module, if not specified then
                        //  pass null into the repository...the cvs command
                        //  line for cvsnt/ cvs seems to bomb out when
                        //  it sends to the server
                        this.files = arguments[i++];
                    }
                    else
                    {
                        this.files = String.Empty;
                    }
                    RemoveCommandParser removeCommand =
                        new RemoveCommandParser(this.CvsRoot, files, options);
                    command = removeCommand.CreateCommand();
                    this.currentWorkingDirectory =
                        removeCommand.CurrentWorkingDirectory;
                    break;

                case "rt":
                case "rtag":
                case "rtfreeze":
                    singleOptions   = "abBdfFlMnR";
                    this.commandTxt = arguments[i++];
                    // get rest of arguments which is options on the rtag command.
                    while (arguments.Length > i && arguments[i].IndexOf("-", 0, 1) >= 0)
                    {
                        // Get options with second parameters?
                        if (arguments[i].IndexOfAny(singleOptions.ToCharArray(), 1, 1) >= 0)
                        {
                            for (int cnt = 1; cnt < arguments[i].Length; cnt++)
                            {
                                this.options = this.options + "-" + arguments[i][cnt] + " ";     // No
                            }
                        }
                        else
                        {
                            this.options = this.options + arguments[i];           // Yes
                            this.options = this.options + arguments[i] + " ";
                        }
                        i++;
                    }
                    if (arguments.Length > i)
                    {
                        // Safely grab the module, if not specified then
                        //  pass null into the repository...the cvs command
                        //  line for cvsnt/ cvs seems to bomb out when
                        //  it sends to the server
                        this.repository = arguments[i++];
                    }
                    else
                    {
                        this.repository = String.Empty;
                    }
                    RTagCommandParser rtagCommand =
                        new RTagCommandParser(this.CvsRoot, repository, options);
                    command = rtagCommand.CreateCommand();
                    this.currentWorkingDirectory =
                        rtagCommand.CurrentWorkingDirectory;
                    break;

                case "st":
                case "stat":
                case "status":
                    string[] commandArgs = new string[arguments.Length - i];
                    Array.Copy(arguments, i, commandArgs, 0, arguments.Length - i);
                    factory =
                        new CommandParserFactory("status", commandArgs,
                                                 this.cvsRoot, this.currentWorkingDirectory);

                    parser  = factory.GetCommandParser();
                    i       = arguments.Length;
                    command = parser.CreateCommand();
                    this.currentWorkingDirectory =
                        parser.CurrentWorkingDirectory;
                    break;

                case "up":
                case "upd":
                case "update":
                    singleOptions   = "ACPRbdfmp";
                    this.commandTxt = arguments[i++];
                    // get rest of arguments which is options on the update command.
                    while (arguments.Length > i && arguments[i].IndexOf("-", 0, 1) >= 0)
                    {
                        // Get options with second parameters?
                        if (arguments[i].IndexOfAny(singleOptions.ToCharArray(), 1, 1) >= 0)
                        {
                            for (int cnt = 1; cnt < arguments[i].Length; cnt++)
                            {
                                this.options = this.options + "-" + arguments[i][cnt] + " ";     // No
                            }
                        }
                        else
                        {
                            this.options = this.options + arguments[i];           // Yes
                            this.options = this.options + arguments[i] + " ";
                        }
                        i++;
                    }
                    if (arguments.Length > i)
                    {
                        // Safely grab the module, if not specified then
                        //  pass null into the repository...the cvs command
                        //  line for cvsnt/ cvs seems to bomb out when
                        //  it sends to the server
                        this.repository = arguments[i++];
                    }
                    else
                    {
                        this.repository = String.Empty;
                    }
                    UpdateCommandParser updateCommand =
                        new UpdateCommandParser(this.CvsRoot, repository, options);
                    command = updateCommand.CreateCommand();
                    this.currentWorkingDirectory =
                        updateCommand.CurrentWorkingDirectory;
                    break;

                case "xml":
                    factory =
                        new CommandParserFactory("xml", arguments,
                                                 this.cvsRoot, this.currentWorkingDirectory);

                    // TODO: Move this outside of case statement when all commands use same pattern
                    parser  = factory.GetCommandParser();
                    i       = arguments.Length;
                    command = parser.CreateCommand();
                    this.currentWorkingDirectory =
                        parser.CurrentWorkingDirectory;

                    break;

                default:
                    StringBuilder msg = new StringBuilder();
                    msg.Append("Unknown command entered.  ");
                    msg.Append("command=[").Append(arguments[i]).Append("]");
                    throw new CommandLineParseException(msg.ToString());
                }
            }
            return(command);
        }
Exemplo n.º 28
0
 public ListCommandParser(CvsRoot cvsRoot, string repositoryName, string coOptions)
 {
     this.CvsRoot         = cvsRoot;
     repository           = repositoryName;
     this.unparsedOptions = coOptions;
 }
Exemplo n.º 29
0
        public void AddFilesTest()
        {
            this.CheckoutTestModule();

            String modulePath = Path.Combine(this.GetTempPath(),
                                             this.Settings.Config.Module);

            String[] files = Directory.GetFiles(modulePath, "*.txt");

            Assert.IsTrue(files.Length > 0);
            ArrayList copiedFiles = new ArrayList();

            foreach (String file in files)
            {
                LOGGER.Debug("file=[" + file + "]");
                // Remove the .txt when everything works, giving me bugs...
                String newFileName = Guid.NewGuid().ToString() + ".txt";
                String fullPath    = Path.Combine(modulePath, newFileName);
                File.Copy(file, fullPath);
                copiedFiles.Add(fullPath);
            }

            CvsRoot          root    = new CvsRoot(this.Settings.Config.Cvsroot);
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     this.Settings.Config.LocalPath,
                                     this.Settings.Config.Module);

            CVSServerConnection connection = new CVSServerConnection();

            Assert.IsNotNull(connection);

            AddCommand command = new AddCommand(working);

            //command.Folders = this.GetFolders(modulePath);
            command.Folders = this.GetFoldersToAdd(copiedFiles);

            Assert.IsTrue(command.Folders.Count > 0);
            LOGGER.Debug("folders count=[" + command.Folders.Count + "]");
            foreach (DictionaryEntry folderDic in command.Folders)
            {
                Folder folder = (Folder)folderDic.Value;
                LOGGER.Debug("folder=[" + folder.ToString() + "]");
                LOGGER.Debug("entries count=[" + folder.Entries.Count + "]");
            }
            Assert.IsNotNull(command);

            try {
                connection.Connect(working, this.Settings.Config.ValidPassword);
            } catch (AuthenticationException) {
                // should not get here.
                Assert.IsTrue(true);
            }

            command.Execute(connection);
            connection.Close();

            try {
                connection.Connect(working, this.Settings.Config.ValidPassword);
            } catch (AuthenticationException) {
                Assert.IsTrue(true);
            }
            CommitCommand2 commitCommand = new CommitCommand2(working);

            working.Folders          = command.Folders;
            commitCommand.LogMessage = "AddCommandTest";
            commitCommand.Execute(connection);
            connection.Close();

            Manager manager = new Manager(working.WorkingPath);
            Entries entries = manager.FetchEntries(Path.Combine(modulePath, "Entries"));

            foreach (String addedFile in copiedFiles)
            {
                Assert.IsTrue(entries.Contains(Path.Combine(modulePath, addedFile)));
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// RTags in the cvs repository
 /// </summary>
 /// <param name="cvsroot">User Information</param>
 /// <param name="repository">Repository that contains the files to be tagged</param>
 /// <param name="rtOptions">Options</param>
 public RTagCommandParser(CvsRoot cvsroot, string repository, string rtOptions)
 {
     this.cvsRoot         = cvsroot;
     this.repository      = repository;
     this.unparsedOptions = rtOptions;
 }