class AbstractModuleService implements ModuleServiceCore<T>,
                   ModuleFactory<T> {

    @Override
    public void delete(final Path pathToPomXML,
                       final String comment) {
        try {
            final org.uberfire.java.nio.file.Path projectDirectory = Paths.convert(pathToPomXML).getParent();
            final Module module2Delete = resourceResolver.resolveModule(Paths.convert(projectDirectory));

            final Optional<org.uberfire.java.nio.file.Path> parentPomPath =
                    ofNullable(projectDirectory).flatMap(dir -> ofNullable(dir.getParent()))
                                                .map(dir -> dir.resolve(POM_PATH))
                                                .filter(pom -> ioService.exists(pom));
            final Optional<POM> parentPom = parentPomPath.map(pom -> pomService.load(Paths.convert(pom)));


            // If this is the top module of the project, we should delete the whole repository.
            if (parentPomPath.isPresent() && parentPom.isPresent()) {
                //Note we do *not* raise a DeleteModuleEvent here, as that is handled by DeleteModuleObserverBridge
                ioService.delete(projectDirectory,
                                 StandardDeleteOption.NON_EMPTY_DIRECTORIES,
                                 commentedOptionFactory.makeCommentedOption(comment));

                org.uberfire.java.nio.file.Path pomPath = parentPomPath.get();
                POM pom = parentPom.get();
                pom.setPackaging("pom");
                pom.getModules().remove(module2Delete.getModuleName());
                pomService.save(Paths.convert(pomPath),
                                pom,
                                null,
                                "Removing child module " + module2Delete.getModuleName());
            } else {
                Repository repo = repoService.getRepository(Paths.convert(projectDirectory));
                repoService.removeRepository(repo.getSpace(), repo.getAlias());
            }
        } catch (final Exception e) {
            throw ExceptionUtilities.handleException(e);
        }
    }

    protected  AbstractModuleService();
    public  AbstractModuleService(final IOService ioService,
                                 final POMService pomService,
                                 final RepositoryService repoService,
                                 final Event<NewModuleEvent> newModuleEvent,
                                 final Event<NewPackageEvent> newPackageEvent,
                                 final Event<InvalidateDMOModuleCacheEvent> invalidateDMOCache,
                                 final SessionInfo sessionInfo,
                                 final CommentedOptionFactory commentedOptionFactory,
                                 final ModuleFinder moduleFinder,
                                 final ResourceResolver resourceResolver);

}