@Test public void testShrinkWrapPlans() throws Exception { final File testOutDir = new File(testOutBaseDir, "testShrinkWrapPlans"); FileUtils.deleteDirectory(testOutDir); testOutDir.mkdirs(); final File copyTarget = new File(testOutDir, "copied"); copyTarget.mkdirs(); final String preInstallFilename = "tmp_foo_bar.zip"; final File preInstallPackage = TestPackageUtil.prepareTestPackage(preInstallFilename); final OpearPackageMojo mojo = newMojo(); final MavenProject project = mock(MavenProject.class); mojo.project = project; final String expectFilename = "sample-plan.json"; final File samplePlanFile = new File(srcDir, expectFilename); mojo.planFile = samplePlanFile; final int addPlans = 10; for (int i = 0; i < addPlans; i++) { mojo.additionalPlans.add(samplePlanFile); } List<String> expectedPlanNames = new ArrayList<>(); expectedPlanNames.add(expectFilename); for (int i = 0; i < addPlans; i++) { expectedPlanNames.add("sample-plan_" + (i+1) + ".json"); } Result<List<String>> planNamesResult = mojo.shrinkWrapPlans(copyTarget); assertTrue("is success: " + planNamesResult, planNamesResult.isSuccess()); assertEquals("expect plan names", expectedPlanNames, planNamesResult.getOrDefault(Collections.emptyList())); assertTrue("preinstall is file", new File(copyTarget, preInstallFilename).isFile()); File[] otherZips = copyTarget.listFiles((dir, name) -> !preInstallFilename.equals(name) && name.endsWith(".zip")); assertNotNull("other zips should not be null", otherZips); assertEquals("other zips should be empty", 0, otherZips.length); }
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)); }
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)); } }
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)); }  }
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)); }  @Override void execute(); }
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)); }  @Override void execute(); static final String OPEAR; }