public static string Join <_T0>(Iterable <_T0> strings, string delimiter)
            where _T0 : CharSequence
        {
            int capacity    = 0;
            int delimLength = delimiter.Length;
            Iterator <CharSequence> iter = strings.Iterator <CharSequence>();

            if (iter.HasNext())
            {
                capacity += iter.Next().Length + delimLength;
            }
            StringBuilder buffer = new StringBuilder(capacity);

            iter = strings.Iterator <CharSequence>();
            if (iter.HasNext())
            {
                buffer.Append(iter.Next());
                while (iter.HasNext())
                {
                    buffer.Append(delimiter);
                    buffer.Append(iter.Next());
                }
            }
            return(buffer.ToString());
        }
示例#2
0
        public static string Join <_T0>(Iterable <_T0> strings, [NotNull] string delimiter)
            where _T0 : CharSequence
        {
            int            capacity    = 0;
            int            delimLength = delimiter.Length;
            Iterator <_T0> iter        = strings.Iterator();

            if (iter.HasNext())
            {
                capacity += iter.Next().Length + delimLength;
            }
            StringBuilder buffer = new StringBuilder(capacity);

            iter = strings.Iterator();
            if (iter.HasNext())
            {
                buffer.Append(iter.Next());
                while (iter.HasNext())
                {
                    buffer.Append(delimiter);
                    buffer.Append(iter.Next());
                }
            }
            return(Sharpen.Extensions.ConvertToString(buffer));
        }
示例#3
0
        /// <summary>Asynchronous object size lookup.</summary>
        /// <remarks>Asynchronous object size lookup.</remarks>
        /// <?></?>
        /// <param name="objectIds">
        /// objects to get the size of from the object store. The supplied
        /// collection must not be modified until the queue has finished.
        /// </param>
        /// <param name="reportMissing">
        /// if true missing objects are reported by calling failure with a
        /// MissingObjectException. This may be more expensive for the
        /// implementation to guarantee. If false the implementation may
        /// choose to report MissingObjectException, or silently skip over
        /// the object with no warning.
        /// </param>
        /// <returns>queue to read object sizes from.</returns>
        public virtual AsyncObjectSizeQueue <T> GetObjectSize <T>(Iterable <T> objectIds, bool
                                                                  reportMissing) where T : ObjectId
        {
            Iterator <T> idItr = objectIds.Iterator();

            return(new _AsyncObjectSizeQueue_354 <T>(this, idItr));
        }
示例#4
0
        /// <summary>Asynchronous object opening.</summary>
        /// <remarks>Asynchronous object opening.</remarks>
        /// <?></?>
        /// <param name="objectIds">
        /// objects to open from the object store. The supplied collection
        /// must not be modified until the queue has finished.
        /// </param>
        /// <param name="reportMissing">
        /// if true missing objects are reported by calling failure with a
        /// MissingObjectException. This may be more expensive for the
        /// implementation to guarantee. If false the implementation may
        /// choose to report MissingObjectException, or silently skip over
        /// the object with no warning.
        /// </param>
        /// <returns>queue to read the objects from.</returns>
        public virtual AsyncObjectLoaderQueue <T> Open <T>(Iterable <T> objectIds, bool reportMissing
                                                           ) where T : ObjectId
        {
            Iterator <T> idItr = objectIds.Iterator();

            return(new _AsyncObjectLoaderQueue_272 <T>(this, idItr));
        }
示例#5
0
 public static void ForEach(Iterable <V> @this, java.util.function.Consumer consumer)
 {
     java.util.Iterator <V> i = @this.Iterator();
     while (i.HasNext())
     {
         consumer.Accept(i.Next());
     }
 }
