diff --git a/README.md b/README.md index d57f4c4..0e6d6be 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,10 @@ usage: mvmin [options] [] [] [] --nbi No build-if dependencies are considered, just changed modules. + Intercepted Maven Options: + -rf,--resume-from Resume reactor from specified project (and sub-reactor). + -f,--file Not supported, mvnmin will exit. + Scripting -p Don't invoke maven, print out activated projects, sorted, newline separated. diff --git a/src/main/java/com/elasticpath/tools/mavenminimal/MvnMinCli.java b/src/main/java/com/elasticpath/tools/mavenminimal/MvnMinCli.java index a5333d0..2ddb18c 100644 --- a/src/main/java/com/elasticpath/tools/mavenminimal/MvnMinCli.java +++ b/src/main/java/com/elasticpath/tools/mavenminimal/MvnMinCli.java @@ -57,6 +57,7 @@ public class MvnMinCli { private static boolean printMode; private static boolean versionMode; private static boolean buildIfEnabled = true; + private static String resumeFromModule; /** * The default command line entry point for mvnmin. @@ -148,32 +149,41 @@ private static ModuleRequests findChangedProjectsIds(final ProjectRepository rep * @param out the PrintStream to report any issues to. */ private static void parseArgs(final String[] args, final PrintStream out) { + boolean parsingResumeFrom = false; for (String arg : args) { - if (arg.matches("--all")) { - allPomMode = true; - } else if (arg.equals("-d") || arg.equals("--dry-run")) { - dryRunMode = true; - } else if (arg.matches("--diff.*")) { - int equalsIndex = arg.indexOf('='); - if (equalsIndex > -1 && equalsIndex + 1 < arg.length()) { - commitDiffArg = arg.substring(equalsIndex + 1); - } - if (!commitDiffArg.contains("..")) { - commitDiffArg += ".."; + if (parsingResumeFrom) { + parsingResumeFrom = false; + resumeFromModule = arg; + } else { + if (arg.matches("--all")) { + allPomMode = true; + } else if (arg.equals("-d") || arg.equals("--dry-run")) { + dryRunMode = true; + } else if (arg.matches("--diff.*")) { + int equalsIndex = arg.indexOf('='); + if (equalsIndex > -1 && equalsIndex + 1 < arg.length()) { + commitDiffArg = arg.substring(equalsIndex + 1); + } + if (!commitDiffArg.contains("..")) { + commitDiffArg += ".."; + } + diffCommitMode = true; + } else if (arg.matches("--help")) { + printUsage(out); + exit(0); + } else if (arg.equals("-p")) { + printMode = true; + } else if (arg.equals("--nbi")) { + buildIfEnabled = false; + } else if (arg.equals("--version")) { + versionMode = true; + } else if (arg.equals("-f") || arg.equals("--file")) { + out.println("The options '-f' and '--file' are not supported by mvnmin, exiting."); + exit(1); + } else if (arg.equals("-rf") || arg.equals("--resume-from")) { + parsingResumeFrom = true; + // the next param is out project } - diffCommitMode = true; - } else if (arg.matches("--help")) { - printUsage(out); - exit(0); - } else if (arg.equals("-p")) { - printMode = true; - } else if (arg.equals("--nbi")) { - buildIfEnabled = false; - } else if (arg.equals("--version")) { - versionMode = true; - } else if (arg.equals("-f") || arg.equals("--file")) { - out.println("The options '-f' and '--file' are not supported by mvnmin, exiting."); - exit(1); } } } @@ -195,6 +205,10 @@ private static void printUsage(final PrintStream out) { out.println(" --nbi No build-if dependencies are considered, just "); out.println(" changed modules."); out.println(); + out.println(" Intercepted Maven Options:"); + out.println(" -rf,--resume-from Resume reactor from specified project (and sub-reactor)."); + out.println(" -f,--file Not supported, mvnmin will exit."); + out.println(); out.println(" Scripting"); out.println(" -p Don't invoke maven, print out activated projects,"); out.println(" sorted, newline separated."); @@ -280,12 +294,32 @@ private static int executeMavenOnReactors(final ExtendedReactor xreactor, final ReactorPrinter printer = new ReactorPrinter(maxReactorNameLength.getAsInt(), out); printer.newline(); // add some spacing + // Skip the reactors before the one containing the resume-from module, let the rest run. + if (resumeFromModule != null) { + boolean resumeFromActivated = false; + for (Reactor subReactor : xreactor.getSubReactors()) { + if (!resumeFromActivated) { + for (String activeModule : subReactor.getActiveModules()) { // can't simply do `contains()` + Logger.debug(activeModule); + if (activeModule.contains(resumeFromModule)) { // look for the abbreviated module name + resumeFromActivated = true; + } else { + Logger.debug("Skipping " + subReactor.getReactorName() + + " looking for resume-from module: " + resumeFromModule); + subReactor.setSkipReactor(true); + } + } + } + } + } int mavenExitValue = 0; for (Reactor subReactor : xreactor.getSubReactors()) { if (mavenExitValue == 0) { mavenExitValue = - MavenDriver.runMvnForReactor(subReactor, filteredArgs, mvnMinConfig.getMvnCommand(), dryRun, printer); + MavenDriver.runMvnForReactor( + subReactor, filteredArgs, mvnMinConfig.getMvnCommand(), + dryRun, printer, resumeFromModule); printer.newline(); } else { out.println("mvnmin: Maven failed to run successfully."); @@ -299,6 +333,8 @@ private static List removeNonMavenArgs(final String[] args) { List mavenArguments = new ArrayList<>(Arrays.asList(args)); removeArgPair(mavenArguments, "-pl"); removeArgPair(mavenArguments, "--projects"); + removeArgPair(mavenArguments, "-rf"); + removeArgPair(mavenArguments, "--resume-from"); mavenArguments.removeIf(s -> s.equals("--all")); mavenArguments.removeIf(s -> s.equals("--d")); diff --git a/src/main/java/com/elasticpath/tools/mavenminimal/reactor/MavenDriver.java b/src/main/java/com/elasticpath/tools/mavenminimal/reactor/MavenDriver.java index a398ea0..35a40b6 100644 --- a/src/main/java/com/elasticpath/tools/mavenminimal/reactor/MavenDriver.java +++ b/src/main/java/com/elasticpath/tools/mavenminimal/reactor/MavenDriver.java @@ -60,12 +60,13 @@ public class MavenDriver { * @param overrideMvnCommand an override to use for a maven command * @param dryRun false to invoke maven, true to skip * @param printer the output printer + * @param resumeFromModule the module to resume from for this reactor (null if not applicable) * @return the exit status of the maven invocation (or zero if dryRun is true) */ public static int runMvnForReactor( final Reactor reactor, final List args, final String overrideMvnCommand, - final boolean dryRun, final ReactorPrinter printer) { - CommandLine command = determineMavenCommand(reactor, args, overrideMvnCommand); + final boolean dryRun, final ReactorPrinter printer, final String resumeFromModule) { + CommandLine command = determineMavenCommand(reactor, args, overrideMvnCommand, resumeFromModule); printer.commandSummary(reactor, command); if (dryRun || !reactor.shouldBuild()) { @@ -96,9 +97,11 @@ private static int executeMaven(final CommandLine command, final ReactorPrinter * @param reactor the list of project IDs to be passed to maven to build * @param inputArgs the command line arguments that were passed to the tool * @param overrideMvnCommand the mvn command to used (can be null) + * @param resumeFromModule the module to rsult from, or null if not applicable. * @return the Maven command to execute */ - private static CommandLine determineMavenCommand(final Reactor reactor, final List inputArgs, final String overrideMvnCommand) { + private static CommandLine determineMavenCommand( + final Reactor reactor, final List inputArgs, final String overrideMvnCommand, final String resumeFromModule) { AtomicReference goal = new AtomicReference<>(""); List mavenMinimalArguments = new ArrayList<>(inputArgs); @@ -130,6 +133,17 @@ private static CommandLine determineMavenCommand(final Reactor reactor, final Li mavenArguments.add("-T1"); } + // Skip the reactors before the one containing the resume-from module, let the rest run. + if (resumeFromModule != null) { + for (String activeModule : reactor.getActiveModules()) { // can't simply do `contains()` + if (activeModule.contains(resumeFromModule)) { // look for the abbreviated module name + mavenArguments.add("-rf"); + mavenArguments.add(resumeFromModule); + break; + } + } + } + if (reactor.hasActiveModules()) { mavenArguments.add("--projects"); mavenArguments.add(String.join(",", reactor.getActiveModules()));