Skip to main content

sqry_classpath/
lib.rs

1//! JVM classpath analysis for sqry.
2//!
3//! This crate provides bytecode parsing, build system resolution, and graph integration
4//! for JVM classpath dependencies (Java, Kotlin, Scala). It enables sqry to resolve
5//! imports and type references across workspace source code and compiled library JARs.
6//!
7//! # Architecture
8//!
9//! The classpath pipeline runs as a pre-pass before the main build graph pipeline:
10//!
11//! 1. **Detect** - Identify the build system (Gradle, Maven, Bazel, sbt)
12//! 2. **Resolve** - Extract the classpath JAR list via build tool subprocess
13//! 3. **Scan** - Parse `.class` bytecode from each JAR into `ClassStub` records
14//! 4. **Cache** - Persist parsed stubs per JAR (SHA-256 keyed) for incremental rebuilds
15//! 5. **Index** - Merge all stubs into a `ClasspathIndex` for fast FQN lookup
16//! 6. **Emit** - Create synthetic graph nodes and register in `ExportMap`
17//!
18//! # Feature Gate
19//!
20//! All classpath functionality is gated behind the `jvm-classpath` feature on `sqry-core`.
21//! When disabled, no classpath code is compiled and there is zero overhead.
22
23pub mod bytecode;
24pub mod detect;
25pub mod graph;
26pub mod kotlin;
27pub mod pipeline;
28pub mod resolve;
29pub mod scala;
30pub mod stub;
31
32use thiserror::Error;
33
34/// Errors that can occur during classpath analysis.
35#[derive(Debug, Error)]
36pub enum ClasspathError {
37    /// Build system detection failed.
38    #[error("build system detection failed: {0}")]
39    DetectionFailed(String),
40
41    /// Classpath resolution failed (build tool subprocess error).
42    #[error("classpath resolution failed: {0}")]
43    ResolutionFailed(String),
44
45    /// Bytecode parsing error for a specific class.
46    #[error("bytecode parse error in {class_name}: {reason}")]
47    BytecodeParseError { class_name: String, reason: String },
48
49    /// JAR file could not be read.
50    #[error("JAR read error for {path}: {reason}")]
51    JarReadError { path: String, reason: String },
52
53    /// Cache I/O error.
54    #[error("cache error: {0}")]
55    CacheError(String),
56
57    /// Index persistence error.
58    #[error("index error: {0}")]
59    IndexError(String),
60
61    /// Graph emission error.
62    #[error("graph emission error: {0}")]
63    EmissionError(String),
64
65    /// Generic I/O error.
66    #[error(transparent)]
67    Io(#[from] std::io::Error),
68}
69
70/// Result type for classpath operations.
71pub type ClasspathResult<T> = Result<T, ClasspathError>;