public ProbeAndFindProjectFileProvider(
     ILogger <ProbeAndFindProjectFileProvider> logger,
     IOptions <DetectorOptions> options)
 {
     _logger  = logger;
     _options = options.Value;
 }
Example #2
0
        public void Detect_ReturnsResult_WhenCustomRequirementsFileExists()
        {
            // Arrange
            var options = new DetectorOptions
            {
                CustomRequirementsTxtPath = "foo/requirements.txt",
            };
            var detector  = CreatePythonPlatformDetector(options);
            var sourceDir = Directory.CreateDirectory(Path.Combine(_tempDirRoot, Guid.NewGuid().ToString("N")))
                            .FullName;
            var subDirStr = "foo";
            var subDir    = Directory.CreateDirectory(Path.Combine(sourceDir, subDirStr)).FullName;

            IOHelpers.CreateFile(subDir, "foo==1.1", "requirements.txt");
            var repo    = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance);
            var context = CreateContext(repo);

            // Act
            var result = detector.Detect(context);

            // Assert
            var pythonPlatformResult = Assert.IsType <PythonPlatformDetectorResult>(result);

            Assert.NotNull(pythonPlatformResult);
            Assert.Equal(PythonConstants.PlatformName, pythonPlatformResult.Platform);
            Assert.Equal(string.Empty, pythonPlatformResult.AppDirectory);
            Assert.True(pythonPlatformResult.HasRequirementsTxtFile);
            Assert.Null(pythonPlatformResult.PlatformVersion);
        }
Example #3
0
        public void GetRelativePathToProjectFile_ReturnsOnlyAzureFunctionsApp_WhenOryxAppType_IsSetTo_Functions()
        {
            // Arrange
            var sourceRepoDir = CreateSourceRepoDir();
            var srcDir        = CreateDir(sourceRepoDir, "src");
            var webApp1Dir    = CreateDir(srcDir, "WebApp1");

            File.WriteAllText(Path.Combine(webApp1Dir, "WebApp1.csproj"), WebSdkProjectFile);

            var azureFunctionsApp1Dir = CreateDir(srcDir, "AzureFunctionsApp1");

            File.WriteAllText(Path.Combine(
                                  azureFunctionsApp1Dir,
                                  "AzureFunctionsApp1.csproj"),
                              AzureFunctionsProjectFile);

            var expectedRelativePath = Path.Combine("src", "AzureFunctionsApp1", "AzureFunctionsApp1.csproj");

            var sourceRepo = CreateSourceRepo(sourceRepoDir);
            var context    = GetContext(sourceRepo);
            var options    = new DetectorOptions();

            options.AppType = Constants.FunctionApplications;
            var provider = GetProjectFileProvider(options);

            // Act
            var actual = provider.GetRelativePathToProjectFile(context);

            // Assert
            Assert.Equal(expectedRelativePath, actual);
        }
Example #4
0
        public void GetRelativePathToProjectFile_Throws_IfPathInProjectEnvVariableValue_DoesNotExist()
        {
            // Arrange
            var sourceRepoDir = CreateSourceRepoDir();
            var srcDir        = CreateDir(sourceRepoDir, "src");
            var webApp1Dir    = CreateDir(srcDir, "WebApp1");

            File.WriteAllText(Path.Combine(webApp1Dir, "WebApp1.csproj"), WebSdkProjectFile);
            var webApp2Dir = CreateDir(srcDir, "WebApp2");

            File.WriteAllText(Path.Combine(webApp2Dir, "WebApp2.csproj"), WebSdkProjectFile);
            var sourceRepo          = CreateSourceRepo(sourceRepoDir);
            var relativeProjectPath = Path.Combine("src", "WebApp2", "WebApp2-doesnotexist.csproj");
            var options             = new DetectorOptions();

            options.Project = relativeProjectPath;
            var context  = GetContext(sourceRepo);
            var provider = GetProjectFileProvider(options);

            // Act & Assert
            var exception = Assert.Throws <InvalidProjectFileException>(
                () => provider.GetRelativePathToProjectFile(context));

            Assert.Contains("Could not find the .NET Core project file.", exception.Message);
        }
