diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/PlaceMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/PlaceMojo.java index acc5ac5290..0bed8cc577 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/PlaceMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/PlaceMojo.java @@ -74,6 +74,11 @@ public final class PlaceMojo extends SafeMojo { */ public static final String ATTR_PLD_ORIGIN = "dependency"; + /** + * Attr in CSV. + */ + public static final String ATTR_PLD_UNPLACED = "unplaced"; + /** * Output. * @checkstyle MemberNameCheck (7 lines) @@ -205,7 +210,8 @@ private int place(final Path home, final String dep) throws IOException { this.outputDir.toString().length() + 1 ) ) - .set(PlaceMojo.ATTR_PLD_ORIGIN, dep); + .set(PlaceMojo.ATTR_PLD_ORIGIN, dep) + .set(PlaceMojo.ATTR_PLD_UNPLACED, "false"); ++copied; } if (copied > 0) { 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 5072425ecb..7a0bfc4a70 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 @@ -122,6 +122,8 @@ public void placeThem() throws IOException { * @param tojos All binaries found * @return Number of files deleted * @throws IOException If fails + * @todo #1319:30min If all .class files for a dependency are removed then + * unplaced attribute should be set to `true` for a dependency jar entry as well. */ private int killThem(final Iterable tojos) throws IOException { int unplaced = 0; @@ -156,6 +158,7 @@ private int killThem(final Iterable tojos) throws IOException { } if (UnplaceMojo.delete(path)) { unplaced += 1; + tojo.set(PlaceMojo.ATTR_PLD_UNPLACED, "true"); Logger.debug( this, "Binary %s of %s deleted", new Rel(path), tojo.get(PlaceMojo.ATTR_PLD_ORIGIN) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/PlaceMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/PlaceMojoTest.java index c4b0fd62d9..e6574700b5 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/PlaceMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/PlaceMojoTest.java @@ -65,6 +65,10 @@ void placesBinaries(@TempDir final Path temp) throws Exception { ); } + /** + * Test. + * @param temp Path to temp directory. + */ @Test void placesMissing(@TempDir final Path temp) throws Exception { final Path bins = temp.resolve(ResolveMojo.DIR); 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 bf5f49bf45..dc06168b55 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 @@ -38,6 +38,7 @@ * @since 0.1 * @checkstyle LocalFinalVariableNameCheck (100 lines) */ +@SuppressWarnings("PMD.AvoidDuplicateLiterals") final class UnplaceMojoTest { /** * Value for 'class' ATTR_KIND. @@ -162,4 +163,60 @@ void testKeepRemoveBinaries(@TempDir final Path temp) throws Exception { Matchers.is(false) ); } + + @Test + void testUnplaceRemoveBinaries(@TempDir final Path temp) throws Exception { + final Path foo = temp.resolve("a/b/c/foo6.class"); + new Home().save("testUnplaceRemoveBinaries", foo); + final Path list = temp.resolve("placed.csv"); + Catalogs.INSTANCE.make(list) + .add(foo.toString()) + .set(PlaceMojo.ATTR_PLD_KIND, UnplaceMojoTest.ATTR_KIND_CLASS) + .set(PlaceMojo.ATTR_PLD_RELATED, "a/b/c/foo6.class") + .set(PlaceMojo.ATTR_PLD_ORIGIN, "some-keep-remove.jar") + .set(PlaceMojo.ATTR_PLD_HASH, new FileHash(foo)) + .set(PlaceMojo.ATTR_PLD_UNPLACED, "false"); + new Moja<>(UnplaceMojo.class) + .with("placed", list.toFile()) + .with("placedFormat", "csv") + .with("removeBinaries", new SetOf<>("**foo6.class")) + .execute(); + final Path placed = temp.resolve("placed.csv"); + MatcherAssert.assertThat( + Files.readString(placed).contains("false"), + Matchers.is(false) + ); + MatcherAssert.assertThat( + Files.readString(placed).contains("true"), + Matchers.is(true) + ); + } + + @Test + void testUnplaceKeepBinaries(@TempDir final Path temp) throws Exception { + final Path foo = temp.resolve("a/b/c/foo6.class"); + new Home().save("testUnplaceKeepBinaries", foo); + final Path list = temp.resolve("placed.csv"); + Catalogs.INSTANCE.make(list) + .add(foo.toString()) + .set(PlaceMojo.ATTR_PLD_KIND, UnplaceMojoTest.ATTR_KIND_CLASS) + .set(PlaceMojo.ATTR_PLD_RELATED, "a/b/c/foo6.class") + .set(PlaceMojo.ATTR_PLD_ORIGIN, "some-keep-remove.jar") + .set(PlaceMojo.ATTR_PLD_HASH, new FileHash(foo)) + .set(PlaceMojo.ATTR_PLD_UNPLACED, "false"); + new Moja<>(UnplaceMojo.class) + .with("placed", list.toFile()) + .with("placedFormat", "csv") + .with("keepBinaries", new SetOf<>("**foo6.class")) + .execute(); + final Path placed = temp.resolve("placed.csv"); + MatcherAssert.assertThat( + Files.readString(placed).contains("false"), + Matchers.is(true) + ); + MatcherAssert.assertThat( + Files.readString(placed).contains("true"), + Matchers.is(false) + ); + } }