Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update specs to 2024.1 #155

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugins {
id "com.diffplug.spotless" version "5.1.0"
id "java"
id 'net.researchgate.release' version '3.0.2'
id("com.vanniktech.maven.publish") version "0.26.0" apply false
alias(libs.plugins.release)
alias(libs.plugins.superPublish) apply(false)
}

repositories {
Expand Down Expand Up @@ -35,4 +35,4 @@ tasks.wrapper {
// You can either download the binary-only version of Gradle (BIN) or
// the full version (with sources and documentation) of Gradle (ALL)
distributionType = Wrapper.DistributionType.ALL
}
}
16 changes: 15 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ plugins {
id("java-library")
id("signing")
id("com.github.johnrengelman.shadow") version "7.1.1"
id("com.vanniktech.maven.publish")
alias(libs.plugins.superPublish)
jacoco
alias(libs.plugins.buildConfig)
}

repositories {
Expand Down Expand Up @@ -186,3 +187,16 @@ val integrationTest = tasks.create("integrationTest", Test::class.java) {
tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
}

buildConfig {
sourceSets.getByName("main") {
packageName("io.lionweb.lioncore.java")
buildConfigField("String", "CURRENT_SPECS_VERSION", "\"${specsVersion}\"")
}
}

spotless {
java {
target("src/**/*.java")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this approach works, as the contents differ for each release (e.g. PrimitiveType JSON will be gone in 2024.1).

The idea in LW-MPS (Not sure whether it works):

class LionCoreConstants_2023_1 implements ILionCoreConstants_2023_1, and adheres to 2023.1

Until now, class LionCoreConstants extends LionCoreConstants_2023_1 implements ILionCoreConstants and contained the changes we've had since 2023.1 release.
ILionCoreConstants extends ILionCoreConstants_2023_1.

Once we have 2024.1, I'll rename LionCoreConstants -> LionCoreConstants_2024_1 and have a new class LionCoreConstants extends LionCoreConstants_2024_1. LionCoreConstants_2024_1 will override getJsonType() to throw UnsupportedException.

I never access anything statically, always hand in an instance of ILionCoreConstants.

This way:

  • All unchanged elements between LW releases have the same Java object identity.
  • I can always decide explicitly which version I want to use.
  • Using unsupported elements in any LW release throws exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly ILionCoreConstants would contain methods for all the things that were created across the versions, throwing an exception when we access one not supported by that particular instance. For the sake of making an example, if we introduce in 2024.1 a date type, and then we remove it in 2025.1 we could have ILionCoreConstants_2023_1.getDate and ILionCoreConstants_2025_1.getDate throw an exception, while ILionCoreConstants_2024_1.getDate would return a proper value. Do I understand correctly?

For the time being, I wonder if we want to support 2023.1 at all in new versions of LionWeb Java. The user base is basically just us, and we can keep using previous versions of LionWeb Java until we want to move to 2024.1. Doing so will simplify the design, and postpone the problem of supporting multiple versions to the time when the user base will need retrocompatibility.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly ILionCoreConstants would contain methods for all the things that were created across the versions, throwing an exception when we access one not supported by that particular instance. For the sake of making an example, if we introduce in 2024.1 a date type, and then we remove it in 2025.1 we could have ILionCoreConstants_2023_1.getDate and ILionCoreConstants_2025_1.getDate throw an exception, while ILionCoreConstants_2024_1.getDate would return a proper value. Do I understand correctly?

Almost: The interface hierarchy would be:

  • ILCC_2023_1
    • ILCC_2024_1
      getDate()
      • ILCC_2025_1
        • ILCC

The class hierarchy would be:

  • LCC_2023_1
    • LCC_2024_1
      getDate() { return xxx; }
      • LCC_2025_1
        getDate() { throw Unsupported; }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ILionCoreConstants is always the newest one, and old ones don't change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the time being, I wonder if we want to support 2023.1 at all in new versions of LionWeb Java. The user base is basically just us, and we can keep using previous versions of LionWeb Java until we want to move to 2024.1. Doing so will simplify the design, and postpone the problem of supporting multiple versions to the time when the user base will need retrocompatibility.
What do you think?

There aren't many users yet, but we could use it as training for version changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let me try something to take into account support for 2023.1, as an exercise. I would aim to have a simpler structure, if I can find an acceptable solution

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ private LionCoreBuiltins() {
super("LionCore_builtins");
setID("LionCore-builtins");
setKey("LionCore-builtins");
setVersion(JsonSerialization.DEFAULT_SERIALIZATION_FORMAT);
// TODO we should move to the current version
setVersion(JsonSerialization.SERIALIZATION_FORMAT_2023_1);
PrimitiveType string = new PrimitiveType(this, "String");
new PrimitiveType(this, "Boolean");
new PrimitiveType(this, "Integer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public static Language getInstance() {
INSTANCE = new Language("LionCore_M3");
INSTANCE.setID("-id-LionCore-M3");
INSTANCE.setKey("LionCore-M3");
INSTANCE.setVersion(JsonSerialization.DEFAULT_SERIALIZATION_FORMAT);
// TODO we should move to the current version
INSTANCE.setVersion(JsonSerialization.SERIALIZATION_FORMAT_2023_1);

// We first instantiate all Concepts and Interfaces
// we add features only after as the features will have references to these elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import io.lionweb.lioncore.java.BuildConfig;
import io.lionweb.lioncore.java.api.ClassifierInstanceResolver;
import io.lionweb.lioncore.java.api.CompositeClassifierInstanceResolver;
import io.lionweb.lioncore.java.api.LocalClassifierInstanceResolver;
Expand Down Expand Up @@ -39,7 +40,14 @@
* behavior explicitly by calling getNodeInstantiator().enableDynamicNodes().
*/
public class JsonSerialization {
public static final String DEFAULT_SERIALIZATION_FORMAT = "2023.1";
public static final String DEFAULT_SERIALIZATION_FORMAT = BuildConfig.CURRENT_SPECS_VERSION;
public static final String SERIALIZATION_FORMAT_2023_1 = "2023.1";
public static final Set<String> SUPPORTED_FORMATS =
new HashSet<>(Arrays.asList(DEFAULT_SERIALIZATION_FORMAT, SERIALIZATION_FORMAT_2023_1));

public static boolean isFormatSupported(String format) {
return SUPPORTED_FORMATS.contains(format);
}

public static void saveLanguageToFile(Language language, File file) throws IOException {
String content = getStandardSerialization().serializeTreesToJsonString(language);
Expand Down Expand Up @@ -484,9 +492,11 @@ private String serializePropertyValue(@Nonnull DataType dataType, @Nullable Obje
}

private void validateSerializationBlock(SerializedChunk serializationBlock) {
if (!serializationBlock.getSerializationFormatVersion().equals(DEFAULT_SERIALIZATION_FORMAT)) {
if (!isFormatSupported(serializationBlock.getSerializationFormatVersion())) {
throw new IllegalArgumentException(
"Only serializationFormatVersion = '" + DEFAULT_SERIALIZATION_FORMAT + "' is supported");
"Serialization format '"
+ serializationBlock.getSerializationFormatVersion()
+ "' is not supported");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class CorrespondanceWithDocumentationTest {

private static final String SPECIFICATION_COMMIT_CONSIDERED =
"69ddbf4685acf1ef6d83c400570fb6c37efa4cfc";
"d138a4f3f6ea86e4ff27ff5cc515488aef30bd1c";

@Test
public void lioncoreIsTheSameAsInTheOrganizationRepo() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public void serializationOfEnumLiteralUsingEnumerationValueInstances() {
assertEquals(
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [{\n"
+ " \"version\": \"1\",\n"
+ " \"key\": \"mm_key\"\n"
Expand Down Expand Up @@ -462,7 +462,7 @@ public void serializationOfEnumLiteralUsingEnumInstances() {
assertEquals(
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [{\n"
+ " \"version\": \"1\",\n"
+ " \"key\": \"mm_key\"\n"
Expand Down Expand Up @@ -515,7 +515,7 @@ public void deserializeEnumerationLiteralsUsingEnumerationValueInstances() {
JsonElement je =
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [{\n"
+ " \"version\": \"1\",\n"
+ " \"key\": \"mm_key\"\n"
Expand Down Expand Up @@ -589,7 +589,7 @@ public void deserializeEnumerationLiteralsUsingEnumInstances() {
JsonElement je =
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [{\n"
+ " \"version\": \"1\",\n"
+ " \"key\": \"mm_key\"\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void serializeLionCoreToSerializedChunk() {
SerializedChunk serializedChunk =
jsonSerialization.serializeTreeToSerializationBlock(LionCore.getInstance());

assertEquals("2023.1", serializedChunk.getSerializationFormatVersion());
assertEquals("2024.1", serializedChunk.getSerializationFormatVersion());

assertEquals(2, serializedChunk.getLanguages().size());
Assert.assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void serializeBoolean() {
JsonObject expected =
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [],\n"
+ " \"nodes\": [\n"
+ " {\n"
Expand Down Expand Up @@ -89,7 +89,7 @@ public void deserializeBoolean() {
JsonObject serialized =
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [],\n"
+ " \"nodes\": [\n"
+ " {\n"
Expand Down Expand Up @@ -161,7 +161,7 @@ public void serializeString() {
JsonObject expected =
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [],\n"
+ " \"nodes\": [\n"
+ " {\n"
Expand Down Expand Up @@ -227,7 +227,7 @@ public void deserializeString() {
JsonObject serialized =
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [],\n"
+ " \"nodes\": [\n"
+ " {\n"
Expand Down Expand Up @@ -298,7 +298,7 @@ public void serializeInteger() {
JsonObject expected =
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [],\n"
+ " \"nodes\": [\n"
+ " {\n"
Expand Down Expand Up @@ -364,7 +364,7 @@ public void deserializeInteger() {
JsonObject serialized =
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [],\n"
+ " \"nodes\": [\n"
+ " {\n"
Expand Down Expand Up @@ -439,7 +439,7 @@ public void serializeJSON() {
JsonObject expected =
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [],\n"
+ " \"nodes\": [\n"
+ " {\n"
Expand Down Expand Up @@ -508,7 +508,7 @@ public void deserializeJSON() {
JsonObject serialized =
JsonParser.parseString(
"{\n"
+ " \"serializationFormatVersion\": \"2023.1\",\n"
+ " \"serializationFormatVersion\": \"2024.1\",\n"
+ " \"languages\": [],\n"
+ " \"nodes\": [\n"
+ " {\n"
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/resources/serialization/bobslibrary.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"serializationFormatVersion": "2023.1",
"serializationFormatVersion": "2024.1",
"languages": [],
"nodes": [
{
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/resources/serialization/foo-library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"serializationFormatVersion": "2023.1",
"serializationFormatVersion": "2024.1",
"languages": [],
"nodes": [
{
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/resources/serialization/langeng-library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"serializationFormatVersion": "2023.1",
"serializationFormatVersion": "2024.1",
"languages": [],
"nodes": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"serializationFormatVersion": "2023.1",
"serializationFormatVersion": "2024.1",
"languages": [],
"nodes": [
{
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/resources/serialization/lioncore.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"serializationFormatVersion": "2023.1",
"serializationFormatVersion": "2024.1",
"languages": [
{
"key": "LionCore-M3",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version=0.2.17-SNAPSHOT
specsVersion=2023.1
specsVersion=2024.1
jvmVersion=1.8
org.gradle.jvmargs=-Dfile.encoding=UTF-8
SONATYPE_CONNECT_TIMEOUT_SECONDS=200
Expand Down
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[plugins]
buildConfig = { id = "com.github.gmazzo.buildconfig", version = "5.3.5" }
release = { id = "net.researchgate.release", version = "3.0.2" }
superPublish = { id = "com.vanniktech.maven.publish", version = "0.28.0" }

Loading