コード例 #1
0
        public static SourceCodeRepository CreateSourceCodeRepository(string path, string tempDir)
        {
            SourceCodeRepository sourceCodeRepository;

            if (string.IsNullOrWhiteSpace(path))
            {
                sourceCodeRepository = DummyCodeRepository.Instance;
            }
            else if (Directory.Exists(path))
            {
                sourceCodeRepository = new DirectoryCodeRepository(path);
            }
            else if (File.Exists(path))
            {
                string extensions = Path.GetExtension(path);
                if (extensions.EqualsIgnoreCase(".zip"))
                {
                    sourceCodeRepository = new ZipCachingRepository(path)
                    {
                        ExtractPath = tempDir
                    };
                }
                else
                {
                    sourceCodeRepository          = new FileCodeRepository(path);
                    sourceCodeRepository.LoadJson = extensions.EqualsIgnoreCase(".json");
                }
            }
            else
            {
                string url            = path;
                string projectName    = null;
                string urlWithoutHttp = TextUtils.HttpRegex.Replace(url, "");

                if (!url.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
                {
                    if (urlWithoutHttp.StartsWith("github.com", StringComparison.OrdinalIgnoreCase))
                    {
                        url = url + "/archive/master.zip";
                    }
                }

                if (urlWithoutHttp.StartsWith("github.com", StringComparison.OrdinalIgnoreCase))
                {
                    projectName = urlWithoutHttp.Split('/').ElementAtOrDefault(2);
                }

                var zipAtUrlCachedCodeRepository = new ZipAtUrlCachingRepository(url, projectName)
                {
                    DownloadPath = tempDir
                };
                sourceCodeRepository = zipAtUrlCachedCodeRepository;
            }

            return(sourceCodeRepository);
        }
コード例 #2
0
        public void AggregateFiles_TestProject_CorrectCountAndRelativePaths()
        {
            string rootPath   = Path.Combine(TestUtility.TestsDataPath, "Test Project");
            var    repository = new DirectoryCodeRepository(rootPath, CSharp.Language);
            var    fileNames  = repository.GetFileNames().Select(fileName => repository.ReadFile(fileName)).ToArray();

            Assert.AreEqual(7, fileNames.Length);

            Assert.IsNotNull(fileNames.SingleOrDefault(f =>
                                                       f.Name == "1.cs" && f.RelativePath == "" && f.FullName == Path.Combine(rootPath, "1.cs")));
            Assert.IsNotNull(fileNames.SingleOrDefault(f =>
                                                       f.Name == "1.cs" && f.RelativePath == "Folder" && f.FullName == Path.Combine(rootPath, "Folder", "1.cs")));
        }
コード例 #3
0
        public void Check_AspxFileWithCSharpLanguage_NotIgnored()
        {
            var repository = new DirectoryCodeRepository("", CSharp.Language);

            Assert.IsFalse(repository.IsFileIgnored("page.aspx", true));
        }