49
49
import com .semmle .util .trap .dependencies .TrapSet ;
50
50
import com .semmle .util .trap .pathtransformers .PathTransformer ;
51
51
52
+ import com .github .codeql .Compression ;
53
+
52
54
public class OdasaOutput {
53
55
private final File trapFolder ;
54
56
private final File sourceArchiveFolder ;
@@ -63,16 +65,18 @@ public class OdasaOutput {
63
65
private final boolean trackClassOrigins ;
64
66
65
67
private final Logger log ;
68
+ private final Compression compression ;
66
69
67
70
/** DEBUG only: just use the given file as the root for TRAP, source archive etc */
68
- OdasaOutput (File outputRoot , Logger log ) {
71
+ OdasaOutput (File outputRoot , Compression compression , Logger log ) {
69
72
this .trapFolder = new File (outputRoot , "trap" );
70
73
this .sourceArchiveFolder = new File (outputRoot , "src_archive" );
71
74
this .trackClassOrigins = false ;
72
75
this .log = log ;
76
+ this .compression = compression ;
73
77
}
74
78
75
- public OdasaOutput (boolean trackClassOrigins , Logger log ) {
79
+ public OdasaOutput (boolean trackClassOrigins , Compression compression , Logger log ) {
76
80
String trapFolderVar = Env .systemEnv ().getFirstNonEmpty ("CODEQL_EXTRACTOR_JAVA_TRAP_DIR" , Var .TRAP_FOLDER .name ());
77
81
if (trapFolderVar == null ) {
78
82
throw new ResourceError ("CODEQL_EXTRACTOR_JAVA_TRAP_DIR was not set" );
@@ -85,6 +89,7 @@ public OdasaOutput(boolean trackClassOrigins, Logger log) {
85
89
this .sourceArchiveFolder = new File (sourceArchiveVar );
86
90
this .trackClassOrigins = trackClassOrigins ;
87
91
this .log = log ;
92
+ this .compression = compression ;
88
93
}
89
94
90
95
public File getTrapFolder () {
@@ -180,18 +185,18 @@ private File getTrapFileForJarFile(File jarFile) {
180
185
return null ;
181
186
return FileUtil .appendAbsolutePath (
182
187
currentSpecFileEntry .getTrapFolder (),
183
- JARS_DIR + "/" + PathTransformer .std ().fileAsDatabaseString (jarFile ) + ".trap.gz" );
188
+ JARS_DIR + "/" + PathTransformer .std ().fileAsDatabaseString (jarFile ) + ".trap" + compression . getExtension () );
184
189
}
185
190
186
191
private File getTrapFileForModule (String moduleName ) {
187
192
return FileUtil .appendAbsolutePath (
188
193
currentSpecFileEntry .getTrapFolder (),
189
- MODULES_DIR + "/" + moduleName + ".trap.gz" );
194
+ MODULES_DIR + "/" + moduleName + ".trap" + compression . getExtension () );
190
195
}
191
196
192
197
private File trapFileFor (File file ) {
193
198
return FileUtil .appendAbsolutePath (currentSpecFileEntry .getTrapFolder (),
194
- PathTransformer .std ().fileAsDatabaseString (file ) + ".trap.gz" );
199
+ PathTransformer .std ().fileAsDatabaseString (file ) + ".trap" + compression . getExtension () );
195
200
}
196
201
197
202
private File getTrapFileForDecl (IrElement sym , String signature ) {
@@ -214,7 +219,7 @@ private String trapFilePathForDecl(IrElement sym, String signature) {
214
219
binaryName .replace ('.' , '/' ) +
215
220
signature +
216
221
".members" +
217
- ".trap.gz" ;
222
+ ".trap" + compression . getExtension () ;
218
223
return result ;
219
224
}
220
225
@@ -245,7 +250,7 @@ private TrapFileManager getMembersWriterForDecl(File trap, File trapFileBase, Tr
245
250
// don't need to rewrite it only to rename it
246
251
// again.
247
252
File trapFileDir = trap .getParentFile ();
248
- File trapOld = new File (trapFileDir , trap .getName ().replace (".trap.gz" , ".trap-old.gz" ));
253
+ File trapOld = new File (trapFileDir , trap .getName ().replace (".trap" + compression . getExtension () , ".trap-old" + compression . getExtension () ));
249
254
if (trapOld .exists ()) {
250
255
log .trace ("Not rewriting trap file for " + trap .toString () + " as the trap-old exists" );
251
256
return null ;
@@ -272,7 +277,7 @@ private TrapFileManager getMembersWriterForDecl(File trap, File trapFileBase, Tr
272
277
}
273
278
274
279
private TrapFileManager trapWriter (File trapFile , IrElement sym , String signature ) {
275
- if (!trapFile .getName ().endsWith (".trap.gz" ))
280
+ if (!trapFile .getName ().endsWith (".trap" + compression . getExtension () ))
276
281
throw new CatastrophicError ("OdasaOutput only supports writing to compressed trap files" );
277
282
String relative = FileUtil .relativePath (trapFile , currentSpecFileEntry .getTrapFolder ());
278
283
trapFile .getParentFile ().mkdirs ();
@@ -321,7 +326,7 @@ public void close() {
321
326
writeTrapDependencies (trapDependenciesForClass );
322
327
}
323
328
private void writeTrapDependencies (TrapDependencies trapDependencies ) {
324
- String dep = trapDependencies .trapFile ().replace (".trap.gz" , ".dep" );
329
+ String dep = trapDependencies .trapFile ().replace (".trap" + compression . getExtension () , ".dep" );
325
330
trapDependencies .save (
326
331
currentSpecFileEntry .getTrapFolder ().toPath ().resolve (dep ));
327
332
}
@@ -335,7 +340,7 @@ public void setHasError() {
335
340
* Trap file locking.
336
341
*/
337
342
338
- private final Pattern selectClassVersionComponents = Pattern .compile ("(.*)#(-?[0-9]+)\\ .(-?[0-9]+)-(-?[0-9]+)-(.*)\\ .trap\\ .gz " );
343
+ private final Pattern selectClassVersionComponents = Pattern .compile ("(.*)#(-?[0-9]+)\\ .(-?[0-9]+)-(-?[0-9]+)-(.*)\\ .trap.* " );
339
344
340
345
/**
341
346
* <b>CAUTION</b>: to avoid the potential for deadlock between multiple concurrent extractor processes,
@@ -412,12 +417,12 @@ private TrapLocker(IrElement decl, String signature, boolean fromSource) {
412
417
trapFileVersion = new TrapClassVersion (0 , 0 , 0 , "kotlin" );
413
418
else
414
419
trapFileVersion = TrapClassVersion .fromSymbol (sym , log );
415
- String baseName = normalTrapFile .getName ().replace (".trap.gz" , "" );
420
+ String baseName = normalTrapFile .getName ().replace (".trap" + compression . getExtension () , "" );
416
421
// If a class has lots of inner classes, then we get lots of files
417
422
// in a single directory. This makes our directory listings later slow.
418
423
// To avoid this, rather than using files named .../Foo*, we use .../Foo/Foo*.
419
424
trapFileBase = new File (new File (normalTrapFile .getParentFile (), baseName ), baseName );
420
- trapFile = new File (trapFileBase .getPath () + '#' + trapFileVersion .toString () + ".trap.gz" );
425
+ trapFile = new File (trapFileBase .getPath () + '#' + trapFileVersion .toString () + ".trap" + compression . getExtension () );
421
426
}
422
427
}
423
428
private TrapLocker (File jarFile ) {
@@ -488,7 +493,7 @@ public int compare(Pair<File, TrapClassVersion> p1, Pair<File, TrapClassVersion>
488
493
for (Pair <File , TrapClassVersion > p : pairs ) {
489
494
if (!latestVersion .equals (p .snd ())) {
490
495
File f = p .fst ();
491
- File fOld = new File (f .getParentFile (), f .getName ().replace (".trap.gz" , ".trap-old.gz" ));
496
+ File fOld = new File (f .getParentFile (), f .getName ().replace (".trap" + compression . getExtension () , ".trap-old" + compression . getExtension () ));
492
497
// We aren't interested in whether or not this succeeds;
493
498
// it may fail because a concurrent extractor has already
494
499
// renamed it.
0 commit comments