Repository: objectionary/eo
Issue: `keepBinaries` property is not respected in `UnplaceMojo`

Within `UnplaceMojo` we have config parameter `keepBinaries` which is supposed to prevent specified compiled (placed) files from removal. 
However current implementation ignore it since it calls consequently two steps:
1. `keepThem` step would remove everything but specified in `keepBinaries`
2. `killThem` step would remove everything with no respect to `keepBinaries`

Need to make `killThem` respect `keepBinaries` property.

Changed files:
eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceMojoTest.java
eo-maven-plugin/src/main/java/org/eolang/maven/UnplaceMojo.java

diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/UnplaceMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/UnplaceMojo.java
index fdbbe2150..8648526e6 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/UnplaceMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/UnplaceMojo.java
@@ -150,6 +150,10 @@ public final class UnplaceMojo extends SafeMojo {
                     related, tojo.get(PlaceMojo.ATTR_ORIGIN)
                 );
             }
+            if (UnplaceMojo.inside(related, this.keepBinaries)
+                && !UnplaceMojo.inside(related, this.removeBinaries)) {
+                continue;
+            }
             if (UnplaceMojo.delete(path)) {
                 unplaced += 1;
                 Logger.debug(
diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceMojoTest.java
index 5b68695c3..890b50a70 100644
--- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceMojoTest.java
+++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceMojoTest.java
@@ -25,6 +25,7 @@ package org.eolang.maven;
 
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import org.cactoos.set.SetOf;
 import org.hamcrest.MatcherAssert;
 import org.hamcrest.Matchers;
 import org.junit.jupiter.api.Test;
@@ -37,6 +38,10 @@ import org.junit.jupiter.api.io.TempDir;
  * @checkstyle LocalFinalVariableNameCheck (100 lines)
  */
 final class UnplaceMojoTest {
+    /**
+     * Value for 'class' ATTR_KIND.
+     */
+    private static final String ATTR_KIND_CLASS = "class";
 
     @Test
     void testCleaning(@TempDir final Path temp) throws Exception {
@@ -52,25 +57,25 @@ final class UnplaceMojoTest {
         final Path list = temp.resolve("placed.csv");
         Catalogs.INSTANCE.make(list)
             .add(foo.toString())
-            .set(PlaceMojo.ATTR_KIND, "class")
+            .set(PlaceMojo.ATTR_KIND, UnplaceMojoTest.ATTR_KIND_CLASS)
             .set(PlaceMojo.ATTR_RELATED, "---")
             .set(PlaceMojo.ATTR_ORIGIN, "some.jar")
             .set(PlaceMojo.ATTR_HASH, new FileHash(foo));
         Catalogs.INSTANCE.make(list)
             .add(foo2.toString())
-            .set(PlaceMojo.ATTR_KIND, "class")
+            .set(PlaceMojo.ATTR_KIND, UnplaceMojoTest.ATTR_KIND_CLASS)
             .set(PlaceMojo.ATTR_RELATED, "---")
             .set(PlaceMojo.ATTR_ORIGIN, "some.jar")
             .set(PlaceMojo.ATTR_HASH, new FileHash(foo2));
         Catalogs.INSTANCE.make(list)
             .add(foo3.toString())
-            .set(PlaceMojo.ATTR_KIND, "class")
+            .set(PlaceMojo.ATTR_KIND, UnplaceMojoTest.ATTR_KIND_CLASS)
             .set(PlaceMojo.ATTR_RELATED, "---")
             .set(PlaceMojo.ATTR_ORIGIN, "some.jar")
             .set(PlaceMojo.ATTR_HASH, new FileHash(foo3));
         Catalogs.INSTANCE.make(list)
             .add(foo4.toString())
-            .set(PlaceMojo.ATTR_KIND, "class")
+            .set(PlaceMojo.ATTR_KIND, UnplaceMojoTest.ATTR_KIND_CLASS)
             .set(PlaceMojo.ATTR_RELATED, "---")
             .set(PlaceMojo.ATTR_ORIGIN, "some.jar")
             .set(PlaceMojo.ATTR_HASH, new FileHash(foo4));
@@ -99,4 +104,59 @@ final class UnplaceMojoTest {
             Matchers.is(false)
         );
     }
+
+    @Test
+    void testKeepBinaries(@TempDir final Path temp) throws Exception {
+        final Path foo = temp.resolve("a/b/c/foo5.class");
+        new Home().save("testKeepBinaries", foo);
+        final Path pparent = foo.getParent().getParent();
+        final Path list = temp.resolve("placed.csv");
+        Catalogs.INSTANCE.make(list)
+            .add(foo.toString())
+            .set(PlaceMojo.ATTR_KIND, UnplaceMojoTest.ATTR_KIND_CLASS)
+            .set(PlaceMojo.ATTR_RELATED, "a/b/c/foo5.class")
+            .set(PlaceMojo.ATTR_ORIGIN, "some-keep.jar")
+            .set(PlaceMojo.ATTR_HASH, new FileHash(foo));
+        new Moja<>(UnplaceMojo.class)
+            .with("placed", list.toFile())
+            .with("placedFormat", "csv")
+            .with("keepBinaries", new SetOf<>("**foo5.class"))
+            .execute();
+        MatcherAssert.assertThat(
+            new Home().exists(foo),
+            Matchers.is(true)
+        );
+        MatcherAssert.assertThat(
+            new Home().exists(Paths.get(String.valueOf(pparent))),
+            Matchers.is(true)
+        );
+    }
+
+    @Test
+    void testKeepRemoveBinaries(@TempDir final Path temp) throws Exception {
+        final Path foo = temp.resolve("a/b/c/foo6.class");
+        new Home().save("testKeepRemoveBinaries", foo);
+        final Path pparent = foo.getParent().getParent();
+        final Path list = temp.resolve("placed.csv");
+        Catalogs.INSTANCE.make(list)
+            .add(foo.toString())
+            .set(PlaceMojo.ATTR_KIND, UnplaceMojoTest.ATTR_KIND_CLASS)
+            .set(PlaceMojo.ATTR_RELATED, "a/b/c/foo6.class")
+            .set(PlaceMojo.ATTR_ORIGIN, "some-keep-remove.jar")
+            .set(PlaceMojo.ATTR_HASH, new FileHash(foo));
+        new Moja<>(UnplaceMojo.class)
+            .with("placed", list.toFile())
+            .with("placedFormat", "csv")
+            .with("keepBinaries", new SetOf<>("**foo6.class"))
+            .with("removeBinaries", new SetOf<>("**foo6.class"))
+            .execute();
+        MatcherAssert.assertThat(
+            new Home().exists(foo),
+            Matchers.is(false)
+        );
+        MatcherAssert.assertThat(
+            new Home().exists(Paths.get(String.valueOf(pparent))),
+            Matchers.is(false)
+        );
+    }
 }