1+ use env_logger;
2+ use log:: { info, debug, error} ;
3+ use syncable_cli:: analyzer:: dependency_parser:: { DependencyParser , Language } ;
4+ use syncable_cli:: analyzer:: vulnerability_checker:: VulnerabilityChecker ;
5+ use std:: path:: Path ;
6+ use std:: env;
7+
8+ #[ tokio:: main]
9+ async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
10+ // Enable debug logging
11+ env:: set_var ( "RUST_LOG" , "debug" ) ;
12+ env_logger:: init ( ) ;
13+
14+ // Get project path from command line args or use current directory
15+ let args: Vec < String > = env:: args ( ) . collect ( ) ;
16+ let project_path = if args. len ( ) > 1 {
17+ Path :: new ( & args[ 1 ] )
18+ } else {
19+ Path :: new ( "." )
20+ } ;
21+
22+ info ! ( "🔍 Debug Java vulnerability scanning in: {}" , project_path. display( ) ) ;
23+
24+ // Parse dependencies
25+ let parser = DependencyParser :: new ( ) ;
26+ info ! ( "📦 Parsing dependencies..." ) ;
27+ let dependencies = parser. parse_all_dependencies ( project_path) ?;
28+
29+ if dependencies. is_empty ( ) {
30+ error ! ( "❌ No dependencies found!" ) ;
31+ info ! ( "Make sure you're in a Java project directory with:" ) ;
32+ info ! ( " - pom.xml (Maven project)" ) ;
33+ info ! ( " - build.gradle or build.gradle.kts (Gradle project)" ) ;
34+ return Ok ( ( ) ) ;
35+ }
36+
37+ // Show detailed dependency information
38+ info ! ( "📊 Found dependencies in {} languages:" , dependencies. len( ) ) ;
39+ for ( lang, deps) in & dependencies {
40+ info ! ( " {:?}: {} dependencies" , lang, deps. len( ) ) ;
41+ if * lang == Language :: Java {
42+ info ! ( " Java dependencies details:" ) ;
43+ for dep in deps. iter ( ) . take ( 10 ) {
44+ info ! ( " - {} v{} (source: {:?})" , dep. name, dep. version, dep. source) ;
45+ }
46+ if deps. len ( ) > 10 {
47+ info ! ( " ... and {} more" , deps. len( ) - 10 ) ;
48+ }
49+ }
50+ }
51+
52+ // Check if Java dependencies were found
53+ if !dependencies. contains_key ( & Language :: Java ) {
54+ error ! ( "❌ No Java dependencies detected!" ) ;
55+ info ! ( "Troubleshooting steps:" ) ;
56+ info ! ( "1. Make sure you're in a Java project directory" ) ;
57+ info ! ( "2. For Maven projects: ensure pom.xml exists and has <dependencies> section" ) ;
58+ info ! ( "3. For Gradle projects: ensure build.gradle exists with dependency declarations" ) ;
59+ info ! ( "4. Run 'mvn dependency:resolve' or 'gradle build' to ensure dependencies are resolved" ) ;
60+ return Ok ( ( ) ) ;
61+ }
62+
63+ // Check vulnerabilities
64+ info ! ( "🛡️ Checking for vulnerabilities..." ) ;
65+ let checker = VulnerabilityChecker :: new ( ) ;
66+
67+ match checker. check_all_dependencies ( & dependencies, project_path) . await {
68+ Ok ( report) => {
69+ info ! ( "✅ Vulnerability scan completed successfully!" ) ;
70+ info ! ( "📊 Results:" ) ;
71+ info ! ( " Total vulnerabilities: {}" , report. total_vulnerabilities) ;
72+ info ! ( " Critical: {}" , report. critical_count) ;
73+ info ! ( " High: {}" , report. high_count) ;
74+ info ! ( " Medium: {}" , report. medium_count) ;
75+ info ! ( " Low: {}" , report. low_count) ;
76+
77+ if report. total_vulnerabilities > 0 {
78+ info ! ( "🚨 Vulnerable dependencies:" ) ;
79+ for vuln_dep in & report. vulnerable_dependencies {
80+ info ! ( " - {} v{} ({} vulnerabilities)" ,
81+ vuln_dep. name, vuln_dep. version, vuln_dep. vulnerabilities. len( ) ) ;
82+ for vuln in & vuln_dep. vulnerabilities {
83+ info ! ( " • {} [{:?}] - {}" , vuln. id, vuln. severity, vuln. title) ;
84+ }
85+ }
86+ } else {
87+ info ! ( "✅ No vulnerabilities found!" ) ;
88+ info ! ( "This could mean:" ) ;
89+ info ! ( " - Your dependencies are up to date and secure" ) ;
90+ info ! ( " - The vulnerability scanner (grype) didn't find any issues" ) ;
91+ info ! ( " - The dependency versions couldn't be matched with vulnerability databases" ) ;
92+ }
93+ }
94+ Err ( e) => {
95+ error ! ( "❌ Vulnerability scanning failed: {}" , e) ;
96+ info ! ( "Common issues:" ) ;
97+ info ! ( " - grype not installed: brew install grype" ) ;
98+ info ! ( " - Project not built: run 'mvn compile' or 'gradle build'" ) ;
99+ info ! ( " - Dependencies not resolved: run 'mvn dependency:resolve'" ) ;
100+ }
101+ }
102+
103+ Ok ( ( ) )
104+ }
0 commit comments