View Javadoc

1   package org.apache.maven.scm.manager.plexus;
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.scm.log.ScmLogger;
23  import org.apache.maven.scm.manager.AbstractScmManager;
24  import org.apache.maven.scm.provider.ScmProvider;
25  import org.codehaus.plexus.logging.LogEnabled;
26  import org.codehaus.plexus.logging.Logger;
27  import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
28  
29  import java.util.HashMap;
30  import java.util.Map;
31  
32  /**
33   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
34   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
35   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
36   * @author Olivier Lamy
37   *
38   * @plexus.component role="org.apache.maven.scm.manager.ScmManager"
39   */
40  public class DefaultScmManager
41      extends AbstractScmManager
42      implements Initializable, LogEnabled
43  {
44      /**
45       * @plexus.requirement role="org.apache.maven.scm.provider.ScmProvider"
46       */
47      private Map<String,ScmProvider> scmProviders;
48  
49      private Logger logger;
50  
51      // ----------------------------------------------------------------------
52      // LogEnabled implementation
53      // ----------------------------------------------------------------------
54  
55      public void enableLogging( Logger logger )
56      {
57          this.logger = logger;
58      }
59  
60      protected Logger getLogger()
61      {
62          return logger;
63      }
64  
65      protected void setupLogger( Object component )
66      {
67          setupLogger( component, logger );
68      }
69  
70      protected void setupLogger( Object component, String subCategory )
71      {
72          if ( subCategory == null )
73          {
74              throw new IllegalStateException( "Logging category must be defined." );
75          }
76  
77          Logger logger = this.logger.getChildLogger( subCategory );
78  
79          setupLogger( component, logger );
80      }
81  
82      protected void setupLogger( Object component, Logger logger )
83      {
84          if ( component instanceof LogEnabled )
85          {
86              ( (LogEnabled) component ).enableLogging( logger );
87          }
88      }
89  
90      // ----------------------------------------------------------------------
91      // Component Lifecycle
92      // ----------------------------------------------------------------------
93  
94      /** {@inheritDoc} */
95      public void initialize()
96      {
97          if ( scmProviders == null )
98          {
99              scmProviders = new HashMap<String,ScmProvider>( 0 );
100         }
101 
102         if ( getLogger().isWarnEnabled() && scmProviders.size() == 0 )
103         {
104             getLogger().warn( "No SCM providers configured." );
105         }
106 
107         setScmProviders( scmProviders );
108     }
109 
110     /** {@inheritDoc} */
111     protected ScmLogger getScmLogger()
112     {
113         return new PlexusLogger( getLogger() );
114     }
115 }