class OpearPackageMojo extends AbstractCommonMojo {

    static Result<Map<String, OakpalPlan>> copyPlans(final @NotNull File toDir, final @NotNull List<OakpalPlan> plans) {
        final Map<String, OakpalPlan> renamed = mapDestFileNames(new LinkedHashMap<>(), plans, OakpalPlan::getName);

        final JsonWriterFactory writerFactory =
                Json.createWriterFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true));
        final Result<List<String>> filenameResults = renamed.entrySet().stream().map(result1(entry -> {
            try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(new File(toDir, entry.getKey())));
                 JsonWriter writer = writerFactory.createWriter(osw)) {
                writer.writeObject(entry.getValue().toJson());
                return entry.getKey();
            }
        })).collect(Result.tryCollect(Collectors.toList()));

        return filenameResults.map(filenames ->
                filenames.stream()
                        .map(zipKeysWithValueFunc(renamed::get))
                        .collect(entriesToMap()));
    }

}