From 37f0172c59980de021ea235d3b29b6f1337bfcb0 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Mon, 13 Jan 2025 12:00:18 +0300 Subject: [PATCH] feat(#946): try to add 'version' meta --- .../directives/DirectivesMetas.java | 32 +++++++++++++------ .../jeo/representation/xmir/JcabiXmlNode.java | 2 +- .../directives/DirectivesMetasTest.java | 13 ++++++-- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java index 536c28fc3..07a061a0e 100644 --- a/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java +++ b/src/main/java/org/eolang/jeo/representation/directives/DirectivesMetas.java @@ -23,6 +23,7 @@ */ package org.eolang.jeo.representation.directives; +import com.jcabi.manifests.Manifests; import java.util.Iterator; import org.eolang.jeo.representation.ClassName; import org.eolang.jeo.representation.PrefixedName; @@ -50,13 +51,12 @@ public DirectivesMetas(final ClassName classname) { @Override public Iterator iterator() { - final Iterator result; - if (this.name.pckg().isEmpty()) { - result = new Directives().iterator(); - } else { - result = new Directives().add("metas").append(this.pckg()).up().iterator(); + final Directives result = new Directives().add("metas"); + result.append(this.version()); + if (!this.name.pckg().isEmpty()) { + result.append(this.pckg()); } - return result; + return result.up().iterator(); } /** @@ -76,9 +76,9 @@ ClassName className() { private Directives pckg() { final Directives result; final String original = this.name.pckg(); - if (original.isEmpty()) { - result = new Directives(); - } else { +// if (original.isEmpty()) { +// result = new Directives(); +// } else { final String prefixed = new PrefixedName(original).encode(); result = new Directives() .add("meta") @@ -86,7 +86,19 @@ private Directives pckg() { .add("tail").set(prefixed).up() .add("part").set(prefixed).up() .up(); - } +// } return result; } + + /** + * The version directives of jeo-maven-plugin. + * @return Version directives. + */ + private Directives version() { + return new Directives() + .add("meta") + .add("head").set("version").up() + .add("tail").set(Manifests.read("JEO-Version")).up() + .up(); + } } diff --git a/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlNode.java b/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlNode.java index 061a7c27e..a74f17a26 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlNode.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/JcabiXmlNode.java @@ -160,7 +160,7 @@ public void validate() { final Collection ignore = new HashSet<>(Arrays.asList( "mandatory-home", "name-outside-of-abstract-object", - "mandatory-version", +// "mandatory-version", "empty-object", "incorrect-package", "object-does-not-match-filename" diff --git a/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java b/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java index e840e99d2..c5795579a 100644 --- a/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java +++ b/src/test/java/org/eolang/jeo/representation/directives/DirectivesMetasTest.java @@ -79,8 +79,17 @@ void addsNothingExceptPackage() { void createsDirectivesWithEmptyPackage() { MatcherAssert.assertThat( "We expect that / won't be created if package is empty", - new DirectivesMetas(new ClassName("WithoutPackage")), - Matchers.emptyIterable() + new Xembler(new DirectivesMetas(new ClassName("WithoutPackage"))).xmlQuietly(), + Matchers.not(XhtmlMatchers.hasXPath("/metas/meta[head[text()='package']]")) + ); + } + + @Test + void createsDirectivesWithVersion() { + MatcherAssert.assertThat( + "We expect that / will be created", + new Xembler(new DirectivesMetas(new ClassName("WithVersion"))).xmlQuietly(), + XhtmlMatchers.hasXPath("/metas/meta[head[text()='version']]") ); } }