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

#1602 Change delimiter between name and version #2353

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
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(
" ",
"",
maxonfjvipon marked this conversation as resolved.
Show resolved Hide resolved
"//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
15 changes: 10 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,8 @@ 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.
* @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 +65,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 @@ -34,6 +34,9 @@
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.OnCached;
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 +55,12 @@ final class DiscoverMojoTest {
/**
* Text.
*/
private static final String TEXT = "org.eolang.txt.text|5f82cc1";
private static final ObjectName TEXT = new OnCached(
new OnDefault(
"org.eolang.txt.text",
new CommitHash.ChConstant("5f82cc1")
)
);

/**
* Default assertion message.
Expand Down Expand Up @@ -116,17 +124,19 @@ 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 OnCached(
new OnDefault("org.eolang.stdout", new CommitHash.ChConstant("9c93528"))
);
final String nop = "org.eolang.nop";
final ForeignTojos tojos = maven.externalTojos();
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_CONTAIN, DiscoverMojoTest.TEXT),
tojos.contains(DiscoverMojoTest.TEXT),
tojos.contains(DiscoverMojoTest.TEXT.toString()),
Matchers.is(true)
);
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_NOT, stdout),
tojos.contains(stdout),
tojos.contains(stdout.toString()),
Matchers.is(false)
);
MatcherAssert.assertThat(
Expand Down Expand Up @@ -159,23 +169,21 @@ void discoversWithSeveralObjectsWithDifferentVersions(
" nop"
)
.execute(new FakeMaven.Discover());
final String first = String.format(
"org.eolang.txt.sprintf|%s",
hashes.get("0.28.1").value()
final ObjectName first = new OnCached(
new OnDefault("org.eolang.txt.sprintf", hashes.get("0.28.1"))
);
final String second = String.format(
"org.eolang.txt.sprintf|%s",
hashes.get("0.28.2").value()
final ObjectName second = new OnCached(
new OnDefault("org.eolang.txt.sprintf", hashes.get("0.28.2"))
);
final ForeignTojos tojos = maven.externalTojos();
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_CONTAIN, first),
tojos.contains(first),
tojos.contains(first.toString()),
Matchers.is(true)
);
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_CONTAIN, second),
tojos.contains(second),
tojos.contains(second.toString()),
Matchers.is(true)
);
}
Expand All @@ -188,15 +196,17 @@ 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 OnCached(
new OnDefault("org.eolang.seq", new CommitHash.ChConstant("6c6269d"))
);
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_NOT, seq),
maven.externalTojos().contains(seq),
maven.externalTojos().contains(seq.toString()),
Matchers.is(false)
);
MatcherAssert.assertThat(
String.format(DiscoverMojoTest.SHOULD_NOT, DiscoverMojoTest.TEXT),
maven.externalTojos().contains(DiscoverMojoTest.TEXT),
maven.externalTojos().contains(DiscoverMojoTest.TEXT.toString()),
Matchers.is(false)
);
}
Expand Down
17 changes: 12 additions & 5 deletions eo-maven-plugin/src/test/java/org/eolang/maven/ProbeMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
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.OnCached;
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 +70,9 @@ final class ProbeMojoTest {
/**
* Stdout.
*/
private static final String STDOUT = "org.eolang.io.stdout|9c93528";
private static final ObjectName STDOUT = new OnCached(
new OnDefault("org.eolang.io.stdout", new CommitHash.ChConstant("9c93528"))
);

@Test
@ExtendWith(OnlineCondition.class)
Expand Down Expand Up @@ -159,7 +164,7 @@ void findsProbesWithVersionsInOneObjectionary(@TempDir final Path temp) throws I
"Tojos should have contained versioned object %s after probing, but they didn't",
ProbeMojoTest.STDOUT
),
maven.externalTojos().contains(ProbeMojoTest.STDOUT),
maven.externalTojos().contains(ProbeMojoTest.STDOUT.toString()),
Matchers.is(true)
);
MatcherAssert.assertThat(
Expand Down Expand Up @@ -187,7 +192,9 @@ 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 number = new OnCached(
new OnDefault("org.eolang.txt.text", new CommitHash.ChConstant("5f82cc1"))
);
final FakeMaven maven = new FakeMaven(temp)
.with(
"objectionaries",
Expand All @@ -205,15 +212,15 @@ void findsProbesWithVersionsInDifferentObjectionaries(@TempDir final Path temp)
"Tojos should have contained versioned object %s after probing, but they didn't",
ProbeMojoTest.STDOUT
),
maven.externalTojos().contains(ProbeMojoTest.STDOUT),
maven.externalTojos().contains(ProbeMojoTest.STDOUT.toString()),
Matchers.is(true)
);
MatcherAssert.assertThat(
String.format(
"Tojos should have contained versioned object %s after probing, but they didn't",
number
),
maven.externalTojos().contains(number),
maven.externalTojos().contains(number.toString()),
Matchers.is(true)
);
MatcherAssert.assertThat(
Expand Down
42 changes: 25 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,9 @@
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.OnCached;
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 +72,9 @@ final class PullMojoTest {
/**
* Versioned source.
*/
private static final String VERSIONED = "%s/org/eolang/io/stdout|9c93528.eo";
private static final ObjectName VERSIONED = new OnCached(
new OnDefault("%s/org/eolang/io/stdout", new CommitHash.ChConstant("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, new CommitHash.ChConstant("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,40 @@ 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 OnCached(
maxonfjvipon marked this conversation as resolved.
Show resolved Hide resolved
new OnDefault("%s/org/eolang/io/sprintf", new CommitHash.ChConstant("17f892.eo"))
);
final ObjectName string = new OnCached(
new OnDefault("%s/org/eolang/string", new CommitHash.ChConstant("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 +288,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
Loading
Loading