1 package org.apache.maven.scm.manager.plexus;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
34
35
36
37
38
39
40 public class DefaultScmManager
41 extends AbstractScmManager
42 implements Initializable, LogEnabled
43 {
44
45
46
47 private Map<String, ScmProvider> scmProviders;
48
49 private Logger logger;
50
51
52
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
92
93
94
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
111 protected ScmLogger getScmLogger()
112 {
113 return new PlexusLogger( getLogger() );
114 }
115 }