ARTEMIS-574 fixing home and instance on DTO, CLI and maven plugin

This commit is contained in:
Clebert Suconic 2016-06-17 14:57:01 -04:00
parent ad5e7bf68b
commit 286a4ba9ed
5 changed files with 34 additions and 6 deletions

View File

@ -148,7 +148,7 @@ public abstract class Configurable extends ActionAbstract {
if (brokerDTO == null) {
getConfiguration();
brokerDTO = BrokerFactory.createBrokerConfiguration(configuration);
brokerDTO = BrokerFactory.createBrokerConfiguration(configuration, getBrokerHome(), getBrokerInstance());
if (brokerConfig != null) {
if (!brokerConfig.startsWith("file:")) {

View File

@ -30,6 +30,10 @@ import org.apache.activemq.artemis.utils.FactoryFinder;
public class BrokerFactory {
public static BrokerDTO createBrokerConfiguration(URI configURI) throws Exception {
return createBrokerConfiguration(configURI, null, null);
}
public static BrokerDTO createBrokerConfiguration(URI configURI, String artemisHome, String artemisInstance) throws Exception {
if (configURI.getScheme() == null) {
throw new ConfigurationException("Invalid configuration URI, no scheme specified: " + configURI);
}
@ -43,11 +47,16 @@ public class BrokerFactory {
throw new ConfigurationException("Invalid configuration URI, can't find configuration scheme: " + configURI.getScheme());
}
return factory.createBroker(configURI);
return factory.createBroker(configURI, artemisHome, artemisInstance);
}
public static BrokerDTO createBrokerConfiguration(String configuration) throws Exception {
return createBrokerConfiguration(new URI(configuration));
return createBrokerConfiguration(new URI(configuration), null, null);
}
public static BrokerDTO createBrokerConfiguration(String configuration, String artemisHome, String artemisInstance) throws Exception {
return createBrokerConfiguration(new URI(configuration), artemisHome, artemisInstance);
}
static String fixupFileURI(String value) {

View File

@ -23,4 +23,6 @@ import java.net.URI;
public interface BrokerFactoryHandler {
BrokerDTO createBroker(URI brokerURI) throws Exception;
BrokerDTO createBroker(URI brokerURI, String artemisHome, String artemisInstance) throws Exception;
}

View File

@ -27,10 +27,15 @@ public class XmlBrokerFactoryHandler implements BrokerFactoryHandler {
@Override
public BrokerDTO createBroker(URI brokerURI) throws Exception {
return createBroker(brokerURI, null, null);
}
@Override
public BrokerDTO createBroker(URI brokerURI, String artemisHome, String artemisInstance) throws Exception {
File file = new File(brokerURI.getSchemeSpecificPart());
if (!file.exists()) {
throw new ConfigurationException("Invalid configuration URI, can't find file: " + file.getName());
}
return XmlUtil.decode(BrokerDTO.class, file);
return XmlUtil.decode(BrokerDTO.class, file, artemisHome, artemisInstance);
}
}

View File

@ -76,6 +76,11 @@ public class XmlUtil {
private static final XMLInputFactory factory = XMLInputFactory.newInstance();
public static <T> T decode(Class<T> clazz, File configuration) throws Exception {
return decode(clazz, configuration, null, null);
}
/** We offer parameters for artemisInstance and artemisHoms as they could be coming from the CLI or Maven Plugin */
public static <T> T decode(Class<T> clazz, File configuration, String artemisHome, String artemisInstance) throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance("org.apache.activemq.artemis.dto");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
@ -86,9 +91,16 @@ public class XmlUtil {
Schema schema = sf.newSchema(xsdSource);
unmarshaller.setSchema(schema);
Properties props = new Properties(System.getProperties());
if (artemisHome != null) {
props.put("artemis.home", artemisHome);
}
if (artemisInstance != null) {
props.put("artemis.instance", artemisInstance);
}
XMLStreamReader reader = factory.createXMLStreamReader(new FileInputStream(configuration));
//TODO - support properties files
Properties props = System.getProperties();
if (props != null) {
reader = new PropertiesFilter(reader, props);