From 7ac62d563f4c37eaec8521d7dcaef50b643335ff Mon Sep 17 00:00:00 2001
From: levBagryansky <28lev11@gmail.com>
Date: Mon, 11 Sep 2023 16:15:36 +0300
Subject: [PATCH 1/8] #2492: Fixed bug related to caching.
---
.../java/org/eolang/maven/BinarizeMojo.java | 8 +++--
.../org/eolang/maven/BinarizeMojoTest.java | 35 +++++++++++++++++++
2 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
index 5982979b3a..010e442a7d 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
@@ -194,9 +194,11 @@ private static boolean sameFile(final Path src, final Path cached) {
new TextOf(src)
).asString()
).equals(
- new UncheckedText(
- new TextOf(cached)
- ).asString()
+ BinarizeMojo.uncomment(
+ new UncheckedText(
+ new TextOf(cached)
+ ).asString()
+ )
);
}
diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java
index 5ae47e39f3..e4a176fab1 100644
--- a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java
+++ b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java
@@ -23,10 +23,12 @@
*/
package org.eolang.maven;
+import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
+import org.apache.commons.lang3.SystemUtils;
import org.eolang.maven.rust.Names;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
@@ -139,4 +141,37 @@ void boostsSecondCompilation(@TempDir final Path temp) throws IOException {
Matchers.lessThan(first)
);
}
+
+ @Test
+ @Tag("slow")
+ void doesNotRecompile(@TempDir final Path temp) throws IOException {
+ final FakeMaven maven;
+ final Path cache = temp.resolve(".cache");
+ synchronized (BinarizeMojoTest.class) {
+ maven = new FakeMaven(temp)
+ .withProgram(BinarizeMojoTest.SRC.resolve("simple-rust.eo"))
+ .with("cache", cache);
+ }
+ maven.execute(new FakeMaven.Binarize());
+ final String lib;
+ if (SystemUtils.IS_OS_WINDOWS) {
+ lib = "common.dll";
+ } else if (SystemUtils.IS_OS_LINUX) {
+ lib = "libcommon.so";
+ } else {
+ lib = "libcommon.dylib";
+ }
+ final File executable = cache
+ .resolve("Lib/native0/target/debug/")
+ .resolve(lib)
+ .toFile();
+ final long first = executable.lastModified();
+ maven.execute(new FakeMaven.Binarize());
+ final long second = executable.lastModified();
+ MatcherAssert.assertThat(first, Matchers.not(0L));
+ MatcherAssert.assertThat(
+ second,
+ Matchers.equalTo(first)
+ );
+ }
}
From 66ec7ee46d5ce2767cb8555831d312353290ef95 Mon Sep 17 00:00:00 2001
From: levBagryansky <28lev11@gmail.com>
Date: Mon, 11 Sep 2023 17:57:14 +0300
Subject: [PATCH 2/8] #2263: Copy executable file only.
---
eo-maven-plugin/pom.xml | 1 -
.../java/org/eolang/maven/BinarizeMojo.java | 49 ++++++++++++++++---
2 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/eo-maven-plugin/pom.xml b/eo-maven-plugin/pom.xml
index 86901a4705..38c7279ec6 100644
--- a/eo-maven-plugin/pom.xml
+++ b/eo-maven-plugin/pom.xml
@@ -205,7 +205,6 @@ SOFTWARE.
org.apache.commons
commons-lang3
3.13.0
- test
commons-io
diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
index 010e442a7d..451cf6a1bb 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
@@ -30,6 +30,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.SystemUtils;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
@@ -54,9 +55,31 @@
threadSafe = true,
requiresDependencyResolution = ResolutionScope.COMPILE
)
-@SuppressWarnings("PMD.LongVariable")
+@SuppressWarnings({"PMD.LongVariable", "PMD.StaticAccessToStaticFields"})
public final class BinarizeMojo extends SafeMojo {
+ /**
+ * Name of executable file which is result of cargo building.
+ */
+ public static final String LIB;
+
+ static {
+ if (SystemUtils.IS_OS_WINDOWS) {
+ LIB = "common.dll";
+ } else if (SystemUtils.IS_OS_LINUX) {
+ LIB = "libcommon.so";
+ } else if (SystemUtils.IS_OS_MAC) {
+ LIB = "libcommon.dylib";
+ } else {
+ throw new IllegalArgumentException(
+ String.format(
+ "Rust inserts are not supported by %s os. Only windows, linux and macos are allowed.",
+ System.getProperty("os.name")
+ )
+ );
+ }
+ }
+
/**
* The directory where to binarize to.
*/
@@ -123,15 +146,10 @@ private static boolean valid(final File project) {
* @throws IOException If any issues with IO.
*/
private void build(final File project) throws IOException {
- final File target = project.toPath().resolve("target").toFile();
final File cached = this.cache
.resolve("Lib")
.resolve(project.getName())
.resolve("target").toFile();
- if (cached.exists()) {
- Logger.info(this, "Copying %s to %s", cached, target);
- FileUtils.copyDirectory(cached, target);
- }
if (BinarizeMojo.sameProject(
project.toPath(),
this.cache
@@ -143,7 +161,26 @@ private void build(final File project) throws IOException {
"content of %s was not changed since the last launch",
project.getName()
);
+ final File executable = cached.toPath()
+ .resolve("debug")
+ .resolve(BinarizeMojo.LIB)
+ .toFile();
+ if (executable.exists()) {
+ FileUtils.copyFile(
+ executable,
+ project.toPath()
+ .resolve("target")
+ .resolve("debug")
+ .resolve(BinarizeMojo.LIB)
+ .toFile()
+ );
+ }
} else {
+ final File target = project.toPath().resolve("target").toFile();
+ if (cached.exists()) {
+ Logger.info(this, "Copying %s to %s", cached, target);
+ FileUtils.copyDirectory(cached, target);
+ }
Logger.info(this, "Building %s rust project..", project.getName());
try {
new Jaxec("cargo", "build").withHome(project).execUnsafe();
From 322741e72e0b7bc38461c6f4993d10f415b56a12 Mon Sep 17 00:00:00 2001
From: levBagryansky <28lev11@gmail.com>
Date: Mon, 11 Sep 2023 17:58:12 +0300
Subject: [PATCH 3/8] #2263: Edited log.info to make it clearer.
---
.../src/main/java/org/eolang/maven/BinarizeParseMojo.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java
index 9e17788ebc..46a62cf144 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java
@@ -157,7 +157,7 @@ public void exec() throws IOException {
this,
"Binarized %s from %s",
filename,
- input.xpath("/program/@name").get(0)
+ node.xpath("@code_loc").get(0)
);
new Project(this.targetDir.toPath().resolve("Lib/".concat(function)))
.with(new Module(code, "src/foo"), dependencies)
From ac5831d422fba1ee9e6e916444725a0ef53d9e0d Mon Sep 17 00:00:00 2001
From: levBagryansky <28lev11@gmail.com>
Date: Mon, 11 Sep 2023 17:59:57 +0300
Subject: [PATCH 4/8] #2263: Improved the test
---
.../test/java/org/eolang/maven/BinarizeMojoTest.java | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java
index e4a176fab1..1846bdf1de 100644
--- a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java
+++ b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java
@@ -28,7 +28,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
-import org.apache.commons.lang3.SystemUtils;
import org.eolang.maven.rust.Names;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
@@ -153,17 +152,9 @@ void doesNotRecompile(@TempDir final Path temp) throws IOException {
.with("cache", cache);
}
maven.execute(new FakeMaven.Binarize());
- final String lib;
- if (SystemUtils.IS_OS_WINDOWS) {
- lib = "common.dll";
- } else if (SystemUtils.IS_OS_LINUX) {
- lib = "libcommon.so";
- } else {
- lib = "libcommon.dylib";
- }
final File executable = cache
.resolve("Lib/native0/target/debug/")
- .resolve(lib)
+ .resolve(BinarizeMojo.LIB)
.toFile();
final long first = executable.lastModified();
maven.execute(new FakeMaven.Binarize());
From e24f541b58feca650ab1f50ca76249b8f5cb7f25 Mon Sep 17 00:00:00 2001
From: levBagryansky <28lev11@gmail.com>
Date: Mon, 11 Sep 2023 18:05:59 +0300
Subject: [PATCH 5/8] #2263: Edited log message again
---
.../src/main/java/org/eolang/maven/BinarizeParseMojo.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java
index 46a62cf144..0c59bf10d7 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java
@@ -155,8 +155,9 @@ public void exec() throws IOException {
);
Logger.info(
this,
- "Binarized %s from %s",
+ "Binarized %s from %s:%s",
filename,
+ input.xpath("/program/@name").get(0),
node.xpath("@code_loc").get(0)
);
new Project(this.targetDir.toPath().resolve("Lib/".concat(function)))
From a40586231159e54003dd2ef54f6e44710924716b Mon Sep 17 00:00:00 2001
From: levBagryansky <28lev11@gmail.com>
Date: Tue, 12 Sep 2023 11:53:29 +0300
Subject: [PATCH 6/8] #2263: Edited exception message
---
.../src/main/java/org/eolang/maven/BinarizeMojo.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
index 451cf6a1bb..66a9042a55 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
@@ -73,7 +73,7 @@ public final class BinarizeMojo extends SafeMojo {
} else {
throw new IllegalArgumentException(
String.format(
- "Rust inserts are not supported by %s os. Only windows, linux and macos are allowed.",
+ "Rust inserts are not supported in %s os. Only windows, linux and macos are allowed.",
System.getProperty("os.name")
)
);
From aa292f07ee270835273e28125544f0a6154e82c4 Mon Sep 17 00:00:00 2001
From: levBagryansky <28lev11@gmail.com>
Date: Mon, 2 Oct 2023 13:05:57 +0300
Subject: [PATCH 7/8] #2263: Replaced static section by private static method
---
.../java/org/eolang/maven/BinarizeMojo.java | 42 +++++++++++--------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
index 66a9042a55..23e92fec4a 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
@@ -61,24 +61,7 @@ public final class BinarizeMojo extends SafeMojo {
/**
* Name of executable file which is result of cargo building.
*/
- public static final String LIB;
-
- static {
- if (SystemUtils.IS_OS_WINDOWS) {
- LIB = "common.dll";
- } else if (SystemUtils.IS_OS_LINUX) {
- LIB = "libcommon.so";
- } else if (SystemUtils.IS_OS_MAC) {
- LIB = "libcommon.dylib";
- } else {
- throw new IllegalArgumentException(
- String.format(
- "Rust inserts are not supported in %s os. Only windows, linux and macos are allowed.",
- System.getProperty("os.name")
- )
- );
- }
- }
+ public static final String LIB = BinarizeMojo.common();
/**
* The directory where to binarize to.
@@ -130,6 +113,29 @@ public void exec() throws IOException {
Logger.info(this, "Built in total %d cargo projects", total);
}
+ /**
+ * Calculates name for Rust shared library depending on OS.
+ * @return Name.
+ */
+ private static String common() {
+ final String result;
+ if (SystemUtils.IS_OS_WINDOWS) {
+ result = "common.dll";
+ } else if (SystemUtils.IS_OS_LINUX) {
+ result = "libcommon.so";
+ } else if (SystemUtils.IS_OS_MAC) {
+ result = "libcommon.dylib";
+ } else {
+ throw new IllegalArgumentException(
+ String.format(
+ "Rust inserts are not supported in %s os. Only windows, linux and macos are allowed.",
+ System.getProperty("os.name")
+ )
+ );
+ }
+ return result;
+ }
+
/**
* Is the project valid?
* @param project File to check.
From 8a40156a7dc07c7095bb6c87f7e4cb44a1e43f37 Mon Sep 17 00:00:00 2001
From: levBagryansky <28lev11@gmail.com>
Date: Mon, 2 Oct 2023 13:39:00 +0300
Subject: [PATCH 8/8] #2263: Removed pmd suppress warning
---
.../src/main/java/org/eolang/maven/BinarizeMojo.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
index 23e92fec4a..a85d388fe0 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeMojo.java
@@ -55,7 +55,7 @@
threadSafe = true,
requiresDependencyResolution = ResolutionScope.COMPILE
)
-@SuppressWarnings({"PMD.LongVariable", "PMD.StaticAccessToStaticFields"})
+@SuppressWarnings("PMD.LongVariable")
public final class BinarizeMojo extends SafeMojo {
/**