List of usage examples for org.apache.commons.cli CommandLine getOptionValues
public String[] getOptionValues(char opt)
From source file:org.apache.hive.ptest.RunTests.java
public static void main(String[] args) throws Exception { LOG.info("Args " + Arrays.toString(args)); CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption(null, PROPERTIES, true, "properties file"); options.addOption(null, REPOSITORY, true, "Overrides git repository in properties file"); options.addOption(null, REPOSITORY_NAME, true, "Overrides git repository *name* in properties file"); options.addOption(null, BRANCH, true, "Overrides git branch in properties file"); options.addOption(null, PATCH, true, "URI to patch, either file:/// or http(s)://"); options.addOption(ANT_ARG, null, true, "Supplemntal ant arguments"); options.addOption(null, JAVA_HOME, true, "Java Home for compiling and running tests"); options.addOption(null, ANT_ENV_OPTS, true, "ANT_OPTS environemnt variable setting"); CommandLine commandLine = parser.parse(options, args); if (!commandLine.hasOption(PROPERTIES)) { throw new IllegalArgumentException( Joiner.on(" ").join(RunTests.class.getName(), "--" + PROPERTIES, "config.properties")); }/*from w ww .j av a 2 s. c o m*/ Configuration conf = Configuration.fromFile(commandLine.getOptionValue(PROPERTIES)); String repository = Strings.nullToEmpty(commandLine.getOptionValue(REPOSITORY)).trim(); if (!repository.isEmpty()) { conf.setRepository(repository); } String repositoryName = Strings.nullToEmpty(commandLine.getOptionValue(REPOSITORY_NAME)).trim(); if (!repositoryName.isEmpty()) { conf.setRepositoryName(repositoryName); } String branch = Strings.nullToEmpty(commandLine.getOptionValue(BRANCH)).trim(); if (!branch.isEmpty()) { conf.setBranch(branch); } String patch = Strings.nullToEmpty(commandLine.getOptionValue(PATCH)).trim(); if (!patch.isEmpty()) { conf.setPatch(patch); } String javaHome = Strings.nullToEmpty(commandLine.getOptionValue(JAVA_HOME)).trim(); if (!javaHome.isEmpty()) { conf.setJavaHome(javaHome); } String antEnvOpts = Strings.nullToEmpty(commandLine.getOptionValue(ANT_ENV_OPTS)).trim(); if (!antEnvOpts.isEmpty()) { conf.setAntEnvOpts(antEnvOpts); } String[] supplementalAntArgs = commandLine.getOptionValues(ANT_ARG); if (supplementalAntArgs != null && supplementalAntArgs.length > 0) { String antArgs = Strings.nullToEmpty(conf.getAntArgs()); if (!(antArgs.isEmpty() || antArgs.endsWith(" "))) { antArgs += " "; } antArgs += "-" + ANT_ARG + Joiner.on(" -" + ANT_ARG).join(supplementalAntArgs); conf.setAntArgs(antArgs); } RunTests ptest = new RunTests(conf, new LocalCommandFactory(), new SSHCommandExecutor(), new SCPCommandExecutor(), new RSyncCommandExecutor()); ptest.run(); }
From source file:org.apache.isis.core.runtime.optionhandler.OptionHandlerAbstract.java
protected List<String> getOptionValues(final CommandLine commandLine, final String opt) { final List<String> list = new ArrayList<String>(); final String[] optionValues = commandLine.getOptionValues(opt); if (optionValues != null) { for (final String optionValue : optionValues) { ListExtensions.appendDelimitedStringToList(optionValue, list); }/*w ww. j a va 2s . c o m*/ } return list; }
From source file:org.apache.jxtadoop.util.GenericOptionsParser.java
/** * Modify configuration according user-specified generic options * @param conf Configuration to be modified * @param line User-specified generic options *//*from w w w .j av a 2 s . c o m*/ private void processGeneralOptions(Configuration conf, CommandLine line) { if (line.hasOption("fs")) { FileSystem.setDefaultUri(conf, line.getOptionValue("fs")); } if (line.hasOption("jt")) { conf.set("mapred.job.tracker", line.getOptionValue("jt")); } if (line.hasOption("conf")) { String[] values = line.getOptionValues("conf"); for (String value : values) { conf.addResource(new Path(value)); } } try { if (line.hasOption("libjars")) { conf.set("tmpjars", validateFiles(line.getOptionValue("libjars"), conf)); //setting libjars in client classpath URL[] libjars = getLibJars(conf); if (libjars != null && libjars.length > 0) { conf.setClassLoader(new URLClassLoader(libjars, conf.getClassLoader())); Thread.currentThread().setContextClassLoader( new URLClassLoader(libjars, Thread.currentThread().getContextClassLoader())); } } if (line.hasOption("files")) { conf.set("tmpfiles", validateFiles(line.getOptionValue("files"), conf)); } if (line.hasOption("archives")) { conf.set("tmparchives", validateFiles(line.getOptionValue("archives"), conf)); } } catch (IOException ioe) { System.err.println(StringUtils.stringifyException(ioe)); } if (line.hasOption('D')) { String[] property = line.getOptionValues('D'); for (String prop : property) { String[] keyval = prop.split("=", 2); if (keyval.length == 2) { conf.set(keyval[0], keyval[1]); } } } conf.setBoolean("mapred.used.genericoptionsparser", true); }
From source file:org.apache.marmotta.loader.core.MarmottaLoader.java
public static Configuration parseOptions(String[] args) throws ParseException { Options options = buildOptions();/*from ww w .j av a 2s. c o m*/ CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); Configuration result = new MapConfiguration(new HashMap<String, Object>()); if (cmd.hasOption('B')) { // check backends Set<String> existing = Sets .newHashSet(Iterators.transform(backends.iterator(), new BackendIdentifierFunction())); if (!existing.contains(cmd.getOptionValue('B'))) { throw new ParseException("the backend " + cmd.getOptionValue('B') + " does not exist"); } result.setProperty(LoaderOptions.BACKEND, cmd.getOptionValue('B')); } if (cmd.hasOption('b')) { result.setProperty(LoaderOptions.BASE_URI, cmd.getOptionValue('b')); } if (cmd.hasOption('z')) { result.setProperty(LoaderOptions.COMPRESSION, CompressorStreamFactory.GZIP); } if (cmd.hasOption('j')) { result.setProperty(LoaderOptions.COMPRESSION, CompressorStreamFactory.BZIP2); } if (cmd.hasOption('c')) { result.setProperty(LoaderOptions.CONTEXT, cmd.getOptionValue('c')); } if (cmd.hasOption('t')) { RDFFormat fmt = getRDFFormat(cmd.getOptionValue('t')); if (fmt == null) { throw new ParseException("unrecognized MIME type: " + cmd.getOptionValue('t')); } result.setProperty(LoaderOptions.FORMAT, fmt.getDefaultMIMEType()); } if (cmd.hasOption('f')) { result.setProperty(LoaderOptions.FILES, Arrays.asList(cmd.getOptionValues('f'))); } if (cmd.hasOption('d')) { result.setProperty(LoaderOptions.DIRS, Arrays.asList(cmd.getOptionValues('d'))); } if (cmd.hasOption('a')) { result.setProperty(LoaderOptions.ARCHIVES, Arrays.asList(cmd.getOptionValues('a'))); } if (cmd.hasOption('s')) { result.setProperty(LoaderOptions.STATISTICS_ENABLED, true); result.setProperty(LoaderOptions.STATISTICS_GRAPH, cmd.getOptionValue('s')); } if (cmd.hasOption('D')) { for (Map.Entry e : cmd.getOptionProperties("D").entrySet()) { result.setProperty(e.getKey().toString(), e.getValue()); } } for (LoaderBackend b : backends) { for (Option option : b.getOptions()) { if (cmd.hasOption(option.getOpt())) { String key = String.format("backend.%s.%s", b.getIdentifier(), option.getLongOpt() != null ? option.getLongOpt() : option.getOpt()); if (option.hasArg()) { if (option.hasArgs()) { result.setProperty(key, Arrays.asList(cmd.getOptionValues(option.getOpt()))); } else { result.setProperty(key, cmd.getOptionValue(option.getOpt())); } } else { result.setProperty(key, true); } } } } return result; }
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 ava 2 s .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.CopyOfMavenCli.java
static void populateProperties(CommandLine commandLine, Properties systemProperties, Properties userProperties) { EnvironmentUtils.addEnvVars(systemProperties); // ---------------------------------------------------------------------- // Options that are set on the command line become system properties // and therefore are set in the session properties. System properties // are most dominant. // ---------------------------------------------------------------------- if (commandLine.hasOption(CLIManager.SET_SYSTEM_PROPERTY)) { String[] defStrs = commandLine.getOptionValues(CLIManager.SET_SYSTEM_PROPERTY); if (defStrs != null) { for (String defStr : defStrs) { setCliProperty(defStr, userProperties); }// w w w . j av a2 s . c o m } } SystemProperties.addSystemProperties(systemProperties); // ---------------------------------------------------------------------- // Properties containing info about the currently running version of Maven // These override any corresponding properties set on the command line // ---------------------------------------------------------------------- Properties buildProperties = CLIReportingUtils.getBuildProperties(); String mavenVersion = buildProperties.getProperty(CLIReportingUtils.BUILD_VERSION_PROPERTY); systemProperties.setProperty("maven.version", mavenVersion); String mavenBuildVersion = CLIReportingUtils.createMavenVersionString(buildProperties); systemProperties.setProperty("maven.build.version", mavenBuildVersion); }
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 w ww . j a v 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.DefaultMavenExecutionRequestBuilder.java
static void populateProperties(CommandLine commandLine, Properties systemProperties, Properties userProperties) { EnvironmentUtils.addEnvVars(systemProperties); // ---------------------------------------------------------------------- // Options that are set on the command line become system properties // and therefore are set in the session properties. System properties // are most dominant. // ---------------------------------------------------------------------- if (commandLine.hasOption(CLIManager.SET_SYSTEM_PROPERTY)) { String[] defStrs = commandLine.getOptionValues(CLIManager.SET_SYSTEM_PROPERTY); if (defStrs != null) { for (String defStr : defStrs) { setCliProperty(defStr, userProperties); }/*from w w w .j a va 2 s . co m*/ } } systemProperties.putAll(System.getProperties()); // ---------------------------------------------------------------------- // Properties containing info about the currently running version of Maven // These override any corresponding properties set on the command line // ---------------------------------------------------------------------- Properties buildProperties = CLIReportingUtils.getBuildProperties(); String mavenVersion = buildProperties.getProperty(CLIReportingUtils.BUILD_VERSION_PROPERTY); systemProperties.setProperty("maven.version", mavenVersion); String mavenBuildVersion = CLIReportingUtils.createMavenVersionString(buildProperties); systemProperties.setProperty("maven.build.version", mavenBuildVersion); }
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 ww w.ja v 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<>(); 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."); }/*from w w w. j a v a 2s . 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; }