class OpearPackageMojo extends AbstractCommonMojo {

    Result<List<String>> shrinkWrapPlans(final @NotNull File toDir) {
        final Result<List<OakpalPlan>> initialResult =
                !(planFile != null && planFile.isFile())
                        ? Result.success(new ArrayList<>())
                        : Result.success(planFile)
                        .flatMap(compose1(File::toURI, result1(URI::toURL)))
                        .flatMap(OakpalPlan::fromJson)
                        .map(compose1(Collections::singletonList, ArrayList::new));

        final Result<List<OakpalPlan>> addedResult = initialResult.flatMap(plans ->
                additionalPlans.stream()
                        .map(compose1(File::toURI, result1(URI::toURL)))
                        .collect(Result.tryCollect(Collectors.toList()))
                        .flatMap(planUrls -> planUrls.stream()
                                .map(OakpalPlan::fromJson)
                                .collect(Result.logAndRestream())
                                .collect(Result.tryCollect(Collectors.toList()))));


        final Result<List<OakpalPlan>> allPlansResult = initialResult.flatMap(initial ->
                addedResult.map(added -> {
                    initial.addAll(added);
                    return initial;
                }));

        final Result<Map<URL, String>> renamedResult = allPlansResult
                .flatMap(plans -> copyUrlStreams(toDir, plans.stream()
                        .flatMap(plan -> Stream.concat(
                                plan.getPreInstallUrls().stream(),
                                plan.getRepoInitUrls().stream()))
                        .collect(Collectors.toList())));
        final Result<Map<String, OakpalPlan>> rewrittenResult = renamedResult.flatMap(renamed ->
                allPlansResult.map(allPlans -> allPlans.stream()
                        .map(plan -> rewritePlan(toDir, renamed, plan, plan.getName()))
                        .collect(Collectors.toList()))
                        .flatMap(allPlans -> copyPlans(toDir, allPlans)));

        return rewrittenResult.map(compose1(Map::keySet, ArrayList::new));
    }

}