1 package org.apache.maven.continuum.notification.console;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.continuum.model.project.ProjectScmRoot;
23 import org.apache.maven.continuum.model.project.BuildResult;
24 import org.apache.maven.continuum.model.project.Project;
25 import org.apache.maven.continuum.notification.AbstractContinuumNotifier;
26 import org.apache.maven.continuum.notification.ContinuumNotificationDispatcher;
27 import org.apache.maven.continuum.notification.MessageContext;
28 import org.apache.maven.continuum.notification.NotificationException;
29 import org.codehaus.plexus.util.StringUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37
38
39 public class ConsoleNotifier
40 extends AbstractContinuumNotifier
41 {
42 private static final Logger log = LoggerFactory.getLogger( ConsoleNotifier.class );
43
44
45
46
47
48 public String getType()
49 {
50 return "console";
51 }
52
53 public void sendMessage( String messageId, MessageContext context )
54 throws NotificationException
55 {
56 Project project = context.getProject();
57
58 BuildResult build = context.getBuildResult();
59
60 ProjectScmRoot projectScmRoot = context.getProjectScmRoot();
61
62 if ( messageId.equals( ContinuumNotificationDispatcher.MESSAGE_ID_BUILD_STARTED ) )
63 {
64 buildStarted( project );
65 }
66 else if ( messageId.equals( ContinuumNotificationDispatcher.MESSAGE_ID_CHECKOUT_STARTED ) )
67 {
68 checkoutStarted( project );
69 }
70 else if ( messageId.equals( ContinuumNotificationDispatcher.MESSAGE_ID_CHECKOUT_COMPLETE ) )
71 {
72 checkoutComplete( project );
73 }
74 else if ( messageId.equals( ContinuumNotificationDispatcher.MESSAGE_ID_RUNNING_GOALS ) )
75 {
76 runningGoals( project, build );
77 }
78 else if ( messageId.equals( ContinuumNotificationDispatcher.MESSAGE_ID_GOALS_COMPLETED ) )
79 {
80 goalsCompleted( project, build );
81 }
82 else if ( messageId.equals( ContinuumNotificationDispatcher.MESSAGE_ID_BUILD_COMPLETE ) )
83 {
84 buildComplete( project, build );
85 }
86 else if ( messageId.equals( ContinuumNotificationDispatcher.MESSAGE_ID_PREPARE_BUILD_COMPLETE ) )
87 {
88 prepareBuildComplete( projectScmRoot );
89 }
90 else
91 {
92 log.warn( "Unknown messageId: '" + messageId + "'." );
93 }
94 }
95
96
97
98
99
100 private void buildStarted( Project project )
101 {
102 out( project, null, "Build started." );
103 }
104
105 private void checkoutStarted( Project project )
106 {
107 out( project, null, "Checkout started." );
108 }
109
110 private void checkoutComplete( Project project )
111 {
112 out( project, null, "Checkout complete." );
113 }
114
115 private void runningGoals( Project project, BuildResult build )
116 {
117 out( project, build, "Running goals." );
118 }
119
120 private void goalsCompleted( Project project, BuildResult build )
121 {
122 if ( build.getError() == null )
123 {
124 out( project, build, "Goals completed. state: " + build.getState() );
125 }
126 else
127 {
128 out( project, build, "Goals completed." );
129 }
130 }
131
132 private void buildComplete( Project project, BuildResult build )
133 {
134 if ( build.getError() == null )
135 {
136 out( project, build, "Build complete. state: " + build.getState() );
137 }
138 else
139 {
140 out( project, build, "Build complete." );
141 }
142 }
143
144 private void prepareBuildComplete( ProjectScmRoot projectScmRoot )
145 {
146 if ( StringUtils.isEmpty( projectScmRoot.getError() ) )
147 {
148 out( projectScmRoot, "Prepare build complete. state: " + projectScmRoot.getState() );
149 }
150 else
151 {
152 out( projectScmRoot, "Prepare build complete." );
153 }
154 }
155
156 private void out( Project project, BuildResult build, String msg )
157 {
158 System.out.println( "Build event for project '" + project.getName() + "':" + msg );
159
160 if ( build != null && !StringUtils.isEmpty( build.getError() ) )
161 {
162 System.out.println( build.getError() );
163 }
164 }
165
166 private void out( ProjectScmRoot projectScmRoot, String msg )
167 {
168 if ( projectScmRoot != null )
169 {
170 System.out.println( "Prepare build event for '" + projectScmRoot.getScmRootAddress() + "':" + msg );
171
172 if ( !StringUtils.isEmpty( projectScmRoot.getError() ) )
173 {
174 System.out.println( projectScmRoot.getError() );
175 }
176 }
177 }
178 }