in assessment/collectors/app_code_collector.go [476:553]
func (m *MigrationCodeSummarizer) AnalyzeProject(ctx context.Context) (*CodeAssessment, error) {
logger.Log.Info(fmt.Sprintf("analyzing project: %s", m.projectRootPath))
dependencyGraph, processingOrder := m.projectDependencyAnalyzer.GetExecutionOrder(m.projectRootPath)
m.projectDependencyAnalyzer.LogDependencyGraph(dependencyGraph, m.projectRootPath)
m.projectDependencyAnalyzer.LogExecutionOrder(processingOrder)
m.dependencyGraph = dependencyGraph
var allSnippets []Snippet
projectCodeAssessment := &CodeAssessment{
ProjectPath: m.projectRootPath,
Snippets: &allSnippets,
GeneralWarnings: make([]string, 0, 10),
}
parallelTaskRunner := &task.RunParallelTasksImpl[*FileAnalysisInput, *FileAnalysisResponse]{}
fileIndex := 0
totalLinesOfCode := 0
projectProgrammingLanguage := m.projectProgrammingLanguage
detectedFramework := m.sourceDatabaseFramework
logger.Log.Info("initiating file scanning and analysis. this may take a few minutes.")
for _, fileBatch := range processingOrder {
analysisInputs := make([]*FileAnalysisInput, 0, len(fileBatch))
for _, filePath := range fileBatch {
fileIndex++
fileContent, err := m.fetchFileContent(filePath)
if err != nil {
logger.Log.Error("Error fetching file content: ", zap.Error(err))
continue
}
totalLinesOfCode += strings.Count(fileContent, "\n")
isDependentOnDAO, methodChanges := m.analyzeFileDependencies(filePath, fileContent)
if !isDependentOnDAO {
continue
}
analysisInputs = append(analysisInputs, &FileAnalysisInput{
Context: ctx,
ProjectPath: m.projectRootPath,
FilePath: filePath,
MethodChanges: methodChanges,
FileContent: fileContent,
FileIndex: fileIndex,
})
}
if len(analysisInputs) == 0 {
continue
}
analysisResults, err := parallelTaskRunner.RunParallelTasks(analysisInputs, 20, m.AnalyzeFileTask, false)
if err != nil {
logger.Log.Error("Error running parallel file analysis: ", zap.Error(err))
} else {
for _, result := range analysisResults {
analysisResponse := result.Result
logger.Log.Debug("File Code Assessment Result: ",
zap.Any("codeAssessment", analysisResponse.CodeAssessment),
zap.String("filePath", analysisResponse.AnalyzedFilePath))
*projectCodeAssessment.Snippets = append(*projectCodeAssessment.Snippets, *analysisResponse.CodeAssessment.Snippets...)
projectCodeAssessment.GeneralWarnings = append(projectCodeAssessment.GeneralWarnings, analysisResponse.CodeAssessment.GeneralWarnings...)
m.fileDependencyAnalysis[analysisResponse.AnalyzedFilePath] = FileDependencyInfo{
PublicMethodSignatures: analysisResponse.MethodSignatures,
IsDAODependent: true,
}
}
}
}
projectCodeAssessment.Language = projectProgrammingLanguage
projectCodeAssessment.Framework = detectedFramework
projectCodeAssessment.TotalLoc = totalLinesOfCode
projectCodeAssessment.TotalFiles = fileIndex
return projectCodeAssessment, nil
}