Support for custom webapps and sysprops, #412,#413

This commit is contained in:
Martin Bergljung
2016-10-03 12:05:39 +01:00
parent 4e26291761
commit a07219e6e6
4 changed files with 130 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ package org.alfresco.maven.plugin;
import org.alfresco.maven.plugin.config.ModuleDependency; import org.alfresco.maven.plugin.config.ModuleDependency;
import org.alfresco.maven.plugin.config.TomcatDependency; import org.alfresco.maven.plugin.config.TomcatDependency;
import org.alfresco.maven.plugin.config.TomcatWebapp;
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;
@@ -230,6 +231,22 @@ public class RunMojo extends AbstractMojo {
@Parameter(property = "maven.alfresco.tomcat.dependencies", defaultValue = "") @Parameter(property = "maven.alfresco.tomcat.dependencies", defaultValue = "")
protected List<TomcatDependency> tomcatDependencies; protected List<TomcatDependency> 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<String, String> 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<TomcatWebapp> tomcatCustomWebapps;
/** /**
* Maven GAV properties for standard Alfresco web applications. * Maven GAV properties for standard Alfresco web applications.
*/ */
@@ -975,6 +992,15 @@ public class RunMojo extends AbstractMojo {
activitiGroupId, activitiAdminWarArtifactId, activitiVersion, "/activiti-admin", null)); 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 // 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! // to avoid NPEs. If there's a better way to do this, then feel free to change it!
Element[] webapps = new Element[webapps2Deploy.size()]; Element[] webapps = new Element[webapps2Deploy.size()];
@@ -990,6 +1016,12 @@ public class RunMojo extends AbstractMojo {
// Should be in activiti-jar/src/test/resources // Should be in activiti-jar/src/test/resources
systemProps.add(element(name("log4j.configuration"), "log4j-dev.properties")); 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<String, String> 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 // 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! // to avoid NPEs. If there's a better way to do this, then feel free to change it!
Element[] systemPropArray = new Element[systemProps.size()]; Element[] systemPropArray = new Element[systemProps.size()];

View File

@@ -1,7 +1,7 @@
/** /**
* Copyright (C) 2016 Alfresco Software Limited. * Copyright (C) 2016 Alfresco Software Limited.
* <p/> * <p/>
* This file is part of the Alfresco SDK Samples project. * This file is part of the Alfresco SDK project.
* <p/> * <p/>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -1,7 +1,7 @@
/** /**
* Copyright (C) 2016 Alfresco Software Limited. * Copyright (C) 2016 Alfresco Software Limited.
* <p/> * <p/>
* This file is part of the Alfresco SDK Samples project. * This file is part of the Alfresco SDK project.
* <p/> * <p/>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -18,8 +18,6 @@
package org.alfresco.maven.plugin.config; package org.alfresco.maven.plugin.config;
import org.apache.commons.lang.StringUtils;
/** /**
* Tomcat Dependency used in Embedded Tomcat Maven plugin configuration. * Tomcat Dependency used in Embedded Tomcat Maven plugin configuration.
* <p/> * <p/>

View File

@@ -0,0 +1,96 @@
/**
* Copyright (C) 2016 Alfresco Software Limited.
* <p/>
* This file is part of the Alfresco SDK 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;
/**
* 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.
* <p/>
* Alfresco Maven Plugin config looks something like this:
* <pre>
* {@code
* <tomcatWebapps>
* <tomcatWebapp>
* <groupId>com.exari</groupId>
* <artifactId>exari-docgen-cmwar</artifactId>
* <version>${project.version}</version>
* <contextPath>/exari</contextPath>
* <contextFile>${project.build.directory}/contexts/context-docgen.xml</contextFile>
* </tomcatWebapp>
* <tomcatWebapps>
* }
* </pre>
*
* @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 + '\'' +
'}';
}
}