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
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions eo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ SOFTWARE.
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
OlesiaSub marked this conversation as resolved.
Show resolved Hide resolved
</plugin>
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public final class PlaceMojo extends SafeMojo {
*/
public static final String ATTR_HASH = "hash";

/**
* Attr in CSV.
*/
public static final String ATTR_UNPLACED = "unplaced";

/**
* Where the binary is coming from (JAR name).
*/
Expand Down Expand Up @@ -202,7 +207,8 @@ private int place(final Path home, final String dep) throws IOException {
this.outputDir.toString().length() + 1
)
)
.set(PlaceMojo.ATTR_ORIGIN, dep);
.set(PlaceMojo.ATTR_ORIGIN, dep)
.set(PlaceMojo.ATTR_UNPLACED, "false");
++copied;
}
if (copied > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void placeThem() throws IOException {
deleted += this.killThem(tojos);
if (tojos.isEmpty()) {
Logger.info(
this, "No binaries were placed into %s, nothing to uplace",
this, "No binaries were placed into %s, nothing to unplace",
new Home().rel(this.placed.toPath())
);
} else if (deleted == 0) {
Expand All @@ -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_UNPLACED, "true");
Logger.debug(
this, "Binary %s of %s deleted",
new Home().rel(path), tojo.get(PlaceMojo.ATTR_ORIGIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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 @@ -23,6 +23,7 @@
*/
package org.eolang.maven;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.cactoos.set.SetOf;
Expand All @@ -37,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 @@ -159,4 +161,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_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))
.set(PlaceMojo.ATTR_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_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))
.set(PlaceMojo.ATTR_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)
);
}
}