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
52
53
54
55
56
57
58
59
60
61 public final void execute() throws MojoExecutionException,
62 MojoFailureException
63 {
64 if (isToSkip())
65 {
66 return;
67 }
68
69 super.execute();
70
71 final BugzillaCommandFactory bugzillaCommandFactory =
72 new BugzillaCommandFactory();
73
74 final MavenProject project = getProject();
75 commandFactory = new MavenCommandFactory(project, bugzillaCommandFactory);
76
77 final boolean loginRequired = StringUtils.isNotBlank(server.getUsername());
78 loginOnDemand(loginRequired);
79
80 try
81 {
82 run();
83 }
84 finally
85 {
86 logoutOnDemand(loginRequired);
87 }
88 }
89
90 private void loginOnDemand(final boolean loginRequired)
91 throws MojoFailureException
92 {
93 if (loginRequired)
94 {
95 final LoginCommand loginCommand =
96 commandFactory.createLoginCommand(server);
97 console.execute(loginCommand);
98 }
99 else
100 {
101 final LogLevel logLevel = new LogLevel(verbose);
102 if (logLevel.isVerbose())
103 {
104 getLog()
105 .info(
106 "Login skipped since no credentials specified.\n"
107 + "Please refer to\n"
108 + " http://www.smartics.eu/bugzilla-maven-plugin/usage.html#Basic_Configuration\n"
109 + "for information on how to configure login credentials.");
110 }
111 }
112 }
113
114 private void logoutOnDemand(final boolean loginRequired)
115 throws MojoFailureException
116 {
117 if (loginRequired)
118 {
119 final LogoutCommand logoutCommand = commandFactory.createLogoutCommand();
120 console.execute(logoutCommand);
121 }
122 }
123
124
125
126
127
128
129
130
131
132
133 protected abstract void run() throws MojoExecutionException,
134 MojoFailureException;
135
136
137
138 }