From a07219e6e6a5a9ccfa03d06b081da21434430aef Mon Sep 17 00:00:00 2001 From: Martin Bergljung Date: Mon, 3 Oct 2016 12:05:39 +0100 Subject: [PATCH] Support for custom webapps and sysprops, #412,#413 --- .../org/alfresco/maven/plugin/RunMojo.java | 32 +++++++ .../maven/plugin/config/MavenDependency.java | 2 +- .../maven/plugin/config/TomcatDependency.java | 4 +- .../maven/plugin/config/TomcatWebapp.java | 96 +++++++++++++++++++ 4 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/TomcatWebapp.java diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/RunMojo.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/RunMojo.java index bc89c6db..496bb4ee 100644 --- a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/RunMojo.java +++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/RunMojo.java @@ -19,6 +19,7 @@ package org.alfresco.maven.plugin; import org.alfresco.maven.plugin.config.ModuleDependency; import org.alfresco.maven.plugin.config.TomcatDependency; +import org.alfresco.maven.plugin.config.TomcatWebapp; import org.apache.commons.lang.StringUtils; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; @@ -230,6 +231,22 @@ public class RunMojo extends AbstractMojo { @Parameter(property = "maven.alfresco.tomcat.dependencies", defaultValue = "") protected List tomcatDependencies; + /** + * System Properties to feed the Tomcat plugin before start. + * Normally there would not be any extra dependencies, but we could run a custom webapp that needed + * a custom sys prop set. + */ + @Parameter(property = "maven.alfresco.tomcat.system.properties", defaultValue = "") + protected Map tomcatSystemProperties; + + /** + * Custom webapps that should be deployed to the embedded Tomcat engine. + * Normally there would not be any extra webapps, but we could run a bigger project that uses + * some custom webapp. + */ + @Parameter(property = "maven.alfresco.tomcat.custom.webapps", defaultValue = "") + protected List tomcatCustomWebapps; + /** * Maven GAV properties for standard Alfresco web applications. */ @@ -975,6 +992,15 @@ public class RunMojo extends AbstractMojo { activitiGroupId, activitiAdminWarArtifactId, activitiVersion, "/activiti-admin", null)); } + if (tomcatCustomWebapps != null && !tomcatCustomWebapps.isEmpty()) { + // We got extra custom webapps to deploy + for (TomcatWebapp customWebapp: tomcatCustomWebapps) { + webapps2Deploy.add(createWebAppElement( + customWebapp.getGroupId(), customWebapp.getArtifactId(), customWebapp.getVersion(), + customWebapp.getContextPath(), customWebapp.getContextFile())); + } + } + // This might be ugly, the MojoExecuter will only accept Element[] and we need this list to be dynamic // to avoid NPEs. If there's a better way to do this, then feel free to change it! Element[] webapps = new Element[webapps2Deploy.size()]; @@ -990,6 +1016,12 @@ public class RunMojo extends AbstractMojo { // Should be in activiti-jar/src/test/resources systemProps.add(element(name("log4j.configuration"), "log4j-dev.properties")); } + // Add custom system properties defined in plugin config + if (tomcatSystemProperties != null && !tomcatSystemProperties.isEmpty()) { + for (Map.Entry sysProp : tomcatSystemProperties.entrySet()) { + systemProps.add(element(name(sysProp.getKey()), sysProp.getValue())); + } + } // This might be ugly, the MojoExecuter will only accept Element[] and we need this list to be dynamic // to avoid NPEs. If there's a better way to do this, then feel free to change it! Element[] systemPropArray = new Element[systemProps.size()]; diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/MavenDependency.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/MavenDependency.java index 53ab3f4b..7e53b68f 100644 --- a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/MavenDependency.java +++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/MavenDependency.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2016 Alfresco Software Limited. *

- * This file is part of the Alfresco SDK Samples project. + * This file is part of the Alfresco SDK project. *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/TomcatDependency.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/TomcatDependency.java index 0bb7dd17..7fcb5122 100644 --- a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/TomcatDependency.java +++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/TomcatDependency.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2016 Alfresco Software Limited. *

- * This file is part of the Alfresco SDK Samples project. + * This file is part of the Alfresco SDK project. *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ package org.alfresco.maven.plugin.config; -import org.apache.commons.lang.StringUtils; - /** * Tomcat Dependency used in Embedded Tomcat Maven plugin configuration. *

diff --git a/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/TomcatWebapp.java b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/TomcatWebapp.java new file mode 100644 index 00000000..f4793300 --- /dev/null +++ b/plugins/alfresco-maven-plugin/src/main/java/org/alfresco/maven/plugin/config/TomcatWebapp.java @@ -0,0 +1,96 @@ +/** + * Copyright (C) 2016 Alfresco Software Limited. + *

+ * This file is part of the Alfresco SDK project. + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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; + +/** + * Tomcat Webapp used in Embedded Tomcat Maven plugin configuration. + * These are custom webapps that you would want to include for some reason + * (The {webapp artifact}.war need to be available in a Maven Repo). + * Note. the standard webapps are included with plugin properties such as enablePlatform and enableShare. + *

+ * Alfresco Maven Plugin config looks something like this: + *

+ *    {@code
+ *    
+ *      
+ *          com.exari
+ *          exari-docgen-cmwar
+ *          ${project.version}
+ *          /exari
+ *          ${project.build.directory}/contexts/context-docgen.xml
+ *      
+ *    
+ *    }
+ * 
+ * + * @author martin.bergljung@alfresco.com + * @version 1.0 + * @since 3.0.0 + */ +public class TomcatWebapp extends MavenDependency { + private String contextPath; + private String contextFile; + + public TomcatWebapp() {} + + public TomcatWebapp(String g, String a, String v, String contextPath, String contextFile) { + super(g, a, v); + this.contextPath = contextPath; + this.contextFile = contextFile; + } + + public String getContextPath() { + return contextPath; + } + + public String getContextFile() { + return contextFile; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof TomcatWebapp)) return false; + if (!super.equals(o)) return false; + + TomcatWebapp that = (TomcatWebapp) o; + + if (!contextPath.equals(that.contextPath)) return false; + return !(contextFile != null ? !contextFile.equals(that.contextFile) : that.contextFile != null); + + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + contextPath.hashCode(); + result = 31 * result + (contextFile != null ? contextFile.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "TomcatWebapp{" + + "groupId='" + getGroupId() + '\'' + + ", artifactId='" + getArtifactId() + '\'' + + ", version='" + getVersion() + '\'' + + ", contextPath='" + contextPath + '\'' + + ", contextFile='" + contextFile + '\'' + + '}'; + } +}