@@ -101,26 +101,6 @@ class KotlinExtractorExtension(
101101 val usesK2 = usesK2(pluginContext)
102102 // This default should be kept in sync with com.semmle.extractor.java.interceptors.KotlinInterceptor.initializeExtractionContext
103103 val trapDir = File (System .getenv(" CODEQL_EXTRACTOR_JAVA_TRAP_DIR" ).takeUnless { it.isNullOrEmpty() } ? : " kotlin-extractor/trap" )
104- val compression_env_var = " CODEQL_EXTRACTOR_JAVA_OPTION_TRAP_COMPRESSION"
105- val compression_option = System .getenv(compression_env_var)
106- val defaultCompression = Compression .GZIP
107- val (compression, compressionWarning) =
108- if (compression_option == null ) {
109- Pair (defaultCompression, null )
110- } else {
111- try {
112- @OptIn(kotlin.ExperimentalStdlibApi ::class ) // Annotation required by kotlin versions < 1.5
113- val compression_option_upper = compression_option.uppercase()
114- if (compression_option_upper == " BROTLI" ) {
115- Pair (Compression .GZIP , " Kotlin extractor doesn't support Brotli compression. Using GZip instead." )
116- } else {
117- Pair (Compression .valueOf(compression_option_upper), null )
118- }
119- } catch (e: IllegalArgumentException ) {
120- Pair (defaultCompression,
121- " Unsupported compression type (\$ $compression_env_var ) \" $compression_option \" . Supported values are ${Compression .values().joinToString()} " )
122- }
123- }
124104 // The invocation TRAP file will already have been started
125105 // before the plugin is run, so we always use no compression
126106 // and we open it in append mode.
@@ -152,9 +132,7 @@ class KotlinExtractorExtension(
152132 if (System .getenv(" CODEQL_EXTRACTOR_JAVA_KOTLIN_DUMP" ) == " true" ) {
153133 logger.info(" moduleFragment:\n " + moduleFragment.dump())
154134 }
155- if (compressionWarning != null ) {
156- logger.warn(compressionWarning)
157- }
135+ val compression = getCompression(logger)
158136
159137 val primitiveTypeMapping = PrimitiveTypeMapping (logger, pluginContext)
160138 // FIXME: FileUtil expects a static global logger
@@ -182,6 +160,29 @@ class KotlinExtractorExtension(
182160 }
183161 }
184162
163+ private fun getCompression (logger : Logger ): Compression {
164+ val compression_env_var = " CODEQL_EXTRACTOR_JAVA_OPTION_TRAP_COMPRESSION"
165+ val compression_option = System .getenv(compression_env_var)
166+ val defaultCompression = Compression .GZIP
167+ if (compression_option == null ) {
168+ return defaultCompression
169+ } else {
170+ try {
171+ @OptIn(kotlin.ExperimentalStdlibApi ::class ) // Annotation required by kotlin versions < 1.5
172+ val compression_option_upper = compression_option.uppercase()
173+ if (compression_option_upper == " BROTLI" ) {
174+ logger.warn(" Kotlin extractor doesn't support Brotli compression. Using GZip instead." )
175+ return Compression .GZIP
176+ } else {
177+ return Compression .valueOf(compression_option_upper)
178+ }
179+ } catch (e: IllegalArgumentException ) {
180+ logger.warn(" Unsupported compression type (\$ $compression_env_var ) \" $compression_option \" . Supported values are ${Compression .values().joinToString()} ." )
181+ return defaultCompression
182+ }
183+ }
184+ }
185+
185186 private fun logPeakMemoryUsage (logger : Logger , time : String ) {
186187 logger.info(" Peak memory: Usage $time " )
187188
0 commit comments