View Javadoc

1   package org.apache.continuum.buildagent.build.execution.manager;
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.continuum.buildagent.build.execution.ContinuumAgentBuildExecutor;
23  import org.apache.maven.continuum.ContinuumException;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  import java.util.HashMap;
28  import java.util.Map;
29  
30  /**
31   * @plexus.component role="org.apache.continuum.buildagent.build.execution.manager.BuildAgentBuildExecutorManager"
32   * role-hint"default"
33   */
34  public class DefaultBuildAgentBuildExecutorManager
35      implements BuildAgentBuildExecutorManager
36  {
37      private static final Logger log = LoggerFactory.getLogger( DefaultBuildAgentBuildExecutorManager.class );
38  
39      /**
40       * @plexus.requirement role="org.apache.continuum.buildagent.build.execution.ContinuumAgentBuildExecutor"
41       */
42      private Map<String, ContinuumAgentBuildExecutor> executors;
43  
44      // ----------------------------------------------------------------------
45      // Component Lifecycle
46      // ----------------------------------------------------------------------
47  
48      public void initialize()
49      {
50          if ( executors == null )
51          {
52              executors = new HashMap<String, ContinuumAgentBuildExecutor>();
53          }
54  
55          if ( executors.size() == 0 )
56          {
57              log.warn( "No build executors defined." );
58          }
59          else
60          {
61              log.info( "Build executors:" );
62  
63              for ( String key : executors.keySet() )
64              {
65                  log.info( "  " + key );
66              }
67          }
68      }
69  
70      // ----------------------------------------------------------------------
71      // BuildExecutorManager Implementation
72      // ----------------------------------------------------------------------
73  
74      public ContinuumAgentBuildExecutor getBuildExecutor( String builderType )
75          throws ContinuumException
76      {
77          ContinuumAgentBuildExecutor executor = executors.get( builderType );
78  
79          if ( executor == null )
80          {
81              throw new ContinuumException( "No such executor: '" + builderType + "'." );
82          }
83  
84          return executor;
85      }
86  
87      public boolean hasBuildExecutor( String executorId )
88      {
89          return executors.containsKey( executorId );
90      }
91  }