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())); }  @Override void execute(); static final String OPEAR; }
@Test public void testCopyPlans() throws Exception { final File testOutDir = new File(testOutBaseDir, "testCopyPlans"); FileUtils.deleteDirectory(testOutDir); testOutDir.mkdirs(); final File copyTarget = new File(testOutDir, "copied"); copyTarget.mkdirs(); final String expectFilename = "sample-plan.json"; final URL samplePlanUrl = new File(srcDir, expectFilename).toURI().toURL(); final Result<OakpalPlan> simplePlan = OakpalPlan.fromJson(samplePlanUrl); Result<Map<String, OakpalPlan>> copyResult = OpearPackageMojo.copyPlans(copyTarget, Arrays.asList(simplePlan.getOrDefault(null))); assertTrue("is success " + copyResult, copyResult.isSuccess()); Map<String, OakpalPlan> copyMap = copyResult.getOrDefault(Collections.emptyMap()); assertTrue("contains key: " + copyMap.keySet(), copyMap.containsKey(expectFilename)); final File destFile = new File(copyTarget, expectFilename); assertTrue("file exists: " + destFile, destFile.isFile()); }