8000 Cache annotation processor classpaths in repository storage dir · sakerbuild/saker.java.compiler@a91fb78 · GitHub
[go: up one dir, main page]

Skip to content

Commit a91fb78

Browse files
committed
Cache annotation processor classpaths in repository storage dir
The input classpaths from where the saker.java.processor task loads the annotation processors are cached in the storage directory associated with the saker.java.compiler package. See issue #1
1 parent d31023d commit a91fb78

File tree

3 files changed

+679
-325
lines changed

3 files changed

+679
-325
lines changed

impl/src/main/saker/java/compiler/impl/JavaTaskUtils.java

Lines changed: 1 addition & 188 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@
1616
package saker.java.compiler.impl;
1717

1818
import java.io.Externalizable;
19-
import java.io.FileNotFoundException;
2019
import java.io.IOException;
2120
import java.io.ObjectInput;
2221
import java.io.ObjectOutput;
2322
import java.util.Collection;
2423
import java.util.Collections;
2524
import java.util.Comparator;
2625
import java.util.HashSet;
27-
import java.util.LinkedHashMap;
2826
import java.util.LinkedHashSet;
2927
import java.util.List;
30-
import java.util.Map;
3128
import java.util.Map.Entry;
3229
import java.util.NavigableMap;
3330
import java.util.NavigableSet;
@@ -36,27 +33,15 @@
3633
import java.util.TreeSet;
3734
import java.util.function.Function;
3835

39< 8000 /code>-
import saker.build.file.SakerDirectory;
40-
import saker.build.file.SakerFile;
4136
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;
4537
import saker.build.file.path.SakerPath;
4638
import saker.build.file.provider.FileEntry;
4739
import saker.build.file.provider.LocalFileProvider;
48-
import saker.build.file.provider.SakerPathFiles;
4940
import saker.build.runtime.execution.ExecutionContext;
5041
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;
5542
import saker.build.task.dependencies.CommonTaskOutputChangeDetector;
56-
import saker.build.task.dependencies.FileCollectionStrategy;
5743
import saker.build.task.dependencies.TaskOutputChangeDetector;
5844
import saker.build.task.identifier.TaskIdentifier;
59-
import saker.build.task.utils.dependencies.RecursiveIgnoreCaseExtensionFileCollectionStrategy;
6045
import saker.build.thirdparty.org.objectweb.asm.ClassReader;
6146
import saker.build.thirdparty.org.objectweb.asm.ClassVisitor;
6247
import saker.build.thirdparty.org.objectweb.asm.ModuleVisitor;
@@ -67,28 +52,11 @@
6752
import saker.build.thirdparty.saker.util.io.ByteArrayRegion;
6853
import saker.build.thirdparty.saker.util.io.FileUtils;
6954
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;
7855
import saker.java.compiler.api.compile.JavaCompilationWorkerTaskIdentifier;
79-
import saker.java.compiler.api.compile.JavaCompilerWorkerTaskOutput;
8056
import saker.java.compiler.api.compile.SakerJavaCompilerUtils;
8157
import saker.java.compiler.api.option.JavaAddExports;
82-
import saker.java.compiler.impl.JavaTaskUtils.LocalDirectoryClassFilesExecutionProperty.PropertyValue;
8358
import saker.java.compiler.impl.compile.InternalJavaCompilerOutput;
8459
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;
9260

9361
public class JavaTaskUtils {
9462
public static final String EXTENSION_CLASSFILE = "class";
@@ -217,162 +185,7 @@ public static Collection<String> toAddExportsCommandLineStrings(JavaAddExports a
217185
return SakerJavaCompilerUtils.toAddExportsCommandLineStrings(addexports);
218186
}
219187

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(cla F438 ssdirpath, "." + 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-
}
188+
376189

377190
public static class LocalDirectoryClassFilesExecutionProperty
378191
implements ExecutionProperty<LocalDirectoryClassFilesExecutionProperty.PropertyValue>, Externalizable {

0 commit comments

Comments
 (0)
0