Skip to content

Commit

Permalink
feat(objectionary#946): try to add 'version' meta
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Jan 13, 2025
1 parent cc32282 commit 37f0172
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,13 +51,12 @@ public DirectivesMetas(final ClassName classname) {

@Override
public Iterator<Directive> iterator() {
final Iterator<Directive> 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();
}

/**
Expand All @@ -76,17 +76,29 @@ 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")
.add("head").set("package").up()
.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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void validate() {
final Collection<String> 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,17 @@ void addsNothingExceptPackage() {
void createsDirectivesWithEmptyPackage() {
MatcherAssert.assertThat(
"We expect that <metas>/<package> 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 <metas>/<version> will be created",
new Xembler(new DirectivesMetas(new ClassName("WithVersion"))).xmlQuietly(),
XhtmlMatchers.hasXPath("/metas/meta[head[text()='version']]")
);
}
}

0 comments on commit 37f0172

Please sign in to comment.