Beispiel #1
0
        /// <summary>
        /// Updates the project.json file with the specified version.
        /// </summary>
        /// <param name="version">The version to inject.</param>
        /// <returns>True if the file has actually been modified. False if they are the same or the project file can not be updated.</returns>
        public bool UpdateProjectJSONFile(string version)
        {
            string text = File.ReadAllText(_projectFile);

            if (_frameworks == null)
            {
                _frameworks = JSONFrameworksFinder.GetFrameworks(text);
            }
            ProjectFileContent content = new ProjectFileContent(text, _ctx.ContainsProject);

            if (content.Version == null)
            {
                _ctx.Logger.Warn("Unable to update version in: " + _projectFile);
            }
            else if (content.Version == version)
            {
                _ctx.Logger.Trace("(File is up to date.)");
            }
            else
            {
                string modified = content.GetReplacedText(version);
                if (_projectFileCache == null)
                {
                    _projectFileCache = text;
                    string fLock = _projectDir + "project.lock.json";
                    if (File.Exists(fLock))
                    {
                        _projectLockFileCache = File.ReadAllText(fLock);
                    }
                }
                File.WriteAllText(_projectFile, modified);
                return(true);
            }
            return(false);
        }
Beispiel #2
0
 private SimpleRepositoryInfo GetRepositoryInfo(ILogger logger, Action <IWorkingFolderModifiedFile, ProjectFileContent> hook)
 {
     return(SimpleRepositoryInfo.LoadFromPath(logger, _solutionDir, (log, hasRepoXml, options) =>
     {
         options.IgnoreModifiedFileFullProcess = true;
         options.IgnoreModifiedFilePredicate = m =>
         {
             if (m.Path.EndsWith("project.json", StringComparison.Ordinal) &&
                 _projects.FirstOrDefault(p => PathComparer.Default.Equals(p.RelativeProjectFilePath, m.Path)) != null)
             {
                 var local = new ProjectFileContent(File.ReadAllText(m.FullPath), ContainsProject);
                 var committed = new ProjectFileContent(m.CommittedText, ContainsProject);
                 if (local.EqualsWithoutVersion(committed))
                 {
                     if (hook != null)
                     {
                         hook(m, committed);
                     }
                     return true;
                 }
             }
             return false;
         };
     }
                                              ));
 }
        /// <summary>
        /// Checks whether the two files are equal regardless of the "version: "" property.
        /// Line endings must be normalized (or be the same) for this to work correctly.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns><c>true</c> if files are the same or differ only by their version, <c>false</c> otherwise.</returns>
        public bool EqualsWithoutVersion(ProjectFileContent other)
        {
            // This ensures that ExtractVersion has been called.
            if ((Version != null) != (other.Version != null))
            {
                return(false);
            }
            if (_thisVersion == null)
            {
                return(_text == other._text);
            }
            if (_allVersions.Count != other._allVersions.Count)
            {
                return(false);
            }
            int last = 0, oLast = 0;

            for (int i = 0; i < _allVersions.Count; ++i)
            {
                VersionOccurrence o  = _allVersions[i];
                VersionOccurrence oo = other._allVersions[i];
                int lenBefore        = o.Start - last;
                if (lenBefore != (oo.Start - oLast) ||
                    string.Compare(_text, last, other._text, oLast, lenBefore, StringComparison.Ordinal) != 0)
                {
                    return(false);
                }
                last  = o.End;
                oLast = oo.End;
            }
            int lenAfter = _text.Length - last;

            if (lenAfter != (other._text.Length - oLast) ||
                string.Compare(_text, last, other._text, oLast, lenAfter, StringComparison.Ordinal) != 0)
            {
                return(false);
            }
            return(true);
        }
Beispiel #4
0
 private SimpleRepositoryInfo GetRepositoryInfo( ILogger logger, Action<IWorkingFolderModifiedFile,ProjectFileContent> hook )
 {
     return SimpleRepositoryInfo.LoadFromPath( logger, _solutionDir, ( log, hasRepoXml, options ) =>
     {
         options.IgnoreModifiedFileFullProcess = true;
         options.IgnoreModifiedFilePredicate = m =>
         {
             if( m.Path.EndsWith( "project.json", StringComparison.Ordinal )
                 && _projects.FirstOrDefault( p => PathComparer.Default.Equals( p.RelativeProjectFilePath, m.Path ) ) != null )
             {
                 var local = new ProjectFileContent( File.ReadAllText( m.FullPath ), ContainsProject );
                 var committed = new ProjectFileContent( m.CommittedText, ContainsProject );
                 if( local.EqualsWithoutVersion( committed ) )
                 {
                     if( hook != null ) hook( m, committed );
                     return true;
                 }
             }
             return false;
         };
     }
   );
 }
Beispiel #5
0
 /// <summary>
 /// Updates the project.json file with the specified version.
 /// </summary>
 /// <param name="version">The version to inject.</param>
 /// <returns>True if the file has actually been modified. False if they are the same or the project file can not be updated.</returns>
 public bool UpdateProjectJSONFile( string version )
 {
     string text = File.ReadAllText( _projectFile );
     if( _frameworks == null ) _frameworks = JSONFrameworksFinder.GetFrameworks( text );
     ProjectFileContent content = new ProjectFileContent( text, _ctx.ContainsProject );
     if( content.Version == null ) _ctx.Logger.Warn( "Unable to update version in: " + _projectFile );
     else if( content.Version == version )
     {
         _ctx.Logger.Trace( "(File is up to date.)" );
     }
     else
     {
         string modified = content.GetReplacedText( version );
         if( _projectFileCache == null )
         {
             _projectFileCache = text;
             string fLock = _projectDir + "project.lock.json";
             if( File.Exists( fLock ) ) _projectLockFileCache = File.ReadAllText( fLock );
         }
         File.WriteAllText( _projectFile, modified );
         return true;
     }
     return false;
 }
Beispiel #6
0
 /// <summary>
 /// Checks whether the two files are equal regardless of the "version: "" property.
 /// Line endings must be normalized (or be the same) for this to work correctly.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns><c>true</c> if files are the same or differ only by their version, <c>false</c> otherwise.</returns>
 public bool EqualsWithoutVersion( ProjectFileContent other )
 {
     // This ensures that ExtractVersion has been called.
     if( (Version != null) != (other.Version != null) ) return false;
     if( _thisVersion == null ) return _text == other._text;
     if( _allVersions.Count != other._allVersions.Count ) return false;
     int last = 0, oLast = 0;
     for( int i = 0; i < _allVersions.Count; ++i )
     {
         VersionOccurrence o = _allVersions[i];
         VersionOccurrence oo = other._allVersions[i];
         int lenBefore = o.Start - last;
         if( lenBefore != (oo.Start - oLast)
             || string.Compare( _text, last, other._text, oLast, lenBefore, StringComparison.Ordinal ) != 0 )
         {
             return false;
         }
         last = o.End;
         oLast = oo.End;
     }
     int lenAfter = _text.Length - last;
     if( lenAfter != (other._text.Length - oLast)
         || string.Compare( _text, last, other._text, oLast, lenAfter, StringComparison.Ordinal ) != 0 )
     {
         return false;
     }
     return true;
 }