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.toolchain.model.PersistedToolchains;
23  import org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Reader;
24  import org.codehaus.plexus.component.annotations.Component;
25  import org.codehaus.plexus.component.annotations.Requirement;
26  import org.codehaus.plexus.logging.Logger;
27  import org.codehaus.plexus.util.ReaderFactory;
28  
29  import java.io.File;
30  import java.io.Reader;
31  
32  /**
33   * @author Benjamin Bentmann
34   * @deprecated instead use {@link org.apache.maven.toolchain.building.DefaultToolchainsBuilder}
35   */
36  @Deprecated
37  @Component( role = ToolchainsBuilder.class, hint = "default" )
38  public class DefaultToolchainsBuilder
39      implements ToolchainsBuilder
40  {
41  
42      @Requirement
43      private Logger logger;
44  
45      public PersistedToolchains build( File userToolchainsFile )
46          throws MisconfiguredToolchainException
47      {
48          PersistedToolchains toolchains = null;
49  
50          if ( userToolchainsFile != null && userToolchainsFile.isFile() )
51          {
52              try ( Reader in = ReaderFactory.newXmlReader( userToolchainsFile ) )
53              {
54                  toolchains = new MavenToolchainsXpp3Reader().read( in );
55              }
56              catch ( Exception e )
57              {
58                  throw new MisconfiguredToolchainException(
59                      "Cannot read toolchains file at " + userToolchainsFile.getAbsolutePath(), e );
60              }
61  
62          }
63          else if ( userToolchainsFile != null )
64          {
65              logger.debug( "Toolchains configuration was not found at " + userToolchainsFile );
66          }
67  
68          return toolchains;
69      }
70  
71  }