Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Sep 8, 2023
2 parents f3bb740 + 089a625 commit 1f4614e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 157 deletions.
43 changes: 3 additions & 40 deletions eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ abstract class SafeMojo extends AbstractMojo {
)
protected File foreign;

/**
* File with external "tojos".
* @checkstyle VisibilityModifierCheck (10 lines)
*/
@Parameter(
property = "eo.external",
required = true,
defaultValue = "${project.build.directory}/eo-external.csv"
)
protected File external;

/**
* Format of "foreign" file ("json" or "csv").
* @checkstyle MemberNameCheck (7 lines)
Expand Down Expand Up @@ -202,34 +191,17 @@ abstract class SafeMojo extends AbstractMojo {

/**
* Used for object versioning implementation.
* If set to TRUE, external tojos are used instead of foreign ones and all
* inherited Mojos behave a bit differently.
* If set to TRUE - objects are parsed, stored in tojos and processed as versioned.
* @todo #1602:30min Remove the flag when objection versioned is
* implemented. The variable is used for implementation of object
* versioning. It allows to use external tojos instead of foreign in Mojos.
* for the test purposes. When object versioning is implemented there
* versioning. When object versioning is implemented there
* will be no need for that variable
* @checkstyle VisibilityModifierCheck (10 lines)
* @checkstyle MemberNameCheck (10 lines)
*/
@Parameter(property = "eo.withVersions", defaultValue = "false")
protected boolean withVersions;

/**
* External tojos.
* @todo #1602:30min Use external tojos to implement object versioning.
* Implementation of object versioning will bring a lot significant
* changes. That's why it's better to use independent separated tojos for
* that purpose. At the end when object versioning works - just replace
* them and remove unnecessary one.
* @checkstyle MemberNameCheck (7 lines)
* @checkstyle VisibilityModifierCheck (5 lines)
*/
protected final ForeignTojos externalTojos = new ForeignTojos(
() -> Catalogs.INSTANCE.make(this.external.toPath(), this.foreignFormat),
() -> this.scope
);

