|
14 | 14 | from ..constants import DEFAULT_JGO_CACHE |
15 | 15 | from ..parse.coordinate import Coordinate |
16 | 16 | from .bytecode import detect_jar_java_version |
17 | | -from .cache import write_metadata_cache |
| 17 | +from .cache import is_cache_valid, read_metadata_cache, write_metadata_cache |
18 | 18 | from .environment import Environment |
19 | 19 | from .jar import ( |
| 20 | + ModuleInfo, |
20 | 21 | autocomplete_main_class, |
21 | 22 | classify_jar, |
22 | 23 | detect_main_class_from_jar, |
@@ -875,45 +876,68 @@ def process_artifact(artifact, source_path): |
875 | 876 | # Compute SHA256 first (needed for cache and lockfile) |
876 | 877 | sha256 = compute_sha256(source_path) if source_path.exists() else None |
877 | 878 |
|
878 | | - # Detect minimum Java version from bytecode |
879 | | - min_java_ver = detect_jar_java_version(source_path) |
880 | | - |
881 | | - # Use fast module detection (no subprocess) |
882 | | - module_info = detect_module_info(source_path) |
883 | | - |
884 | | - # Get jar tool lazily only when we need it |
885 | | - jar_tool = get_jar_tool_lazy() |
886 | | - |
887 | | - if jar_tool: |
888 | | - # Baseline jar tool available - use precise classification |
889 | | - if module_info.is_modular: |
890 | | - # Fast path: JAR has module-info.class or Automatic-Module-Name |
891 | | - # Type 1: Has module-info.class (not automatic) |
892 | | - # Type 2: Has Automatic-Module-Name (is automatic) |
893 | | - jar_type = 2 if module_info.is_automatic else 1 |
894 | | - else: |
895 | | - # Slow path: Need subprocess to distinguish type 3 vs 4 |
896 | | - _log.debug( |
897 | | - f"Analyzing JAR for modularizability: {artifact.filename}" |
898 | | - ) |
899 | | - jar_type = classify_jar(source_path, jar_tool) |
900 | | - else: |
901 | | - # No jar tool available - use simple module detection |
902 | | - jar_type = None # Not classified |
903 | | - |
904 | | - # Write to cache for next time |
| 879 | + # Try to read from metadata cache first |
| 880 | + cached_metadata = None |
905 | 881 | if sha256: |
906 | | - write_metadata_cache( |
| 882 | + cached_metadata = read_metadata_cache( |
907 | 883 | artifact.groupId, |
908 | 884 | artifact.artifactId, |
909 | 885 | artifact.version, |
910 | 886 | artifact.filename, |
911 | 887 | self.cache_dir, |
912 | | - sha256, |
913 | | - jar_type, |
914 | | - min_java_ver, |
915 | | - module_info, |
916 | 888 | ) |
| 889 | + # Validate cache by SHA256 |
| 890 | + if cached_metadata and is_cache_valid(cached_metadata, sha256): |
| 891 | + # Cache hit! Use cached values |
| 892 | + min_java_ver = cached_metadata.min_java_version |
| 893 | + jar_type = cached_metadata.jar_type |
| 894 | + module_info = ModuleInfo(**cached_metadata.module_info) |
| 895 | + _log.debug(f"Using cached metadata for {artifact.filename}") |
| 896 | + else: |
| 897 | + # Cache miss or invalid - will compute below |
| 898 | + cached_metadata = None |
| 899 | + |
| 900 | + # If we didn't get valid cached data, compute it now |
| 901 | + if cached_metadata is None: |
| 902 | + # Detect minimum Java version from bytecode |
| 903 | + min_java_ver = detect_jar_java_version(source_path) |
| 904 | + |
| 905 | + # Use fast module detection (no subprocess) |
| 906 | + module_info = detect_module_info(source_path) |
| 907 | + |
| 908 | + # Get jar tool lazily only when we need it |
| 909 | + jar_tool = get_jar_tool_lazy() |
| 910 | + |
| 911 | + if jar_tool: |
| 912 | + # Baseline jar tool available - use precise classification |
| 913 | + if module_info.is_modular: |
| 914 | + # Fast path: JAR has module-info.class or Automatic-Module-Name |
| 915 | + # Type 1: Has module-info.class (not automatic) |
| 916 | + # Type 2: Has Automatic-Module-Name (is automatic) |
| 917 | + jar_type = 2 if module_info.is_automatic else 1 |
| 918 | + else: |
| 919 | + # Slow path: Need subprocess to distinguish type 3 vs 4 |
| 920 | + _log.debug( |
| 921 | + f"Analyzing JAR for modularizability: {artifact.filename}" |
| 922 | + ) |
| 923 | + jar_type = classify_jar(source_path, jar_tool) |
| 924 | + else: |
| 925 | + # No jar tool available - use simple module detection |
| 926 | + jar_type = None # Not classified |
| 927 | + |
| 928 | + # Write to cache for next time |
| 929 | + if sha256: |
| 930 | + write_metadata_cache( |
| 931 | + artifact.groupId, |
| 932 | + artifact.artifactId, |
| 933 | + artifact.version, |
| 934 | + artifact.filename, |
| 935 | + self.cache_dir, |
| 936 | + sha256, |
| 937 | + jar_type, |
| 938 | + min_java_ver, |
| 939 | + module_info, |
| 940 | + ) |
917 | 941 |
|
918 | 942 | # Determine target directory based on jar_type |
919 | 943 | if jar_type is not None: |
|
0 commit comments