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 7, 2023
2 parents 9c5802d + 6cb35fd commit 38bcaa0
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 56 deletions.
18 changes: 10 additions & 8 deletions eo-maven-plugin/src/main/java/org/eolang/maven/DiscoverMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private Collection<String> discover(final Path file) {
}

/**
* Get unique list of object names from given XML.
* Get a unique list of object names from given XML.
* @param xml XML.
* @return Object names.
*/
Expand All @@ -122,15 +122,17 @@ private static Set<String> names(final XML xml) {
obj -> !obj.isEmpty(),
xml.xpath(
String.join(
" ",
"",
"//o[",
"not(starts-with(@base,'.'))",
"and @base != 'Q'",
"and @base != '^'",
"and @base != '$'",
"and @base != '&'",
"and not(@ref)",
"]/string-join((@base, @ver),'|')"
" and @base != 'Q'",
" and @base != '^'",
" and @base != '$'",
" and @base != '&'",
" and not(@ref)",
"]/string-join((@base, @ver),'",
VersionsMojo.DELIMITER,
"')"
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,18 @@
* rewriting files in "1-parse" and don't do anything if is not really critical
*/
public final class VersionsMojo extends SafeMojo {
/**
* Delimiter between name and hash in EO object name.
*/
public static final String DELIMITER = "#";

/**
* Tag pattern.
*/
private static final Pattern SEMVER = Pattern.compile("[0-9]+\\.[0-9]+\\.[0-9]+");

/**
* Commit hashes map.
* Commit-hashes map.
*/
private final Map<String, CommitHash> hashes = new CommitHashesMap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.eolang.maven.hash.CommitHash;

/**
* Object name with version.
* Object name with a version.
*
* @since 0.29.6
*/
Expand Down
26 changes: 21 additions & 5 deletions eo-maven-plugin/src/main/java/org/eolang/maven/name/OnDefault.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.eolang.maven.name;

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

/**
Expand All @@ -44,8 +45,19 @@ public final class OnDefault implements ObjectName {

/**
* Ctor.
* @param object Object full name with version or not.
* @param def Default hash if version in full name is absent.
* Please use the constructor for tests only because it can't guarantee
* that {@code hash} is actually hash but not a random string.
* @param object Object full name with a version or not.
* @param hash Default hash is a version in full name is absent.
*/
public OnDefault(final String object, final String hash) {
this(object, new CommitHash.ChConstant(hash));
}

/**
* Ctor.
* @param object Object full name with a version or not.
* @param def Default hash if a version in full name is absent.
*/
public OnDefault(final String object, final CommitHash def) {
this.object = object;
Expand All @@ -64,15 +76,19 @@ public CommitHash hash() {

@Override
public String toString() {
return String.join("|", this.split()[0], this.split()[1]);
return String.join(
VersionsMojo.DELIMITER,
this.split()[0],
this.split()[1]
);
}

/**
* Split given object.
* Split a given object.
* @return Split object to name and hash.
*/
private String[] split() {
String[] splt = this.object.split("\\|");
String[] splt = this.object.split(VersionsMojo.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 @@ -30,7 +30,7 @@
/**
* Swapped object name.
* Depends on encapsulated condition behaves like one of the encapsulated object names.
* If second object is not provided - behaves like {@link OnUnversioned}
* If a second object is not provided - behaves like {@link OnUnversioned}
*
* @since 0.29.6
* @todo #2328:30min Inline code in {@code toString()} method. For some reason
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ public boolean contains(final String name) {
return !this.select(tojo -> tojo.get(Attribute.ID.key()).equals(name)).isEmpty();
}

/**
* Check if the tojos contains a foreign tojo with object name.
* @param name The name of the tojo.
* @return True if tojo exists.
*/
public boolean contains(final ObjectName name) {
return this.contains(name.toString());
}

/**
* Get the size of the tojos.
* @return The size of the tojos.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.cactoos.io.ResourceOf;
import org.eolang.maven.hash.CommitHash;
import org.eolang.maven.hash.CommitHashesMap;
import org.eolang.maven.name.ObjectName;
import org.eolang.maven.name.OnDefault;
import org.eolang.maven.tojos.ForeignTojo;
import org.eolang.maven.tojos.ForeignTojos;
import org.hamcrest.MatcherAssert;
Expand All @@ -52,7 +54,7 @@ final class DiscoverMojoTest {
/**
* Text.
*/
private static final String TEXT = "org.eolang.txt.text|5f82cc1";
private static final ObjectName TEXT = new OnDefault("org.eolang.txt.text", "5f82cc1");

/**
* Default assertion message.
Expand Down Expand Up @@ -116,7 +118,7 @@ void discoversWithVersions(@TempDir final Path tmp) throws IOException {
.with("hashes", new CommitHashesMap.Fake())
.withVersionedProgram()
.execute(new FakeMaven.Discover());
final String stdout = "org.eolang.stdout|9c93528";
final ObjectName stdout = new OnDefault("org.eolang.stdout", "9c93528");
final String nop = "org.eolang.nop";
final ForeignTojos tojos = maven.externalTojos();
MatcherAssert.assertThat(
Expand Down Expand Up @@ -159,14 +161,8 @@ void discoversWithSeveralObjectsWithDifferentVersions(
" nop"
)
.execute(new FakeMaven.Discover());
final String first = String.format(
"org.eolang.txt.sprintf|%s",
hashes.get("0.28.1").value()
);
final String second = String.format(
"org.eolang.txt.sprintf|%s",
hashes.get("0.28.2").value()
);
final ObjectName first = new OnDefault("org.eolang.txt.sprintf", hashes.get("0.28.1"));
final ObjectName second = new OnDefault("org.eolang.txt.sprintf", hashes.get("0.28.2"));
final ForeignTojos tojos = maven.externalTojos();
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_CONTAIN, first),
Expand All @@ -188,7 +184,7 @@ void doesNotDiscoverWithVersions(@TempDir final Path tmp) throws IOException {
.with("hashes", new CommitHashesMap.Fake())
.withVersionedProgram()
.execute(new FakeMaven.Discover());
final String seq = "org.eolang.seq|6c6269d";
final ObjectName seq = new OnDefault("org.eolang.seq", "6c6269d");
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_NOT, seq),
maven.externalTojos().contains(seq),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.eolang.maven.hash.ChText;
import org.eolang.maven.hash.CommitHash;
import org.eolang.maven.hash.CommitHashesMap;
import org.eolang.maven.name.ObjectName;
import org.eolang.maven.name.OnDefault;
import org.eolang.maven.objectionary.Objectionaries;
import org.eolang.maven.objectionary.ObjsDefault;
import org.eolang.maven.objectionary.OyRemote;
Expand Down Expand Up @@ -67,7 +69,7 @@ final class ProbeMojoTest {
/**
* Stdout.
*/
private static final String STDOUT = "org.eolang.io.stdout|9c93528";
private static final ObjectName STDOUT = new OnDefault("org.eolang.io.stdout", "9c93528");

@Test
@ExtendWith(OnlineCondition.class)
Expand Down Expand Up @@ -187,7 +189,7 @@ void findsProbesWithVersionsInDifferentObjectionaries(@TempDir final Path temp)
final Map<String, CommitHash> hashes = new CommitHashesMap.Fake();
final CommitHash first = hashes.get("0.28.5");
final CommitHash second = hashes.get("0.28.6");
final String number = "org.eolang.txt.text|5f82cc1";
final ObjectName text = new OnDefault("org.eolang.txt.text", "5f82cc1");
final FakeMaven maven = new FakeMaven(temp)
.with(
"objectionaries",
Expand All @@ -211,9 +213,9 @@ void findsProbesWithVersionsInDifferentObjectionaries(@TempDir final Path temp)
MatcherAssert.assertThat(
String.format(
"Tojos should have contained versioned object %s after probing, but they didn't",
number
text
),
maven.externalTojos().contains(number),
maven.externalTojos().contains(text),
Matchers.is(true)
);
MatcherAssert.assertThat(
Expand Down
38 changes: 21 additions & 17 deletions eo-maven-plugin/src/test/java/org/eolang/maven/PullMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.eolang.maven.hash.ChText;
import org.eolang.maven.hash.CommitHash;
import org.eolang.maven.hash.CommitHashesMap;
import org.eolang.maven.name.ObjectName;
import org.eolang.maven.name.OnDefault;
import org.eolang.maven.objectionary.Objectionaries;
import org.eolang.maven.objectionary.ObjsDefault;
import org.eolang.maven.objectionary.OyRemote;
Expand Down Expand Up @@ -69,7 +71,10 @@ final class PullMojoTest {
/**
* Versioned source.
*/
private static final String VERSIONED = "%s/org/eolang/io/stdout|9c93528.eo";
private static final ObjectName VERSIONED = new OnDefault(
"%s/org/eolang/io/stdout",
"9c93528.eo"
);

@Test
void pullsSuccessfully(@TempDir final Path temp) throws IOException {
Expand Down Expand Up @@ -173,20 +178,19 @@ void skipsPullMojo(@TempDir final Path temp) throws IOException {
);
}

@Disabled
@Test
void pullsVersionedObjectSuccessfully(@TempDir final Path temp) throws IOException {
final FakeMaven maven = new FakeMaven(temp);
maven.foreignTojos()
.add("org.eolang.io.stdout|9c93528")
.add(new OnDefault(PullMojoTest.STDOUT, "9c93528"))
.withVersion("*.*.*");
maven.execute(PullMojo.class);
MatcherAssert.assertThat(
String.format(
"File by path %s should have existed after pulling, but it didn't",
PullMojoTest.path(PullMojoTest.VERSIONED)
PullMojoTest.path(PullMojoTest.VERSIONED.toString())
),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED.toString()),
Matchers.is(true)
);
}
Expand All @@ -210,9 +214,9 @@ void pullsProbedVersionedObjectFromOneObjectionary(@TempDir final Path temp)
MatcherAssert.assertThat(
String.format(
"File by path %s should have existed after pulling, but it didn't",
PullMojoTest.path(PullMojoTest.VERSIONED)
PullMojoTest.path(PullMojoTest.VERSIONED.toString())
),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED.toString()),
Matchers.is(true)
);
}
Expand All @@ -238,36 +242,36 @@ void pullsProbedVersionedObjectsFromDifferentObjectionaries(@TempDir final Path
.with("hsh", third)
.withVersionedProgram()
.execute(new FakeMaven.Pull());
final String sprintf = "%s/org/eolang/io/sprintf|17f892.eo";
final String string = "%s/org/eolang/string|5f82cc";
final ObjectName sprintf = new OnDefault("%s/org/eolang/io/sprintf", "17f892.eo");
final ObjectName string = new OnDefault("%s/org/eolang/string", "5f82cc.eo");
MatcherAssert.assertThat(
String.format(
"File by path %s should have existed after pulling, but it didn't",
PullMojoTest.path(PullMojoTest.VERSIONED)
PullMojoTest.path(PullMojoTest.VERSIONED.toString())
),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED.toString()),
Matchers.is(true)
);
MatcherAssert.assertThat(
String.format(
"File by path %s should have existed after pulling, but it didn't",
PullMojoTest.path(sprintf)
PullMojoTest.path(sprintf.toString())
),
PullMojoTest.exists(temp, sprintf),
PullMojoTest.exists(temp, sprintf.toString()),
Matchers.is(true)
);
MatcherAssert.assertThat(
String.format(
"File by path %s should have existed after pulling, but it didn't",
PullMojoTest.path(string)
PullMojoTest.path(string.toString())
),
PullMojoTest.exists(temp, string),
PullMojoTest.exists(temp, string.toString()),
Matchers.is(true)
);
}

/**
* Check if given source files exists in target directory.
* Check if the given source file exists in the target directory.
*
* @param temp Test temporary directory.
* @param source Source file.
Expand All @@ -280,7 +284,7 @@ private static boolean exists(final Path temp, final String source) {
}

/**
* Format given source path.
* Format given a source path.
* @param source Source path.
* @return Formatted source path.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
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 @@ -48,7 +49,7 @@ final class OnDefaultTest {
* Test object.
*/
private static final String OBJECT = String.join(
"|",
VersionsMojo.DELIMITER,
OnDefaultTest.STDOUT,
OnDefaultTest.HASH
);
Expand Down Expand Up @@ -105,7 +106,7 @@ void takesHashFromGivenFullName() {
@Test
void buildsFullNameWithGivenDefaultHash() {
final String built = String.join(
"|",
VersionsMojo.DELIMITER,
OnDefaultTest.STDOUT,
OnDefaultTest.FAKE.value()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
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 @@ -37,12 +38,12 @@ class OnSwapTest {
/**
* First.
*/
private static final String FIRST = "stdout|1234567";
private static final String FIRST = String.join(VersionsMojo.DELIMITER, "stdout", "1234567");

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

/**
* Fake hash.
Expand Down
Loading

0 comments on commit 38bcaa0

Please sign in to comment.