1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.pyx4me.maven.obex;
22
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoFailureException;
25 import org.apache.maven.plugin.logging.Log;
26 import org.apache.maven.settings.Server;
27 import org.apache.maven.settings.Settings;
28 import org.codehaus.plexus.util.xml.Xpp3Dom;
29
30 public abstract class AbstractDeviceMojo extends AbstractMojo {
31
32
33
34
35
36
37 protected String server = "obex-device";
38
39
40
41
42
43
44 protected String serverSufix;
45
46
47
48
49
50
51
52
53 protected Settings settings;
54
55 private static boolean configured = false;
56
57 protected ServerConfig getServerConfig(String serverSufix) throws MojoFailureException {
58 ServerConfig cfg = new ServerConfig();
59
60 cfg.serverID = server;
61 if (serverSufix != null) {
62 cfg.serverID += serverSufix;
63 }
64
65 Server srv = settings.getServer(cfg.serverID);
66 if (srv == null) {
67 throw new MojoFailureException("You have to configure the server with the id '" + cfg.serverID
68 + "' in your seetings.xml file.");
69 }
70 Xpp3Dom config = (Xpp3Dom) srv.getConfiguration();
71 Xpp3Dom url = config.getChild("url");
72 if (url == null) {
73 throw new MojoFailureException("You have to configure the server '" + cfg.serverID
74 + "' configuration url in your seetings.xml file.");
75 }
76 cfg.url = url.getValue();
77 cfg.alias = cfg.serverID + " (" + url.getValue() + ")";
78 Xpp3Dom aliasXml = config.getChild("alias");
79 if (aliasXml != null) {
80 cfg.alias = aliasXml.getValue();
81 }
82 Xpp3Dom stackXml = config.getChild("stack");
83 if (stackXml != null) {
84 cfg.stack = stackXml.getValue();
85 }
86 return cfg;
87 }
88
89 static void configureBlueCove(ServerConfig cfg, Log log) {
90 if (configured) {
91 return;
92 }
93 configured = true;
94 try {
95 BlueCoveSpecific.configureBlueCove(cfg, log);
96 } catch (Throwable notBlueCove) {
97 }
98 }
99 }