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 15, 2023
2 parents 6791cb5 + 716599c commit c4087fa
Show file tree
Hide file tree
Showing 15 changed files with 455 additions and 457 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import org.cactoos.iterable.Filtered;
import org.cactoos.set.SetOf;
import org.eolang.maven.name.ObjectName;
import org.eolang.maven.name.OnReplaced;
import org.eolang.maven.name.OnSwap;
import org.eolang.maven.name.OnVersioned;
import org.eolang.maven.tojos.ForeignTojo;
import org.eolang.maven.util.Rel;

Expand Down Expand Up @@ -66,7 +66,7 @@ public void exec() throws FileNotFoundException {
.map(
name -> new OnSwap(
this.withVersions,
new OnVersioned(name, this.hashes)
new OnReplaced(name, this.hashes)
)
)
.peek(
Expand Down Expand Up @@ -125,6 +125,7 @@ private Collection<String> discover(final Path file) {

/**
* Get a unique list of object names from given XML.
*
* @param xml XML.
* @return Object names.
*/
Expand All @@ -143,7 +144,7 @@ private static Set<String> names(final XML xml) {
" and @base != '&'",
" and not(@ref)",
"]/string-join((@base, @ver),'",
OnVersioned.DELIMITER,
OnReplaced.DELIMITER,
"')"
)
)
Expand Down
8 changes: 4 additions & 4 deletions eo-maven-plugin/src/main/java/org/eolang/maven/ProbeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.eolang.maven.hash.CommitHash;
import org.eolang.maven.name.ObjectName;
import org.eolang.maven.name.OnCached;
import org.eolang.maven.name.OnDefault;
import org.eolang.maven.name.OnReplaced;
import org.eolang.maven.name.OnSwap;
import org.eolang.maven.name.OnVersioned;
import org.eolang.maven.objectionary.Objectionaries;
Expand Down Expand Up @@ -129,7 +129,7 @@ public void exec() throws IOException {
new ChNarrow(
new OnSwap(
this.withVersions,
new OnDefault(tojo.identifier(), this.hsh)
new OnVersioned(tojo.identifier(), this.hsh)
).hash()
)
).withProbed(count);
Expand Down Expand Up @@ -166,8 +166,8 @@ private Collection<ObjectName> probes(final Path file) throws FileNotFoundExcept
obj -> new OnCached(
new OnSwap(
this.withVersions,
new OnDefault(
new OnVersioned(ProbeMojo.noPrefix(obj), this.hashes),
new OnVersioned(
new OnReplaced(ProbeMojo.noPrefix(obj), this.hashes),
this.hsh
)
)
Expand Down
4 changes: 2 additions & 2 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import org.eolang.maven.hash.CommitHash;
import org.eolang.maven.name.ObjectName;
import org.eolang.maven.name.OnCached;
import org.eolang.maven.name.OnDefault;
import org.eolang.maven.name.OnSwap;
import org.eolang.maven.name.OnVersioned;
import org.eolang.maven.objectionary.Objectionaries;
import org.eolang.maven.objectionary.ObjsDefault;
import org.eolang.maven.tojos.ForeignTojo;
Expand Down Expand Up @@ -110,7 +110,7 @@ public void exec() throws IOException {
final ObjectName name = new OnCached(
new OnSwap(
this.withVersions,
new OnDefault(tojo.identifier(), this.hsh)
new OnVersioned(tojo.identifier(), this.hsh)
)
);
tojo.withSource(this.pull(name).toAbsolutePath())
Expand Down
121 changes: 0 additions & 121 deletions eo-maven-plugin/src/main/java/org/eolang/maven/name/OnDefault.java

This file was deleted.

132 changes: 132 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/name/OnReplaced.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.maven.name;

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

/**
* Object name replaced.
* This is object name that parses raw sting like:
* - "org.eolang.text#0.1.0" into "org.eolang.text"
* and "4b19944"
* - "org.eolang.string#a1b2c3d" into "org.eolang.string"
* and "be83d9a"
* Pay attention to that versions transformed into narrow hashes.
* If a version is not provided - behaves like {@link OnUnversioned}.
*
* @since 0.30
* @todo #2376:90min Frontend and backend delimiters differ.
* I was confused with the delimiter '#' that we use in {@link OnReplaced} 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 OnReplaced 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:
* - "org.eolang.text#0.1.0"
* - "org.eolang.string#1.23.1"
* - "org.eolang.math#3.3.3"
*/
private final String raw;

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

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

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

@Override
public String value() {
return this.split()[0];
}

@Override
public CommitHash hash() {
return this.hashes.get(this.split()[1]);
}

@Override
public String toString() {
final String result;
if (this.raw.contains(OnReplaced.DELIMITER)) {
result = String.join(
"",
this.value(),
OnReplaced.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(OnReplaced.DELIMITER);
}
}

Loading

3 comments on commit c4087fa

@0pdd
Copy link

@0pdd 0pdd commented on c4087fa Aug 15, 2023

Choose a reason for hiding this comment

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

Puzzle 2381-b6d409bc disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/name/OnDefault.java), that's why I closed #2389. 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 c4087fa Aug 15, 2023

Choose a reason for hiding this comment

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

Puzzle 2376-007b3f61 disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/name/OnVersioned.java), that's why I closed #2382. 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 c4087fa Aug 15, 2023

Choose a reason for hiding this comment

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

Puzzle 2376-11b46788 discovered in eo-maven-plugin/src/main/java/org/eolang/maven/name/OnReplaced.java) and submitted as #2394. 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.