示例#6
0
        private static void BuildStopWordIndex(Iterable <RevCommit> log, Repository repository, Git git)
        {
            Console.WriteLine("Index build start -" + System.DateTime.Now);
            DateTime startTime = DateTime.Now;

            for (Iterator <RevCommit> iterator = log.Iterator(); iterator.HasNext();)
            {
                RevCommit rev = iterator.Next();
                var       dt  = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(rev.CommitTime).ToLocalTime();

                DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
                df.SetRepository(repository);
                df.SetDiffComparator(RawTextComparator.DEFAULT);
                df.SetDetectRenames(true);

                List <String> files = new List <string>();
                if (rev.ParentCount > 0)
                {
                    List <DiffEntry> diffs = df.Scan(rev.GetParent(0).Tree, rev.Tree).ToList();
                    foreach (DiffEntry diff in diffs)
                    {
                        string filename = diff.GetNewPath();
                        if (Utils.AllowedFileExtentions(filename))
                        {
                            string data = GitHelper.GetCommitDiff(repository, git, rev, filename);
                            StopWords.StopWordIndexBuilder.BuildWordIndex(filename, data);
                        }
                    }
                }

                if (DateTime.Now.Subtract(startTime).TotalMinutes > 60)
                {
                    break;
                }
            }

            Console.WriteLine("Index build end -" + System.DateTime.Now);

            StopWords.StopWordIndexBuilder.BuildStopWordsIndex();
            StopWords.StopWordIndexBuilder.WriteToFile();

            Console.WriteLine("Stop word keyword index build completed..");
        }
示例#7
0
        public virtual void TestTrackingUpdate()
        {
            Repository db2             = CreateBareRepository();
            string     remote          = "origin";
            string     branch          = "refs/heads/master";
            string     trackingBranch  = "refs/remotes/" + remote + "/master";
            Git        git             = new Git(db);
            RevCommit  commit1         = git.Commit().SetMessage("Initial commit").Call();
            RefUpdate  branchRefUpdate = db.UpdateRef(branch);

            branchRefUpdate.SetNewObjectId(commit1.Id);
            branchRefUpdate.Update();
            RefUpdate trackingBranchRefUpdate = db.UpdateRef(trackingBranch);

            trackingBranchRefUpdate.SetNewObjectId(commit1.Id);
            trackingBranchRefUpdate.Update();
            StoredConfig config       = ((FileBasedConfig)db.GetConfig());
            RemoteConfig remoteConfig = new RemoteConfig(config, remote);
            URIish       uri          = new URIish(db2.Directory.ToURI().ToURL());

            remoteConfig.AddURI(uri);
            remoteConfig.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + remote +
                                                     "/*"));
            remoteConfig.Update(config);
            config.Save();
            RevCommit             commit2        = git.Commit().SetMessage("Commit to push").Call();
            RefSpec               spec           = new RefSpec(branch + ":" + branch);
            Iterable <PushResult> resultIterable = git.Push().SetRemote(remote).SetRefSpecs(spec
                                                                                            ).Call();
            PushResult        result            = resultIterable.Iterator().Next();
            TrackingRefUpdate trackingRefUpdate = result.GetTrackingRefUpdate(trackingBranch);

            NUnit.Framework.Assert.IsNotNull(trackingRefUpdate);
            NUnit.Framework.Assert.AreEqual(trackingBranch, trackingRefUpdate.GetLocalName());
            NUnit.Framework.Assert.AreEqual(branch, trackingRefUpdate.GetRemoteName());
            NUnit.Framework.Assert.AreEqual(commit2.Id, trackingRefUpdate.GetNewObjectId());
            NUnit.Framework.Assert.AreEqual(commit2.Id, db.Resolve(trackingBranch));
            NUnit.Framework.Assert.AreEqual(commit2.Id, db2.Resolve(branch));
        }
