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 10, 2023
2 parents 6281849 + 9eed2b4 commit d6696e1
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.cactoos.experimental.Threads;
import org.cactoos.iterable.Filtered;
import org.cactoos.iterable.Mapped;
import org.cactoos.number.SumOf;
import org.eolang.maven.rust.BuildFailureException;

/**
Expand All @@ -45,9 +49,6 @@
* Now it copies cargo project to cache directory in the end of every
* compilation. It is better to copy the project only if it was changed
* with the last compilation.
* @todo #2195:90min Make cargo compilation in parallel. Now cargo
* projects are being built consistently which is too long.
* It is much better to build them in parallel to reduce time.
*/
@Mojo(
name = "binarize",
Expand Down Expand Up @@ -77,11 +78,35 @@ public final class BinarizeMojo extends SafeMojo {
@Override
public void exec() throws IOException {
new Moja<>(BinarizeParseMojo.class).copy(this).execute();
for (final File project: targetDir.toPath().resolve("Lib").toFile().listFiles()) {
if (project.isDirectory() && project.toPath().resolve("Cargo.toml").toFile().exists()) {
this.build(project);
}
}
final int total = new SumOf(
new Threads<>(
Runtime.getRuntime().availableProcessors(),
new Mapped<>(
project -> () -> {
this.build(project);
return 1;
},
new Filtered<>(
project -> BinarizeMojo.valid(project),
targetDir.toPath().resolve("Lib").toFile().listFiles()
)
)
)
).intValue();
Logger.info(
this,
String.format("Built in total %d cargo projects", total)
);
}

/**
* Is the project valid?
* @param project File to check.
* @return True if valid. Otherwise false.
*/
private static boolean valid(final File project) {
return project.isDirectory()
&& project.toPath().resolve("Cargo.toml").toFile().exists();
}

/**
Expand All @@ -91,7 +116,7 @@ public void exec() throws IOException {
*/
private void build(final File project) throws IOException {
final File target = project.toPath().resolve("target").toFile();
final File cached = cache
final File cached = this.cache
.resolve("Lib")
.resolve(project.getName())
.resolve("target").toFile();
Expand All @@ -117,16 +142,6 @@ private void build(final File project) throws IOException {
)
) {
proc.stdout();
proc.waitFor();
} catch (final InterruptedException exception) {
Thread.currentThread().interrupt();
throw new BuildFailureException(
String.format(
"Interrupted while building %s",
project
),
exception
);
} catch (final IllegalArgumentException exc) {
throw new BuildFailureException(
String.format(
Expand Down

1 comment on commit d6696e1

@0pdd
Copy link

@0pdd 0pdd commented on d6696e1 Jul 10, 2023

Choose a reason for hiding this comment

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

Puzzle 2195-24c0d5f1 disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java), that's why I closed #2208. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.