From c3288f6644308ee7c778b019ee2a02ee7c04bb41 Mon Sep 17 00:00:00 2001 From: Adam Wisniewski Date: Fri, 15 Mar 2019 23:17:10 -0400 Subject: [PATCH] wildfly runtime prototype --- .../boosters/AbstractBoosterConfig.java | 25 +-- .../liberty/AbstractBoosterLibertyConfig.java | 46 ++++++ .../CDIBoosterLibertyConfig.java} | 12 +- .../JAXRSBoosterLibertyConfig.java} | 10 +- .../JDBCBoosterLibertyConfig.java} | 141 ++++++++-------- .../JPABoosterLibertyConfig.java} | 10 +- .../JSONPBoosterLibertyConfig.java} | 12 +- .../MPConfigBoosterLibertyConfig.java} | 12 +- .../MPHealthBoosterLibertyConfig.java} | 12 +- .../MPOpenTracingBoosterLibertyConfig.java} | 11 +- .../MPRestClientBoosterLibertyConfig.java} | 13 +- .../wildfly/AbstractBoosterWildflyConfig.java | 32 ++++ .../wildfly/CDIBoosterWildflyConfig.java | 37 +++++ .../wildfly/JAXRSBoosterWildflyConfig.java | 36 ++++ .../wildfly/JDBCBoosterWildflyConfig.java | 128 +++++++++++++++ .../wildfly/JPABoosterWildflyConfig.java | 36 ++++ .../wildfly/JSONPBoosterWildflyConfig.java | 37 +++++ .../wildfly/MPConfigBoosterWildflyConfig.java | 36 ++++ .../wildfly/MPHealthBoosterWildflyConfig.java | 36 ++++ .../MPOpenTracingBoosterWildflyConfig.java | 36 ++++ .../MPRestClientBoosterWildflyConfig.java | 37 +++++ .../common/config/BoosterConfigurator.java | 83 ++++++++-- ...tants.java => LibertyConfigConstants.java} | 6 +- .../config/LibertyServerConfigGenerator.java | 13 +- .../config/WildflyServerConfigGenerator.java | 84 ++++++++++ .../boost/common/utils/SpringBootUtil.java | 80 +++++---- .../common/boosters/JDBCBoosterTest.java | 110 +++++++------ .../config/BoosterConfiguratorTest.java | 28 ++-- .../LibertyServerConfigGeneratorTest.java | 5 +- .../boost/common/utils/BoosterUtil.java | 11 +- .../booster-wildfly/invoker.properties | 1 + .../boost-boosters/booster-wildfly/pom.xml | 11 ++ boost-maven/boost-boosters/pom.xml | 1 + .../invoker.properties | 4 +- .../boost/maven/BoostDebugMojo.java | 45 +++++ .../boost/maven/BoostPackageMojo.java | 58 +++++++ .../openliberty/boost/maven/BoostRunMojo.java | 56 +++++++ .../boost/maven/BoostStartMojo.java | 56 +++++++ .../boost/maven/BoostStopMojo.java | 56 +++++++ .../boost/maven/liberty/LibertyDebugMojo.java | 2 +- .../maven/liberty/LibertyPackageMojo.java | 20 +-- .../boost/maven/liberty/LibertyRunMojo.java | 2 +- .../boost/maven/liberty/LibertyStartMojo.java | 2 +- .../boost/maven/liberty/LibertyStopMojo.java | 2 +- .../boost/maven/utils/MavenProjectUtil.java | 13 ++ .../maven/wildfly/AbstractWildflyMojo.java | 115 +++++++++++++ .../maven/wildfly/WildflyPackageMojo.java | 154 ++++++++++++++++++ .../boost/maven/wildfly/WildflyRunMojo.java | 55 +++++++ .../boost/maven/wildfly/WildflyStartMojo.java | 48 ++++++ .../boost/maven/wildfly/WildflyStopMojo.java | 54 ++++++ 50 files changed, 1654 insertions(+), 276 deletions(-) create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/AbstractBoosterLibertyConfig.java rename boost-common/src/main/java/io/openliberty/boost/common/boosters/{CDIBoosterConfig.java => liberty/CDIBoosterLibertyConfig.java} (78%) rename boost-common/src/main/java/io/openliberty/boost/common/boosters/{JAXRSBoosterConfig.java => liberty/JAXRSBoosterLibertyConfig.java} (78%) rename boost-common/src/main/java/io/openliberty/boost/common/boosters/{JDBCBoosterConfig.java => liberty/JDBCBoosterLibertyConfig.java} (57%) rename boost-common/src/main/java/io/openliberty/boost/common/boosters/{JPABoosterConfig.java => liberty/JPABoosterLibertyConfig.java} (78%) rename boost-common/src/main/java/io/openliberty/boost/common/boosters/{JSONPBoosterConfig.java => liberty/JSONPBoosterLibertyConfig.java} (78%) rename boost-common/src/main/java/io/openliberty/boost/common/boosters/{MPConfigBoosterConfig.java => liberty/MPConfigBoosterLibertyConfig.java} (77%) rename boost-common/src/main/java/io/openliberty/boost/common/boosters/{MPHealthBoosterConfig.java => liberty/MPHealthBoosterLibertyConfig.java} (78%) rename boost-common/src/main/java/io/openliberty/boost/common/boosters/{MPOpenTracingBoosterConfig.java => liberty/MPOpenTracingBoosterLibertyConfig.java} (75%) rename boost-common/src/main/java/io/openliberty/boost/common/boosters/{MPRestClientBoosterConfig.java => liberty/MPRestClientBoosterLibertyConfig.java} (76%) create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/AbstractBoosterWildflyConfig.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/CDIBoosterWildflyConfig.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JAXRSBoosterWildflyConfig.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JDBCBoosterWildflyConfig.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JPABoosterWildflyConfig.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JSONPBoosterWildflyConfig.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPConfigBoosterWildflyConfig.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPHealthBoosterWildflyConfig.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPOpenTracingBoosterWildflyConfig.java create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPRestClientBoosterWildflyConfig.java rename boost-common/src/main/java/io/openliberty/boost/common/config/{ConfigConstants.java => LibertyConfigConstants.java} (96%) create mode 100644 boost-common/src/main/java/io/openliberty/boost/common/config/WildflyServerConfigGenerator.java create mode 100644 boost-maven/boost-boosters/booster-wildfly/invoker.properties create mode 100644 boost-maven/boost-boosters/booster-wildfly/pom.xml create mode 100644 boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostDebugMojo.java create mode 100644 boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostPackageMojo.java create mode 100644 boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostRunMojo.java create mode 100644 boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostStartMojo.java create mode 100644 boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostStopMojo.java create mode 100644 boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/AbstractWildflyMojo.java create mode 100644 boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyPackageMojo.java create mode 100644 boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyRunMojo.java create mode 100644 boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyStartMojo.java create mode 100644 boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyStopMojo.java diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/AbstractBoosterConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/AbstractBoosterConfig.java index 8fc15221..bfb98673 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/boosters/AbstractBoosterConfig.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/AbstractBoosterConfig.java @@ -16,9 +16,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.util.Properties; - -import org.w3c.dom.Document; import io.openliberty.boost.common.BoostException; @@ -45,30 +42,12 @@ public static String getCoordindates(Class klass) throws BoostException { return coordinates.value(); } - protected static final String BOOSTERS_GROUP_ID = "io.openliberty.boosters"; + public static final String BOOSTERS_GROUP_ID = "io.openliberty.boosters"; protected String EE_7_VERSION = "0.1-SNAPSHOT"; protected String EE_8_VERSION = "0.2-SNAPSHOT"; protected String MP_20_VERSION = "0.2-SNAPSHOT"; - /** - * Return the Liberty feature name - * - * @return - */ - public abstract String getFeature(); - - /** - * Add the server.xml configuration for this booster - * - * @param doc - */ - public abstract void addServerConfig(Document doc); - - /** - * Return the properties required by this booster - */ - public abstract Properties getServerProperties(); - + /** * Return the dependency that this booster requires * diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/AbstractBoosterLibertyConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/AbstractBoosterLibertyConfig.java new file mode 100644 index 00000000..c07830e0 --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/AbstractBoosterLibertyConfig.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package io.openliberty.boost.common.boosters.liberty; + +import java.util.Properties; + +import org.w3c.dom.Document; + +import io.openliberty.boost.common.boosters.AbstractBoosterConfig; + +/** + * Interface to describe common function across all technology Booster Pack + * Config Objects + * + */ +public abstract class AbstractBoosterLibertyConfig extends AbstractBoosterConfig { + + /** + * Return the Liberty feature name + * + * @return + */ + public abstract String getFeature(); + + /** + * Add the server.xml configuration for this booster + * + * @param doc + */ + public abstract void addServerConfig(Document doc); + + /** + * Return the properties required by this booster + */ + public abstract Properties getServerProperties(); + +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/CDIBoosterConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/CDIBoosterLibertyConfig.java similarity index 78% rename from boost-common/src/main/java/io/openliberty/boost/common/boosters/CDIBoosterConfig.java rename to boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/CDIBoosterLibertyConfig.java index 8f0423a9..cc09df63 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/boosters/CDIBoosterConfig.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/CDIBoosterLibertyConfig.java @@ -8,9 +8,9 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package io.openliberty.boost.common.boosters; +package io.openliberty.boost.common.boosters.liberty; -import static io.openliberty.boost.common.config.ConfigConstants.CDI_20; +import static io.openliberty.boost.common.config.LibertyConfigConstants.CDI_20; import java.util.Map; import java.util.Properties; @@ -21,14 +21,14 @@ import io.openliberty.boost.common.BoostLoggerI; import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; -@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":cdi") -public class CDIBoosterConfig extends AbstractBoosterConfig { +@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":cdi") +public class CDIBoosterLibertyConfig extends AbstractBoosterLibertyConfig { String libertyFeature = null; - public CDIBoosterConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + public CDIBoosterLibertyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { String version = dependencies.get(getCoordindates(this.getClass())); - + // if it is the 1.0 version = EE7 feature level if (version.equals(MP_20_VERSION)) { libertyFeature = CDI_20; diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/JAXRSBoosterConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JAXRSBoosterLibertyConfig.java similarity index 78% rename from boost-common/src/main/java/io/openliberty/boost/common/boosters/JAXRSBoosterConfig.java rename to boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JAXRSBoosterLibertyConfig.java index 4b758e5d..0253db22 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/boosters/JAXRSBoosterConfig.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JAXRSBoosterLibertyConfig.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package io.openliberty.boost.common.boosters; +package io.openliberty.boost.common.boosters.liberty; import org.w3c.dom.Document; @@ -16,17 +16,17 @@ import io.openliberty.boost.common.BoostLoggerI; import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; -import static io.openliberty.boost.common.config.ConfigConstants.*; +import static io.openliberty.boost.common.config.LibertyConfigConstants.*; import java.util.Map; import java.util.Properties; -@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":jaxrs") -public class JAXRSBoosterConfig extends AbstractBoosterConfig { +@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":jaxrs") +public class JAXRSBoosterLibertyConfig extends AbstractBoosterLibertyConfig { String libertyFeature = null; - public JAXRSBoosterConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + public JAXRSBoosterLibertyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { String version = dependencies.get(getCoordindates(this.getClass())); if (version.equals(EE_7_VERSION)) { libertyFeature = JAXRS_20; diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/JDBCBoosterConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JDBCBoosterLibertyConfig.java similarity index 57% rename from boost-common/src/main/java/io/openliberty/boost/common/boosters/JDBCBoosterConfig.java rename to boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JDBCBoosterLibertyConfig.java index 57ce45c9..f8e6fa8b 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/boosters/JDBCBoosterConfig.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JDBCBoosterLibertyConfig.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package io.openliberty.boost.common.boosters; +package io.openliberty.boost.common.boosters.liberty; import io.openliberty.boost.common.config.BoostProperties; import io.openliberty.boost.common.BoostException; @@ -16,7 +16,7 @@ import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; import io.openliberty.boost.common.utils.BoostUtil; -import static io.openliberty.boost.common.config.ConfigConstants.*; +import static io.openliberty.boost.common.config.LibertyConfigConstants.*; import java.util.Map; import java.util.Properties; @@ -25,8 +25,8 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; -@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":jdbc") -public class JDBCBoosterConfig extends AbstractBoosterConfig { +@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":jdbc") +public class JDBCBoosterLibertyConfig extends AbstractBoosterLibertyConfig { public static String DERBY_DEPENDENCY = "org.apache.derby:derby"; public static String DB2_DEPENDENCY = "com.ibm.db2.jcc:db2jcc"; @@ -39,22 +39,22 @@ public class JDBCBoosterConfig extends AbstractBoosterConfig { private Properties serverProperties; - public JDBCBoosterConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + public JDBCBoosterLibertyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { // Check for user defined database dependencies String configuredDatabaseDep = null; - if (dependencies.containsKey(JDBCBoosterConfig.DERBY_DEPENDENCY)) { - String derbyVersion = dependencies.get(JDBCBoosterConfig.DERBY_DEPENDENCY); - configuredDatabaseDep = JDBCBoosterConfig.DERBY_DEPENDENCY + ":" + derbyVersion; - - } else if (dependencies.containsKey(JDBCBoosterConfig.DB2_DEPENDENCY)) { - String db2Version = dependencies.get(JDBCBoosterConfig.DB2_DEPENDENCY); - configuredDatabaseDep = JDBCBoosterConfig.DB2_DEPENDENCY + ":" + db2Version; - - } else if (dependencies.containsKey(JDBCBoosterConfig.MYSQL_DEPENDENCY)) { - String mysqlVersion = dependencies.get(JDBCBoosterConfig.MYSQL_DEPENDENCY); - configuredDatabaseDep = JDBCBoosterConfig.MYSQL_DEPENDENCY + ":" + mysqlVersion; + if (dependencies.containsKey(JDBCBoosterLibertyConfig.DERBY_DEPENDENCY)) { + String derbyVersion = dependencies.get(JDBCBoosterLibertyConfig.DERBY_DEPENDENCY); + configuredDatabaseDep = JDBCBoosterLibertyConfig.DERBY_DEPENDENCY + ":" + derbyVersion; + + } else if (dependencies.containsKey(JDBCBoosterLibertyConfig.DB2_DEPENDENCY)) { + String db2Version = dependencies.get(JDBCBoosterLibertyConfig.DB2_DEPENDENCY); + configuredDatabaseDep = JDBCBoosterLibertyConfig.DB2_DEPENDENCY + ":" + db2Version; + + } else if (dependencies.containsKey(JDBCBoosterLibertyConfig.MYSQL_DEPENDENCY)) { + String mysqlVersion = dependencies.get(JDBCBoosterLibertyConfig.MYSQL_DEPENDENCY); + configuredDatabaseDep = JDBCBoosterLibertyConfig.MYSQL_DEPENDENCY + ":" + mysqlVersion; } Properties boostConfigProperties = BoostProperties.getConfiguredBoostProperties(logger); @@ -86,41 +86,49 @@ private void init(Properties boostConfigProperties, String configuredDatabaseDep // Set server properties this.serverProperties = new Properties(); - // Initialize defaults and required properties for each datasource vendor + // Initialize defaults and required properties for each datasource + // vendor if (this.dependency.startsWith(DERBY_DEPENDENCY)) { - // Embedded Derby requires a database name. Set a default for this and create it. + // Embedded Derby requires a database name. Set a default for this + // and create it. this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, DERBY_DB); this.serverProperties.put(BoostProperties.DATASOURCE_CREATE_DATABASE, "create"); - + } else if (this.dependency.startsWith(DB2_DEPENDENCY)) { - // For DB2, since we are expecting the database to exist, there is no - // default value we can set for databaseName that would be of any use. - // Likewise, for user and password, there isn't anything we could set - // here that would make sense. Since these properties are required, - // set empty strings as there values to create place holders. If they - // are not overridden by the user at package time, they can be overridden - // at runtime. - this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, ""); - this.serverProperties.put(BoostProperties.DATASOURCE_USER, ""); - this.serverProperties.put(BoostProperties.DATASOURCE_PASSWORD, ""); + // For DB2, since we are expecting the database to exist, there is + // no + // default value we can set for databaseName that would be of any + // use. + // Likewise, for user and password, there isn't anything we could + // set + // here that would make sense. Since these properties are required, + // set empty strings as there values to create place holders. If + // they + // are not overridden by the user at package time, they can be + // overridden + // at runtime. + this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, ""); + this.serverProperties.put(BoostProperties.DATASOURCE_USER, ""); + this.serverProperties.put(BoostProperties.DATASOURCE_PASSWORD, ""); this.serverProperties.put(BoostProperties.DATASOURCE_SERVER_NAME, LOCALHOST); - this.serverProperties.put(BoostProperties.DATASOURCE_PORT_NUMBER, DB2_DEFAULT_PORT_NUMBER); - + this.serverProperties.put(BoostProperties.DATASOURCE_PORT_NUMBER, DB2_DEFAULT_PORT_NUMBER); + } else if (this.dependency.startsWith(MYSQL_DEPENDENCY)) { - // Same set of minimum requirements for MySQL - this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, ""); - this.serverProperties.put(BoostProperties.DATASOURCE_USER, ""); - this.serverProperties.put(BoostProperties.DATASOURCE_PASSWORD, ""); + // Same set of minimum requirements for MySQL + this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, ""); + this.serverProperties.put(BoostProperties.DATASOURCE_USER, ""); + this.serverProperties.put(BoostProperties.DATASOURCE_PASSWORD, ""); this.serverProperties.put(BoostProperties.DATASOURCE_SERVER_NAME, LOCALHOST); - this.serverProperties.put(BoostProperties.DATASOURCE_PORT_NUMBER, MYSQL_DEFAULT_PORT_NUMBER); - } - - // Find and add all "boost.db." properties. This will override any default values + this.serverProperties.put(BoostProperties.DATASOURCE_PORT_NUMBER, MYSQL_DEFAULT_PORT_NUMBER); + } + + // Find and add all "boost.db." properties. This will override any + // default values for (String key : boostConfigProperties.stringPropertyNames()) { - if ( key.startsWith(BoostProperties.DATASOURCE_PREFIX)) { - String value = (String) boostConfigProperties.get(key); - this.serverProperties.put(key, value); - } + if (key.startsWith(BoostProperties.DATASOURCE_PREFIX)) { + String value = (String) boostConfigProperties.get(key); + this.serverProperties.put(key, value); + } } } @@ -145,14 +153,14 @@ public String getDependency() { public void addServerConfig(Document doc) { if (dependency.startsWith(DERBY_DEPENDENCY)) { - addDatasourceConfig(doc, PROPERTIES_DERBY_EMBEDDED, DERBY_JAR); + addDatasourceConfig(doc, PROPERTIES_DERBY_EMBEDDED, DERBY_JAR); } else if (dependency.startsWith(DB2_DEPENDENCY)) { - addDatasourceConfig(doc, PROPERTIES_DB2_JCC, DB2_JAR); - + addDatasourceConfig(doc, PROPERTIES_DB2_JCC, DB2_JAR); + } else if (dependency.startsWith(MYSQL_DEPENDENCY)) { - // Use generic element for MySQL - addDatasourceConfig(doc, PROPERTIES, MYSQL_JAR); + // Use generic element for MySQL + addDatasourceConfig(doc, PROPERTIES, MYSQL_JAR); } } @@ -194,27 +202,30 @@ private void addDatasourceConfig(Document doc, String datasourcePropertiesElemen jdbcDriver.setAttribute("id", JDBC_DRIVER_1); jdbcDriver.setAttribute(LIBRARY_REF, JDBC_LIBRARY_1); serverRoot.appendChild(jdbcDriver); - + // Add container authentication - if (this.serverProperties.containsKey(BoostProperties.DATASOURCE_USER) && this.serverProperties.containsKey(BoostProperties.DATASOURCE_PASSWORD)) { - dataSource.setAttribute(CONTAINER_AUTH_DATA_REF, DATASOURCE_AUTH_DATA); - - Element containerAuthData = doc.createElement(AUTH_DATA); - containerAuthData.setAttribute("id", DATASOURCE_AUTH_DATA); - containerAuthData.setAttribute(USER, BoostUtil.makeVariable(BoostProperties.DATASOURCE_USER)); - containerAuthData.setAttribute(PASSWORD, BoostUtil.makeVariable(BoostProperties.DATASOURCE_PASSWORD)); - serverRoot.appendChild(containerAuthData); + if (this.serverProperties.containsKey(BoostProperties.DATASOURCE_USER) + && this.serverProperties.containsKey(BoostProperties.DATASOURCE_PASSWORD)) { + dataSource.setAttribute(CONTAINER_AUTH_DATA_REF, DATASOURCE_AUTH_DATA); + + Element containerAuthData = doc.createElement(AUTH_DATA); + containerAuthData.setAttribute("id", DATASOURCE_AUTH_DATA); + containerAuthData.setAttribute(USER, BoostUtil.makeVariable(BoostProperties.DATASOURCE_USER)); + containerAuthData.setAttribute(PASSWORD, BoostUtil.makeVariable(BoostProperties.DATASOURCE_PASSWORD)); + serverRoot.appendChild(containerAuthData); } } - + private void addDatasourceProperties(Element properties) { - for (String property : this.serverProperties.stringPropertyNames()) { - // We are using container authentication. Do not include user or password here - if ( !property.equals(BoostProperties.DATASOURCE_USER) && !property.equals(BoostProperties.DATASOURCE_PASSWORD)) { - - String attribute = property.replace(BoostProperties.DATASOURCE_PREFIX, ""); - properties.setAttribute(attribute, BoostUtil.makeVariable(property)); - } + for (String property : this.serverProperties.stringPropertyNames()) { + // We are using container authentication. Do not include user or + // password here + if (!property.equals(BoostProperties.DATASOURCE_USER) + && !property.equals(BoostProperties.DATASOURCE_PASSWORD)) { + + String attribute = property.replace(BoostProperties.DATASOURCE_PREFIX, ""); + properties.setAttribute(attribute, BoostUtil.makeVariable(property)); + } } } } diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/JPABoosterConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JPABoosterLibertyConfig.java similarity index 78% rename from boost-common/src/main/java/io/openliberty/boost/common/boosters/JPABoosterConfig.java rename to boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JPABoosterLibertyConfig.java index 1b3295c4..a8d73a94 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/boosters/JPABoosterConfig.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JPABoosterLibertyConfig.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package io.openliberty.boost.common.boosters; +package io.openliberty.boost.common.boosters.liberty; import org.w3c.dom.Document; @@ -16,17 +16,17 @@ import io.openliberty.boost.common.BoostLoggerI; import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; -import static io.openliberty.boost.common.config.ConfigConstants.*; +import static io.openliberty.boost.common.config.LibertyConfigConstants.*; import java.util.Map; import java.util.Properties; -@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":jpa") -public class JPABoosterConfig extends AbstractBoosterConfig { +@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":jpa") +public class JPABoosterLibertyConfig extends AbstractBoosterLibertyConfig { String libertyFeature = null; - public JPABoosterConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + public JPABoosterLibertyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { String version = dependencies.get(getCoordindates(this.getClass())); if (version.equals(EE_7_VERSION)) { libertyFeature = JPA_21; diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/JSONPBoosterConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JSONPBoosterLibertyConfig.java similarity index 78% rename from boost-common/src/main/java/io/openliberty/boost/common/boosters/JSONPBoosterConfig.java rename to boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JSONPBoosterLibertyConfig.java index 0c23d473..e2ad3ff5 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/boosters/JSONPBoosterConfig.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/JSONPBoosterLibertyConfig.java @@ -8,9 +8,9 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package io.openliberty.boost.common.boosters; +package io.openliberty.boost.common.boosters.liberty; -import static io.openliberty.boost.common.config.ConfigConstants.JSONP_11; +import static io.openliberty.boost.common.config.LibertyConfigConstants.JSONP_11; import java.util.Map; import java.util.Properties; @@ -21,14 +21,14 @@ import io.openliberty.boost.common.BoostLoggerI; import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; -@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":jsonp") -public class JSONPBoosterConfig extends AbstractBoosterConfig { +@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":jsonp") +public class JSONPBoosterLibertyConfig extends AbstractBoosterLibertyConfig { String libertyFeature = null; - public JSONPBoosterConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + public JSONPBoosterLibertyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { String version = dependencies.get(getCoordindates(this.getClass())); - + if (version.equals(MP_20_VERSION)) { libertyFeature = JSONP_11; } diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/MPConfigBoosterConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPConfigBoosterLibertyConfig.java similarity index 77% rename from boost-common/src/main/java/io/openliberty/boost/common/boosters/MPConfigBoosterConfig.java rename to boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPConfigBoosterLibertyConfig.java index 827464a3..6ed30678 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/boosters/MPConfigBoosterConfig.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPConfigBoosterLibertyConfig.java @@ -8,9 +8,9 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package io.openliberty.boost.common.boosters; +package io.openliberty.boost.common.boosters.liberty; -import static io.openliberty.boost.common.config.ConfigConstants.MPCONFIG_13; +import static io.openliberty.boost.common.config.LibertyConfigConstants.MPCONFIG_13; import java.util.Map; import java.util.Properties; @@ -21,12 +21,12 @@ import io.openliberty.boost.common.BoostLoggerI; import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; -@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":mpConfig") -public class MPConfigBoosterConfig extends AbstractBoosterConfig { +@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":mpConfig") +public class MPConfigBoosterLibertyConfig extends AbstractBoosterLibertyConfig { String libertyFeature = null; - - public MPConfigBoosterConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + + public MPConfigBoosterLibertyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { String version = dependencies.get(getCoordindates(this.getClass())); // if it is the 1.0 version = EE7 feature level if (version.equals(MP_20_VERSION)) { diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/MPHealthBoosterConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPHealthBoosterLibertyConfig.java similarity index 78% rename from boost-common/src/main/java/io/openliberty/boost/common/boosters/MPHealthBoosterConfig.java rename to boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPHealthBoosterLibertyConfig.java index 655fff11..597aa566 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/boosters/MPHealthBoosterConfig.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPHealthBoosterLibertyConfig.java @@ -8,9 +8,9 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package io.openliberty.boost.common.boosters; +package io.openliberty.boost.common.boosters.liberty; -import static io.openliberty.boost.common.config.ConfigConstants.MPHEALTH_10; +import static io.openliberty.boost.common.config.LibertyConfigConstants.MPHEALTH_10; import java.util.Map; import java.util.Properties; @@ -21,12 +21,12 @@ import io.openliberty.boost.common.BoostLoggerI; import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; -@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":mpHealth") -public class MPHealthBoosterConfig extends AbstractBoosterConfig { +@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":mpHealth") +public class MPHealthBoosterLibertyConfig extends AbstractBoosterLibertyConfig { String libertyFeature = null; - - public MPHealthBoosterConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + + public MPHealthBoosterLibertyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { String version = dependencies.get(getCoordindates(this.getClass())); // if it is the 2.0 version = MP2.0 feature level if (version.equals(MP_20_VERSION)) { diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/MPOpenTracingBoosterConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPOpenTracingBoosterLibertyConfig.java similarity index 75% rename from boost-common/src/main/java/io/openliberty/boost/common/boosters/MPOpenTracingBoosterConfig.java rename to boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPOpenTracingBoosterLibertyConfig.java index 83fa5698..bd9ce524 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/boosters/MPOpenTracingBoosterConfig.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPOpenTracingBoosterLibertyConfig.java @@ -8,9 +8,9 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package io.openliberty.boost.common.boosters; +package io.openliberty.boost.common.boosters.liberty; -import static io.openliberty.boost.common.config.ConfigConstants.MPOPENTRACING_11; +import static io.openliberty.boost.common.config.LibertyConfigConstants.MPOPENTRACING_11; import java.util.Map; import java.util.Properties; @@ -21,12 +21,13 @@ import io.openliberty.boost.common.BoostLoggerI; import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; -@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":mpOpenTracing") -public class MPOpenTracingBoosterConfig extends AbstractBoosterConfig { +@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":mpOpenTracing") +public class MPOpenTracingBoosterLibertyConfig extends AbstractBoosterLibertyConfig { String libertyFeature = null; - public MPOpenTracingBoosterConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + public MPOpenTracingBoosterLibertyConfig(Map dependencies, BoostLoggerI logger) + throws BoostException { String version = dependencies.get(getCoordindates(this.getClass())); if (version.equals(MP_20_VERSION)) { libertyFeature = MPOPENTRACING_11; diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/MPRestClientBoosterConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPRestClientBoosterLibertyConfig.java similarity index 76% rename from boost-common/src/main/java/io/openliberty/boost/common/boosters/MPRestClientBoosterConfig.java rename to boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPRestClientBoosterLibertyConfig.java index 4a979ffc..c9db6cea 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/boosters/MPRestClientBoosterConfig.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/liberty/MPRestClientBoosterLibertyConfig.java @@ -8,9 +8,9 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package io.openliberty.boost.common.boosters; +package io.openliberty.boost.common.boosters.liberty; -import static io.openliberty.boost.common.config.ConfigConstants.MPRESTCLIENT_11; +import static io.openliberty.boost.common.config.LibertyConfigConstants.MPRESTCLIENT_11; import java.util.Map; import java.util.Properties; @@ -21,14 +21,15 @@ import io.openliberty.boost.common.BoostLoggerI; import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; -@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":mpRestClient") -public class MPRestClientBoosterConfig extends AbstractBoosterConfig { +@BoosterCoordinates(AbstractBoosterLibertyConfig.BOOSTERS_GROUP_ID + ":mpRestClient") +public class MPRestClientBoosterLibertyConfig extends AbstractBoosterLibertyConfig { String libertyFeature = null; - public MPRestClientBoosterConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + public MPRestClientBoosterLibertyConfig(Map dependencies, BoostLoggerI logger) + throws BoostException { String version = dependencies.get(getCoordindates(this.getClass())); - + // if it is the 1.0 version = EE7 feature level if (version.equals(MP_20_VERSION)) { libertyFeature = MPRESTCLIENT_11; diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/AbstractBoosterWildflyConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/AbstractBoosterWildflyConfig.java new file mode 100644 index 00000000..365f456d --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/AbstractBoosterWildflyConfig.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package io.openliberty.boost.common.boosters.wildfly; + +import java.util.List; + +import io.openliberty.boost.common.boosters.AbstractBoosterConfig; + +/** + * Interface to describe common function across all technology Booster Pack + * Config Objects + * + */ +public abstract class AbstractBoosterWildflyConfig extends AbstractBoosterConfig { + + /** + * Return the command to pass to the wildfly CLI + * + * @return + */ + public abstract List getCliCommands(); + +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/CDIBoosterWildflyConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/CDIBoosterWildflyConfig.java new file mode 100644 index 00000000..39a80f5e --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/CDIBoosterWildflyConfig.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.common.boosters.wildfly; + +import java.util.List; +import java.util.Map; + +import io.openliberty.boost.common.BoostException; +import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; + +@BoosterCoordinates(AbstractBoosterWildflyConfig.BOOSTERS_GROUP_ID + ":cdi") +public class CDIBoosterWildflyConfig extends AbstractBoosterWildflyConfig { + + + public CDIBoosterWildflyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + String version = dependencies.get(getCoordindates(this.getClass())); + } + + @Override + public List getCliCommands() { + return null; + } + + @Override + public String getDependency() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JAXRSBoosterWildflyConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JAXRSBoosterWildflyConfig.java new file mode 100644 index 00000000..f1e8a093 --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JAXRSBoosterWildflyConfig.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.common.boosters.wildfly; + +import io.openliberty.boost.common.BoostException; +import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; + +import java.util.List; +import java.util.Map; + +@BoosterCoordinates(AbstractBoosterWildflyConfig.BOOSTERS_GROUP_ID + ":jaxrs") +public class JAXRSBoosterWildflyConfig extends AbstractBoosterWildflyConfig { + + public JAXRSBoosterWildflyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + String version = dependencies.get(getCoordindates(this.getClass())); + } + + @Override + public List getCliCommands() { + return null; + } + + @Override + public String getDependency() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JDBCBoosterWildflyConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JDBCBoosterWildflyConfig.java new file mode 100644 index 00000000..7648fad6 --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JDBCBoosterWildflyConfig.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.common.boosters.wildfly; + +import io.openliberty.boost.common.config.BoostProperties; +import io.openliberty.boost.common.BoostException; +import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; +import io.openliberty.boost.common.utils.BoostUtil; + +import static io.openliberty.boost.common.config.LibertyConfigConstants.*; + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +@BoosterCoordinates(AbstractBoosterWildflyConfig.BOOSTERS_GROUP_ID + ":jdbc") +public class JDBCBoosterWildflyConfig extends AbstractBoosterWildflyConfig { + + public static String DERBY_DEPENDENCY = "org.apache.derby:derby"; + public static String DB2_DEPENDENCY = "com.ibm.db2.jcc:db2jcc"; + public static String MYSQL_DEPENDENCY = "mysql:mysql-connector-java"; + + private static String DERBY_DEFAULT = "org.apache.derby:derby:10.14.2.0"; + + private String dependency; + private List configurationCommands; + + public JDBCBoosterWildflyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + + // Check for user defined database dependencies + String configuredDatabaseDep = null; + + if (dependencies.containsKey(JDBCBoosterWildflyConfig.DERBY_DEPENDENCY)) { + String derbyVersion = dependencies.get(JDBCBoosterWildflyConfig.DERBY_DEPENDENCY); + configuredDatabaseDep = JDBCBoosterWildflyConfig.DERBY_DEPENDENCY + ":" + derbyVersion; + + } else if (dependencies.containsKey(JDBCBoosterWildflyConfig.DB2_DEPENDENCY)) { + String db2Version = dependencies.get(JDBCBoosterWildflyConfig.DB2_DEPENDENCY); + configuredDatabaseDep = JDBCBoosterWildflyConfig.DB2_DEPENDENCY + ":" + db2Version; + + } else if (dependencies.containsKey(JDBCBoosterWildflyConfig.MYSQL_DEPENDENCY)) { + String mysqlVersion = dependencies.get(JDBCBoosterWildflyConfig.MYSQL_DEPENDENCY); + configuredDatabaseDep = JDBCBoosterWildflyConfig.MYSQL_DEPENDENCY + ":" + mysqlVersion; + } + + Properties boostConfigProperties = BoostProperties.getConfiguredBoostProperties(logger); + init(boostConfigProperties, configuredDatabaseDep); + } + + private void init(Properties boostConfigProperties, String configuredDatabaseDep) { + + if (configuredDatabaseDep == null) { + this.dependency = DERBY_DEFAULT; + } else { + this.dependency = configuredDatabaseDep; + } + + +// // Initialize defaults and required properties for each datasource +// // vendor +// if (this.dependency.startsWith(DERBY_DEPENDENCY)) { +// // Embedded Derby requires a database name. Set a default for this +// // and create it. +// this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, DERBY_DB); +// this.serverProperties.put(BoostProperties.DATASOURCE_CREATE_DATABASE, "create"); +// +// } else if (this.dependency.startsWith(DB2_DEPENDENCY)) { +// // For DB2, since we are expecting the database to exist, there is +// // no +// // default value we can set for databaseName that would be of any +// // use. +// // Likewise, for user and password, there isn't anything we could +// // set +// // here that would make sense. Since these properties are required, +// // set empty strings as there values to create place holders. If +// // they +// // are not overridden by the user at package time, they can be +// // overridden +// // at runtime. +// this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, ""); +// this.serverProperties.put(BoostProperties.DATASOURCE_USER, ""); +// this.serverProperties.put(BoostProperties.DATASOURCE_PASSWORD, ""); +// this.serverProperties.put(BoostProperties.DATASOURCE_SERVER_NAME, LOCALHOST); +// this.serverProperties.put(BoostProperties.DATASOURCE_PORT_NUMBER, DB2_DEFAULT_PORT_NUMBER); +// +// } else if (this.dependency.startsWith(MYSQL_DEPENDENCY)) { +// // Same set of minimum requirements for MySQL +// this.serverProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, ""); +// this.serverProperties.put(BoostProperties.DATASOURCE_USER, ""); +// this.serverProperties.put(BoostProperties.DATASOURCE_PASSWORD, ""); +// this.serverProperties.put(BoostProperties.DATASOURCE_SERVER_NAME, LOCALHOST); +// this.serverProperties.put(BoostProperties.DATASOURCE_PORT_NUMBER, MYSQL_DEFAULT_PORT_NUMBER); +// } +// +// // Find and add all "boost.db." properties. This will override any +// // default values +// for (String key : boostConfigProperties.stringPropertyNames()) { +// if (key.startsWith(BoostProperties.DATASOURCE_PREFIX)) { +// String value = (String) boostConfigProperties.get(key); +// this.serverProperties.put(key, value); +// } +// } + } + + @Override + public List getCliCommands() { + return configurationCommands; + } + + @Override + public String getDependency() { + + return dependency; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JPABoosterWildflyConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JPABoosterWildflyConfig.java new file mode 100644 index 00000000..32925e22 --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JPABoosterWildflyConfig.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.common.boosters.wildfly; + +import io.openliberty.boost.common.BoostException; +import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; + +import java.util.List; +import java.util.Map; + +@BoosterCoordinates(AbstractBoosterWildflyConfig.BOOSTERS_GROUP_ID + ":jpa") +public class JPABoosterWildflyConfig extends AbstractBoosterWildflyConfig { + + public JPABoosterWildflyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + String version = dependencies.get(getCoordindates(this.getClass())); + } + + @Override + public List getCliCommands() { + return null; + } + + @Override + public String getDependency() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JSONPBoosterWildflyConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JSONPBoosterWildflyConfig.java new file mode 100644 index 00000000..0a473261 --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/JSONPBoosterWildflyConfig.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.common.boosters.wildfly; + +import java.util.List; +import java.util.Map; + +import io.openliberty.boost.common.BoostException; +import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; + +@BoosterCoordinates(AbstractBoosterWildflyConfig.BOOSTERS_GROUP_ID + ":jsonp") +public class JSONPBoosterWildflyConfig extends AbstractBoosterWildflyConfig { + + public JSONPBoosterWildflyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + String version = dependencies.get(getCoordindates(this.getClass())); + } + + @Override + public List getCliCommands() { + return null; + } + + @Override + public String getDependency() { + return null; + } + +} \ No newline at end of file diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPConfigBoosterWildflyConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPConfigBoosterWildflyConfig.java new file mode 100644 index 00000000..e59d156e --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPConfigBoosterWildflyConfig.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.common.boosters.wildfly; + +import java.util.List; +import java.util.Map; + +import io.openliberty.boost.common.BoostException; +import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; + +@BoosterCoordinates(AbstractBoosterWildflyConfig.BOOSTERS_GROUP_ID + ":mpConfig") +public class MPConfigBoosterWildflyConfig extends AbstractBoosterWildflyConfig { + + public MPConfigBoosterWildflyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + String version = dependencies.get(getCoordindates(this.getClass())); + } + + @Override + public List getCliCommands() { + return null; + } + + @Override + public String getDependency() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPHealthBoosterWildflyConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPHealthBoosterWildflyConfig.java new file mode 100644 index 00000000..b8cbc678 --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPHealthBoosterWildflyConfig.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.common.boosters.wildfly; + +import java.util.List; +import java.util.Map; + +import io.openliberty.boost.common.BoostException; +import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; + +@BoosterCoordinates(AbstractBoosterWildflyConfig.BOOSTERS_GROUP_ID + ":mpHealth") +public class MPHealthBoosterWildflyConfig extends AbstractBoosterWildflyConfig { + + public MPHealthBoosterWildflyConfig(Map dependencies, BoostLoggerI logger) throws BoostException { + String version = dependencies.get(getCoordindates(this.getClass())); + } + + @Override + public List getCliCommands() { + return null; + } + + @Override + public String getDependency() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPOpenTracingBoosterWildflyConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPOpenTracingBoosterWildflyConfig.java new file mode 100644 index 00000000..cbc9bfba --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPOpenTracingBoosterWildflyConfig.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.common.boosters.wildfly; + +import java.util.List; +import java.util.Map; + +import io.openliberty.boost.common.BoostException; +import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; + +@BoosterCoordinates(AbstractBoosterWildflyConfig.BOOSTERS_GROUP_ID + ":mpOpenTracing") +public class MPOpenTracingBoosterWildflyConfig extends AbstractBoosterWildflyConfig { + + public MPOpenTracingBoosterWildflyConfig(Map dependencies, BoostLoggerI logger) + throws BoostException { + } + + @Override + public List getCliCommands() { + return null; + } + + @Override + public String getDependency() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPRestClientBoosterWildflyConfig.java b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPRestClientBoosterWildflyConfig.java new file mode 100644 index 00000000..313f70db --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/boosters/wildfly/MPRestClientBoosterWildflyConfig.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.common.boosters.wildfly; + +import java.util.List; +import java.util.Map; + +import io.openliberty.boost.common.BoostException; +import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates; + +@BoosterCoordinates(AbstractBoosterWildflyConfig.BOOSTERS_GROUP_ID + ":mpRestClient") +public class MPRestClientBoosterWildflyConfig extends AbstractBoosterWildflyConfig { + + public MPRestClientBoosterWildflyConfig(Map dependencies, BoostLoggerI logger) + throws BoostException { + String version = dependencies.get(getCoordindates(this.getClass())); + } + + @Override + public List getCliCommands() { + return null; + } + + @Override + public String getDependency() { + return null; + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterConfigurator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterConfigurator.java index c8482171..f3025bea 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterConfigurator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/BoosterConfigurator.java @@ -12,6 +12,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -22,6 +23,8 @@ import io.openliberty.boost.common.BoostException; import io.openliberty.boost.common.BoostLoggerI; import io.openliberty.boost.common.boosters.AbstractBoosterConfig; +import io.openliberty.boost.common.boosters.liberty.AbstractBoosterLibertyConfig; +import io.openliberty.boost.common.boosters.wildfly.AbstractBoosterWildflyConfig; public class BoosterConfigurator { @@ -41,40 +44,67 @@ public class BoosterConfigurator { * @throws NoSuchMethodException * @throws SecurityException */ - public static List getBoosterPackConfigurators(Map dependencies, + public static List getBoosterLibertyConfigurators(Map dependencies, BoostLoggerI logger) throws BoostException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - List boosterPackConfigList = new ArrayList(); + List boosterConfigList = new ArrayList(); - Reflections reflections = new Reflections("io.openliberty.boost.common.boosters"); + Reflections reflections = new Reflections("io.openliberty.boost.common.boosters.liberty"); - Set> allClasses = reflections.getSubTypesOf(AbstractBoosterConfig.class); - for (Class boosterClass : allClasses) { - if (dependencies.containsKey(AbstractBoosterConfig.getCoordindates(boosterClass))) { + Set> allClasses = reflections + .getSubTypesOf(AbstractBoosterLibertyConfig.class); + for (Class boosterClass : allClasses) { + if (dependencies.containsKey(AbstractBoosterLibertyConfig.getCoordindates(boosterClass))) { Constructor cons = boosterClass.getConstructor(Map.class, BoostLoggerI.class); Object o = cons.newInstance(dependencies, logger); - if (o instanceof AbstractBoosterConfig) { - boosterPackConfigList.add((AbstractBoosterConfig) o); + if (o instanceof AbstractBoosterLibertyConfig) { + boosterConfigList.add((AbstractBoosterLibertyConfig) o); } else { throw new BoostException( - "Found a class in io.openliberty.boost.common.boosters that did not extend AbstractBoosterConfig. This should never happen."); + "Found a class in io.openliberty.boost.common.boosters that did not extend AbstractBoosterLibertyConfig. This should never happen."); } } } - return boosterPackConfigList; + return boosterConfigList; + } + + public static List getBoosterWildflyConfigurators(Map dependencies, + BoostLoggerI logger) throws BoostException, InstantiationException, IllegalAccessException, + IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + + List boosterConfigList = new ArrayList(); + + Reflections reflections = new Reflections("io.openliberty.boost.common.boosters.wildfly"); + + Set> allClasses = reflections + .getSubTypesOf(AbstractBoosterWildflyConfig.class); + for (Class boosterClass : allClasses) { + if (dependencies.containsKey(AbstractBoosterWildflyConfig.getCoordindates(boosterClass))) { + Constructor cons = boosterClass.getConstructor(Map.class, BoostLoggerI.class); + Object o = cons.newInstance(dependencies, logger); + if (o instanceof AbstractBoosterWildflyConfig) { + boosterConfigList.add((AbstractBoosterWildflyConfig) o); + } else { + throw new BoostException( + "Found a class in io.openliberty.boost.common.boosters that did not extend AbstractBoosterWildflyConfig. This should never happen."); + } + } + } + + return boosterConfigList; } public static void generateLibertyServerConfig(String libertyServerPath, - List boosterPackConfigurators, List warNames, BoostLoggerI logger) + List boosterPackConfigurators, List warNames, BoostLoggerI logger) throws Exception { LibertyServerConfigGenerator serverConfig = new LibertyServerConfigGenerator(libertyServerPath, logger); // Loop through configuration objects and get features and XML config // (if any) - for (AbstractBoosterConfig configurator : boosterPackConfigurators) { + for (AbstractBoosterLibertyConfig configurator : boosterPackConfigurators) { serverConfig.addFeature(configurator.getFeature()); serverConfig.addBoosterConfig(configurator); } @@ -91,13 +121,38 @@ public static void generateLibertyServerConfig(String libertyServerPath, serverConfig.writeToServer(); } + + public static void generateWildflyServerConfig(String wildflyInstallPath, + List boosterPackConfigurators, List warFiles, BoostLoggerI logger) + throws Exception { + + WildflyServerConfigGenerator serverConfig = new WildflyServerConfigGenerator(wildflyInstallPath, logger); + + // Loop through configuration objects and get features and XML config + // (if any) + for (AbstractBoosterWildflyConfig configurator : boosterPackConfigurators) { + serverConfig.addBoosterConfig(configurator); + } + + // Add war configuration is necessary + if (!warFiles.isEmpty()) { + for (Path warFile : warFiles) { + serverConfig.addApplication(warFile.toString()); + + } + } else { + throw new Exception( + "No war files were found. The project must have a war packaging type or specify war dependencies."); + } + + } - public static List getDependenciesToCopy(List boosterPackConfigurators, + public static List getDependenciesToCopy(List boosterConfigurators, BoostLoggerI logger) { List dependenciesToCopy = new ArrayList(); - for (AbstractBoosterConfig configurator : boosterPackConfigurators) { + for (AbstractBoosterConfig configurator : boosterConfigurators) { String dependencyToCopy = configurator.getDependency(); if (dependencyToCopy != null) { diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/ConfigConstants.java b/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyConfigConstants.java similarity index 96% rename from boost-common/src/main/java/io/openliberty/boost/common/config/ConfigConstants.java rename to boost-common/src/main/java/io/openliberty/boost/common/config/LibertyConfigConstants.java index 676c70c6..5cc0c462 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/ConfigConstants.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyConfigConstants.java @@ -11,7 +11,7 @@ package io.openliberty.boost.common.config; -public final class ConfigConstants { +public final class LibertyConfigConstants { public static final String FEATURE = "feature"; public static final String DEPENDENCY = "dependency"; @@ -21,8 +21,8 @@ public final class ConfigConstants { public static final String WAR_PKG_TYPE = "war"; public static final String INSTALL_PACKAGE_SPRING = "spring-boot-project"; - public static final String INSTALL_PACKAGE_ALL= "all"; - public static final String INSTALL_PACKAGE_DEP= "dependencies"; + public static final String INSTALL_PACKAGE_ALL = "all"; + public static final String INSTALL_PACKAGE_DEP = "dependencies"; public static final String FEATURE_MANAGER = "featureManager"; public static final String HTTP_ENDPOINT = "httpEndpoint"; diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java index 362ce45e..4ddf872c 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/LibertyServerConfigGenerator.java @@ -10,7 +10,7 @@ *******************************************************************************/ package io.openliberty.boost.common.config; -import static io.openliberty.boost.common.config.ConfigConstants.*; +import static io.openliberty.boost.common.config.LibertyConfigConstants.*; import java.io.File; import java.io.FileOutputStream; @@ -36,7 +36,7 @@ import org.w3c.dom.Element; import io.openliberty.boost.common.BoostLoggerI; -import io.openliberty.boost.common.boosters.AbstractBoosterConfig; +import io.openliberty.boost.common.boosters.liberty.AbstractBoosterLibertyConfig; import io.openliberty.boost.common.utils.BoostUtil; /** @@ -61,7 +61,9 @@ public class LibertyServerConfigGenerator { public LibertyServerConfigGenerator(String serverPath, BoostLoggerI logger) throws ParserConfigurationException { this.serverPath = serverPath; - this.libertyInstallPath = serverPath + "/../../.."; // Three directories back from 'wlp/usr/servers/BoostServer' + this.libertyInstallPath = serverPath + "/../../.."; // Three directories + // back from + // 'wlp/usr/servers/BoostServer' this.logger = logger; generateDocument(); @@ -178,7 +180,8 @@ public void addFeatures(List features) { } /** - * Write the server.xml and bootstrap.properties to the server config directory + * Write the server.xml and bootstrap.properties to the server config + * directory * * @throws TransformerException * @throws IOException @@ -228,7 +231,7 @@ public void addBootstrapProperties(Properties properties) throws IOException { } } - public void addBoosterConfig(AbstractBoosterConfig configurator) throws IOException { + public void addBoosterConfig(AbstractBoosterLibertyConfig configurator) throws IOException { configurator.addServerConfig(getServerDoc()); Properties properties = configurator.getServerProperties(); diff --git a/boost-common/src/main/java/io/openliberty/boost/common/config/WildflyServerConfigGenerator.java b/boost-common/src/main/java/io/openliberty/boost/common/config/WildflyServerConfigGenerator.java new file mode 100644 index 00000000..ea2ff246 --- /dev/null +++ b/boost-common/src/main/java/io/openliberty/boost/common/config/WildflyServerConfigGenerator.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2018, 2019 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.common.config; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.List; + +import javax.xml.parsers.ParserConfigurationException; + +import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.boosters.wildfly.AbstractBoosterWildflyConfig; +import net.wasdev.wlp.common.plugins.util.OSUtil; + +/** + * Create a Liberty server.xml + * + */ +public class WildflyServerConfigGenerator { + + private final String wildflyInstallPath; + private final String cliScript; + + private final BoostLoggerI logger; + + public WildflyServerConfigGenerator(String wildflyInstallPath, BoostLoggerI logger) + throws ParserConfigurationException { + + this.logger = logger; + this.wildflyInstallPath = wildflyInstallPath; + + if (OSUtil.isWindows()) { + this.cliScript = "jboss-cli.bat"; + } else { + this.cliScript = "jboss-cli.sh"; + } + } + + public void addBoosterConfig(AbstractBoosterWildflyConfig configurator) throws IOException { + List commands = configurator.getCliCommands(); + if (commands != null) { + for (String command : commands) { + runCliScript(command); + } + } + } + + public void addApplication(String pathToWar) throws IOException { + runCliScript("deploy --force " + pathToWar); + + } + + private void runCliScript(String command) throws IOException { + + ProcessBuilder pb = new ProcessBuilder(wildflyInstallPath + "/bin/" + cliScript, + "--commands=embed-server," + command); + Process cliProcess = pb.start(); + + // Print error stream + BufferedReader error = new BufferedReader(new InputStreamReader(cliProcess.getErrorStream())); + String line; + while ((line = error.readLine()) != null) { + logger.debug(line); + } + + // Print output stream + BufferedReader in = new BufferedReader(new InputStreamReader(cliProcess.getInputStream())); + while ((line = in.readLine()) != null) { + logger.debug(line); + } + + // TODO: throw exception if error stream has any content + + } +} diff --git a/boost-common/src/main/java/io/openliberty/boost/common/utils/SpringBootUtil.java b/boost-common/src/main/java/io/openliberty/boost/common/utils/SpringBootUtil.java index 0f731dcb..e42d5b0d 100644 --- a/boost-common/src/main/java/io/openliberty/boost/common/utils/SpringBootUtil.java +++ b/boost-common/src/main/java/io/openliberty/boost/common/utils/SpringBootUtil.java @@ -11,7 +11,7 @@ package io.openliberty.boost.common.utils; -import static io.openliberty.boost.common.config.ConfigConstants.*; +import static io.openliberty.boost.common.config.LibertyConfigConstants.*; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -41,7 +41,7 @@ import io.openliberty.boost.common.BoostException; import io.openliberty.boost.common.BoostLoggerI; -import io.openliberty.boost.common.config.ConfigConstants; +import io.openliberty.boost.common.config.LibertyConfigConstants; import io.openliberty.boost.common.config.LibertyServerConfigGenerator; import net.wasdev.wlp.common.plugins.util.PluginExecutionException; @@ -60,16 +60,17 @@ public class SpringBootUtil { public static final String SERVER_SSL_KEY_ALIAS = "server.ssl.key-alias"; private static final String APPLICATION_PROPERTIES_FILE = "application.properties"; - + private static final String SPRING_WEBMVC = "org.springframework:spring-webmvc"; private static final String SPRING_WEBSOCKET = "org.springframework:spring-websocket"; private static final String LIBERTY_USE_DEFAULT_HOST = "server.liberty.use-default-host"; /** - * Get the expected path of the Spring Boot Uber JAR (with .spring extension) - * that was preserved during the Boost packaging process. No guarantee that the - * path exists or the artifact is indeed a Spring Boot Uber JAR. + * Get the expected path of the Spring Boot Uber JAR (with .spring + * extension) that was preserved during the Boost packaging process. No + * guarantee that the path exists or the artifact is indeed a Spring Boot + * Uber JAR. * * @param artifact * @return the canonical path @@ -117,8 +118,8 @@ public static File copySpringBootUberJar(File artifact, BoostLoggerI logger) thr } /** - * Add the Spring Boot Version property to the Manifest file in the Liberty Uber - * JAR. This is to trick Spring Boot into not repackaging it. + * Add the Spring Boot Version property to the Manifest file in the Liberty + * Uber JAR. This is to trick Spring Boot into not repackaging it. * * @param artifact * @param springBootVersion @@ -221,8 +222,8 @@ private static Properties getSpringBootApplicationProperties(String springBootPr return applicationProperties; } - public static List getLibertyFeaturesForSpringBoot(String springBootVersion, - Map dependencies, Properties applicationProperties, BoostLoggerI logger) { + public static List getLibertyFeaturesForSpringBoot(String springBootVersion, + Map dependencies, Properties applicationProperties, BoostLoggerI logger) { List featuresToAdd = new ArrayList(); @@ -258,7 +259,8 @@ public static List getLibertyFeaturesForSpringBoot(String springBootVers featuresToAdd.add(TRANSPORT_SECURITY_10); } - // Add any other Liberty features needed depending on the spring framework + // Add any other Liberty features needed depending on the spring + // framework // dependencies defined for (String dependency : dependencies.keySet()) { if (dependency.equals(SPRING_WEBMVC)) { @@ -292,10 +294,10 @@ public static List getLibertyFeaturesForSpringBoot(String springBootVers * @throws IOException * @throws TransformerException */ - public static void generateLibertyServerConfig(String springBootProjectResources, String libertyServerPath, - String springBootVersion, Map dependencies, BoostLoggerI logger, Boolean useDefaultHost) - throws ParserConfigurationException, IOException, TransformerException { - + public static void generateLibertyServerConfig(String springBootProjectResources, String libertyServerPath, + String springBootVersion, Map dependencies, BoostLoggerI logger, Boolean useDefaultHost) + throws ParserConfigurationException, IOException, TransformerException { + logger.info("Generating Liberty server configuration"); // Generate Liberty configuration @@ -305,8 +307,8 @@ public static void generateLibertyServerConfig(String springBootProjectResources Properties applicationProperties = getSpringBootApplicationProperties(springBootProjectResources); // Find and add appropriate springBoot features - List featuresNeededForSpringBootApp = getLibertyFeaturesForSpringBoot(springBootVersion, - dependencies, applicationProperties, logger); + List featuresNeededForSpringBootApp = getLibertyFeaturesForSpringBoot(springBootVersion, dependencies, + applicationProperties, logger); serverConfig.addFeatures(featuresNeededForSpringBootApp); @@ -320,49 +322,59 @@ public static void generateLibertyServerConfig(String springBootProjectResources Map keystoreProperties = new HashMap(); Map keyProperties = new HashMap(); - // For each Spring Boot keystore property, add an entry to the keystore map + // For each Spring Boot keystore property, add an entry to the + // keystore map // which maps our - // Liberty keystore attribute to a bootstrap variable with the same name as the + // Liberty keystore attribute to a bootstrap variable with the + // same name as the // Spring Boot property. // The Spring Boot properties will then be added to the server's // bootstrap.properties file. - keystoreProperties.put(ConfigConstants.LOCATION, BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEYSTORE)); + keystoreProperties.put(LibertyConfigConstants.LOCATION, + BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEYSTORE)); if (springBootServerProps.containsKey(SpringBootUtil.SERVER_SSL_KEYSTORE_PASSWORD)) { - keystoreProperties.put(ConfigConstants.PASSWORD, - BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEYSTORE_PASSWORD)); + keystoreProperties.put(LibertyConfigConstants.PASSWORD, + BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEYSTORE_PASSWORD)); } if (springBootServerProps.containsKey(SpringBootUtil.SERVER_SSL_KEYSTORE_TYPE)) { - keystoreProperties.put(ConfigConstants.TYPE, BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEYSTORE_TYPE)); + keystoreProperties.put(LibertyConfigConstants.TYPE, + BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEYSTORE_TYPE)); } if (springBootServerProps.containsKey(SpringBootUtil.SERVER_SSL_KEYSTORE_PROVIDER)) { - keystoreProperties.put(ConfigConstants.PROVIDER, - BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEYSTORE_PROVIDER)); + keystoreProperties.put(LibertyConfigConstants.PROVIDER, + BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEYSTORE_PROVIDER)); } // Add any key properties to the separate key map. if (springBootServerProps.containsKey(SpringBootUtil.SERVER_SSL_KEY_PASSWORD)) { - keyProperties.put(ConfigConstants.KEY_PASSWORD, - BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEY_PASSWORD)); + keyProperties.put(LibertyConfigConstants.KEY_PASSWORD, + BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEY_PASSWORD)); } if (springBootServerProps.containsKey(SpringBootUtil.SERVER_SSL_KEY_ALIAS)) { - keyProperties.put(ConfigConstants.NAME, BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEY_ALIAS)); + keyProperties.put(LibertyConfigConstants.NAME, + BoostUtil.makeVariable(SpringBootUtil.SERVER_SSL_KEY_ALIAS)); } - // Create keystore element in server.xml and endpoint with http disabled. + // Create keystore element in server.xml and endpoint with http + // disabled. serverConfig.addKeystore(keystoreProperties, keyProperties); serverConfig.addHttpEndpoint(BoostUtil.makeVariable(SpringBootUtil.SERVER_ADDRESS), "-1", - BoostUtil.makeVariable(SpringBootUtil.SERVER_PORT)); + BoostUtil.makeVariable(SpringBootUtil.SERVER_PORT)); - // Since the keystore for the Spring Boot app is created manually and already + // Since the keystore for the Spring Boot app is created + // manually and already // exists, - // if it is specified on the classpath, we need to copy it to the Liberty + // if it is specified on the classpath, we need to copy it to + // the Liberty // server. Otherwise, - // we can just reference the external location without needing to copy the file. + // we can just reference the external location without needing + // to copy the file. String keystoreFile = springBootServerProps.getProperty(SpringBootUtil.SERVER_SSL_KEYSTORE); if (keystoreFile.startsWith("classpath:")) { - // Keystore is in resources directory of spring boot application + // Keystore is in resources directory of spring boot + // application keystoreFile = keystoreFile.replace("classpath:", ""); springBootServerProps.put(SpringBootUtil.SERVER_SSL_KEYSTORE, keystoreFile); diff --git a/boost-common/src/test/java/io/openliberty/boost/common/boosters/JDBCBoosterTest.java b/boost-common/src/test/java/io/openliberty/boost/common/boosters/JDBCBoosterTest.java index e086fad2..dd388fd5 100644 --- a/boost-common/src/test/java/io/openliberty/boost/common/boosters/JDBCBoosterTest.java +++ b/boost-common/src/test/java/io/openliberty/boost/common/boosters/JDBCBoosterTest.java @@ -1,6 +1,6 @@ package io.openliberty.boost.common.boosters; -import static io.openliberty.boost.common.config.ConfigConstants.*; +import static io.openliberty.boost.common.config.LibertyConfigConstants.*; import static io.openliberty.boost.common.utils.DOMUtils.getDirectChildrenByTag; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -21,6 +21,8 @@ import io.openliberty.boost.common.BoostException; import io.openliberty.boost.common.BoostLoggerI; +import io.openliberty.boost.common.boosters.liberty.AbstractBoosterLibertyConfig; +import io.openliberty.boost.common.boosters.liberty.JDBCBoosterLibertyConfig; import io.openliberty.boost.common.config.BoostProperties; import io.openliberty.boost.common.config.BoosterConfigurator; import io.openliberty.boost.common.config.LibertyServerConfigGenerator; @@ -38,7 +40,7 @@ public class JDBCBoosterTest { public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(); private Map getJDBCDependency() throws BoostException { - return BoosterUtil.createDependenciesWithBoosterAndVersion(JDBCBoosterConfig.class, "0.1-SNAPSHOT"); + return BoosterUtil.createDependenciesWithBoosterAndVersion(JDBCBoosterLibertyConfig.class, "0.1-SNAPSHOT"); } private final String DB2_DEPENDENCY_VERSION = "db2jcc4"; @@ -70,8 +72,8 @@ public void testAddJdbcBoosterFeature_SE_16() throws Exception { // Set compiler target property System.setProperty(BoostProperties.INTERNAL_COMPILER_TARGET, "1.6"); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addFeature(boosters.get(0).getFeature()); serverConfig.writeToServer(); @@ -100,8 +102,8 @@ public void testAddJdbcBoosterFeature_SE_17() throws Exception { // Set compiler target property System.setProperty(BoostProperties.INTERNAL_COMPILER_TARGET, "1.7"); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addFeature(boosters.get(0).getFeature()); serverConfig.writeToServer(); @@ -130,8 +132,8 @@ public void testAddJdbcBoosterFeature_SE_7() throws Exception { // Set compiler target property System.setProperty(BoostProperties.INTERNAL_COMPILER_TARGET, "7"); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addFeature(boosters.get(0).getFeature()); serverConfig.writeToServer(); @@ -160,8 +162,8 @@ public void testAddJdbcBoosterFeature_SE_18() throws Exception { // Set compiler target property System.setProperty(BoostProperties.INTERNAL_COMPILER_TARGET, "1.8"); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addFeature(boosters.get(0).getFeature()); serverConfig.writeToServer(); @@ -190,8 +192,8 @@ public void testAddJdbcBoosterFeature_SE_8() throws Exception { // Set compiler target property System.setProperty(BoostProperties.INTERNAL_COMPILER_TARGET, "8"); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addFeature(boosters.get(0).getFeature()); serverConfig.writeToServer(); @@ -220,8 +222,8 @@ public void testAddJdbcBoosterFeature_SE9() throws Exception { // Set compiler target property System.setProperty(BoostProperties.INTERNAL_COMPILER_TARGET, "9"); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addFeature(boosters.get(0).getFeature()); serverConfig.writeToServer(); @@ -250,8 +252,8 @@ public void testAddJdbcBoosterFeature_SE11() throws Exception { // Set compiler target property System.setProperty(BoostProperties.INTERNAL_COMPILER_TARGET, "11"); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addFeature(boosters.get(0).getFeature()); serverConfig.writeToServer(); @@ -277,8 +279,8 @@ public void testAddJdbcBoosterConfig_Derby() throws Exception { LibertyServerConfigGenerator serverConfig = new LibertyServerConfigGenerator( outputDir.getRoot().getAbsolutePath(), logger); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -305,7 +307,8 @@ public void testAddJdbcBoosterConfig_Derby() throws Exception { dataSource.getAttribute(JDBC_DRIVER_REF)); List propertiesDerbyEmbeddedList = getDirectChildrenByTag(dataSource, PROPERTIES_DERBY_EMBEDDED); - assertEquals("Didn't find one and only one " + PROPERTIES_DERBY_EMBEDDED, 1, propertiesDerbyEmbeddedList.size()); + assertEquals("Didn't find one and only one " + PROPERTIES_DERBY_EMBEDDED, 1, + propertiesDerbyEmbeddedList.size()); Element propertiesDerbyEmbedded = propertiesDerbyEmbeddedList.get(0); assertEquals("The createDatabase attribute is not correct", @@ -339,9 +342,10 @@ public void testAddJdbcBoosterConfig_DB2() throws Exception { // Add JDBC booster and DB2 to dependency map Map dependencies = getJDBCDependency(); - dependencies.put(JDBCBoosterConfig.DB2_DEPENDENCY, DB2_DEPENDENCY_VERSION); + dependencies.put(JDBCBoosterLibertyConfig.DB2_DEPENDENCY, DB2_DEPENDENCY_VERSION); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(dependencies, logger); + List boosters = BoosterConfigurator.getBoosterLibertyConfigurators(dependencies, + logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -402,7 +406,7 @@ public void testAddJdbcBoosterConfig_DB2() throws Exception { assertEquals("AuthData password is not correct", BoostUtil.makeVariable(BoostProperties.DATASOURCE_PASSWORD), authData.getAttribute(PASSWORD)); } - + /** * Test that the server.xml is fully configured with the MySQL datasource * @@ -418,9 +422,10 @@ public void testAddJdbcBoosterConfig_MySQL() throws Exception { // Add JDBC booster and MySQL to dependency map Map dependencies = getJDBCDependency(); - dependencies.put(JDBCBoosterConfig.MYSQL_DEPENDENCY, MYSQL_DEPENDENCY_VERSION); + dependencies.put(JDBCBoosterLibertyConfig.MYSQL_DEPENDENCY, MYSQL_DEPENDENCY_VERSION); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(dependencies, logger); + List boosters = BoosterConfigurator.getBoosterLibertyConfigurators(dependencies, + logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -456,11 +461,9 @@ public void testAddJdbcBoosterConfig_MySQL() throws Exception { BoostUtil.makeVariable(BoostProperties.DATASOURCE_DATABASE_NAME), properties.getAttribute(DATABASE_NAME)); assertEquals("The serverName attribute is not correct", - BoostUtil.makeVariable(BoostProperties.DATASOURCE_SERVER_NAME), - properties.getAttribute(SERVER_NAME)); + BoostUtil.makeVariable(BoostProperties.DATASOURCE_SERVER_NAME), properties.getAttribute(SERVER_NAME)); assertEquals("The portNumber attribute is not correct", - BoostUtil.makeVariable(BoostProperties.DATASOURCE_PORT_NUMBER), - properties.getAttribute(PORT_NUMBER)); + BoostUtil.makeVariable(BoostProperties.DATASOURCE_PORT_NUMBER), properties.getAttribute(PORT_NUMBER)); // Check that the element is correctly configured List jdbcDriverList = getDirectChildrenByTag(serverRoot, JDBC_DRIVER); @@ -499,8 +502,8 @@ public void testAddJdbcBoosterConfig_with_databaseName_configured() throws Excep // Set database name property System.setProperty(BoostProperties.DATASOURCE_DATABASE_NAME, "myDatabase"); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -529,8 +532,8 @@ public void testAddJdbcBoosterConfig_with_databaseName_derby_default() throws Ex LibertyServerConfigGenerator serverConfig = new LibertyServerConfigGenerator( outputDir.getRoot().getAbsolutePath(), logger); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -562,8 +565,8 @@ public void testAddJdbcBoosterConfig_with_createDatabase_configured() throws Exc // Set database name property System.setProperty(BoostProperties.DATASOURCE_CREATE_DATABASE, "false"); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -592,8 +595,8 @@ public void testAddJdbcBoosterConfig_with_createDatabase_derby_default() throws LibertyServerConfigGenerator serverConfig = new LibertyServerConfigGenerator( outputDir.getRoot().getAbsolutePath(), logger); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -624,9 +627,10 @@ public void testAddJdbcBoosterConfig_with_portNumber_db2_default() throws Except // Add JDBC booster and DB2 to dependency map Map dependencies = getJDBCDependency(); - dependencies.put(JDBCBoosterConfig.DB2_DEPENDENCY, DB2_DEPENDENCY_VERSION); + dependencies.put(JDBCBoosterLibertyConfig.DB2_DEPENDENCY, DB2_DEPENDENCY_VERSION); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(dependencies, logger); + List boosters = BoosterConfigurator.getBoosterLibertyConfigurators(dependencies, + logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -640,10 +644,10 @@ public void testAddJdbcBoosterConfig_with_portNumber_db2_default() throws Except assertEquals("The property set in bootstrap.properties for " + BoostProperties.DATASOURCE_PORT_NUMBER + " is not correct", DB2_DEFAULT_PORT_NUMBER, propertyFound); } - + /** - * Test that the default portNumber property for mysql is correctly written to - * bootstrap.properties + * Test that the default portNumber property for mysql is correctly written + * to bootstrap.properties * * @throws ParserConfigurationException * @throws TransformerException @@ -657,9 +661,10 @@ public void testAddJdbcBoosterConfig_with_portNumber_mysql_default() throws Exce // Add JDBC booster and DB2 to dependency map Map dependencies = getJDBCDependency(); - dependencies.put(JDBCBoosterConfig.MYSQL_DEPENDENCY, MYSQL_DEPENDENCY_VERSION); + dependencies.put(JDBCBoosterLibertyConfig.MYSQL_DEPENDENCY, MYSQL_DEPENDENCY_VERSION); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(dependencies, logger); + List boosters = BoosterConfigurator.getBoosterLibertyConfigurators(dependencies, + logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -692,9 +697,10 @@ public void testAddJdbcBoosterConfig_with_portNumber_configured() throws Excepti // Add JDBC booster and DB2 to dependency map Map dependencies = getJDBCDependency(); - dependencies.put(JDBCBoosterConfig.DB2_DEPENDENCY, DB2_DEPENDENCY_VERSION); + dependencies.put(JDBCBoosterLibertyConfig.DB2_DEPENDENCY, DB2_DEPENDENCY_VERSION); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(dependencies, logger); + List boosters = BoosterConfigurator.getBoosterLibertyConfigurators(dependencies, + logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -727,9 +733,10 @@ public void testAddJdbcBoosterConfig_with_serverName_configured() throws Excepti // Add JDBC booster and DB2 to dependency map Map dependencies = getJDBCDependency(); - dependencies.put(JDBCBoosterConfig.DB2_DEPENDENCY, DB2_DEPENDENCY_VERSION); + dependencies.put(JDBCBoosterLibertyConfig.DB2_DEPENDENCY, DB2_DEPENDENCY_VERSION); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(dependencies, logger); + List boosters = BoosterConfigurator.getBoosterLibertyConfigurators(dependencies, + logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -760,9 +767,10 @@ public void testAddJdbcBoosterConfig_with_serverName_default() throws Exception // Add JDBC booster and DB2 to dependency map Map dependencies = getJDBCDependency(); - dependencies.put(JDBCBoosterConfig.DB2_DEPENDENCY, DB2_DEPENDENCY_VERSION); + dependencies.put(JDBCBoosterLibertyConfig.DB2_DEPENDENCY, DB2_DEPENDENCY_VERSION); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(dependencies, logger); + List boosters = BoosterConfigurator.getBoosterLibertyConfigurators(dependencies, + logger); serverConfig.addBoosterConfig(boosters.get(0)); @@ -794,8 +802,8 @@ public void testAddJdbcBoosterConfig_with_generic_property() throws Exception { // Set database name property System.setProperty(BoostProperties.DATASOURCE_PREFIX + "randomProperty", "randomValue"); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); serverConfig.addBoosterConfig(boosters.get(0)); diff --git a/boost-common/src/test/java/io/openliberty/boost/common/config/BoosterConfiguratorTest.java b/boost-common/src/test/java/io/openliberty/boost/common/config/BoosterConfiguratorTest.java index e40b7a46..157e49a8 100644 --- a/boost-common/src/test/java/io/openliberty/boost/common/config/BoosterConfiguratorTest.java +++ b/boost-common/src/test/java/io/openliberty/boost/common/config/BoosterConfiguratorTest.java @@ -23,8 +23,8 @@ import io.openliberty.boost.common.BoostException; import io.openliberty.boost.common.BoostLoggerI; -import io.openliberty.boost.common.boosters.AbstractBoosterConfig; -import io.openliberty.boost.common.boosters.JDBCBoosterConfig; +import io.openliberty.boost.common.boosters.liberty.AbstractBoosterLibertyConfig; +import io.openliberty.boost.common.boosters.liberty.JDBCBoosterLibertyConfig; import io.openliberty.boost.common.config.BoostProperties; import io.openliberty.boost.common.config.BoosterConfigurator; import io.openliberty.boost.common.utils.BoosterUtil; @@ -36,7 +36,7 @@ public class BoosterConfiguratorTest { public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(); private Map getJDBCDependency() throws BoostException { - return BoosterUtil.createDependenciesWithBoosterAndVersion(JDBCBoosterConfig.class, "0.1-SNAPSHOT"); + return BoosterUtil.createDependenciesWithBoosterAndVersion(JDBCBoosterLibertyConfig.class, "0.1-SNAPSHOT"); } /** @@ -46,19 +46,20 @@ private Map getJDBCDependency() throws BoostException { * */ @Test - public void testGetBoosterPackConfigurators_jdbc_default() throws Exception { + public void testGetBoosterLibertyConfigurators_jdbc_default() throws Exception { // Get booster configurators BoostLoggerI logger = CommonLogger.getInstance(); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); // Check that the JDBCBoosterPackConfigurator was created - AbstractBoosterConfig booster = boosters.get(0); - assertTrue("JDBC booster was not found in booster configurator list", booster instanceof JDBCBoosterConfig); + AbstractBoosterLibertyConfig booster = boosters.get(0); + assertTrue("JDBC booster was not found in booster configurator list", + booster instanceof JDBCBoosterLibertyConfig); // Check that the custom databaseName is set - assertEquals("Database name is not correct", ConfigConstants.DERBY_DB, + assertEquals("Database name is not correct", LibertyConfigConstants.DERBY_DB, booster.getServerProperties().getProperty(BoostProperties.DATASOURCE_DATABASE_NAME)); } @@ -80,12 +81,13 @@ public void testGetBoosterPackConfigurators_jdbc_with_databaseName() throws Exce // Get booster configurators BoostLoggerI logger = CommonLogger.getInstance(); - List boosters = BoosterConfigurator.getBoosterPackConfigurators(getJDBCDependency(), - logger); + List boosters = BoosterConfigurator + .getBoosterLibertyConfigurators(getJDBCDependency(), logger); // Check that the JDBCBoosterPackConfigurator was created - AbstractBoosterConfig booster = boosters.get(0); - assertTrue("JDBC booster was not found in booster configurator list", booster instanceof JDBCBoosterConfig); + AbstractBoosterLibertyConfig booster = boosters.get(0); + assertTrue("JDBC booster was not found in booster configurator list", + booster instanceof JDBCBoosterLibertyConfig); // Check that the custom databaseName is set assertEquals("Database name is not correct", databaseName, diff --git a/boost-common/src/test/java/io/openliberty/boost/common/config/LibertyServerConfigGeneratorTest.java b/boost-common/src/test/java/io/openliberty/boost/common/config/LibertyServerConfigGeneratorTest.java index 0f56a88e..0755f3a4 100644 --- a/boost-common/src/test/java/io/openliberty/boost/common/config/LibertyServerConfigGeneratorTest.java +++ b/boost-common/src/test/java/io/openliberty/boost/common/config/LibertyServerConfigGeneratorTest.java @@ -29,7 +29,7 @@ import io.openliberty.boost.common.config.LibertyServerConfigGenerator; import io.openliberty.boost.common.BoostLoggerI; -import static io.openliberty.boost.common.config.ConfigConstants.*; +import static io.openliberty.boost.common.config.LibertyConfigConstants.*; import static io.openliberty.boost.common.utils.DOMUtils.getDirectChildrenByTag; public class LibertyServerConfigGeneratorTest { @@ -66,7 +66,8 @@ public void testAddSpringFeature() throws ParserConfigurationException, Transfor @Test public void testZeroFeaturesInDefaultServerConfig() throws ParserConfigurationException, TransformerException, IOException { - LibertyServerConfigGenerator g = new LibertyServerConfigGenerator(outputDir.getRoot().getAbsolutePath(), logger); + LibertyServerConfigGenerator g = new LibertyServerConfigGenerator(outputDir.getRoot().getAbsolutePath(), + logger); Element serverRoot = g.getServerDoc().getDocumentElement(); List featureMgrList = getDirectChildrenByTag(serverRoot, FEATURE_MANAGER); assertEquals("Didn't find one and only one featureMgr", 1, featureMgrList.size()); diff --git a/boost-common/src/test/java/io/openliberty/boost/common/utils/BoosterUtil.java b/boost-common/src/test/java/io/openliberty/boost/common/utils/BoosterUtil.java index 915210fa..9d53e6f4 100644 --- a/boost-common/src/test/java/io/openliberty/boost/common/utils/BoosterUtil.java +++ b/boost-common/src/test/java/io/openliberty/boost/common/utils/BoosterUtil.java @@ -4,14 +4,15 @@ import java.util.Map; import io.openliberty.boost.common.BoostException; -import io.openliberty.boost.common.boosters.AbstractBoosterConfig; +import io.openliberty.boost.common.boosters.liberty.AbstractBoosterLibertyConfig; public class BoosterUtil { - - public static Map createDependenciesWithBoosterAndVersion(Class booster, String version) throws BoostException { + + public static Map createDependenciesWithBoosterAndVersion(Class booster, String version) + throws BoostException { Map map = new HashMap(); - map.put(AbstractBoosterConfig.getCoordindates(booster), version); + map.put(AbstractBoosterLibertyConfig.getCoordindates(booster), version); return map; } - + } \ No newline at end of file diff --git a/boost-maven/boost-boosters/booster-wildfly/invoker.properties b/boost-maven/boost-boosters/booster-wildfly/invoker.properties new file mode 100644 index 00000000..5bb0ebae --- /dev/null +++ b/boost-maven/boost-boosters/booster-wildfly/invoker.properties @@ -0,0 +1 @@ +invoker.goals.1 = clean install \ No newline at end of file diff --git a/boost-maven/boost-boosters/booster-wildfly/pom.xml b/boost-maven/boost-boosters/booster-wildfly/pom.xml new file mode 100644 index 00000000..5806595a --- /dev/null +++ b/boost-maven/boost-boosters/booster-wildfly/pom.xml @@ -0,0 +1,11 @@ + + + 4.0.0 + + io.openliberty.boosters + wildfly + 0.1-SNAPSHOT + + diff --git a/boost-maven/boost-boosters/pom.xml b/boost-maven/boost-boosters/pom.xml index 27949cf8..98face7c 100644 --- a/boost-maven/boost-boosters/pom.xml +++ b/boost-maven/boost-boosters/pom.xml @@ -24,6 +24,7 @@ booster-mpHealth-20 booster-mpOpenTracing-20 booster-mpRestClient-20 + booster-wildfly diff --git a/boost-maven/boost-maven-plugin/src/it/test-jdbc-derby-default/invoker.properties b/boost-maven/boost-maven-plugin/src/it/test-jdbc-derby-default/invoker.properties index 2955519c..a4d95399 100644 --- a/boost-maven/boost-maven-plugin/src/it/test-jdbc-derby-default/invoker.properties +++ b/boost-maven/boost-maven-plugin/src/it/test-jdbc-derby-default/invoker.properties @@ -1,3 +1,3 @@ -invoker.goals.1 = clean install +invoker.goals.1 = clean install -e # purposely avoid clean second time -invoker.goals.2 = clean install -Dboost.db.databaseName=myCustomDerbyDB \ No newline at end of file +invoker.goals.2 = clean install -Dboost.db.databaseName=myCustomDerbyDB -e \ No newline at end of file diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostDebugMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostDebugMojo.java new file mode 100644 index 00000000..10cd1c68 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostDebugMojo.java @@ -0,0 +1,45 @@ +package io.openliberty.boost.maven; + +import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment; +import static org.twdata.maven.mojoexecutor.MojoExecutor.goal; +import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; +import static org.twdata.maven.mojoexecutor.MojoExecutor.version; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; + +@Mojo(name = "debug", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) +public class BoostDebugMojo extends AbstractMojo { + + @Parameter(defaultValue = "${project}", readonly = true) + protected MavenProject project; + + @Parameter(defaultValue = "${session}", readonly = true) + protected MavenSession session; + + @Component + protected BuildPluginManager pluginManager; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + // Check our runtime and execute maven goal for either liberty-debug or + // wildfly-debug + + executeMojo( + plugin(groupId("io.openliberty.boost"), artifactId("boost-maven-plugin"), version("0.1.3-SNAPSHOT")), + goal("liberty-debug"), configuration(), executionEnvironment(project, session, pluginManager)); + } + +} diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostPackageMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostPackageMojo.java new file mode 100644 index 00000000..d3d07f87 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostPackageMojo.java @@ -0,0 +1,58 @@ +package io.openliberty.boost.maven; + +import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment; +import static org.twdata.maven.mojoexecutor.MojoExecutor.goal; +import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; +import static org.twdata.maven.mojoexecutor.MojoExecutor.version; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; + +import io.openliberty.boost.maven.utils.BoostLogger; +import io.openliberty.boost.maven.utils.MavenProjectUtil; + +@Mojo(name = "package", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME) +public class BoostPackageMojo extends AbstractMojo { + + @Parameter(defaultValue = "${project}", readonly = true) + protected MavenProject project; + + @Parameter(defaultValue = "${session}", readonly = true) + protected MavenSession session; + + @Component + protected BuildPluginManager pluginManager; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + // Check our runtime and execute maven goal for either libertyPackage or + // wildflyPackage + String runtime = MavenProjectUtil.getBoostRuntime(project, BoostLogger.getInstance()); + if (runtime.equals("wildfly")) { + executeMojo( + plugin(groupId("io.openliberty.boost"), artifactId("boost-maven-plugin"), + version("0.1.3-SNAPSHOT")), + goal("wildfly-package"), configuration(), executionEnvironment(project, session, pluginManager)); + } else { + + executeMojo( + plugin(groupId("io.openliberty.boost"), artifactId("boost-maven-plugin"), + version("0.1.3-SNAPSHOT")), + goal("liberty-package"), configuration(), executionEnvironment(project, session, pluginManager)); + } + } + +} diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostRunMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostRunMojo.java new file mode 100644 index 00000000..b079a18e --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostRunMojo.java @@ -0,0 +1,56 @@ +package io.openliberty.boost.maven; + +import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment; +import static org.twdata.maven.mojoexecutor.MojoExecutor.goal; +import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; +import static org.twdata.maven.mojoexecutor.MojoExecutor.version; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; + +import io.openliberty.boost.maven.utils.BoostLogger; +import io.openliberty.boost.maven.utils.MavenProjectUtil; + +@Mojo(name = "run", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) +public class BoostRunMojo extends AbstractMojo { + + @Parameter(defaultValue = "${project}", readonly = true) + protected MavenProject project; + + @Parameter(defaultValue = "${session}", readonly = true) + protected MavenSession session; + + @Component + protected BuildPluginManager pluginManager; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + // Check our runtime and execute maven goal for either liberty-run or + // wildfly-run + String runtime = MavenProjectUtil.getBoostRuntime(project, BoostLogger.getInstance()); + BoostLogger.getInstance().info("Boost runtime is: " + runtime); + if (runtime.equals("wildfly")) { + executeMojo( + plugin(groupId("io.openliberty.boost"), artifactId("boost-maven-plugin"), + version("0.1.3-SNAPSHOT")), + goal("wildfly-run"), configuration(), executionEnvironment(project, session, pluginManager)); + } else { + executeMojo( + plugin(groupId("io.openliberty.boost"), artifactId("boost-maven-plugin"), version("0.1.3-SNAPSHOT")), + goal("liberty-run"), configuration(), executionEnvironment(project, session, pluginManager)); + } + } + +} diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostStartMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostStartMojo.java new file mode 100644 index 00000000..29310591 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostStartMojo.java @@ -0,0 +1,56 @@ +package io.openliberty.boost.maven; + +import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment; +import static org.twdata.maven.mojoexecutor.MojoExecutor.goal; +import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; +import static org.twdata.maven.mojoexecutor.MojoExecutor.version; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; + +import io.openliberty.boost.maven.utils.BoostLogger; +import io.openliberty.boost.maven.utils.MavenProjectUtil; + +@Mojo(name = "start", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) +public class BoostStartMojo extends AbstractMojo { + + @Parameter(defaultValue = "${project}", readonly = true) + protected MavenProject project; + + @Parameter(defaultValue = "${session}", readonly = true) + protected MavenSession session; + + @Component + protected BuildPluginManager pluginManager; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + // Check our runtime and execute maven goal for either liberty-start or + // wildfly-start + String runtime = MavenProjectUtil.getBoostRuntime(project, BoostLogger.getInstance()); + BoostLogger.getInstance().info("Boost runtime is: " + runtime); + if (runtime.equals("wildfly")) { + executeMojo( + plugin(groupId("io.openliberty.boost"), artifactId("boost-maven-plugin"), + version("0.1.3-SNAPSHOT")), + goal("wildfly-start"), configuration(), executionEnvironment(project, session, pluginManager)); + } else { + executeMojo( + plugin(groupId("io.openliberty.boost"), artifactId("boost-maven-plugin"), version("0.1.3-SNAPSHOT")), + goal("liberty-start"), configuration(), executionEnvironment(project, session, pluginManager)); + } + } + +} diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostStopMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostStopMojo.java new file mode 100644 index 00000000..71b4556c --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/BoostStopMojo.java @@ -0,0 +1,56 @@ +package io.openliberty.boost.maven; + +import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment; +import static org.twdata.maven.mojoexecutor.MojoExecutor.goal; +import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; +import static org.twdata.maven.mojoexecutor.MojoExecutor.version; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; + +import io.openliberty.boost.maven.utils.BoostLogger; +import io.openliberty.boost.maven.utils.MavenProjectUtil; + +@Mojo(name = "stop", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) +public class BoostStopMojo extends AbstractMojo { + + @Parameter(defaultValue = "${project}", readonly = true) + protected MavenProject project; + + @Parameter(defaultValue = "${session}", readonly = true) + protected MavenSession session; + + @Component + protected BuildPluginManager pluginManager; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + // Check our runtime and execute maven goal for either liberty-stop or + // wildfly-stop + String runtime = MavenProjectUtil.getBoostRuntime(project, BoostLogger.getInstance()); + BoostLogger.getInstance().info("Boost runtime is: " + runtime); + if (runtime.equals("wildfly")) { + executeMojo( + plugin(groupId("io.openliberty.boost"), artifactId("boost-maven-plugin"), + version("0.1.3-SNAPSHOT")), + goal("wildfly-stop"), configuration(), executionEnvironment(project, session, pluginManager)); + } else { + executeMojo( + plugin(groupId("io.openliberty.boost"), artifactId("boost-maven-plugin"), version("0.1.3-SNAPSHOT")), + goal("liberty-stop"), configuration(), executionEnvironment(project, session, pluginManager)); + } + } + +} diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyDebugMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyDebugMojo.java index 654c0997..66028c44 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyDebugMojo.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyDebugMojo.java @@ -25,7 +25,7 @@ * debugger connects to debug port 7777. * */ -@Mojo(name = "debug") +@Mojo(name = "liberty-debug") public class LibertyDebugMojo extends AbstractLibertyMojo { /** diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyPackageMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyPackageMojo.java index c9bf458b..83c761b5 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyPackageMojo.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyPackageMojo.java @@ -24,11 +24,11 @@ import org.apache.maven.plugins.annotations.*; import io.openliberty.boost.common.BoostException; -import io.openliberty.boost.common.boosters.AbstractBoosterConfig; +import io.openliberty.boost.common.boosters.liberty.AbstractBoosterLibertyConfig; import io.openliberty.boost.common.utils.BoostUtil; import io.openliberty.boost.common.config.BoostProperties; import io.openliberty.boost.common.config.BoosterConfigurator; -import io.openliberty.boost.common.config.ConfigConstants; +import io.openliberty.boost.common.config.LibertyConfigConstants; import io.openliberty.boost.common.utils.SpringBootUtil; import io.openliberty.boost.maven.utils.BoostLogger; import io.openliberty.boost.maven.utils.MavenProjectUtil; @@ -42,10 +42,10 @@ * the 'jar' packaging type). * */ -@Mojo(name = "package", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME) +@Mojo(name = "liberty-package", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME) public class LibertyPackageMojo extends AbstractLibertyMojo { - protected List boosterPackConfigurators; + protected List boosterPackConfigurators; String springBootVersion = null; @@ -102,7 +102,7 @@ public void execute() throws MojoExecutionException { generateServerConfigSpringBoot(); installMissingFeatures(); - installApp(ConfigConstants.INSTALL_PACKAGE_SPRING); + installApp(LibertyConfigConstants.INSTALL_PACKAGE_SPRING); if (springBootUberJar != null) { // Create the Liberty Uber JAR from the Spring Boot Uber JAR in @@ -130,7 +130,7 @@ public void execute() throws MojoExecutionException { Map dependencies = MavenProjectUtil.getAllDependencies(project, repoSystem, repoSession, remoteRepos, BoostLogger.getInstance()); - this.boosterPackConfigurators = BoosterConfigurator.getBoosterPackConfigurators(dependencies, + this.boosterPackConfigurators = BoosterConfigurator.getBoosterLibertyConfigurators(dependencies, BoostLogger.getInstance()); } catch (Exception e) { @@ -148,13 +148,13 @@ public void execute() throws MojoExecutionException { // the LMP would write out a webapp stanza into config dropins that // would include a config-root setting set to the app name. if (project.getPackaging().equals("war")) { - installApp(ConfigConstants.INSTALL_PACKAGE_ALL); + installApp(LibertyConfigConstants.INSTALL_PACKAGE_ALL); } else { // This is temporary. When packing type is "jar", if we // set installAppPackages=all, the LMP will try to install // the project jar and fail. Once this is fixed, we can always // set installAppPackages=all. - installApp(ConfigConstants.INSTALL_PACKAGE_DEP); + installApp(LibertyConfigConstants.INSTALL_PACKAGE_DEP); } // Not sure this works yet, the main idea is to NOT create this with @@ -216,7 +216,7 @@ private List getWarNames() { } } - if (project.getPackaging().equals(ConfigConstants.WAR_PKG_TYPE)) { + if (project.getPackaging().equals(LibertyConfigConstants.WAR_PKG_TYPE)) { if (project.getVersion() == null) { warNames.add(project.getArtifactId()); } else { @@ -316,7 +316,7 @@ private void installApp(String installAppPackagesVal) throws MojoExecutionExcept Element serverName = element(name("serverName"), libertyServerName); Xpp3Dom configuration = configuration(installAppPackages, serverName, getRuntimeArtifactElement()); - if (!ConfigConstants.INSTALL_PACKAGE_SPRING.equals(installAppPackagesVal)) { + if (!LibertyConfigConstants.INSTALL_PACKAGE_SPRING.equals(installAppPackagesVal)) { configuration.addChild(element(name("appsDirectory"), "apps").toDom()); configuration.addChild(element(name("looseApplication"), "true").toDom()); } diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyRunMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyRunMojo.java index 3f86fd8b..faaa4a3d 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyRunMojo.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyRunMojo.java @@ -23,7 +23,7 @@ /** * Runs the executable archive application (in the console foreground). */ -@Mojo(name = "run") +@Mojo(name = "liberty-run") public class LibertyRunMojo extends AbstractLibertyMojo { /** diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyStartMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyStartMojo.java index 8a848dcf..9af13724 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyStartMojo.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyStartMojo.java @@ -24,7 +24,7 @@ * Starts the executable archive application as a background process. * */ -@Mojo(name = "start") +@Mojo(name = "liberty-start") public class LibertyStartMojo extends AbstractLibertyMojo { /** diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyStopMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyStopMojo.java index b3b137f7..68db2456 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyStopMojo.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/liberty/LibertyStopMojo.java @@ -23,7 +23,7 @@ * Stops the executable archive application started by the 'start' or 'run' * goals. */ -@Mojo(name = "stop") +@Mojo(name = "liberty-stop") public class LibertyStopMojo extends AbstractLibertyMojo { @Override diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/utils/MavenProjectUtil.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/utils/MavenProjectUtil.java index bd31e104..bf10cc2e 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/utils/MavenProjectUtil.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/utils/MavenProjectUtil.java @@ -48,6 +48,19 @@ public static String findSpringBootVersion(MavenProject project) { return version; } + + public static String getBoostRuntime(MavenProject project, BoostLogger logger) { + logger.debug("Determining Boost runtime"); + for (Artifact artifact : project.getArtifacts()) { + if ("io.openliberty.boosters".equals(artifact.getGroupId()) && "wildfly".equals(artifact.getArtifactId())) { + logger.debug("Using Wildfly runtime"); + return "wildfly"; + } + } + + logger.debug("Using Liberty runtime"); + return "liberty"; + } public static Map getAllDependencies(MavenProject project, RepositorySystem repoSystem, RepositorySystemSession repoSession, List remoteRepos, BoostLogger logger) diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/AbstractWildflyMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/AbstractWildflyMojo.java new file mode 100644 index 00000000..fb89e11a --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/AbstractWildflyMojo.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.maven.wildfly; + +import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.element; +import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment; +import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.name; +import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; +import static org.twdata.maven.mojoexecutor.MojoExecutor.version; + +import java.util.List; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.codehaus.mojo.pluginsupport.MojoSupport; +import org.codehaus.mojo.pluginsupport.util.ArtifactItem; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; +import org.twdata.maven.mojoexecutor.MojoExecutor.Element; +import org.twdata.maven.mojoexecutor.MojoExecutor.ExecutionEnvironment; + +public abstract class AbstractWildflyMojo extends MojoSupport { + + + protected String wildflyMavenPluginGroupId = "org.wildfly.plugins"; + protected String wildflyMavenPluginArtifactId = "wildfly-maven-plugin"; + + protected String mavenDependencyPluginGroupId = "org.apache.maven.plugins"; + protected String mavenDependencyPluginArtifactId = "maven-dependency-plugin"; + + @Parameter(defaultValue = "2.0.1.Final", readonly = true) + protected String wildflyMavenPluginVersion; + + @Parameter(defaultValue = "${project.build.directory}", readonly = true) + protected String projectBuildDir; + + @Parameter(defaultValue = "${project}", readonly = true) + protected MavenProject project; + + @Parameter(defaultValue = "${session}", readonly = true) + protected MavenSession session; + + @Parameter(defaultValue = "${repositorySystemSession}", readonly = true) + protected RepositorySystemSession repoSession; + + @Parameter( defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true ) + protected List remoteRepos; + + @Component + protected RepositorySystem repoSystem; + + @Component + protected BuildPluginManager pluginManager; + + @Parameter + protected ArtifactItem runtimeArtifact; + + @Parameter(property = "useDefaultHost", defaultValue = "false", readonly = true) + protected boolean useDefaultHost; + + protected Plugin getPlugin() throws MojoExecutionException { + return plugin(groupId(wildflyMavenPluginGroupId), artifactId(wildflyMavenPluginArtifactId), + version(wildflyMavenPluginVersion)); + } + + protected Plugin getMavenDependencyPlugin() throws MojoExecutionException { + return plugin(groupId(mavenDependencyPluginGroupId), artifactId(mavenDependencyPluginArtifactId)); + } + + protected Element getRuntimeArtifactElement() { + return element(name("artifactItem"), element(name("groupId"), runtimeArtifact.getGroupId()), + element(name("artifactId"), runtimeArtifact.getArtifactId()), + element(name("version"), runtimeArtifact.getVersion()), + element(name("type"), runtimeArtifact.getType())); + } + + protected ExecutionEnvironment getExecutionEnvironment() { + return executionEnvironment(project, session, pluginManager); + } + + /** + * Create default runtime artifact, if one has not been provided by the user + */ + private void createDefaultRuntimeArtifactIfNeeded() { + if (runtimeArtifact == null) { + runtimeArtifact = new ArtifactItem(); + runtimeArtifact.setGroupId("org.wildfly"); + runtimeArtifact.setArtifactId("wildfly-dist"); + runtimeArtifact.setVersion("16.0.0.Final"); + runtimeArtifact.setType("zip"); + } + } + + @Override + public void execute() throws MojoExecutionException { + createDefaultRuntimeArtifactIfNeeded(); + } + +} diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyPackageMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyPackageMojo.java new file mode 100644 index 00000000..765f0721 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyPackageMojo.java @@ -0,0 +1,154 @@ +/******************************************************************************* + * Copyright (c) 2018, 2019 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.maven.wildfly; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.*; + +import io.openliberty.boost.common.boosters.wildfly.AbstractBoosterWildflyConfig; +import io.openliberty.boost.common.config.BoostProperties; +import io.openliberty.boost.common.config.BoosterConfigurator; +import io.openliberty.boost.maven.utils.BoostLogger; +import io.openliberty.boost.maven.utils.MavenProjectUtil; + +import static org.twdata.maven.mojoexecutor.MojoExecutor.*; + +/** + * Packages an existing application into a Wildfly executable jar so that the + * application can be run from the command line using java -jar. (This is for + * the 'jar' packaging type). + * + */ +@Mojo(name = "wildfly-package", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME) +public class WildflyPackageMojo extends AbstractWildflyMojo { + + protected List boosterConfigurators; + + String wildflyInstallPath; + + @Override + public void execute() throws MojoExecutionException { + super.execute(); + + wildflyInstallPath = projectBuildDir + "/wildfly-" + runtimeArtifact.getVersion(); + + installWildfly(); + + // /** + // * Whether the packaged Liberty Uber JAR will be the project artifact. + // * This should be the case in Spring Boot scenarios since Spring Boot + // * developers expect a runnable JAR. + // */ + // boolean attach; + + // Determine the Java compiler target version and set this + // internally + String javaCompilerTargetVersion = MavenProjectUtil.getJavaCompilerTargetVersion(project); + System.setProperty(BoostProperties.INTERNAL_COMPILER_TARGET, javaCompilerTargetVersion); + + try { + // Get booster dependencies from project + Map dependencies = MavenProjectUtil.getAllDependencies(project, repoSystem, repoSession, + remoteRepos, BoostLogger.getInstance()); + + this.boosterConfigurators = BoosterConfigurator.getBoosterWildflyConfigurators(dependencies, + BoostLogger.getInstance()); + } catch (Exception e) { + throw new MojoExecutionException(e.getMessage(), e); + } + + copyBoosterDependencies(); + + configureServer(); + } + + private void installWildfly() throws MojoExecutionException { + + executeMojo(getMavenDependencyPlugin(), goal("unpack"), + configuration(element(name("outputDirectory"), projectBuildDir), + element(name("artifactItems"), getRuntimeArtifactElement())), + getExecutionEnvironment()); + } + + /** + * Generate config for the Wildfly server based on the Maven + * + * @throws MojoExecutionException + */ + private void configureServer() throws MojoExecutionException { + + List warFiles = getWarFiles(); + try { + // Generate server config + BoosterConfigurator.generateWildflyServerConfig(wildflyInstallPath, boosterConfigurators, warFiles, + BoostLogger.getInstance()); + + } catch (Exception e) { + throw new MojoExecutionException("Unable to configure the Wildfly server.", e); + } + } + + private List getWarFiles() { + List warFiles = new ArrayList(); + + // TODO: are these war files downloaded to target? Do we need to copy + // them using the dependency plugin? + for (Artifact artifact : project.getArtifacts()) { + if (artifact.getType().equals("war")) { + warFiles.add(Paths.get(artifact.getArtifactId() + "-" + artifact.getVersion())); + } + } + + if (project.getVersion() == null) { + warFiles.add(Paths.get(projectBuildDir + "/" + project.getArtifactId() + ".war")); + } else { + warFiles.add( + Paths.get(projectBuildDir + "/" + project.getArtifactId() + "-" + project.getVersion() + ".war")); + } + + return warFiles; + } + + /** + * Get all booster dependencies and invoke the maven-dependency-plugin to + * copy them to the Liberty server. + * + * @throws MojoExecutionException + * + */ + private void copyBoosterDependencies() throws MojoExecutionException { + + List dependenciesToCopy = BoosterConfigurator.getDependenciesToCopy(boosterConfigurators, + BoostLogger.getInstance()); + + for (String dep : dependenciesToCopy) { + + String[] dependencyInfo = dep.split(":"); + + executeMojo(getMavenDependencyPlugin(), goal("copy"), + configuration(element(name("outputDirectory"), projectBuildDir + "/boostDependencies"), + element(name("artifactItems"), + element(name("artifactItem"), element(name("groupId"), dependencyInfo[0]), + element(name("artifactId"), dependencyInfo[1]), + element(name("version"), dependencyInfo[2])))), + getExecutionEnvironment()); + } + } + +} diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyRunMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyRunMojo.java new file mode 100644 index 00000000..b16e4c86 --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyRunMojo.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.maven.wildfly; + +import java.io.IOException; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Mojo; + +import net.wasdev.wlp.common.plugins.util.OSUtil; + +/** + * Runs the executable archive application (in the console foreground). + */ +@Mojo(name = "wildfly-run") +public class WildflyRunMojo extends AbstractWildflyMojo { + + @Override + public void execute() throws MojoExecutionException { + super.execute(); + + String wildflyInstallPath = projectBuildDir + "/wildfly-" + runtimeArtifact.getVersion(); + + String startScript = "standalone.sh"; + if (OSUtil.isWindows()) { + startScript = "standalone.bat"; + } + + ProcessBuilder pb = new ProcessBuilder(); + pb.command(wildflyInstallPath + "/bin/" + startScript); + pb.inheritIO(); + + Process process = null; + try { + process = pb.start(); + process.waitFor(); + } catch (IOException | InterruptedException e) { + throw new MojoExecutionException("Could not start Wildfly server", e); + } finally { + if (process != null) { + process.destroy(); + } + } + + } + +} diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyStartMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyStartMojo.java new file mode 100644 index 00000000..e3c387ee --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyStartMojo.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.maven.wildfly; + +import java.io.IOException; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Mojo; + +import net.wasdev.wlp.common.plugins.util.OSUtil; + +/** + * Runs the executable archive application (in the console foreground). + */ +@Mojo(name = "wildfly-start") +public class WildflyStartMojo extends AbstractWildflyMojo { + + @Override + public void execute() throws MojoExecutionException { + super.execute(); + + String wildflyInstallPath = projectBuildDir + "/wildfly-" + runtimeArtifact.getVersion(); + + String startScript = "standalone.sh"; + if (OSUtil.isWindows()) { + startScript = "standalone.bat"; + } + + ProcessBuilder pb = new ProcessBuilder(); + pb.command(wildflyInstallPath + "/bin/" + startScript); + + try { + pb.start(); + } catch (IOException e) { + throw new MojoExecutionException("Could not start Wildfly server", e); + } + + } + +} diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyStopMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyStopMojo.java new file mode 100644 index 00000000..ffa95a6a --- /dev/null +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/maven/wildfly/WildflyStopMojo.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package io.openliberty.boost.maven.wildfly; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Mojo; + +import net.wasdev.wlp.common.plugins.util.OSUtil; + +/** + * Runs the executable archive application (in the console foreground). + */ +@Mojo(name = "wildfly-stop") +public class WildflyStopMojo extends AbstractWildflyMojo { + + @Override + public void execute() throws MojoExecutionException { + super.execute(); + + String wildflyInstallPath = projectBuildDir + "/wildfly-" + runtimeArtifact.getVersion(); + + String cliScript = "jboss-cli.sh"; + if (OSUtil.isWindows()) { + cliScript = "jboss-cli.bat"; + } + + List stopCommand = new ArrayList(); + stopCommand.add(wildflyInstallPath + "/bin/" + cliScript); + stopCommand.add("--connect"); + stopCommand.add("shutdown"); + + ProcessBuilder pb = new ProcessBuilder(); + pb.command(stopCommand); + + try { + pb.start(); + } catch (IOException e) { + throw new MojoExecutionException("Could not stop Wildfly server", e); + } + } + +}