View Javadoc
1   package org.apache.maven.toolchain;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.api.toolchain.PersistedToolchains;
23  import org.apache.maven.toolchain.v4.MavenToolchainsXpp3Reader;
24  import org.codehaus.plexus.util.ReaderFactory;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  import java.io.File;
29  import java.io.Reader;
30  
31  import javax.inject.Named;
32  import javax.inject.Singleton;
33  
34  /**
35   * @author Benjamin Bentmann
36   * @deprecated instead use {@link org.apache.maven.toolchain.building.DefaultToolchainsBuilder}
37   */
38  @Deprecated
39  @Named( "default" )
40  @Singleton
41  public class DefaultToolchainsBuilder
42      implements ToolchainsBuilder
43  {
44      private final Logger logger = LoggerFactory.getLogger( getClass() );
45  
46      public PersistedToolchains build( File userToolchainsFile )
47          throws MisconfiguredToolchainException
48      {
49          PersistedToolchains toolchains = null;
50  
51          if ( userToolchainsFile != null && userToolchainsFile.isFile() )
52          {
53              try ( Reader in = ReaderFactory.newXmlReader( userToolchainsFile ) )
54              {
55                  toolchains = new MavenToolchainsXpp3Reader().read( in );
56              }
57              catch ( Exception e )
58              {
59                  throw new MisconfiguredToolchainException(
60                      "Cannot read toolchains file at " + userToolchainsFile.getAbsolutePath(), e );
61              }
62  
63          }
64          else if ( userToolchainsFile != null )
65          {
66              logger.debug( "Toolchains configuration was not found at " + userToolchainsFile );
67          }
68  
69          return toolchains;
70      }
71  
72  }