Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Aug 11, 2023
2 parents 6879741 + 81ff9ff commit b64b485
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private static Set<String> names(final XML xml) {
" and @base != '&'",
" and not(@ref)",
"]/string-join((@base, @ver),'",
VersionsMojo.DELIMITER,
OnVersioned.DELIMITER,
"')"
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@
* @since 0.29.6
*/
public final class VersionsMojo extends SafeMojo {
/**
* Delimiter between name and hash in EO object name.
*/
public static final String DELIMITER = "#";

/**
* Tag pattern.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.eolang.maven.name;

import org.eolang.maven.VersionsMojo;
import org.eolang.maven.hash.CommitHash;

/**
Expand Down Expand Up @@ -77,7 +76,7 @@ public CommitHash hash() {
@Override
public String toString() {
return String.join(
VersionsMojo.DELIMITER,
OnVersioned.DELIMITER,
this.split()[0],
this.split()[1]
);
Expand All @@ -88,7 +87,7 @@ public String toString() {
* @return Split object to name and hash.
*/
private String[] split() {
String[] splt = this.object.split(VersionsMojo.DELIMITER);
String[] splt = this.object.split(OnVersioned.DELIMITER);
if (splt.length == 1) {
splt = new String[]{splt[0], this.hsh.value()};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,53 @@
*/
package org.eolang.maven.name;

import java.util.Map;
import org.eolang.maven.hash.CommitHash;
import org.eolang.maven.hash.CommitHashesMap;

/**
* Object name versioned.
* This is object name that parses raw sting like:
* - "org.eolang.text#0.1.0" into "org.eolang.text"
* and "4b19944d86058e3c81e558340a3a13bc335a2b48"
* and "4b19944"
* - "org.eolang.string#a1b2c3d" into "org.eolang.string"
* and "be83d9adda4b7c9e670e625fe951c80f3ead4177"
* and "be83d9a"
* Pay attention that versions transformed into hashes.
* If a version is not provided - behaves like {@link OnUnversioned}.
*
* @since 0.30
* @todo #2281:30min Implement OnVersioned class.
* This class should parse raw string into object name and hash from object name with semver
* version. In other words this class should replace the behavior of
* {@link org.eolang.maven.VersionsMojo} class. When this class is implemented,
* remove the {@link org.eolang.maven.VersionsMojo class}.
* Don't forget to add tests for this class.
* @todo #2376:90min Remove VersionsMojo.
* It is not used anymore. Remove it and all its dependencies from all the places.
* We need to apply {@link OnVersioned} in {@link org.eolang.maven.DiscoverMojo}
* and replace all the tests from VersionsMojoTest to DiscoverMojoTest.
* Also we need to enable the next tests:
* - {@link org.eolang.maven.ProbeMojoTest#findsProbesWithVersionsInDifferentObjectionaries()}
* - {@link org.eolang.maven.PullMojoTest#pullsProbedVersionedObjectsFromDifferentObjectionaries()}
* - {@link org.eolang.maven.DiscoverMojoTest#discoversWithSeveralObjectsWithDifferentVersions()}
* - {@link org.eolang.maven.DiscoverMojoTest#discoversWithVersions()}
* Don't forget to remove that puzzle after all.
* @todo #2376:90min Frontend and backend delimiters differ.
* I was confused with the delimiter '#' that we use in {@link OnVersioned} and delimiter which
* we use in the frontend. For example:
* - "org.eolang.text|0.1.0" - frontend
* - "org.eolang.text#0.1.0" - backend
* The problem here is that we use the '|' delimiter on the frontend and '#' in the backend, but
* both of them mean the same thing - object name + version.
* I believe that we need to use the same symbol in both places, because it will be easier to
* understand the code. So, my suggestion to use '|' in both places.
*/
public final class OnVersioned implements ObjectName {

/**
* Delimiter between name and hash in EO object name.
*/
public static final String DELIMITER = "#";

/**
* Default hashes.
*/
private static final Map<String, CommitHash> DEFAULT = new CommitHashesMap();

/**
* Raw string.
* Examples:
Expand All @@ -54,30 +79,64 @@ public final class OnVersioned implements ObjectName {
*/
private final String raw;

/**
* All hashes.
*/
private final Map<String, ? extends CommitHash> hashes;

/**
* Constructor.
* @param origin Raw string.
*/
public OnVersioned(final String origin) {
this(origin, OnVersioned.DEFAULT);
}

/**
* Constructor.
* @param origin Raw string.
* @param all All hashes.
*/
OnVersioned(
final String origin,
final Map<String, ? extends CommitHash> all
) {
this.raw = origin;
this.hashes = all;
}

@Override
public String value() {
throw new UnsupportedOperationException(
"This 'value()' method is not supported for OnVersioned yet"
);
return this.split()[0];
}

@Override
public CommitHash hash() {
throw new UnsupportedOperationException(
"The 'hash()' method is not supported for OnVersioned yet"
);
return this.hashes.get(this.split()[1]);
}

@Override
public String toString() {
return this.raw;
final String result;
if (this.raw.contains(OnVersioned.DELIMITER)) {
result = String.join(
"",
this.value(),
OnVersioned.DELIMITER,
this.hash().value()
);
} else {
result = this.value();
}
return result;
}

/**
* Split raw string into name and hash.
* @return Array of two elements: name and hash.
*/
private String[] split() {
return this.raw.split(OnVersioned.DELIMITER);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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 @@ -112,6 +113,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 Down Expand Up @@ -139,6 +141,7 @@ void discoversWithVersions(@TempDir final Path tmp) throws IOException {
}

@Test
@Disabled
void discoversWithSeveralObjectsWithDifferentVersions(
@TempDir final Path tmp
) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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 @@ -184,6 +185,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 @@ -221,6 +222,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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.eolang.maven.name;

import org.eolang.maven.VersionsMojo;
import org.eolang.maven.hash.CommitHash;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand All @@ -49,7 +48,7 @@ final class OnDefaultTest {
* Test object.
*/
private static final String OBJECT = String.join(
VersionsMojo.DELIMITER,
OnVersioned.DELIMITER,
OnDefaultTest.STDOUT,
OnDefaultTest.HASH
);
Expand Down Expand Up @@ -106,7 +105,7 @@ void takesHashFromGivenFullName() {
@Test
void buildsFullNameWithGivenDefaultHash() {
final String built = String.join(
VersionsMojo.DELIMITER,
OnVersioned.DELIMITER,
OnDefaultTest.STDOUT,
OnDefaultTest.FAKE.value()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.eolang.maven.name;

import org.eolang.maven.VersionsMojo;
import org.eolang.maven.hash.CommitHash;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand All @@ -38,12 +37,12 @@ class OnSwapTest {
/**
* First.
*/
private static final String FIRST = String.join(VersionsMojo.DELIMITER, "stdout", "1234567");
private static final String FIRST = String.join(OnVersioned.DELIMITER, "stdout", "1234567");

/**
* Second.
*/
private static final String SECOND = String.join(VersionsMojo.DELIMITER, "sprintf", "7654321");
private static final String SECOND = String.join(OnVersioned.DELIMITER, "sprintf", "7654321");

/**
* Fake hash.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.eolang.maven.name;

import org.eolang.maven.VersionsMojo;
import org.eolang.maven.hash.CommitHash;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand All @@ -38,7 +37,7 @@ final class OnUnversionedTest {
@Test
void returnsFullNameWithVersions() {
final String stdout = "stdout";
final String object = String.join(VersionsMojo.DELIMITER, stdout, "1234567");
final String object = String.join(OnVersioned.DELIMITER, stdout, "1234567");
MatcherAssert.assertThat(
String.format(
"Unversioned object %s as string should have been equal to %s, but it didn't",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package org.eolang.maven.name;

import org.eolang.maven.hash.CommitHashesMap;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
Expand Down Expand Up @@ -57,7 +57,6 @@ final class OnVersionedTest {
"org.eolang.penguin, org.eolang.penguin#0.28.7",
"org.eolang.eagle, org.eolang.eagle#0.28.9"
})
@Disabled("Enable when OnVersioned.value() is implemented")
void retrievesName(final String expected, final String origin) {
final OnVersioned name = new OnVersioned(origin);
MatcherAssert.assertThat(
Expand All @@ -67,29 +66,28 @@ void retrievesName(final String expected, final String origin) {
);
}

@Test
@ParameterizedTest
@CsvSource({
"15c85d7f8cffe15b0deba96e90bdac98a76293bb, org.eolang.string#0.23.17",
"4b19944d86058e3c81e558340a3a13bc335a2b48, org.eolang.dummy#0.23.19",
"0aa6875c40d099c3f670e93d4134b629566c5643, org.eolang.text#0.25.0",
"ff32e9ff70c2b3be75982757f4b0607dc37b258a, org.eolang.aug#0.25.5",
"e0b783692ef749bb184244acb2401f551388a328, org.eolang.sept#0.26.0",
"cc554ab82909eebbfdacd8a840f9cf42a99b64cf, org.eolang.oct#0.27.0",
"00b60c7b2112cbad4e37ba96b162469a0e75f6df, org.eolang.nov#0.27.2",
"6a70071580e95aeac104b2e48293d3dfe0669973, org.eolang.dec#0.28.0",
"0c15066a2026cec69d613b709a301f1573f138ec, org.eolang.mon#0.28.1",
"9b883935257bd59d1ba36240f7e213d4890df7ca, org.eolang.tu#0.28.10",
"a7a4556bf1aa697324d805570f42d70affdddb75, org.eolang.wen#0.28.14",
"54d83d4b1d28075ee623d58fd742eaa529febd3d, org.eolang.th#0.28.2",
"6c6269d1f9a1c81ffe641538f119fe4e12706cb3, org.eolang.fri#0.28.4",
"9c9352890b5d30e1b89c9147e7c95a90c9b8709f, org.eolang.sat#0.28.5",
"17f89293e5ae6115e9a0234b754b22918c11c602, org.eolang.sun#0.28.6",
"5f82cc1edffad67bf4ba816610191403eb18af5d, org.eolang.penguin#0.28.7",
"be83d9adda4b7c9e670e625fe951c80f3ead4177, org.eolang.eagle#0.28.9"
"15c85d7, org.eolang.string#0.23.17",
"4b19944, org.eolang.dummy#0.23.19",
"0aa6875, org.eolang.text#0.25.0",
"ff32e9f, org.eolang.aug#0.25.5",
"e0b7836, org.eolang.sept#0.26.0",
"cc554ab, org.eolang.oct#0.27.0",
"00b60c7, org.eolang.nov#0.27.2",
"6a70071, org.eolang.dec#0.28.0",
"0c15066, org.eolang.mon#0.28.1",
"9b88393, org.eolang.tu#0.28.10",
"a7a4556, org.eolang.wen#0.28.14",
"54d83d4, org.eolang.th#0.28.2",
"6c6269d, org.eolang.fri#0.28.4",
"9c93528, org.eolang.sat#0.28.5",
"17f8929, org.eolang.sun#0.28.6",
"5f82cc1, org.eolang.penguin#0.28.7",
"be83d9a, org.eolang.eagle#0.28.9"
})
@Disabled("Enable when OnVersioned.hash() is implemented")
void retrievesHash(final String expected, final String origin) {
final OnVersioned name = new OnVersioned(origin);
final OnVersioned name = new OnVersioned(origin, new CommitHashesMap.Fake());
MatcherAssert.assertThat(
String.format("Can't retrieve object hash from %s versioned object %s", name, origin),
name.hash().value(),
Expand All @@ -98,13 +96,15 @@ void retrievesHash(final String expected, final String origin) {
}

@Test
@Disabled("Enable when OnVersioned.toString() is implemented properly")
void convertsToStringWithNonEmptyVersion() {
final OnVersioned name = new OnVersioned("org.eolang.string#0.23.17");
final OnVersioned name = new OnVersioned(
"org.eolang.string#0.23.17",
new CommitHashesMap.Fake()
);
MatcherAssert.assertThat(
String.format("Can't convert versioned object %s to string", name),
name.toString(),
Matchers.equalTo("org.eolang.string#15c85d7f8cffe15b0deba96e90bdac98a76293bb")
Matchers.equalTo("org.eolang.string#15c85d7")
);
}

Expand Down

3 comments on commit b64b485

@0pdd
Copy link

@0pdd 0pdd commented on b64b485 Aug 11, 2023

Choose a reason for hiding this comment

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

Puzzle 2281-493fd13a disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/name/OnVersioned.java), that's why I closed #2376. 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 b64b485 Aug 11, 2023

Choose a reason for hiding this comment

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

Puzzle 2376-3d36c5d7 discovered in eo-maven-plugin/src/main/java/org/eolang/maven/name/OnVersioned.java) and submitted as #2381. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on b64b485 Aug 11, 2023

Choose a reason for hiding this comment

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

Puzzle 2376-007b3f61 discovered in eo-maven-plugin/src/main/java/org/eolang/maven/name/OnVersioned.java) and submitted as #2382. 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.