Example #5
0
        public void Detect_ReturnsFrameworkInfos_RemovesAngularAndReact(string packageJson)
        {
            // Arrange
            var sourceRepo = new MemorySourceRepo();

            sourceRepo.AddFile(packageJson, NodeConstants.PackageJsonFileName);
            var context = CreateContext(sourceRepo);
            var options = new DetectorOptions
            {
                DisableFrameworkDetection = false,
            };
            var           detector = CreateNodePlatformDetector(options);
            List <string> expectedFrameworkNames = new List <string>()
            {
                "jQuery", "Gatsby", "VuePress"
            };
            List <string> expectedFrameworkVersions = new List <string>()
            {
                "3.5.1", "1.2.3", "4.5.6"
            };
            // Act
            var result = (NodePlatformDetectorResult)detector.Detect(context);

            // Assert
            Assert.NotNull(result);
            Assert.Equal("nodejs", result.Platform);
            Assert.Null(result.PlatformVersion);
            Assert.Equal(string.Empty, result.AppDirectory);
            Assert.Equal(expectedFrameworkNames, result.Frameworks.Select(x => x.Framework).ToList());
            Assert.Equal(expectedFrameworkVersions, result.Frameworks.Select(x => x.FrameworkVersion).ToList());
        }
Example #6
0
        public void GetRelativePathToProjectFile_DoesNotThrow_IfRepoHasMultipleWebApps_AndProjectEnvVariableIsSet(
            string projectFileExtension)
        {
            // Arrange
            var sourceRepoDir = CreateSourceRepoDir();
            var srcDir        = CreateDir(sourceRepoDir, "src");
            var webApp1Dir    = CreateDir(srcDir, "WebApp1");

            File.WriteAllText(Path.Combine(webApp1Dir, $"WebApp1.{projectFileExtension}"), webApp1Dir);
            var webApp2Dir  = CreateDir(srcDir, "WebApp2");
            var projectFile = Path.Combine(webApp2Dir, $"WebApp2.{projectFileExtension}");

            File.WriteAllText(projectFile, webApp1Dir);
            var sourceRepo          = CreateSourceRepo(sourceRepoDir);
            var relativeProjectPath = Path.Combine("src", "WebApp2", $"WebApp2.{projectFileExtension}");
            var options             = new DetectorOptions();

            options.Project = relativeProjectPath;
            var context  = GetContext(sourceRepo);
            var provider = GetProjectFileProvider(options);

            // Act
            var actualFile = provider.GetRelativePathToProjectFile(context);

            // Assert
            Assert.Equal(relativeProjectPath, actualFile);
        }
Example #7
0
        public void Detect_ReturnsFrameworkInfos_IfKeywordExistsInPackageJsonFile()
        {
            // Arrange
            var sourceRepo = new MemorySourceRepo();

            sourceRepo.AddFile(PackageJsonWithFrameworks, NodeConstants.PackageJsonFileName);
            sourceRepo.AddFile("", NodeConstants.FlutterYamlFileName);
            var context = CreateContext(sourceRepo);
            var options = new DetectorOptions
            {
                DisableFrameworkDetection = false,
            };
            var           detector = CreateNodePlatformDetector(options);
            List <string> expectedFrameworkNames = new List <string>()
            {
                "Aurelia", "Svelte", "jQuery", "React", "Flutter"
            };
            List <string> expectedFrameworkVersions = new List <string>()
            {
                "1.3.1", "3.0.0", "3.5.1", "16.12.0", ""
            };

            // Act
            var result = (NodePlatformDetectorResult)detector.Detect(context);

            // Assert
            Assert.NotNull(result);
            Assert.Equal("nodejs", result.Platform);
            Assert.Null(result.PlatformVersion);
            Assert.Equal(string.Empty, result.AppDirectory);
            Assert.Equal(expectedFrameworkNames, result.Frameworks.Select(x => x.Framework).ToList());
            Assert.Equal(expectedFrameworkVersions, result.Frameworks.Select(x => x.FrameworkVersion).ToList());
        }
        public void GetRelativePathToProjectFile_ReturnsAzureFunctionsApp_OnlyWhenNoWebAppIsFound()
        {
            // Arrange
            var sourceRepoDir = CreateSourceRepoDir();
            var srcDir        = CreateDir(sourceRepoDir, "src");
            var app1Dir       = CreateDir(srcDir, "App1");

            File.WriteAllText(Path.Combine(app1Dir, "App1.csproj"), NonWebSdkProjectFile);
            var azureFunctionsAppDir = CreateDir(srcDir, "AzureFunctionsApp1");

            File.WriteAllText(Path.Combine(
                                  azureFunctionsAppDir,
                                  "AzureFunctionsApp1.csproj"),
                              AzureFunctionsProjectFile);
            var expectedRelativePath = Path.Combine("src", "AzureFunctionsApp1", "AzureFunctionsApp1.csproj");
            var sourceRepo           = CreateSourceRepo(sourceRepoDir);
            var context = GetContext(sourceRepo);
            var options = new DetectorOptions();

            options.AppType = null;
            var provider = GetProjectFileProvider(options);

            // Act
            var actual = provider.GetRelativePathToProjectFile(context);

            // Assert
            Assert.Equal(expectedRelativePath, actual);
        }
