use of org.apache.maven.settings.building.SettingsProblem in project kie-wb-common by kiegroup.
the class AFSettingsXmlConfigurationProcessor method process.
@Override
public void process(AFCliRequest cliRequest) throws Exception {
CommandLine commandLine = cliRequest.getCommandLine();
String workingDirectory = cliRequest.getWorkingDirectory();
MavenExecutionRequest request = cliRequest.getRequest();
Path userSettingsFile;
if (commandLine.hasOption(CLIManager.ALTERNATE_USER_SETTINGS)) {
userSettingsFile = Paths.get(commandLine.getOptionValue(CLIManager.ALTERNATE_USER_SETTINGS));
userSettingsFile = resolvePath(userSettingsFile, workingDirectory);
if (!Files.isRegularFile(userSettingsFile)) {
throw new FileNotFoundException("The specified user settings file does not exist: " + userSettingsFile);
}
} else {
userSettingsFile = DEFAULT_USER_SETTINGS_FILE;
}
Path globalSettingsFile;
if (commandLine.hasOption(CLIManager.ALTERNATE_GLOBAL_SETTINGS)) {
globalSettingsFile = Paths.get(commandLine.getOptionValue(CLIManager.ALTERNATE_GLOBAL_SETTINGS));
globalSettingsFile = resolvePath(globalSettingsFile, workingDirectory);
if (!Files.isRegularFile(globalSettingsFile)) {
throw new FileNotFoundException("The specified global settings file does not exist: " + globalSettingsFile);
}
} else {
globalSettingsFile = DEFAULT_GLOBAL_SETTINGS_FILE;
}
request.setGlobalSettingsFile(globalSettingsFile.toFile());
request.setUserSettingsFile(userSettingsFile.toFile());
AFSettingsBuildingRequest settingsRequest = new AFSettingsBuildingRequest();
settingsRequest.setGlobalSettingsFile(globalSettingsFile.toFile());
settingsRequest.setUserSettingsFile(userSettingsFile.toFile());
settingsRequest.setSystemProperties(cliRequest.getSystemProperties());
settingsRequest.setUserProperties(cliRequest.getUserProperties());
if (request.getEventSpyDispatcher() != null) {
request.getEventSpyDispatcher().onEvent(settingsRequest);
}
logger.debug("Reading global settings from " + getLocation(settingsRequest.getGlobalSettingsSource(), settingsRequest.getGlobalSettingsPath()));
logger.debug("Reading user settings from " + getLocation(settingsRequest.getUserSettingsSource(), settingsRequest.getUserSettingsPath()));
SettingsBuildingResult settingsResult = settingsBuilder.build(settingsRequest);
if (request.getEventSpyDispatcher() != null) {
request.getEventSpyDispatcher().onEvent(settingsResult);
}
populateFromSettings(request, settingsResult.getEffectiveSettings());
if (!settingsResult.getProblems().isEmpty() && logger.isWarnEnabled()) {
logger.warn("");
logger.warn("Some problems were encountered while building the effective settings");
for (SettingsProblem problem : settingsResult.getProblems()) {
logger.warn(problem.getMessage() + " @ " + problem.getLocation());
}
logger.warn("");
}
}
use of org.apache.maven.settings.building.SettingsProblem in project karaf by apache.
the class MavenConfigurationSupport method readSettings.
/**
* Reads on demand <code>settings.xml</code> file - without password decryption. Also
* collects declared servers by ID.
* @param settingsFile
*/
protected synchronized Settings readSettings(File settingsFile) throws SettingsBuildingException {
if (!settingsFile.isFile() || !settingsFile.canRead()) {
return null;
}
try {
DefaultSettingsBuilderFactory factory = new DefaultSettingsBuilderFactory();
DefaultSettingsBuilder builder = factory.newInstance();
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
request.setUserSettingsFile(settingsFile);
SettingsBuildingResult result = builder.build(request);
if (result.getProblems().size() > 0) {
for (SettingsProblem problem : result.getProblems()) {
System.err.println(problem);
}
return null;
} else {
Settings settings = result.getEffectiveSettings();
if (settings.getServers() != null) {
for (Server server : settings.getServers()) {
servers.put(server.getId(), server);
}
}
return settings;
}
} catch (Throwable e) {
System.err.println(e.getMessage());
LOG.error(e.getMessage(), e);
throw e;
}
}
use of org.apache.maven.settings.building.SettingsProblem in project tycho by eclipse.
the class SettingsDecrypterHelper method logProblems.
private void logProblems(SettingsDecryptionResult decryptionResult) {
boolean hasErrors = false;
for (SettingsProblem problem : decryptionResult.getProblems()) {
switch(problem.getSeverity()) {
case FATAL:
case ERROR:
logger.error(problem.toString());
hasErrors = true;
break;
case WARNING:
logger.warn(problem.toString());
break;
default:
throw new IllegalStateException("unknown problem severity: " + problem.getSeverity());
}
}
if (hasErrors) {
throw new RuntimeException("Error(s) while decrypting. See details above.");
}
}
use of org.apache.maven.settings.building.SettingsProblem in project flyway by flyway.
the class AbstractFlywayMojo method loadCredentialsFromSettings.
/**
* Load username and password from settings.
*
* @throws FlywayException when the credentials could not be loaded.
*/
private void loadCredentialsFromSettings() throws FlywayException {
final Server server = settings.getServer(serverId);
if (user == null) {
if (server != null) {
user = server.getUsername();
SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(server));
for (SettingsProblem problem : result.getProblems()) {
if (problem.getSeverity() == SettingsProblem.Severity.ERROR || problem.getSeverity() == SettingsProblem.Severity.FATAL) {
throw new FlywayException("Unable to decrypt password: " + problem, problem.getException());
}
}
password = result.getServer().getPassword();
}
} else if (server != null) {
throw new FlywayException("You specified credentials both in the Flyway config and settings.xml. Use either one or the other");
}
}
use of org.apache.maven.settings.building.SettingsProblem in project sts4 by spring-projects.
the class MavenBridge method decryptPassword.
public Server decryptPassword(Server server) throws MavenException {
SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
SettingsDecryptionResult result = lookup(SettingsDecrypter.class).decrypt(request);
for (SettingsProblem problem : result.getProblems()) {
log.warn(problem.getMessage(), problem.getException());
}
return result.getServer();
}
Aggregations