Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jul 22, 2023
2 parents 6a7fb22 + 52103c8 commit a0f2696
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 39 deletions.
66 changes: 54 additions & 12 deletions eo-maven-plugin/src/main/java/org/eolang/maven/ProbeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.cactoos.iterable.Filtered;
import org.cactoos.iterator.Mapped;
import org.cactoos.list.ListOf;
import org.eolang.maven.hash.ChCached;
import org.eolang.maven.hash.ChCompound;
import org.eolang.maven.hash.ChNarrow;
import org.eolang.maven.hash.CommitHash;
Expand All @@ -55,6 +58,15 @@
* <a href="https://github.com/objectionary/eo/issues/1323">this issue</a>.
*
* @since 0.28.11
* @todo #1602:30min Resolve code duplication. Probe and Pull mojos have several
* identical fields, methods and lines of code. Need to resolve this code
* duplication. One more abstract class is not an option. We can either join
* them into one mojo, or composite them inside other mojo.
* @todo #1602:30min Add version to "probe" meta in xmir. To probe objects
* {@link ProbeMojo} gets object names from "probe" meta in xmir. Objects
* appear there after "add-probes.xsl" transformation. So to probe objects
* with versions in {@link ProbeMojo} we need to add information about these
* versions in xmir before the mojo.
* @checkstyle CyclomaticComplexityCheck (300 lines)
*/
@Mojo(
Expand All @@ -63,7 +75,6 @@
threadSafe = true
)
public final class ProbeMojo extends SafeMojo {

/**
* The Git hash to pull objects from, in objectionary.
*
Expand Down Expand Up @@ -97,20 +108,27 @@ public final class ProbeMojo extends SafeMojo {
@SuppressWarnings("PMD.ImmutableField")
private Objectionary objectionary;

/**
* Hash-Objectionary map.
* @todo #1602:30min Use objectionaries to probe objects with different
* versions. Objects with different versions are stored in different
* storages (objectionaries). Every objectionary has its own hash.
* To get versioned object from objectionary firstly we need to get
* right objectionary by object's version and then get object from that
* objectionary by name.
* @checkstyle MemberNameCheck (5 lines)
*/
private final Map<String, Objectionary> objectionaries = new HashMap<>();

@Override
public void exec() throws IOException {
final CommitHash hash = new ChCompound(
this.offlineHashFile, this.offlineHash, this.tag
final CommitHash hash = new ChCached(
new ChCompound(
this.offlineHashFile, this.offlineHash, this.tag
)
);
if (this.objectionary == null) {
this.objectionary = new OyFallbackSwap(
new OyHome(
new ChNarrow(hash),
this.cache
),
new OyIndexed(new OyRemote(hash)),
this.forceUpdate()
);
this.objectionary = this.objectionaryByHash(hash);
}
final Collection<String> probed = new HashSet<>(1);
final Collection<ForeignTojo> tojos = this.scopedTojos().unprobed();
Expand Down Expand Up @@ -152,6 +170,31 @@ public void exec() throws IOException {
}
}

/**
* Get objectionary by given hash from the map.
* @param hash Hash.
* @return Objectionary by given hash.
*/
private Objectionary objectionaryByHash(final CommitHash hash) {
final String value = hash.value();
if (!this.objectionaries.containsKey(value)) {
this.objectionaries.put(
value,
new OyFallbackSwap(
new OyHome(
new ChNarrow(hash),
this.cache
),
new OyIndexed(
new OyRemote(hash)
),
this.forceUpdate()
)
);
}
return this.objectionaries.get(value);
}

/**
* Find all probes found in the provided XML file.
*
Expand Down Expand Up @@ -210,5 +253,4 @@ private static String noPrefix(final String obj) {
private boolean forceUpdate() {
return this.session.getRequest().isUpdateSnapshots();
}

}
84 changes: 59 additions & 25 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.eolang.maven.hash.ChCached;
import org.eolang.maven.hash.ChCompound;
import org.eolang.maven.hash.ChNarrow;
import org.eolang.maven.hash.CommitHash;
Expand All @@ -54,7 +57,6 @@
threadSafe = true
)
public final class PullMojo extends SafeMojo {

/**
* The directory where to process to.
*/
Expand All @@ -69,15 +71,6 @@ public final class PullMojo extends SafeMojo {
@Parameter(property = "eo.tag", required = true, defaultValue = "master")
private String tag = "master";

/**
* Pull again even if the .eo file is already present?
*
* @checkstyle MemberNameCheck (7 lines)
* @since 0.10.0
*/
@Parameter(property = "eo.overWrite", required = true, defaultValue = "false")
private boolean overWrite;

/**
* Read hashes from local file.
*
Expand All @@ -102,24 +95,36 @@ public final class PullMojo extends SafeMojo {
@SuppressWarnings("PMD.ImmutableField")
private Objectionary objectionary;

/**
* Hash-Objectionary map.
* @todo #1602:30min Use objectionaries to pull objects with different
* versions. Objects with different versions are stored in different
* storages (objectionaries). Every objectionary has its own hash.
* To pull versioned object from objectionary firstly we need to get
* right objectionary by object's version and then get object from that
* objectionary by name.
* @checkstyle MemberNameCheck (5 lines)
*/
private final Map<String, Objectionary> objectionaries = new HashMap<>();

/**
* Pull again even if the .eo file is already present?
*
* @checkstyle MemberNameCheck (7 lines)
* @since 0.10.0
*/
@Parameter(property = "eo.overWrite", required = true, defaultValue = "false")
private boolean overWrite;

@Override
public void exec() throws IOException {
final CommitHash hash = new ChCompound(
this.offlineHashFile, this.offlineHash, this.tag
final CommitHash hash = new ChCached(
new ChCompound(
this.offlineHashFile, this.offlineHash, this.tag
)
);
if (this.objectionary == null) {
this.objectionary = new OyFallbackSwap(
new OyHome(
new ChNarrow(hash),
this.cache
),
new OyCaching(
new ChNarrow(hash),
this.cache,
new OyIndexed(new OyRemote(hash))
),
this.session.getRequest().isUpdateSnapshots()
);
this.objectionary = this.objectionaryByHash(hash);
}
final Collection<ForeignTojo> tojos = this.scopedTojos().withoutSources();
for (final ForeignTojo tojo : tojos) {
Expand All @@ -132,6 +137,36 @@ public void exec() throws IOException {
);
}

/**
* Get objectionary from the map by given hash.
* @param hash Hash.
* @return Objectionary by given hash.
*/
private Objectionary objectionaryByHash(final CommitHash hash) {
final String value = hash.value();
final CommitHash narrow = new ChCached(new ChNarrow(hash));
if (!this.objectionaries.containsKey(value)) {
this.objectionaries.put(
value,
new OyFallbackSwap(
new OyHome(
narrow,
this.cache
),
new OyCaching(
narrow,
this.cache,
new OyIndexed(
new OyRemote(hash)
)
),
this.session.getRequest().isUpdateSnapshots()
)
);
}
return this.objectionaries.get(value);
}

/**
* Pull one object.
*
Expand Down Expand Up @@ -161,5 +196,4 @@ name, new Rel(src)
}
return src;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ public final class OyRemote implements Objectionary {
/**
* Constructor.
* @param hash Commit hash
* @throws IOException if fails.
*/
public OyRemote(final CommitHash hash) throws IOException {
public OyRemote(final CommitHash hash) {
this.template = new UrlOy(
"https://raw.githubusercontent.com/objectionary/home/%s/objects/%s.eo",
hash.value()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import org.eolang.maven.OnlineCondition;
import org.eolang.maven.hash.ChNarrow;
import org.eolang.maven.hash.ChRemote;
import org.eolang.maven.hash.CommitHash;
import org.hamcrest.MatcherAssert;
Expand Down Expand Up @@ -76,4 +77,22 @@ void checksPresenceOfObject() throws IOException {
Matchers.is(true)
);
}

@Test
@ExtendWith(OnlineCondition.class)
void checksPresenceOfObjectWithNarrowHash() throws IOException {
final String stdout = "org.eolang.io.stdout";
MatcherAssert.assertThat(
String.format(
"OyRemote with narrow hash should have contained object %s, but it didn't",
stdout
),
new OyRemote(
new ChNarrow(
new ChRemote("master")
)
).contains(stdout),
Matchers.is(true)
);
}
}

4 comments on commit a0f2696

@0pdd
Copy link

@0pdd 0pdd commented on a0f2696 Jul 22, 2023

Choose a reason for hiding this comment

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

Puzzle 1602-d9e86093 discovered in eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java) and submitted as #2299. 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 a0f2696 Jul 22, 2023

Choose a reason for hiding this comment

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

Puzzle 1602-da3646cb discovered in eo-maven-plugin/src/main/java/org/eolang/maven/ProbeMojo.java) and submitted as #2300. 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 a0f2696 Jul 22, 2023

Choose a reason for hiding this comment

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

Puzzle 1602-046e3035 discovered in eo-maven-plugin/src/main/java/org/eolang/maven/ProbeMojo.java) and submitted as #2301. 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 a0f2696 Jul 22, 2023

Choose a reason for hiding this comment

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

Puzzle 1602-73bdd8c0 discovered in eo-maven-plugin/src/main/java/org/eolang/maven/ProbeMojo.java) and submitted as #2302. 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.