示例#8
0
        static void Main(string[] args)
        {
            Iterable <RevCommit> gitLogs = GetRevCommitList();

            int count = 0;

            DateTime startTime = System.DateTime.Now;

            Dictionary <string, string> gitLogDictionary = new Dictionary <string, string>();


            Dictionary <string, Dictionary <string, string> > groupedChangeSets = new Dictionary <string, Dictionary <string, string> >();

            HashSet <string> commitIDs = new HashSet <string>();



            for (Iterator <RevCommit> iterator = gitLogs.Iterator(); iterator.HasNext();)
            {
                RevCommit rev = iterator.Next();

                //System.Console.WriteLine(rev.Id.FirstByte);
                //System.Console.WriteLine(rev.GetFullMessage());
                // TermFrequency.Add(rev.Id.Name, rev.GetFullMessage());

                gitLogDictionary.Add(rev.Id.Name, TermFrequency.CleanInput(rev.GetFullMessage()));
                //System.Console.ReadLine();

                count++;
            }


            int loopCount = 0;
            Iterable <RevCommit> gitLogs1 = GetRevCommitList();

            //for (Iterator<RevCommit> iterator2 = gitLogs1.Iterator(); iterator2.HasNext(); )
            foreach (var itemParent in gitLogDictionary)
            {
                //RevCommit rev = iterator2.Next();

                bool first = true;
                if (!itemParent.Value.ToLower().Contains("merge branch") && !commitIDs.Contains(itemParent.Key))
                {
                    foreach (var item in gitLogDictionary)
                    {
                        if (!item.Value.ToLower().Contains("merge branch"))
                        {
                            if (item.Key != itemParent.Key && TermFrequency.GetSimilarityValue(itemParent.Value, item.Value) > 0.8)
                            {
                                if (first)
                                {
                                    groupedChangeSets.Add(itemParent.Key, new Dictionary <string, string>()
                                    {
                                        { itemParent.Key, itemParent.Value }
                                    });
                                    commitIDs.Add(itemParent.Key);
                                    first = false;
                                }

                                groupedChangeSets[itemParent.Key].Add(item.Key, item.Value);
                                commitIDs.Add(item.Key);

                                string Test1 = "1";
                            }
                        }
                    }
                }

                loopCount++;
                System.Console.Clear();
                System.Console.WriteLine(loopCount);
            }

            TimeSpan TotalTime = (System.DateTime.Now - startTime);


            foreach (var item in groupedChangeSets)
            {
                foreach (var item1 in item.Value)
                {
                    //System.Console.WriteLine(item.Key + ";" + item1.Key + ";" + item1.Value);
                    WriteData(item.Key, item1.Key, item1.Value);
                }
            }

            System.Console.WriteLine(TotalTime);
            // System.Console.ReadLine();
            //TermFrequency.Print();
        }
