Ejemplo n.º 1
0
        /// <summary> Adds the file or directpry to the repository.</summary>
        /// <param name="parentFolder">StarTeam folder underwhich items will be added.</param>
        /// <param name="file">the file or directory to add</param>
        /// <returns>true if the file was successfully added otherwise false.</returns>
        private bool add(InterOpStarTeam.StFolder parentFolder, FileInfo file)
        {
            // If the current file is a Directory, we need to process all of its children as well.
            if (Directory.Exists(file.FullName))
            {
                if (!_createFolders)
                {
                    Log(Level.Info, "Could not add new folder as createfolders is disabled: {0}",
                        file.FullName);
                    return(false);
                }

                Log(Level.Info, "Adding new folder to repository: {0}", file.FullName);
                InterOpStarTeam.StFolder newFolder = starteamFolderFactory.Create(parentFolder);
                newFolder.Name = file.Name;
                newFolder.update();

                // now visit this new folder to take care of adding any files or subfolders within it.
                if (this.recursive)
                {
                    visit(newFolder, file);
                }
            }
            else
            {
                Log(Level.Info, "Adding new file to repository: {0}", file.FullName);
                InterOpStarTeam.StFile newFile = starteamFileFactory.Create(parentFolder);
                newFile.Add(file.FullName, file.Name, null, _comment, starTeamLockTypeStatics.UNLOCKED, true, true);

                _updateLabel(newFile);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Locate the <c>versionnumber.xml</c> file in the repository. If it
        /// is not present, the file is created. The file is checked out
        /// exclusively for editing.
        /// </summary>
        /// <param name="snapshot">StarTeam view we are working with.</param>
        /// <returns>
        /// StarTeam file handle containing version xml.
        /// </returns>
        private InterOpStarTeam.StFile getVersionStFile(InterOpStarTeam.StView snapshot)
        {
            InterOpStarTeam.StFile stVersionFile = null;
            //connect to starteam and get root folder
            InterOpStarTeam.StFolder starTeamRootFolder = snapshot.RootFolder;

            //get contents of root folder and look for version file
            //this is weird as I cannot see how to ask StarTeam for an individual file
            foreach (InterOpStarTeam.StFile stFile in starTeamRootFolder.getItems("File"))
            {
                if (stFile.Name == _versionFile)
                {
                    stVersionFile = stFile;
                    break;
                }
            }

            if (stVersionFile == null)
            {
                stVersionFile = createVersionStFile(starTeamRootFolder);
            }
            else
            {
                stVersionFile.checkout(starTeamLockTypeStatics.EXCLUSIVE, true,
                                       true, true);
            }
            return(stVersionFile);
        }
Ejemplo n.º 3
0
 private void _updateLabel(InterOpStarTeam.StFile stFile)
 {
     //if user defined a label attach the item checked to that label
     if (_stLabel != null)
     {
         _stLabel.moveLabelToItem((InterOpStarTeam.StItem)stFile);
         _stLabel.update();
     }
 }
Ejemplo n.º 4
0
 protected internal virtual void list(InterOpStarTeam.StFile reposFile, FileInfo localFile)
 {
     System.Text.StringBuilder b = new System.Text.StringBuilder();
     if (null == _rootLocalFolder)
     {
         InterOpStarTeam.StStatusStaticsClass starTeamStatus = new InterOpStarTeam.StStatusStaticsClass();
         // status is irrelevant to us if we have specified a
         // root local folder.
         b.Append(pad(starTeamStatus.Name(reposFile.Status), 12) + " ");
     }
     b.Append(pad(getUserName(reposFile.Locker), 20) + " " + reposFile.ModifiedTime.ToShortDateString() + rpad(reposFile.LocalSize.ToString(), 9) + " " + reposFile.Name);
     Log(Level.Info, b.ToString());
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the versionumber.xml file in the repository.
        /// </summary>
        /// <param name="stFolder">StarTeam folder desired to put the versionnumber.xml files into</param>
        /// <returns>StarTeam File handle to the created file.</returns>
        private InterOpStarTeam.StFile createVersionStFile(InterOpStarTeam.StFolder stFolder)
        {
            // instantiated here as they are only necessary when adding
            InterOpStarTeam.StFileFactoryClass starteamFileFactory = new InterOpStarTeam.StFileFactoryClass();
            string versionFilePath = stFolder.getFilePath(_versionFile);

            // create xml and save to local file
            try {
                StreamWriter  s         = new StreamWriter(versionFilePath, false, System.Text.ASCIIEncoding.ASCII);
                XmlTextWriter xmlWriter = new XmlTextWriter(s);
                xmlWriter.WriteStartDocument(false);
                xmlWriter.WriteStartElement("stautolabel");
                xmlWriter.WriteStartElement("version");
                xmlWriter.WriteAttributeString("major", "1");
                xmlWriter.WriteAttributeString("minor", "0");
                xmlWriter.WriteAttributeString("build", "0");
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
                xmlWriter.Close();
            } catch (System.Security.SecurityException ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "You do not have access to '{0}'.", versionFilePath), Location, ex);
            } catch (IOException ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Version filepath '{0}' is invalid.", versionFilePath), Location, ex);
            }

            //add local file to starteam
            InterOpStarTeam.StFile newFile = starteamFileFactory.Create(stFolder);
            string comment = "version number xml created by stautonumber NAnt task";

            newFile.Add(versionFilePath, _versionFile, comment, comment,
                        starTeamLockTypeStatics.UNLOCKED, true, true);

            return(newFile);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Looks for versionnumber.xml at root of repository.
        /// Updates the xml in this file to correspond with properties set by user and checks in changes.
        /// A label is then created based on properties set.
        /// </summary>
        /// <remarks>
        /// Default behavior is to <see cref="IncrementBuild"/> number.
        /// If user sets <see cref="MajorVersion"/>, <see cref="MinorVersion"/>, or <see cref="BuildVersion"/> no incrementing is done
        /// and the exact version set and/or read from versionnumber.xml is used.
        /// <para>The title of the Label is the <see cref="LabelTask.Label"/> property concatenated with the version number Major.Minor.Build</para>
        /// </remarks>
        protected override void  ExecuteTask()
        {
            InterOpStarTeam.StView snapshot = openView();
            InterOpStarTeam.StFile stFile   = getVersionStFile(snapshot);

            try {
                //load xml document find versions and save incremented version
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(stFile.FullName);
                XmlNode nodeVersion = xmlDoc.DocumentElement.SelectSingleNode("version");
                if (_versionMajor < 0)
                {
                    _versionMajor = Convert.ToInt32(nodeVersion.Attributes.GetNamedItem("major").InnerText);
                }
                if (_versionMinor < 0)
                {
                    _versionMinor = Convert.ToInt32(nodeVersion.Attributes.GetNamedItem("minor").InnerText);
                }
                if (_versionBuild < 0)
                {
                    _versionBuild = Convert.ToInt32(nodeVersion.Attributes.GetNamedItem("build").InnerText);
                }

                if (_doIncrement == true)
                {
                    if (_incrementMajor == true)
                    {
                        _versionMajor++;
                    }
                    if (_incrementMinor == true)
                    {
                        _versionMinor++;
                    }
                    if (_incrementBuild == true)
                    {
                        _versionBuild++;
                    }
                }
                nodeVersion.Attributes.GetNamedItem("major").InnerText =
                    _versionMajor.ToString(CultureInfo.InvariantCulture);
                nodeVersion.Attributes.GetNamedItem("minor").InnerText =
                    _versionMinor.ToString(CultureInfo.InvariantCulture);
                nodeVersion.Attributes.GetNamedItem("build").InnerText =
                    _versionBuild.ToString(CultureInfo.InvariantCulture);
                xmlDoc.Save(stFile.FullName);
            } catch (XmlException ex) {
                throw new BuildException("Error parsing / updating version xml",
                                         Location, ex);
            }

            stFile.checkin("version updated via stautolabel", starTeamLockTypeStatics.UNLOCKED,
                           true, true, true);
            this.Label = string.Format(CultureInfo.InvariantCulture,
                                       "{0}{1}.{2}.{3}", this.Label, _versionMajor, _versionMinor,
                                       _versionBuild);
            this.Properties["label"]        = this.Label;
            this.Properties["Version.text"] = _versionMajor.ToString(CultureInfo.InvariantCulture) + "."
                                              + _versionMinor.ToString(CultureInfo.InvariantCulture) + "."
                                              + _versionBuild.ToString(CultureInfo.InvariantCulture);
            this.Properties["Version.major"] = _versionMajor.ToString(CultureInfo.InvariantCulture);
            this.Properties["Version.minor"] = _versionMinor.ToString(CultureInfo.InvariantCulture);
            this.Properties["Version.build"] = _versionBuild.ToString(CultureInfo.InvariantCulture);

            createLabel(snapshot);
        }