Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1319 mark unplaced #1330

Closed
wants to merge 9 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tojo> tojos) throws IOException {
int unplaced = 0;
Expand Down Expand Up @@ -156,6 +158,7 @@ private int killThem(final Iterable<Tojo> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ void placesBinaries(@TempDir final Path temp) throws Exception {
);
}

/**
* Test.
* @param temp Path to temp directory.
* @todo #1319:30min Why do we need lines 85-87 in this test?
OlesiaSub marked this conversation as resolved.
Show resolved Hide resolved
* They don't check anything and the test passes if these lines are commented out anyway.
* Either the test is written incorrectly and assumes that
* these lines affect its behaviour or they can be removed.
*/
@Test
void placesMissing(@TempDir final Path temp) throws Exception {
final Path bins = temp.resolve(ResolveMojo.DIR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @since 0.1
* @checkstyle LocalFinalVariableNameCheck (100 lines)
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
final class UnplaceMojoTest {
/**
* Value for 'class' ATTR_KIND.
Expand Down Expand Up @@ -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)
);
}
}