103 lines
3.9 KiB
C#
Executable File
103 lines
3.9 KiB
C#
Executable File
using System;
|
|
using System.Linq;
|
|
|
|
namespace MarketAlly.ProjectDetector.Detectors;
|
|
|
|
public class StandaloneProjectDetector : IProjectTypeDetector
|
|
{
|
|
public ProjectTypeDetectionResult Detect(ProjectAnalysis analysis)
|
|
{
|
|
var confidence = 0;
|
|
var reasons = new List<string>();
|
|
|
|
// This is a fallback detector for single projects that don't fit other categories
|
|
// It should have relatively low confidence and be used as a general classifier
|
|
|
|
// Check if it's a single project (not a solution with multiple projects)
|
|
var projectFileCount = analysis.Files.Count(f =>
|
|
f.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) ||
|
|
f.EndsWith(".vbproj", StringComparison.OrdinalIgnoreCase) ||
|
|
f.EndsWith(".fsproj", StringComparison.OrdinalIgnoreCase));
|
|
|
|
if (projectFileCount == 1)
|
|
{
|
|
confidence += 30;
|
|
reasons.Add("Single project file detected");
|
|
}
|
|
|
|
// Check for basic project structure without specific technology markers
|
|
if (analysis.Files.Any(f => f.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)) ||
|
|
analysis.Files.Any(f => f.EndsWith(".js", StringComparison.OrdinalIgnoreCase)) ||
|
|
analysis.Files.Any(f => f.EndsWith(".py", StringComparison.OrdinalIgnoreCase)) ||
|
|
analysis.Files.Any(f => f.EndsWith(".java", StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
confidence += 25;
|
|
reasons.Add("Contains source code files");
|
|
}
|
|
|
|
// Check for common project files that don't indicate specific technology
|
|
var commonFiles = new[] { "README.md", "LICENSE", ".gitignore", "package.json", "requirements.txt" };
|
|
if (commonFiles.Any(file => analysis.Files.Any(f =>
|
|
f.Equals(file, StringComparison.OrdinalIgnoreCase))))
|
|
{
|
|
confidence += 15;
|
|
reasons.Add("Contains common project files");
|
|
}
|
|
|
|
// Check for basic folder structure
|
|
if (analysis.Folders.Any(f => f.Equals("src", StringComparison.OrdinalIgnoreCase)) ||
|
|
analysis.Folders.Any(f => f.Equals("lib", StringComparison.OrdinalIgnoreCase)) ||
|
|
analysis.Folders.Any(f => f.Equals("app", StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
confidence += 10;
|
|
reasons.Add("Contains basic project structure");
|
|
}
|
|
|
|
// Reduce confidence if it has no clear project indicators
|
|
if (!analysis.PackageReferences.Any() &&
|
|
!analysis.PackageJsonDependencies.Any() &&
|
|
!analysis.PythonRequirements.Any() &&
|
|
!analysis.MavenConfig.Any() &&
|
|
!analysis.GradleConfig.Any())
|
|
{
|
|
confidence += 20;
|
|
reasons.Add("No specific technology dependencies detected");
|
|
}
|
|
|
|
// This should be a low-confidence fallback
|
|
confidence = Math.Min(confidence, 45); // Cap at 45% to ensure other detectors take precedence
|
|
|
|
return new ProjectTypeDetectionResult
|
|
{
|
|
IsMatch = confidence >= 20,
|
|
ProjectType = ProjectType.Standalone,
|
|
Confidence = confidence,
|
|
Reason = string.Join(", ", reasons)
|
|
};
|
|
}
|
|
}
|
|
|
|
public class GenericProjectDetector : IProjectTypeDetector
|
|
{
|
|
public ProjectTypeDetectionResult Detect(ProjectAnalysis analysis)
|
|
{
|
|
// This is the ultimate fallback - always returns true with minimal confidence
|
|
var confidence = 10;
|
|
var reasons = new List<string> { "Generic project (no specific type detected)" };
|
|
|
|
// Give a slight boost if it has any source files
|
|
if (analysis.Files.Any())
|
|
{
|
|
confidence += 5;
|
|
reasons.Add("Contains files");
|
|
}
|
|
|
|
return new ProjectTypeDetectionResult
|
|
{
|
|
IsMatch = true,
|
|
ProjectType = ProjectType.Other,
|
|
Confidence = confidence,
|
|
Reason = string.Join(", ", reasons)
|
|
};
|
|
}
|
|
} |