public string GetRelativePathToProjectFile(ScriptGeneratorContext context) { var projectPath = GetProjectInfoFromSettings(context); if (string.IsNullOrEmpty(projectPath)) { _logger.LogDebug( "No request to build a particular project file explicitly either using the " + $"'{EnvironmentSettingsKeys.Project}' environment variable or the " + $"'{DotNetCoreConstants.ProjectBuildPropertyKey}' build property"); return(null); } var projectFileWithRelativePath = projectPath.Trim(); var projectFile = Path.Combine(context.SourceRepo.RootPath, projectFileWithRelativePath); if (context.SourceRepo.FileExists(projectFile)) { _logger.LogDebug($"Using the given .NET Core project file to build."); } else { _logger.LogWarning($"Could not find the .NET Core project file."); throw new InvalidUsageException( string.Format(Resources.Labels.DotNetCoreCouldNotFindProjectFileToBuild, projectFile)); } return(projectFileWithRelativePath); }
public LanguageDetectorResult Detect(ScriptGeneratorContext context) { var sourceRepo = context.SourceRepo; if (!sourceRepo.FileExists(PhpConstants.ComposerFileName)) { _logger.LogDebug($"File '{PhpConstants.ComposerFileName}' does not exist in source repo"); return(null); } dynamic composerFile = null; try { composerFile = sourceRepo.ReadJsonObjectFromFile(PhpConstants.ComposerFileName); } catch (Exception ex) { // We just ignore errors, so we leave malformed composer.json files for Composer to handle, // not us. This prevents us from erroring out when Composer itself might be able to tolerate // some errors in the composer.json file. _logger.LogWarning( ex, $"Exception caught while trying to deserialize {PhpConstants.ComposerFileName.Hash()}"); } string runtimeVersion = VerifyAndResolveVersion(composerFile?.require?.php?.Value as string); return(new LanguageDetectorResult { Language = PhpConstants.PhpName, LanguageVersion = runtimeVersion, }); }
public LanguageDetectorResult Detect(ScriptGeneratorContext context) { var sourceRepo = context.SourceRepo; if (!sourceRepo.FileExists(PythonConstants.RequirementsFileName)) { _logger.LogDebug($"File '{PythonConstants.RequirementsFileName}' does not exist in source repo"); return(null); } string runtimeVersion = DetectPythonVersionFromRuntimeFile(sourceRepo); if (string.IsNullOrEmpty(runtimeVersion)) { var files = sourceRepo.EnumerateFiles( PythonConstants.PythonFileNamePattern, searchSubDirectories: false); if (files == null || !files.Any()) { _logger.LogDebug($"Files with extension '{PythonConstants.PythonFileNamePattern}' do not exist " + "in source repo root"); return(null); } } runtimeVersion = VerifyAndResolveVersion(runtimeVersion); return(new LanguageDetectorResult { Language = PythonConstants.PythonName, LanguageVersion = runtimeVersion, }); }
public LanguageDetectorResult Detect(ScriptGeneratorContext context) { var projectFile = _projectFileProvider.GetRelativePathToProjectFile(context); if (string.IsNullOrEmpty(projectFile)) { return(null); } var sourceRepo = context.SourceRepo; var projectFileDoc = XDocument.Load(new StringReader(sourceRepo.ReadFile(projectFile))); var targetFrameworkElement = projectFileDoc.XPathSelectElement( DotNetCoreConstants.TargetFrameworkElementXPathExpression); var targetFramework = targetFrameworkElement?.Value; if (string.IsNullOrEmpty(targetFramework)) { _logger.LogDebug( $"Could not find 'TargetFramework' element in the project file."); return(null); } // If a repo explicitly specifies an sdk version, then just use it as it is. string languageVersion = null; if (sourceRepo.FileExists(DotNetCoreConstants.GlobalJsonFileName)) { var globalJson = GetGlobalJsonObject(sourceRepo); var sdkVersion = globalJson?.sdk?.version?.Value as string; if (sdkVersion != null) { languageVersion = sdkVersion; } } if (string.IsNullOrEmpty(languageVersion)) { languageVersion = DetermineSdkVersion(targetFramework); } if (languageVersion == null) { _logger.LogDebug( $"Could not find a {DotNetCoreConstants.LanguageName} version corresponding to 'TargetFramework'" + $" '{targetFramework}'."); return(null); } languageVersion = VerifyAndResolveVersion(languageVersion); return(new LanguageDetectorResult { Language = DotNetCoreConstants.LanguageName, LanguageVersion = languageVersion, }); }
public virtual string GetRelativePathToProjectFile(ScriptGeneratorContext context) { foreach (var projectFileProvider in _projectFileProviders) { var projectFile = projectFileProvider.GetRelativePathToProjectFile(context); if (!string.IsNullOrEmpty(projectFile)) { return(projectFile); } } return(null); }
public string GetRelativePathToProjectFile(ScriptGeneratorContext context) { var sourceRepo = context.SourceRepo; // Check if root of the repo has a .csproj or a .fsproj file var projectFile = GetProjectFileAtRoot(sourceRepo, DotNetCoreConstants.CSharpProjectFileExtension) ?? GetProjectFileAtRoot(sourceRepo, DotNetCoreConstants.FSharpProjectFileExtension); if (projectFile != null) { return(new FileInfo(projectFile).Name); } return(null); }
private string GetProjectInfoFromSettings(ScriptGeneratorContext context) { // Value from command line has higher precedence than from environment variables if (context.Properties != null && context.Properties.TryGetValue( DotNetCoreConstants.ProjectBuildPropertyKey, out var projectFromProperty)) { return(projectFromProperty); } if (!string.IsNullOrEmpty(_options.Project)) { return(_options.Project); } return(null); }
public LanguageDetectorResult Detect(ScriptGeneratorContext context) { return(_detector.Detect(context)); }
public LanguageDetectorResult Detect(ScriptGeneratorContext context) { bool isNodeApp = false; var sourceRepo = context.SourceRepo; if (sourceRepo.FileExists(NodeConstants.PackageJsonFileName) || sourceRepo.FileExists(NodeConstants.PackageLockJsonFileName) || sourceRepo.FileExists(NodeConstants.YarnLockFileName)) { isNodeApp = true; } else { _logger.LogDebug( $"Could not find {NodeConstants.PackageJsonFileName}/{NodeConstants.PackageLockJsonFileName}" + $"/{NodeConstants.YarnLockFileName} in repo"); } if (!isNodeApp) { // Copying the logic currently running in Kudu: var mightBeNode = false; foreach (var typicalNodeFile in TypicalNodeDetectionFiles) { if (sourceRepo.FileExists(typicalNodeFile)) { mightBeNode = true; break; } } if (mightBeNode) { // Check if any of the known iis start pages exist // If so, then it is not a node.js web site otherwise it is foreach (var iisStartupFile in IisStartupFiles) { if (sourceRepo.FileExists(iisStartupFile)) { _logger.LogDebug( "App in repo is not a Node.js app as it has the file {iisStartupFile}", iisStartupFile.Hash()); return(null); } } isNodeApp = true; } else { // No point in logging the actual file list, as it's constant _logger.LogDebug("Could not find typical Node.js files in repo"); } } if (isNodeApp) { var packageJson = NodePlatform.GetPackageJsonObject(sourceRepo, _logger); var nodeVersion = DetectNodeVersion(packageJson); return(new LanguageDetectorResult { Language = NodeConstants.NodeJsName, LanguageVersion = nodeVersion, }); } else { _logger.LogDebug("App in repo is not a Node.js app"); } return(null); }
public string GetRelativePathToProjectFile(ScriptGeneratorContext context) { if (_probedForProjectFile) { return(_projectFileRelativePath); } var sourceRepo = context.SourceRepo; string projectFile = null; // Check if any of the sub-directories has a .csproj or .fsproj file and if that file has references // to websdk or azure functions // Since enumerating all files in the directory may take some time, write a message using the // given IStandardOutputWriter to alert the user of what is happening. _writer.WriteLine(string.Format(Labels.DotNetCoreEnumeratingFilesInRepo, DotNetCoreConstants.CSharpProjectFileExtension)); // search for .csproj files var projectFiles = GetAllProjectFilesInRepo( sourceRepo, DotNetCoreConstants.CSharpProjectFileExtension); if (!projectFiles.Any()) { _logger.LogDebug( "Could not find any files with extension " + $"'{DotNetCoreConstants.CSharpProjectFileExtension}' in repo."); // search for .fsproj files projectFiles = GetAllProjectFilesInRepo( sourceRepo, DotNetCoreConstants.FSharpProjectFileExtension); if (!projectFiles.Any()) { _logger.LogDebug( "Could not find any files with extension " + $"'{DotNetCoreConstants.FSharpProjectFileExtension}' in repo."); return(null); } } var webAppProjects = new List <string>(); var azureFunctionsProjects = new List <string>(); var allProjects = new List <string>(); foreach (var file in projectFiles) { allProjects.Add(file); if (ProjectFileHelpers.IsAspNetCoreWebApplicationProject(sourceRepo, file)) { webAppProjects.Add(file); } else if (ProjectFileHelpers.IsAzureFunctionsProject(sourceRepo, file)) { azureFunctionsProjects.Add(file); } } projectFile = GetProject(webAppProjects); if (projectFile == null) { projectFile = GetProject(azureFunctionsProjects); } if (projectFile == null) { _logger.LogDebug("Could not find a .NET Core project file to build."); return(null); } // Cache the results _probedForProjectFile = true; _projectFileRelativePath = ProjectFileHelpers.GetRelativePathToRoot(projectFile, sourceRepo.RootPath); return(_projectFileRelativePath); }