Skip to content

Commit

Permalink
WIP Next Phase...
Browse files Browse the repository at this point in the history
This includes only indirectly related work, such as:

* Add check-jsonschema pre-commit
  • Loading branch information
vorburger committed Feb 7, 2024
1 parent 5f7f8b7 commit ac92587
Show file tree
Hide file tree
Showing 50 changed files with 4,602 additions and 46 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
common --enable_bzlmod
common --extra_toolchains=@local_jdk//:all

# Java version must match .devcontainer/devcontainer.json
# https://bazel.build/docs/bazel-and-java#java-versions
build --java_language_version=21
build --tool_java_language_version=21
Expand Down
16 changes: 9 additions & 7 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
{
"name": "Enola.dev's Dev Containers.dev",

// TODO Define, build and use a Dev. Env. Dockerfile (see https://containers.dev/guide/dockerfile),
// to make it easy to use the required tools even outside of DevContainers in Codespaces!
// (And integrate onCreateCommand and features into that container, and documents its use.)

// This is the "fat" container with a lot of ready tools
// from https://github.com/devcontainers/images/tree/main/src/universal
"image": "mcr.microsoft.com/devcontainers/universal:2-linux",
//
// "image": "mcr.microsoft.com/devcontainers/base:bookworm"
// from https://github.com/devcontainers/images/tree/main/src/base-debian
// from https://github.com/devcontainers/templates/tree/main/src/debian
// is very minimal, and we would need to add a lot...
//
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile

// https://containers.dev/implementors/json_reference/#lifecycle-scripts
// is what you want, NOT features' "ghcr.io/devcontainers-contrib/features/bash-command:1"
Expand All @@ -20,8 +17,13 @@

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
// Java version must match .bazelrc
"ghcr.io/devcontainers/features/java:1": {
"version": "21"
},
// protoc is used by tools/protoc/protoc.bash
"ghcr.io/devcontainers-contrib/features/protoc-asdf:1": {
"version": "3.6.1"
}
},

Expand Down
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ tab_width = unset
[*.json]
indent_size = 2
tab_width = 2
max_line_length = unset

[*.jsonc]
indent_size = 2
tab_width = 2
max_line_length = unset

[*.json5]
indent_size = 2
tab_width = 2
max_line_length = unset

[*.toml]
indent_size = 2
Expand Down
39 changes: 35 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,44 @@ repos:
hooks:
- id: csslint

# https://editorconfig.org check should run AFTER all of the formatters (above)
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 2.7.3
# https://yamllint.readthedocs.io/en/stable/integration.html#integration-with-pre-commit
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.33.0
hooks:
- id: editorconfig-checker
- id: yamllint
# https://yamllint.readthedocs.io/en/stable/configuration.html#errors-and-warnings
args: [--strict]

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.6
hooks:
- id: shellcheck

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.3
hooks:
- id: check-github-actions
args: ["--verbose"]
- id: check-github-workflows
args: ["--verbose"]
- id: check-dependabot
args: ["--verbose"]
- id: check-renovate
args: ["--verbose"]
- id: check-metaschema
files: \.schema\.json$
args: ["--verbose"]
# TODO Change once https://github.com/python-jsonschema/check-jsonschema/issues/340 is implemented
- id: check-jsonschema
# files: .+/models/.+\.(yaml|json)$
files: \.types\.yaml$
args: ["--verbose", "--schemafile", "docs/models/enola/schemas/Types.schema.json"]
- id: check-jsonschema
files: \.type\.yaml$
args: ["--verbose", "--schemafile", "docs/models/enola/schemas/Type.schema.json"]

# https://editorconfig.org check should run AFTER all of the formatters (above)
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 2.7.3
hooks:
- id: editorconfig-checker
42 changes: 30 additions & 12 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
"bazel.buildifierFixOnFormat": true,
"bazel.enableCodeLens": true,
"bazel.executable": "bazelisk",
"bazel.projectview.open": false,
// https://github.com/bazelbuild/vscode-bazel/issues/216
// https://github.com/bazelbuild/vscode-bazel/issues/223
// https://github.com/bazelbuild/vscode-bazel/issues/261
"bazel.projectview.open": false,
"bazel.queriesShareServer": true,

"cSpell.words": ["Bazel", "bazelisk", "Classpath", "Enola", "Intelli", "protolint", "textproto"],
"cSpell.words": [
"Bazel",
"bazelisk",
"Classpath",
"Enola",
"Intelli",
"protolint",
"textproto"
],

"editor.formatOnType": true,
"editor.formatOnSave": true,
Expand All @@ -28,6 +36,9 @@
"[markdown]": {
"editor.defaultFormatter": "DavidAnson.vscode-markdownlint"
},
// TODO change to 'smartWithSelection' when it works better?
// https://code.visualstudio.com/updates/v1_86#_languages
"markdown.editor.pasteUrlAsFormattedLink.enabled": "never",
"markdown.validate.fileLinks.enabled": "error",
"markdown.validate.enabled": true,
"markdown.validate.fragmentLinks.enabled": "error",
Expand All @@ -41,6 +52,9 @@

