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 28, 2023
2 parents ed4c55e + 2da11e4 commit 032cd80
Show file tree
Hide file tree
Showing 12 changed files with 423 additions and 130 deletions.
17 changes: 12 additions & 5 deletions eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
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.objectionary.Objectionary;
import org.eolang.maven.objectionary.Objectionaries;
import org.eolang.maven.objectionary.ObjsDefault;

/**
* Pull all necessary EO XML files from Objectionary and parse them all.
Expand Down Expand Up @@ -65,10 +66,11 @@ public final class AssembleMojo extends SafeMojo {
private File outputDir;

/**
* The objectionary.
* Objectionaries.
* @checkstyle MemberNameCheck (6 lines)
* @checkstyle ConstantUsageCheck (5 lines)
*/
@SuppressWarnings("PMD.ImmutableField")
private Objectionary objectionary;
private final Objectionaries objectionaries = new ObjsDefault();

/**
* The central.
Expand All @@ -85,8 +87,13 @@ public final class AssembleMojo extends SafeMojo {
private boolean overWrite;

/**
* The Git hash to pull objects from, in objectionary.
* The Git tag to pull objects from, in objectionary.
* @since 0.21.0
* @todo #2302:30min Rename the parameter "hash". This parameter is actually
* a tag, not a hash. By this tag application actually finds hash and then
* uses it. So need to rename this parameter to "tag" and rename it in all
* places where it's used. Also it would be better to use name "hash" for
* parameter "hsh" in {@link ProbeMojo} and {@link PullMojo}
*/
@SuppressWarnings("PMD.ImmutableField")
@Parameter(property = "eo.hash", required = true, defaultValue = "master")
Expand Down
69 changes: 21 additions & 48 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,20 +29,20 @@
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.ChRemote;
import org.eolang.maven.hash.CommitHash;
import org.eolang.maven.objectionary.Objectionaries;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.objectionary.ObjsDefault;
import org.eolang.maven.objectionary.OyFallbackSwap;
import org.eolang.maven.objectionary.OyHome;
import org.eolang.maven.objectionary.OyIndexed;
Expand Down Expand Up @@ -71,7 +71,7 @@
)
public final class ProbeMojo extends SafeMojo {
/**
* The Git hash to pull objects from, in objectionary.
* The Git tag to pull objects from, in objectionary.
*
* @since 0.21.0
*/
Expand All @@ -80,50 +80,24 @@ public final class ProbeMojo extends SafeMojo {
private String tag = "master";

/**
* Read hashes from local file.
*
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(property = "offlineHashFile")
private Path offlineHashFile;

/**
* Return hash by pattern.
* -DofflineHash=0.*.*:abc2sd3
* -DofflineHash=0.2.7:abc2sd3,0.2.8:s4se2fe
* The Git hash to pull objects from, in objectionary.
* If not set, will be computed from {@code tag} field.
*
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(property = "offlineHash")
private String offlineHash;

/**
* The objectionary.
* @since 0.29.6
*/
@SuppressWarnings("PMD.ImmutableField")
private Objectionary objectionary;
private CommitHash hsh;

/**
* 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.
* Objectionaries.
* @checkstyle MemberNameCheck (5 lines)
*/
private final Map<String, Objectionary> objectionaries = new HashMap<>();
private final Objectionaries objectionaries = new ObjsDefault();

@Override
public void exec() throws IOException {
final CommitHash hash = new ChCached(
new ChCompound(
this.offlineHashFile, this.offlineHash, this.tag
)
);
if (this.objectionary == null) {
this.objectionary = this.objectionaryByHash(hash);
if (this.hsh == null) {
this.hsh = new ChRemote(this.tag);
}
final Collection<String> probed = new HashSet<>(1);
final Collection<ForeignTojo> tojos = this.scopedTojos().unprobed();
Expand All @@ -135,7 +109,7 @@ public void exec() throws IOException {
}
int count = 0;
for (final String name : names) {
if (!this.objectionary.contains(name)) {
if (!this.objectionaryByHash(this.hsh).contains(name)) {
continue;
}
++count;
Expand All @@ -144,7 +118,7 @@ public void exec() throws IOException {
.withDiscoveredAt(src);
probed.add(name);
}
tojo.withHash(new ChNarrow(hash)).withProbed(count);
tojo.withHash(new ChNarrow(this.hsh)).withProbed(count);
}
if (tojos.isEmpty()) {
if (this.scopedTojos().size() == 0) {
Expand All @@ -171,10 +145,10 @@ public void exec() throws IOException {
* @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,
final CommitHash cached = new ChCached(hash);
return this.objectionaries
.with(
cached,
new OyFallbackSwap(
new OyHome(
new ChNarrow(hash),
Expand All @@ -183,11 +157,10 @@ private Objectionary objectionaryByHash(final CommitHash hash) {
new OyIndexed(
new OyRemote(hash)
),
this.forceUpdate()
this::forceUpdate
)
);
}
return this.objectionaries.get(value);
)
.get(cached);
}

/**
Expand Down
69 changes: 24 additions & 45 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,16 +27,16 @@
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.ChRemote;
import org.eolang.maven.hash.CommitHash;
import org.eolang.maven.objectionary.Objectionaries;
import org.eolang.maven.objectionary.Objectionary;
import org.eolang.maven.objectionary.ObjsDefault;
import org.eolang.maven.objectionary.OyCaching;
import org.eolang.maven.objectionary.OyFallbackSwap;
import org.eolang.maven.objectionary.OyHome;
Expand All @@ -63,7 +63,7 @@ public final class PullMojo extends SafeMojo {
public static final String DIR = "3-pull";

/**
* The Git hash to pull objects from, in objectionary.
* The Git tag to pull objects from, in objectionary.
*
* @since 0.21.0
*/
Expand All @@ -72,31 +72,16 @@ public final class PullMojo extends SafeMojo {
private String tag = "master";

/**
* Read hashes from local file.
*
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(property = "offlineHashFile")
private Path offlineHashFile;

/**
* Return hash by pattern.
* -DofflineHash=0.*.*:abc2sd3
* -DofflineHash=0.2.7:abc2sd3,0.2.8:s4se2fe
* The Git hash to pull objects from, in objectionary.
* If not set, will be computed from {@code tag} field.
*
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(property = "offlineHash")
private String offlineHash;

/**
* The objectionary.
* @since 0.29.6
*/
@SuppressWarnings("PMD.ImmutableField")
private Objectionary objectionary;
private CommitHash hsh;

/**
* Hash-Objectionary map.
* Objectionaries.
* @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.
Expand All @@ -105,7 +90,7 @@ public final class PullMojo extends SafeMojo {
* objectionary by name.
* @checkstyle MemberNameCheck (5 lines)
*/
private final Map<String, Objectionary> objectionaries = new HashMap<>();
private final Objectionaries objectionaries = new ObjsDefault();

/**
* Pull again even if the .eo file is already present?
Expand All @@ -118,22 +103,17 @@ public final class PullMojo extends SafeMojo {

@Override
public void exec() throws IOException {
final CommitHash hash = new ChCached(
new ChCompound(
this.offlineHashFile, this.offlineHash, this.tag
)
);
if (this.objectionary == null) {
this.objectionary = this.objectionaryByHash(hash);
if (this.hsh == null) {
this.hsh = new ChRemote(this.tag);
}
final Collection<ForeignTojo> tojos = this.scopedTojos().withoutSources();
for (final ForeignTojo tojo : tojos) {
tojo.withSource(this.pull(tojo.identifier()).toAbsolutePath())
.withHash(new ChNarrow(hash));
.withHash(new ChNarrow(this.hsh));
}
Logger.info(
this, "%d program(s) pulled from %s",
tojos.size(), this.objectionary
tojos.size(), this.objectionaryByHash(this.hsh)
);
}

Expand All @@ -143,11 +123,11 @@ public void exec() throws IOException {
* @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,
final CommitHash cached = new ChCached(hash);
final CommitHash narrow = new ChNarrow(cached);
return this.objectionaries
.with(
cached,
new OyFallbackSwap(
new OyHome(
narrow,
Expand All @@ -157,14 +137,13 @@ private Objectionary objectionaryByHash(final CommitHash hash) {
narrow,
this.cache,
new OyIndexed(
new OyRemote(hash)
new OyRemote(cached)
)
),
this.session.getRequest().isUpdateSnapshots()
() -> this.session.getRequest().isUpdateSnapshots()
)
);
}
return this.objectionaries.get(value);
)
.get(cached);
}

/**
Expand All @@ -186,7 +165,7 @@ name, new Rel(src)
);
} else {
new Home(dir).save(
this.objectionary.get(name),
this.objectionaryByHash(this.hsh).get(name),
dir.relativize(src)
);
Logger.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class ChConstant implements CommitHash {
*
* @param hash Hardcoded value.
*/
ChConstant(final String hash) {
public ChConstant(final String hash) {
this.hash = hash;
}

Expand Down
Loading

6 comments on commit 032cd80

@0pdd
Copy link

@0pdd 0pdd commented on 032cd80 Jul 28, 2023

Choose a reason for hiding this comment

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

Puzzle 1602-73bdd8c0 disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/ProbeMojo.java), that's why I closed #2302. 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 032cd80 Jul 28, 2023

Choose a reason for hiding this comment

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

Puzzle 2302-7adb5af1 discovered in eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java) and submitted as #2327. 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 032cd80 Jul 28, 2023

Choose a reason for hiding this comment

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

Puzzle 2302-25a30f7e discovered in eo-maven-plugin/src/test/java/org/eolang/maven/ProbeMojoTest.java) and submitted as #2328. 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 032cd80 Jul 28, 2023

Choose a reason for hiding this comment

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

Puzzle 2302-40705385 discovered in eo-maven-plugin/src/test/java/org/eolang/maven/ProbeMojoTest.java) and submitted as #2329. 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 032cd80 Jul 28, 2023

Choose a reason for hiding this comment

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

Puzzle 2302-8638ac29 discovered in eo-maven-plugin/src/test/java/org/eolang/maven/ProbeMojoTest.java) and submitted as #2330. 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 032cd80 Jul 28, 2023

Choose a reason for hiding this comment

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

Puzzle 2302-4b0bd16e discovered in eo-maven-plugin/src/test/java/org/eolang/maven/ProbeMojoTest.java) and submitted as #2331. 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.