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 run();
81
82 logoutOnDemand(loginRequired);
83 }
84
85 private void loginOnDemand(final boolean loginRequired)
86 throws MojoFailureException
87 {
88 if (loginRequired)
89 {
90 final LoginCommand loginCommand =
91 commandFactory.createLoginCommand(server);
92 console.execute(loginCommand);
93 }
94 else
95 {
96 final LogLevel logLevel = new LogLevel(verbose);
97 if (logLevel.isVerbose())
98 {
99 getLog()
100 .info(
101 "Login skipped since no credentials specified.\n"
102 + "Please refer to\n"
103 + " http://www.smartics.eu/bugzilla-maven-plugin/usage.html#Basic_Configuration\n"
104 + "for information on how to configure login credentials.");
105 }
106 }
107 }
108
109 private void logoutOnDemand(final boolean loginRequired)
110 throws MojoFailureException
111 {
112 if (loginRequired)
113 {
114 final LogoutCommand logoutCommand = commandFactory.createLogoutCommand();
115 console.execute(logoutCommand);
116 }
117 }
118
119
120
121
122
123
124
125
126
127
128 protected abstract void run() throws MojoExecutionException,
129 MojoFailureException;
130
131
132
133 }