"java.completion.importOrder": ["#", "", "javax", "java"], //# is static
"java.format.settings.google.extra": "--aosp", // For 4 instead of 2 spaces!
// Keep this version in sync with the same version in .pre-commit-config.yaml
// NB: Changes to this are only taken into account on start-up, so need to restart.
"java.format.settings.google.version": "1.19.2",
"[java]": {
"editor.tabSize": 4,
// Format Java using https://github.com/google/google-java-format,
Expand All @@ -52,18 +66,22 @@
"source.addMissingImports": "never"
}
},
// Keep this version in sync with the same version in .pre-commit-config.yaml
// NB: Changes to this are only taken into account on start-up, so need to restart.
"java.format.settings.google.version": "1.19.2",
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.updateBuildConfiguration": "automatic",
"java.server.launchMode": "Standard",
"java": {
"completion.favoriteStaticMembers": ["com.google.common.truth.Truth.*"]
},

"[json5]": {
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},

"[proto3]": {
"editor.defaultFormatter": "zxh404.vscode-proto3"
},

// https://squidfunk.github.io/mkdocs-material/creating-your-site/#configuration
"yaml.schemas": {
"https://squidfunk.github.io/mkdocs-material/schema.json": "mkdocs.yaml"
Expand All @@ -87,33 +105,33 @@
"**/.factorypath": true,
"**/.project": true,
"**/.settings": true,
"**/*.crswap": true,
"**/eclipse-bin/": true,
"**/eclipse-testbin/": true,
"**/.bazeltargets": true,
".be": false,
".cache": false,
".devcontainer": false,
".eclipse": false,
".git": false,
".github": false,
".idea": false,
".ijwb": false,
".venv": false,
".vscode": false,
"bazel-bin": false,
"bazel-enola": false,
"bazel-out": false,
"bazel-testlogs": false,
".github": false,
".vscode": false,
"bin": false,
"cli": false,
"common": false,
"connectors": false,
"core": false,
"docs": false,
"site": false,
"tools": false,
"web": false,
"node_modules": false,
".be": false,
"bin": false,
".devcontainer": false
"web": false,
"BUILT": false
}
}
21 changes: 21 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2024 The Enola <https://enola.dev> Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# https://yamllint.readthedocs.io/en/stable/configuration.html

rules:
# Let's just check this only via .editorconfig instead
line-length: disable
20 changes: 20 additions & 0 deletions core/impl/src/main/java/dev/enola/core/AbstractRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2024 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.core;

public abstract class AbstractRepository {}
19 changes: 18 additions & 1 deletion core/impl/src/main/java/dev/enola/core/EnolaServiceProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import dev.enola.core.meta.EntityKindRepository;
import dev.enola.core.meta.SchemaAspect;
import dev.enola.core.meta.TypeRegistryWrapper;
import dev.enola.core.meta.TypeRegistryWrapper.Builder;
import dev.enola.core.type.TypeRepository;

import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path;
Expand All @@ -41,8 +43,20 @@ public class EnolaServiceProvider {

public EnolaServiceProvider(EntityKindRepository ekr)
throws ValidationException, EnolaException {
this(ekr, TypeRepository.newBuilder().build());
}

public EnolaServiceProvider(EntityKindRepository ekr, TypeRepository tyr)
throws ValidationException, EnolaException {
enolaService = new EnolaServiceRegistry();
var trb = TypeRegistryWrapper.newBuilder();
process(ekr, trb);
process(tyr, trb);
this.typeRegistry = trb.build();
}

private void process(EntityKindRepository ekr, TypeRegistryWrapper.Builder trb)
throws ValidationException, EnolaException {
for (var ek : ekr.list()) {
var aspectsBuilder = ImmutableList.<EntityAspect>builder();

Expand Down Expand Up @@ -115,7 +129,10 @@ public EnolaServiceProvider(EntityKindRepository ekr)
trb.add(aspect.getDescriptors());
}
}
this.typeRegistry = trb.build();
}

private void process(TypeRepository tyr, Builder trb) {
// TODO Implement...
}

public EnolaService getEnolaService() {
Expand Down
78 changes: 78 additions & 0 deletions core/impl/src/main/java/dev/enola/core/type/TypeRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2024 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.core.type;

import com.google.common.collect.ImmutableSortedMap;
import com.google.protobuf.TypeRegistry;

import dev.enola.core.meta.proto.Type;

/**
* Repository of {@link Type}.
*
* <p>Not to be confused with {@link TypeRegistry}.
*/
public class TypeRepository {
// TODO Extract what's general here to share with PropertyRepository et al.

private final ImmutableSortedMap<String, Type> types;

private TypeRepository(ImmutableSortedMap<String, Type> types) {
this.types = types;
}

public Iterable<Type> list() {
return types.values();
}

public Iterable<String> names() {
return types.keySet();
}

public Type getByName(String name) {
return types.get(name);
}

public static Builder newBuilder() {
return new Builder();
}

public static class Builder {
private final ImmutableSortedMap.Builder<String, Type> types =
ImmutableSortedMap.naturalOrder();

public void add(Type.Builder type) {
require(type.getUri(), "uri");
// TODO setUrl(...), based on some sort of baseURL to the Web UI
var name = require(type.getName(), "name");
types.put(name, type.build());
}

public TypeRepository build() {
return new TypeRepository(types.build());
}

private <T> T require(T what, String identification) {
if (what == null)
throw new IllegalArgumentException("Type '" + identification + "' is required");
return what;
}

private Builder() {}
}
}
Loading

0 comments on commit ac92587

Please sign in to comment.