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 9, 2023
2 parents 9a37bdc + d3e9394 commit 6309ea9
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 42 deletions.
9 changes: 9 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.io.File;
import java.nio.file.Path;
import org.eolang.maven.name.ObjectName;

/**
* Make the place for the object.
Expand All @@ -38,6 +39,14 @@ public final class Place {
*/
private final String name;

/**
* Ctor.
* @param obj The name of the object
*/
public Place(final ObjectName obj) {
this(obj.toString());
}

/**
* Ctor.
* @param obj The name of the object
Expand Down
33 changes: 24 additions & 9 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@
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.ChNarrow;
import org.eolang.maven.hash.ChRemote;
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.objectionary.Objectionaries;
import org.eolang.maven.objectionary.ObjsDefault;
import org.eolang.maven.tojos.ForeignTojo;
Expand Down Expand Up @@ -94,12 +99,22 @@ public final class PullMojo extends SafeMojo {
@Override
public void exec() throws IOException {
if (this.hsh == null) {
this.hsh = new ChRemote(this.tag);
this.hsh = new ChCached(
new ChNarrow(
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(this.hsh));
final ObjectName name = new OnCached(
new OnSwap(
this.withVersions,
new OnDefault(tojo.identifier(), this.hsh)
)
);
tojo.withSource(this.pull(name).toAbsolutePath())
.withHash(new ChNarrow(name.hash()));
}
Logger.info(
this,
Expand All @@ -111,28 +126,28 @@ public void exec() throws IOException {
/**
* Pull one object.
*
* @param name Name of the object, e.g. "org.eolang.io.stdout"
* @param object Name of the object with/without version, e.g. "org.eolang.io.stdout#5f82cc1"
* @return The path of .eo file
* @throws IOException If fails
*/
private Path pull(final String name) throws IOException {
private Path pull(final ObjectName object) throws IOException {
final Path dir = this.targetDir.toPath().resolve(PullMojo.DIR);
final Path src = new Place(name).make(
final Path src = new Place(object).make(
dir, "eo"
);
if (src.toFile().exists() && !this.overWrite) {
Logger.debug(
this, "The object '%s' already pulled to %s (and 'overWrite' is false)",
name, new Rel(src)
object, new Rel(src)
);
} else {
new Home(dir).save(
this.objectionaries.object(this.hsh, name),
this.objectionaries.object(object),
dir.relativize(src)
);
Logger.debug(
this, "The sources of the object '%s' pulled to %s",
name, new Rel(src)
object, new Rel(src)
);
}
return src;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.io.IOException;
import org.cactoos.Input;
import org.eolang.maven.hash.CommitHash;
import org.eolang.maven.name.ObjectName;

/**
Expand All @@ -35,19 +34,18 @@
public interface Objectionaries {

/**
* Get object by hash and name.
* @param hash Commit hash
* Get an object by hash and name.
* @param name Object name
* @return Object
* @throws IOException If some I/O problem happens.
*/
Input object(CommitHash hash, String name) throws IOException;
Input object(ObjectName name) throws IOException;

/**
* Check if object exists.
* Check if an object exists.
*
* @param name Object name
* @return True if object exists, false otherwise
* @return True if an object exists, false otherwise
* @throws IOException If some I/O problem happens.
*/
boolean contains(ObjectName name) throws IOException;
Expand Down Expand Up @@ -80,8 +78,8 @@ public Fake(final Objectionary objry) {
}

@Override
public Input object(final CommitHash hash, final String name) throws IOException {
return this.objectionary.get(name);
public Input object(final ObjectName name) throws IOException {
return this.objectionary.get(name.value());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ private ObjsDefault(
}

@Override
public Input object(final CommitHash hash, final String name) throws IOException {
return this.objectionary(hash).get(name);
public Input object(final ObjectName name) throws IOException {
return this.objectionary(name.hash()).get(name.value());
}

@Override
Expand Down
65 changes: 42 additions & 23 deletions eo-maven-plugin/src/test/java/org/eolang/maven/PullMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.eolang.maven.util.Home;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -55,7 +54,7 @@
*
* @since 0.1
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"})
@ExtendWith(OnlineCondition.class)
final class PullMojoTest {
/**
Expand Down Expand Up @@ -181,21 +180,21 @@ void skipsPullMojo(@TempDir final Path temp) throws IOException {
@Test
void pullsVersionedObjectSuccessfully(@TempDir final Path temp) throws IOException {
final FakeMaven maven = new FakeMaven(temp);
maven.foreignTojos()
maven.externalTojos()
.add(new OnDefault(PullMojoTest.STDOUT, "9c93528"))
.withVersion("*.*.*");
maven.execute(PullMojo.class);
maven.with("withVersions", true)
.execute(PullMojo.class);
MatcherAssert.assertThat(
String.format(
"File by path %s should have existed after pulling, but it didn't",
PullMojoTest.path(PullMojoTest.VERSIONED.toString())
PullMojoTest.path(PullMojoTest.VERSIONED)
),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED.toString()),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED),
Matchers.is(true)
);
}

@Disabled
@Test
void pullsProbedVersionedObjectFromOneObjectionary(@TempDir final Path temp)
throws IOException {
Expand All @@ -214,62 +213,73 @@ 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.toString())
PullMojoTest.path(PullMojoTest.VERSIONED)
),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED.toString()),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED),
Matchers.is(true)
);
}

@Disabled
@Test
void pullsProbedVersionedObjectsFromDifferentObjectionaries(@TempDir final Path temp)
throws IOException {
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 CommitHash third = hashes.get("0.28.7");
final CommitHash first = hashes.get("0.28.4");
final CommitHash second = hashes.get("0.28.5");
final CommitHash third = hashes.get("0.28.6");
final CommitHash fourth = hashes.get("0.28.7");
new FakeMaven(temp)
.with(
"objectionaries",
new ObjsDefault(
new MapEntry<>(first, new OyRemote(first)),
new MapEntry<>(second, new OyRemote(second)),
new MapEntry<>(third, new OyRemote(third))
new MapEntry<>(third, new OyRemote(third)),
new MapEntry<>(fourth, new OyRemote(fourth))
)
)
.with("withVersions", true)
.with("hsh", third)
.with("hsh", fourth)
.withVersionedProgram()
.execute(new FakeMaven.Pull());
final ObjectName sprintf = new OnDefault("%s/org/eolang/io/sprintf", "17f892.eo");
final ObjectName string = new OnDefault("%s/org/eolang/string", "5f82cc.eo");
final ObjectName sprintf = new OnDefault("%s/org/eolang/txt/sprintf", "17f8929.eo");
final ObjectName string = new OnDefault("%s/org/eolang/string", "5f82cc1.eo");
MatcherAssert.assertThat(
String.format(
"File by path %s should have existed after pulling, but it didn't",
PullMojoTest.path(PullMojoTest.VERSIONED.toString())
PullMojoTest.path(PullMojoTest.VERSIONED)
),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED.toString()),
PullMojoTest.exists(temp, PullMojoTest.VERSIONED),
Matchers.is(true)
);
MatcherAssert.assertThat(
String.format(
"File by path %s should have existed after pulling, but it didn't",
PullMojoTest.path(sprintf.toString())
PullMojoTest.path(sprintf)
),
PullMojoTest.exists(temp, sprintf.toString()),
PullMojoTest.exists(temp, sprintf),
Matchers.is(true)
);
MatcherAssert.assertThat(
String.format(
"File by path %s should have existed after pulling, but it didn't",
PullMojoTest.path(string.toString())
PullMojoTest.path(string)
),
PullMojoTest.exists(temp, string.toString()),
PullMojoTest.exists(temp, string),
Matchers.is(true)
);
}

/**
* Check if the given source file exists in the target directory.
* @param temp Test temporary directory.
* @param source Source file as object name.
* @return If given source file exists.
*/
private static boolean exists(final Path temp, final ObjectName source) {
return PullMojoTest.exists(temp, source.toString());
}

/**
* Check if the given source file exists in the target directory.
*
Expand All @@ -283,6 +293,15 @@ private static boolean exists(final Path temp, final String source) {
);
}

/**
* Format given a source path.
* @param source Source path as object name.
* @return Formatted source path.
*/
private static String path(final ObjectName source) {
return PullMojoTest.path(source.toString());
}

/**
* Format given a source path.
* @param source Source path.
Expand Down

0 comments on commit 6309ea9

Please sign in to comment.