/**
* Commit hashes.
* @checkstyle VisibilityModifierCheck (5 lines)
Expand Down Expand Up @@ -323,9 +295,6 @@ public final void execute() throws MojoFailureException, MojoExecutionException
if (this.foreign != null) {
SafeMojo.closeTojos(this.tojos);
}
if (this.external != null) {
SafeMojo.closeTojos(this.externalTojos);
}
if (this.placed != null) {
SafeMojo.closeTojos(this.placedTojos);
}
Expand All @@ -342,13 +311,7 @@ public final void execute() throws MojoFailureException, MojoExecutionException
* @checkstyle AnonInnerLengthCheck (100 lines)
*/
protected final ForeignTojos scopedTojos() {
final ForeignTojos tjs;
if (this.external != null && this.withVersions) {
tjs = this.externalTojos;
} else {
tjs = this.tojos;
}
return tjs;
return this.tojos;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ final class DiscoverMojoTest {
* Default assertion message.
*/
private static final String SHOULD_CONTAIN =
"External tojos should contain %s object after discovering, but they didn't";
"Tojos should contain %s object after discovering, but they didn't";

/**
* Default assertion message.
*/
private static final String SHOULD_NOT =
"External tojos should not contain %s object after discovering, but they did";
"Tojos should not contain %s object after discovering, but they did";

@ParameterizedTest
@CsvSource({
Expand Down Expand Up @@ -121,7 +121,7 @@ void discoversWithVersions(@TempDir final Path tmp) throws IOException {
.execute(new FakeMaven.Discover());
final ObjectName stdout = new OnVersioned("org.eolang.stdout", "9c93528");
final String nop = "org.eolang.nop";
final ForeignTojos tojos = maven.externalTojos();
final ForeignTojos tojos = maven.foreignTojos();
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_CONTAIN, DiscoverMojoTest.TEXT),
tojos.contains(DiscoverMojoTest.TEXT),
Expand Down Expand Up @@ -163,7 +163,7 @@ void discoversWithSeveralObjectsWithDifferentVersions(
.execute(new FakeMaven.Discover());
final ObjectName first = new OnVersioned("org.eolang.txt.sprintf", hashes.get("0.28.1"));
final ObjectName second = new OnVersioned("org.eolang.txt.sprintf", hashes.get("0.28.2"));
final ForeignTojos tojos = maven.externalTojos();
final ForeignTojos tojos = maven.foreignTojos();
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_CONTAIN, first),
tojos.contains(first),
Expand Down Expand Up @@ -193,7 +193,7 @@ void discoversDifferentUnversionedObjectsFromDifferentVersionedObjects(@TempDir
.withProgram(second, new OnVersioned(object, two))
.withProgram(first, new OnDefault(object))
.execute(new FakeMaven.Discover())
.externalTojos();
.foreignTojos();
MatcherAssert.assertThat(
String.format(
"Tojos should contained 3 similar objects %s: 2 with different hashes %s and one without; but they didn't",
Expand All @@ -219,12 +219,12 @@ void doesNotDiscoverWithVersions(@TempDir final Path tmp) throws IOException {
final ObjectName seq = new OnVersioned("org.eolang.seq", "6c6269d");
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_NOT, seq),
maven.externalTojos().contains(seq),
maven.foreignTojos().contains(seq),
Matchers.is(false)
);
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_NOT, DiscoverMojoTest.TEXT),
maven.externalTojos().contains(DiscoverMojoTest.TEXT),
maven.foreignTojos().contains(DiscoverMojoTest.TEXT),
Matchers.is(false)
);
}
Expand Down
47 changes: 1 addition & 46 deletions eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ public <T extends AbstractMojo> FakeMaven execute(final Class<T> mojo) throws IO
if (this.defaults) {
this.params.putIfAbsent("targetDir", this.targetPath().toFile());
this.params.putIfAbsent("foreign", this.foreignPath().toFile());
this.params.putIfAbsent("external", this.externalPath().toFile());
this.params.putIfAbsent("foreignFormat", "csv");
this.params.putIfAbsent("project", new MavenProjectStub());
final Path transpiled = Paths.get("transpiled");
Expand Down Expand Up @@ -285,28 +284,6 @@ ForeignTojos foreignTojos() {
);
}

/**
* External tojos for eo-external.* file.
* @return External tojos.
*/
ForeignTojos externalTojos() {
return new ForeignTojos(
() -> Catalogs.INSTANCE.make(this.externalPath()),
this::scope
);
}

/**
* Tojo for eo-external.* file.
*
* @return TjSmart of the current eo-external.file.
*/
TjSmart external() {
return new TjSmart(
Catalogs.INSTANCE.make(this.externalPath())
);
}

/**
* Sets placed tojo attribute.
*
Expand Down Expand Up @@ -415,23 +392,17 @@ FakeMaven withProgram(final String content, final ObjectName object)
.withScope(scope)
.withVersion(version)
.withSource(source);
this.externalTojos()
.add(object)
.withScope(scope)
.withVersion(version)
.withSource(source);
this.current.incrementAndGet();
return this;
}

/**
* Specify hash for all foreign and external tojos.
* Specify hash for all foreign tojos.
* @param hash Commit hash
* @return The same maven instance.
*/
FakeMaven allTojosWithHash(final CommitHash hash) {
this.foreignTojos().all().forEach(tojo -> tojo.withHash(hash));
this.externalTojos().all().forEach(tojo -> tojo.withHash(hash));
return this;
}

Expand All @@ -451,14 +422,6 @@ Path foreignPath() {
return this.workspace.absolute(Paths.get("eo-foreign.csv"));
}

/**
* Path to or eo-external.* file after all changes.
* @return Path to eo-foreign.* file.
*/
Path externalPath() {
return this.workspace.absolute(Paths.get("eo-external.csv"));
}

/**
* Tojo for placed.json file.
*
Expand Down Expand Up @@ -496,14 +459,6 @@ ForeignTojo programTojo() {
return this.foreignTojos().find(FakeMaven.tojoId(this.current.get() - 1));
}

/**
* Same as {@link FakeMaven#programTojo()} but for external tojos.
* @return Tojo entry.
*/
ForeignTojo programExternalTojo() {
return this.externalTojos().find(FakeMaven.tojoId(this.current.get() - 1));
}

/**
* The version of eo-maven-plugin for tests.
* @return Version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void extendsTojosWithVersionedOne(@TempDir final Path temp) throws IOException {
final ForeignTojos tojos = new FakeMaven(temp)
.with("withVersions", true)
.execute(MarkMojo.class)
.externalTojos();
.foreignTojos();
final ObjectName object = new OnVersioned("foo.bar", "6a70071");
MatcherAssert.assertThat(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ void findsProbesWithVersionsInOneObjectionary(@TempDir final Path temp) throws I
"Tojos should contain versioned object %s after probing, but they didn't",
ProbeMojoTest.STDOUT
),
maven.externalTojos().contains(ProbeMojoTest.STDOUT),
maven.foreignTojos().contains(ProbeMojoTest.STDOUT),
Matchers.is(true)
);
MatcherAssert.assertThat(
"Program tojo entry in tojos after probing should contain one probed object",
maven.programExternalTojo().probed(),
maven.programTojo().probed(),
Matchers.equalTo("1")
);
MatcherAssert.assertThat(
"Program tojo entry in tojos after probing should contain given hash",
maven.programExternalTojo().hash(),
maven.programTojo().hash(),
Matchers.equalTo(hash.value())
);
}
Expand Down Expand Up @@ -200,17 +200,17 @@ void findsProbesWithVersionsInDifferentObjectionaries(@TempDir final Path temp)
"Tojos should contain versioned objects '%s' after probing, but they didn't",
Arrays.asList(text, ProbeMojoTest.STDOUT)
),
maven.externalTojos().contains(text, ProbeMojoTest.STDOUT),
maven.foreignTojos().contains(text, ProbeMojoTest.STDOUT),
Matchers.is(true)
);
MatcherAssert.assertThat(
"Program tojo after probing should contain exactly two probed objects",
maven.programExternalTojo().probed(),
maven.programTojo().probed(),
Matchers.equalTo("2")
);
MatcherAssert.assertThat(
"Program tojo after probing should have given hash",
maven.programExternalTojo().hash(),
maven.programTojo().hash(),
Matchers.equalTo(first.value())
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void skipsPullMojo(@TempDir final Path temp) throws IOException {
@Test
void pullsVersionedObjectSuccessfully(@TempDir final Path temp) throws IOException {
final FakeMaven maven = new FakeMaven(temp);
maven.externalTojos()
maven.foreignTojos()
.add(new OnVersioned(PullMojoTest.STDOUT, "9c93528"))
.withVersion("*.*.*");
maven.with("withVersions", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.NoSuchElementException;
import org.cactoos.io.ResourceOf;
import org.eolang.maven.util.Home;
import org.hamcrest.MatcherAssert;
Expand Down Expand Up @@ -102,61 +101,6 @@ void doesNotFailWhenNoStrictNames(@TempDir final Path temp) throws IOException {
);
}

@Test
void registersInExternal(@TempDir final Path temp) throws IOException {
new Home(temp).save(
new ResourceOf("org/eolang/maven/file-name/abc-def.eo"),
Paths.get("src/eo/org/eolang/maven/foo.eo")
);
final String name = "org.eolang.maven.foo";
final FakeMaven maven = new FakeMaven(temp)
.with(RegisterMojoTest.PARAM, temp.resolve(RegisterMojoTest.SOURCES).toFile())
.with("withVersions", true)
.execute(new FakeMaven.Register());
MatcherAssert.assertThat(
String.format(
"Source object %s placed in %s should have been registered in external tojos but it didn't",
name,
RegisterMojoTest.SOURCES
),
maven.external()
.getById(name)
.exists("id"),
Matchers.is(true)
);
MatcherAssert.assertThat(
"External and foreign tojos should not have the same status after registering because external should replace foreign but they didn't",
maven.foreignTojos().status(),
Matchers.not(
Matchers.equalTo(
maven.externalTojos().status()
)
)
);
}

@Test
void doesNotRegisterInExternal(@TempDir final Path temp) throws IOException {
new Home(temp).save(
new ResourceOf("org/eolang/maven/file-name/abc-def.eo"),
Paths.get("src/eo/org/eolang/maven/foo.eo")
);
final String name = "org.eolang.maven.foo";
Assertions.assertThrows(
NoSuchElementException.class,
() -> new FakeMaven(temp)
.with(RegisterMojoTest.PARAM, temp.resolve(RegisterMojoTest.SOURCES).toFile())
.with("withVersions", false)
.execute(new FakeMaven.Register())
.external()
.getById(name),
String.format(
"External tojos should not have contained %s because \"withVersions\" is FALSE, but they did",
name
)
);
}

@Test
void throwsExceptionInCaseSourceDirIsNotSet(@TempDir final Path temp) {
Assertions.assertThrows(
Expand Down

3 comments on commit 1f4614e

@0pdd
Copy link

@0pdd 0pdd commented on 1f4614e Sep 8, 2023

Choose a reason for hiding this comment

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

Puzzle 1602-b2f8e2db disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java), that's why I closed #2226. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on 1f4614e Sep 8, 2023

Choose a reason for hiding this comment

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

Puzzle 1602-46b0e5d9 disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java), that's why I closed #2258. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on 1f4614e Sep 8, 2023

Choose a reason for hiding this comment

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

Puzzle 1602-e06a1aef discovered in eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java) and submitted as #2481. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.