Example #9
0
        public AudioFeatures(DetectorOptions options, string csvDirectory, float correction, IProgress <string> progress = null)
        {
            //force garbage collection
            GC.Collect(2, GCCollectionMode.Forced, true);

            _csvDirectory          = csvDirectory;
            _outerProgressReporter = progress ?? new Progress <string>();
            _correction            = correction;
            _innerProgressReporter = new Progress <string>(status =>
            {
                _outerProgressReporter.Report(_currentTask + ":" + status);
            });

            _onsetDetector = new OnsetDetector(options, _innerProgressReporter);
        }
Example #10
0
        protected DefaultProjectFileProvider GetProjectFileProvider(DetectorOptions options = null)
        {
            options = options ?? new DetectorOptions();

            var providers = new IProjectFileProvider[]
            {
                new ExplicitProjectFileProvider(
                    Options.Create(options),
                    NullLogger <ExplicitProjectFileProvider> .Instance),
                new RootDirectoryProjectFileProvider(NullLogger <RootDirectoryProjectFileProvider> .Instance),
                new ProbeAndFindProjectFileProvider(
                    NullLogger <ProbeAndFindProjectFileProvider> .Instance,
                    Options.Create(options)),
            };

            return(new DefaultProjectFileProvider(providers));
        }
Example #11
0
        public void GetRelativePathToProjectFile_ThrowsWhenAppTypeIsSetToWebAppsAndMultipleProjectFilesAreFound()
        {
            // Arrange
            var sourceRepoDir = CreateSourceRepoDir();
            var srcDir        = CreateDir(sourceRepoDir, "src");
            var webApp1Dir    = CreateDir(srcDir, "WebApp1");

            File.WriteAllText(Path.Combine(webApp1Dir, "WebApp1.csproj"), WebSdkProjectFile);
            var webApp2Dir = CreateDir(srcDir, "WebApp2");

            File.WriteAllText(Path.Combine(webApp2Dir, "WebApp2.csproj"), WebSdkProjectFile);

            var azureFunctionsApp1Dir = CreateDir(srcDir, "AzureFunctionsApp1");

            File.WriteAllText(Path.Combine(
                                  azureFunctionsApp1Dir,
                                  "AzureFunctionsApp1.csproj"),
                              AzureFunctionsProjectFile);

            var azureBlazorWasmApp1Dir = CreateDir(srcDir, "BlazorWasmApp1");

            File.WriteAllText(Path.Combine(
                                  azureBlazorWasmApp1Dir,
                                  "BlazorWasmApp1.csproj"),
                              AzureBlazorWasmClientNetStandardProjectFile);

            var sourceRepo = CreateSourceRepo(sourceRepoDir);
            var context    = GetContext(sourceRepo);
            var options    = new DetectorOptions();

            options.AppType = Constants.WebApplications;

            var provider = GetProjectFileProvider(options);

            // Act & Assert
            var exception = Assert.Throws <InvalidProjectFileException>(
                () => provider.GetRelativePathToProjectFile(context));

            Assert.StartsWith(
                "Ambiguity in selecting a project to build. Found multiple projects:",
                exception.Message);
            Assert.DoesNotContain("AzureFunctionsApp1.csproj", exception.Message);
            Assert.DoesNotContain("BlazorWasmApp1.csproj", exception.Message);
        }
Example #12
0
        public void GetRelativePathToProjectFile_ReturnsFile_IfProjEnvVariableIsSet_AndIsAtRoot()
        {
            // Arrange
            var expectedPath  = "WebApp1.csproj";
            var sourceRepoDir = CreateSourceRepoDir();
            var projectFile   = Path.Combine(sourceRepoDir, expectedPath);

            File.WriteAllText(projectFile, WebSdkProjectFile);
            var sourceRepo      = CreateSourceRepo(sourceRepoDir);
            var context         = GetContext(sourceRepo);
            var detectorOptions = new DetectorOptions();

            detectorOptions.Project = expectedPath;
            var provider = GetProjectFileProvider(detectorOptions);

            // Act
            var actualFilePath = provider.GetRelativePathToProjectFile(context);

            // Assert
            Assert.Equal(expectedPath, actualFilePath);
        }
