Search in sources :

Example 1 with SettingsProblem

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("");
    }
}
Also used : Path(java.nio.file.Path) CommandLine(org.apache.commons.cli.CommandLine) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) FileNotFoundException(java.io.FileNotFoundException) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Example 2 with SettingsProblem

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;
    }
}
Also used : Server(org.apache.maven.settings.Server) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) DefaultSettingsBuilder(org.apache.maven.settings.building.DefaultSettingsBuilder) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) SettingsProblem(org.apache.maven.settings.building.SettingsProblem) Settings(org.apache.maven.settings.Settings) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Example 3 with SettingsProblem

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.");
    }
}
Also used : SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Example 4 with SettingsProblem

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");
    }
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) Server(org.apache.maven.settings.Server) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Example 5 with SettingsProblem

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();
}
Also used : SettingsDecrypter(org.apache.maven.settings.crypto.SettingsDecrypter) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionRequest(org.apache.maven.settings.crypto.SettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Aggregations

SettingsProblem (org.apache.maven.settings.building.SettingsProblem)9 Server (org.apache.maven.settings.Server)5 DefaultSettingsDecryptionRequest (org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest)4 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)4 SettingsBuildingResult (org.apache.maven.settings.building.SettingsBuildingResult)3 FileNotFoundException (java.io.FileNotFoundException)2 Path (java.nio.file.Path)2 CommandLine (org.apache.commons.cli.CommandLine)2 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)2 Proxy (org.apache.maven.settings.Proxy)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Settings (org.apache.maven.settings.Settings)1 DefaultSettingsBuilder (org.apache.maven.settings.building.DefaultSettingsBuilder)1 DefaultSettingsBuilderFactory (org.apache.maven.settings.building.DefaultSettingsBuilderFactory)1 DefaultSettingsBuildingRequest (org.apache.maven.settings.building.DefaultSettingsBuildingRequest)1 DefaultSettingsProblem (org.apache.maven.settings.building.DefaultSettingsProblem)1 SettingsBuildingRequest (org.apache.maven.settings.building.SettingsBuildingRequest)1 DefaultSettingsDecrypter (org.apache.maven.settings.crypto.DefaultSettingsDecrypter)1 SettingsDecrypter (org.apache.maven.settings.crypto.SettingsDecrypter)1