Documentation
¶
Index ¶
Constants ¶
const ( JAVA = "src/main/java" WEBAPP = "src/main/webapp" )
const ( JavaFile = ".java" JavaArchive = ".jar" WebArchive = ".war" EnterpriseArchive = ".ear" ClassFile = ".class" MvnURIPrefix = "mvn://" PomXmlFile = "pom.xml" )
const ( METAINF = "META-INF" WEBINF = "WEB-INF" )
const ( // File and directory permissions DirPermRWX = 0755 // rwxr-xr-x: Owner can read/write/execute, others can read/execute DirPermRWXGrp = 0770 // rwxrwx---: Owner and group can read/write/execute FilePermRW = 0644 // rw-r--r--: Owner can read/write, others can read )
const ( EMBEDDED_KONVEYOR_GROUP = "io.konveyor.embededdep" DefaultWorkerPoolSize = 10 // Number of parallel workers for decompilation )
const ( CSS = "css" JS = "js" IMAGES = "images" HTML = "html" )
const KeySize = 40
Variables ¶
This section is empty.
Functions ¶
func AppendToFile ¶
AppendToFile reads the entire content of src file and appends it to dst file. The destination file must already exist and be writable. Returns error if file operations fail.
Types ¶
type Decompiler ¶
type Decompiler interface {
// DecompileIntoProject decompiles a binary artifact into a project directory structure.
// Used for decompiling application binaries (not dependencies).
//
// Returns list of discovered JavaArtifacts from embedded dependencies.
DecompileIntoProject(context context.Context, binaryPath, projectPath string) ([]JavaArtifact, error)
// Decompile treats an artifact as a dependency and decompiles it into Maven repository structure.
// Creates proper groupId/artifactId/version directory hierarchy in the local Maven repository.
//
// Returns list of JavaArtifacts including the main artifact and any discovered embedded dependencies.
Decompile(context context.Context, binaryPath string) ([]JavaArtifact, error)
}
Decompiler is the public interface for decompiling Java binary artifacts. It provides two modes of operation:
- Decompile: Treats artifact as a dependency, creating Maven repository structure
- DecompileIntoProject: Decompiles into a project directory for analysis
The decompiler uses a worker pool to parallelize decompilation of multiple artifacts.
type DecompilerOpts ¶
type DecompilerOpts struct {
DecompileTool string // Absolute path to FernFlower decompiler JAR
// contains filtered or unexported fields
}
DecompilerOpts contains configuration options for creating a Decompiler instance. All fields must be properly initialized except workers which defaults to DefaultWorkerPoolSize if zero.
type DecomplierResponse ¶
type DecomplierResponse struct {
Artifacts []JavaArtifact // List of artifacts discovered during decompilation
// contains filtered or unexported fields
}
DecomplierResponse contains the results from a decompilation operation. It is sent through a channel to communicate results from worker goroutines.
type IndexEntry ¶
type IndexEntry struct {
Key string // The search key
Offset int64 // Byte offset of the line in the data file
Length int64 // Length of the line in the data file
}
IndexEntry represents a single entry in the search index. It contains the key and metadata needed to locate the corresponding value in the data file.
type JavaArtifact ¶
type JavaArtifact struct {
FoundOnline bool // Whether the artifact was found in Maven Central or known OSS repositories
Packaging string // Archive type: .jar, .war, .ear
GroupId string // Maven groupId (e.g., "org.springframework")
ArtifactId string // Maven artifactId (e.g., "spring-core")
Version string // Maven version (e.g., "5.3.21")
Sha1 string // SHA1 hash for verification and lookups
}
JavaArtifact represents Maven coordinates and metadata for a Java dependency artifact. It is used to identify JAR files and manage their Maven repository locations.
The artifact can be constructed from various sources:
- SHA1 hash lookup in Maven index
- Embedded pom.properties in JAR META-INF
- Inferred from file path structure
func ToDependency ¶
func ToDependency(_ context.Context, log logr.Logger, labeler labels.Labeler, jarFile string, mavenIndexPath string) (JavaArtifact, error)
ToDependency identifies Maven coordinates for a JAR file using multiple strategies. It attempts identification in the following order:
- SHA1 hash lookup in Maven index (fastest, requires mavenIndexPath)
- Extract from embedded pom.properties in JAR META-INF (fallback)
Parameters:
- jarFile: Absolute path to the JAR file to identify
- mavenIndexPath: Path to the txt index file
- log: Logger for progress and error reporting
- labeler: Used to determine if dependency is open source (unused in current implementation)
Returns the JavaArtifact with coordinates, or empty artifact with error if all strategies fail.
func ToFilePathDependency ¶
func ToFilePathDependency(_ context.Context, filePath string) (JavaArtifact, error)
ToFilePathDependency infers Maven coordinates from a file path structure. This is used as a last-resort fallback when neither SHA1 lookup nor embedded POM work.
The function assumes the file path follows Java package structure: /org/springframework/boot/loader/jar/Something.class becomes:
- GroupId: org.springframework.boot.loader
- ArtifactId: jar
- Version: 0.0.0 (placeholder)
Parameters:
- filePath: Path to a .class file within a decompiled structure
Returns JavaArtifact with inferred coordinates. Version is always set to "0.0.0".
func (JavaArtifact) EqualsPomDep ¶
func (j JavaArtifact) EqualsPomDep(dependency gopom.Dependency) bool
EqualsPomDep compares a JavaArtifact with a gopom.Dependency for equality. Returns true if groupId, artifactId, and version all match. Returns false if any field is nil or doesn't match.
func (JavaArtifact) IsValid ¶
func (j JavaArtifact) IsValid() bool
IsValid checks if the artifact has the minimum required Maven coordinates. Returns true if groupId, artifactId, and version are all non-empty.
func (JavaArtifact) ToPomDep ¶
func (j JavaArtifact) ToPomDep() gopom.Dependency
ToPomDep converts a JavaArtifact to a gopom.Dependency structure. This is used when generating or updating pom.xml files with discovered dependencies.
type Resolver ¶
type Resolver interface {
// ResolveSources downloads dependency sources and decompiles JARs that lack source artifacts.
// This is a critical step for enabling deep code analysis, as it ensures the language server
// has access to all dependency source code.
//
// Process:
// 1. Execute build tool command to download available source JARs
// 2. Parse output to identify dependencies without sources
// 3. Locate binary JARs for unresolved dependencies
// 4. Decompile missing sources using a decompiler (parallel worker pool)
// 5. Store decompiled sources in appropriate repository structure
//
// Parameters:
// - ctx: Context for cancellation and timeout control (typically 5-10 minute timeout)
//
// Returns:
// - sourceLocation (string): Absolute path to project source directory
// For source projects: Original project location
// For binary artifacts: Path to generated project directory
// - dependencyLocation (string): Absolute path to local dependency repository
// May be empty string if the build tool uses a different caching mechanism
// - error: Error if source resolution fails
//
// Example Usage:
// resolver, _ := buildTool.GetResolver("/path/to/decompiler.jar")
// srcPath, depPath, err := resolver.ResolveSources(ctx)
// if err != nil {
// // Handle resolution failure
// }
// // srcPath: Project directory with sources
// // depPath: Repository with dependency sources (may be empty)
//
// Performance Considerations:
// - Uses worker pool for parallel decompilation
// - Can take several minutes for large projects with many dependencies
// - Progress logged at various verbosity levels
// - Individual decompilation failures logged but don't stop overall process
//
// Error Handling:
// - Returns error if build tool command fails completely
// - Returns error if decompiler initialization fails
// - Logs individual JAR decompilation failures but continues
// - May cache errors to avoid repeated failures
ResolveSources(ctx context.Context) (sourceLocation string, dependencyLocation string, err error)
}
Resolver handles downloading and decompiling dependency sources for different build systems. It ensures that all project dependencies have accessible source code for analysis, either by downloading source JARs from repositories or by decompiling binary JARs using a decompiler.
The resolver is obtained from BuildTool.GetResolver() and is automatically invoked during provider initialization when BuildTool.ShouldResolve() returns true or when running in FullAnalysisMode.
func GetBinaryResolver ¶
func GetBinaryResolver(options ResolverOptions) Resolver
GetBinaryResolver creates a new binary dependency resolver with the provided options. The resolver is used for analyzing standalone binary artifacts (JAR/WAR/EAR) without accompanying source code or build files.
func GetGradleResolver ¶
func GetGradleResolver(opts ResolverOptions) Resolver
func GetMavenResolver ¶
func GetMavenResolver(options ResolverOptions) Resolver
type ResolverOptions ¶
type ResolverOptions struct {
// Log is the logger instance for logging resolver operations.
// Used by all resolver types for progress tracking and error reporting.
Log logr.Logger
// Location is the absolute path to the project directory or binary artifact.
// Points to the root of the project or the binary file to be analyzed.
Location string
// DecompileTool is the absolute path to the decompiler JAR.
// Required by all resolver types for decompiling dependencies without sources.
DecompileTool string
// Labeler identifies whether dependencies are open source or internal.
// Used to determine if remote repository lookups should be attempted.
Labeler labels.Labeler
// LocalRepo is the path to the local dependency repository where
// dependencies and their sources are cached.
// May not be used by all build tools.
LocalRepo string
// BuildFile points to build tool-specific configuration file.
// May be a settings file or build definition depending on the build tool.
BuildFile string
// GlobalBuildFile points to build-tool specific global configuration file
// May be a settings file or build definition depending on the build tool.
GlobalBuildFile string
// Insecure allows insecure HTTPS connections when downloading dependencies.
// Should only be used in development/testing environments.
Insecure bool
// Version is the build tool version detected from the project.
// Used by some resolvers to determine compatibility requirements.
Version version.Version
// Wrapper is the absolute path to the build tool wrapper executable.
// Used by build tools that support wrapper scripts for reproducible builds.
Wrapper string
// JavaHome is the path to the Java installation to use for build tool execution.
// May be set based on build tool version requirements.
JavaHome string
// GradleTaskFile is the path to a custom task file for source download.
// Optional custom task file to use instead of embedded defaults.
GradleTaskFile string
// MavenIndexPath is the path to a Maven index for artifact metadata searches.
// Used to look up artifact information when identifying dependencies.
MavenIndexPath string
}
ResolverOptions contains configuration options for creating build tool-specific resolvers. Different resolvers use different subsets of these options based on their requirements.