All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.maven.settings.validation.DefaultSettingsValidator Maven / Gradle / Ivy

There is a newer version: 4.0.0-beta-5
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.maven.settings.validation;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import java.util.List;
import java.util.regex.Pattern;

import org.apache.maven.api.services.BuilderProblem;
import org.apache.maven.api.services.SettingsBuilder;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.building.SettingsProblem.Severity;
import org.apache.maven.settings.building.SettingsProblemCollector;

/**
 */
@Named
@Singleton
public class DefaultSettingsValidator implements SettingsValidator {

    private static final String ID = "[\\w.-]+";
    private static final Pattern ID_REGEX = Pattern.compile(ID);

    private final SettingsBuilder settingsBuilder;

    @Inject
    public DefaultSettingsValidator(SettingsBuilder settingsBuilder) {
        this.settingsBuilder = settingsBuilder;
    }

    @Override
    public void validate(Settings settings, SettingsProblemCollector problems) {
        validate(settings, false, problems);
    }

    @Override
    public void validate(Settings settings, boolean isProjectSettings, SettingsProblemCollector problems) {
        List list = settingsBuilder.validate(settings.getDelegate(), isProjectSettings);
        for (BuilderProblem problem : list) {
            addViolation(problems, Severity.valueOf(problem.getSeverity().name()), problem.getMessage());
        }
    }

    // ----------------------------------------------------------------------
    // Field validation
    // ----------------------------------------------------------------------

    private static void addViolation(SettingsProblemCollector problems, Severity severity, String message) {
        problems.add(severity, message, -1, -1, null);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy