16
16
package saker .java .compiler .impl ;
17
17
18
18
import java .io .Externalizable ;
19
- import java .io .FileNotFoundException ;
20
19
import java .io .IOException ;
21
20
import java .io .ObjectInput ;
22
21
import java .io .ObjectOutput ;
23
22
import java .util .Collection ;
24
23
import java .util .Collections ;
25
24
import java .util .Comparator ;
26
25
import java .util .HashSet ;
27
- import java .util .LinkedHashMap ;
28
26
import java .util .LinkedHashSet ;
29
27
import java .util .List ;
30
- import java .util .Map ;
31
28
import java .util .Map .Entry ;
32
29
import java .util .NavigableMap ;
33
30
import java .util .NavigableSet ;
36
33
import java .util .TreeSet ;
37
34
import java .util .function .Function ;
38
35
39
- import saker .build .file .SakerDirectory ;
40
- import saker .build .file .SakerFile ;
41
36
import saker .build .file .content .ContentDescriptor ;
42
- import saker .build .file .content .DirectoryContentDescriptor ;
43
- import saker .build .file .content .MultiPathContentDescriptor ;
44
- import saker .build .file .content .SerializableContentDescriptor ;
45
37
import saker .build .file .path .SakerPath ;
46
38
import saker .build .file .provider .FileEntry ;
47
39
import saker .build .file .provider .LocalFileProvider ;
48
- import saker .build .file .provider .SakerPathFiles ;
49
40
import saker .build .runtime .execution .ExecutionContext ;
50
41
import saker .build .runtime .execution .ExecutionProperty ;
51
- import saker .build .runtime .execution .SakerLog ;
52
- import saker .build .task .TaskContext ;
53
- import saker .build .task .TaskDependencyFuture ;
54
- import saker .build .task .TaskExecutionUtilities ;
55
42
import saker .build .task .dependencies .CommonTaskOutputChangeDetector ;
56
- import saker .build .task .dependencies .FileCollectionStrategy ;
57
43
import saker .build .task .dependencies .TaskOutputChangeDetector ;
58
44
import saker .build .task .identifier .TaskIdentifier ;
59
- import saker .build .task .utils .dependencies .RecursiveIgnoreCaseExtensionFileCollectionStrategy ;
60
45
import saker .build .thirdparty .org .objectweb .asm .ClassReader ;
61
46
import saker .build .thirdparty .org .objectweb .asm .ClassVisitor ;
62
47
import saker .build .thirdparty .org .objectweb .asm .ModuleVisitor ;
67
52
import saker .build .thirdparty .saker .util .io .ByteArrayRegion ;
68
53
import saker .build .thirdparty .saker .util .io .FileUtils ;
69
54
import saker .build .thirdparty .saker .util .io .SerialUtils ;
70
- import saker .java .compiler .api .classpath .ClassPathEntry ;
71
- import saker .java .compiler .api .classpath .ClassPathReference ;
72
- import saker .java .compiler .api .classpath .ClassPathVisitor ;
73
- import saker .java .compiler .api .classpath .CompilationClassPath ;
74
- import saker .java .compiler .api .classpath .FileClassPath ;
75
- import saker .java .compiler .api .classpath .JavaClassPath ;
76
- import saker .java .compiler .api .classpath .JavaClassPathBuilder ;
77
- import saker .java .compiler .api .classpath .SDKClassPath ;
78
55
import saker .java .compiler .api .compile .JavaCompilationWorkerTaskIdentifier ;
79
- import saker .java .compiler .api .compile .JavaCompilerWorkerTaskOutput ;
80
56
import saker .java .compiler .api .compile .SakerJavaCompilerUtils ;
81
57
import saker .java .compiler .api .option .JavaAddExports ;
82
- import saker .java .compiler .impl .JavaTaskUtils .LocalDirectoryClassFilesExecutionProperty .PropertyValue ;
83
58
import saker .java .compiler .impl .compile .InternalJavaCompilerOutput ;
84
59
import saker .java .compiler .impl .compile .util .LocalPathFileContentDescriptorExecutionProperty ;
85
- import saker .sdk .support .api .SDKPathReference ;
86
- import saker .sdk .support .api .SDKReference ;
87
- import saker .sdk .support .api .SDKSupportUtils ;
88
- import saker .std .api .file .location .ExecutionFileLocation ;
89
- import saker .std .api .file .location .FileLocation ;
90
- import saker .std .api .file .location .FileLocationVisitor ;
91
- import saker .std .api .file .location .LocalFileLocation ;
92
60
93
61
public class JavaTaskUtils {
94
62
public static final String EXTENSION_CLASSFILE = "class" ;
@@ -217,163 +185,6 @@ public static Collection<String> toAddExportsCommandLineStrings(JavaAddExports a
217
185
return SakerJavaCompilerUtils .toAddExportsCommandLineStrings (addexports );
218
186
}
219
187
220
- /**
221
- * @return The content descriptors may be <code>null</code>.
222
- */
223
- public static Map <FileLocation , ContentDescriptor > collectFileLocationsWithImplementationDependencyReporting (
224
- TaskContext taskcontext , JavaClassPath classpath , Object tag , Map <String , SDKReference > sdks ,
225
- Function <ClassPathEntry , FileLocation > classpathentryfilelocationhandler ) throws IOException {
226
- if (classpath == null ) {
227
- return Collections .emptyMap ();
228
- }
229
- Map <FileLocation , ContentDescriptor > result = new LinkedHashMap <>();
230
- classpath .accept (new ClassPathVisitor () {
231
- private Set <JavaCompilationWorkerTaskIdentifier > handledWorkerTaskIds = new HashSet <>();
232
-
233
- @ Override
234
- public void visit (ClassPathReference classpath ) {
235
- Collection <? extends ClassPathEntry > entries = classpath .getEntries ();
236
- if (ObjectUtils .isNullOrEmpty (entries )) {
237
- SakerLog .warning ().println ("No class path entries found for: " + classpath );
238
- return ;
239
- }
240
- for (ClassPathEntry entry : entries ) {
241
- if (entry == null ) {
242
- SakerLog .warning ().println ("Class path entry is null for: " + classpath );
243
- continue ;
244
- }
245
- FileLocation filelocation = classpathentryfilelocationhandler .apply (entry );
246
- if (filelocation == null ) {
247
- SakerLog .warning ().println ("No class path file location for: " + entry );
248
- continue ;
249
- }
250
- handleFileLocation (filelocation );
251
-
252
- Collection <? extends ClassPathReference > additionalclasspaths = entry
253
- .getAdditionalClassPathReferences ();
254
- if (!ObjectUtils .isNullOrEmpty (additionalclasspaths )) {
255
- JavaClassPathBuilder additionalcpbuilder = JavaClassPathBuilder .newBuilder ();
256
- for (ClassPathReference additionalcp : additionalclasspaths ) {
257
- additionalcpbuilder .addClassPath (additionalcp );
258
- }
259
- JavaClassPath additionalcp = additionalcpbuilder .build ();
260
- additionalcp .accept (this );
261
- }
262
- }
263
- }
264
-
265
- @ Override
266
- public void visit (CompilationClassPath classpath ) {
267
- JavaCompilationWorkerTaskIdentifier workertaskid = classpath .getCompilationWorkerTaskIdentifier ();
268
- if (!handledWorkerTaskIds .add (workertaskid )) {
269
- //don't get the task result to not install another dependency
270
- return ;
271
- }
272
- TaskDependencyFuture <?> depresult = taskcontext .getTaskDependencyFuture (workertaskid );
273
- JavaCompilerWorkerTaskOutput output = (JavaCompilerWorkerTaskOutput ) depresult .getFinished ();
274
- SakerPath classdirpath = output .getClassDirectory ();
275
- ExecutionFileLocation filelocation = ExecutionFileLocation .create (classdirpath );
276
- JavaClassPath outputcp = output .getClassPath ();
277
-
278
- Object implversionkey = output .getImplementationVersionKey ();
279
- if (implversionkey != null ) {
280
- depresult .setTaskOutputChangeDetector (SakerJavaCompilerUtils
281
- .getCompilerOutputImplementationVersionKeyTaskOutputChangeDetector (implversionkey ));
282
- depresult .setTaskOutputChangeDetector (
283
- SakerJavaCompilerUtils .getCompilerOutputClassPathTaskOutputChangeDetector (outputcp ));
284
- result .put (filelocation , new SerializableContentDescriptor (implversionkey ));
285
- } else {
286
- SakerDirectory classesdir = taskcontext .getTaskUtilities ().resolveDirectoryAtPath (classdirpath );
287
- if (classesdir == null ) {
288
- throw ObjectUtils .sneakyThrow (
289
- new FileNotFoundException ("Compilation class directory not found: " + classesdir ));
290
- }
291
-
292
- FileCollectionStrategy classfileadditiondep = RecursiveIgnoreCaseExtensionFileCollectionStrategy
293
- .create (classdirpath , "." + EXTENSION_CLASSFILE );
294
- NavigableMap <SakerPath , SakerFile > classfiles = taskcontext .getTaskUtilities ()
295
- .collectFilesReportInputFileAndAdditionDependency (tag , classfileadditiondep );
296
-
297
- NavigableMap <SakerPath , ContentDescriptor > contentmap = SakerPathFiles .toFileContentMap (classfiles );
298
- result .put (filelocation , new MultiPathContentDescriptor (contentmap ));
299
- }
300
- if (outputcp != null ) {
301
- outputcp .accept (this );
302
- }
303
- }
304
-
305
- @ Override
306
- public void visit (FileClassPath classpath ) {
307
- FileLocation location = classpath .getFileLocation ();
308
- handleFileLocation (location );
309
- }
310
-
311
- @ Override
312
- public void visit (SDKClassPath classpath ) {
313
- SDKPathReference sdkpathref = classpath .getSDKPathReference ();
314
- SakerPath path = SDKSupportUtils .getSDKPathReferencePath (sdkpathref , sdks );
315
- LocalFileLocation fileloc = LocalFileLocation .create (path );
316
- result .put (fileloc , null );
317
- }
318
-
319
- private ContentDescriptor handleExecutionFileLocation (SakerPath path , SakerFile cpfile ) {
320
- if (cpfile instanceof SakerDirectory ) {
321
- FileCollectionStrategy classfileadditiondep = RecursiveIgnoreCaseExtensionFileCollectionStrategy
322
- .create (path , "." + EXTENSION_CLASSFILE );
323
- NavigableMap <SakerPath , SakerFile > classfiles = taskcontext .getTaskUtilities ()
324
- .collectFilesReportInputFileAndAdditionDependency (tag , classfileadditiondep );
325
- return new MultiPathContentDescriptor (SakerPathFiles .toFileContentMap (classfiles ));
326
- }
327
- taskcontext .getTaskUtilities ().reportInputFileDependency (tag , cpfile );
328
- return cpfile .getContentDescriptor ();
329
- }
330
-
331
- private void handleFileLocation (FileLocation location ) {
332
- if (result .containsKey (location )) {
333
- return ;
334
- }
335
- ContentDescriptor [] cdres = { null };
336
- location .accept (new FileLocationVisitor () {
337
- @ Override
338
- public void visit (ExecutionFileLocation loc ) {
339
- SakerPath path = loc .getPath ();
340
- SakerFile cpfile = taskcontext .getTaskUtilities ().resolveAtPath (path );
341
- if (cpfile == null ) {
342
- throw ObjectUtils
343
- .sneakyThrow (new FileNotFoundException ("Class path file not found: " + path ));
344
- }
345
- cdres [0 ] = handleExecutionFileLocation (path , cpfile );
346
- }
347
-
348
- @ Override
349
- public void visit (LocalFileLocation loc ) {
350
- SakerPath path = loc .getLocalPath ();
351
- TaskExecutionUtilities taskutils = taskcontext .getTaskUtilities ();
352
- ContentDescriptor cd = taskutils .getReportExecutionDependency (
353
- new LocalPathFileContentDescriptorExecutionProperty (path ));
354
- if (cd == null ) {
355
- throw ObjectUtils
356
- .sneakyThrow (new FileNotFoundException ("Class path local file not found: " + path ));
357
- }
358
-
359
- if (DirectoryContentDescriptor .INSTANCE .equals (cd )) {
360
- //the class path denotes a directory
361
- //add the dependencies on the class files
362
-
363
- PropertyValue pval = taskutils
364
- .getReportExecutionDependency (new LocalDirectoryClassFilesExecutionProperty (path ));
365
- cdres [0 ] = new MultiPathContentDescriptor (pval .getContents ());
366
- } else {
367
- cdres [0 ] = cd ;
368
- }
369
- }
370
- });
371
- result .put (location , cdres [0 ]);
372
- }
373
- });
374
- return result ;
375
- }
376
-
377
188
public static class LocalDirectoryClassFilesExecutionProperty
378
189
implements ExecutionProperty <LocalDirectoryClassFilesExecutionProperty .PropertyValue >, Externalizable {
379
190
private static final long serialVersionUID = 1L ;
@@ -438,6 +249,7 @@ public String toString() {
438
249
439
250
}
440
251
252
+ private TaskIdentifier associatedTaskId ;
441
253
private SakerPath path ;
442
254
443
255
/**
@@ -446,7 +258,8 @@ public String toString() {
446
258
public LocalDirectoryClassFilesExecutionProperty () {
447
259
}
448
260
449
- public LocalDirectoryClassFilesExecutionProperty (SakerPath path ) {
261
+ public LocalDirectoryClassFilesExecutionProperty (TaskIdentifier associatedTaskId , SakerPath path ) {
262
+ this .associatedTaskId = associatedTaskId ;
450
263
this .path = path ;
451
264
}
452
265
@@ -465,7 +278,7 @@ public PropertyValue getCurrentValue(ExecutionContext executioncontext) throws E
465
278
}
466
279
SakerPath cpabspath = path .resolve (keypath );
467
280
ContentDescriptor classfilecd = executioncontext .getExecutionPropertyCurrentValue (
468
- new LocalPathFileContentDescriptorExecutionProperty (cpabspath ));
281
+ new LocalPathFileContentDescriptorExecutionProperty (associatedTaskId , cpabspath ));
469
282
if (classfilecd == null ) {
470
283
continue ;
471
284
}
@@ -476,18 +289,21 @@ public PropertyValue getCurrentValue(ExecutionContext executioncontext) throws E
476
289
477
290
@ Override
478
291
public void writeExternal (ObjectOutput out ) throws IOException {
292
+ out .writeObject (associatedTaskId );
479
293
out .writeObject (path );
480
294
}
481
295
482
296
@ Override
483
297
public void readExternal (ObjectInput in ) throws IOException , ClassNotFoundException {
298
+ associatedTaskId = (TaskIdentifier ) in .readObject ();
484
299
path = (SakerPath ) in .readObject ();
485
300
}
486
301
487
302
@ Override
488
303
public int hashCode () {
489
304
final int prime = 31 ;
490
305
int result = 1 ;
306
+ result = prime * result + ((associatedTaskId == null ) ? 0 : associatedTaskId .hashCode ());
491
307
result = prime * result + ((path == null ) ? 0 : path .hashCode ());
492
308
return result ;
493
309
}
@@ -501,6 +317,11 @@ public boolean equals(Object obj) {
501
317
if (getClass () != obj .getClass ())
502
318
return false ;
503
319
LocalDirectoryClassFilesExecutionProperty other = (LocalDirectoryClassFilesExecutionProperty ) obj ;
320
+ if (associatedTaskId == null ) {
321
+ if (other .associatedTaskId != null )
322
+ return false ;
323
+ } else if (!associatedTaskId .equals (other .associatedTaskId ))
324
+ return false ;
504
325
if (path == null ) {
505
326
if (other .path != null )
506
327
return false ;
0 commit comments