View Javadoc

1   package org.apache.maven.plugin.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 java.util.HashMap;
23  import java.util.Map;
24  
25  import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
26  import org.codehaus.plexus.component.configurator.ConfigurationListener;
27  import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter;
28  import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter;
29  import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
30  import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
31  import org.codehaus.plexus.configuration.PlexusConfiguration;
32  import org.codehaus.plexus.configuration.PlexusConfigurationException;
33  
34  /**
35   * Plexus ConfigurationConverter
36   *
37   * @author mkleint
38   */
39  public class ToolchainConverter
40      extends AbstractConfigurationConverter
41  {
42  
43      public static final String ROLE = ConfigurationConverter.class.getName();
44  
45      /**
46       * @see org.codehaus.plexus.component.configurator.converters.ConfigurationConverter#canConvert(java.lang.Class)
47       */
48      public boolean canConvert( Class type )
49      {
50          return Toolchains.class.isAssignableFrom( type );
51      }
52  
53      /**
54       * @see org.codehaus.plexus.component.configurator.converters.ConfigurationConverter#fromConfiguration(org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup, org.codehaus.plexus.configuration.PlexusConfiguration, java.lang.Class, java.lang.Class, java.lang.ClassLoader, org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator, org.codehaus.plexus.component.configurator.ConfigurationListener)
55       */
56      public Object fromConfiguration( ConverterLookup converterLookup,
57                                       PlexusConfiguration configuration,
58                                       Class type, Class baseType,
59                                       ClassLoader classLoader,
60                                       ExpressionEvaluator expressionEvaluator,
61                                       ConfigurationListener listener )
62          throws ComponentConfigurationException
63      {
64          Toolchains retValue = new Toolchains();
65          processConfiguration( retValue, configuration, expressionEvaluator );
66  
67          return retValue;
68      }
69  
70      private void processConfiguration( Toolchains chain,
71                                         PlexusConfiguration configuration,
72                                         ExpressionEvaluator expressionEvaluator )
73          throws ComponentConfigurationException
74      {
75          Map map = new HashMap();
76          PlexusConfiguration[] tools = configuration.getChildren();
77          for ( int i = 0; i < tools.length; i++ )
78          {
79              String type = tools[i].getName();
80              PlexusConfiguration[] params = tools[i].getChildren();
81              Map parameters = new HashMap();
82              for ( int j = 0; j < params.length; j++ )
83              {
84                  try
85                  {
86                      String name = params[j].getName();
87                      String val = params[j].getValue();
88                      parameters.put( name, val );
89                  }
90                  catch ( PlexusConfigurationException ex )
91                  {
92                      throw new ComponentConfigurationException( ex );
93                  }
94              }
95              map.put( type, parameters );
96          }
97          chain.toolchains = map;
98      }
99  }