mirror of
https://github.com/Alfresco/alfresco-sdk.git
synced 2025-05-19 17:15:24 +00:00
Support for MySQL, PostgreSQL, and custom Tomcat dependencies, #400
This commit is contained in:
parent
b46f173fb4
commit
04fe0678d7
@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.maven.plugin;
|
package org.alfresco.maven.plugin;
|
||||||
|
|
||||||
|
import org.alfresco.maven.plugin.config.ModuleDependency;
|
||||||
|
import org.alfresco.maven.plugin.config.TomcatDependency;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
@ -112,9 +114,21 @@ public class RunMojo extends AbstractMojo {
|
|||||||
* Switch to enable/disable the H2 database when running embedded Tomcat.
|
* Switch to enable/disable the H2 database when running embedded Tomcat.
|
||||||
* This also brings in the needed H2 database scripts.
|
* This also brings in the needed H2 database scripts.
|
||||||
*/
|
*/
|
||||||
@Parameter(property = "maven.alfresco.enableH2", defaultValue = "true")
|
@Parameter(property = "maven.alfresco.enableH2", defaultValue = "false")
|
||||||
protected boolean enableH2;
|
protected boolean enableH2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch to enable/disable the MySQL database when running embedded Tomcat.
|
||||||
|
*/
|
||||||
|
@Parameter(property = "maven.alfresco.enableMySQL", defaultValue = "false")
|
||||||
|
protected boolean enableMySQL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch to enable/disable the PostgreSQL database when running embedded Tomcat.
|
||||||
|
*/
|
||||||
|
@Parameter(property = "maven.alfresco.enablePostgreSQL", defaultValue = "false")
|
||||||
|
protected boolean enablePostgreSQL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch to enable/disable the Platform/Repository (alfresco.war) when running embedded Tomcat.
|
* Switch to enable/disable the Platform/Repository (alfresco.war) when running embedded Tomcat.
|
||||||
*/
|
*/
|
||||||
@ -175,6 +189,14 @@ public class RunMojo extends AbstractMojo {
|
|||||||
@Parameter(property = "maven.alfresco.edition", defaultValue = ALFRESCO_COMMUNITY_EDITION)
|
@Parameter(property = "maven.alfresco.edition", defaultValue = ALFRESCO_COMMUNITY_EDITION)
|
||||||
protected String alfrescoEdition;
|
protected String alfrescoEdition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tomcat Dependencies that should be added to the Embedded Tomcat configuration before start.
|
||||||
|
* Normally there would not be any extra dependencies, but could be if you run an Enterprise database
|
||||||
|
* such as Oracle, for which there's no quick config, such as enableH2, enableMySQL, or enablePostgreSQL.
|
||||||
|
*/
|
||||||
|
@Parameter(property = "maven.alfresco.tomcat.dependencies", defaultValue = "")
|
||||||
|
protected List<TomcatDependency> tomcatDependencies;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maven GAV properties for standard Alfresco web applications.
|
* Maven GAV properties for standard Alfresco web applications.
|
||||||
*/
|
*/
|
||||||
@ -250,6 +272,7 @@ public class RunMojo extends AbstractMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (startTomcat) {
|
if (startTomcat) {
|
||||||
|
checkDatabaseConfig();
|
||||||
startTomcat();
|
startTomcat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -549,7 +572,7 @@ public class RunMojo extends AbstractMojo {
|
|||||||
List<Element> ampModules = new ArrayList<>();
|
List<Element> ampModules = new ArrayList<>();
|
||||||
List<Element> jarModules = new ArrayList<>();
|
List<Element> jarModules = new ArrayList<>();
|
||||||
|
|
||||||
if (modules != null) {
|
if (modules != null && modules.size() > 0) {
|
||||||
for (ModuleDependency moduleDep : modules) {
|
for (ModuleDependency moduleDep : modules) {
|
||||||
Element el = element(name("artifactItem"),
|
Element el = element(name("artifactItem"),
|
||||||
element(name("groupId"), moduleDep.getGroupId()),
|
element(name("groupId"), moduleDep.getGroupId()),
|
||||||
@ -694,6 +717,30 @@ public class RunMojo extends AbstractMojo {
|
|||||||
return warArtifactId;
|
return warArtifactId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that a database configuration has been supplied correctly
|
||||||
|
*/
|
||||||
|
private void checkDatabaseConfig() throws MojoExecutionException {
|
||||||
|
if (enableH2 && !enableMySQL && !enablePostgreSQL) {
|
||||||
|
// Run with the H2 database
|
||||||
|
return;
|
||||||
|
} else if (!enableH2 && enableMySQL && !enablePostgreSQL) {
|
||||||
|
// Run with the MySQL database
|
||||||
|
return;
|
||||||
|
} else if (!enableH2 && !enableMySQL && enablePostgreSQL) {
|
||||||
|
// Run with the PostgreSQL database
|
||||||
|
return;
|
||||||
|
} else if (!enableH2 && !enableMySQL && !enablePostgreSQL) {
|
||||||
|
// Run with a database configured via Tomcat Dependencies
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw new MojoExecutionException(
|
||||||
|
"Invalid database configuration, " +
|
||||||
|
"should be enableH2 or enableMySQL or enablePostgreSQL " +
|
||||||
|
"or none (i.e. config via Tomcat Dependencies)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start up the embedded Tomcat server with the webapps that has been
|
* Start up the embedded Tomcat server with the webapps that has been
|
||||||
* configured in the SDK project.
|
* configured in the SDK project.
|
||||||
@ -703,27 +750,43 @@ public class RunMojo extends AbstractMojo {
|
|||||||
protected void startTomcat() throws MojoExecutionException {
|
protected void startTomcat() throws MojoExecutionException {
|
||||||
getLog().info("Starting Tomcat");
|
getLog().info("Starting Tomcat");
|
||||||
|
|
||||||
List<Dependency> tomcatDependencies = new ArrayList<Dependency>();
|
List<Dependency> tomcatPluginDependencies = new ArrayList<Dependency>();
|
||||||
ArrayList webapps2Deploy = new ArrayList<Element>();
|
ArrayList webapps2Deploy = new ArrayList<Element>();
|
||||||
|
|
||||||
// Add the basic Tomcat dependencies
|
// Add the basic Tomcat dependencies
|
||||||
tomcatDependencies.add(
|
tomcatPluginDependencies.add(
|
||||||
// Packaging goes faster with this lib
|
// Packaging goes faster with this lib
|
||||||
dependency("org.codehaus.plexus", "plexus-archiver", "2.3"));
|
dependency("org.codehaus.plexus", "plexus-archiver", "2.3"));
|
||||||
tomcatDependencies.add(
|
tomcatPluginDependencies.add(
|
||||||
// The following dependency is needed, otherwise you get
|
// The following dependency is needed, otherwise you get
|
||||||
// Caused by: java.lang.NoSuchMethodError:
|
// Caused by: java.lang.NoSuchMethodError:
|
||||||
// javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig
|
// javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig
|
||||||
// This method is in Servlet API 3.0
|
// This method is in Servlet API 3.0
|
||||||
dependency("javax.servlet", "javax.servlet-api", "3.0.1"));
|
dependency("javax.servlet", "javax.servlet-api", "3.0.1"));
|
||||||
|
|
||||||
|
// Do we have any extra Tomcat Plugin dependencies to include?
|
||||||
|
if (tomcatDependencies != null && tomcatDependencies.size() > 0) {
|
||||||
|
for (TomcatDependency tomcatDep : tomcatDependencies) {
|
||||||
|
tomcatPluginDependencies.add(
|
||||||
|
dependency(tomcatDep.getGroupId(), tomcatDep.getArtifactId(), tomcatDep.getVersion()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (enableH2) {
|
if (enableH2) {
|
||||||
tomcatDependencies.add(
|
tomcatPluginDependencies.add(
|
||||||
// Bring in the flat file H2 database
|
// Bring in the flat file H2 database
|
||||||
dependency("com.h2database", "h2", "1.4.190"));
|
dependency("com.h2database", "h2", "1.4.190"));
|
||||||
|
|
||||||
// Copy the h2 scripts
|
// Copy the h2 scripts
|
||||||
copyH2Dialect();
|
copyH2Dialect();
|
||||||
|
} else if (enableMySQL) {
|
||||||
|
tomcatPluginDependencies.add(
|
||||||
|
// Bring in the MySQL JDBC Driver
|
||||||
|
dependency("mysql", "mysql-connector-java", "5.1.32"));
|
||||||
|
} else if (enablePostgreSQL) {
|
||||||
|
tomcatPluginDependencies.add(
|
||||||
|
// Bring in the PostgreSQL JDBC Driver
|
||||||
|
dependency("org.postgresql", "postgresql", "9.4-1201-jdbc41"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enablePlatform) {
|
if (enablePlatform) {
|
||||||
@ -757,7 +820,7 @@ public class RunMojo extends AbstractMojo {
|
|||||||
groupId("org.apache.tomcat.maven"),
|
groupId("org.apache.tomcat.maven"),
|
||||||
artifactId("tomcat7-maven-plugin"),
|
artifactId("tomcat7-maven-plugin"),
|
||||||
version(MAVEN_TOMCAT7_PLUGIN_VERSION),
|
version(MAVEN_TOMCAT7_PLUGIN_VERSION),
|
||||||
tomcatDependencies
|
tomcatPluginDependencies
|
||||||
),
|
),
|
||||||
goal("run"),
|
goal("run"),
|
||||||
configuration(
|
configuration(
|
||||||
|
@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2016 Alfresco Software Limited.
|
||||||
|
* <p/>
|
||||||
|
* This file is part of the Alfresco SDK Samples project.
|
||||||
|
* <p/>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p/>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p/>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.maven.plugin.config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Maven Dependency containing the Group ID, Artifact ID, and Version (GAV).
|
||||||
|
*
|
||||||
|
* @author martin.bergljung@alfresco.com
|
||||||
|
* @version 1.0
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
public abstract class MavenDependency {
|
||||||
|
private String groupId;
|
||||||
|
private String artifactId;
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
public MavenDependency() {}
|
||||||
|
|
||||||
|
public MavenDependency(String g, String a, String v) {
|
||||||
|
this.groupId = g;
|
||||||
|
this.artifactId = a;
|
||||||
|
this.version = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupId() {
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupId(String groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArtifactId() {
|
||||||
|
return artifactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArtifactId(String artifactId) {
|
||||||
|
this.artifactId = artifactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof MavenDependency)) return false;
|
||||||
|
|
||||||
|
MavenDependency that = (MavenDependency) o;
|
||||||
|
|
||||||
|
if (!groupId.equals(that.groupId)) return false;
|
||||||
|
if (!artifactId.equals(that.artifactId)) return false;
|
||||||
|
return version.equals(that.version);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = groupId.hashCode();
|
||||||
|
result = 31 * result + artifactId.hashCode();
|
||||||
|
result = 31 * result + version.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "MavenDependency{" +
|
||||||
|
"groupId='" + groupId + '\'' +
|
||||||
|
", artifactId='" + artifactId + '\'' +
|
||||||
|
", version='" + version + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@ -16,72 +16,59 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.alfresco.maven.plugin;
|
package org.alfresco.maven.plugin.config;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines an Alfresco extension module dependency (JAR or AMP) to be
|
* Defines an Alfresco extension module dependency (JAR or AMP) to be
|
||||||
* overlayed on an Alfresco webapp file via Maven WAR plugin.
|
* overlayed on an Alfresco webapp file.
|
||||||
* <p/>
|
* <p/>
|
||||||
* This is so we can skip the WAR projects in the AIO project,
|
* This is so we can skip the WAR projects in the AIO project,
|
||||||
* and so we can include the Share Services AMP when running
|
* and so we can include the Share Services AMP when running
|
||||||
* with a simple platform JAR.
|
* with a simple platform JAR.
|
||||||
* <p/>
|
* <p/>
|
||||||
* This class is used by the RunMojo class.
|
* This class is used by the RunMojo class.
|
||||||
|
* <p/>
|
||||||
|
* Alfresco Maven Plugin config looks something like this:
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <platformModules>
|
||||||
|
* <moduleDependency>
|
||||||
|
* <groupId>${alfresco.groupId}</groupId>
|
||||||
|
* <artifactId>alfresco-share-services</artifactId>
|
||||||
|
* <version>${alfresco.share.version}</version>
|
||||||
|
* <type>amp</type>
|
||||||
|
* </moduleDependency>
|
||||||
|
* <moduleDependency>
|
||||||
|
* <groupId>${project.groupId}</groupId>
|
||||||
|
* <artifactId>${project.artifactId}</artifactId>
|
||||||
|
* <version>${project.version}</version>
|
||||||
|
* </moduleDependency>
|
||||||
|
* </platformModules>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author martin.bergljung@alfresco.com
|
* @author martin.bergljung@alfresco.com
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public class ModuleDependency {
|
public class ModuleDependency extends MavenDependency {
|
||||||
public static final String TYPE_JAR = "jar";
|
public static final String TYPE_JAR = "jar";
|
||||||
public static final String TYPE_AMP = "amp";
|
public static final String TYPE_AMP = "amp";
|
||||||
|
|
||||||
private String groupId;
|
|
||||||
private String artifactId;
|
|
||||||
private String version;
|
|
||||||
private String type = TYPE_JAR;
|
private String type = TYPE_JAR;
|
||||||
|
|
||||||
public ModuleDependency() {}
|
public ModuleDependency() {
|
||||||
|
super();
|
||||||
public ModuleDependency(String g, String a, String v) {
|
|
||||||
this.groupId = g;
|
|
||||||
this.artifactId = a;
|
|
||||||
this.version = v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModuleDependency(String g, String a, String v, String t) {
|
public ModuleDependency(String g, String a, String v, String t) {
|
||||||
this.groupId = g;
|
super(g,a,v);
|
||||||
this.artifactId = a;
|
|
||||||
this.version = v;
|
|
||||||
this.type = t;
|
this.type = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGroupId() {
|
|
||||||
return groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGroupId(String groupId) {
|
|
||||||
this.groupId = groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getArtifactId() {
|
|
||||||
return artifactId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setArtifactId(String artifactId) {
|
|
||||||
this.artifactId = artifactId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(String version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@ -102,21 +89,16 @@ public class ModuleDependency {
|
|||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (!(o instanceof ModuleDependency)) return false;
|
if (!(o instanceof ModuleDependency)) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
|
||||||
ModuleDependency that = (ModuleDependency) o;
|
ModuleDependency that = (ModuleDependency) o;
|
||||||
|
|
||||||
if (!groupId.equals(that.groupId)) return false;
|
|
||||||
if (!artifactId.equals(that.artifactId)) return false;
|
|
||||||
if (!version.equals(that.version)) return false;
|
|
||||||
return !(type != null ? !type.equals(that.type) : that.type != null);
|
return !(type != null ? !type.equals(that.type) : that.type != null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = groupId.hashCode();
|
int result = super.hashCode();
|
||||||
result = 31 * result + artifactId.hashCode();
|
|
||||||
result = 31 * result + version.hashCode();
|
|
||||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -124,9 +106,9 @@ public class ModuleDependency {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ModuleDependency{" +
|
return "ModuleDependency{" +
|
||||||
"groupId='" + groupId + '\'' +
|
"groupId='" + getGroupId() + '\'' +
|
||||||
", artifactId='" + artifactId + '\'' +
|
", artifactId='" + getArtifactId() + '\'' +
|
||||||
", version='" + version + '\'' +
|
", version='" + getVersion() + '\'' +
|
||||||
", type='" + type + '\'' +
|
", type='" + type + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2016 Alfresco Software Limited.
|
||||||
|
* <p/>
|
||||||
|
* This file is part of the Alfresco SDK Samples project.
|
||||||
|
* <p/>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p/>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p/>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.maven.plugin.config;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tomcat Dependency used in Embedded Tomcat Maven plugin configuration.
|
||||||
|
* <p/>
|
||||||
|
* Alfresco Maven Plugin config looks something like this:
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <tomcatDependencies>
|
||||||
|
* <tomcatDependency>
|
||||||
|
* <groupId>mysql</groupId>
|
||||||
|
* <artifactId>mysql-connector-java</artifactId>
|
||||||
|
* <version>5.1.32</version>
|
||||||
|
* </tomcatDependency>
|
||||||
|
* <tomcatDependencies>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author martin.bergljung@alfresco.com
|
||||||
|
* @version 1.0
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
public class TomcatDependency extends MavenDependency {
|
||||||
|
|
||||||
|
public TomcatDependency() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TomcatDependency(String g, String a, String v) {
|
||||||
|
super(g,a,v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TomcatDependency{" +
|
||||||
|
"groupId='" + getGroupId() + '\'' +
|
||||||
|
", artifactId='" + getArtifactId() + '\'' +
|
||||||
|
", version='" + getVersion() + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user