001package org.apache.maven.toolchain;
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.toolchain.model.PersistedToolchains;
023import org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Reader;
024import org.codehaus.plexus.component.annotations.Component;
025import org.codehaus.plexus.component.annotations.Requirement;
026import org.codehaus.plexus.logging.Logger;
027import org.codehaus.plexus.util.ReaderFactory;
028
029import java.io.File;
030import java.io.Reader;
031
032/**
033 * @author Benjamin Bentmann
034 * @deprecated instead use {@link org.apache.maven.toolchain.building.DefaultToolchainsBuilder}
035 */
036@Deprecated
037@Component( role = ToolchainsBuilder.class, hint = "default" )
038public class DefaultToolchainsBuilder
039    implements ToolchainsBuilder
040{
041
042    @Requirement
043    private Logger logger;
044
045    public PersistedToolchains build( File userToolchainsFile )
046        throws MisconfiguredToolchainException
047    {
048        PersistedToolchains toolchains = null;
049
050        if ( userToolchainsFile != null && userToolchainsFile.isFile() )
051        {
052            try ( Reader in = ReaderFactory.newXmlReader( userToolchainsFile ) )
053            {
054                toolchains = new MavenToolchainsXpp3Reader().read( in );
055            }
056            catch ( Exception e )
057            {
058                throw new MisconfiguredToolchainException(
059                    "Cannot read toolchains file at " + userToolchainsFile.getAbsolutePath(), e );
060            }
061
062        }
063        else if ( userToolchainsFile != null )
064        {
065            logger.debug( "Toolchains configuration was not found at " + userToolchainsFile );
066        }
067
068        return toolchains;
069    }
070
071}