Beispiel #1
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..");
        }
        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();
        }
Beispiel #3
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();
        }