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

feat(#1602): default empty versions near to the root object #2501

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ private void parse(final ForeignTojo tojo) throws IOException {
new Syntax(
name,
new InputOf(source),
new OutputTo(baos)
new OutputTo(baos),
this.withVersions
).parse();
final String parsed = new XMLDocument(
new Xembler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -57,6 +58,18 @@
* check here is related to particular mojos (and we should check their
* behaviour in appropriate tests). In other words there are integration tests
* here. And, probably, it is not the best place for them.
* @todo #1602:30min Enable tests related to object versioning. The main concept of object
* versioned was changed: now we don't add suffix with version to object, but want to make version
* as prefix (before org.eolang) so it would be transpiled to {@link org.eolang.PhPackage}. Need
* either to refactor tests or remove them after object versioning is implemented. Tests are:
* - {@link AssembleMojoTest#assemblesTogetherWithVersions}
* - {@link DiscoverMojoTest#discoversWithVersions}
* - {@link DiscoverMojoTest#discoversWithSeveralObjectsWithDifferentVersions}
* - {@link DiscoverMojoTest#discoversDifferentUnversionedObjectsFromDifferentVersionedObjects}
* - {@link ProbeMojoTest#findsProbesWithVersionsInDifferentObjectionaries}
* - {@link ProbeMojoTest#findsProbesWithVersionsInOneObjectionary}
* - {@link PullMojoTest#pullsProbedVersionedObjectsFromDifferentObjectionaries}
* - {@link PullMojoTest#pullsProbedVersionedObjectFromOneObjectionary}
*/
@ExtendWith(OnlineCondition.class)
final class AssembleMojoTest {
Expand Down Expand Up @@ -116,6 +129,7 @@ void assemblesTogether(@TempDir final Path temp) throws IOException {
}

@Test
@Disabled
void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception {
final Map<String, CommitHash> hashes = new CommitHashesMap.Fake();
final CommitHash master = hashes.get("master");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eolang.maven.tojos.ForeignTojos;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -114,6 +115,7 @@ void discoversForDifferentScopes(@TempDir final Path tmp) throws IOException {
}

@Test
@Disabled
void discoversWithVersions(@TempDir final Path tmp) throws IOException {
final FakeMaven maven = new FakeMaven(tmp)
.with("withVersions", true)
Expand All @@ -140,6 +142,7 @@ void discoversWithVersions(@TempDir final Path tmp) throws IOException {
}

@Test
@Disabled
void discoversWithSeveralObjectsWithDifferentVersions(
@TempDir final Path tmp
) throws IOException {
Expand Down Expand Up @@ -177,6 +180,7 @@ void discoversWithSeveralObjectsWithDifferentVersions(
}

@Test
@Disabled
void discoversDifferentUnversionedObjectsFromDifferentVersionedObjects(@TempDir final Path tmp)
throws IOException {
final Map<String, CommitHash> hashes = new CommitHashesMap.Fake();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.eolang.maven.util.Home;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -147,6 +148,7 @@ void findsProbesInOyRemote(@TempDir final Path temp) throws IOException {

@Test
@ExtendWith(OnlineCondition.class)
@Disabled
void findsProbesWithVersionsInOneObjectionary(@TempDir final Path temp) throws IOException {
final CommitHash hash = new CommitHashesMap.Fake().get("0.28.5");
final FakeMaven maven = new FakeMaven(temp)
Expand Down Expand Up @@ -177,6 +179,7 @@ void findsProbesWithVersionsInOneObjectionary(@TempDir final Path temp) throws I

@Test
@ExtendWith(OnlineCondition.class)
@Disabled
void findsProbesWithVersionsInDifferentObjectionaries(@TempDir final Path temp)
throws IOException {
final Map<String, CommitHash> hashes = new CommitHashesMap.Fake();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eolang.maven.util.Home;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -191,6 +192,7 @@ void pullsVersionedObjectSuccessfully(@TempDir final Path temp) throws IOExcepti
}

@Test
@Disabled
void pullsProbedVersionedObjectFromOneObjectionary(@TempDir final Path temp)
throws IOException {
new FakeMaven(temp)
Expand All @@ -216,6 +218,7 @@ void pullsProbedVersionedObjectFromOneObjectionary(@TempDir final Path temp)
}

@Test
@Disabled
void pullsProbedVersionedObjectsFromDifferentObjectionaries(@TempDir final Path temp)
throws IOException {
final Map<String, CommitHash> hashes = new CommitHashesMap.Fake();
Expand Down
4 changes: 3 additions & 1 deletion eo-parser/src/main/java/org/eolang/parser/CheckPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ public Collection<String> failures() throws IOException {
final Map<String, Object> map = yaml.load(this.script);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final String src = map.get("eo").toString();
final boolean versioned = map.containsKey("versioned");
new Syntax(
"scenario",
new InputOf(String.format("%s\n", src)),
new OutputTo(baos)
new OutputTo(baos),
versioned
).parse();
final XML xml = new XMLDocument(baos.toByteArray());
baos.reset();
Expand Down
20 changes: 20 additions & 0 deletions eo-parser/src/main/java/org/eolang/parser/Objects.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* Object tree.
* @since 0.1
*/
@SuppressWarnings("PMD.TooManyMethods")
interface Objects extends Iterable<Directive> {

/**
Expand Down Expand Up @@ -69,6 +70,18 @@ interface Objects extends Iterable<Directive> {
*/
void xprop(String key, Object xpath);

/**
* Optional property.
* Add property depends on given condition.
* @param condition Condition
* @param key Key
* @todo #2503:30min Remove the method. This method is temporary used in {@link XeListener}
* while implementing object versioning feature. When it's done - need to remove it and replace
* all its occurrences in {@link XeListener} with {@code prop} method calls. Also need to
* remove {@code versioned} field from {@link XeListener} since it won't be used anymore.
*/
void oprop(boolean condition, String key);
Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon Could you please rename this method? It is hard to understand what you mean by this abbreviation. I don't think you meant this.

Copy link
Member Author

Choose a reason for hiding this comment

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

@volodya-lombrozo first "o" stands for "optional". Property that will be added depends on giving condition

Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon Why do we need such a method, if in case of condition==false we can just avoid calling this method?

Copy link
Member Author

@maxonfjvipon maxonfjvipon Sep 20, 2023

Choose a reason for hiding this comment

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

@volodya-lombrozo this method is used 8 times in XeListener. We either call oprop 8 times or replace these calls with if (this.versioned) { this.objects.prop(key); } at 8 places

Copy link
Member

Choose a reason for hiding this comment

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

@maxonfjvipon I don't know how it happened that we have xprop method, but both of them xprop and oprop:

  1. Hard readable.
  2. Might produce some issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

@volodya-lombrozo there's nothing about overloading

  1. prop - just adds property, uses attr from Xemlby
  2. xprop - changes property by given xpath, uses xattr from Xembly. It was added here: feat(#2399): new syntax ebnf #2474
  3. oprop - addes property if given condition is TRUE. Actually is a temporary method. When object versioning is implemented it will be removed and all its occurrences will be replaced with prop


/**
* Enter last object.
*/
Expand Down Expand Up @@ -136,6 +149,13 @@ public void xprop(final String key, final Object xpath) {
this.dirs.xattr(key, xpath);
}

@Override
public void oprop(final boolean condition, final String key) {
if (condition) {
this.prop(key);
}
}

@Override
public void enter() {
this.dirs.xpath("o[last()]").strict(1);
Expand Down
64 changes: 41 additions & 23 deletions eo-parser/src/main/java/org/eolang/parser/ParsingTrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
import com.jcabi.xml.XSL;
import com.jcabi.xml.XSLDocument;
import com.yegor256.xsline.StAfter;
import com.yegor256.xsline.StEndless;
import com.yegor256.xsline.StLambda;
import com.yegor256.xsline.StSequence;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.TrDefault;
import com.yegor256.xsline.TrEnvelope;
import com.yegor256.xsline.TrFast;
import com.yegor256.xsline.TrJoined;
import com.yegor256.xsline.TrLambda;
import com.yegor256.xsline.TrLogged;
import java.util.logging.Level;
Expand All @@ -44,13 +47,21 @@
public final class ParsingTrain extends TrEnvelope {

/**
* Apply changes to each XML after processing.
* Apply changes to each XML after processing each shift.
*/
private static final XSL EACH = new XSLDocument(
ParsingTrain.class.getResourceAsStream("_each.xsl"),
"each.xsl"
).with(new ClasspathSources(ParsingTrain.class));

/**
* Apply changes to each XML after processing all shifts.
*/
private static final XSL VERSIONS = new XSLDocument(
ParsingTrain.class.getResourceAsStream("move-versions-deeper.xsl"),
"move-versions-deeper.xsl"
).with(new ClasspathSources(ParsingTrain.class));

/**
* Sheets in the right order.
*/
Expand Down Expand Up @@ -110,34 +121,41 @@ public ParsingTrain() {
*/
ParsingTrain(final String... sheets) {
super(
new TrLambda(
new TrFast(
new TrLambda(
new TrLogged(
new TrClasspath<>(sheets).back(),
ParsingTrain.class,
Level.FINEST
new TrJoined<>(
maxonfjvipon marked this conversation as resolved.
Show resolved Hide resolved
new TrLambda(
new TrFast(
new TrLambda(
new TrLogged(
new TrClasspath<>(sheets).back(),
ParsingTrain.class,
Level.FINEST
),
StEoLogged::new
),
StEoLogged::new
TrFast.class,
500L
),
TrFast.class,
500L
),
shift -> new StSequence(
shift.uid(),
xml -> xml.nodes("//error[@severity='critical']").isEmpty(),
new StAfter(
shift,
new StLambda(
shift::uid,
(pos, xml) -> ParsingTrain.EACH.with("step", pos)
.with("sheet", shift.uid())
.transform(xml)
shift -> new StSequence(
shift.uid(),
xml -> xml.nodes("//error[@severity='critical']").isEmpty(),
new StAfter(
shift,
new StLambda(
shift::uid,
(pos, xml) -> ParsingTrain.EACH
.with("step", pos)
.with("sheet", shift.uid())
.transform(xml)
)
)
)
),
new TrDefault<>(
new StEndless(
new StLambda(ParsingTrain.VERSIONS::transform)
)
)
)
);
}

}
27 changes: 24 additions & 3 deletions eo-parser/src/main/java/org/eolang/parser/Syntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,43 @@ public final class Syntax {
*/
private final Output target;

/**
* Add versions to all objects or not.
*/
private final boolean versioned;

/**
* Ctor.
*
* @param nme The name of it
* @param ipt Input text
* @param tgt Target
* @checkstyle ParameterNumberCheck (10 lines)
*/
public Syntax(
final String nme,
final Input ipt,
final Output tgt
) {
this(nme, ipt, tgt, false);
}

/**
* Ctor.
* @param nme The name of it
* @param ipt Input text
* @param tgt Target
* @param versioned Add versions to all objects or not
* @checkstyle ParameterNumberCheck (10 lines)
*/
public Syntax(
final String nme,
final Input ipt,
final Output tgt,
final boolean versioned
) {
this.name = nme;
this.input = ipt;
this.target = tgt;
this.versioned = versioned;
}

/**
Expand All @@ -114,7 +135,7 @@ public void parse() throws IOException {
);
parser.removeErrorListeners();
parser.addErrorListener(spy);
final XeListener xel = new XeListener(this.name);
final XeListener xel = new XeListener(this.name, this.versioned);
new ParseTreeWalker().walk(xel, parser.program());
final XML dom = new XMLDocument(
new Xembler(
Expand Down
Loading
Loading