Example #13
0
        public void Detect_ReturnsNull_WhenCustomRequirementsFileDoesNotExist()
        {
            // Arrange
            var options = new DetectorOptions
            {
                CustomRequirementsTxtPath = "foo/requirements.txt",
            };
            var detector  = CreatePythonPlatformDetector(options);
            var sourceDir = Directory.CreateDirectory(Path.Combine(_tempDirRoot, Guid.NewGuid().ToString("N")))
                            .FullName;

            IOHelpers.CreateFile(sourceDir, "foo==1.1", "requirements.txt");
            var repo    = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance);
            var context = CreateContext(repo);

            // Act
            var result = detector.Detect(context);

            // Assert
            Assert.Null(result);
        }
        public void GetRelativePathToProjectFile_ReturnsRelativePath_WhenSourceRepoHasValidProjectTypeAtRoot_AndDeepProbingIsDisabled()
        {
            // Arrange
            var sourceRepoDir = CreateSourceRepoDir();

            File.WriteAllText(Path.Combine(sourceRepoDir, "WebApp1.csproj"), WebSdkProjectFile);
            var expectedPath = "WebApp1.csproj";
            var sourceRepo   = CreateSourceRepo(sourceRepoDir);
            var context      = GetContext(sourceRepo);
            var options      = new DetectorOptions
            {
                DisableRecursiveLookUp = true,
            };
            var provider = GetProjectFileProvider(options);

            // Act
            var actual = provider.GetRelativePathToProjectFile(context);

            // Assert
            Assert.Equal(expectedPath, actual);
        }
        public void GetRelativePathToProjectFile_ReturnsNull_WhenSourceRepoHasValidProjectType_ButDeepProbingIsDisabled()
        {
            // Arrange
            var sourceRepoDir = CreateSourceRepoDir();
            var srcDir        = CreateDir(sourceRepoDir, "src");
            var webApp1Dir    = CreateDir(srcDir, "WebApp1");

            File.WriteAllText(Path.Combine(webApp1Dir, "WebApp1.csproj"), WebSdkProjectFile);
            var sourceRepo = CreateSourceRepo(sourceRepoDir);
            var context    = GetContext(sourceRepo);
            var options    = new DetectorOptions
            {
                DisableRecursiveLookUp = true,
            };
            var provider = GetProjectFileProvider(options);

            // Act
            var actual = provider.GetRelativePathToProjectFile(context);

            // Assert
            Assert.Null(actual);
        }
Example #16
0
        public void Detect_ReutrnsResult_WhenRequirementsFileExistsAtRoot_AndDeepProbingIsDisabled()
        {
            // Arrange
            var options = new DetectorOptions
            {
                DisableRecursiveLookUp = true,
            };
            var detector  = CreatePythonPlatformDetector(options);
            var sourceDir = Directory.CreateDirectory(Path.Combine(_tempDirRoot, Guid.NewGuid().ToString("N")))
                            .FullName;

            IOHelpers.CreateFile(sourceDir, "foo==1.1", PythonConstants.RequirementsFileName);
            var repo    = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance);
            var context = CreateContext(repo);

            // Act
            var result = detector.Detect(context);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(PythonConstants.PlatformName, result.Platform);
            Assert.Null(result.PlatformVersion);
        }
Example #17
0
        public void Detect_ReturnsNull_WhenDotPyFilesExistInSubFolders_AndDeepProbingIsDisabled()
        {
            // Arrange
            var options = new DetectorOptions
            {
                DisableRecursiveLookUp = true,
            };
            var detector  = CreatePythonPlatformDetector(options);
            var sourceDir = Directory.CreateDirectory(Path.Combine(_tempDirRoot, Guid.NewGuid().ToString("N")))
                            .FullName;
            var subDir = Directory.CreateDirectory(Path.Combine(sourceDir, Guid.NewGuid().ToString("N"))).FullName;

            IOHelpers.CreateFile(subDir, "foo.py content", "foo.py");
            IOHelpers.CreateFile(subDir, "foo==1.1", PythonConstants.RequirementsFileName);
            var repo    = new LocalSourceRepo(sourceDir, NullLoggerFactory.Instance);
            var context = CreateContext(repo);

            // Act
            var result = detector.Detect(context);

            // Assert
            Assert.Null(result);
        }
