1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.ci.maven.mojo;
17
18 import java.util.Properties;
19
20 import org.apache.maven.plugin.MojoExecutionException;
21 import org.apache.maven.plugin.MojoFailureException;
22
23 import de.smartics.ci.comm.CiController;
24 import de.smartics.ci.comm.LogLevel;
25 import de.smartics.ci.comm.command.CommandException;
26
27
28
29
30
31
32
33
34 public class GenericJobApiUsageHudsonCiMojo extends AbstractHudsonCiMojo
35 {
36
37
38
39
40
41
42
43
44
45
46
47
48
49 private String xmlQueryString;
50
51
52
53
54
55
56
57
58 private String ciXmlJobApiUrl;
59
60
61
62
63
64
65
66
67 private String regexp;
68
69
70
71
72
73
74
75 private String jobName;
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 public final void execute() throws MojoExecutionException,
97 MojoFailureException
98 {
99 executeManualConfiguration();
100 }
101
102 private void executeManualConfiguration() throws MojoExecutionException
103 {
104 final LogLevel logLevel = new LogLevel(verbose);
105 try
106 {
107 final CiController controller = loginToCiServer(logLevel);
108 executeCommand(jobName, null, controller);
109 }
110 catch (final Exception e)
111 {
112 logError("Terminated handling jobs. Rollback not possile. Please check status manually at: "
113 + getCiServer().getUrl());
114 throw new MojoExecutionException("Cannot handle jobName " + jobName, e);
115 }
116 }
117
118
119
120
121
122
123 public final void executeCommand(final String jobName,
124 final String jobConfigString, final CiController controller)
125 throws CommandException
126 {
127 executeGenericJob(controller, jobName);
128 }
129
130 private void executeGenericJob(final CiController controller,
131 final String jobName) throws CommandException
132 {
133 final Properties properties = project.getProperties();
134 addCiServerUrl(properties);
135 controller.executeGenericJobCommand(jobName, ciXmlJobApiUrl,
136 xmlQueryString, regexp, properties);
137 }
138
139 private void addCiServerUrl(final Properties properties)
140 {
141 try
142 {
143 final String ciServerUrl = getCiServer().getUrl();
144 properties.put("ciServer", ciServerUrl);
145 }
146 catch (final MojoExecutionException e)
147 {
148 if (logger.isWarnEnabled())
149 {
150 logger.warn("ciServerUrl could not be retrieved.");
151 }
152 }
153 }
154
155
156
157 }