more clean up, and improve FileTable
This commit is contained in:
-44
@@ -1,44 +0,0 @@
|
||||
package p.studio.compiler.dtos;
|
||||
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record PrometeuManifestDTO(
|
||||
String name,
|
||||
String version,
|
||||
String language,
|
||||
List<DependencyDeclaration> dependencies) {
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = DependencyDeclaration.Local.class),
|
||||
@JsonSubTypes.Type(value = DependencyDeclaration.Git.class)
|
||||
})
|
||||
public interface DependencyDeclaration {
|
||||
@Getter
|
||||
class Local implements DependencyDeclaration {
|
||||
private final String path;
|
||||
|
||||
@JsonCreator
|
||||
public Local(@JsonProperty("path") final String path) {
|
||||
this.path = path;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Getter
|
||||
class Git implements DependencyDeclaration {
|
||||
private final String url;
|
||||
private final String rev;
|
||||
|
||||
@JsonCreator
|
||||
public Git(@JsonProperty("url") final String url, @JsonProperty("rev") final String rev) {
|
||||
this.url = url;
|
||||
this.rev = rev;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
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 ReadOnlyList<Path> sourceRoots;
|
||||
private final FrontendSpec frontendSpec;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
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;
|
||||
}
|
||||
+23
-2
@@ -1,11 +1,32 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import p.studio.compiler.source.SourceFile;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
public class FileTable extends InternTable<FileId, SourceFile> {
|
||||
|
||||
private final Map<ProjectId, Set<FileId>> projectFiles = new HashMap<>();
|
||||
|
||||
public class FileTable extends InternTable<FileId, Path> {
|
||||
public FileTable() {
|
||||
super(FileId::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileId register(final SourceFile 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) {
|
||||
final var fileIds = projectFiles.get(projectId);
|
||||
if (CollectionUtils.isEmpty(fileIds)) {
|
||||
return List.of();
|
||||
}
|
||||
return fileIds.stream().map(this::get).toList();
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -2,9 +2,9 @@ package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.compiler.source.identifiers.SourceIdentifier;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class InternTable<IDENTIFIER extends SourceIdentifier, VALUE>
|
||||
@@ -21,8 +21,8 @@ public abstract class InternTable<IDENTIFIER extends SourceIdentifier, VALUE>
|
||||
return identifierByValue.computeIfAbsent(value, super::register);
|
||||
}
|
||||
|
||||
public IDENTIFIER get(final VALUE value) {
|
||||
return identifierByValue.get(value);
|
||||
public Optional<IDENTIFIER> optional(final VALUE value) {
|
||||
return Optional.ofNullable(identifierByValue.get(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+27
-1
@@ -1,11 +1,37 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.compiler.models.ProjectDescriptor;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ProjectTable extends DenseTable<ProjectId, ProjectDescriptor> {
|
||||
|
||||
private final Map<Path, ProjectId> projectIdByPath = new HashMap<>();
|
||||
|
||||
public class ProjectTable extends InternTable<ProjectId, Path> {
|
||||
public ProjectTable() {
|
||||
super(ProjectId::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectId register(final ProjectDescriptor value) {
|
||||
return projectIdByPath.computeIfAbsent(value.getRootPath(), ignored -> super.register(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
projectIdByPath.clear();
|
||||
}
|
||||
|
||||
public Optional<ProjectDescriptor> optional(Path pathCanon) {
|
||||
return optionalId(pathCanon).map(this::get);
|
||||
}
|
||||
|
||||
public Optional<ProjectId> optionalId(Path pathCanon) {
|
||||
return Optional.ofNullable(projectIdByPath.get(pathCanon));
|
||||
}
|
||||
}
|
||||
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package p.studio.compiler.utilities;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import p.studio.compiler.dtos.PrometeuManifestDTO;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class PrometeuManifestMapper {
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
public static PrometeuManifestDTO read(Path manifestPath) {
|
||||
try {
|
||||
return mapper.readValue(manifestPath.toFile(), PrometeuManifestDTO.class);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("failed to read manifest " + manifestPath, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user