示例#9
0
        static void Main(string[] args)
        {
            FileRepositoryBuilder builder    = new FileRepositoryBuilder();
            Repository            repository = builder.SetGitDir(new FilePath(@"D:\Personal\E Books\Higher Education\Research\SampleProjects\NopCommerce\.git"))
                                                                  //Repository repository = builder.SetGitDir(new FilePath(@"C:\Users\neemathu\Documents\GitHub\angular.js\.git"))
                                                                  // Repository repository = builder.SetGitDir(new FilePath(@"D:\Personal\E Books\Higher Education\RefactoringActivity\ganttproject\.git"))
                                               .ReadEnvironment() // scan environment GIT_* variables
                                               .FindGitDir()      // scan up the file system tree
                                               .Build();



            HashSet <String>         uniqueFile      = new HashSet <string>();
            Dictionary <String, int> logicalCoupling = new Dictionary <string, int>();

            RevWalk rw = new RevWalk(repository);


            Git git = new Git(repository);

            Iterable <RevCommit> log = git.Log().Call();

            for (Iterator <RevCommit> iterator = log.Iterator(); iterator.HasNext();)
            {
                RevCommit rev = iterator.Next();


                //RevWalk revWalk = new RevWalk(git.GetRepository());
                //RevTree revTree = revWalk.ParseTree(rev.Tree.Id);
                //TreeWalk treeWalk = new TreeWalk(git.GetRepository());
                //treeWalk.AddTree(revTree);

                //while (treeWalk.Next())
                //{
                //    //compare treeWalk.NameString yourself


                //    byte[] bytes = treeWalk.ObjectReader.Open(treeWalk.GetObjectId(0)).GetBytes();
                //    string result1 = System.Text.Encoding.UTF8.GetString(bytes);


                //}



                // Sharpen.OutputStream os = new Sharpen.OutputStream();

                //rev.CopyRawTo(os);

                //System.Console.WriteLine("Author: "+rev.GetAuthorIdent().GetName());
                //System.Console.WriteLine("ID:" + rev.Id);


                var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(rev.CommitTime).ToLocalTime();
                //var ts = new TimeSpan(DateTime.UtcNow.Ticks - rev.CommitTime);
                //System.Console.WriteLine("Date:" + dt.ToString());
                //System.Console.WriteLine("Description:" + rev.GetFullMessage());

                DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
                df.SetRepository(repository);
                df.SetDiffComparator(RawTextComparator.DEFAULT);
                df.SetDetectRenames(true);

                List <String> files = new List <string>();

                if (rev.ParentCount > 0)
                {
                    List <DiffEntry> diffs = df.Scan(rev.GetParent(0).Tree, rev.Tree).ToList();


                    foreach (DiffEntry diff in diffs)
                    {
                        // Fetch data from the commited new file
                        //ObjectLoader loader = repository.Open(diff.GetNewId().ToObjectId());
                        //OutputStream @out = new ByteArrayOutputStream();
                        ////loader.CopyTo(@out);

                        ////Fetch diffrence of commit
                        //DiffCommand diff1 = git.Diff().SetPathFilter(PathFilter.Create(diff.GetNewPath())).SetOldTree(GetTreeIterator(rev.GetParent(0).Tree.Name, repository)).SetNewTree(GetTreeIterator(rev.Tree.Name, repository)).SetOutputStream(@out);
                        //IList<DiffEntry>  entries = diff1.Call();
                        //string data = @out.ToString();

                        files.Add(diff.GetNewPath());
                        uniqueFile.Add(diff.GetNewPath());
                        //System.Console.WriteLine(String.Format("FilePath: {0} {1}", diff.GetNewMode().GetBits(), diff.GetNewPath()));
                    }
                }



                if (isContainFile(rev, files))
                {
                    //System.Console.WriteLine(rev.Id);
                    //System.Console.WriteLine(dt);
                    //System.Console.WriteLine(rev.GetAuthorIdent().GetName());
                    //System.Console.WriteLine(rev.GetFullMessage());

                    tfIdfBeforeData.Add(rev.Id.Name, new Dictionary <string, Dictionary <string, double> >());


                    foreach (String file in files)
                    {
                        String fileName = file.Substring(file.LastIndexOf("/") + 1, file.Length - file.LastIndexOf("/") - 1);

                        if (IsFileExtentionAllowed(fileName))
                        {
                            string data = GetCommitDiff(repository, git, rev, file);
                            Dictionary <string, double> tokensTF = GetTokensWithTF(data);

                            tfIdfBeforeData[rev.Id.Name].Add(file, tokensTF);


                            //System.Console.WriteLine("File path: " + file);
                            //System.Console.WriteLine(data);
                            //System.Console.WriteLine("------------------");

                            if (!logicalCoupling.ContainsKey(fileName))
                            {
                                logicalCoupling.Add(fileName, 1);
                            }
                            else
                            {
                                logicalCoupling[fileName] += 1;
                            }
                        }
                    }

                    //System.Console.WriteLine("###################################");
                }


                //foreach (var item in uniqueFile)
                //{

                //    System.Console.WriteLine(item);
                //}

                //System.Console.WriteLine("--------------------");


                //http://stackoverflow.com/questions/11869412/jgit-using-revwalk-to-get-revcommit-returns-nothing

                ////ObjectId head = repository.Resolve("master");
                //RevWalk walk = new RevWalk(repository);

                //foreach (var commit in walk)
                //{
                //    String email = commit.GetAuthorIdent().GetEmailAddress();
                //}
            }

            CalculateTfIdfScore("defaultResources.nopres.xml");

            CalculateLogicalDependency(logicalCoupling);

            System.Console.WriteLine("----------Done----------");
            System.Console.ReadLine();
        }
