List of usage examples for org.apache.commons.cli CommandLine getArgList
public List getArgList()
From source file:org.apache.maven.cli.CopyOfMavenCli.java
private MavenExecutionRequest populateRequest(CliRequest cliRequest) { MavenExecutionRequest request = cliRequest.request; CommandLine commandLine = cliRequest.commandLine; String workingDirectory = cliRequest.workingDirectory; boolean quiet = cliRequest.quiet; boolean showErrors = cliRequest.showErrors; String[] deprecatedOptions = { "up", "npu", "cpu", "npr" }; for (String deprecatedOption : deprecatedOptions) { if (commandLine.hasOption(deprecatedOption)) { slf4jLogger.warn("Command line option -" + deprecatedOption + " is deprecated and will be removed in future Maven versions."); }/*from w w w . j av a 2s . c om*/ } // ---------------------------------------------------------------------- // Now that we have everything that we need we will fire up plexus and // bring the maven component to life for use. // ---------------------------------------------------------------------- if (commandLine.hasOption(CLIManager.BATCH_MODE)) { request.setInteractiveMode(false); } boolean noSnapshotUpdates = false; if (commandLine.hasOption(CLIManager.SUPRESS_SNAPSHOT_UPDATES)) { noSnapshotUpdates = true; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @SuppressWarnings("unchecked") List<String> goals = commandLine.getArgList(); boolean recursive = true; // this is the default behavior. String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; if (commandLine.hasOption(CLIManager.NON_RECURSIVE)) { recursive = false; } if (commandLine.hasOption(CLIManager.FAIL_FAST)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; } else if (commandLine.hasOption(CLIManager.FAIL_AT_END)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END; } else if (commandLine.hasOption(CLIManager.FAIL_NEVER)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER; } if (commandLine.hasOption(CLIManager.OFFLINE)) { request.setOffline(true); } boolean updateSnapshots = false; if (commandLine.hasOption(CLIManager.UPDATE_SNAPSHOTS)) { updateSnapshots = true; } String globalChecksumPolicy = null; if (commandLine.hasOption(CLIManager.CHECKSUM_FAILURE_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL; } else if (commandLine.hasOption(CLIManager.CHECKSUM_WARNING_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN; } File baseDirectory = new File(workingDirectory, "").getAbsoluteFile(); // ---------------------------------------------------------------------- // Profile Activation // ---------------------------------------------------------------------- List<String> activeProfiles = new ArrayList<String>(); List<String> inactiveProfiles = new ArrayList<String>(); if (commandLine.hasOption(CLIManager.ACTIVATE_PROFILES)) { String[] profileOptionValues = commandLine.getOptionValues(CLIManager.ACTIVATE_PROFILES); if (profileOptionValues != null) { for (String profileOptionValue : profileOptionValues) { StringTokenizer profileTokens = new StringTokenizer(profileOptionValue, ","); while (profileTokens.hasMoreTokens()) { String profileAction = profileTokens.nextToken().trim(); if (profileAction.startsWith("-") || profileAction.startsWith("!")) { inactiveProfiles.add(profileAction.substring(1)); } else if (profileAction.startsWith("+")) { activeProfiles.add(profileAction.substring(1)); } else { activeProfiles.add(profileAction); } } } } } TransferListener transferListener; if (quiet) { transferListener = new QuietMavenTransferListener(); } else if (request.isInteractiveMode() && !cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) { // // If we're logging to a file then we don't want the console transfer listener as it will spew // download progress all over the place // transferListener = getConsoleTransferListener(); } else { transferListener = getBatchTransferListener(); } ExecutionListener executionListener = new ExecutionEventLogger(); executionListener = eventSpyDispatcher.chainListener(executionListener); String alternatePomFile = null; if (commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)) { alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE); } File userToolchainsFile; if (commandLine.hasOption(CLIManager.ALTERNATE_USER_TOOLCHAINS)) { userToolchainsFile = new File(commandLine.getOptionValue(CLIManager.ALTERNATE_USER_TOOLCHAINS)); userToolchainsFile = resolveFile(userToolchainsFile, workingDirectory); } else { userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE; } request.setBaseDirectory(baseDirectory).setGoals(goals).setSystemProperties(cliRequest.systemProperties) .setUserProperties(cliRequest.userProperties).setReactorFailureBehavior(reactorFailureBehaviour) // default: fail fast .setRecursive(recursive) // default: true .setShowErrors(showErrors) // default: false .addActiveProfiles(activeProfiles) // optional .addInactiveProfiles(inactiveProfiles) // optional .setExecutionListener(executionListener).setTransferListener(transferListener) // default: batch mode which goes along with interactive .setUpdateSnapshots(updateSnapshots) // default: false .setNoSnapshotUpdates(noSnapshotUpdates) // default: false .setGlobalChecksumPolicy(globalChecksumPolicy) // default: warn .setUserToolchainsFile(userToolchainsFile); if (alternatePomFile != null) { File pom = resolveFile(new File(alternatePomFile), workingDirectory); if (pom.isDirectory()) { pom = new File(pom, "pom.xml"); } request.setPom(pom); } else { File pom = modelProcessor.locatePom(baseDirectory); if (pom.isFile()) { request.setPom(pom); } } if ((request.getPom() != null) && (request.getPom().getParentFile() != null)) { request.setBaseDirectory(request.getPom().getParentFile()); } if (commandLine.hasOption(CLIManager.RESUME_FROM)) { request.setResumeFrom(commandLine.getOptionValue(CLIManager.RESUME_FROM)); } if (commandLine.hasOption(CLIManager.PROJECT_LIST)) { String[] projectOptionValues = commandLine.getOptionValues(CLIManager.PROJECT_LIST); List<String> inclProjects = new ArrayList<String>(); List<String> exclProjects = new ArrayList<String>(); if (projectOptionValues != null) { for (String projectOptionValue : projectOptionValues) { StringTokenizer projectTokens = new StringTokenizer(projectOptionValue, ","); while (projectTokens.hasMoreTokens()) { String projectAction = projectTokens.nextToken().trim(); if (projectAction.startsWith("-") || projectAction.startsWith("!")) { exclProjects.add(projectAction.substring(1)); } else if (projectAction.startsWith("+")) { inclProjects.add(projectAction.substring(1)); } else { inclProjects.add(projectAction); } } } } request.setSelectedProjects(inclProjects); request.setExcludedProjects(exclProjects); } if (commandLine.hasOption(CLIManager.ALSO_MAKE) && !commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_UPSTREAM); } else if (!commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM); } else if (commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_BOTH); } String localRepoProperty = request.getUserProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); if (localRepoProperty == null) { localRepoProperty = request.getSystemProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); } if (localRepoProperty != null) { request.setLocalRepositoryPath(localRepoProperty); } request.setCacheNotFound(true); request.setCacheTransferError(false); // // Builder, concurrency and parallelism // // We preserve the existing methods for builder selection which is to look for various inputs in the threading // configuration. We don't have an easy way to allow a pluggable builder to provide its own configuration parameters // but this is sufficient for now. Ultimately we want components like Builders to provide a way to extend the command // line to accept its own configuration parameters. // final String threadConfiguration = commandLine.hasOption(CLIManager.THREADS) ? commandLine.getOptionValue(CLIManager.THREADS) : request.getSystemProperties().getProperty(MavenCli.THREADS_DEPRECATED); // TODO: Remove this setting. Note that the int-tests use it if (threadConfiguration != null) { // // Default to the standard multithreaded builder // request.setBuilderId("multithreaded"); if (threadConfiguration.contains("C")) { request.setDegreeOfConcurrency(calculateDegreeOfConcurrencyWithCoreMultiplier(threadConfiguration)); } else { request.setDegreeOfConcurrency(Integer.valueOf(threadConfiguration)); } } // // Allow the builder to be overriden by the user if requested. The builders are now pluggable. // if (commandLine.hasOption(CLIManager.BUILDER)) { request.setBuilderId(commandLine.getOptionValue(CLIManager.BUILDER)); } return request; }
From source file:org.apache.maven.cli.DefaultMavenExecutionRequestBuilder.java
private MavenExecutionRequest populateRequest(CliRequest cliRequest) { MavenExecutionRequest request = cliRequest.request; CommandLine commandLine = cliRequest.commandLine; String workingDirectory = cliRequest.workingDirectory; boolean quiet = cliRequest.quiet; boolean showErrors = cliRequest.showErrors; String[] deprecatedOptions = { "up", "npu", "cpu", "npr" }; for (String deprecatedOption : deprecatedOptions) { if (commandLine.hasOption(deprecatedOption)) { slf4jLogger.warn("Command line option -" + deprecatedOption + " is deprecated and will be removed in future Maven versions."); }/*from ww w . j av a2 s.c o m*/ } // ---------------------------------------------------------------------- // Now that we have everything that we need we will fire up plexus and // bring the maven component to life for use. // ---------------------------------------------------------------------- if (commandLine.hasOption(CLIManager.BATCH_MODE)) { request.setInteractiveMode(false); } boolean noSnapshotUpdates = false; if (commandLine.hasOption(CLIManager.SUPRESS_SNAPSHOT_UPDATES)) { noSnapshotUpdates = true; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @SuppressWarnings("unchecked") List<String> goals = commandLine.getArgList(); boolean recursive = true; // this is the default behavior. String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; if (commandLine.hasOption(CLIManager.NON_RECURSIVE)) { recursive = false; } if (commandLine.hasOption(CLIManager.FAIL_FAST)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; } else if (commandLine.hasOption(CLIManager.FAIL_AT_END)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END; } else if (commandLine.hasOption(CLIManager.FAIL_NEVER)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER; } if (commandLine.hasOption(CLIManager.OFFLINE)) { request.setOffline(true); } boolean updateSnapshots = false; if (commandLine.hasOption(CLIManager.UPDATE_SNAPSHOTS)) { updateSnapshots = true; } String globalChecksumPolicy = null; if (commandLine.hasOption(CLIManager.CHECKSUM_FAILURE_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL; } else if (commandLine.hasOption(CLIManager.CHECKSUM_WARNING_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN; } File baseDirectory = new File(workingDirectory, "").getAbsoluteFile(); // ---------------------------------------------------------------------- // Profile Activation // ---------------------------------------------------------------------- List<String> activeProfiles = new ArrayList<String>(); List<String> inactiveProfiles = new ArrayList<String>(); if (commandLine.hasOption(CLIManager.ACTIVATE_PROFILES)) { String[] profileOptionValues = commandLine.getOptionValues(CLIManager.ACTIVATE_PROFILES); if (profileOptionValues != null) { for (String profileOptionValue : profileOptionValues) { StringTokenizer profileTokens = new StringTokenizer(profileOptionValue, ","); while (profileTokens.hasMoreTokens()) { String profileAction = profileTokens.nextToken().trim(); if (profileAction.startsWith("-") || profileAction.startsWith("!")) { inactiveProfiles.add(profileAction.substring(1)); } else if (profileAction.startsWith("+")) { activeProfiles.add(profileAction.substring(1)); } else { activeProfiles.add(profileAction); } } } } } TransferListener transferListener; if (quiet) { transferListener = new QuietMavenTransferListener(); } else if (request.isInteractiveMode() && !cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) { // // If we're logging to a file then we don't want the console transfer listener as it will spew // download progress all over the place // transferListener = getConsoleTransferListener(); } else { transferListener = getBatchTransferListener(); } ExecutionListener executionListener = new ExecutionEventLogger(); executionListener = eventSpyDispatcher.chainListener(executionListener); String alternatePomFile = null; if (commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)) { alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE); } File userToolchainsFile; if (commandLine.hasOption(CLIManager.ALTERNATE_USER_TOOLCHAINS)) { userToolchainsFile = new File(commandLine.getOptionValue(CLIManager.ALTERNATE_USER_TOOLCHAINS)); userToolchainsFile = resolveFile(userToolchainsFile, workingDirectory); } else { userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE; } request.setBaseDirectory(baseDirectory).setGoals(goals).setSystemProperties(cliRequest.systemProperties) .setUserProperties(cliRequest.userProperties).setReactorFailureBehavior(reactorFailureBehaviour) // default: fail fast .setRecursive(recursive) // default: true .setShowErrors(showErrors) // default: false .addActiveProfiles(activeProfiles) // optional .addInactiveProfiles(inactiveProfiles) // optional .setExecutionListener(executionListener).setTransferListener(transferListener) // default: batch mode which goes along with interactive .setUpdateSnapshots(updateSnapshots) // default: false .setNoSnapshotUpdates(noSnapshotUpdates) // default: false .setGlobalChecksumPolicy(globalChecksumPolicy) // default: warn .setUserToolchainsFile(userToolchainsFile); if (alternatePomFile != null) { File pom = resolveFile(new File(alternatePomFile), workingDirectory); if (pom.isDirectory()) { pom = new File(pom, "pom.xml"); } request.setPom(pom); } else { File pom = modelProcessor.locatePom(baseDirectory); if (pom.isFile()) { request.setPom(pom); } } if ((request.getPom() != null) && (request.getPom().getParentFile() != null)) { request.setBaseDirectory(request.getPom().getParentFile()); } if (commandLine.hasOption(CLIManager.RESUME_FROM)) { request.setResumeFrom(commandLine.getOptionValue(CLIManager.RESUME_FROM)); } if (commandLine.hasOption(CLIManager.PROJECT_LIST)) { String[] values = commandLine.getOptionValues(CLIManager.PROJECT_LIST); List<String> projects = new ArrayList<String>(); for (String value : values) { String[] tmp = StringUtils.split(value, ","); projects.addAll(Arrays.asList(tmp)); } request.setSelectedProjects(projects); } if (commandLine.hasOption(CLIManager.ALSO_MAKE) && !commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_UPSTREAM); } else if (!commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM); } else if (commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_BOTH); } String localRepoProperty = request.getUserProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); if (localRepoProperty == null) { localRepoProperty = request.getSystemProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); } if (localRepoProperty != null) { request.setLocalRepositoryPath(localRepoProperty); } final String threadConfiguration = commandLine.hasOption(CLIManager.THREADS) ? commandLine.getOptionValue(CLIManager.THREADS) : request.getSystemProperties().getProperty(MavenCli.THREADS_DEPRECATED); // TODO: Remove this setting. Note that the int-tests use it if (threadConfiguration != null) { request.setPerCoreThreadCount(threadConfiguration.contains("C")); if (threadConfiguration.contains("W")) { LifecycleWeaveBuilder.setWeaveMode(request.getUserProperties()); } request.setThreadCount(threadConfiguration.replace("C", "").replace("W", "").replace("auto", "")); } request.setCacheNotFound(true); request.setCacheTransferError(false); return request; }
From source file:org.apache.maven.cli.MavenCli.java
void cli(CliRequest cliRequest) throws Exception { ///*from w w w .j av a2s . co m*/ // Parsing errors can happen during the processing of the arguments and we prefer not having to check if // the logger is null and construct this so we can use an SLF4J logger everywhere. // slf4jLogger = new Slf4jStdoutLogger(); CLIManager cliManager = new CLIManager(); List<String> args = new ArrayList<>(); try { File configFile = new File(cliRequest.multiModuleProjectDirectory, MVN_MAVEN_CONFIG); if (configFile.isFile()) { for (String arg : Files.toString(configFile, Charsets.UTF_8).split("\\s+")) { if (!arg.isEmpty()) { args.add(arg); } } CommandLine config = cliManager.parse(args.toArray(new String[args.size()])); List<?> unrecongized = config.getArgList(); if (!unrecongized.isEmpty()) { throw new ParseException("Unrecognized maven.config entries: " + unrecongized); } } } catch (ParseException e) { System.err.println("Unable to parse maven.config: " + e.getMessage()); cliManager.displayHelp(System.out); throw e; } try { args.addAll(0, Arrays.asList(cliRequest.args)); cliRequest.commandLine = cliManager.parse(args.toArray(new String[args.size()])); } catch (ParseException e) { System.err.println("Unable to parse command line options: " + e.getMessage()); cliManager.displayHelp(System.out); throw e; } if (cliRequest.commandLine.hasOption(CLIManager.HELP)) { cliManager.displayHelp(System.out); throw new ExitException(0); } if (cliRequest.commandLine.hasOption(CLIManager.VERSION)) { System.out.println(CLIReportingUtils.showVersion()); throw new ExitException(0); } }
From source file:org.apache.maven.cli.MavenCli.java
private MavenExecutionRequest populateRequest(CliRequest cliRequest, MavenExecutionRequest request) { CommandLine commandLine = cliRequest.commandLine; String workingDirectory = cliRequest.workingDirectory; boolean quiet = cliRequest.quiet; boolean showErrors = cliRequest.showErrors; String[] deprecatedOptions = { "up", "npu", "cpu", "npr" }; for (String deprecatedOption : deprecatedOptions) { if (commandLine.hasOption(deprecatedOption)) { slf4jLogger.warn("Command line option -" + deprecatedOption + " is deprecated and will be removed in future Maven versions."); }//from w ww . j av a 2 s . c o m } // ---------------------------------------------------------------------- // Now that we have everything that we need we will fire up plexus and // bring the maven component to life for use. // ---------------------------------------------------------------------- if (commandLine.hasOption(CLIManager.BATCH_MODE)) { request.setInteractiveMode(false); } boolean noSnapshotUpdates = false; if (commandLine.hasOption(CLIManager.SUPRESS_SNAPSHOT_UPDATES)) { noSnapshotUpdates = true; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @SuppressWarnings("unchecked") List<String> goals = commandLine.getArgList(); boolean recursive = true; // this is the default behavior. String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; if (commandLine.hasOption(CLIManager.NON_RECURSIVE)) { recursive = false; } if (commandLine.hasOption(CLIManager.FAIL_FAST)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; } else if (commandLine.hasOption(CLIManager.FAIL_AT_END)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END; } else if (commandLine.hasOption(CLIManager.FAIL_NEVER)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER; } if (commandLine.hasOption(CLIManager.OFFLINE)) { request.setOffline(true); } boolean updateSnapshots = false; if (commandLine.hasOption(CLIManager.UPDATE_SNAPSHOTS)) { updateSnapshots = true; } String globalChecksumPolicy = null; if (commandLine.hasOption(CLIManager.CHECKSUM_FAILURE_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL; } else if (commandLine.hasOption(CLIManager.CHECKSUM_WARNING_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN; } File baseDirectory = new File(workingDirectory, "").getAbsoluteFile(); // ---------------------------------------------------------------------- // Profile Activation // ---------------------------------------------------------------------- List<String> activeProfiles = new ArrayList<>(); List<String> inactiveProfiles = new ArrayList<>(); if (commandLine.hasOption(CLIManager.ACTIVATE_PROFILES)) { String[] profileOptionValues = commandLine.getOptionValues(CLIManager.ACTIVATE_PROFILES); if (profileOptionValues != null) { for (String profileOptionValue : profileOptionValues) { StringTokenizer profileTokens = new StringTokenizer(profileOptionValue, ","); while (profileTokens.hasMoreTokens()) { String profileAction = profileTokens.nextToken().trim(); if (profileAction.startsWith("-") || profileAction.startsWith("!")) { inactiveProfiles.add(profileAction.substring(1)); } else if (profileAction.startsWith("+")) { activeProfiles.add(profileAction.substring(1)); } else { activeProfiles.add(profileAction); } } } } } TransferListener transferListener; if (quiet) { transferListener = new QuietMavenTransferListener(); } else if (request.isInteractiveMode() && !cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) { // // If we're logging to a file then we don't want the console transfer listener as it will spew // download progress all over the place // transferListener = getConsoleTransferListener(cliRequest.commandLine.hasOption(CLIManager.DEBUG)); } else { transferListener = getBatchTransferListener(); } ExecutionListener executionListener = new ExecutionEventLogger(); if (eventSpyDispatcher != null) { executionListener = eventSpyDispatcher.chainListener(executionListener); } String alternatePomFile = null; if (commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)) { alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE); } File userToolchainsFile; if (commandLine.hasOption(CLIManager.ALTERNATE_USER_TOOLCHAINS)) { userToolchainsFile = new File(commandLine.getOptionValue(CLIManager.ALTERNATE_USER_TOOLCHAINS)); userToolchainsFile = resolveFile(userToolchainsFile, workingDirectory); } else { userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE; } request.setBaseDirectory(baseDirectory).setGoals(goals).setSystemProperties(cliRequest.systemProperties) .setUserProperties(cliRequest.userProperties).setReactorFailureBehavior(reactorFailureBehaviour) // default: fail fast .setRecursive(recursive) // default: true .setShowErrors(showErrors) // default: false .addActiveProfiles(activeProfiles) // optional .addInactiveProfiles(inactiveProfiles) // optional .setExecutionListener(executionListener).setTransferListener(transferListener) // default: batch mode which goes along with interactive .setUpdateSnapshots(updateSnapshots) // default: false .setNoSnapshotUpdates(noSnapshotUpdates) // default: false .setGlobalChecksumPolicy(globalChecksumPolicy) // default: warn .setMultiModuleProjectDirectory(cliRequest.multiModuleProjectDirectory); if (alternatePomFile != null) { File pom = resolveFile(new File(alternatePomFile), workingDirectory); if (pom.isDirectory()) { pom = new File(pom, "pom.xml"); } request.setPom(pom); } else if (modelProcessor != null) { File pom = modelProcessor.locatePom(baseDirectory); if (pom.isFile()) { request.setPom(pom); } } if ((request.getPom() != null) && (request.getPom().getParentFile() != null)) { request.setBaseDirectory(request.getPom().getParentFile()); } if (commandLine.hasOption(CLIManager.RESUME_FROM)) { request.setResumeFrom(commandLine.getOptionValue(CLIManager.RESUME_FROM)); } if (commandLine.hasOption(CLIManager.PROJECT_LIST)) { String[] projectOptionValues = commandLine.getOptionValues(CLIManager.PROJECT_LIST); List<String> inclProjects = new ArrayList<>(); List<String> exclProjects = new ArrayList<>(); if (projectOptionValues != null) { for (String projectOptionValue : projectOptionValues) { StringTokenizer projectTokens = new StringTokenizer(projectOptionValue, ","); while (projectTokens.hasMoreTokens()) { String projectAction = projectTokens.nextToken().trim(); if (projectAction.startsWith("-") || projectAction.startsWith("!")) { exclProjects.add(projectAction.substring(1)); } else if (projectAction.startsWith("+")) { inclProjects.add(projectAction.substring(1)); } else { inclProjects.add(projectAction); } } } } request.setSelectedProjects(inclProjects); request.setExcludedProjects(exclProjects); } if (commandLine.hasOption(CLIManager.ALSO_MAKE) && !commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_UPSTREAM); } else if (!commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM); } else if (commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_BOTH); } String localRepoProperty = request.getUserProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); if (localRepoProperty == null) { localRepoProperty = request.getSystemProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); } if (localRepoProperty != null) { request.setLocalRepositoryPath(localRepoProperty); } request.setCacheNotFound(true); request.setCacheTransferError(false); // // Builder, concurrency and parallelism // // We preserve the existing methods for builder selection which is to look for various inputs in the threading // configuration. We don't have an easy way to allow a pluggable builder to provide its own configuration // parameters but this is sufficient for now. Ultimately we want components like Builders to provide a way to // extend the command line to accept its own configuration parameters. // final String threadConfiguration = commandLine.hasOption(CLIManager.THREADS) ? commandLine.getOptionValue(CLIManager.THREADS) : request.getSystemProperties().getProperty(MavenCli.THREADS_DEPRECATED); // TODO: Remove this setting. Note that the int-tests use it if (threadConfiguration != null) { // // Default to the standard multithreaded builder // request.setBuilderId("multithreaded"); if (threadConfiguration.contains("C")) { request.setDegreeOfConcurrency(calculateDegreeOfConcurrencyWithCoreMultiplier(threadConfiguration)); } else { request.setDegreeOfConcurrency(Integer.valueOf(threadConfiguration)); } } // // Allow the builder to be overriden by the user if requested. The builders are now pluggable. // if (commandLine.hasOption(CLIManager.BUILDER)) { request.setBuilderId(commandLine.getOptionValue(CLIManager.BUILDER)); } return request; }
From source file:org.apache.maven.cli.NoSyspropChangingMavenCli.java
private MavenExecutionRequest populateRequest(CliRequest cliRequest) { MavenExecutionRequest request = cliRequest.request; CommandLine commandLine = cliRequest.commandLine; String workingDirectory = cliRequest.workingDirectory; boolean quiet = cliRequest.quiet; boolean showErrors = cliRequest.showErrors; String[] deprecatedOptions = { "up", "npu", "cpu", "npr" }; for (String deprecatedOption : deprecatedOptions) { if (commandLine.hasOption(deprecatedOption)) { logger.warn("Command line option -" + deprecatedOption + " is deprecated and will be removed in future Maven versions."); }// w w w . j av a 2 s.co m } // ---------------------------------------------------------------------- // Now that we have everything that we need we will fire up plexus and // bring the maven component to life for use. // ---------------------------------------------------------------------- if (commandLine.hasOption(CLIManager.BATCH_MODE)) { request.setInteractiveMode(false); } boolean noSnapshotUpdates = false; if (commandLine.hasOption(CLIManager.SUPRESS_SNAPSHOT_UPDATES)) { noSnapshotUpdates = true; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @SuppressWarnings("unchecked") List<String> goals = commandLine.getArgList(); boolean recursive = true; // this is the default behavior. String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; if (commandLine.hasOption(CLIManager.NON_RECURSIVE)) { recursive = false; } if (commandLine.hasOption(CLIManager.FAIL_FAST)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; } else if (commandLine.hasOption(CLIManager.FAIL_AT_END)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END; } else if (commandLine.hasOption(CLIManager.FAIL_NEVER)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER; } if (commandLine.hasOption(CLIManager.OFFLINE)) { request.setOffline(true); } boolean updateSnapshots = false; if (commandLine.hasOption(CLIManager.UPDATE_SNAPSHOTS)) { updateSnapshots = true; } String globalChecksumPolicy = null; if (commandLine.hasOption(CLIManager.CHECKSUM_FAILURE_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL; } else if (commandLine.hasOption(CLIManager.CHECKSUM_WARNING_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN; } File baseDirectory = new File(workingDirectory, "").getAbsoluteFile(); // ---------------------------------------------------------------------- // Profile Activation // ---------------------------------------------------------------------- List<String> activeProfiles = new ArrayList<String>(); List<String> inactiveProfiles = new ArrayList<String>(); if (commandLine.hasOption(CLIManager.ACTIVATE_PROFILES)) { String[] profileOptionValues = commandLine.getOptionValues(CLIManager.ACTIVATE_PROFILES); if (profileOptionValues != null) { for (int i = 0; i < profileOptionValues.length; ++i) { StringTokenizer profileTokens = new StringTokenizer(profileOptionValues[i], ","); while (profileTokens.hasMoreTokens()) { String profileAction = profileTokens.nextToken().trim(); if (profileAction.startsWith("-") || profileAction.startsWith("!")) { inactiveProfiles.add(profileAction.substring(1)); } else if (profileAction.startsWith("+")) { activeProfiles.add(profileAction.substring(1)); } else { activeProfiles.add(profileAction); } } } } } TransferListener transferListener; if (quiet) { transferListener = new QuietMavenTransferListener(); } else if (request.isInteractiveMode()) { transferListener = new ConsoleMavenTransferListener(System.out); } else { transferListener = new BatchModeMavenTransferListener(System.out); } ExecutionListener executionListener = new ExecutionEventLogger(logger); executionListener = eventSpyDispatcher.chainListener(executionListener); String alternatePomFile = null; if (commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)) { alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE); } File userToolchainsFile; if (commandLine.hasOption(CLIManager.ALTERNATE_USER_TOOLCHAINS)) { userToolchainsFile = new File(commandLine.getOptionValue(CLIManager.ALTERNATE_USER_TOOLCHAINS)); userToolchainsFile = resolveFile(userToolchainsFile, workingDirectory); } else { userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE; } request.setBaseDirectory(baseDirectory).setGoals(goals).setSystemProperties(cliRequest.systemProperties) .setUserProperties(cliRequest.userProperties).setReactorFailureBehavior(reactorFailureBehaviour) // default: fail fast .setRecursive(recursive) // default: true .setShowErrors(showErrors) // default: false .addActiveProfiles(activeProfiles) // optional .addInactiveProfiles(inactiveProfiles) // optional .setExecutionListener(executionListener).setTransferListener(transferListener) // default: batch mode which goes along with interactive .setUpdateSnapshots(updateSnapshots) // default: false .setNoSnapshotUpdates(noSnapshotUpdates) // default: false .setGlobalChecksumPolicy(globalChecksumPolicy) // default: warn .setUserToolchainsFile(userToolchainsFile); if (alternatePomFile != null) { File pom = resolveFile(new File(alternatePomFile), workingDirectory); request.setPom(pom); } else { File pom = modelProcessor.locatePom(baseDirectory); if (pom.isFile()) { request.setPom(pom); } } if ((request.getPom() != null) && (request.getPom().getParentFile() != null)) { request.setBaseDirectory(request.getPom().getParentFile()); } if (commandLine.hasOption(CLIManager.RESUME_FROM)) { request.setResumeFrom(commandLine.getOptionValue(CLIManager.RESUME_FROM)); } if (commandLine.hasOption(CLIManager.PROJECT_LIST)) { String[] values = commandLine.getOptionValues(CLIManager.PROJECT_LIST); List<String> projects = new ArrayList<String>(); for (int i = 0; i < values.length; i++) { String[] tmp = StringUtils.split(values[i], ","); projects.addAll(Arrays.asList(tmp)); } request.setSelectedProjects(projects); } if (commandLine.hasOption(CLIManager.ALSO_MAKE) && !commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_UPSTREAM); } else if (!commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM); } else if (commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_BOTH); } String localRepoProperty = request.getUserProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); if (localRepoProperty == null) { localRepoProperty = request.getSystemProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); } if (localRepoProperty != null) { request.setLocalRepositoryPath(localRepoProperty); } final String threadConfiguration = commandLine.hasOption(CLIManager.THREADS) ? commandLine.getOptionValue(CLIManager.THREADS) : request.getSystemProperties().getProperty(MavenCli.THREADS_DEPRECATED); // TODO: Remove this setting. Note that the int-tests use it if (threadConfiguration != null) { request.setPerCoreThreadCount(threadConfiguration.contains("C")); if (threadConfiguration.contains("W")) { LifecycleWeaveBuilder.setWeaveMode(request.getUserProperties()); } request.setThreadCount(threadConfiguration.replace("C", "").replace("W", "").replace("auto", "")); } request.setCacheNotFound(true); request.setCacheTransferError(false); return request; }
From source file:org.apache.ofbiz.base.start.StartupCommandUtil.java
private static final void validateAllCommandArguments(CommandLine commandLine) throws StartupException { // Make sure no extra options are passed if (!commandLine.getArgList().isEmpty()) { throw new StartupException("unrecognized options / properties: " + commandLine.getArgList()); }//from w ww . jav a 2 s .c o m // PORTOFFSET validation if (commandLine.hasOption(StartupOption.PORTOFFSET.getName())) { Properties optionProperties = commandLine.getOptionProperties(StartupOption.PORTOFFSET.getName()); try { int portOffset = Integer.parseInt(optionProperties.keySet().iterator().next().toString()); if (portOffset < 0) { throw new StartupException("you can only pass positive integers to the option --" + StartupOption.PORTOFFSET.getName()); } } catch (NumberFormatException e) { throw new StartupException( "you can only pass positive integers to the option --" + StartupOption.PORTOFFSET.getName(), e); } } }
From source file:org.apache.oozie.cli.OozieCLI.java
private void adminCommand(CommandLine commandLine) throws OozieCLIException { XOozieClient wc = createXOozieClient(commandLine); List<String> options = new ArrayList<String>(); for (Option option : commandLine.getOptions()) { options.add(option.getOpt());/* w ww . j av a 2s . c o m*/ } try { SYSTEM_MODE status = SYSTEM_MODE.NORMAL; if (options.contains(VERSION_OPTION)) { System.out.println("Oozie server build version: " + wc.getServerBuildVersion()); } else if (options.contains(SYSTEM_MODE_OPTION)) { String systemModeOption = commandLine.getOptionValue(SYSTEM_MODE_OPTION).toUpperCase(); try { status = SYSTEM_MODE.valueOf(systemModeOption); } catch (Exception e) { throw new OozieCLIException( "Invalid input provided for option: " + SYSTEM_MODE_OPTION + " value given :" + systemModeOption + " Expected values are: NORMAL/NOWEBSERVICE/SAFEMODE "); } wc.setSystemMode(status); System.out.println("System mode: " + status); } else if (options.contains(STATUS_OPTION)) { status = wc.getSystemMode(); System.out.println("System mode: " + status); } else if (options.contains(UPDATE_SHARELIB_OPTION)) { System.out.println(wc.updateShareLib()); } else if (options.contains(LIST_SHARELIB_LIB_OPTION)) { String sharelibKey = null; if (commandLine.getArgList().size() > 0) { sharelibKey = (String) commandLine.getArgList().get(0); } System.out.println(wc.listShareLib(sharelibKey)); } else if (options.contains(QUEUE_DUMP_OPTION)) { List<String> list = wc.getQueueDump(); if (list != null && list.size() != 0) { for (String str : list) { System.out.println(str); } } else { System.out.println("QueueDump is null!"); } } else if (options.contains(AVAILABLE_SERVERS_OPTION)) { Map<String, String> availableOozieServers = new TreeMap<String, String>( wc.getAvailableOozieServers()); for (Map.Entry<String, String> ent : availableOozieServers.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } } else if (options.contains(SERVER_CONFIGURATION_OPTION)) { Map<String, String> serverConfig = new TreeMap<String, String>(wc.getServerConfiguration()); for (Map.Entry<String, String> ent : serverConfig.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } } else if (options.contains(SERVER_OS_ENV_OPTION)) { Map<String, String> osEnv = new TreeMap<String, String>(wc.getOSEnv()); for (Map.Entry<String, String> ent : osEnv.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } } else if (options.contains(SERVER_JAVA_SYSTEM_PROPERTIES_OPTION)) { Map<String, String> javaSysProps = new TreeMap<String, String>(wc.getJavaSystemProperties()); for (Map.Entry<String, String> ent : javaSysProps.entrySet()) { System.out.println(ent.getKey() + " : " + ent.getValue()); } } else if (options.contains(METRICS_OPTION)) { OozieClient.Metrics metrics = wc.getMetrics(); if (metrics == null) { System.out.println("Metrics are unavailable. Try Instrumentation (-" + INSTRUMENTATION_OPTION + ") instead"); } else { printMetrics(metrics); } } else if (options.contains(INSTRUMENTATION_OPTION)) { OozieClient.Instrumentation instrumentation = wc.getInstrumentation(); if (instrumentation == null) { System.out.println( "Instrumentation is unavailable. Try Metrics (-" + METRICS_OPTION + ") instead"); } else { printInstrumentation(instrumentation); } } else if (options.contains(PURGE_OPTION)) { String purgeOptions = commandLine.getOptionValue(PURGE_OPTION); System.out.println(wc.purgeCommand(purgeOptions)); } } catch (OozieClientException ex) { throw new OozieCLIException(ex.toString(), ex); } }
From source file:org.apache.oozie.cli.OozieCLI.java
private void scriptLanguageCommand(CommandLine commandLine, String jobType) throws IOException, OozieCLIException { List<String> args = commandLine.getArgList(); if (args.size() > 0) { // checking if args starts with -X (because CLIParser cannot check this) if (!args.get(0).equals("-X")) { throw new OozieCLIException("Unrecognized option: " + args.get(0) + " Expecting -X"); }/*from w w w .j a v a 2 s. c om*/ args.remove(0); } if (!commandLine.hasOption(SCRIPTFILE_OPTION)) { throw new OozieCLIException("Need to specify -file <scriptfile>"); } if (!commandLine.hasOption(CONFIG_OPTION)) { throw new OozieCLIException("Need to specify -config <configfile>"); } try { XOozieClient wc = createXOozieClient(commandLine); Properties conf = getConfiguration(wc, commandLine); String script = commandLine.getOptionValue(SCRIPTFILE_OPTION); List<String> paramsList = new ArrayList<String>(); if (commandLine.hasOption("P")) { Properties params = commandLine.getOptionProperties("P"); for (String key : params.stringPropertyNames()) { paramsList.add(key + "=" + params.getProperty(key)); } } System.out.println( JOB_ID_PREFIX + wc.submitScriptLanguage(conf, script, args.toArray(new String[args.size()]), paramsList.toArray(new String[paramsList.size()]), jobType)); } catch (OozieClientException ex) { throw new OozieCLIException(ex.toString(), ex); } }
From source file:org.apache.oozie.cli.OozieCLI.java
private void sqoopCommand(CommandLine commandLine) throws IOException, OozieCLIException { List<String> args = commandLine.getArgList(); if (args.size() > 0) { // checking if args starts with -X (because CLIParser cannot check this) if (!args.get(0).equals("-X")) { throw new OozieCLIException("Unrecognized option: " + args.get(0) + " Expecting -X"); }/* ww w . j ava 2 s . co m*/ args.remove(0); } if (!commandLine.hasOption(SQOOP_COMMAND_OPTION)) { throw new OozieCLIException("Need to specify -command"); } if (!commandLine.hasOption(CONFIG_OPTION)) { throw new OozieCLIException("Need to specify -config <configfile>"); } try { XOozieClient wc = createXOozieClient(commandLine); Properties conf = getConfiguration(wc, commandLine); String[] command = commandLine.getOptionValues(SQOOP_COMMAND_OPTION); System.out .println(JOB_ID_PREFIX + wc.submitSqoop(conf, command, args.toArray(new String[args.size()]))); } catch (OozieClientException ex) { throw new OozieCLIException(ex.toString(), ex); } }
From source file:org.apache.openejb.cli.MainImpl.java
public void main(String[] args) { args = processSystemProperties(args); finder = new ResourceFinder(BASE_PATH); locale = Locale.getDefault().getLanguage(); descriptionI18n = descriptionBase + "." + locale; final CommandLineParser parser = new PosixParser(); // create the Options final Options options = new Options(); options.addOption(null, "version", false, ""); options.addOption("h", "help", false, ""); options.addOption("e", "errors", false, "Produce execution error messages"); CommandLine line = null; String commandName = null;// w w w . ja v a 2s . co m try { // parse the arguments up until the first // command, then let the rest fall into // the arguments array. line = parser.parse(options, args, true); // Get and remove the commandName (first arg) final List<String> list = line.getArgList(); if (list.size() > 0) { commandName = list.get(0); list.remove(0); } // The rest of the args will be passed to the command args = line.getArgs(); } catch (final ParseException exp) { exp.printStackTrace(); System.exit(-1); } if (line.hasOption("version")) { OpenEjbVersion.get().print(System.out); System.exit(0); } else if (line.hasOption("help") || commandName == null || commandName.equals("help")) { help(); System.exit(0); } Properties props = null; try { props = finder.findProperties(commandName); } catch (final IOException e1) { System.out.println("Unavailable command: " + commandName); help(false); System.exit(1); } if (props == null) { System.out.println("Unavailable command: " + commandName); help(false); System.exit(1); } // Shift the command name itself off the args list final String mainClass = props.getProperty(MAIN_CLASS_PROPERTY_NAME); if (mainClass == null) { throw new NullPointerException( "Command " + commandName + " did not specify a " + MAIN_CLASS_PROPERTY_NAME + " property"); } Class<?> clazz = null; try { clazz = Thread.currentThread().getContextClassLoader().loadClass(mainClass); } catch (final ClassNotFoundException cnfe) { throw new IllegalStateException( "Main class of command " + commandName + " does not exist: " + mainClass, cnfe); } Method mainMethod = null; try { mainMethod = clazz.getMethod("main", String[].class); } catch (final Exception e) { throw new IllegalStateException( "Main class of command " + commandName + " does not have a static main method: " + mainClass, e); } try { // WARNING, Definitely do *not* unwrap 'new Object[]{args}' to 'args' mainMethod.invoke(clazz, new Object[] { args }); } catch (final Throwable e) { if (line.hasOption("errors")) { e.printStackTrace(); } System.exit(-10); } }