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