Example #18
0
        public void Detect_ReturnsTrue_IfOnlyGemfileExist_AndItsStaticWebApp()
        {
            // Arrange
            var options = new DetectorOptions
            {
                AppType = Constants.StaticSiteApplications,
            };
            var detector = CreateRubyPlatformDetector();
            var repo     = new MemorySourceRepo();

            repo.AddFile("", RubyConstants.GemFileName);
            var context = CreateContext(repo);

            // Act
            var result = (RubyPlatformDetectorResult)detector.Detect(context);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(RubyConstants.PlatformName, result.Platform);
            Assert.Null(result.PlatformVersion);
            Assert.Equal(string.Empty, result.AppDirectory);
            Assert.True(result.GemfileExists);
            Assert.False(result.ConfigYmlFileExists);
        }
Example #19
0
        public void GetRelativePathToProjectFile_ReturnsFile_IfProjEnvVariableIsSet_AndProjectFileIsNotSupported(
            string projectFileExtension)
        {
            // Arrange
            var sourceRepoDir = CreateSourceRepoDir();
            var srcDir        = CreateDir(sourceRepoDir, "src");
            var webApp1Dir    = CreateDir(srcDir, "WebApp1");
            var projectFile   = Path.Combine(webApp1Dir, $"WebApp1.{projectFileExtension}");

            File.WriteAllText(projectFile, NonWebSdkProjectFile);
            var sourceRepo          = CreateSourceRepo(sourceRepoDir);
            var relativeProjectPath = Path.Combine("src", "WebApp1", $"WebApp1.{projectFileExtension}");
            var options             = new DetectorOptions();

            options.Project = relativeProjectPath;
            var context  = GetContext(sourceRepo);
            var provider = GetProjectFileProvider(options);

            // Act
            var actualFilePath = provider.GetRelativePathToProjectFile(context);

            // Assert
            Assert.Equal(relativeProjectPath, actualFilePath);
        }
Example #20
0
 private RubyDetector CreateRubyPlatformDetector(DetectorOptions options = null)
 {
     options = options ?? new DetectorOptions();
     return(new RubyDetector(NullLogger <RubyDetector> .Instance, Options.Create(options)));
 }
Example #21
0
 /// <summary>
 /// Creates an instance of <see cref="PythonDetector"/>.
 /// </summary>
 /// <param name="logger">The <see cref="ILogger{PythonDetector}"/>.</param>
 /// <param name="options">The <see cref="DetectorOptions"/>.</param>
 public PythonDetector(ILogger <PythonDetector> logger, IOptions <DetectorOptions> options)
 {
     _logger  = logger;
     _options = options.Value;
 }
Example #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GolangDetector"/> class.
 /// </summary>
 /// <param name="logger">The <see cref="ILogger{GolangDetector}"/>.</param>
 /// <param name="options">The <see cref="DetectorOptions"/>.</param>
 public GolangDetector(ILogger <GolangDetector> logger, IOptions <DetectorOptions> options)
 {
     this.logger  = logger;
     this.options = options.Value;
 }
Example #23
0
 /// <summary>
 /// Creates an instance of <see cref="RubyDetector"/>.
 /// </summary>
 /// <param name="logger">The <see cref="ILogger{RubyDetector}"/>.</param>
 /// <param name="options">The <see cref="DetectorOptions"/>.</param>
 public RubyDetector(ILogger <RubyDetector> logger, IOptions <DetectorOptions> options)
 {
     _logger  = logger;
     _options = options.Value;
 }
Example #24
0
 private GolangDetector CreateGolangPlatformDetector(DetectorOptions options = null)
 {
     options = options ?? new DetectorOptions();
     return(new GolangDetector(NullLogger <GolangDetector> .Instance, Options.Create(options)));
 }
Example #25
0
 private PythonDetector CreatePythonPlatformDetector(DetectorOptions options = null)
 {
     options = options ?? new DetectorOptions();
     return(new PythonDetector(NullLogger <PythonDetector> .Instance, Options.Create(options)));
 }
Example #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NodeDetector"/> class.
 /// </summary>
 /// <param name="logger">The <see cref="ILogger{NodeDetector}"/>.</param>
 /// <param name="options">The <see cref="DetectorOptions"/>.</param>
 public NodeDetector(ILogger <NodeDetector> logger, IOptions <DetectorOptions> options)
 {
     this.logger  = logger;
     this.options = options.Value;
 }