示例#10
0
        static void Main(string[] args)
        {
            //string input = "group, and test but not testing.  But yes to test";
            //string val="Group";
            //string pattern = @"\b" + val + @"\b";
            //string replace = " ";
            //string result = System.Text.RegularExpressions.Regex.Replace(input, pattern, replace, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            //Console.WriteLine(result);

            FileRepositoryBuilder builder    = new FileRepositoryBuilder();
            Repository            repository = builder.SetGitDir(new FilePath(@"D:\Personal\E Books\Higher Education\Research\SampleProjects\NopCommerce\.git"))
                                                                  //Repository repository = builder.SetGitDir(new FilePath(@"C:\Users\neemathu\Documents\GitHub\angular.js\.git"))
                                                                  // Repository repository = builder.SetGitDir(new FilePath(@"D:\Personal\E Books\Higher Education\RefactoringActivity\ganttproject\.git"))
                                               .ReadEnvironment() // scan environment GIT_* variables
                                               .FindGitDir()      // scan up the file system tree
                                               .Build();

            RevWalk rw = new RevWalk(repository);

            Git git = new Git(repository);

            Iterable <RevCommit> log = git.Log().Call();


            if (args.Length > 0)
            {
                switch (args[0])
                {
                case "buildstopwordindex":
                    BuildStopWordIndex(log, repository, git);
                    return;

                    break;

                default:
                    break;
                }
            }


            // Iterat over revisions
            for (Iterator <RevCommit> iterator = log.Iterator(); iterator.HasNext();)
            {
                RevCommit rev = iterator.Next();

                var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(rev.CommitTime).ToLocalTime();

                DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
                df.SetRepository(repository);
                df.SetDiffComparator(RawTextComparator.DEFAULT);
                df.SetDetectRenames(true);

                List <String> files = new List <string>();
                if (rev.ParentCount > 0)
                {
                    List <DiffEntry> diffs = df.Scan(rev.GetParent(0).Tree, rev.Tree).ToList();
                    foreach (DiffEntry diff in diffs)
                    {
                        // Fetch data from the commited new file
                        //ObjectLoader loader = repository.Open(diff.GetNewId().ToObjectId());
                        //OutputStream @out = new ByteArrayOutputStream();
                        ////loader.CopyTo(@out);

                        ////Fetch diffrence of commit
                        //DiffCommand diff1 = git.Diff().SetPathFilter(PathFilter.Create(diff.GetNewPath())).SetOldTree(GetTreeIterator(rev.GetParent(0).Tree.Name, repository)).SetNewTree(GetTreeIterator(rev.Tree.Name, repository)).SetOutputStream(@out);
                        //IList<DiffEntry>  entries = diff1.Call();
                        //string data = @out.ToString();

                        string filePath = diff.GetNewPath();

                        //if (fileCount.ContainsKey(filePath))
                        //{
                        //    fileCount[filePath] = fileCount[filePath] + 1;

                        //}
                        //else
                        //{
                        //    fileCount.Add(filePath, 1);

                        //}

                        files.Add(filePath);

                        //System.Console.WriteLine(String.Format("FilePath: {0} {1}", diff.GetNewMode().GetBits(), diff.GetNewPath()));
                    }
                    //continue;
                }

                if (GitHelper.HasFile(files))
                {
                    foreach (String file in files)
                    {
                        String FileName = file.Substring(file.LastIndexOf("/") + 1, file.Length - file.LastIndexOf("/") - 1);
                        if (Utils.AllowedFileExtentions(FileName))
                        {
                            string DiffContent = GitHelper.GetCommitDiff(repository, git, rev, file);
                            //data = Common.Utils.RemoveStopWords(data);

                            LogicalDependency.LogicalDependency.AddArtifact(rev.Id.Name, file, DiffContent);

                            //StopWords.StopWordIndexBuilder.BuildWordIndex(file, data);
                        }
                    }
                }
            }

            //var sortedElements = fileCount.OrderByDescending(kvp => kvp.Value);

            //foreach (var item in sortedElements)
            //{
            //    Console.WriteLine(item.Key + ": " + item.Value);
            //}

            LogicalDependency.LogicalDependency.CalculateSimilarityIndex();
        }