1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.maven.bugzilla;
17
18 import org.apache.maven.plugin.MojoExecutionException;
19 import org.apache.maven.plugin.MojoFailureException;
20 import org.apache.maven.project.MavenProject;
21 import org.codehaus.plexus.util.StringUtils;
22
23 import de.smartics.maven.bugzilla.command.BugzillaCommandFactory;
24 import de.smartics.maven.issue.command.LoginCommand;
25 import de.smartics.maven.issue.command.LogoutCommand;
26 import de.smartics.maven.issue.util.LogLevel;
27
28
29
30
31 public abstract class AbstractIssueManagementMojo extends AbstractIssueMojo
32 {
33
34
35
36
37
38
39
40
41
42 protected MavenCommandFactory commandFactory;
43
44
45
46
47
48
49
50
51 protected String issueServerVersion;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 public final void execute() throws MojoExecutionException,
71 MojoFailureException
72 {
73 if (isToSkip())
74 {
75 return;
76 }
77
78 super.execute();
79
80 final BugzillaCommandFactory bugzillaCommandFactory =
81 new BugzillaCommandFactory(issueServerVersion);
82
83 final MavenProject project = getProject();
84 commandFactory = new MavenCommandFactory(project, bugzillaCommandFactory);
85
86 final boolean loginRequired = StringUtils.isNotBlank(server.getUsername());
87 loginOnDemand(loginRequired);
88
89 try
90 {
91 run();
92 }
93 finally
94 {
95 logoutOnDemand(loginRequired);
96 }
97 }
98
99 private void loginOnDemand(final boolean loginRequired)
100 throws MojoFailureException
101 {
102 if (loginRequired)
103 {
104 final LoginCommand loginCommand =
105 commandFactory.createLoginCommand(server);
106 console.execute(loginCommand);
107 }
108 else
109 {
110 final LogLevel logLevel = new LogLevel(verbose);
111 if (logLevel.isVerbose())
112 {
113 getLog()
114 .info(
115 "Login skipped since no credentials specified.\n"
116 + "Please refer to\n"
117 + " http://www.smartics.eu/bugzilla-maven-plugin/usage.html#Basic_Configuration\n"
118 + "for information on how to configure login credentials.");
119 }
120 }
121 }
122
123 private void logoutOnDemand(final boolean loginRequired)
124 throws MojoFailureException
125 {
126 if (loginRequired)
127 {
128 final LogoutCommand logoutCommand = commandFactory.createLogoutCommand();
129 console.execute(logoutCommand);
130 }
131 }
132
133
134
135
136
137
138
139
140
141
142 protected abstract void run() throws MojoExecutionException,
143 MojoFailureException;
144
145
146
147 }