added Load into compiler pipeline
This commit is contained in:
+3
-3
@@ -9,9 +9,9 @@ import java.nio.file.Path;
|
||||
@Builder
|
||||
@Getter
|
||||
public final class ProjectDescriptor {
|
||||
private final Path rootPath;
|
||||
private final String name;
|
||||
private final String version;
|
||||
private final Path rootPath; // canon root path
|
||||
private final String name; // project name
|
||||
private final String version; // project version
|
||||
private final ReadOnlyList<Path> sourceRoots;
|
||||
private final FrontendSpec frontendSpec;
|
||||
}
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
import p.studio.compiler.utilities.SourceProvider;
|
||||
import p.studio.compiler.utilities.SourceProviderFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
public class SourceHandle {
|
||||
@Getter
|
||||
private final ProjectId projectId;
|
||||
@EqualsAndHashCode.Include
|
||||
@Getter
|
||||
private final Path path; // canon path to file
|
||||
@Getter
|
||||
private final String filename;
|
||||
@Getter
|
||||
private final long size;
|
||||
@Getter
|
||||
private final long lastModified;
|
||||
private final SourceProvider provider;
|
||||
|
||||
public SourceHandle(
|
||||
final ProjectId projectId,
|
||||
final Path path,
|
||||
final long size,
|
||||
final long lastModified,
|
||||
final SourceProviderFactory factory) {
|
||||
this.projectId = projectId;
|
||||
this.path = path;
|
||||
this.filename = path.getFileName().toString();
|
||||
this.size = size;
|
||||
this.lastModified = lastModified;
|
||||
this.provider = factory.create(path);
|
||||
}
|
||||
|
||||
public byte[] readBytes() throws IOException {
|
||||
return provider.read();
|
||||
}
|
||||
|
||||
public String readUtf8() throws IOException {
|
||||
return new String(readBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package p.studio.compiler.source;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class SourceFile {
|
||||
private final ProjectId projectId;
|
||||
private final String module;
|
||||
private final String name;
|
||||
private final String extension;
|
||||
private final byte[] content;
|
||||
}
|
||||
+7
-6
@@ -1,13 +1,14 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import p.studio.compiler.source.SourceFile;
|
||||
import p.studio.compiler.models.SourceHandle;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FileTable extends InternTable<FileId, SourceFile> {
|
||||
public class FileTable extends InternTable<FileId, SourceHandle> {
|
||||
|
||||
private final Map<ProjectId, Set<FileId>> projectFiles = new HashMap<>();
|
||||
|
||||
@@ -16,17 +17,17 @@ public class FileTable extends InternTable<FileId, SourceFile> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileId register(final SourceFile value) {
|
||||
public FileId register(final SourceHandle value) {
|
||||
final var fileId = super.register(value);
|
||||
projectFiles.computeIfAbsent(value.getProjectId(), ignored -> new HashSet<>()).add(fileId);
|
||||
return fileId;
|
||||
}
|
||||
|
||||
public List<SourceFile> getSourceFiles(final ProjectId projectId) {
|
||||
public ReadOnlyList<FileId> getFiles(final ProjectId projectId) {
|
||||
final var fileIds = projectFiles.get(projectId);
|
||||
if (CollectionUtils.isEmpty(fileIds)) {
|
||||
return List.of();
|
||||
return ReadOnlyList.empty();
|
||||
}
|
||||
return fileIds.stream().map(this::get).toList();
|
||||
return ReadOnlyList.wrap(fileIds);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package p.studio.compiler.utilities;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SourceProvider {
|
||||
byte[] read() throws IOException;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package p.studio.compiler.utilities;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SourceProviderFactory {
|
||||
SourceProvider create(Path path);
|
||||
|
||||
static SourceProviderFactory filesystem() {
|
||||
return path -> new SourceProvider() {
|
||||
|
||||
private volatile byte[] cachedBytes = null;
|
||||
|
||||
@Override
|
||||
public byte[] read() throws IOException {
|
||||
if (Objects.isNull(cachedBytes)) {
|
||||
cachedBytes = Files.readAllBytes(path);
|
||||
}
|
||||
return cachedBytes;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// more providers can be added here, e.g., in-memory, etc.
|
||||
}
|
||||
Reference in New Issue
Block a user