View Javadoc

1   /**
2    * Pyx4me framework
3    * Copyright (C) 2006-2008 pyx4j.com.
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing,
12   * software distributed under the License is distributed on an
13   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14   * KIND, either express or implied.  See the License for the
15   * specific language governing permissions and limitations
16   * under the License.
17   * 
18   * @author vlads
19   * @version $Id: AbstractDeviceMojo.java 2066 2008-06-21 23:16:18Z vlads $
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  	 * The server id prefix in settings.xml to use when connecting.
33  	 * 
34  	 * @parameter expression="${obex.server}" default-value="obex-device"
35  	 * @required
36  	 */
37  	protected String server = "obex-device";
38  
39  	/**
40  	 * Specifies optional sufix for server ID to use.
41  	 * 
42  	 * @parameter expression="${obex.c}"
43  	 */
44  	protected String serverSufix;
45  
46  	/**
47  	 * The current user system settings for use in Maven.
48  	 * 
49  	 * @parameter expression="${settings}"
50  	 * @required
51  	 * @readonly
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  }