001package org.apache.maven.settings.building;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.settings.io.DefaultSettingsReader;
023import org.apache.maven.settings.io.DefaultSettingsWriter;
024import org.apache.maven.settings.io.SettingsReader;
025import org.apache.maven.settings.io.SettingsWriter;
026import org.apache.maven.settings.validation.DefaultSettingsValidator;
027import org.apache.maven.settings.validation.SettingsValidator;
028
029/**
030 * A factory to create settings builder instances when no dependency injection is available. <em>Note:</em> This class
031 * is only meant as a utility for developers that want to employ the settings builder outside of the Maven build system,
032 * Maven plugins should always acquire settings builder instances via dependency injection. Developers might want to
033 * subclass this factory to provide custom implementations for some of the components used by the settings builder.
034 *
035 * @author Benjamin Bentmann
036 */
037public class DefaultSettingsBuilderFactory
038{
039
040    protected SettingsReader newSettingsReader()
041    {
042        return new DefaultSettingsReader();
043    }
044
045    protected SettingsWriter newSettingsWriter()
046    {
047        return new DefaultSettingsWriter();
048    }
049
050    protected SettingsValidator newSettingsValidator()
051    {
052        return new DefaultSettingsValidator();
053    }
054
055    /**
056     * Creates a new settings builder instance.
057     *
058     * @return The new settings builder instance, never {@code null}.
059     */
060    public DefaultSettingsBuilder newInstance()
061    {
062        DefaultSettingsBuilder builder = new DefaultSettingsBuilder();
063
064        builder.setSettingsReader( newSettingsReader() );
065        builder.setSettingsWriter( newSettingsWriter() );
066        builder.setSettingsValidator( newSettingsValidator() );
067
068        return builder;
069    }
070
071}