eo icon indicating copy to clipboard operation
eo copied to clipboard

eo-maven-plugin:clean

Open yegor256 opened this issue 2 years ago • 17 comments

Let's add a new goal to our Maven plugin: clean. It should simply delete the directory target/eo (which is configurable through Maven property) and report about it in the log.

yegor256 avatar Aug 18 '22 04:08 yegor256

@Graur please, take care of this

yegor256 avatar Aug 18 '22 04:08 yegor256

@includealex please, take this task

Graur avatar Aug 19 '22 13:08 Graur

@includealex First you need to create a new Mojo, let's call it CleanMojo. Then pay attention to how ResolveMojo class store files in target/eo directory. Then implement in you new CleanMojo deleting of this directory (maybe also UnplaceMojo help you with this). And finally, place this new goal in AssembleMojo

Graur avatar Aug 19 '22 13:08 Graur

@Graur sure.

includealex avatar Aug 20 '22 11:08 includealex

@l3r8yJ Can you help us here?

Graur avatar Sep 19 '22 12:09 Graur

@Graur yeah

l3r8yJ avatar Sep 19 '22 12:09 l3r8yJ

@Graur

@Mojo(
    name = "clean",
    defaultPhase = LifecyclePhase.CLEAN,
    threadSafe = true
)
public class CleanMojo extends SafeMojo {

    @Override
    void exec() throws IOException {
        try (Stream<Path> paths = Files.walk(this.targetDir.toPath())) {
            paths
                .sorted(Comparator.reverseOrder())
                .map(Path::toFile)
                .forEach(File::delete);
        }
    }
}

can i use try with resource in this way?

l3r8yJ avatar Sep 19 '22 13:09 l3r8yJ

@l3r8yJ Sure

Graur avatar Sep 19 '22 13:09 Graur

@Graur what should I write in the javadoc tag @since x.x.x instead of x.x.x?

l3r8yJ avatar Sep 19 '22 13:09 l3r8yJ

@l3r8yJ The next EO version

Graur avatar Sep 19 '22 13:09 Graur

@Graur 0.28.6, right?

l3r8yJ avatar Sep 19 '22 14:09 l3r8yJ

@l3r8yJ Yep, 0.28.6

Graur avatar Sep 19 '22 14:09 Graur

@Graur In AssembleMojo i should put my CleanMojo to

final Moja<?>[] mojas = {
    new Moja<>(ParseMojo.class),
    new Moja<>(OptimizeMojo.class),
    new Moja<>(DiscoverMojo.class),
    new Moja<>(PullMojo.class),
    new Moja<>(ResolveMojo.class),
    new Moja<>(MarkMojo.class),
    new Moja<>(PlaceMojo.class),
    new Moja<>(CleanMojo.class), // here or we got mojo which turns on after we have built and tested? 
};

l3r8yJ avatar Sep 19 '22 14:09 l3r8yJ

@l3r8yJ Maybe we don't need to put it in AssembleMojo. We can make this CleanMojo as optional configuration. @yegor256 What do you think?

Graur avatar Sep 19 '22 14:09 Graur

@yegor256 @Graur eo:clean should be a standalone command, a very simple one, just deleting eo/target. It has nothing to do with other commands.

yegor256 avatar Sep 19 '22 14:09 yegor256

@yegor256 got you

l3r8yJ avatar Sep 19 '22 14:09 l3r8yJ

@yegor256 @Graur do we have more separate plugin commands so I can see an example of how to make it?

UPD: found in qulice irrelevant now.

l3r8yJ avatar Sep 19 '22 14:09 l3r8yJ