in daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java [940:997]
private static void configure(
CliRequest cliRequest,
EventSpyDispatcher eventSpyDispatcher,
Map<String, ConfigurationProcessor> configurationProcessors)
throws Exception {
//
// This is not ideal but there are events specifically for configuration from the CLI which I don't
// believe are really valid but there are ITs which assert the right events are published so this
// needs to be supported so the EventSpyDispatcher needs to be put in the CliRequest so that
// it can be accessed by configuration processors.
//
cliRequest.request.setEventSpyDispatcher(eventSpyDispatcher);
//
// We expect at most 2 implementations to be available. The SettingsXmlConfigurationProcessor implementation
// is always available in the core and likely always will be, but we may have another ConfigurationProcessor
// present supplied by the user. The rule is that we only allow the execution of one ConfigurationProcessor.
// If there is more than one then we execute the one supplied by the user, otherwise we execute the
// the default SettingsXmlConfigurationProcessor.
//
int userSuppliedConfigurationProcessorCount = configurationProcessors.size() - 1;
if (userSuppliedConfigurationProcessorCount == 0) {
//
// Our settings.xml source is historically how we have configured Maven from the CLI so we are going to
// have to honour its existence forever. So let's run it.
//
configurationProcessors.get(SettingsXmlConfigurationProcessor.HINT).process(cliRequest);
} else if (userSuppliedConfigurationProcessorCount == 1) {
//
// Run the user supplied ConfigurationProcessor
//
for (Entry<String, ConfigurationProcessor> entry : configurationProcessors.entrySet()) {
String hint = entry.getKey();
if (!hint.equals(SettingsXmlConfigurationProcessor.HINT)) {
ConfigurationProcessor configurationProcessor = entry.getValue();
configurationProcessor.process(cliRequest);
}
}
} else if (userSuppliedConfigurationProcessorCount > 1) {
//
// There are too many ConfigurationProcessors so we don't know which one to run so report the error.
//
StringBuilder sb = new StringBuilder(String.format(
"\nThere can only be one user supplied ConfigurationProcessor, there are %s:\n\n",
userSuppliedConfigurationProcessorCount));
for (Entry<String, ConfigurationProcessor> entry : configurationProcessors.entrySet()) {
String hint = entry.getKey();
if (!hint.equals(SettingsXmlConfigurationProcessor.HINT)) {
ConfigurationProcessor configurationProcessor = entry.getValue();
sb.append(String.format(
"%s\n", configurationProcessor.getClass().getName()));
}
}
sb.append("\n");
throw new Exception(sb.toString());
}
}